-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmpost.go
More file actions
55 lines (42 loc) · 1.05 KB
/
mpost.go
File metadata and controls
55 lines (42 loc) · 1.05 KB
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
package mpost
import (
"context"
"github.com/hard-soft-ware/mpost/acceptor"
"github.com/hard-soft-ware/mpost/command"
"github.com/hard-soft-ware/mpost/enum"
"github.com/hard-soft-ware/mpost/hook"
"github.com/hard-soft-ware/mpost/serial"
)
////////////////////////////////////
type MpostObj struct {
port *serial.SerialStruct
dataLinkLayer *dataObj
coupon *CouponObj
messageQueue chan *messageObj
replyQueue chan []byte
DocType enum.DocumentType
Log *LogObj
Method *MethodsObj
Ctx context.Context
CtxCancel context.CancelFunc
}
func New() *MpostObj {
obj := MpostObj{
messageQueue: make(chan *messageObj, 1),
replyQueue: make(chan []byte, 1),
Log: newLog(),
}
acceptor.Clean()
command.Clean()
hook.Clean()
obj.Method = obj.newMethods()
obj.Ctx, obj.CtxCancel = context.WithCancel(context.Background())
hook.Raise.Log = func(eventType enum.EventType, i int) {
obj.Log.Event(eventType, i)
}
return &obj
}
//
func (a *MpostObj) AddHook(ev enum.EventType, h func(int)) {
hook.Add(ev, h)
}