-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathcmd.go
59 lines (49 loc) · 1.05 KB
/
cmd.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package beehive
import (
"encoding/gob"
"errors"
"fmt"
)
// Cmd represents a control command.
//
// If App is "" and To is 0, the command is handed to the hive.
// If App is not "" and To is 0, the command should be handed to the qee.
// Otherwise it is for a bee of that app.
type cmd struct {
Hive uint64
App string
Bee uint64
Data interface{}
}
func (c cmd) String() string {
return fmt.Sprintf("CMD -> %v/%s/%v\t%#v", c.Hive, c.App, c.Bee, c.Data)
}
// ErrInvalidCmd is returned when the requested command is invalid or is not
// supported by the receiver of the command.
var ErrInvalidCmd = errors.New("invalid command")
type cmdAndChannel struct {
cmd cmd
ch chan cmdResult
}
type cmdResult struct {
Data interface{}
Err error
}
func (r cmdResult) get() (interface{}, error) {
return r.Data, r.Err
}
func newCmdAndChannel(d interface{}, h uint64, a string, b uint64,
ch chan cmdResult) cmdAndChannel {
return cmdAndChannel{
cmd: cmd{
Hive: h,
App: a,
Bee: b,
Data: d,
},
ch: ch,
}
}
func init() {
gob.Register(cmd{})
}