go_dreamfactory/modules/gateway/module.go
2022-05-31 18:47:34 +08:00

68 lines
2.0 KiB
Go

package gateway
import (
"go_dreamfactory/comm"
"go_dreamfactory/modules"
"github.com/liwei1dao/lego/base"
"github.com/liwei1dao/lego/core"
"github.com/liwei1dao/lego/sys/log"
)
func NewModule() core.IModule {
m := new(Gateway)
return m
}
type Gateway struct {
modules.ModuleBase
service base.IRPCXService
wsservice_comp *WSService_Comp
agentmgr_comp *AgentMgr_Comp
}
func (this *Gateway) GetType() core.M_Modules {
return comm.SM_GateModule
}
func (this *Gateway) NewOptions() (options core.IModuleOptions) {
return new(Options)
}
func (this *Gateway) Service() base.IRPCXService {
return this.service
}
func (this *Gateway) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) {
err = this.ModuleBase.Init(service, module, options)
this.service = service.(base.IRPCXService)
return
}
func (this *Gateway) Start() (err error) {
this.service.RegisterFunctionName(string(comm.Rpc_GatewayAgentBuild), this.agentmgr_comp.Build)
this.service.RegisterFunctionName(string(comm.Rpc_GatewayAgentUnBuild), this.agentmgr_comp.UnBuild)
this.service.RegisterFunctionName(string(comm.Rpc_GatewayAgentSendMsg), this.agentmgr_comp.SendMsgToAgent)
this.service.RegisterFunctionName(string(comm.Rpc_GatewayAgentClose), this.agentmgr_comp.CloseAgent)
err = this.ModuleBase.Start()
return
}
func (this *Gateway) OnInstallComp() {
this.ModuleBase.OnInstallComp()
this.agentmgr_comp = this.RegisterComp(new(AgentMgr_Comp)).(*AgentMgr_Comp)
this.wsservice_comp = this.RegisterComp(new(WSService_Comp)).(*WSService_Comp)
}
//有新的连接对象进入
func (this *Gateway) Connect(a IAgent) {
log.Debugf("[Module.Gateway] have new connect:Ip[%s] SessionId:[%s]", a.IP(), a.SessionId())
this.agentmgr_comp.Connect(a)
}
//有新的连接对象进入
func (this *Gateway) DisConnect(a IAgent) {
log.Debugf("[Module.Gateway] have disConnect:Ip[%s] SessionId:[%s] uid:[%d]", a.IP(), a.SessionId(), a.UserId())
this.agentmgr_comp.DisConnect(a)
}