Skip to content

Commit dec1341

Browse files
committed
[common] Add event.DeviceEvent
1 parent 955ac46 commit dec1341

1 file changed

Lines changed: 86 additions & 0 deletions

File tree

common/event/deviceevent.go

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
* === This file is part of ALICE O² ===
3+
*
4+
* Copyright 2018 CERN and copyright holders of ALICE O².
5+
* Author: Teo Mrnjavac <teo.mrnjavac@cern.ch>
6+
*
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
*
20+
* In applying this license CERN does not waive the privileges and
21+
* immunities granted to it by virtue of its status as an
22+
* Intergovernmental Organization or submit itself to any jurisdiction.
23+
*/
24+
25+
package event
26+
27+
import (
28+
"github.com/AliceO2Group/Control/executor/protos"
29+
"github.com/mesos/mesos-go/api/v1/lib"
30+
)
31+
32+
type DeviceEventOrigin struct {
33+
AgentId mesos.AgentID `json:"agentId"`
34+
ExecutorId mesos.ExecutorID `json:"executorId"`
35+
TaskId mesos.TaskID `json:"taskId"`
36+
}
37+
38+
type DeviceEvent interface {
39+
GetName() string
40+
GetOrigin() DeviceEventOrigin
41+
GetType() pb.DeviceEventType
42+
}
43+
44+
type DeviceEventBase struct {
45+
Type pb.DeviceEventType `json:"type"`
46+
Origin DeviceEventOrigin `json:"origin"`
47+
MessageType string `json:"_messageType"`
48+
}
49+
50+
func (b *DeviceEventBase) GetOrigin() DeviceEventOrigin {
51+
if b == nil {
52+
return DeviceEventOrigin{}
53+
}
54+
return b.Origin
55+
}
56+
57+
func (b *DeviceEventBase) GetType() pb.DeviceEventType {
58+
if b == nil {
59+
return pb.DeviceEventType_NULL_DEVICE_EVENT
60+
}
61+
return b.Type
62+
}
63+
64+
func NewDeviceEvent(origin DeviceEventOrigin, t pb.DeviceEventType) (de DeviceEvent) {
65+
switch t {
66+
case pb.DeviceEventType_END_OF_DATA:
67+
de = &EndOfData{
68+
DeviceEventBase: DeviceEventBase{
69+
Type: t,
70+
Origin: origin,
71+
MessageType: "DeviceEvent",
72+
},
73+
}
74+
case pb.DeviceEventType_NULL_DEVICE_EVENT:
75+
de = nil
76+
}
77+
return de
78+
}
79+
80+
type EndOfData struct {
81+
DeviceEventBase
82+
}
83+
84+
func (e *EndOfData) GetName() string {
85+
return "END_OF_DATA"
86+
}

0 commit comments

Comments
 (0)