summaryrefslogtreecommitdiffstats
path: root/lib/xsapiv1
diff options
context:
space:
mode:
Diffstat (limited to 'lib/xsapiv1')
-rw-r--r--lib/xsapiv1/events.go60
1 files changed, 55 insertions, 5 deletions
diff --git a/lib/xsapiv1/events.go b/lib/xsapiv1/events.go
index 84a364c..e42563c 100644
--- a/lib/xsapiv1/events.go
+++ b/lib/xsapiv1/events.go
@@ -48,13 +48,23 @@ const (
EventTypePrefix = "event:" // following by event type
// Supported Events type
- EVTAll = EventTypePrefix + "all"
+ EVTAll = EventTypePrefix + "all"
+
EVTFolderChange = EventTypePrefix + "folder-change" // type EventMsg with Data type xsapiv1.FolderConfig
EVTFolderStateChange = EventTypePrefix + "folder-state-change" // type EventMsg with Data type xsapiv1.FolderConfig
- EVTSDKAdd = EventTypePrefix + "sdk-add" // type EventMsg with Data type xsapiv1.SDK
- EVTSDKRemove = EventTypePrefix + "sdk-remove" // type EventMsg with Data type xsapiv1.SDK
- EVTSDKManagement = EventTypePrefix + "sdk-management" // type EventMsg with Data type xsapiv1.SDKManagementMsg
- EVTSDKStateChange = EventTypePrefix + "sdk-state-change" // type EventMsg with Data type xsapiv1.SDK
+
+ EVTSDKAdd = EventTypePrefix + "sdk-add" // type EventMsg with Data type xsapiv1.SDK
+ EVTSDKRemove = EventTypePrefix + "sdk-remove" // type EventMsg with Data type xsapiv1.SDK
+ EVTSDKManagement = EventTypePrefix + "sdk-management" // type EventMsg with Data type xsapiv1.SDKManagementMsg
+ EVTSDKStateChange = EventTypePrefix + "sdk-state-change" // type EventMsg with Data type xsapiv1.SDK
+
+ EVTTargetAdd = EventTypePrefix + "target-add" // type EventMsg with Data type xsapiv1.TargetConfig
+ EVTTargetRemove = EventTypePrefix + "target-remove" // type EventMsg with Data type xsapiv1.TargetConfig
+ EVTTargetStateChange = EventTypePrefix + "target-state-change" // type EventMsg with Data type xsapiv1.TargetConfig
+
+ EVTTargetTerminalAdd = EventTypePrefix + "target-terminal-add" // type EventMsg with Data type xsapiv1.TerminalConfig
+ EVTTargetTerminalRemove = EventTypePrefix + "target-terminal-remove" // type EventMsg with Data type xsapiv1.TerminalConfig
+ EVTTargetTerminalStateChange = EventTypePrefix + "target-terminal-state-change" // type EventMsg with Data type xsapiv1.TerminalConfig
)
// EVTAllList List of all supported events
@@ -65,6 +75,12 @@ var EVTAllList = []string{
EVTSDKRemove,
EVTSDKManagement,
EVTSDKStateChange,
+ EVTTargetAdd,
+ EVTTargetRemove,
+ EVTTargetStateChange,
+ EVTTargetTerminalAdd,
+ EVTTargetTerminalRemove,
+ EVTTargetTerminalStateChange,
}
// DecodeFolderConfig Helper to decode Data field type FolderConfig
@@ -100,3 +116,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
+}