2014-10-21 22:02:20 +00:00
|
|
|
package ipc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"reflect"
|
|
|
|
|
|
|
|
"github.com/docker/libchan"
|
|
|
|
)
|
|
|
|
|
2014-10-29 19:14:19 +00:00
|
|
|
// Request defines a remote method call request
|
2014-10-29 01:15:40 +00:00
|
|
|
// A return value struct is to be sent over the ResponseChannel
|
2014-10-21 22:02:20 +00:00
|
|
|
type Request struct {
|
|
|
|
Type string
|
|
|
|
Parameters map[string]interface{}
|
|
|
|
ResponseChannel libchan.Sender
|
|
|
|
}
|
|
|
|
|
|
|
|
type responseError struct {
|
|
|
|
Type string
|
|
|
|
Message string
|
|
|
|
}
|
|
|
|
|
2014-10-29 19:14:19 +00:00
|
|
|
// ResponseError wraps an error in a serializable struct containing the error's type and message
|
2014-10-21 22:02:20 +00:00
|
|
|
func ResponseError(err error) *responseError {
|
|
|
|
if err == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return &responseError{
|
|
|
|
Type: reflect.TypeOf(err).String(),
|
|
|
|
Message: err.Error(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (err *responseError) Error() string {
|
|
|
|
return fmt.Sprintf("%s: %s", err.Type, err.Message)
|
|
|
|
}
|
|
|
|
|
2014-10-29 01:15:40 +00:00
|
|
|
// IPC method call response object definitions
|
|
|
|
|
2014-10-29 19:14:19 +00:00
|
|
|
// ReadStreamResponse is a response for a ReadStream request
|
2014-10-21 22:02:20 +00:00
|
|
|
type ReadStreamResponse struct {
|
2014-10-31 18:50:02 +00:00
|
|
|
Reader io.ReadCloser
|
2014-10-21 22:02:20 +00:00
|
|
|
Error *responseError
|
|
|
|
}
|
|
|
|
|
2014-10-29 19:14:19 +00:00
|
|
|
// WriteStreamResponse is a response for a WriteStream request
|
2014-10-21 22:02:20 +00:00
|
|
|
type WriteStreamResponse struct {
|
|
|
|
Error *responseError
|
|
|
|
}
|
|
|
|
|
2014-10-29 19:14:19 +00:00
|
|
|
// ResumeWritePositionResponse is a response for a ResumeWritePosition request
|
2014-10-21 22:02:20 +00:00
|
|
|
type ResumeWritePositionResponse struct {
|
|
|
|
Position uint64
|
|
|
|
Error *responseError
|
|
|
|
}
|
|
|
|
|
2014-10-29 19:14:19 +00:00
|
|
|
// ListResponse is a response for a List request
|
2014-10-21 22:02:20 +00:00
|
|
|
type ListResponse struct {
|
|
|
|
Keys []string
|
|
|
|
Error *responseError
|
|
|
|
}
|
|
|
|
|
2014-10-29 19:14:19 +00:00
|
|
|
// MoveResponse is a response for a Move request
|
2014-10-21 22:02:20 +00:00
|
|
|
type MoveResponse struct {
|
|
|
|
Error *responseError
|
|
|
|
}
|
|
|
|
|
2014-10-29 19:14:19 +00:00
|
|
|
// DeleteResponse is a response for a Delete request
|
2014-10-21 22:02:20 +00:00
|
|
|
type DeleteResponse struct {
|
|
|
|
Error *responseError
|
|
|
|
}
|