2019-10-24 06:36:42 -07:00
|
|
|
/*
|
|
|
|
* Copyright 2019 by its authors. See AUTHORS.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
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 ELDBUS_PROXY_CALL_HH
|
|
|
|
#define ELDBUS_PROXY_CALL_HH
|
|
|
|
|
|
|
|
#include <Eina.hh>
|
|
|
|
#include <eldbus_error.hh>
|
|
|
|
#include <eldbus_signature_traits.hh>
|
|
|
|
#include <eldbus_message_arguments.hh>
|
|
|
|
#include <eldbus_message.hh>
|
|
|
|
#include <eldbus_raw_tuple.hh>
|
|
|
|
#include <eina_integer_sequence.hh>
|
|
|
|
#include <eina_tuple_unwrap.hh>
|
|
|
|
|
|
|
|
#include <tuple>
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
namespace efl { namespace eldbus { namespace _detail {
|
|
|
|
|
|
|
|
template <typename T> struct tag {};
|
|
|
|
|
|
|
|
template <typename Seq, typename Callback, std::size_t... I>
|
|
|
|
void _on_call_impl(void* data, Eldbus_Message const* message, Eldbus_Pending* pending)
|
|
|
|
{
|
|
|
|
std::unique_ptr<Callback> callback(static_cast<Callback*>(data));
|
|
|
|
|
|
|
|
const char* errname, *errmsg;
|
|
|
|
if (eldbus_message_error_get(message, &errname, &errmsg))
|
|
|
|
{
|
2014-07-03 15:35:40 -07:00
|
|
|
Seq 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_message_ref(const_cast<Eldbus_Message*>(message));
|
|
|
|
eldbus::const_message msg(message);
|
|
|
|
eina::error_code ec (eldbus::call_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<std::tuple_size<Seq>::value>()
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
typename raw_tuple<Seq>::type tuple;
|
|
|
|
if(std::tuple_size<Seq>::value)
|
|
|
|
{
|
|
|
|
if(!_detail::_init_raw_tuple<0u, Seq>
|
|
|
|
(eldbus_message_iter_get(message)
|
|
|
|
, tuple, std::integral_constant<bool, (std::tuple_size<Seq>::value == 0)>()))
|
|
|
|
{
|
2014-07-03 15:35:40 -07:00
|
|
|
Seq 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_message_ref(const_cast<Eldbus_Message*>(message));
|
|
|
|
eldbus::const_message msg(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<std::tuple_size<Seq>::value>()
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
eina::error_code ec;
|
|
|
|
::eldbus_message_ref(const_cast<Eldbus_Message*>(message));
|
|
|
|
eldbus::const_message msg(message);
|
|
|
|
eina::call_tuple_unwrap_prefix
|
|
|
|
(*callback, tuple, eina::make_index_sequence<std::tuple_size<Seq>::value>()
|
|
|
|
, ec, msg, pending);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Seq, typename Callback>
|
|
|
|
void _on_call(void* data, Eldbus_Message const* message, Eldbus_Pending* pending)
|
|
|
|
{
|
|
|
|
_detail::_on_call_impl<Seq, Callback>(data, message, pending);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename R, typename Callback, typename... Args>
|
|
|
|
void proxy_call_impl2(Eldbus_Proxy* proxy, const char* method, double timeout
|
|
|
|
, Callback&& callback, Args const&... args)
|
|
|
|
{
|
|
|
|
typedef std::tuple<Args...> tuple_args;
|
|
|
|
char signature[signature_size<tuple_args>::value +1];
|
|
|
|
_detail::init_signature_array<Args...>
|
|
|
|
(signature, eina::make_index_sequence<signature_size<tuple_args>::value +1>());
|
|
|
|
|
2015-05-22 02:31:18 -07:00
|
|
|
Callback* c = new Callback(std::forward<Callback>(callback));
|
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_proxy_call(proxy, method, &_on_call<R, Callback>, c, timeout, signature
|
|
|
|
, _detail::to_raw(args)...);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename R, typename Callback, typename... Args>
|
|
|
|
void proxy_call_impl(tag<R>, Eldbus_Proxy* proxy, const char* method, double timeout
|
|
|
|
, Callback&& callback, Args const&... args)
|
|
|
|
{
|
|
|
|
typedef std::tuple<R> reply_tuple;
|
2015-05-22 02:31:18 -07:00
|
|
|
_detail::proxy_call_impl2<reply_tuple>(proxy, method, timeout, std::forward<Callback>(callback), args...);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
template <typename... R, typename Callback, typename... Args>
|
|
|
|
void proxy_call_impl(tag<std::tuple<R...> >, Eldbus_Proxy* proxy, const char* method, double timeout
|
|
|
|
, Callback&& callback, Args const&... args)
|
|
|
|
{
|
|
|
|
typedef std::tuple<R...> reply_tuple;
|
2015-05-22 02:31:18 -07:00
|
|
|
_detail::proxy_call_impl2<reply_tuple>(proxy, method, timeout, std::forward<Callback>(callback), args...);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Callback, typename... Args>
|
|
|
|
void proxy_call_impl(tag<void>, Eldbus_Proxy* proxy, const char* method, double timeout
|
|
|
|
, Callback&& callback, Args const&... args)
|
|
|
|
{
|
|
|
|
typedef std::tuple<> reply_tuple;
|
2015-05-22 02:31:18 -07:00
|
|
|
_detail::proxy_call_impl2<reply_tuple>(proxy, method, timeout, std::forward<Callback>(callback), args...);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
template <typename R, typename Callback, typename... Args>
|
|
|
|
void proxy_call(Eldbus_Proxy* proxy, const char* method, double timeout
|
|
|
|
, Callback&& callback, Args const&... args)
|
|
|
|
{
|
2015-05-22 02:31:18 -07:00
|
|
|
return proxy_call_impl(tag<R>(), proxy, method, timeout, std::forward<Callback>(callback), args...);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
} } }
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|