src/dbus/qdbusconnection_p.h
changeset 18 2f34d5167611
parent 3 41300fa6a67c
child 30 5dc02b23752f
equal deleted inserted replaced
3:41300fa6a67c 18:2f34d5167611
     1 /****************************************************************************
     1 /****************************************************************************
     2 **
     2 **
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     4 ** All rights reserved.
     4 ** All rights reserved.
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     6 **
     6 **
     7 ** This file is part of the QtDBus module of the Qt Toolkit.
     7 ** This file is part of the QtDBus module of the Qt Toolkit.
     8 **
     8 **
   117     };
   117     };
   118 
   118 
   119     struct SignalHook
   119     struct SignalHook
   120     {
   120     {
   121         inline SignalHook() : obj(0), midx(-1) { }
   121         inline SignalHook() : obj(0), midx(-1) { }
   122         QString owner, service, path, signature;
   122         QString 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         QStringList argumentMatch;
   127         QByteArray matchRule;
   127         QByteArray matchRule;
   153     typedef QList<QPair<DBusTimeout *, int> > PendingTimeoutList;
   153     typedef QList<QPair<DBusTimeout *, int> > PendingTimeoutList;
   154 
   154 
   155     typedef QMultiHash<QString, SignalHook> SignalHookHash;
   155     typedef QMultiHash<QString, SignalHook> SignalHookHash;
   156     typedef QHash<QString, QDBusMetaObject* > MetaObjectHash;
   156     typedef QHash<QString, QDBusMetaObject* > MetaObjectHash;
   157     typedef QHash<QByteArray, int> MatchRefCountHash;
   157     typedef QHash<QByteArray, int> MatchRefCountHash;
   158     typedef QHash<QString, int> WatchedServicesHash;
   158 
       
   159     struct WatchedServiceData {
       
   160         WatchedServiceData() : refcount(0) {}
       
   161         QString owner;
       
   162         int refcount;
       
   163     };
       
   164     typedef QHash<QString, WatchedServiceData> WatchedServicesHash;
   159 
   165 
   160 public:
   166 public:
   161     // public methods are entry points from other objects
   167     // public methods are entry points from other objects
   162     explicit QDBusConnectionPrivate(QObject *parent = 0);
   168     explicit QDBusConnectionPrivate(QObject *parent = 0);
   163     ~QDBusConnectionPrivate();
   169     ~QDBusConnectionPrivate();
   175     QDBusMessage sendWithReply(const QDBusMessage &message, int mode, int timeout = -1);
   181     QDBusMessage sendWithReply(const QDBusMessage &message, int mode, int timeout = -1);
   176     QDBusMessage sendWithReplyLocal(const QDBusMessage &message);
   182     QDBusMessage sendWithReplyLocal(const QDBusMessage &message);
   177     QDBusPendingCallPrivate *sendWithReplyAsync(const QDBusMessage &message, int timeout = -1);
   183     QDBusPendingCallPrivate *sendWithReplyAsync(const QDBusMessage &message, int timeout = -1);
   178     int sendWithReplyAsync(const QDBusMessage &message, QObject *receiver,
   184     int sendWithReplyAsync(const QDBusMessage &message, QObject *receiver,
   179                            const char *returnMethod, const char *errorMethod, int timeout = -1);
   185                            const char *returnMethod, const char *errorMethod, int timeout = -1);
   180     bool connectSignal(const QString &service, const QString &owner, const QString &path, const QString& interface,
   186     bool connectSignal(const QString &service, const QString &path, const QString& interface,
   181                        const QString &name, const QStringList &argumentMatch, const QString &signature,
   187                        const QString &name, const QStringList &argumentMatch, const QString &signature,
   182                        QObject *receiver, const char *slot);
   188                        QObject *receiver, const char *slot);
   183     void connectSignal(const QString &key, const SignalHook &hook);
   189     void connectSignal(const QString &key, const SignalHook &hook);
   184     SignalHookHash::Iterator disconnectSignal(SignalHookHash::Iterator &it);
   190     SignalHookHash::Iterator disconnectSignal(SignalHookHash::Iterator &it);
   185     bool disconnectSignal(const QString &service, const QString &path, const QString& interface,
   191     bool disconnectSignal(const QString &service, const QString &path, const QString& interface,
   186                           const QString &name, const QStringList &argumentMatch, const QString &signature,
   192                           const QString &name, const QStringList &argumentMatch, const QString &signature,
   187                           QObject *receiver, const char *slot);
   193                           QObject *receiver, const char *slot);
   188     void registerObject(const ObjectTreeNode *node);
   194     void registerObject(const ObjectTreeNode *node);
   189     void connectRelay(const QString &service, const QString &currentOwner,
   195     void connectRelay(const QString &service,
   190                       const QString &path, const QString &interface,
   196                       const QString &path, const QString &interface,
   191                       QDBusAbstractInterface *receiver, const char *signal);
   197                       QDBusAbstractInterface *receiver, const char *signal);
   192     void disconnectRelay(const QString &service, const QString &currentOwner,
   198     void disconnectRelay(const QString &service,
   193                          const QString &path, const QString &interface,
   199                          const QString &path, const QString &interface,
   194                          QDBusAbstractInterface *receiver, const char *signal);
   200                          QDBusAbstractInterface *receiver, const char *signal);
   195 
   201 
   196     bool handleMessage(const QDBusMessage &msg);
   202     bool handleMessage(const QDBusMessage &msg);
   197     void waitForFinished(QDBusPendingCallPrivate *pcall);
   203     void waitForFinished(QDBusPendingCallPrivate *pcall);
   220     void sendError(const QDBusMessage &msg, QDBusError::ErrorType code);
   226     void sendError(const QDBusMessage &msg, QDBusError::ErrorType code);
   221     void deliverCall(QObject *object, int flags, const QDBusMessage &msg,
   227     void deliverCall(QObject *object, int flags, const QDBusMessage &msg,
   222                      const QList<int> &metaTypes, int slotIdx);
   228                      const QList<int> &metaTypes, int slotIdx);
   223 
   229 
   224     bool isServiceRegisteredByThread(const QString &serviceName) const;
   230     bool isServiceRegisteredByThread(const QString &serviceName) const;
       
   231 
       
   232     QString getNameOwnerNoCache(const QString &service);
   225 
   233 
   226 protected:
   234 protected:
   227     void customEvent(QEvent *e);
   235     void customEvent(QEvent *e);
   228     void timerEvent(QTimerEvent *e);
   236     void timerEvent(QTimerEvent *e);
   229 
   237 
   269     QMutex dispatchLock;
   277     QMutex dispatchLock;
   270     QReadWriteLock lock;
   278     QReadWriteLock lock;
   271     QDBusError lastError;
   279     QDBusError lastError;
   272 
   280 
   273     QStringList serviceNames;
   281     QStringList serviceNames;
   274     WatchedServicesHash watchedServiceNames;
   282     WatchedServicesHash watchedServices;
   275     SignalHookHash signalHooks;
   283     SignalHookHash signalHooks;
   276     MatchRefCountHash matchRefCounts;
   284     MatchRefCountHash matchRefCounts;
   277     ObjectTreeNode rootNode;
   285     ObjectTreeNode rootNode;
   278     MetaObjectHash cachedMetaObjects;
   286     MetaObjectHash cachedMetaObjects;
   279 
   287 
   282 
   290 
   283 public:
   291 public:
   284     // static methods
   292     // static methods
   285     static int findSlot(QObject *obj, const QByteArray &normalizedName, QList<int>& params);
   293     static int findSlot(QObject *obj, const QByteArray &normalizedName, QList<int>& params);
   286     static bool prepareHook(QDBusConnectionPrivate::SignalHook &hook, QString &key,
   294     static bool prepareHook(QDBusConnectionPrivate::SignalHook &hook, QString &key,
   287                             const QString &service, const QString &owner,
   295                             const QString &service,
   288                             const QString &path, const QString &interface, const QString &name,
   296                             const QString &path, const QString &interface, const QString &name,
   289                             const QStringList &argMatch,
   297                             const QStringList &argMatch,
   290                             QObject *receiver, const char *signal, int minMIdx,
   298                             QObject *receiver, const char *signal, int minMIdx,
   291                             bool buildSignature);
   299                             bool buildSignature);
   292     static DBusHandlerResult messageFilter(DBusConnection *, DBusMessage *, void *);
   300     static DBusHandlerResult messageFilter(DBusConnection *, DBusMessage *, void *);