21#include <sigc++/sigc++.h>
26#ifndef DBUSCXX_UTILITY_H
27#define DBUSCXX_UTILITY_H
29#define DBUS_CXX_INTROSPECTABLE_INTERFACE "org.freedesktop.DBus.Introspectable"
30#define DBUS_CXX_PEER_INTERFACE "org.freedesktop.DBus.Peer"
31#define DBUS_CXX_PROPERTIES_INTERFACE "org.freedesktop.DBus.Properties"
32#define DBUS_CXX_OBJECT_MANAGER_INTERFACE "org.freedesktop.DBus.ObjectManager"
33#define DBUS_CXX_PROPERTY_EMITS_CHANGE_SIGNAL_ANNOTATION "org.freedesktop.DBus.Property.EmitsChangedSignal"
61#define DBUS_CXX_ITERATOR_SUPPORT( CppType, DBusType ) \
63 DBus::MessageIterator& operator>>(DBus::MessageIterator& __msgiter, CppType& __cpptype) \
65 DBusType __dbustype; \
66 __msgiter >> __dbustype; \
67 __cpptype = static_cast< CppType >( __dbustype ); \
72 DBus::MessageAppendIterator& operator<<(DBus::MessageAppendIterator& __msgiter, CppType& __cpptype) \
74 __msgiter << static_cast< DBusType >( __cpptype ); \
79 inline std::string signature( CppType ) { DBusType d; return signature( d ); } \
96void log_std_err(
const char* logger_name,
const struct ::SL_LogLocation* location,
98 const char* log_string );
112void hexdump(
const std::vector<uint8_t>* vec, std::ostream* stream );
121void hexdump(
const uint8_t* vec,
const uint32_t len, std::ostream* stream );
141template<
typename... argn>
150 std::string
introspect(
const std::vector<std::string>&,
int,
const std::string& )
const {
155template<
typename arg1,
typename... argn>
159 std::string arg1_name = demangle<arg1>();
162 if( remaining_args.size() > 1 ) {
166 return arg1_name + remaining_args;
169 std::string
introspect(
const std::vector<std::string>& names,
int idx,
const std::string& spaces )
const {
171 std::ostringstream output;
172 std::string name = names.size() > idx ? names[idx] :
"";
176 if( name.size() > 0 ) { output <<
"name=\"" << name <<
"\" "; }
178 output <<
"type=\"" <<
signature( arg ) <<
"\" ";
179 output <<
"direction=\"in\"/>\n";
185template<
typename... argn>
194 std::string
introspect(
const std::vector<std::string>&,
int,
const std::string& )
const {
199template<
typename arg1,
typename... argn>
203 std::string arg1_name = demangle<arg1>();
206 if( remaining_args.size() > 1 ) {
210 return arg1_name + remaining_args;
213 std::string
introspect(
const std::vector<std::string>& names,
int& idx,
const std::string& spaces )
const {
215 std::ostringstream output;
216 std::string name = names.size() > idx ? names[idx] :
"";
220 if( name.size() > 0 ) { output <<
"name=\"" << name <<
"\" "; }
222 output <<
"type=\"" <<
signature( arg ) <<
"\" ";
223 output <<
"direction=\"out\"/>\n";
237template<
typename ...Args>
247 std::string
introspect(
const std::vector<std::string>& names,
int idx,
const std::string& spaces )
const {
248 std::ostringstream sout;
253 void extractAndCall( std::shared_ptr<const CallMessage> callmsg, std::shared_ptr<ReturnMessage>, sigc::slot<
void( Args... )> slot ) {
255 std::tuple<Args...> tup_args;
256 std::apply( [i](
auto&& ...arg )
mutable {
257 ( void )( i >> ... >> arg );
261 std::apply( slot, tup_args );
265template<
typename T_ret,
typename ...Args>
272 std::ostringstream ret;
273 ret << demangle<T_ret>();
280 std::string
introspect(
const std::vector<std::string>& names,
int idx,
const std::string& spaces )
const {
281 std::ostringstream sout;
283 std::string name =
"";
285 if( names.size() > 0 ) {
289 sout << spaces <<
"<arg ";
291 if( name.size() > 0 ) { sout <<
"name=\"" << name <<
"\" "; }
293 sout <<
"type=\"" <<
signature( ret_type ) <<
"\" "
294 <<
"direction=\"out\"/>\n";
309 void extractAndCall( std::shared_ptr<const CallMessage> callmsg, std::shared_ptr<ReturnMessage> retmsg, sigc::slot<T_ret( Args... )> slot ) {
311 std::tuple<Args...> tup_args;
312 std::apply( [i](
auto&& ...arg )
mutable {
313 ( void )( i >> ... >> arg );
318 retval = std::apply( slot, tup_args );
324template<
typename... T_ret,
typename ...Args>
331 std::ostringstream ret;
339 std::string
introspect(
const std::vector<std::string>& names,
int idx,
const std::string& spaces )
const {
340 std::ostringstream sout;
348 std::tuple<Args...> tup_args;
349 std::apply( [i](
auto&& ...arg )
mutable {
350 ( void )( i >> ... >> arg );
355 retval = std::apply( slot, tup_args );
372std::tuple<bool, int, std::vector<int>, std::chrono::milliseconds>
wait_for_fd_activity( std::vector<int> fds,
int timeout_ms );
Extraction iterator allowing values to be retrieved from a message.
Definition: messageiterator.h:56
Definition: multiplereturn.h:29
Definition: signature.h:210
std::string method_sig() const
Definition: utility.h:158
std::string introspect(const std::vector< std::string > &names, int idx, const std::string &spaces) const
Definition: utility.h:169
std::string introspect(const std::vector< std::string > &, int, const std::string &) const
Definition: utility.h:150
std::string method_sig() const
Definition: utility.h:146
Definition: utility.h:142
std::string multireturn_sig() const
Definition: utility.h:202
std::string introspect(const std::vector< std::string > &names, int &idx, const std::string &spaces) const
Definition: utility.h:213
std::string multireturn_sig() const
Definition: utility.h:190
std::string introspect(const std::vector< std::string > &, int, const std::string &) const
Definition: utility.h:194
Definition: utility.h:186
static int retval
Definition: glib-caller.cpp:7
std::tuple< bool, int, std::vector< int >, std::chrono::milliseconds > wait_for_fd_activity(std::vector< int > fds, int timeout_ms)
Wait for activity on any of the given FDs.
Definition: utility.cpp:115
Global DBus namespace, where everything happens.
Definition: callmessage.cpp:18
void log_std_err(const char *logger_name, const struct SL_LogLocation *location, const enum SL_LogLevel level, const char *log_string)
Definition: utility.cpp:54
void set_default_endianess(DBus::Endianess endianess)
Set the default endianess that the library uses in order to send messages.
Definition: utility.cpp:160
void hexdump(const std::vector< uint8_t > *vec, std::ostream *stream)
Print the vector as a hexdump output to the given output stream.
Definition: utility.cpp:76
DBus::Endianess default_endianess()
Definition: utility.cpp:164
void set_logging_function(simplelogger_log_function function)
Definition: utility.cpp:50
void set_log_level(const enum SL_LogLevel level)
Definition: utility.cpp:72
std::string signature(const std::tuple< T... > &)
Endianess
Definition: enums.h:114
void(* simplelogger_log_function)(const char *logger_name, const struct SL_LogLocation *location, const enum SL_LogLevel level, const char *log_string)
Pointer to a function that does the actual log operation.
Definition: simplelogger_defs.h:38
SL_LogLevel
Level of the log message.
Definition: simplelogger_defs.h:26
std::string debug_string() const
Definition: utility.h:330
void extractAndCall(std::shared_ptr< const CallMessage > callmsg, std::shared_ptr< ReturnMessage > retmsg, sigc::slot< DBus::MultipleReturn< T_ret... >(Args...)> slot)
Definition: utility.h:346
std::string dbus_sig() const
Definition: utility.h:326
std::string introspect(const std::vector< std::string > &names, int idx, const std::string &spaces) const
Definition: utility.h:339
std::string dbus_sig() const
Definition: utility.h:267
void extractAndCall(std::shared_ptr< const CallMessage > callmsg, std::shared_ptr< ReturnMessage > retmsg, sigc::slot< T_ret(Args...)> slot)
Definition: utility.h:309
std::string introspect(const std::vector< std::string > &names, int idx, const std::string &spaces) const
Definition: utility.h:280
std::string debug_string() const
Definition: utility.h:271
std::string debug_string() const
Definition: utility.h:243
void extractAndCall(std::shared_ptr< const CallMessage > callmsg, std::shared_ptr< ReturnMessage >, sigc::slot< void(Args...)> slot)
Definition: utility.h:253
std::string introspect(const std::vector< std::string > &names, int idx, const std::string &spaces) const
Definition: utility.h:247
std::string dbus_sig() const
Definition: utility.h:239
Definition: utility.h:235