qdbusconnection_p.h

00001 /* qdbusconnection_p.h QDBusConnection private object
00002  *
00003  * Copyright (C) 2005 Harald Fernengel <harry@kdevelop.org>
00004  *
00005  * Licensed under the Academic Free License version 2.1
00006  *
00007  * This program is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 2 of the License, or
00010  * (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020  *
00021  */
00022 
00023 //
00024 //  W A R N I N G
00025 //  -------------
00026 //
00027 // This file is not part of the public API.  This header file may
00028 // change from version to version without notice, or even be
00029 // removed.
00030 //
00031 // We mean it.
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

Generated on Wed Feb 27 10:13:38 2008 for D-BUS by  doxygen 1.4.6