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