summaryrefslogtreecommitdiff
path: root/src/bindings/cxx/eo_cxx/eo_event.hh
diff options
context:
space:
mode:
authorFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2016-05-23 12:01:30 -0300
committerFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2016-05-23 15:05:50 -0300
commite3c8b280c639058c54f5576f189d0dc288105fc7 (patch)
treee313fa05bd9d2b2cb88623f6adea2c3b396b66e8 /src/bindings/cxx/eo_cxx/eo_event.hh
parent930f39b91b12b311f40cd96b4cf2e85085b01832 (diff)
c++: Reorganized C++ binding generation
Moved all generation to a single Makefile_Cxx.am file instead of throughout the whole project. And fixed C++ generation on Elementary after elm merge.
Diffstat (limited to 'src/bindings/cxx/eo_cxx/eo_event.hh')
-rw-r--r--src/bindings/cxx/eo_cxx/eo_event.hh152
1 files changed, 152 insertions, 0 deletions
diff --git a/src/bindings/cxx/eo_cxx/eo_event.hh b/src/bindings/cxx/eo_cxx/eo_event.hh
new file mode 100644
index 0000000000..320bfc9cba
--- /dev/null
+++ b/src/bindings/cxx/eo_cxx/eo_event.hh
@@ -0,0 +1,152 @@
1
2///
3/// @file eo_event.hh
4///
5
6#ifndef EFL_CXX_EO_EVENT_HH
7#define EFL_CXX_EO_EVENT_HH
8
9#include <Eo.h>
10#include <Ecore.h>
11
12#include <functional>
13#include <memory>
14
15namespace efl { namespace eo {
16
17typedef ::Eo_Callback_Priority callback_priority;
18namespace callback_priorities
19{
20static const callback_priority before = -100;
21static const callback_priority default_ = 0;
22static const callback_priority after = 100;
23}
24
25struct signal_connection
26{
27 signal_connection(std::function<void()> deleter)
28 : _deleter(deleter) {}
29 void disconnect()
30 {
31 if(_deleter)
32 {
33 _deleter();
34 _deleter = std::function<void()>();
35 }
36 }
37private:
38 std::function<void()> _deleter;
39 friend struct scoped_signal_connection;
40};
41
42struct scoped_signal_connection
43{
44 scoped_signal_connection(signal_connection const& other)
45 : _deleter(other._deleter)
46 {
47 }
48 ~scoped_signal_connection()
49 {
50 disconnect();
51 }
52 void disconnect()
53 {
54 if(_deleter)
55 {
56 _deleter();
57 _deleter = std::function<void()>();
58 }
59 }
60 scoped_signal_connection(scoped_signal_connection&& other)
61 : _deleter(other._deleter)
62 {
63 other._deleter = std::function<void()>();
64 }
65private:
66 std::function<void()> _deleter;
67
68 scoped_signal_connection& operator=(scoped_signal_connection const&) = delete;
69 scoped_signal_connection(scoped_signal_connection const&) = delete;
70};
71
72template <typename F>
73struct _event_deleter
74{
75 _event_deleter(F* data, Eo* eo, ::Eo_Event_Cb cb, Eo_Event_Description const* description)
76 : _data(data), _eo( ::eo_ref(eo)), _cb(cb), _description(description)
77 {
78 }
79 ~_event_deleter()
80 {
81 ::eo_unref(_eo);
82 }
83 _event_deleter(_event_deleter const& other)
84 : _data(other._data), _eo( ::eo_ref(other._eo)), _cb(other._cb), _description(other._description)
85 {}
86 _event_deleter& operator=(_event_deleter const& other)
87 {
88 ::eo_unref( _eo);
89 _data = other._data;
90 _eo = ::eo_ref(other._eo);
91 _cb = other._cb;
92 _description = other._description;
93 return *this;
94 }
95
96 void operator()() const
97 {
98 ::eo_event_callback_del(_eo, _description, _cb, _data);
99 ::ecore_main_loop_thread_safe_call_async(&_deleter_call, _data);
100 }
101
102private:
103 static void _deleter_call(void* data)
104 {
105 delete static_cast<F*>(data);
106 }
107
108 F* _data;
109 Eo* _eo;
110 ::Eo_Event_Cb _cb;
111 Eo_Event_Description const* _description;
112};
113
114template <typename F>
115signal_connection make_signal_connection(std::unique_ptr<F>& data, Eo* eo, ::Eo_Event_Cb cb, Eo_Event_Description const* description)
116{
117 signal_connection c(_event_deleter<F>(data.get(), eo, cb, description));
118 data.release();
119 return c;
120}
121
122namespace _detail {
123
124template <typename T, typename F>
125Eina_Bool really_call_event(T& wrapper, F& f, Eo_Event_Description const& desc, void *info
126 , std::true_type)
127{
128 f(wrapper, desc, info);
129 return true;
130}
131template <typename T, typename F>
132Eina_Bool really_call_event(T& wrapper, F& f, Eo_Event_Description const& desc, void *info
133 , std::false_type)
134{
135 return f(wrapper, desc, info);
136}
137
138template <typename T, typename F>
139Eina_Bool
140event_callback(void *data, ::Eo_Event const* event)
141{
142 T wrapper(::eo_ref(event->object));
143 F *f = static_cast<F*>(data);
144 return _detail::really_call_event(wrapper, *f, *event->desc, event->info
145 , std::is_void<decltype((*f)(wrapper, *event->desc, event->info))>());
146}
147
148}
149
150} }
151
152#endif