object.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_OBJECT_H 00026 #define __DBUSXX_OBJECT_H 00027 00028 #include <string> 00029 #include <list> 00030 00031 #include "api.h" 00032 #include "interface.h" 00033 #include "connection.h" 00034 #include "message.h" 00035 #include "types.h" 00036 00037 namespace DBus 00038 { 00039 00040 class DXXAPI Object 00041 { 00042 protected: 00043 00044 Object(Connection &conn, const Path &path, const char *service); 00045 00046 public: 00047 00048 virtual ~Object(); 00049 00050 inline const DBus::Path &path() const; 00051 00052 inline const std::string &service() const; 00053 00054 inline Connection &conn(); 00055 00056 void set_timeout(int new_timeout = -1); 00057 00058 inline int get_timeout() const; 00059 00060 private: 00061 00062 DXXAPILOCAL virtual bool handle_message(const Message &) = 0; 00063 DXXAPILOCAL virtual void register_obj() = 0; 00064 DXXAPILOCAL virtual void unregister_obj(bool throw_on_error = true) = 0; 00065 00066 private: 00067 00068 Connection _conn; 00069 DBus::Path _path; 00070 std::string _service; 00071 int _default_timeout; 00072 }; 00073 00074 /* 00075 */ 00076 00077 Connection &Object::conn() 00078 { 00079 return _conn; 00080 } 00081 00082 const DBus::Path &Object::path() const 00083 { 00084 return _path; 00085 } 00086 00087 const std::string &Object::service() const 00088 { 00089 return _service; 00090 } 00091 00092 int Object::get_timeout() const 00093 { 00094 return _default_timeout; 00095 } 00096 00097 /* 00098 */ 00099 00100 class DXXAPI Tag 00101 { 00102 public: 00103 00104 virtual ~Tag() 00105 {} 00106 }; 00107 00108 /* 00109 */ 00110 00111 class ObjectAdaptor; 00112 00113 typedef std::list<ObjectAdaptor *> ObjectAdaptorPList; 00114 typedef std::list<std::string> ObjectPathList; 00115 00116 class DXXAPI ObjectAdaptor : public Object, public virtual AdaptorBase 00117 { 00118 public: 00119 00120 static ObjectAdaptor *from_path(const Path &path); 00121 00122 static ObjectAdaptorPList from_path_prefix(const std::string &prefix); 00123 00124 static ObjectPathList child_nodes_from_prefix(const std::string &prefix); 00125 00126 struct Private; 00127 00128 ObjectAdaptor(Connection &conn, const Path &path); 00129 00130 ~ObjectAdaptor(); 00131 00132 inline const ObjectAdaptor *object() const; 00133 00134 protected: 00135 00136 class DXXAPI Continuation 00137 { 00138 public: 00139 00140 inline MessageIter &writer(); 00141 00142 inline Tag *tag(); 00143 00144 private: 00145 00146 Continuation(Connection &conn, const CallMessage &call, const Tag *tag); 00147 00148 Connection _conn; 00149 CallMessage _call; 00150 MessageIter _writer; 00151 ReturnMessage _return; 00152 const Tag *_tag; 00153 00154 friend class ObjectAdaptor; 00155 }; 00156 00157 void return_later(const Tag *tag); 00158 00159 void return_now(Continuation *ret); 00160 00161 void return_error(Continuation *ret, const Error error); 00162 00163 Continuation *find_continuation(const Tag *tag); 00164 00165 private: 00166 00167 void _emit_signal(SignalMessage &); 00168 00169 bool handle_message(const Message &); 00170 00171 void register_obj(); 00172 void unregister_obj(bool throw_on_error = true); 00173 00174 typedef std::map<const Tag *, Continuation *> ContinuationMap; 00175 ContinuationMap _continuations; 00176 00177 friend struct Private; 00178 }; 00179 00180 const ObjectAdaptor *ObjectAdaptor::object() const 00181 { 00182 return this; 00183 } 00184 00185 Tag *ObjectAdaptor::Continuation::tag() 00186 { 00187 return const_cast<Tag *>(_tag); 00188 } 00189 00190 MessageIter &ObjectAdaptor::Continuation::writer() 00191 { 00192 return _writer; 00193 } 00194 00195 /* 00196 */ 00197 00198 class ObjectProxy; 00199 00200 typedef std::list<ObjectProxy *> ObjectProxyPList; 00201 00202 class DXXAPI ObjectProxy : public Object, public virtual ProxyBase 00203 { 00204 public: 00205 00206 ObjectProxy(Connection &conn, const Path &path, const char *service = ""); 00207 00208 ~ObjectProxy(); 00209 00210 inline const ObjectProxy *object() const; 00211 00212 private: 00213 00214 Message _invoke_method(CallMessage &); 00215 00216 bool _invoke_method_noreply(CallMessage &call); 00217 00218 bool handle_message(const Message &); 00219 00220 void register_obj(); 00221 void unregister_obj(bool throw_on_error = true); 00222 00223 private: 00224 00225 MessageSlot _filtered; 00226 }; 00227 00228 const ObjectProxy *ObjectProxy::object() const 00229 { 00230 return this; 00231 } 00232 00233 } /* namespace DBus */ 00234 00235 #endif//__DBUSXX_OBJECT_H