eldbus-cxx: Implementation of eldbus C++ API
Summary:
Applications can:
void method_callback(void* data, const Eldbus_Service_Interface* iface,
const Eldbus_Message* message);
struct { ... } data_struct;
Eldbus_Method methods[] =
{
"method1", ELDBUS_ARGS("b", "bool"), ELDBUS_ARGS("b", "bool"), ELDBUS_METHOD_FLAG_HAS_DATA
, (Eldbus_Method_Cb)&method_callback, &data_struct
};
And method_callback will be called with data parameter pointing to data_struct global object.
Also, Eldbus-cxx supports registering an interface passing a lambda or
function object as method. For example:
edb::service_interface iface = edb::service_interface_register
(c, path, interface
, es::method("SendStringAndBool"
, [expected_string, expected_bool] (std::string const& n, bool b
, bool* out)
{
std::cout << "Running SendStringAndBool" << std::endl;
ck_assert(n == expected_string);
ck_assert(b == expected_bool);
*out = b;
return n;
}
, es::ins<std::string, bool>("string", "bool")
, es::outs<std::string, bool>("string", "bool")
)
);
When a request for "SendStringAndBool" with the proper signature is
called, executes the lambda and replies with the return value and
its bool* out parameter value.
Reviewers: cedric, woohyun, raster
CC: savio, cedric
Differential Revision: https://phab.enlightenment.org/D1052
2014-07-03 00:28:22 -07:00
|
|
|
#ifndef EFL_ELDBUS_CXX_ELDBUS_FREEDESKTOP_HH
|
|
|
|
#define EFL_ELDBUS_CXX_ELDBUS_FREEDESKTOP_HH
|
|
|
|
|
|
|
|
#include <eldbus_message.hh>
|
|
|
|
#include <eldbus_service.hh>
|
|
|
|
#include <eldbus_basic.hh>
|
|
|
|
#include <eldbus_raw_tuple.hh>
|
|
|
|
|
|
|
|
namespace efl { namespace eldbus { namespace _detail {
|
|
|
|
|
|
|
|
template <typename Callback, typename... Ins>
|
|
|
|
void _callback_wrapper(void* data, Eldbus_Message const* message, Eldbus_Pending* pending)
|
|
|
|
{
|
|
|
|
Callback* callback(static_cast<Callback*>(data));
|
|
|
|
|
|
|
|
const char* errname, *errmsg;
|
|
|
|
if (eldbus_message_error_get(message, &errname, &errmsg))
|
|
|
|
{
|
|
|
|
std::cout << "error " << errname << " " << errmsg << std::endl;
|
|
|
|
std::tuple<Ins...> tuple;
|
|
|
|
eldbus::const_message msg( ::eldbus_message_ref(const_cast<Eldbus_Message*>(message)));
|
|
|
|
eina::error_code ec (eldbus::call_error_code(), eina::eina_error_category());
|
|
|
|
eina::call_tuple_unwrap_prefix
|
|
|
|
(*callback, tuple, eina::make_index_sequence<sizeof...(Ins)>()
|
|
|
|
, ec, msg, pending);
|
|
|
|
}
|
|
|
|
|
|
|
|
typename raw_tuple<std::tuple<Ins...> >::type tuple;
|
|
|
|
if(sizeof...(Ins))
|
|
|
|
{
|
|
|
|
if(!_detail::_init_raw_tuple<0u, std::tuple<Ins...> >
|
|
|
|
(eldbus_message_iter_get(message)
|
|
|
|
, tuple, std::integral_constant<bool, (sizeof...(Ins) == 0)>()))
|
|
|
|
{
|
|
|
|
std::cout << "error init raw tuple" << std::endl;
|
2014-07-03 15:35:40 -07:00
|
|
|
std::tuple<Ins...> tuple_;
|
eldbus-cxx: Implementation of eldbus C++ API
Summary:
Applications can:
void method_callback(void* data, const Eldbus_Service_Interface* iface,
const Eldbus_Message* message);
struct { ... } data_struct;
Eldbus_Method methods[] =
{
"method1", ELDBUS_ARGS("b", "bool"), ELDBUS_ARGS("b", "bool"), ELDBUS_METHOD_FLAG_HAS_DATA
, (Eldbus_Method_Cb)&method_callback, &data_struct
};
And method_callback will be called with data parameter pointing to data_struct global object.
Also, Eldbus-cxx supports registering an interface passing a lambda or
function object as method. For example:
edb::service_interface iface = edb::service_interface_register
(c, path, interface
, es::method("SendStringAndBool"
, [expected_string, expected_bool] (std::string const& n, bool b
, bool* out)
{
std::cout << "Running SendStringAndBool" << std::endl;
ck_assert(n == expected_string);
ck_assert(b == expected_bool);
*out = b;
return n;
}
, es::ins<std::string, bool>("string", "bool")
, es::outs<std::string, bool>("string", "bool")
)
);
When a request for "SendStringAndBool" with the proper signature is
called, executes the lambda and replies with the return value and
its bool* out parameter value.
Reviewers: cedric, woohyun, raster
CC: savio, cedric
Differential Revision: https://phab.enlightenment.org/D1052
2014-07-03 00:28:22 -07:00
|
|
|
eldbus::const_message msg( ::eldbus_message_ref(const_cast<Eldbus_Message*>(message)));
|
|
|
|
eina::error_code ec(eldbus::signature_mismatch_error_code(), eina::eina_error_category());
|
|
|
|
eina::call_tuple_unwrap_prefix
|
2014-07-03 15:35:40 -07:00
|
|
|
(*callback, tuple_, eina::make_index_sequence<sizeof...(Ins)>()
|
eldbus-cxx: Implementation of eldbus C++ API
Summary:
Applications can:
void method_callback(void* data, const Eldbus_Service_Interface* iface,
const Eldbus_Message* message);
struct { ... } data_struct;
Eldbus_Method methods[] =
{
"method1", ELDBUS_ARGS("b", "bool"), ELDBUS_ARGS("b", "bool"), ELDBUS_METHOD_FLAG_HAS_DATA
, (Eldbus_Method_Cb)&method_callback, &data_struct
};
And method_callback will be called with data parameter pointing to data_struct global object.
Also, Eldbus-cxx supports registering an interface passing a lambda or
function object as method. For example:
edb::service_interface iface = edb::service_interface_register
(c, path, interface
, es::method("SendStringAndBool"
, [expected_string, expected_bool] (std::string const& n, bool b
, bool* out)
{
std::cout << "Running SendStringAndBool" << std::endl;
ck_assert(n == expected_string);
ck_assert(b == expected_bool);
*out = b;
return n;
}
, es::ins<std::string, bool>("string", "bool")
, es::outs<std::string, bool>("string", "bool")
)
);
When a request for "SendStringAndBool" with the proper signature is
called, executes the lambda and replies with the return value and
its bool* out parameter value.
Reviewers: cedric, woohyun, raster
CC: savio, cedric
Differential Revision: https://phab.enlightenment.org/D1052
2014-07-03 00:28:22 -07:00
|
|
|
, ec, msg, pending);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
std::cout << "OK go" << std::endl;
|
|
|
|
eina::error_code ec;
|
|
|
|
eldbus::const_message msg( ::eldbus_message_ref(const_cast<Eldbus_Message*>(message)));
|
|
|
|
eina::call_tuple_unwrap_prefix
|
|
|
|
(*callback, tuple, eina::make_index_sequence<sizeof...(Ins)>()
|
|
|
|
, ec, msg, pending);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename F>
|
|
|
|
void _free_cb(void* data, const void*)
|
|
|
|
{
|
|
|
|
delete static_cast<F*>(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename... Ins, typename F>
|
|
|
|
pending name_request(connection& c, const char* bus, unsigned int flags, F&& function)
|
|
|
|
{
|
2015-05-22 02:31:18 -07:00
|
|
|
F* f = new F(std::forward<F>(function));
|
eldbus-cxx: Implementation of eldbus C++ API
Summary:
Applications can:
void method_callback(void* data, const Eldbus_Service_Interface* iface,
const Eldbus_Message* message);
struct { ... } data_struct;
Eldbus_Method methods[] =
{
"method1", ELDBUS_ARGS("b", "bool"), ELDBUS_ARGS("b", "bool"), ELDBUS_METHOD_FLAG_HAS_DATA
, (Eldbus_Method_Cb)&method_callback, &data_struct
};
And method_callback will be called with data parameter pointing to data_struct global object.
Also, Eldbus-cxx supports registering an interface passing a lambda or
function object as method. For example:
edb::service_interface iface = edb::service_interface_register
(c, path, interface
, es::method("SendStringAndBool"
, [expected_string, expected_bool] (std::string const& n, bool b
, bool* out)
{
std::cout << "Running SendStringAndBool" << std::endl;
ck_assert(n == expected_string);
ck_assert(b == expected_bool);
*out = b;
return n;
}
, es::ins<std::string, bool>("string", "bool")
, es::outs<std::string, bool>("string", "bool")
)
);
When a request for "SendStringAndBool" with the proper signature is
called, executes the lambda and replies with the return value and
its bool* out parameter value.
Reviewers: cedric, woohyun, raster
CC: savio, cedric
Differential Revision: https://phab.enlightenment.org/D1052
2014-07-03 00:28:22 -07:00
|
|
|
pending r = ::eldbus_name_request(c.native_handle(), bus, flags
|
|
|
|
, &_detail::_callback_wrapper<F, Ins...>, f);
|
|
|
|
eldbus_pending_free_cb_add(r.native_handle(), &_detail::_free_cb<F>, f);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
} }
|
|
|
|
|
|
|
|
#endif
|