summaryrefslogtreecommitdiffstats
path: root/lib/xsapiv1
diff options
context:
space:
mode:
authorSebastien Douheret <sebastien.douheret@iot.bzh>2018-01-23 15:31:00 +0100
committerSebastien Douheret <sebastien.douheret@iot.bzh>2018-01-23 15:31:00 +0100
commitdcdee5e2aa05ec07e7e750bea4faad63bce7b668 (patch)
tree68d6755cb7e0bbb1b4fdbdb2e60456d1ef17f30e /lib/xsapiv1
parent297955b744110f67dad475e628bf068ec849b190 (diff)
Reworked SDKs events (introduced sdk-state-change)
Split add/remove/state-change from installing output (AKA SDKManagement event) in order to clearly separate events used to send installation output and sdk config changes. Signed-off-by: Sebastien Douheret <sebastien.douheret@iot.bzh>
Diffstat (limited to 'lib/xsapiv1')
-rw-r--r--lib/xsapiv1/events.go25
-rw-r--r--lib/xsapiv1/sdks.go7
2 files changed, 29 insertions, 3 deletions
diff --git a/lib/xsapiv1/events.go b/lib/xsapiv1/events.go
index aa17187..84a364c 100644
--- a/lib/xsapiv1/events.go
+++ b/lib/xsapiv1/events.go
@@ -51,8 +51,9 @@ const (
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
- EVTSDKInstall = EventTypePrefix + "sdk-install" // type EventMsg with Data type xsapiv1.SDKManagementMsg
- EVTSDKRemove = EventTypePrefix + "sdk-remove" // type EventMsg with Data type xsapiv1.SDKManagementMsg
+ 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
)
@@ -60,8 +61,9 @@ const (
var EVTAllList = []string{
EVTFolderChange,
EVTFolderStateChange,
- EVTSDKInstall,
+ EVTSDKAdd,
EVTSDKRemove,
+ EVTSDKManagement,
EVTSDKStateChange,
}
@@ -81,3 +83,20 @@ func (e *EventMsg) DecodeFolderConfig() (FolderConfig, error) {
}
return f, err
}
+
+// DecodeSDKEvent Helper to decode Data field type SDK
+func (e *EventMsg) DecodeSDKEvent() (SDK, error) {
+ var err error
+ s := SDK{}
+ switch e.Type {
+ case EVTSDKAdd, EVTSDKRemove, EVTSDKStateChange:
+ d := []byte{}
+ d, err = json.Marshal(e.Data)
+ if err == nil {
+ err = json.Unmarshal(d, &s)
+ }
+ default:
+ err = fmt.Errorf("Invalid type")
+ }
+ return s, err
+}
diff --git a/lib/xsapiv1/sdks.go b/lib/xsapiv1/sdks.go
index f751fc6..abb5d4a 100644
--- a/lib/xsapiv1/sdks.go
+++ b/lib/xsapiv1/sdks.go
@@ -65,10 +65,17 @@ type SDKInstallArgs struct {
InstallArgs []string `json:"installArgs"` // args directly passed to add/install script
}
+// SDK SDKManagementMsg Actions
+const (
+ SdkMgtActionInstall = "installing"
+ SdkMgtActionRemove = "removing"
+)
+
// SDKManagementMsg Message send during SDK installation or when installation is complete
type SDKManagementMsg struct {
CmdID string `json:"cmdID"`
Timestamp string `json:"timestamp"`
+ Action string `json:"action"`
Sdk SDK `json:"sdk"`
Stdout string `json:"stdout"`
Stderr string `json:"stderr"`