-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathevent.go
41 lines (34 loc) · 904 Bytes
/
event.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package hsm
type EventType uint32
// The types of predefined events.
const (
EventEmpty EventType = iota
EventInit
EventEntry
EventExit
EventUser
)
// The default events(used in state transfer procedure).
// They are defined as global const for optimization.
var StdEvents = map[EventType]*StdEvent{
EventEmpty: NewStdEvent(EventEmpty),
EventInit: NewStdEvent(EventInit),
EventEntry: NewStdEvent(EventEntry),
EventExit: NewStdEvent(EventExit),
}
// Event represents the interface that every message which is dispatched
// to state machine should implements.
type Event interface {
// Returns the type of this event
Type() EventType
}
// StdEvent is the default Event implementation.
type StdEvent struct {
EventType EventType
}
func NewStdEvent(eventType EventType) *StdEvent {
return &StdEvent{eventType}
}
func (stdEvent *StdEvent) Type() EventType {
return stdEvent.EventType
}