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
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 template <typename T>
00136 iterator operator>>( T& value ) const
00137 {
00138 iterator iter = this->begin();
00139 iter >> value;
00140 return iter;
00141 }
00142
00143 template <typename T>
00144 append_iterator operator<<( T& value )
00145 {
00146 append_iterator aiter( *this );
00147 aiter << value;
00148 return aiter;
00149 }
00150
00151 iterator begin() const;
00152
00153 iterator end() const;
00154
00155 append_iterator append();
00156
00157 DBusMessage* cobj() const;
00158
00159 protected:
00160
00161 friend void init(bool);
00162
00163 DBusMessage* m_cobj;
00164
00165 bool m_valid;
00166
00167 };
00168
00169 }
00170
00171 template <typename T>
00172 inline
00173 DBus::Message::iterator operator>>( DBus::Message::const_pointer ptr, T& value )
00174 {
00175 if ( not ptr ) throw -1;
00176 return (*ptr) >> value;
00177 }
00178
00179 template <typename T>
00180 inline
00181 DBus::Message::append_iterator operator<<( DBus::Message::pointer ptr, T& value )
00182 {
00183 if ( not ptr ) throw -1;
00184 return (*ptr) << value;
00185 }
00186
00187 #endif