summaryrefslogtreecommitdiff
path: root/src/bindings/cxx/eldbus_cxx/eldbus_freedesktop.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/eldbus_cxx/eldbus_freedesktop.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/eldbus_cxx/eldbus_freedesktop.hh')
-rw-r--r--src/bindings/cxx/eldbus_cxx/eldbus_freedesktop.hh72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/bindings/cxx/eldbus_cxx/eldbus_freedesktop.hh b/src/bindings/cxx/eldbus_cxx/eldbus_freedesktop.hh
new file mode 100644
index 0000000000..4af8c58e30
--- /dev/null
+++ b/src/bindings/cxx/eldbus_cxx/eldbus_freedesktop.hh
@@ -0,0 +1,72 @@
1#ifndef EFL_ELDBUS_CXX_ELDBUS_FREEDESKTOP_HH
2#define EFL_ELDBUS_CXX_ELDBUS_FREEDESKTOP_HH
3
4#include <eldbus_message.hh>
5#include <eldbus_service.hh>
6#include <eldbus_basic.hh>
7#include <eldbus_raw_tuple.hh>
8
9namespace efl { namespace eldbus { namespace _detail {
10
11template <typename Callback, typename... Ins>
12void _callback_wrapper(void* data, Eldbus_Message const* message, Eldbus_Pending* pending)
13{
14 Callback* callback(static_cast<Callback*>(data));
15
16 const char* errname, *errmsg;
17 if (eldbus_message_error_get(message, &errname, &errmsg))
18 {
19 std::cout << "error " << errname << " " << errmsg << std::endl;
20 std::tuple<Ins...> tuple;
21 eldbus::const_message msg( ::eldbus_message_ref(const_cast<Eldbus_Message*>(message)));
22 eina::error_code ec (eldbus::call_error_code(), eina::eina_error_category());
23 eina::call_tuple_unwrap_prefix
24 (*callback, tuple, eina::make_index_sequence<sizeof...(Ins)>()
25 , ec, msg, pending);
26 }
27
28 typename raw_tuple<std::tuple<Ins...> >::type tuple;
29 if(sizeof...(Ins))
30 {
31 if(!_detail::_init_raw_tuple<0u, std::tuple<Ins...> >
32 (eldbus_message_iter_get(message)
33 , tuple, std::integral_constant<bool, (sizeof...(Ins) == 0)>()))
34 {
35 std::cout << "error init raw tuple" << std::endl;
36 std::tuple<Ins...> tuple_;
37 eldbus::const_message msg( ::eldbus_message_ref(const_cast<Eldbus_Message*>(message)));
38 eina::error_code ec(eldbus::signature_mismatch_error_code(), eina::eina_error_category());
39 eina::call_tuple_unwrap_prefix
40 (*callback, tuple_, eina::make_index_sequence<sizeof...(Ins)>()
41 , ec, msg, pending);
42 }
43 }
44 std::cout << "OK go" << std::endl;
45 eina::error_code ec;
46 eldbus::const_message msg( ::eldbus_message_ref(const_cast<Eldbus_Message*>(message)));
47 eina::call_tuple_unwrap_prefix
48 (*callback, tuple, eina::make_index_sequence<sizeof...(Ins)>()
49 , ec, msg, pending);
50}
51
52template <typename F>
53void _free_cb(void* data, const void*)
54{
55 delete static_cast<F*>(data);
56}
57
58}
59
60template <typename... Ins, typename F>
61pending name_request(connection& c, const char* bus, unsigned int flags, F&& function)
62{
63 F* f = new F(std::forward<F>(function));
64 pending r = ::eldbus_name_request(c.native_handle(), bus, flags
65 , &_detail::_callback_wrapper<F, Ins...>, f);
66 eldbus_pending_free_cb_add(r.native_handle(), &_detail::_free_cb<F>, f);
67 return r;
68}
69
70} }
71
72#endif