https://github.com/coderyi/eventbus
A lightweight event bus for C++
https://github.com/coderyi/eventbus
Last synced: 10 months ago
JSON representation
A lightweight event bus for C++
- Host: GitHub
- URL: https://github.com/coderyi/eventbus
- Owner: coderyi
- License: mit
- Created: 2018-09-14T07:00:20.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-09-14T07:03:59.000Z (almost 8 years ago)
- Last Synced: 2025-04-06T05:42:07.574Z (over 1 year ago)
- Language: C++
- Homepage:
- Size: 4.88 KB
- Stars: 16
- Watchers: 3
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE.txt
Awesome Lists containing this project
README
EventBus是一种发布/订阅模式的框架,主要用于解耦。可以看一下[greenrobot](https://github.com/greenrobot/EventBus)的图

EventBus的优点是基本没有依赖关系,module间通信只需要知道事件名字就可以,是我个人比较推荐的。
示例
```
#include "EventBus.h"
#include
void foo(EventBus::BaseMessage *i)
{
EventBus::Message *j = static_cast*>(i);
std::cout<<*j->getData() << std::endl;
}
int main()
{
EventBus::Bus b;
b.addListener("hello", foo);
delete b.sendMessage(new EventBus::Message("hello", new std::string("Hello world !")));
return 0;
}
```