Commit 971b7732 authored by Zhu Yong's avatar Zhu Yong
Browse files

Add MediaScan and MediaOptimize operations

parent 980e2f41
Loading
Loading
Loading
Loading
+30 −0
Original line number Diff line number Diff line
@@ -262,6 +262,36 @@ func (conn *BlockConnection) SetErasePin(currentPin []byte, newPin []byte) (Stat
	return callback.Status(), nil
}

func (conn *BlockConnection) MediaScan(op *MediaOperation, pri Priority) (Status, error) {
	callback := &GenericCallback{}
	h := NewResponseHandler(callback)
	err := conn.nbc.MediaScan(op, pri, h)
	if err != nil {
		return callback.Status(), err
	}

	for callback.Done() == false {
		conn.nbc.Run()
	}

	return callback.Status(), nil
}

func (conn *BlockConnection) MediaOptimize(op *MediaOperation, pri Priority) (Status, error) {
	callback := &GenericCallback{}
	h := NewResponseHandler(callback)
	err := conn.nbc.MediaOptimize(op, pri, h)
	if err != nil {
		return callback.Status(), err
	}

	for callback.Done() == false {
		conn.nbc.Run()
	}

	return callback.Status(), nil
}

func (conn *BlockConnection) Close() {
	conn.nbc.Close()
}
+7 −0
Original line number Diff line number Diff line
@@ -505,3 +505,10 @@ type KeyRange struct {
	Reverse           bool
	Max               int32
}

type MediaOperation struct {
	StartKey          []byte
	EndKey            []byte
	StartKeyInclusive bool
	EndKeyInclusive   bool
}
+36 −4
Original line number Diff line number Diff line
@@ -240,12 +240,44 @@ func (conn *NonBlockConnection) SetACL(h *ResponseHandler) error {
	return nil
}

func (conn *NonBlockConnection) MediaScan(h *ResponseHandler) error {
	return nil
func (conn *NonBlockConnection) MediaScan(op *MediaOperation, pri Priority, h *ResponseHandler) error {
	msg := newMessage(kproto.Message_HMACAUTH)

	cmd := newCommand(kproto.Command_MEDIASCAN)

	cmd.Body = &kproto.Command_Body{
		Range: &kproto.Command_Range{
			StartKey:          op.StartKey,
			EndKey:            op.EndKey,
			StartKeyInclusive: &op.StartKeyInclusive,
			EndKeyInclusive:   &op.EndKeyInclusive,
		},
	}

func (conn *NonBlockConnection) MediaOptimize(h *ResponseHandler) error {
	return nil
	cmd_pri := convertPriorityToProto(pri)
	cmd.Header.Priority = &cmd_pri

	return conn.service.submit(msg, cmd, nil, h)
}

func (conn *NonBlockConnection) MediaOptimize(op *MediaOperation, pri Priority, h *ResponseHandler) error {
	msg := newMessage(kproto.Message_HMACAUTH)

	cmd := newCommand(kproto.Command_MEDIAOPTIMIZE)

	cmd.Body = &kproto.Command_Body{
		Range: &kproto.Command_Range{
			StartKey:          op.StartKey,
			EndKey:            op.EndKey,
			StartKeyInclusive: &op.StartKeyInclusive,
			EndKeyInclusive:   &op.EndKeyInclusive,
		},
	}

	cmd_pri := convertPriorityToProto(pri)
	cmd.Header.Priority = &cmd_pri

	return conn.service.submit(msg, cmd, nil, h)
}

func (conn *NonBlockConnection) Run() error {