dbus-cxx logo

utility.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2007,2008,2009 by Rick L. Vinyard, Jr.                  *
00003  *   rvinyard@cs.nmsu.edu                                                  *
00004  *                                                                         *
00005  *   This file is part of the dbus-cxx library.                            *
00006  *                                                                         *
00007  *   The dbus-cxx library is free software; you can redistribute it and/or *
00008  *   modify it under the terms of the GNU General Public License           *
00009  *   version 3 as published by the Free Software Foundation.               *
00010  *                                                                         *
00011  *   The dbus-cxx library is distributed in the hope that it will be       *
00012  *   useful, but WITHOUT ANY WARRANTY; without even the implied warranty   *
00013  *   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU   *
00014  *   General Public License for more details.                              *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU General Public License     *
00017  *   along with this software. If not see <http://www.gnu.org/licenses/>.  *
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/signature.h>
00032 
00033 #define DBUS_CXX_PARAM_LIMIT 7
00034 
00035 #ifdef DBUS_CXX_DEBUG_ENABLED
00036   #include <iostream>
00037 
00038 //  #define DEBUG_OUT(x,y) if (DEBUG) std::cout << x << " " << pthread_self() << ": " << y << std::endl
00039 //  #define DBUS_CXX_DEBUG(x) std::cout << pthread_self() << ": " << x << std::endl
00040   #define DEBUG_OUT(x,y) ;
00041   #define DBUS_CXX_DEBUG(x) ;
00042 #else
00043   #define DEBUG_OUT(x,y) ;
00044   #define DBUS_CXX_DEBUG(x) ;
00045 #endif
00046 
00047 
00048 namespace DBus
00049 {
00050 
00051   typedef sigc::nil nil;
00052 
00053   class Connection;
00054 
00055   void init(bool threadsafe=true);
00056   
00057   bool initialized();
00058 
00059   std::string introspect( DBusCxxPointer<Connection> conn, const std::string& destination, const std::string& path );
00060 
00061   inline std::string signature( uint8_t )     { return DBUS_TYPE_BYTE_AS_STRING; }
00062   inline std::string signature( bool )        { return DBUS_TYPE_BOOLEAN_AS_STRING; }
00063   inline std::string signature( int16_t )     { return DBUS_TYPE_INT16_AS_STRING; }
00064   inline std::string signature( uint16_t )    { return DBUS_TYPE_UINT16_AS_STRING; }
00065   inline std::string signature( int32_t )     { return DBUS_TYPE_INT32_AS_STRING; }
00066   inline std::string signature( uint32_t )    { return DBUS_TYPE_UINT32_AS_STRING; }
00067   inline std::string signature( int64_t )     { return DBUS_TYPE_INT64_AS_STRING; }
00068   inline std::string signature( uint64_t )    { return DBUS_TYPE_UINT64_AS_STRING; }
00069   inline std::string signature( double )      { return DBUS_TYPE_DOUBLE_AS_STRING; }
00070   inline std::string signature( std::string ) { return DBUS_TYPE_STRING_AS_STRING; }
00071   inline std::string signature( Signature )   { return DBUS_TYPE_SIGNATURE_AS_STRING; }
00072   // TODO come back and reimplement
00073 //   inline std::string signature( Path )        { return DBUS_TYPE_OBJECT_PATH_AS_STRING; }
00074 //   inline std::string signature( Variant )     { return DBUS_TYPE_VARIANT_AS_STRING; }
00075 //   template <typename T> inline std::string signature( const std::vector<T>& ) { T t; return DBUS_TYPE_ARRAY_AS_STRING + signature( t ); }
00076 
00077 //   template <typename Key,typename Data> inline std::string signature( const std::vector<std::pair<Key,Data> >& )
00078 //   {
00079 //     Key k; Data d;
00080 //     std::string sig;
00081 //     sig = DBUS_TYPE_ARRAY_AS_STRING;
00082 //     sig += DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING + signature(k) + signature(d) + DBUS_DICT_ENTRY_END_CHAR_AS_STRING;
00083 //     return sig;
00084 //   }
00085 
00086 //   template <typename T1>
00087 //   inline std::string signature( const Struct<T1>& )
00088 //   {
00089 //     T1 t1;
00090 //     return DBUS_STRUCT_BEGIN_CHAR_AS_STRING + signature( t1 ) + DBUS_STRUCT_END_CHAR_AS_STRING;
00091 //   }
00092 // 
00093 //   template <typename T1, typename T2>
00094 //   inline std::string signature( const Struct<T1,T2>& )
00095 //   {
00096 //     T1 t1; T2 t2;
00097 //     return DBUS_STRUCT_BEGIN_CHAR_AS_STRING + signature( t1 ) + signature( t2 ) + DBUS_STRUCT_END_CHAR_AS_STRING;
00098 //   }
00099 // 
00100 //   template <typename T1, typename T2, typename T3>
00101 //   inline std::string signature( const Struct<T1,T2,T3>& )
00102 //   {
00103 //     T1 t1; T2 t2; T3 t3;
00104 //     return DBUS_STRUCT_BEGIN_CHAR_AS_STRING + signature( t1 ) + signature( t2 ) + signature( t3 ) + DBUS_STRUCT_END_CHAR_AS_STRING;
00105 //   }
00106 // 
00107 //   template <typename T1, typename T2, typename T3, typename T4>
00108 //   inline std::string signature( const Struct<T1,T2,T3,T4>& )
00109 //   {
00110 //     T1 t1; T2 t2; T3 t3; T4 t4;
00111 //     return DBUS_STRUCT_BEGIN_CHAR_AS_STRING + signature( t1 ) + signature( t2 ) + signature( t3 ) + signature( t4 ) + DBUS_STRUCT_END_CHAR_AS_STRING;
00112 //   }
00113 // 
00114 //   template <typename T1, typename T2, typename T3, typename T4, typename T5>
00115 //   inline std::string signature( const Struct<T1,T2,T3,T4,T5>& )
00116 //   {
00117 //     T1 t1; T2 t2; T3 t3; T4 t4; T5 t5;
00118 //     return DBUS_STRUCT_BEGIN_CHAR_AS_STRING + signature( t1 ) + signature( t2 ) + signature( t3 ) + signature( t4 ) + signature( t5 ) + DBUS_STRUCT_END_CHAR_AS_STRING;
00119 //   }
00120 // 
00121 //   template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
00122 //   inline std::string signature( const Struct<T1,T2,T3,T4,T5,T6>& )
00123 //   {
00124 //     T1 t1; T2 t2; T3 t3; T4 t4; T5 t5; T6 t6;
00125 //     return DBUS_STRUCT_BEGIN_CHAR_AS_STRING + signature( t1 ) + signature( t2 ) + signature( t3 ) + signature( t4 ) + signature( t5 ) + signature( t6 ) + DBUS_STRUCT_END_CHAR_AS_STRING;
00126 //   }
00127 // 
00128 //   template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
00129 //   inline std::string signature( const Struct<T1,T2,T3,T4,T5,T6,T7>& )
00130 //   {
00131 //     T1 t1; T2 t2; T3 t3; T4 t4; T5 t5; T6 t6; T7 t7;
00132 //     return DBUS_STRUCT_BEGIN_CHAR_AS_STRING + signature( t1 ) + signature( t2 ) + signature( t3 ) + signature( t4 ) + signature( t5 ) + signature( t6 ) + signature( t7 ) + DBUS_STRUCT_END_CHAR_AS_STRING;
00133 //   }
00134 
00135   inline Type type( uint8_t )            { return TYPE_BYTE; }
00136   inline Type type( bool )               { return TYPE_BOOLEAN; }
00137   inline Type type( int16_t )            { return TYPE_INT16; }
00138   inline Type type( uint16_t )           { return TYPE_UINT16; }
00139   inline Type type( int32_t )            { return TYPE_INT32; }
00140   inline Type type( uint32_t )           { return TYPE_UINT32; }
00141   inline Type type( int64_t )            { return TYPE_INT64; }
00142   inline Type type( uint64_t )           { return TYPE_UINT64; }
00143   inline Type type( double )             { return TYPE_DOUBLE; }
00144   inline Type type( const std::string& ) { return TYPE_STRING; }
00145   inline Type type( const char* )        { return TYPE_STRING; }
00146 //   inline Type type( Path )               { return TYPE_OBJECT_PATH; }
00147   inline Type type( Signature )          { return TYPE_SIGNATURE; }
00148 //   inline Type type( Variant )            { return TYPE_VARIANT; }
00149 
00150 //   template <typename T> inline Type type(const std::vector<T>&) { return TYPE_ARRAY; }
00151 
00152 //   template <typename T0>
00153 //   inline Type type( const Struct<T0>& ) { return TYPE_STRUCT; }
00154 // 
00155 //   template <typename T0, typename T1>
00156 //   inline Type type( const Struct<T0,T1>& ) { return TYPE_STRUCT; }
00157 // 
00158 //   template <typename T0, typename T1, typename T2>
00159 //   inline Type type( const Struct<T0,T1,T2>& ) { return TYPE_STRUCT; }
00160 // 
00161 //   template <typename T0, typename T1, typename T2, typename T3>
00162 //   inline Type type( const Struct<T0,T1,T2,T3>& ) { return TYPE_STRUCT; }
00163 // 
00164 //   template <typename T0, typename T1, typename T2, typename T3, typename T4>
00165 //   inline Type type( const Struct<T0,T1,T2,T3,T4>& ) { return TYPE_STRUCT; }
00166 // 
00167 //   template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5>
00168 //   inline Type type( const Struct<T0,T1,T2,T3,T4,T5>& ) { return TYPE_STRUCT; }
00169 // 
00170 //   template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
00171 //   inline Type type( const Struct<T0,T1,T2,T3,T4,T5,T6>& ) { return TYPE_STRUCT; }
00172 
00173   inline std::string type_string( uint8_t )     { return "byte"; }
00174   inline std::string type_string( bool )        { return "boolean"; }
00175   inline std::string type_string( int16_t )     { return "int16_t"; }
00176   inline std::string type_string( uint16_t )    { return "uint16_t"; }
00177   inline std::string type_string( int32_t )     { return "int32_t"; }
00178   inline std::string type_string( uint32_t )    { return "uint32_t"; }
00179   inline std::string type_string( int64_t )     { return "int64_t"; }
00180   inline std::string type_string( uint64_t )    { return "uint64_t"; }
00181   inline std::string type_string( double )      { return "double"; }
00182   inline std::string type_string( std::string ) { return "std::string"; }
00183 //   inline std::string type_string( Path )        { return "Path"; }
00184   inline std::string type_string( Signature )   { return "Signature"; }
00185 //   inline std::string type_string( Variant )     { return "Variant"; }
00186 
00187   inline std::string type_string_from_code( DBus::Type t )
00188   {
00189     switch ( t )
00190     {
00191       case TYPE_BYTE:
00192         return "byte";
00193       case TYPE_BOOLEAN:
00194         return "boolean";
00195       case TYPE_INT16:
00196         return "int16_t";
00197       case TYPE_UINT16:
00198         return "uint16_t";
00199       case TYPE_INT32:
00200         return "int32_t";
00201       case TYPE_UINT32:
00202         return "uint32_t";
00203       case TYPE_INT64:
00204         return "int64_t";
00205       case TYPE_UINT64:
00206         return "uint64_t";
00207       case TYPE_DOUBLE:
00208         return "double";
00209       case TYPE_STRING:
00210         return "string";
00211       case TYPE_OBJECT_PATH:
00212         return "Path";
00213       case TYPE_SIGNATURE:
00214         return "Signature";
00215       case TYPE_ARRAY:
00216         return "Array";
00217       case TYPE_VARIANT:
00218         return "Variant";
00219       case TYPE_STRUCT:
00220         return "Struct";
00221       case TYPE_DICT_ENTRY:
00222         return "Dict Entry";
00223       default:
00224         break;
00225     }
00226     return std::string("Invalid");
00227   }
00228 
00229   Type checked_type_cast( int n );
00230 
00231 }
00232 
00233 #endif

Generated on Thu May 28 16:50:50 2009 for dbus-cxx by doxygen 1.5.7.1