diff options
author | Sebastien Douheret <sebastien.douheret@iot.bzh> | 2018-03-15 14:50:27 +0100 |
---|---|---|
committer | Sebastien Douheret <sebastien.douheret@iot.bzh> | 2018-04-05 01:30:28 +0200 |
commit | 08095aa9a0d7b9b7636cdf36a5a5b6df2592bc05 (patch) | |
tree | a62f59e6b0116d31b7ad9ec85974129d9698765b /lib/xsapiv1/events.go | |
parent | 17812a0a4388ab0c87084ef7e8118d87e8fadcf7 (diff) |
Added Target and Terminal events through WS.
Signed-off-by: Sebastien Douheret <sebastien.douheret@iot.bzh>
Diffstat (limited to 'lib/xsapiv1/events.go')
-rw-r--r-- | lib/xsapiv1/events.go | 60 |
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 +} |