message.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 DBUSCXXMESSAGE_H
00021 #define DBUSCXXMESSAGE_H
00022
00023 #include <string>
00024 #include <vector>
00025 #include <map>
00026
00027 #include <dbus/dbus.h>
00028
00029 #include <dbus-cxx/pointer.h>
00030 #include <dbus-cxx/messageiterator.h>
00031 #include <dbus-cxx/messageappenditerator.h>
00032
00033
00034
00035 namespace DBus
00036 {
00037
00038 class ReturnMessage;
00039
00053
00054
00055
00056
00057
00058
00059 class Message
00060 {
00061 public:
00062
00063 typedef DBusCxxPointer<Message> pointer;
00064
00065 typedef DBusCxxPointer<const Message> const_pointer;
00066
00067 typedef DBusCxxWeakPointer<Message> weak_pointer;
00068
00069 protected:
00070
00071 Message( MessageType type );
00072
00073 Message( DBusMessage* cobj=NULL, CreateMethod m = CREATE_ALIAS );
00074
00075 Message( Message::pointer other, CreateMethod m = CREATE_ALIAS );
00076
00077 Message( Message::const_pointer other, CreateMethod m = CREATE_ALIAS );
00078
00079 public:
00080
00081 typedef MessageIterator iterator;
00082
00083 typedef MessageAppendIterator append_iterator;
00084
00085 static pointer create( MessageType type );
00086
00087 static pointer create( DBusMessage* cobj=NULL, CreateMethod m = CREATE_ALIAS );
00088
00089 static pointer create( Message::pointer other, CreateMethod m = CREATE_ALIAS );
00090
00091 static pointer create( Message::const_pointer other, CreateMethod m = CREATE_ALIAS );
00092
00093 DBusCxxPointer<ReturnMessage> create_reply() const;
00094
00095 virtual ~Message();
00096
00097 Message& operator = ( const Message& m );
00098
00099 bool operator == ( const Message& other );
00100
00101 bool is_valid() const;
00102
00103 void invalidate();
00104
00105 operator bool() const;
00106
00107 uint32_t serial() const;
00108
00109 Message copy();
00110
00111 int type() const;
00112
00113 void set_auto_start( bool auto_start);
00114
00115 bool auto_start();
00116
00117 bool set_destination( const std::string& s );
00118
00119 const char* destination() const;
00120
00121 bool set_sender( const std::string& s );
00122
00123 const char* sender() const;
00124
00125 bool is_call( const std::string& interface, const std::string& method ) const;
00126
00127 bool is_signal( const std::string& interface, const std::string& signal_name ) const;
00128
00129 bool is_error( const std::string& error_name ) const;
00130
00131 bool has_destination( const std::string& name ) const;
00132
00133 bool has_sender( const std::string& name ) const;
00134
00135 iterator operator>>( bool& value ) const;
00136 iterator operator>>( uint8_t& value ) const;
00137 iterator operator>>( int16_t& value ) const;
00138 iterator operator>>( uint16_t& value ) const;
00139 iterator operator>>( int32_t& value ) const;
00140 iterator operator>>( uint32_t& value ) const;
00141 iterator operator>>( int64_t& value ) const;
00142 iterator operator>>( uint64_t& value ) const;
00143 iterator operator>>( double& value ) const;
00144 iterator operator>>( const char*& value ) const;
00145 iterator operator>>( std::string& value ) const;
00146
00147 append_iterator operator<<( bool value );
00148 append_iterator operator<<( uint8_t value );
00149 append_iterator operator<<( int16_t value );
00150 append_iterator operator<<( uint16_t value );
00151 append_iterator operator<<( int32_t value );
00152 append_iterator operator<<( uint32_t value );
00153 append_iterator operator<<( int64_t value );
00154 append_iterator operator<<( uint64_t value );
00155 append_iterator operator<<( double value );
00156 append_iterator operator<<( const char* value );
00157 append_iterator operator<<( const std::string& value );
00158
00159 iterator begin() const;
00160
00161 iterator end() const;
00162
00163 append_iterator append();
00164
00165 DBusMessage* cobj() const;
00166
00167 protected:
00168
00169 friend void init(bool);
00170
00171 DBusMessage* m_cobj;
00172
00173 bool m_valid;
00174
00175 };
00176
00177 template <typename T>
00178 inline
00179 Message::iterator operator>>( Message::const_pointer ptr, T& value )
00180 {
00181 if ( not ptr ) throw -1;
00182 return ptr->operator>>( value );
00183 }
00184
00185 template <typename T>
00186 inline
00187 Message::append_iterator operator<<( Message::pointer ptr, T& value )
00188 {
00189 if ( not ptr ) throw -1;
00190 return ptr->operator<<( value );
00191 }
00192
00193 }
00194
00195 #endif