DBus-1-TQt  1.0
tqdbusconnection_p.h
Go to the documentation of this file.
00001 /* qdbusconnection_p.h TQT_DBusConnection private object
00002  *
00003  * Copyright (C) 2005 Harald Fernengel <harry@kdevelop.org>
00004  * Copyright (C) 2005 Kevin Krammer <kevin.krammer@gmx.at>
00005  *
00006  * Licensed under the Academic Free License version 2.1
00007  *
00008  * This program is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * This program is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with this program; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
00021  * USA.
00022  *
00023  */
00024 
00025 //
00026 //  W A R N I N G
00027 //  -------------
00028 //
00029 // This file is not part of the public API.  This header file may
00030 // change from version to version without notice, or even be
00031 // removed.
00032 //
00033 // We mean it.
00034 //
00035 //
00036 
00037 #ifndef TQDBUSCONNECTION_P_H
00038 #define TQDBUSCONNECTION_P_H
00039 
00040 #include <tqguardedptr.h>
00041 #include <tqmap.h>
00042 #include <tqobject.h>
00043 #include <tqvaluelist.h>
00044 
00045 #include <dbus/dbus.h>
00046 
00047 #include "tqdbusatomic.h"
00048 #include "tqdbuserror.h"
00049 #include "tqdbusobject.h"
00050 #include "tqdbusmessage.h"
00051 
00052 class TQT_DBusMessage;
00053 class TQSocketNotifier;
00054 class TQTimer;
00055 class TQTimerEvent;
00056 
00057 struct DBusConnection;
00058 struct DBusServer;
00059 
00060 class TQT_DBusResultInfo
00061 {
00062   public:
00063     TQT_DBusMessage message;
00064     TQObject* receiver;
00065     TQCString method;
00066 };
00067 typedef TQValueList<TQT_DBusResultInfo> TQT_DBusResultInfoList;
00068 
00069 class TQT_DBusConnectionPrivate: public TQObject
00070 {
00071     Q_OBJECT
00072     
00073 
00074 public:
00075     TQT_DBusConnectionPrivate(TQObject *parent = 0);
00076     ~TQT_DBusConnectionPrivate();
00077 
00078     void bindToApplication();
00079 
00080     void setConnection(DBusConnection *connection);
00081     void setServer(DBusServer *server);
00082     void closeConnection();
00083     void timerEvent(TQTimerEvent *e);
00084 
00085     bool handleSignal(DBusMessage *msg);
00086     bool handleObjectCall(DBusMessage *message);
00087     bool handleError();
00088 
00089     void emitPendingCallReply(const TQT_DBusMessage& message);
00090 
00091 signals:
00092     void dbusSignal(const TQT_DBusMessage& message);
00093 
00094     void dbusPendingCallReply(const TQT_DBusMessage& message);
00095 
00096 public slots:
00097     void socketRead(int);
00098     void socketWrite(int);
00099 
00100     void objectDestroyed(TQObject* object);
00101 
00102     void purgeRemovedWatches();
00103 
00104     void scheduleDispatch();
00105     void dispatch();
00106 
00107 public:
00108     DBusError error;
00109     TQT_DBusError lastError;
00110 
00111     enum ConnectionMode { InvalidMode, ServerMode, ClientMode };
00112 
00113     // FIXME TQAtomic ref;
00114     Atomic ref;
00115     ConnectionMode mode;
00116     DBusConnection *connection;
00117     DBusServer *server;
00118 
00119     TQTimer* dispatcher;
00120 
00121     static int messageMetaType;
00122     static int registerMessageMetaType();
00123     int sendWithReplyAsync(const TQT_DBusMessage &message, TQObject *receiver,
00124                            const char *method);
00125     void flush();
00126 
00127     struct Watcher
00128     {
00129         Watcher(): watch(0), read(0), write(0) {}
00130         DBusWatch *watch;
00131         TQSocketNotifier *read;
00132         TQSocketNotifier *write;
00133     };
00134     // FIXME typedef TQMultiHash<int, Watcher> WatcherHash;
00135     typedef TQValueList<Watcher> WatcherList;
00136     WatcherList removedWatches;
00137     typedef TQMap<int, WatcherList> WatcherHash;
00138     WatcherHash watchers;
00139 
00140     // FIXME typedef TQHash<int, DBusTimeout *> TimeoutHash;
00141     typedef TQMap<int, DBusTimeout*> TimeoutHash;
00142     TimeoutHash timeouts;
00143 
00144     typedef TQMap<TQString, TQT_DBusObjectBase*> ObjectMap;
00145     ObjectMap registeredObjects;
00146 
00147     TQValueList<DBusTimeout *> pendingTimeouts;
00148 
00149     struct TQT_DBusPendingCall
00150     {
00151         TQGuardedPtr<TQObject> receiver;
00152         TQCString method;
00153         DBusPendingCall *pending;
00154     };
00155     typedef TQMap<DBusPendingCall*, TQT_DBusPendingCall*> PendingCallMap;
00156     PendingCallMap pendingCalls;
00157 
00158     typedef TQValueList<TQT_DBusMessage> PendingMessagesForEmit;
00159     PendingMessagesForEmit pendingMessages;
00160 
00161     bool inDispatch;
00162 
00163     TQT_DBusResultInfoList m_resultEmissionQueue;
00164 
00165 public:
00166     void newMethodInResultEmissionQueue();
00167 
00168 private slots:
00169     void transmitResultEmissionQueue();
00170     void transmitMessageEmissionQueue();
00171 
00172 private:
00173     TQTimer* m_resultEmissionQueueTimer;
00174     TQTimer* m_messageEmissionQueueTimer;
00175 };
00176 
00177 #endif
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines