summaryrefslogtreecommitdiffstats
path: root/lib/xaapiv1
diff options
context:
space:
mode:
Diffstat (limited to 'lib/xaapiv1')
-rw-r--r--lib/xaapiv1/events.go68
1 files changed, 59 insertions, 9 deletions
diff --git a/lib/xaapiv1/events.go b/lib/xaapiv1/events.go
index 6520057..3a47e49 100644
--- a/lib/xaapiv1/events.go
+++ b/lib/xaapiv1/events.go
@@ -40,15 +40,25 @@ const (
EventTypePrefix = "event:" // following by event type
// Supported Events type
- EVTAll = EventTypePrefix + "all"
- EVTServerConfig = EventTypePrefix + "server-config" // type EventMsg with Data type xaapiv1.ServerCfg
- EVTProjectAdd = EventTypePrefix + "project-add" // type EventMsg with Data type xaapiv1.ProjectConfig
- EVTProjectDelete = EventTypePrefix + "project-delete" // type EventMsg with Data type xaapiv1.ProjectConfig
- EVTProjectChange = EventTypePrefix + "project-state-change" // type EventMsg with Data type xaapiv1.ProjectConfig
- EVTSDKAdd = EventTypePrefix + "sdk-add" // type EventMsg with Data type xaapiv1.SDK
- EVTSDKRemove = EventTypePrefix + "sdk-remove" // type EventMsg with Data type xaapiv1.SDK
- EVTSDKManagement = EventTypePrefix + "sdk-management" // type EventMsg with Data type xaapiv1.SDKManagementMsg
- EVTSDKStateChange = EventTypePrefix + "sdk-state-change" // type EventMsg with Data type xaapiv1.SDK
+ EVTAll = EventTypePrefix + "all"
+
+ EVTServerConfig = EventTypePrefix + "server-config" // type EventMsg with Data type xaapiv1.ServerCfg
+ EVTProjectAdd = EventTypePrefix + "project-add" // type EventMsg with Data type xaapiv1.ProjectConfig
+ EVTProjectDelete = EventTypePrefix + "project-delete" // type EventMsg with Data type xaapiv1.ProjectConfig
+ EVTProjectChange = EventTypePrefix + "project-state-change" // type EventMsg with Data type xaapiv1.ProjectConfig
+
+ EVTSDKAdd = EventTypePrefix + "sdk-add" // type EventMsg with Data type xaapiv1.SDK
+ EVTSDKRemove = EventTypePrefix + "sdk-remove" // type EventMsg with Data type xaapiv1.SDK
+ EVTSDKManagement = EventTypePrefix + "sdk-management" // type EventMsg with Data type xaapiv1.SDKManagementMsg
+ EVTSDKStateChange = EventTypePrefix + "sdk-state-change" // type EventMsg with Data type xaapiv1.SDK
+
+ EVTTargetAdd = EventTypePrefix + "target-add" // type EventMsg with Data type xaapiv1.TargetConfig
+ EVTTargetRemove = EventTypePrefix + "target-remove" // type EventMsg with Data type xaapiv1.TargetConfig
+ EVTTargetStateChange = EventTypePrefix + "target-state-change" // type EventMsg with Data type xaapiv1.TargetConfig
+
+ EVTTargetTerminalAdd = EventTypePrefix + "target-terminal-add" // type EventMsg with Data type xaapiv1.TerminalConfig
+ EVTTargetTerminalRemove = EventTypePrefix + "target-terminal-remove" // type EventMsg with Data type xaapiv1.TerminalConfig
+ EVTTargetTerminalStateChange = EventTypePrefix + "target-terminal-state-change" // type EventMsg with Data type xaapiv1.TerminalConfig
)
// EVTAllList List of all supported events
@@ -61,6 +71,12 @@ var EVTAllList = []string{
EVTSDKRemove,
EVTSDKManagement,
EVTSDKStateChange,
+ EVTTargetAdd,
+ EVTTargetRemove,
+ EVTTargetStateChange,
+ EVTTargetTerminalAdd,
+ EVTTargetTerminalRemove,
+ EVTTargetTerminalStateChange,
}
// EventMsg Event message send over Websocket, data format depend to Type (see DecodeXXX function)
@@ -132,3 +148,37 @@ func (e *EventMsg) DecodeSDKEvent() (SDK, error) {
}
return s, err
}
+
+// DecodeTargetEvent Helper to decode Data field type TargetConfig
+func (e *EventMsg) DecodeTargetEvent() (TargetConfig, error) {
+ var err error
+ p := TargetConfig{}
+ switch e.Type {
+ case EVTTargetAdd, EVTTargetRemove, EVTTargetStateChange:
+ d := []byte{}
+ d, err = json.Marshal(e.Data)
+ if err == nil {
+ err = json.Unmarshal(d, &p)
+ }
+ default:
+ err = fmt.Errorf("Invalid type")
+ }
+ return p, err
+}
+
+// DecodeTerminalEvent Helper to decode Data field type TerminalConfig
+func (e *EventMsg) DecodeTerminalEvent() (TerminalConfig, error) {
+ var err error
+ p := TerminalConfig{}
+ switch e.Type {
+ case EVTTargetTerminalAdd, EVTTargetTerminalRemove, EVTTargetTerminalStateChange:
+ d := []byte{}
+ d, err = json.Marshal(e.Data)
+ if err == nil {
+ err = json.Unmarshal(d, &p)
+ }
+ default:
+ err = fmt.Errorf("Invalid type")
+ }
+ return p, err
+}