X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=lib%2Fxaapiv1%2Fevents.go;h=ab08d0f0da18b7f595320101bbaeb37077fb7998;hb=a2cc38902ff7528870822110c4f04329a3918564;hp=85dc02a7b415018afdeefb3d612b973332b459ab;hpb=82ede02a56e12026b2dfb1baeacabfbd564006b1;p=src%2Fxds%2Fxds-agent.git diff --git a/lib/xaapiv1/events.go b/lib/xaapiv1/events.go index 85dc02a..ab08d0f 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"); @@ -45,6 +45,8 @@ const ( 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 ) // EVTAllList List of all supported events @@ -53,12 +55,14 @@ var EVTAllList = []string{ EVTProjectAdd, EVTProjectDelete, EVTProjectChange, + EVTSDKInstall, + EVTSDKRemove, } // EventMsg Event message send over Websocket, data format depend to Type (see DecodeXXX function) type EventMsg struct { Time string `json:"time"` // Timestamp - FromSessionID string `json:"sessionID"` // Session ID of client that emits this event + FromSessionID string `json:"sessionID"` // Session ID of client who produce this event Type string `json:"type"` // Data type Data interface{} `json:"data"` // Data } @@ -92,3 +96,20 @@ func (e *EventMsg) DecodeProjectConfig() (ProjectConfig, error) { } return p, err } + +// DecodeSDKMsg Helper to decode Data field type SDKManagementMsg +func (e *EventMsg) DecodeSDKMsg() (SDKManagementMsg, error) { + var err error + s := SDKManagementMsg{} + switch e.Type { + case EVTSDKInstall, EVTSDKRemove: + 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 +}