-
Notifications
You must be signed in to change notification settings - Fork 9
Core_Events
pojol edited this page Jun 5, 2018
·
12 revisions
Event
gsf 框架的通信对象,所有Module之间的交互无论是本地还是远程都使用以下接口实现。
用于侦听其他模块发送的消息
| 参数 | |
|---|---|
| event | 需要侦听的事件ID |
| function | 消息的处理函数,返回值Args可以为空 |
代码样例
// c++
listen(tcp_make_acceptor, [&](gsf::ArgsPtr args) {
// pop args
auto _xx = args.pop_xx();
// todo
}); -- lua
listen(event, function(args)
-- pop args
_xx = args[1]
-- todo
end)向某个模块发出一个事件
| - | - |
|---|---|
| target | 目标模块ID |
| event | 事件ID |
| args | 携带的参数列表 |
代码样例
// c++
dispatch(target, event, block::make_args(...))-- lua
dispatch(target, event, args...)跨进程事件,在App::Config 中可以配置rpc消息的超时时间.
| - | - |
|---|---|
| event | 远程事件ID,他们他们需要被定义在event::distributed的区间中 |
| self_id | 自身的模块ID |
| args | 事件的参数 |
| callback | 事件的回掉函数可以为空,如果不为空则必然会返回,succ代表成功,process如果不为-1则代表有多次返回,args为返回的参数 |
代码样例
// c++
rpc(rpc_event, module_id, gsf::make_args(values ... ), [&](const gsf::ArgsPtr &args, int32_t process, bool succ) {
if (succ) {
auto _ret = args->pop_xxx();
...
}
else {
printf(args->pop_err())
}
});-- lua
rpc(rpc_event, module_id, evpack:xxx( ... ), function(res, progress, succ)
if succ == true then
dump(res) -- 展示下结构
else
logWarn("module_name", res[1])
end
end)