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_PROPERTY_EMITS_CHANGE_SIGNAL_ANNOTATION "org.freedesktop.DBus.Property.EmitsChangedSignal"
60 #define DBUS_CXX_ITERATOR_SUPPORT( CppType, DBusType ) \
62 DBus::MessageIterator& operator>>(DBus::MessageIterator& __msgiter, CppType& __cpptype) \
64 DBusType __dbustype; \
65 __msgiter >> __dbustype; \
66 __cpptype = static_cast< CppType >( __dbustype ); \
71 DBus::MessageAppendIterator& operator<<(DBus::MessageAppendIterator& __msgiter, CppType& __cpptype) \
73 __msgiter << static_cast< DBusType >( __cpptype ); \
78 inline std::string signature( CppType ) { DBusType d; return signature( d ); } \
95 void log_std_err(
const char* logger_name,
const struct ::SL_LogLocation* location,
97 const char* log_string );
111 void hexdump(
const std::vector<uint8_t>* vec, std::ostream* stream );
120 void hexdump(
const uint8_t* vec,
const uint32_t len, std::ostream* stream );
140 template<
typename... argn>
149 std::string
introspect(
const std::vector<std::string>&,
int,
const std::string& )
const {
154 template<
typename arg1,
typename... argn>
158 std::string arg1_name = demangle<arg1>();
161 if( remaining_args.size() > 1 ) {
165 return arg1_name + remaining_args;
168 std::string
introspect(
const std::vector<std::string>& names,
int idx,
const std::string& spaces )
const {
170 std::ostringstream output;
171 std::string name = names.size() > idx ? names[idx] :
"";
175 if( name.size() > 0 ) { output <<
"name=\"" << name <<
"\" "; }
177 output <<
"type=\"" <<
signature( arg ) <<
"\" ";
178 output <<
"direction=\"in\"/>\n";
184 template<
typename... argn>
193 std::string
introspect(
const std::vector<std::string>&,
int,
const std::string& )
const {
198 template<
typename arg1,
typename... argn>
202 std::string arg1_name = demangle<arg1>();
205 if( remaining_args.size() > 1 ) {
209 return arg1_name + remaining_args;
212 std::string
introspect(
const std::vector<std::string>& names,
int& idx,
const std::string& spaces )
const {
214 std::ostringstream output;
215 std::string name = names.size() > idx ? names[idx] :
"";
219 if( name.size() > 0 ) { output <<
"name=\"" << name <<
"\" "; }
221 output <<
"type=\"" <<
signature( arg ) <<
"\" ";
222 output <<
"direction=\"out\"/>\n";
236 template<
typename ...Args>
246 std::string
introspect(
const std::vector<std::string>& names,
int idx,
const std::string& spaces )
const {
247 std::ostringstream sout;
252 void extractAndCall( std::shared_ptr<const CallMessage> callmsg, std::shared_ptr<ReturnMessage>, sigc::slot<
void( Args... )> slot ) {
254 std::tuple<Args...> tup_args;
255 std::apply( [i](
auto&& ...arg )
mutable {
256 ( void )( i >> ... >> arg );
260 std::apply( slot, tup_args );
264 template<
typename T_ret,
typename ...Args>
271 std::ostringstream ret;
272 ret << demangle<T_ret>();
279 std::string
introspect(
const std::vector<std::string>& names,
int idx,
const std::string& spaces )
const {
280 std::ostringstream sout;
282 std::string name =
"";
284 if( names.size() > 0 ) {
288 sout << spaces <<
"<arg ";
290 if( name.size() > 0 ) { sout <<
"name=\"" << name <<
"\" "; }
292 sout <<
"type=\"" <<
signature( ret_type ) <<
"\" "
293 <<
"direction=\"out\"/>\n";
308 void extractAndCall( std::shared_ptr<const CallMessage> callmsg, std::shared_ptr<ReturnMessage> retmsg, sigc::slot<T_ret( Args... )> slot ) {
310 std::tuple<Args...> tup_args;
311 std::apply( [i](
auto&& ...arg )
mutable {
312 ( void )( i >> ... >> arg );
317 retval = std::apply( slot, tup_args );
323 template<
typename... T_ret,
typename ...Args>
330 std::ostringstream ret;
338 std::string
introspect(
const std::vector<std::string>& names,
int idx,
const std::string& spaces )
const {
339 std::ostringstream sout;
347 std::tuple<Args...> tup_args;
348 std::apply( [i](
auto&& ...arg )
mutable {
349 ( void )( i >> ... >> arg );
354 retval = std::apply( slot, tup_args );
371 std::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:200
std::string method_sig() const
Definition: utility.h:157
std::string introspect(const std::vector< std::string > &names, int idx, const std::string &spaces) const
Definition: utility.h:168
std::string introspect(const std::vector< std::string > &, int, const std::string &) const
Definition: utility.h:149
std::string method_sig() const
Definition: utility.h:145
Definition: utility.h:141
std::string multireturn_sig() const
Definition: utility.h:201
std::string introspect(const std::vector< std::string > &names, int &idx, const std::string &spaces) const
Definition: utility.h:212
std::string multireturn_sig() const
Definition: utility.h:189
std::string introspect(const std::vector< std::string > &, int, const std::string &) const
Definition: utility.h:193
Definition: utility.h:185
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:114
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:159
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:75
DBus::Endianess default_endianess()
Definition: utility.cpp:163
void set_logging_function(simplelogger_log_function function)
Definition: utility.cpp:50
void set_log_level(const enum SL_LogLevel level)
Definition: utility.cpp:71
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:329
void extractAndCall(std::shared_ptr< const CallMessage > callmsg, std::shared_ptr< ReturnMessage > retmsg, sigc::slot< DBus::MultipleReturn< T_ret... >(Args...)> slot)
Definition: utility.h:345
std::string dbus_sig() const
Definition: utility.h:325
std::string introspect(const std::vector< std::string > &names, int idx, const std::string &spaces) const
Definition: utility.h:338
std::string dbus_sig() const
Definition: utility.h:266
void extractAndCall(std::shared_ptr< const CallMessage > callmsg, std::shared_ptr< ReturnMessage > retmsg, sigc::slot< T_ret(Args...)> slot)
Definition: utility.h:308
std::string introspect(const std::vector< std::string > &names, int idx, const std::string &spaces) const
Definition: utility.h:279
std::string debug_string() const
Definition: utility.h:270
std::string debug_string() const
Definition: utility.h:242
void extractAndCall(std::shared_ptr< const CallMessage > callmsg, std::shared_ptr< ReturnMessage >, sigc::slot< void(Args...)> slot)
Definition: utility.h:252
std::string introspect(const std::vector< std::string > &names, int idx, const std::string &spaces) const
Definition: utility.h:246
std::string dbus_sig() const
Definition: utility.h:238
Definition: utility.h:234