File src/emitter_impl.h changed (mode: 100644) (index fbd4ac5..ae5d6f7) |
5 |
5 |
#include <memory> |
#include <memory> |
6 |
6 |
#include <set> |
#include <set> |
7 |
7 |
|
|
8 |
|
#include "interface.h" |
|
|
8 |
|
#include "interface.h" |
9 |
9 |
|
|
10 |
10 |
namespace om636 { |
namespace om636 { |
11 |
11 |
namespace control { |
namespace control { |
12 |
|
template <typename T, typename ... U> |
|
13 |
|
class EmitterImpl : Emitter<T, U ...> |
|
14 |
|
{ |
|
|
12 |
|
template <typename T, typename... U> |
|
13 |
|
class EmitterImpl : Emitter<T, U...> { |
15 |
14 |
public: |
public: |
16 |
15 |
typedef T event_type; |
typedef T event_type; |
17 |
16 |
typedef std::function<void(U...)> callback_type; |
typedef std::function<void(U...)> callback_type; |
|
... |
... |
namespace control { |
24 |
23 |
void removeListeners(event_type) override; |
void removeListeners(event_type) override; |
25 |
24 |
void removeAllListeners() override; |
void removeAllListeners() override; |
26 |
25 |
|
|
27 |
|
void interupt(event_type, U ...) override; |
|
28 |
|
private: |
|
|
26 |
|
void interupt(event_type, U...) override; |
|
27 |
|
|
|
28 |
|
private: |
29 |
29 |
typedef std::map<event_type, batch_type> map_type; |
typedef std::map<event_type, batch_type> map_type; |
30 |
30 |
void kill_all(map_type&); |
void kill_all(map_type&); |
31 |
31 |
|
|
File src/emitter_impl.hxx changed (mode: 100644) (index 50dae9f..8b1bc11) |
... |
... |
namespace om636 { |
2 |
2 |
namespace control { |
namespace control { |
3 |
3 |
|
|
4 |
4 |
///////////////////////////////////////////////////////////////////////////////////// |
///////////////////////////////////////////////////////////////////////////////////// |
5 |
|
template <typename T, typename ... U> |
|
6 |
|
auto EmitterImpl<T, U ...>::on(event_type e, callback_type c) -> listener_type |
|
|
5 |
|
template <typename T, typename... U> |
|
6 |
|
auto EmitterImpl<T, U...>::on(event_type e, callback_type c) -> listener_type |
7 |
7 |
{ |
{ |
8 |
8 |
return m_repeat[e].hook(c); |
return m_repeat[e].hook(c); |
9 |
9 |
} |
} |
10 |
10 |
|
|
11 |
11 |
///////////////////////////////////////////////////////////////////////////////////// |
///////////////////////////////////////////////////////////////////////////////////// |
12 |
|
template <typename T, typename ... U> |
|
13 |
|
auto EmitterImpl<T, U ...>::once(event_type e, callback_type c) -> listener_type |
|
|
12 |
|
template <typename T, typename... U> |
|
13 |
|
auto EmitterImpl<T, U...>::once(event_type e, callback_type c) -> listener_type |
14 |
14 |
{ |
{ |
15 |
15 |
return m_once[e].hook(c); |
return m_once[e].hook(c); |
16 |
16 |
} |
} |
17 |
17 |
|
|
18 |
18 |
///////////////////////////////////////////////////////////////////////////////////// |
///////////////////////////////////////////////////////////////////////////////////// |
19 |
|
template <typename T, typename ... U> |
|
20 |
|
void EmitterImpl<T, U ...>::removeListeners(event_type e) |
|
|
19 |
|
template <typename T, typename... U> |
|
20 |
|
void EmitterImpl<T, U...>::removeListeners(event_type e) |
21 |
21 |
{ |
{ |
22 |
22 |
m_once[e].unhook(); |
m_once[e].unhook(); |
23 |
23 |
m_repeat[e].unhook(); |
m_repeat[e].unhook(); |
24 |
24 |
} |
} |
25 |
25 |
|
|
26 |
26 |
///////////////////////////////////////////////////////////////////////////////////// |
///////////////////////////////////////////////////////////////////////////////////// |
27 |
|
template <typename T, typename ... U> |
|
28 |
|
void EmitterImpl<T, U ...>::removeAllListeners() |
|
|
27 |
|
template <typename T, typename... U> |
|
28 |
|
void EmitterImpl<T, U...>::removeAllListeners() |
29 |
29 |
{ |
{ |
30 |
30 |
kill_all(m_once); |
kill_all(m_once); |
31 |
31 |
kill_all(m_repeat); |
kill_all(m_repeat); |
32 |
32 |
} |
} |
33 |
33 |
|
|
34 |
34 |
///////////////////////////////////////////////////////////////////////////////////// |
///////////////////////////////////////////////////////////////////////////////////// |
35 |
|
template <typename T, typename ... U> |
|
36 |
|
void EmitterImpl<T, U ...>::interupt(event_type e, U ... arg) |
|
|
35 |
|
template <typename T, typename... U> |
|
36 |
|
void EmitterImpl<T, U...>::interupt(event_type e, U... arg) |
37 |
37 |
{ |
{ |
38 |
38 |
m_once[e].merge_added_elements(); |
m_once[e].merge_added_elements(); |
39 |
39 |
m_repeat[e].merge_added_elements(); |
m_repeat[e].merge_added_elements(); |
40 |
40 |
|
|
41 |
|
utils::process_and_kill(m_once[e].elements(), arg ... ); |
|
42 |
|
utils::process(m_repeat[e].elements(), arg ... ); |
|
|
41 |
|
utils::process_and_kill(m_once[e].elements(), arg...); |
|
42 |
|
utils::process(m_repeat[e].elements(), arg...); |
43 |
43 |
} |
} |
44 |
44 |
|
|
45 |
45 |
///////////////////////////////////////////////////////////////////////////////////// |
///////////////////////////////////////////////////////////////////////////////////// |
46 |
|
template <typename T, typename ... U> |
|
47 |
|
void EmitterImpl<T, U ...>::kill_all(map_type& map) |
|
|
46 |
|
template <typename T, typename... U> |
|
47 |
|
void EmitterImpl<T, U...>::kill_all(map_type& map) |
48 |
48 |
{ |
{ |
49 |
49 |
for_each(map.begin(), map.end(), [](typename map_type::value_type& p) { |
for_each(map.begin(), map.end(), [](typename map_type::value_type& p) { |
50 |
50 |
p.second.unhook(); |
p.second.unhook(); |
File src/interface.h changed (mode: 100644) (index 30575ea..be31d9d) |
10 |
10 |
|
|
11 |
11 |
namespace om636 { |
namespace om636 { |
12 |
12 |
namespace control { |
namespace control { |
13 |
|
|
|
14 |
|
template <typename T, typename ... U> |
|
|
13 |
|
|
|
14 |
|
template <typename T, typename... U> |
15 |
15 |
class Emitter { |
class Emitter { |
16 |
16 |
public: |
public: |
17 |
17 |
typedef T event_type; |
typedef T event_type; |
|
... |
... |
namespace control { |
27 |
27 |
virtual void removeListeners(event_type) = 0; |
virtual void removeListeners(event_type) = 0; |
28 |
28 |
virtual void removeAllListeners() = 0; |
virtual void removeAllListeners() = 0; |
29 |
29 |
|
|
30 |
|
virtual void interupt(event_type, U ...) = 0; |
|
|
30 |
|
virtual void interupt(event_type, U...) = 0; |
31 |
31 |
}; |
}; |
32 |
|
|
|
33 |
|
template <typename T, typename ... U> |
|
34 |
|
class Quemitter : public Emitter<T, U ...> |
|
35 |
|
{ |
|
36 |
|
|
|
|
32 |
|
|
|
33 |
|
template <typename T, typename... U> |
|
34 |
|
class Quemitter : public Emitter<T, U...> { |
|
35 |
|
|
37 |
36 |
public: |
public: |
38 |
|
typedef Emitter<T, U ...> base_type; |
|
39 |
|
using typename base_type::event_type; |
|
40 |
|
using typename base_type::callback_type; |
|
|
37 |
|
typedef Emitter<T, U...> base_type; |
41 |
38 |
using typename base_type::batch_type; |
using typename base_type::batch_type; |
|
39 |
|
using typename base_type::callback_type; |
|
40 |
|
using typename base_type::event_type; |
42 |
41 |
using typename base_type::listener_type; |
using typename base_type::listener_type; |
43 |
42 |
|
|
44 |
43 |
virtual ~Quemitter() = default; |
virtual ~Quemitter() = default; |
45 |
|
virtual void emit(event_type, U ...) = 0; |
|
|
44 |
|
virtual void emit(event_type, U...) = 0; |
46 |
45 |
}; |
}; |
47 |
46 |
|
|
48 |
47 |
} //control |
} //control |
File src/quemitter.h changed (mode: 100644) (index c6dd1cd..5a1be8b) |
... |
... |
namespace control { |
18 |
18 |
class Quemitter |
class Quemitter |
19 |
19 |
: public Emitter<T, U> { |
: public Emitter<T, U> { |
20 |
20 |
|
|
21 |
|
typedef P<Quemitter<T, U, P> > fbp; |
|
|
21 |
|
typedef P<Quemitter<T, U, P>> fbp; |
22 |
22 |
|
|
23 |
23 |
public: |
public: |
24 |
24 |
typedef Emitter<T, U> base_type; |
typedef Emitter<T, U> base_type; |
25 |
|
using typename base_type::event_type; |
|
26 |
25 |
using typename base_type::callback_type; |
using typename base_type::callback_type; |
|
26 |
|
using typename base_type::event_type; |
27 |
27 |
using typename base_type::listener_type; |
using typename base_type::listener_type; |
28 |
28 |
|
|
29 |
29 |
Quemitter() = default; |
Quemitter() = default; |
|
... |
... |
namespace control { |
31 |
31 |
Quemitter(const Quemitter&) = delete; |
Quemitter(const Quemitter&) = delete; |
32 |
32 |
Quemitter& operator=(const Quemitter&) = delete; |
Quemitter& operator=(const Quemitter&) = delete; |
33 |
33 |
|
|
34 |
|
template <class ... V> |
|
35 |
|
void emit(event_type, V ...); |
|
|
34 |
|
template <class... V> |
|
35 |
|
void emit(event_type, V...); |
36 |
36 |
|
|
37 |
37 |
private: |
private: |
38 |
38 |
typedef std::function<void()> function_type; |
typedef std::function<void()> function_type; |
File src/quemitter_impl.h changed (mode: 100644) (index e5ed9b0..5ce6817) |
... |
... |
namespace control { |
16 |
16 |
static void unlocked_mutex(const T&) {} |
static void unlocked_mutex(const T&) {} |
17 |
17 |
}; |
}; |
18 |
18 |
|
|
19 |
|
|
|
20 |
|
template <class T, template <typename> class P, typename ... U> |
|
|
19 |
|
template <class T, template <typename> class P, typename... U> |
21 |
20 |
class QuemitterImpl |
class QuemitterImpl |
22 |
|
: public Quemitter<T, U ...> |
|
23 |
|
{ |
|
24 |
|
typedef Quemitter<T, U ...> base_type; |
|
25 |
|
|
|
|
21 |
|
: public Quemitter<T, U...> { |
|
22 |
|
typedef Quemitter<T, U...> base_type; |
|
23 |
|
|
26 |
24 |
public: |
public: |
27 |
|
using typename base_type::event_type; |
|
28 |
25 |
using typename base_type::callback_type; |
using typename base_type::callback_type; |
|
26 |
|
using typename base_type::event_type; |
29 |
27 |
using typename base_type::listener_type; |
using typename base_type::listener_type; |
30 |
|
|
|
|
28 |
|
|
31 |
29 |
listener_type on(event_type, callback_type) override; |
listener_type on(event_type, callback_type) override; |
32 |
30 |
listener_type once(event_type, callback_type) override; |
listener_type once(event_type, callback_type) override; |
33 |
31 |
|
|
34 |
32 |
void removeListeners(event_type) override; |
void removeListeners(event_type) override; |
35 |
33 |
void removeAllListeners() override; |
void removeAllListeners() override; |
36 |
34 |
|
|
37 |
|
void interupt(event_type, U ...) override; |
|
38 |
|
void emit(event_type, U ...) override; |
|
|
35 |
|
void interupt(event_type, U...) override; |
|
36 |
|
void emit(event_type, U...) override; |
39 |
37 |
|
|
40 |
38 |
private: |
private: |
41 |
|
typedef P<QuemitterImpl<T, P, U ...> > fbp; |
|
42 |
|
typedef std::function<void()> function_type; |
|
|
39 |
|
typedef P<QuemitterImpl<T, P, U...>> fbp; |
|
40 |
|
typedef std::function<void()> function_type; |
43 |
41 |
typedef om636::queue<function_type> queue_type; |
typedef om636::queue<function_type> queue_type; |
44 |
42 |
typedef std::mutex mutex_type; |
typedef std::mutex mutex_type; |
45 |
43 |
|
|
46 |
44 |
void push_event(function_type); |
void push_event(function_type); |
47 |
|
|
|
48 |
|
EmitterImpl<T, U ...> m_reactor; |
|
|
45 |
|
|
|
46 |
|
EmitterImpl<T, U...> m_reactor; |
49 |
47 |
queue_type m_queue; |
queue_type m_queue; |
50 |
48 |
mutex_type m_mutex; |
mutex_type m_mutex; |
51 |
49 |
}; |
}; |
File src/quemitter_impl.hxx changed (mode: 100644) (index 94c636f..c8769a2) |
1 |
1 |
namespace om636 { |
namespace om636 { |
2 |
2 |
namespace control { |
namespace control { |
3 |
|
|
|
|
3 |
|
|
4 |
4 |
///////////////////////////////////////////////////////////////////////////////////// |
///////////////////////////////////////////////////////////////////////////////////// |
5 |
|
template <typename T, template <typename> class P, typename ... U> |
|
6 |
|
auto QuemitterImpl<T, P, U ...>::on(event_type e, callback_type c) -> listener_type |
|
|
5 |
|
template <typename T, template <typename> class P, typename... U> |
|
6 |
|
auto QuemitterImpl<T, P, U...>::on(event_type e, callback_type c) -> listener_type |
7 |
7 |
{ |
{ |
8 |
8 |
return m_reactor.on(e, c); |
return m_reactor.on(e, c); |
9 |
9 |
} |
} |
10 |
10 |
|
|
11 |
11 |
///////////////////////////////////////////////////////////////////////////////////// |
///////////////////////////////////////////////////////////////////////////////////// |
12 |
|
template <typename T, template <typename> class P, typename ... U> |
|
13 |
|
auto QuemitterImpl<T, P, U ...>::once(event_type e, callback_type c) -> listener_type |
|
|
12 |
|
template <typename T, template <typename> class P, typename... U> |
|
13 |
|
auto QuemitterImpl<T, P, U...>::once(event_type e, callback_type c) -> listener_type |
14 |
14 |
{ |
{ |
15 |
15 |
return m_reactor.once(e, c); |
return m_reactor.once(e, c); |
16 |
16 |
} |
} |
17 |
17 |
|
|
18 |
18 |
///////////////////////////////////////////////////////////////////////////////////// |
///////////////////////////////////////////////////////////////////////////////////// |
19 |
|
template <typename T, template <typename> class P, typename ... U> |
|
20 |
|
void QuemitterImpl<T, P, U ...>::removeListeners(event_type e) |
|
|
19 |
|
template <typename T, template <typename> class P, typename... U> |
|
20 |
|
void QuemitterImpl<T, P, U...>::removeListeners(event_type e) |
21 |
21 |
{ |
{ |
22 |
22 |
m_reactor.removeListeners(e); |
m_reactor.removeListeners(e); |
23 |
23 |
} |
} |
24 |
24 |
|
|
25 |
25 |
///////////////////////////////////////////////////////////////////////////////////// |
///////////////////////////////////////////////////////////////////////////////////// |
26 |
|
template <typename T, template <typename> class P, typename ... U> |
|
27 |
|
void QuemitterImpl<T, P, U ...>::removeAllListeners() |
|
|
26 |
|
template <typename T, template <typename> class P, typename... U> |
|
27 |
|
void QuemitterImpl<T, P, U...>::removeAllListeners() |
28 |
28 |
{ |
{ |
29 |
|
m_reactor.removeAllListeners(); |
|
|
29 |
|
m_reactor.removeAllListeners(); |
30 |
30 |
} |
} |
31 |
31 |
|
|
32 |
32 |
///////////////////////////////////////////////////////////////////////////////////// |
///////////////////////////////////////////////////////////////////////////////////// |
33 |
|
template <typename T, template <typename> class P, typename ... U> |
|
34 |
|
void QuemitterImpl<T, P, U ...>::interupt(event_type e, U ... arg) |
|
|
33 |
|
template <typename T, template <typename> class P, typename... U> |
|
34 |
|
void QuemitterImpl<T, P, U...>::interupt(event_type e, U... arg) |
35 |
35 |
{ |
{ |
36 |
|
m_reactor.interupt(e, arg ...); |
|
|
36 |
|
m_reactor.interupt(e, arg...); |
37 |
37 |
} |
} |
38 |
38 |
|
|
39 |
|
|
|
40 |
39 |
///////////////////////////////////////////////////////////////////////////////////////////// |
///////////////////////////////////////////////////////////////////////////////////////////// |
41 |
|
template <typename T, template <typename> class P, typename ... U> |
|
42 |
|
void QuemitterImpl<T, P, U ...>::emit(event_type e, U ... v) |
|
|
40 |
|
template <typename T, template <typename> class P, typename... U> |
|
41 |
|
void QuemitterImpl<T, P, U...>::emit(event_type e, U... v) |
43 |
42 |
{ |
{ |
44 |
|
function_type p([e, v ..., this]() { |
|
45 |
|
interupt(e, v ...); |
|
|
43 |
|
function_type p([e, v..., this]() { |
|
44 |
|
interupt(e, v...); |
46 |
45 |
}); |
}); |
47 |
46 |
|
|
48 |
47 |
push_event(p); |
push_event(p); |
49 |
48 |
} |
} |
50 |
49 |
|
|
51 |
50 |
///////////////////////////////////////////////////////////////////////////////////////////// |
///////////////////////////////////////////////////////////////////////////////////////////// |
52 |
|
template <class T, template <typename> class P, typename ... U> |
|
53 |
|
void QuemitterImpl<T, P, U ...>::push_event(function_type f) |
|
|
51 |
|
template <class T, template <typename> class P, typename... U> |
|
52 |
|
void QuemitterImpl<T, P, U...>::push_event(function_type f) |
54 |
53 |
{ |
{ |
55 |
54 |
m_queue.push(f); |
m_queue.push(f); |
56 |
55 |
fbp::pushed_event(*this); |
fbp::pushed_event(*this); |