utility.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef DBUSUTILITY_H
00021 #define DBUSUTILITY_H
00022
00023 #include <typeinfo>
00024 #include <string>
00025
00026 #include <sigc++/sigc++.h>
00027
00028 #include <dbus-cxx/dbus-cxx-config.h>
00029 #include <dbus-cxx/enums.h>
00030 #include <dbus-cxx/pointer.h>
00031 #include <dbus-cxx/path.h>
00032 #include <dbus-cxx/signature.h>
00033
00034 #define DBUS_CXX_PARAM_LIMIT 7
00035
00036 #ifdef DBUS_CXX_DEBUG_ENABLED
00037 #include <iostream>
00038
00039 #define DEBUG_OUT(x,y) if (DEBUG) std::cout << x << " " << pthread_self() << ": " << y << std::endl
00040 #define DBUS_CXX_DEBUG(x) std::cout << pthread_self() << ": " << x << std::endl
00041
00042
00043 #else
00044 #define DEBUG_OUT(x,y) ;
00045 #define DBUS_CXX_DEBUG(x) ;
00046 #endif
00047
00048 #define DBUS_CXX_INTROSPECTABLE_INTERFACE "org.freedesktop.DBus.Introspectable"
00049
00069 #define DBUS_CXX_ITERATOR_SUPPORT( CppType, DBusType ) \
00070 inline \
00071 DBus::MessageIterator& operator>>(DBus::MessageIterator& __msgiter, CppType& __cpptype) \
00072 { \
00073 DBusType __dbustype; \
00074 __msgiter >> __dbustype; \
00075 __cpptype = static_cast< CppType >( __dbustype ); \
00076 return __msgiter; \
00077 } \
00078 \
00079 inline \
00080 DBus::MessageAppendIterator& operator<<(DBus::MessageAppendIterator& __msgiter, CppType& __cpptype) \
00081 { \
00082 __msgiter << static_cast< DBusType >( __cpptype ); \
00083 return __msgiter; \
00084 } \
00085 \
00086 namespace DBus { \
00087 template<> inline std::string signature< CppType >() { return signature< DBusType >(); } \
00088 }
00089
00090
00091 namespace DBus
00092 {
00093
00094 typedef sigc::nil nil;
00095
00096 class Connection;
00097
00098 void init(bool threadsafe=true);
00099
00100 bool initialized();
00101
00102 std::string introspect( DBusCxxPointer<Connection> conn, const std::string& destination, const std::string& path );
00103
00104 inline std::string signature( uint8_t ) { return DBUS_TYPE_BYTE_AS_STRING; }
00105 inline std::string signature( bool ) { return DBUS_TYPE_BOOLEAN_AS_STRING; }
00106 inline std::string signature( int16_t ) { return DBUS_TYPE_INT16_AS_STRING; }
00107 inline std::string signature( uint16_t ) { return DBUS_TYPE_UINT16_AS_STRING; }
00108 inline std::string signature( int32_t ) { return DBUS_TYPE_INT32_AS_STRING; }
00109 inline std::string signature( uint32_t ) { return DBUS_TYPE_UINT32_AS_STRING; }
00110 inline std::string signature( int64_t ) { return DBUS_TYPE_INT64_AS_STRING; }
00111 inline std::string signature( uint64_t ) { return DBUS_TYPE_UINT64_AS_STRING; }
00112 inline std::string signature( double ) { return DBUS_TYPE_DOUBLE_AS_STRING; }
00113 inline std::string signature( std::string ) { return DBUS_TYPE_STRING_AS_STRING; }
00114 inline std::string signature( Signature ) { return DBUS_TYPE_SIGNATURE_AS_STRING; }
00115 inline std::string signature( Path ) { return DBUS_TYPE_OBJECT_PATH_AS_STRING; }
00116
00117 inline std::string signature( char ) { return DBUS_TYPE_BYTE_AS_STRING; }
00118 inline std::string signature( int8_t ) { return DBUS_TYPE_BYTE_AS_STRING; }
00119
00120 #if DBUS_CXX_SIZEOF_LONG_INT == 4
00121 inline std::string signature( long int ) { return DBUS_TYPE_INT32_AS_STRING; }
00122 inline std::string signature( long unsigned int ) { return DBUS_TYPE_UINT32_AS_STRING; }
00123 #endif
00124
00125 inline std::string signature( float ) { return DBUS_TYPE_DOUBLE_AS_STRING; }
00126
00127 template <typename T> inline std::string signature() { return 1; }
00128 template<> inline std::string signature<uint8_t>() { return DBUS_TYPE_BYTE_AS_STRING; }
00129 template<> inline std::string signature<bool>() { return DBUS_TYPE_BOOLEAN_AS_STRING; }
00130 template<> inline std::string signature<int16_t>() { return DBUS_TYPE_INT16_AS_STRING; }
00131 template<> inline std::string signature<uint16_t>() { return DBUS_TYPE_UINT16_AS_STRING; }
00132 template<> inline std::string signature<int32_t>() { return DBUS_TYPE_INT32_AS_STRING; }
00133 template<> inline std::string signature<uint32_t>() { return DBUS_TYPE_UINT32_AS_STRING; }
00134 template<> inline std::string signature<int64_t>() { return DBUS_TYPE_INT64_AS_STRING; }
00135 template<> inline std::string signature<uint64_t>() { return DBUS_TYPE_UINT64_AS_STRING; }
00136 template<> inline std::string signature<double>() { return DBUS_TYPE_DOUBLE_AS_STRING; }
00137 template<> inline std::string signature<std::string>() { return DBUS_TYPE_STRING_AS_STRING; }
00138 template<> inline std::string signature<Signature>() { return DBUS_TYPE_SIGNATURE_AS_STRING; }
00139 template<> inline std::string signature<Path>() { return DBUS_TYPE_OBJECT_PATH_AS_STRING; }
00140
00141 template<> inline std::string signature<char>() { return DBUS_TYPE_BYTE_AS_STRING; }
00142 template<> inline std::string signature<int8_t>() { return DBUS_TYPE_BYTE_AS_STRING; }
00143
00144 #if DBUS_CXX_SIZEOF_LONG_INT == 4
00145 template<> inline std::string signature<long int>() { return DBUS_TYPE_INT32_AS_STRING; }
00146 template<> inline std::string signature<long unsigned int>() { return DBUS_TYPE_UINT32_AS_STRING; }
00147 #endif
00148
00149 template<> inline std::string signature<float>() { return DBUS_TYPE_DOUBLE_AS_STRING; }
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213 inline Type type( uint8_t ) { return TYPE_BYTE; }
00214 inline Type type( bool ) { return TYPE_BOOLEAN; }
00215 inline Type type( int16_t ) { return TYPE_INT16; }
00216 inline Type type( uint16_t ) { return TYPE_UINT16; }
00217 inline Type type( int32_t ) { return TYPE_INT32; }
00218 inline Type type( uint32_t ) { return TYPE_UINT32; }
00219 inline Type type( int64_t ) { return TYPE_INT64; }
00220 inline Type type( uint64_t ) { return TYPE_UINT64; }
00221 inline Type type( double ) { return TYPE_DOUBLE; }
00222 inline Type type( const std::string& ) { return TYPE_STRING; }
00223 inline Type type( const char* ) { return TYPE_STRING; }
00224 inline Type type( Path ) { return TYPE_OBJECT_PATH; }
00225 inline Type type( Signature ) { return TYPE_SIGNATURE; }
00226
00227
00228 inline Type type( char ) { return TYPE_BYTE; }
00229 inline Type type( int8_t ) { return TYPE_BYTE; }
00230
00231 #if DBUS_CXX_SIZEOF_LONG_INT == 4
00232 inline Type type( long int ) { return TYPE_INT32; }
00233 inline Type type( long unsigned int ) { return TYPE_UINT32; }
00234 #endif
00235
00236 inline Type type( float ) { return TYPE_DOUBLE; }
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262 inline std::string type_string( uint8_t ) { return "byte"; }
00263 inline std::string type_string( bool ) { return "boolean"; }
00264 inline std::string type_string( int16_t ) { return "int16_t"; }
00265 inline std::string type_string( uint16_t ) { return "uint16_t"; }
00266 inline std::string type_string( int32_t ) { return "int32_t"; }
00267 inline std::string type_string( uint32_t ) { return "uint32_t"; }
00268 inline std::string type_string( int64_t ) { return "int64_t"; }
00269 inline std::string type_string( uint64_t ) { return "uint64_t"; }
00270 inline std::string type_string( double ) { return "double"; }
00271 inline std::string type_string( std::string ) { return "std::string"; }
00272 inline std::string type_string( Path ) { return "Path"; }
00273 inline std::string type_string( Signature ) { return "Signature"; }
00274
00275
00276 inline std::string type_string_from_code( DBus::Type t )
00277 {
00278 switch ( t )
00279 {
00280 case TYPE_BYTE:
00281 return "byte";
00282 case TYPE_BOOLEAN:
00283 return "boolean";
00284 case TYPE_INT16:
00285 return "int16_t";
00286 case TYPE_UINT16:
00287 return "uint16_t";
00288 case TYPE_INT32:
00289 return "int32_t";
00290 case TYPE_UINT32:
00291 return "uint32_t";
00292 case TYPE_INT64:
00293 return "int64_t";
00294 case TYPE_UINT64:
00295 return "uint64_t";
00296 case TYPE_DOUBLE:
00297 return "double";
00298 case TYPE_STRING:
00299 return "string";
00300 case TYPE_OBJECT_PATH:
00301 return "Path";
00302 case TYPE_SIGNATURE:
00303 return "Signature";
00304 case TYPE_ARRAY:
00305 return "Array";
00306 case TYPE_VARIANT:
00307 return "Variant";
00308 case TYPE_STRUCT:
00309 return "Struct";
00310 case TYPE_DICT_ENTRY:
00311 return "Dict Entry";
00312 default:
00313 break;
00314 }
00315 return std::string("Invalid");
00316 }
00317
00318 Type checked_type_cast( int n );
00319
00320 }
00321
00322 #endif