This commit is contained in:
azw 2023-08-13 10:56:23 +08:00
parent f38d0d1419
commit 2b5498f808
3 changed files with 30 additions and 15 deletions

41
app.go
View File

@ -9,8 +9,18 @@ import (
"q5" "q5"
) )
type F5App interface { type App interface {
GetPkgName() string GetPkgName() string
NewUuid() int64
GetInstanceId() int32
GetNodeId() int32
GetZoneId() int32
HasFlag(int32) bool
AddIMMsg(uint16, q5.Args)
RegisterIMMsgHandle(uint16, func(uint16,q5.Args))
NotifyLoopCond()
NowUnix() int64
NowUnixMilli() int64
} }
type UserApp interface { type UserApp interface {
@ -21,8 +31,9 @@ type UserApp interface {
} }
type app struct { type app struct {
nodeId int zoneId int32
instanceId int nodeId int32
instanceId int32
terminated bool terminated bool
pkgName string pkgName string
flags map[int32]int32 flags map[int32]int32
@ -37,7 +48,7 @@ type app struct {
chGoLoopWait chan int64 chGoLoopWait chan int64
nowTime time.Time nowTime time.Time
nowUnixNano int64 nowUnixNano int64
imMsgHandlers [1024]func(int16, q5.Args) imMsgHandlers [1024]func(uint16, q5.Args)
maxRunDelay int64 maxRunDelay int64
maxScheduleTime int64 maxScheduleTime int64
userApp UserApp userApp UserApp
@ -59,8 +70,8 @@ func (this *app) init(userApp UserApp) {
_SysLog.Init() _SysLog.Init()
_TgLog = new(TGLog_) _TgLog = new(TGLog_)
_TgLog.Init() _TgLog.Init()
flag.IntVar(&this.nodeId, "n", 0, "node id") //flag.IntVar(&this.nodeId, "n", 0, "node id")
flag.IntVar(&this.instanceId, "i", 0, "instance id") //flag.IntVar(&this.instanceId, "i", 0, "instance id")
flag.Parse() flag.Parse()
this.loopCond = sync.NewCond(new(sync.Mutex)) this.loopCond = sync.NewCond(new(sync.Mutex))
this.chGoLoopTimerExit = make(chan int) this.chGoLoopTimerExit = make(chan int)
@ -104,19 +115,23 @@ func (this *app) NewUuid() int64 {
return 0 return 0
} }
func (this *app) GetInstanceId() uint32 { func (this *app) GetInstanceId() int32 {
return uint32(this.instanceId) return this.instanceId
} }
func (this *app) GetNodeId() uint32 { func (this *app) GetNodeId() int32 {
return uint32(this.nodeId) return this.nodeId
}
func (this *app) GetZoneId() int32 {
return this.nodeId
} }
func (this *app) GetPkgName() string { func (this *app) GetPkgName() string {
return this.pkgName return this.pkgName
} }
func (this *app) SetPkgName(pkgName string) { func (this *app) setPkgName(pkgName string) {
this.pkgName = pkgName this.pkgName = pkgName
} }
@ -125,7 +140,7 @@ func (this *app) HasFlag(flag int32) bool {
return ok return ok
} }
func (this *app) AddIMMsg(msgId int16, params q5.Args) { func (this *app) AddIMMsg(msgId uint16, params q5.Args) {
p := new(IMMsgNode) p := new(IMMsgNode)
p.msgId = msgId p.msgId = msgId
p.params = params p.params = params
@ -143,7 +158,7 @@ func (this *app) AddIMMsg(msgId int16, params q5.Args) {
this.loopCond.Broadcast() this.loopCond.Broadcast()
} }
func (this *app) RegisterIMMsgHandle(msgId int16, handle func(int16,q5.Args)) { func (this *app) RegisterIMMsgHandle(msgId uint16, handle func(uint16,q5.Args)) {
this.imMsgHandlers[msgId] = handle this.imMsgHandlers[msgId] = handle
} }

View File

@ -19,7 +19,7 @@ func TgLog() *TGLog_ {
return _TgLog return _TgLog
} }
func GetApp() F5App { func GetApp() App {
return _app return _app
} }

View File

@ -16,7 +16,7 @@ type MsgNode struct {
} }
type IMMsgNode struct { type IMMsgNode struct {
msgId int16 msgId uint16
params q5.Args params q5.Args
next *IMMsgNode next *IMMsgNode
} }