List of commits:
Subject Hash Author Date (UTC)
simplify interfiace f69d4f7a7c2c02125ac51ffb9d4ba41ed08f8646 mucbuc 2020-01-19 06:41:36
fix another test fd8e7fa14a4daa281e7fbcec875bfe56ce39e400 mucbuc 2020-01-18 22:42:40
working on tests 1b57cbb4e806eda21565dc8bd7e7fe7ff1cb5fff mucbuc 2020-01-18 22:36:15
fix test 8b364e739d1e12cd77b9f63efb0a245a75e695df mucbuc 2020-01-18 21:49:21
fix emit once 71aba1ef472aa23c9c9a8529b5258599a6289c16 mucbuc 2020-01-18 21:41:03
remove agentlifetime test ce0fba661c6110fc050203a1a8f9fedf39258615 mucbuc 2020-01-18 11:25:44
emit with arg passes 1b2288e8472b749c513120c441397a77298ab0b7 mucbuc 2020-01-17 10:58:28
dynamo update 7082792be9aa3ccb56b0afbddf58bdf468d56030 mucbuc 2020-01-17 05:32:03
circuit 9877e777b93a54d396248ad449f6ba5abf324733 mucbuc 2020-01-17 04:22:05
dynamo v2dev 15f474b5a627558c230b2fe96c40fb5c68a176d0 mucbuc 2020-01-17 04:21:40
research 47ce3a71d001f2aea7af852673b42b83f20be4dd Ubuntu 2019-12-22 17:19:57
working on test b646f535e229ff57b421f0bee0570c8a4bda76a9 Ubuntu 2019-12-21 13:20:34
emit with args 81cc2a4373cb92a07ba7acbab65ebabceb826dc0 Ubuntu 2019-12-21 06:40:24
format 1192aea1b3bf9b400e02a11152a38e5dfc6b7ad6 Ubuntu 2019-12-21 06:27:42
todo ce69f800504f9e5c643115b9ca887705dafafde3 Ubuntu 2019-12-18 07:43:15
format e59b4ae5d0286ba6766e66427996f8ccab4eff0e Ubuntu 2019-12-18 07:38:21
redo interface 3dd5822c6288ad004d1ec45e37a6f63d361aff39 Ubuntu 2019-12-18 07:38:11
temp test 54800db7dbd02d7070f5018abd27bea261bd9097 Ubuntu 2019-12-18 07:07:07
cleanup test 58f12d14f6db17e0916b115f470f87393e1ebce6 Ubuntu 2019-12-15 14:52:15
fix build error 51fcd8e612a8e89cf6ef2c94cfb82b664b532313 mucbuc 2019-11-29 06:49:34
Commit f69d4f7a7c2c02125ac51ffb9d4ba41ed08f8646 - simplify interfiace
Author: mucbuc
Author date (UTC): 2020-01-19 06:41
Committer name: mucbuc
Committer date (UTC): 2020-01-19 06:41
Parent(s): fd8e7fa14a4daa281e7fbcec875bfe56ce39e400
Signing key:
Tree: 4c25bad690c3f5c1030935ee5762300bb35e2fa1
File Lines added Lines deleted
src/emitter_impl.h 0 3
src/emitter_impl.hxx 0 8
src/interface.h 0 3
test/emit_once.json 0 9
test/once_while_emit.json 0 9
test/once_while_emit_recursive.json 0 9
test/src/dispatch_logic.cpp 17 35
test/src/emit_once.cpp 0 33
test/src/emit_while_emit.cpp 6 2
test/src/emit_with_arg.cpp 1 1
test/src/emit_with_args.cpp 1 1
test/src/modify_while_traversal.cpp 17 54
test/src/on_while_emit.cpp 1 1
test/src/once_while_emit.cpp 0 36
test/src/once_while_emit_recursive.cpp 0 32
test/tests.json 1 5
File src/emitter_impl.h changed (mode: 100644) (index 865c00d..403b598)
... ... namespace control {
20 20 using typename base_type::listener_type; using typename base_type::listener_type;
21 21
22 22 listener_type on(event_type, callback_type) override; listener_type on(event_type, callback_type) override;
23 listener_type once(event_type, callback_type) override;
24
25 23 void interupt(event_type, U...) override; void interupt(event_type, U...) override;
26 24
27 25 private: private:
 
... ... namespace control {
29 27 typedef std::map<event_type, batch_type> map_type; typedef std::map<event_type, batch_type> map_type;
30 28
31 29 map_type m_repeat; map_type m_repeat;
32 map_type m_once;
33 30 }; };
34 31 } //control } //control
35 32 } // om636 } // om636
File src/emitter_impl.hxx changed (mode: 100644) (index dfa9d36..3d316ac)
... ... namespace control {
8 8 return m_repeat[e].hook(c); return m_repeat[e].hook(c);
9 9 } }
10 10
11 /////////////////////////////////////////////////////////////////////////////////////
12 template <typename T, typename... U>
13 auto EmitterImpl<T, U...>::once(event_type e, callback_type c) -> listener_type
14 {
15 return m_once[e].hook(c);
16 }
17
18 11 ///////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////
19 12 template <typename T, typename... U> template <typename T, typename... U>
20 13 void EmitterImpl<T, U...>::interupt(event_type e, U... arg) void EmitterImpl<T, U...>::interupt(event_type e, U... arg)
21 14 { {
22 m_once[e].invoke_once(arg...);
23 15 m_repeat[e].invoke(arg...); m_repeat[e].invoke(arg...);
24 16 } }
25 17
File src/interface.h changed (mode: 100644) (index 026c834..c7833a5)
... ... namespace control {
17 17 typedef std::shared_ptr<callback_type> listener_type; typedef std::shared_ptr<callback_type> listener_type;
18 18
19 19 virtual ~Emitter() = default; virtual ~Emitter() = default;
20
21 20 virtual listener_type on(event_type, callback_type) = 0; virtual listener_type on(event_type, callback_type) = 0;
22 virtual listener_type once(event_type, callback_type) = 0;
23
24 21 virtual void interupt(event_type, U...) = 0; virtual void interupt(event_type, U...) = 0;
25 22 }; };
26 23
File test/emit_once.json deleted (index e7915a7..0000000)
1 {
2 "include":[
3 "lib/ohm/ohm.json"
4 ],
5 "sources": [
6 "src/emit_once.cpp",
7 "src/emitter_fwd.h"
8 ]
9 }
File test/once_while_emit.json deleted (index ea7764d..0000000)
1 {
2 "include":[
3 "lib/ohm/ohm.json"
4 ],
5 "sources": [
6 "src/once_while_emit.cpp",
7 "src/emitter_fwd.h"
8 ]
9 }
File test/once_while_emit_recursive.json deleted (index 8ea14d7..0000000)
1 {
2 "include":[
3 "lib/ohm/ohm.json"
4 ],
5 "sources": [
6 "src/once_while_emit_recursive.cpp",
7 "src/emitter_fwd.h"
8 ]
9 }
File test/src/dispatch_logic.cpp changed (mode: 100644) (index c573342..ff5bf23)
1 1 #include <iostream> #include <iostream>
2 #include <lib/ohm/src/quemitter.h>
3 #include <tmp/src/test.h>
4 2 #include <vector> #include <vector>
5 3
6 using namespace std;
7 using namespace om636;
8 /////////////////////////////////////////////////////////////////
9 template <template <class, class> class T>
10 void check_dispatch_logic()
4 #include <tmp/src/test.h>
5
6 #include <lib/ohm/src/emitter_impl.h>
7
8 int main()
11 9 { {
12 typedef T<string, function<void()>> emitter_type;
10 using namespace std;
11 using namespace om636;
12 using namespace control;
13
14 typedef EmitterImpl<string> emitter_type;
13 15 typedef typename emitter_type::listener_type listener_type; typedef typename emitter_type::listener_type listener_type;
14 16
15 17 static unsigned trap(0); static unsigned trap(0);
 
... ... void check_dispatch_logic()
27 29 trap = 0; trap = 0;
28 30
29 31 // check dead agent // check dead agent
30 emitter.once(event, tester::trigger_trap);
31 emitter.emit(event);
32 emitter.on(event, tester::trigger_trap);
33 emitter.interupt(event);
32 34 ASSERT(trap == 0); ASSERT(trap == 0);
33 35
34 // check once
35 listeners.push_back(emitter.once(event, tester::trigger_trap));
36 emitter.emit(event);
37 ASSERT(trap == 1);
38 emitter.emit(event);
39 ASSERT(trap == 1);
40
41 36 // check on // check on
42 37 listeners.push_back(emitter.on(event, tester::trigger_trap)); listeners.push_back(emitter.on(event, tester::trigger_trap));
43 emitter.emit(event);
38 emitter.interupt(event);
39 ASSERT(trap == 1);
40 emitter.interupt(event);
44 41 ASSERT(trap == 2); ASSERT(trap == 2);
45 emitter.emit(event);
46 ASSERT(trap == 3);
47 42
48 43 // check duplicate // check duplicate
49 44 listeners.push_back(emitter.on(event, tester::trigger_trap)); listeners.push_back(emitter.on(event, tester::trigger_trap));
50 emitter.emit(event);
51 ASSERT(trap == 5);
52
53 FOOTER;
54 }
55
56 template <class T, class U>
57 using QueuedEmitter = om636::control::Quemitter<T, U>;
58
59 int main()
60 {
61 using namespace std;
62
63 check_dispatch_logic<om636::control::Emitter>();
64 check_dispatch_logic<QueuedEmitter>();
45 emitter.interupt(event);
46 ASSERT(trap == 4);
65 47
66 48 return 0; return 0;
67 49 } }
File test/src/emit_once.cpp deleted (index 9df782b..0000000)
1 #include <tmp/src/test.h>
2
3 #include <iostream>
4 #include <lib/ohm/src/emitter_impl.h>
5
6 using namespace std;
7 using namespace om636;
8 using namespace control;
9
10 int main()
11 {
12 typedef EmitterImpl<string, int> emitter_type;
13 emitter_type e;
14
15 unsigned counter(0);
16
17 auto l(e.once("hello", [&](int) {
18 ++counter;
19 }));
20
21 auto k(e.once("allo", [&](int) {
22 ++counter;
23 }));
24
25 e.interupt("hello", 0);
26 e.interupt("hello", 0);
27 e.interupt("allo", 9);
28 e.interupt("allo", 9);
29
30 ASSERT(counter == 2 && "emit once");
31
32 return 0;
33 }
File test/src/emit_while_emit.cpp changed (mode: 100644) (index 3cf8843..cc80777)
... ... using namespace std;
10 10
11 11 int main() int main()
12 12 { {
13 om636::control::EmitterImpl<string> e;
13 typedef om636::control::EmitterImpl<string> emitter_type;
14 typedef typename emitter_type::listener_type listener_type;
15
16 emitter_type e;
14 17 size_t counter(0); size_t counter(0);
15 18
16 auto p(e.once("e", [&]() {
19 listener_type p(e.on("e", [&]() {
20 p.reset();
17 21 ++counter; ++counter;
18 22 e.interupt("e"); e.interupt("e");
19 23 })); }));
File test/src/emit_with_arg.cpp changed (mode: 100644) (index 9bd79f4..e7af546)
... ... int main()
8 8 auto f = [&](unsigned i) { sum += i; }; auto f = [&](unsigned i) { sum += i; };
9 9
10 10 om636::control::EmitterImpl<std::string, unsigned> e; om636::control::EmitterImpl<std::string, unsigned> e;
11 auto p(e.once("e", f));
11 auto p(e.on("e", f));
12 12 auto q(e.on("e", f)); auto q(e.on("e", f));
13 13 e.interupt("e", 7); e.interupt("e", 7);
14 14
File test/src/emit_with_args.cpp changed (mode: 100644) (index 2a0b464..da2846d)
... ... int main()
8 8 auto f = [&](unsigned i, unsigned j) { sum += i * j; }; auto f = [&](unsigned i, unsigned j) { sum += i * j; };
9 9
10 10 om636::control::EmitterImpl<std::string, unsigned, unsigned> e; om636::control::EmitterImpl<std::string, unsigned, unsigned> e;
11 auto p(e.once("e", f));
11 auto p(e.on("e", f));
12 12 auto q(e.on("e", f)); auto q(e.on("e", f));
13 13 e.interupt("e", 7, 3); e.interupt("e", 7, 3);
14 14
File test/src/modify_while_traversal.cpp changed (mode: 100644) (index 5827cc1..50d4107)
2 2 #include <iostream> #include <iostream>
3 3 #include <vector> #include <vector>
4 4
5 #include <lib/ohm/src/quemitter.h>
6 5 #include <tmp/src/test.h> #include <tmp/src/test.h>
7 6
8 using namespace std;
9 using namespace om636;
10 /////////////////////////////////////////////////////////////////
11 template <template <class, class> class T>
12 void check_modify_while_traversal()
7 #include <lib/ohm/src/emitter_impl.h>
8
9 int main()
13 10 { {
14 typedef T<string, function<void()>> emitter_type;
11
12 using namespace std;
13 using namespace om636;
14 using namespace control;
15
16 typedef EmitterImpl<string> emitter_type;
15 17 typedef typename emitter_type::listener_type listener_type; typedef typename emitter_type::listener_type listener_type;
16 18
17 19 static emitter_type emitter; static emitter_type emitter;
 
... ... void check_modify_while_traversal()
22 24 { {
23 25 ++trap; ++trap;
24 26 } }
25
26 static void remove()
27 {
28 ++trap;
29 emitter.removeListeners(event);
30 }
31
32 static void removeAll()
33 {
34 ++trap;
35 emitter.removeAllListeners();
36 }
37 27 }; };
38 28
39 29 vector<listener_type> listeners; vector<listener_type> listeners;
40 30
41 // test remove while traverse
42 listeners.push_back(emitter.on(event, tester::remove));
43 listeners.push_back(emitter.on(event, tester::remove));
44 listeners.push_back(emitter.once(event, tester::remove));
45 emitter.emit(event);
46 ASSERT(trap == 1);
47
48 // test removeAll while traverse
49 listeners.push_back(emitter.on(event, tester::removeAll));
50 listeners.push_back(emitter.on(event, tester::removeAll));
51 listeners.push_back(emitter.once(event, tester::removeAll));
52 emitter.emit(event);
53 ASSERT(trap == 2);
54
55 31 // test insert while traverse // test insert while traverse
56 listeners.push_back(emitter.once(event, [&]() {
32 listeners.push_back(emitter.on(event, [&]() {
57 33 listeners.push_back(emitter.on(event, tester::trigger_trap)); listeners.push_back(emitter.on(event, tester::trigger_trap));
58 listeners.push_back(emitter.once(event, tester::trigger_trap));
59 34 })); }));
60 emitter.emit(event);
61 ASSERT(trap == 2);
62
63 emitter.emit(event);
64 ASSERT(trap == 4);
65
66 emitter.emit(event);
67 ASSERT(trap == 5);
68
69 FOOTER;
70 }
71
72 template <class T, class U>
73 using QueuedEmitter = om636::control::Quemitter<T, U>;
35 emitter.interupt(event);
36 listeners.front().reset();
37 ASSERT(trap == 0)(trap);
74 38
75 int main()
76 {
77 using namespace std;
39 emitter.interupt(event);
40 ASSERT(trap == 1);
78 41
79 check_modify_while_traversal<om636::control::Emitter>();
80 check_modify_while_traversal<QueuedEmitter>();
42 emitter.interupt(event);
43 ASSERT(trap == 2 && "modify_while_traversau")(trap);
81 44
82 45 return 0; return 0;
83 46 } }
File test/src/on_while_emit.cpp changed (mode: 100644) (index 25d6568..e916b6a)
... ... int main()
19 19
20 20 unsigned counter(0); unsigned counter(0);
21 21
22 listeners.push_back(emitter.once("load", [&]() {
22 listeners.push_back(emitter.on("load", [&]() {
23 23 listeners.push_back(emitter.on("on", [&]() { listeners.push_back(emitter.on("on", [&]() {
24 24 ++counter; ++counter;
25 25 })); }));
File test/src/once_while_emit.cpp deleted (index 38809c1..0000000)
1
2 #include <iostream>
3 #include <vector>
4
5 #include <tmp/src/test.h>
6
7 #include <lib/ohm/src/emitter_impl.h>
8
9 int main()
10 {
11 using namespace std;
12 using namespace om636;
13 using namespace control;
14 typedef EmitterImpl<string> emitter_type;
15 typedef typename emitter_type::listener_type listener_type;
16
17 emitter_type emitter;
18 vector<listener_type> listeners;
19
20 unsigned counter(0);
21
22 listeners.push_back(emitter.once("load", [&]() {
23 listeners.push_back(emitter.once("on", [&]() {
24 ++counter;
25 }));
26
27 emitter.interupt("on");
28 }));
29
30 emitter.interupt("load");
31 emitter.interupt("on");
32
33 ASSERT(counter == 1);
34
35 return 0;
36 }
File test/src/once_while_emit_recursive.cpp deleted (index 5ae623f..0000000)
1
2 #include <iostream>
3 #include <vector>
4
5 #include <tmp/src/test.h>
6
7 #include <lib/ohm/src/emitter_impl.h>
8
9 int main()
10 {
11 using namespace std;
12 using namespace om636;
13 using namespace control;
14
15 typedef EmitterImpl<string> emitter_type;
16 typedef typename emitter_type::listener_type listener_type;
17
18 emitter_type emitter;
19 vector<listener_type> listeners;
20
21 unsigned counter(0);
22
23 listeners.push_back(emitter.once("on", [&]() {
24 ++counter;
25 emitter.interupt("on");
26 }));
27
28 emitter.interupt("on");
29
30 ASSERT(counter == 1 && "check_once_while_emit_recursive");
31 return 0;
32 }
File test/tests.json changed (mode: 100644) (index 984c27a..70c5684)
1 1 { {
2 2 "tests":[ "tests":[
3 3 "concurrent.json", "concurrent.json",
4 "emit_once.json",
5 4 "dispatch_logic.json", "dispatch_logic.json",
6 "emit_while_emit.json",
7 5 "emit_with_arg.json", "emit_with_arg.json",
8 6 "emit_with_args.json", "emit_with_args.json",
9 7 "on.json", "on.json",
10 8 "modify_while_traversal.json", "modify_while_traversal.json",
11 "on_while_emit.json",
12 "once_while_emit.json",
13 "once_while_emit_recursive.json"
9 "on_while_emit.json"
14 10 ] } ] }
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