summaryrefslogtreecommitdiffstats
path: root/lib/xaapiv1
diff options
context:
space:
mode:
authorSebastien Douheret <sebastien.douheret@iot.bzh>2018-01-23 15:33:08 +0100
committerSebastien Douheret <sebastien.douheret@iot.bzh>2018-01-23 15:33:08 +0100
commitfacf3f10b243d027cc2a28661fe1cd8d4253dafa (patch)
treec483a3b2461cce66f109a3318276d276db8bbf3f /lib/xaapiv1
parent6d17c864bad066fbb5400733dcaf918253f5973b (diff)
Reworked SDKs events (introduced sdk-state-change)eel_5.0.1eel/5.0.15.0.1
Signed-off-by: Sebastien Douheret <sebastien.douheret@iot.bzh>
Diffstat (limited to 'lib/xaapiv1')
-rw-r--r--lib/xaapiv1/events.go41
-rw-r--r--lib/xaapiv1/sdks.go7
2 files changed, 37 insertions, 11 deletions
diff --git a/lib/xaapiv1/events.go b/lib/xaapiv1/events.go
index ab08d0f..6520057 100644
--- a/lib/xaapiv1/events.go
+++ b/lib/xaapiv1/events.go
@@ -40,13 +40,15 @@ 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
- EVTSDKInstall = EventTypePrefix + "sdk-install" // type EventMsg with Data type xaapiv1.SDKManagementMsg
- EVTSDKRemove = EventTypePrefix + "sdk-remove" // type EventMsg with Data type xaapiv1.SDKManagementMsg
+ 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
)
// EVTAllList List of all supported events
@@ -55,8 +57,10 @@ var EVTAllList = []string{
EVTProjectAdd,
EVTProjectDelete,
EVTProjectChange,
- EVTSDKInstall,
+ EVTSDKAdd,
EVTSDKRemove,
+ EVTSDKManagement,
+ EVTSDKStateChange,
}
// EventMsg Event message send over Websocket, data format depend to Type (see DecodeXXX function)
@@ -97,12 +101,27 @@ func (e *EventMsg) DecodeProjectConfig() (ProjectConfig, error) {
return p, err
}
-// DecodeSDKMsg Helper to decode Data field type SDKManagementMsg
-func (e *EventMsg) DecodeSDKMsg() (SDKManagementMsg, error) {
+// DecodeSDKMgtMsg Helper to decode Data field type SDKManagementMsg
+func (e *EventMsg) DecodeSDKMgtMsg() (SDKManagementMsg, error) {
var err error
s := SDKManagementMsg{}
+ if e.Type != EVTSDKManagement {
+ return s, fmt.Errorf("Invalid type")
+ }
+ d := []byte{}
+ d, err = json.Marshal(e.Data)
+ if err == nil {
+ err = json.Unmarshal(d, &s)
+ }
+ return s, err
+}
+
+// DecodeSDKEvent Helper to decode Data field type SDK
+func (e *EventMsg) DecodeSDKEvent() (SDK, error) {
+ var err error
+ s := SDK{}
switch e.Type {
- case EVTSDKInstall, EVTSDKRemove:
+ case EVTSDKAdd, EVTSDKRemove, EVTSDKStateChange:
d := []byte{}
d, err = json.Marshal(e.Data)
if err == nil {
diff --git a/lib/xaapiv1/sdks.go b/lib/xaapiv1/sdks.go
index 7f2ab02..97db9a8 100644
--- a/lib/xaapiv1/sdks.go
+++ b/lib/xaapiv1/sdks.go
@@ -53,10 +53,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"`