source: trunk/src/dbus/qdbusconnection_p.h@ 122

Last change on this file since 122 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 12.0 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the QtDBus module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42//
43// W A R N I N G
44// -------------
45//
46// This file is not part of the public API. This header file may
47// change from version to version without notice, or even be
48// removed.
49//
50// We mean it.
51//
52//
53
54#ifndef QDBUSCONNECTION_P_H
55#define QDBUSCONNECTION_P_H
56
57#include <qdbuserror.h>
58#include <qdbusconnection.h>
59
60#include <QtCore/qatomic.h>
61#include <QtCore/qhash.h>
62#include <QtCore/qmutex.h>
63#include <QtCore/qobject.h>
64#include <QtCore/qpointer.h>
65#include <QtCore/qreadwritelock.h>
66#include <QtCore/qstringlist.h>
67#include <QtCore/qvarlengtharray.h>
68#include <QtCore/qvector.h>
69
70#include <qdbus_symbols_p.h>
71
72#include <qdbusmessage.h>
73
74QT_BEGIN_NAMESPACE
75
76class QDBusMessage;
77class QSocketNotifier;
78class QTimerEvent;
79class QDBusObjectPrivate;
80class QDBusCallDeliveryEvent;
81class QDBusActivateObjectEvent;
82class QMetaMethod;
83class QDBusInterfacePrivate;
84struct QDBusMetaObject;
85class QDBusAbstractInterface;
86class QDBusConnectionInterface;
87class QDBusPendingCallPrivate;
88
89class QDBusErrorInternal
90{
91 mutable DBusError error;
92 Q_DISABLE_COPY(QDBusErrorInternal)
93public:
94 inline QDBusErrorInternal() { q_dbus_error_init(&error); }
95 inline ~QDBusErrorInternal() { q_dbus_error_free(&error); }
96 inline bool operator !() const { return !q_dbus_error_is_set(&error); }
97 inline operator DBusError *() { q_dbus_error_free(&error); return &error; }
98 inline operator QDBusError() const { QDBusError err(&error); q_dbus_error_free(&error); return err; }
99};
100
101// QDBusConnectionPrivate holds the DBusConnection and
102// can have many QDBusConnection objects referring to it
103
104class QDBusConnectionPrivate: public QObject
105{
106 Q_OBJECT
107public:
108 // structs and enums
109 enum ConnectionMode { InvalidMode, ServerMode, ClientMode, PeerMode }; // LocalMode
110
111 struct Watcher
112 {
113 Watcher(): watch(0), read(0), write(0) {}
114 DBusWatch *watch;
115 QSocketNotifier *read;
116 QSocketNotifier *write;
117 };
118
119 struct SignalHook
120 {
121 inline SignalHook() : obj(0), midx(-1) { }
122 QString owner, service, path, signature;
123 QObject* obj;
124 int midx;
125 QList<int> params;
126 QByteArray matchRule;
127 };
128
129 struct ObjectTreeNode
130 {
131 typedef QVector<ObjectTreeNode> DataList;
132
133 inline ObjectTreeNode() : obj(0), flags(0) { }
134 inline ObjectTreeNode(const QString &n) // intentionally implicit
135 : name(n), obj(0), flags(0) { }
136 inline ~ObjectTreeNode() { }
137 inline bool operator<(const QString &other) const
138 { return name < other; }
139 inline bool operator<(const QStringRef &other) const
140 { return QStringRef(&name) < other; }
141
142 QString name;
143 QObject* obj;
144 int flags;
145 DataList children;
146 };
147
148public:
149 // typedefs
150 typedef QMultiHash<int, Watcher> WatcherHash;
151 typedef QHash<int, DBusTimeout *> TimeoutHash;
152 typedef QList<QPair<DBusTimeout *, int> > PendingTimeoutList;
153
154 typedef QMultiHash<QString, SignalHook> SignalHookHash;
155 typedef QHash<QString, QDBusMetaObject* > MetaObjectHash;
156 typedef QHash<QByteArray, int> MatchRefCountHash;
157
158public:
159 // public methods are entry points from other objects
160 explicit QDBusConnectionPrivate(QObject *parent = 0);
161 ~QDBusConnectionPrivate();
162 void deleteYourself();
163
164 void setBusService(const QDBusConnection &connection);
165 void setPeer(DBusConnection *connection, const QDBusErrorInternal &error);
166 void setConnection(DBusConnection *connection, const QDBusErrorInternal &error);
167 void setServer(DBusServer *server, const QDBusErrorInternal &error);
168 void closeConnection();
169
170 QString getNameOwner(const QString &service);
171
172 int send(const QDBusMessage &message);
173 QDBusMessage sendWithReply(const QDBusMessage &message, int mode, int timeout = -1);
174 QDBusMessage sendWithReplyLocal(const QDBusMessage &message);
175 QDBusPendingCallPrivate *sendWithReplyAsync(const QDBusMessage &message, int timeout = -1);
176 int sendWithReplyAsync(const QDBusMessage &message, QObject *receiver,
177 const char *returnMethod, const char *errorMethod, int timeout = -1);
178 void connectSignal(const QString &key, const SignalHook &hook);
179 SignalHookHash::Iterator disconnectSignal(SignalHookHash::Iterator &it);
180 void registerObject(const ObjectTreeNode *node);
181 void connectRelay(const QString &service, const QString &currentOwner,
182 const QString &path, const QString &interface,
183 QDBusAbstractInterface *receiver, const char *signal);
184 void disconnectRelay(const QString &service, const QString &currentOwner,
185 const QString &path, const QString &interface,
186 QDBusAbstractInterface *receiver, const char *signal);
187
188 bool handleMessage(const QDBusMessage &msg);