/README.md (b6bc373481c1b1214c4aed468a5d82f1963c8a8f) (2073 bytes) (mode 100644) (type blob)
# ohm
Local message broker
## Interface
```
#pragma once
#include <functional>
#include <map>
#include <memory>
#include <set>
#include <lib/dynamo/src/interface.h>
namespace om636 {
namespace control {
template <typename T, typename... U>
class Emitter {
public:
typedef T event_type;
typedef std::function<void(U...)> callback_type;
typedef std::shared_ptr<callback_type> listener_type;
virtual ~Emitter() = default;
virtual listener_type on(event_type, callback_type) = 0;
virtual listener_type once(event_type, callback_type) = 0;
virtual void interupt(event_type, U...) = 0;
};
template <typename T, typename... U>
class Quemitter : public Emitter<T, U...> {
public:
typedef Emitter<T, U...> base_type;
using typename base_type::callback_type;
using typename base_type::event_type;
using typename base_type::listener_type;
virtual ~Quemitter() = default;
virtual void emit(event_type, U...) = 0;
};
template <typename T, typename... U>
std::shared_ptr<Emitter<T, U...>> make_emitter();
template <typename T, typename... U>
std::shared_ptr<Emitter<T, U...>> make_quemitter();
} //control
} // om636
```
## Examples
### Example 1
#### Source code
```
#include <iostream>
#include <tmp/src/test.h>
#include <lib/ohm/src/index.h>
int main()
{
using namespace om636::control;
using namespace std;
auto e = make_emitter<string, int>();
auto l = e->on("run", [](int v) {
cout << "run " << v << endl;
});
e->interupt("run", 4);
return 0;
}
```
#### Output
```
"run 4\n"
```
### Example 2
#### Source code
```
#include <iostream>
#include <tmp/src/test.h>
#include <lib/ohm/src/index.h>
int main()
{
using namespace om636::control;
using namespace std;
auto e = make_emitter<string, int>();
auto l = e->on("run", [](int v) {
cout << "run " << v << endl;
});
e->interupt("run", 322);
return 0;
}
```
#### Output
```
"run 322\n"
```
Mode |
Type |
Size |
Ref |
File |
100644 |
blob |
29 |
39d4789cd8b99de572602eadbc3c2d1487bbc1de |
.gitignore |
100644 |
blob |
1081 |
4d0dd94bf92b936ef572c2e1b910b54e305932fd |
LICENSE |
100644 |
blob |
2073 |
b6bc373481c1b1214c4aed468a5d82f1963c8a8f |
README.md |
100644 |
blob |
310 |
7579fbbb730a066432c0673baa548ff1e815d55b |
TODO.txt |
100644 |
blob |
143 |
64be33845f1353615206520e562eaf94356b51c6 |
ohm.json |
100644 |
blob |
450 |
e8a8cc741f149829eb82e3f66a5b3c679c5d677b |
package.json |
040000 |
tree |
- |
438c3b392c9b77c4e578c243cee0d48975047621 |
src |
040000 |
tree |
- |
bbb8c91183ec79a78a24028a117a4e2aec9cfd0c |
test |
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"
Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/mucbuc/ohm
Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/mucbuc/ohm
Clone this repository using git:
git clone git://git.rocketgit.com/user/mucbuc/ohm
You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a
merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main