X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=lib%2Fxaapiv1%2Fevents.go;h=65200573223338b24aa2c24f99a40d08f954c5d3;hb=refs%2Ftags%2Feel_5.0.1;hp=16c2dd7cc53c76510f4b3ff973d8689c72114655;hpb=45f6472d1e8ecad428da314a6d762143f033865d;p=src%2Fxds%2Fxds-agent.git diff --git a/lib/xaapiv1/events.go b/lib/xaapiv1/events.go index 16c2dd7..6520057 100644 --- a/lib/xaapiv1/events.go +++ b/lib/xaapiv1/events.go @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017 "IoT.bzh" + * Copyright (C) 2017-2018 "IoT.bzh" * Author Sebastien Douheret * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -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 {