forked from Cyinx/einx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
einx_default.go
67 lines (58 loc) · 1.53 KB
/
einx_default.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
package einx
import (
"github.com/Cyinx/einx/console"
"github.com/Cyinx/einx/event"
"github.com/Cyinx/einx/lua"
"github.com/Cyinx/einx/module"
"github.com/Cyinx/einx/network"
"github.com/Cyinx/einx/slog"
"os"
"os/signal"
)
var _einx_default = &einx{
close_chan: make(chan bool),
}
func GetModule(name string) Module {
return module.GetModule(name)
}
func NewLuaStae() *lua_state.LuaRuntime {
return lua_state.NewLuaStae()
}
func AddTcpServerMgr(m module.Module, addr string, mgr interface{}) {
m_eventer := m.(module.ModuleEventer)
tcp_server := network.NewTcpServerMgr(addr, m_eventer)
e := &event.ComponentEventMsg{}
e.MsgType = event.EVENT_COMPONENT_CREATE
e.Sender = tcp_server
e.Attach = mgr
m_eventer.PushEventMsg(e)
}
func StartTcpClientMgr(m module.Module, name string, mgr interface{}) {
m_eventer := m.(module.ModuleEventer)
tcp_client := network.NewTcpClientMgr(name, m_eventer)
e := &event.ComponentEventMsg{}
e.MsgType = event.EVENT_COMPONENT_CREATE
e.Sender = tcp_client
e.Attach = mgr
m_eventer.PushEventMsg(e)
}
func AddModuleComponent(m module.Module, c Component, mgr interface{}) {
m_eventer := m.(module.ModuleEventer)
e := &event.ComponentEventMsg{}
e.MsgType = event.EVENT_COMPONENT_CREATE
e.Sender = c
e.Attach = mgr
m_eventer.PushEventMsg(e)
}
func Run() {
go console.Run()
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, os.Kill)
sig := <-c
slog.LogWarning("einx", "einx will close down (signal: %v)", sig)
_einx_default.do_close()
}
func Close() {
_einx_default.close()
slog.Close()
}