message.h
Go to the documentation of this file.
00001 /* 00002 * 00003 * D-Bus++ - C++ bindings for D-Bus 00004 * 00005 * Copyright (C) 2005-2007 Paolo Durante <shackan@gmail.com> 00006 * 00007 * 00008 * This library is free software; you can redistribute it and/or 00009 * modify it under the terms of the GNU Lesser General Public 00010 * License as published by the Free Software Foundation; either 00011 * version 2.1 of the License, or (at your option) any later version. 00012 * 00013 * This library is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 * Lesser General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public 00019 * License along with this library; if not, write to the Free Software 00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00021 * 00022 */ 00023 00024 00025 #ifndef __DBUSXX_MESSAGE_H 00026 #define __DBUSXX_MESSAGE_H 00027 00028 #include <string> 00029 #include <map> 00030 00031 #include "api.h" 00032 #include "util.h" 00033 00034 namespace DBus 00035 { 00036 00037 class Message; 00038 class ErrorMessage; 00039 class SignalMessage; 00040 class ReturnMessage; 00041 class Error; 00042 class Connection; 00043 00044 class DXXAPI MessageIter 00045 { 00046 public: 00047 00048 MessageIter() {} 00049 00050 int type(); 00051 00052 bool at_end(); 00053 00054 bool has_next(); 00055 00056 MessageIter &operator ++(); 00057 00058 MessageIter operator ++(int); 00059 00060 bool append_byte(unsigned char byte); 00061 00062 unsigned char get_byte(); 00063 00064 bool append_bool(bool b); 00065 00066 bool get_bool(); 00067 00068 bool append_int16(signed short i); 00069 00070 signed short get_int16(); 00071 00072 bool append_uint16(unsigned short u); 00073 00074 unsigned short get_uint16(); 00075 00076 bool append_int32(signed int i); 00077 00078 signed int get_int32(); 00079 00080 bool append_uint32(unsigned int u); 00081 00082 unsigned int get_uint32(); 00083 00084 bool append_int64(signed long long i); 00085 00086 signed long long get_int64(); 00087 00088 bool append_uint64(unsigned long long i); 00089 00090 unsigned long long get_uint64(); 00091 00092 bool append_double(double d); 00093 00094 double get_double(); 00095 00096 bool append_string(const char *chars); 00097 00098 const char *get_string(); 00099 00100 bool append_path(const char *chars); 00101 00102 const char *get_path(); 00103 00104 bool append_signature(const char *chars); 00105 00106 const char *get_signature(); 00107 00108 char *signature() const; //returned string must be manually free()'d 00109 00110 MessageIter recurse(); 00111 00112 bool append_array(char type, const void *ptr, size_t length); 00113 00114 int array_type(); 00115 00116 int get_array(void *ptr); 00117 00118 bool is_array(); 00119 00120 bool is_dict(); 00121 00122 MessageIter new_array(const char *sig); 00123 00124 MessageIter new_variant(const char *sig); 00125 00126 MessageIter new_struct(); 00127 00128 MessageIter new_dict_entry(); 00129 00130 void close_container(MessageIter &container); 00131 00132 void copy_data(MessageIter &to); 00133 00134 Message &msg() const 00135 { 00136 return *_msg; 00137 } 00138 00139 private: 00140 00141 DXXAPILOCAL MessageIter(Message &msg) : _msg(&msg) {} 00142 00143 DXXAPILOCAL bool append_basic(int type_id, void *value); 00144 00145 DXXAPILOCAL void get_basic(int type_id, void *ptr); 00146 00147 private: 00148 00149 /* I'm sorry, but don't want to include dbus.h in the public api 00150 */ 00151 unsigned char _iter[sizeof(void *) * 3 + sizeof(int) * 11]; 00152 00153 Message *_msg; 00154 00155 friend class Message; 00156 }; 00157 00158 class DXXAPI Message 00159 { 00160 public: 00161 00162 struct Private; 00163 00164 Message(Private *, bool incref = true); 00165 00166 Message(const Message &m); 00167 00168 ~Message(); 00169 00170 Message &operator = (const Message &m); 00171 00172 Message copy(); 00173 00174 int type() const; 00175 00176 int serial() const; 00177 00178 int reply_serial() const; 00179 00180 bool reply_serial(int); 00181 00182 const char *sender() const; 00183 00184 bool sender(const char *s); 00185 00186 const char *destination() const; 00187 00188 bool destination(const char *s); 00189 00190 bool is_error() const; 00191 00192 bool is_signal(const char *interface, const char *member) const; 00193 00194 MessageIter reader() const; 00195 00196 MessageIter writer(); 00197 00198 bool append(int first_type, ...); 00199 00200 void terminate(); 00201 00202 protected: 00203 00204 Message(); 00205 00206 protected: 00207 00208 RefPtrI<Private> _pvt; 00209 00210 /* classes who need to read `_pvt` directly 00211 */ 00212 friend class ErrorMessage; 00213 friend class ReturnMessage; 00214 friend class MessageIter; 00215 friend class Error; 00216 friend class Connection; 00217 }; 00218 00219 /* 00220 */ 00221 00222 class DXXAPI ErrorMessage : public Message 00223 { 00224 public: 00225 00226 ErrorMessage(); 00227 00228 ErrorMessage(const Message &, const char *name, const char *message); 00229 00230 const char *name() const; 00231 00232 bool name(const char *n); 00233 00234 bool operator == (const ErrorMessage &) const; 00235 }; 00236 00237 /* 00238 */ 00239 00240 class DXXAPI SignalMessage : public Message 00241 { 00242 public: 00243 00244 SignalMessage(const char *name); 00245 00246 SignalMessage(const char *path, const char *interface, const char *name); 00247 00248 const char *interface() const; 00249 00250 bool interface(const char *i); 00251 00252 const char *member() const; 00253 00254 bool member(const char *m); 00255 00256 const char *path() const; 00257 00258 char **path_split() const; 00259 00260 bool path(const char *p); 00261 00262 bool operator == (const SignalMessage &) const; 00263 }; 00264 00265 /* 00266 */ 00267 00268 class DXXAPI CallMessage : public Message 00269 { 00270 public: 00271 00272 CallMessage(); 00273 00274 CallMessage(const char *dest, const char *path, const char *iface, const char *method); 00275 00276 const char *interface() const; 00277 00278 bool interface(const char *i); 00279 00280 const char *member() const; 00281 00282 bool member(const char *m); 00283 00284 const char *path() const; 00285 00286 char **path_split() const; 00287 00288 bool path(const char *p); 00289 00290 const char *signature() const; 00291 00292 bool operator == (const CallMessage &) const; 00293 }; 00294 00295 /* 00296 */ 00297 00298 class DXXAPI ReturnMessage : public Message 00299 { 00300 public: 00301 00302 ReturnMessage(const CallMessage &callee); 00303 00304 const char *signature() const; 00305 }; 00306 00307 } /* namespace DBus */ 00308 00309 #endif//__DBUSXX_MESSAGE_H