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
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #ifndef QDBUSCONNECTION_P_H
00036 #define QDBUSCONNECTION_P_H
00037
00038 #include "qdbuserror.h"
00039
00040 #include <QtCore/qatomic.h>
00041 #include <QtCore/qhash.h>
00042 #include <QtCore/qobject.h>
00043 #include <QtCore/qpointer.h>
00044 #include <QtCore/qvarlengtharray.h>
00045
00046 #include <dbus/dbus.h>
00047
00048 class QDBusMessage;
00049 class QSocketNotifier;
00050 class QTimerEvent;
00051
00052 typedef struct DBusConnection;
00053 typedef struct DBusServer;
00054
00055 class QDBusConnectionPrivate: public QObject
00056 {
00057 Q_OBJECT
00058 public:
00059 QDBusConnectionPrivate(QObject *parent = 0);
00060 ~QDBusConnectionPrivate();
00061
00062 void bindToApplication();
00063
00064 void setConnection(DBusConnection *connection);
00065 void setServer(DBusServer *server);
00066 void closeConnection();
00067 void timerEvent(QTimerEvent *e);
00068
00069 bool handleSignal(DBusMessage *msg) const;
00070 bool handleObjectCall(DBusMessage *message) const;
00071 bool handleError();
00072
00073 public slots:
00074 void socketRead(int);
00075 void socketWrite(int);
00076 void objectDestroyed(QObject *o);
00077
00078 public:
00079 DBusError error;
00080 QDBusError lastError;
00081
00082 enum ConnectionMode { InvalidMode, ServerMode, ClientMode };
00083
00084 QAtomic ref;
00085 ConnectionMode mode;
00086 DBusConnection *connection;
00087 DBusServer *server;
00088
00089 static int messageMetaType;
00090 static int registerMessageMetaType();
00091 bool handleSignal(const QString &path, const QDBusMessage &msg) const;
00092 int sendWithReplyAsync(const QDBusMessage &message, QObject *receiver,
00093 const char *method) const;
00094
00095 struct Watcher
00096 {
00097 Watcher(): watch(0), read(0), write(0) {}
00098 DBusWatch *watch;
00099 QSocketNotifier *read;
00100 QSocketNotifier *write;
00101 };
00102 typedef QMultiHash<int, Watcher> WatcherHash;
00103 WatcherHash watchers;
00104
00105 typedef QHash<int, DBusTimeout *> TimeoutHash;
00106 TimeoutHash timeouts;
00107
00108 struct SignalHook
00109 {
00110 QString interface, name;
00111 QPointer<QObject> obj;
00112 int midx;
00113 QVarLengthArray<int, 10> params;
00114
00115 bool setSlot(const char *slotName);
00116 };
00117
00118 typedef QMultiHash<QString, SignalHook> SignalHookHash;
00119 SignalHookHash signalHooks;
00120
00121 struct ObjectHook
00122 {
00123 QString interface;
00124 QPointer<QObject> obj;
00125 };
00126 typedef QMultiHash<QString, ObjectHook> ObjectHookHash;
00127 ObjectHookHash objectHooks;
00128 QList<DBusTimeout *> pendingTimeouts;
00129 };
00130
00131 #endif