-
Notifications
You must be signed in to change notification settings - Fork 0
/
eventproc.go
112 lines (94 loc) · 1.79 KB
/
eventproc.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package watched
import (
"bytes"
"time"
)
type RawEvent []byte
func (re RawEvent) PeekTime() (time.Time, error) {
return PeekTime(re)
}
func (re RawEvent) PeekEvent() (string, error) {
return PeekEvent(re)
}
func (re RawEvent) Peek() (time.Time, string, error) {
return Peek(re)
}
type StatusType int
func (st StatusType) String() string { return statNames[st] }
func ParseStatusType(s string) StatusType {
for i, n := range statNames[1:] {
if n == s {
return StatusType(i + 1)
}
}
return 0
}
const (
StatBackpack StatusType = iota + 1
StatCargo
StatFCMats
StatMarket
StatModules
StatNavRoute
StatOutfit
StatLocker
StatShipyard
StatStatus
EndStatusType
)
const (
StatBackpackName = "Backpack"
StatCargoName = "Cargo"
StatFCMatsName = "FCMaterials"
StatMarketName = "Market"
StatModulesName = "Modules"
StatNavRouteName = "NavRoute"
StatOutfitName = "Outfitting"
StatLockerName = "ShipLocker"
StatShipyardName = "Shipyard"
StatStatusName = "Status"
)
type JounalEvent struct {
File string
EventNo int
Event RawEvent
}
func (e *JounalEvent) Clone() JounalEvent {
return JounalEvent{
File: e.File,
EventNo: e.EventNo,
Event: bytes.Clone(e.Event),
}
}
type StatusEvent struct {
Type StatusType
Event RawEvent
}
func (e *StatusEvent) Clone() StatusEvent {
return StatusEvent{
Type: e.Type,
Event: bytes.Clone(e.Event),
}
}
type EventSrc struct {
Journal <-chan JounalEvent
Status <-chan StatusEvent
}
type EventRecv interface {
OnJournalEvent(e JounalEvent) error
OnStatusEvent(e StatusEvent) error
Close() error
}
var statNames = []string{
"<non-status>",
StatBackpackName,
StatCargoName,
StatFCMatsName,
StatMarketName,
StatModulesName,
StatNavRouteName,
StatOutfitName,
StatLockerName,
StatShipyardName,
StatStatusName,
}