65 #include <QtCore/qreadwritelock.h> |
65 #include <QtCore/qreadwritelock.h> |
66 #include <QtCore/qstringlist.h> |
66 #include <QtCore/qstringlist.h> |
67 #include <QtCore/qvarlengtharray.h> |
67 #include <QtCore/qvarlengtharray.h> |
68 #include <QtCore/qvector.h> |
68 #include <QtCore/qvector.h> |
69 |
69 |
70 #include <qdbus_symbols_p.h> |
70 #include "qdbus_symbols_p.h" |
71 |
71 |
72 #include <qdbusmessage.h> |
72 #include <qdbusmessage.h> |
73 |
73 |
74 QT_BEGIN_NAMESPACE |
74 QT_BEGIN_NAMESPACE |
75 |
75 |
121 inline SignalHook() : obj(0), midx(-1) { } |
121 inline SignalHook() : obj(0), midx(-1) { } |
122 QString owner, service, path, signature; |
122 QString owner, service, path, signature; |
123 QObject* obj; |
123 QObject* obj; |
124 int midx; |
124 int midx; |
125 QList<int> params; |
125 QList<int> params; |
|
126 QStringList argumentMatch; |
126 QByteArray matchRule; |
127 QByteArray matchRule; |
127 }; |
128 }; |
128 |
129 |
129 struct ObjectTreeNode |
130 struct ObjectTreeNode |
130 { |
131 { |
152 typedef QList<QPair<DBusTimeout *, int> > PendingTimeoutList; |
153 typedef QList<QPair<DBusTimeout *, int> > PendingTimeoutList; |
153 |
154 |
154 typedef QMultiHash<QString, SignalHook> SignalHookHash; |
155 typedef QMultiHash<QString, SignalHook> SignalHookHash; |
155 typedef QHash<QString, QDBusMetaObject* > MetaObjectHash; |
156 typedef QHash<QString, QDBusMetaObject* > MetaObjectHash; |
156 typedef QHash<QByteArray, int> MatchRefCountHash; |
157 typedef QHash<QByteArray, int> MatchRefCountHash; |
|
158 typedef QHash<QString, int> WatchedServicesHash; |
157 |
159 |
158 public: |
160 public: |
159 // public methods are entry points from other objects |
161 // public methods are entry points from other objects |
160 explicit QDBusConnectionPrivate(QObject *parent = 0); |
162 explicit QDBusConnectionPrivate(QObject *parent = 0); |
161 ~QDBusConnectionPrivate(); |
163 ~QDBusConnectionPrivate(); |
173 QDBusMessage sendWithReply(const QDBusMessage &message, int mode, int timeout = -1); |
175 QDBusMessage sendWithReply(const QDBusMessage &message, int mode, int timeout = -1); |
174 QDBusMessage sendWithReplyLocal(const QDBusMessage &message); |
176 QDBusMessage sendWithReplyLocal(const QDBusMessage &message); |
175 QDBusPendingCallPrivate *sendWithReplyAsync(const QDBusMessage &message, int timeout = -1); |
177 QDBusPendingCallPrivate *sendWithReplyAsync(const QDBusMessage &message, int timeout = -1); |
176 int sendWithReplyAsync(const QDBusMessage &message, QObject *receiver, |
178 int sendWithReplyAsync(const QDBusMessage &message, QObject *receiver, |
177 const char *returnMethod, const char *errorMethod, int timeout = -1); |
179 const char *returnMethod, const char *errorMethod, int timeout = -1); |
|
180 bool connectSignal(const QString &service, const QString &owner, const QString &path, const QString& interface, |
|
181 const QString &name, const QStringList &argumentMatch, const QString &signature, |
|
182 QObject *receiver, const char *slot); |
178 void connectSignal(const QString &key, const SignalHook &hook); |
183 void connectSignal(const QString &key, const SignalHook &hook); |
179 SignalHookHash::Iterator disconnectSignal(SignalHookHash::Iterator &it); |
184 SignalHookHash::Iterator disconnectSignal(SignalHookHash::Iterator &it); |
|
185 bool disconnectSignal(const QString &service, const QString &path, const QString& interface, |
|
186 const QString &name, const QStringList &argumentMatch, const QString &signature, |
|
187 QObject *receiver, const char *slot); |
180 void registerObject(const ObjectTreeNode *node); |
188 void registerObject(const ObjectTreeNode *node); |
181 void connectRelay(const QString &service, const QString ¤tOwner, |
189 void connectRelay(const QString &service, const QString ¤tOwner, |
182 const QString &path, const QString &interface, |
190 const QString &path, const QString &interface, |
183 QDBusAbstractInterface *receiver, const char *signal); |
191 QDBusAbstractInterface *receiver, const char *signal); |
184 void disconnectRelay(const QString &service, const QString ¤tOwner, |
192 void disconnectRelay(const QString &service, const QString ¤tOwner, |
188 bool handleMessage(const QDBusMessage &msg); |
196 bool handleMessage(const QDBusMessage &msg); |
189 void waitForFinished(QDBusPendingCallPrivate *pcall); |
197 void waitForFinished(QDBusPendingCallPrivate *pcall); |
190 |
198 |
191 QDBusMetaObject *findMetaObject(const QString &service, const QString &path, |
199 QDBusMetaObject *findMetaObject(const QString &service, const QString &path, |
192 const QString &interface, QDBusError &error); |
200 const QString &interface, QDBusError &error); |
193 |
|
194 void registerService(const QString &serviceName); |
|
195 void unregisterService(const QString &serviceName); |
|
196 |
201 |
197 void postEventToThread(int action, QObject *target, QEvent *event); |
202 void postEventToThread(int action, QObject *target, QEvent *event); |
198 |
203 |
199 inline void serverConnection(const QDBusConnection &connection) |
204 inline void serverConnection(const QDBusConnection &connection) |
200 { emit newServerConnection(connection); } |
205 { emit newServerConnection(connection); } |
228 void socketRead(int); |
233 void socketRead(int); |
229 void socketWrite(int); |
234 void socketWrite(int); |
230 void objectDestroyed(QObject *o); |
235 void objectDestroyed(QObject *o); |
231 void relaySignal(QObject *obj, const QMetaObject *, int signalId, const QVariantList &args); |
236 void relaySignal(QObject *obj, const QMetaObject *, int signalId, const QVariantList &args); |
232 void _q_serviceOwnerChanged(const QString &name, const QString &oldOwner, const QString &newOwner); |
237 void _q_serviceOwnerChanged(const QString &name, const QString &oldOwner, const QString &newOwner); |
|
238 void registerService(const QString &serviceName); |
|
239 void unregisterService(const QString &serviceName); |
233 |
240 |
234 signals: |
241 signals: |
235 void serviceOwnerChanged(const QString &name, const QString &oldOwner, const QString &newOwner); |
242 void serviceOwnerChanged(const QString &name, const QString &oldOwner, const QString &newOwner); |
236 void callWithCallbackFailed(const QDBusError &error, const QDBusMessage &message); |
243 void callWithCallbackFailed(const QDBusError &error, const QDBusMessage &message); |
237 void newServerConnection(const QDBusConnection &connection); |
244 void newServerConnection(const QDBusConnection &connection); |
262 QMutex dispatchLock; |
269 QMutex dispatchLock; |
263 QReadWriteLock lock; |
270 QReadWriteLock lock; |
264 QDBusError lastError; |
271 QDBusError lastError; |
265 |
272 |
266 QStringList serviceNames; |
273 QStringList serviceNames; |
|
274 WatchedServicesHash watchedServiceNames; |
267 SignalHookHash signalHooks; |
275 SignalHookHash signalHooks; |
268 MatchRefCountHash matchRefCounts; |
276 MatchRefCountHash matchRefCounts; |
269 ObjectTreeNode rootNode; |
277 ObjectTreeNode rootNode; |
270 MetaObjectHash cachedMetaObjects; |
278 MetaObjectHash cachedMetaObjects; |
271 |
279 |
276 // static methods |
284 // static methods |
277 static int findSlot(QObject *obj, const QByteArray &normalizedName, QList<int>& params); |
285 static int findSlot(QObject *obj, const QByteArray &normalizedName, QList<int>& params); |
278 static bool prepareHook(QDBusConnectionPrivate::SignalHook &hook, QString &key, |
286 static bool prepareHook(QDBusConnectionPrivate::SignalHook &hook, QString &key, |
279 const QString &service, const QString &owner, |
287 const QString &service, const QString &owner, |
280 const QString &path, const QString &interface, const QString &name, |
288 const QString &path, const QString &interface, const QString &name, |
|
289 const QStringList &argMatch, |
281 QObject *receiver, const char *signal, int minMIdx, |
290 QObject *receiver, const char *signal, int minMIdx, |
282 bool buildSignature); |
291 bool buildSignature); |
283 static DBusHandlerResult messageFilter(DBusConnection *, DBusMessage *, void *); |
292 static DBusHandlerResult messageFilter(DBusConnection *, DBusMessage *, void *); |
284 static QDBusCallDeliveryEvent *prepareReply(QDBusConnectionPrivate *target, QObject *object, |
293 static QDBusCallDeliveryEvent *prepareReply(QDBusConnectionPrivate *target, QObject *object, |
285 int idx, const QList<int> &metaTypes, |
294 int idx, const QList<int> &metaTypes, |