Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/dbus/qdbusserver.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||
---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||
2 | ** | - | ||||||
3 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||
4 | ** Copyright (C) 2016 Intel Corporation. | - | ||||||
5 | ** Contact: https://www.qt.io/licensing/ | - | ||||||
6 | ** | - | ||||||
7 | ** This file is part of the QtDBus module of the Qt Toolkit. | - | ||||||
8 | ** | - | ||||||
9 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||
10 | ** Commercial License Usage | - | ||||||
11 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||
12 | ** accordance with the commercial license agreement provided with the | - | ||||||
13 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||
14 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||
15 | ** and conditions see https://www.qt.io/terms-conditions. For further | - | ||||||
16 | ** information use the contact form at https://www.qt.io/contact-us. | - | ||||||
17 | ** | - | ||||||
18 | ** GNU Lesser General Public License Usage | - | ||||||
19 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||
20 | ** General Public License version 3 as published by the Free Software | - | ||||||
21 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||
22 | ** packaging of this file. Please review the following information to | - | ||||||
23 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||
24 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||
25 | ** | - | ||||||
26 | ** GNU General Public License Usage | - | ||||||
27 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||
28 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||
29 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||
30 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||
31 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||
32 | ** included in the packaging of this file. Please review the following | - | ||||||
33 | ** information to ensure the GNU General Public License requirements will | - | ||||||
34 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||
35 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||
36 | ** | - | ||||||
37 | ** $QT_END_LICENSE$ | - | ||||||
38 | ** | - | ||||||
39 | ****************************************************************************/ | - | ||||||
40 | - | |||||||
41 | #include "qdbusserver.h" | - | ||||||
42 | #include "qdbusconnection_p.h" | - | ||||||
43 | #include "qdbusconnectionmanager_p.h" | - | ||||||
44 | #include "qdbusutil_p.h" | - | ||||||
45 | - | |||||||
46 | #ifndef QT_NO_DBUS | - | ||||||
47 | - | |||||||
48 | QT_BEGIN_NAMESPACE | - | ||||||
49 | - | |||||||
50 | /*! | - | ||||||
51 | \class QDBusServer | - | ||||||
52 | \inmodule QtDBus | - | ||||||
53 | - | |||||||
54 | \brief The QDBusServer class provides peer-to-peer communication | - | ||||||
55 | between processes on the same computer. | - | ||||||
56 | */ | - | ||||||
57 | - | |||||||
58 | /*! | - | ||||||
59 | Constructs a QDBusServer with the given \a address, and the given | - | ||||||
60 | \a parent. | - | ||||||
61 | */ | - | ||||||
62 | QDBusServer::QDBusServer(const QString &address, QObject *parent) | - | ||||||
63 | : QObject(parent), d(0) | - | ||||||
64 | { | - | ||||||
65 | if (address.isEmpty()) | - | ||||||
66 | return; | - | ||||||
67 | - | |||||||
68 | if (!qdbus_loadLibDBus()) | - | ||||||
69 | return; | - | ||||||
70 | - | |||||||
71 | emit QDBusConnectionManager::instance()->serverRequested(address, this); | - | ||||||
72 | QObject::connect(d, SIGNAL(newServerConnection(QDBusConnectionPrivate*)), | - | ||||||
73 | this, SLOT(_q_newConnection(QDBusConnectionPrivate*)), Qt::QueuedConnection); | - | ||||||
74 | } | - | ||||||
75 | - | |||||||
76 | /*! | - | ||||||
77 | Constructs a QDBusServer with the given \a parent. The server will listen | - | ||||||
78 | for connections in \c {/tmp} (on Unix systems) or on a TCP port bound to | - | ||||||
79 | localhost (elsewhere). | - | ||||||
80 | */ | - | ||||||
81 | QDBusServer::QDBusServer(QObject *parent) | - | ||||||
82 | : QObject(parent) | - | ||||||
83 | { | - | ||||||
84 | #ifdef Q_OS_UNIX | - | ||||||
85 | // Use Unix sockets on Unix systems only | - | ||||||
86 | const QString address = QStringLiteral("unix:tmpdir=/tmp"); | - | ||||||
87 | #else | - | ||||||
88 | const QString address = QStringLiteral("tcp:"); | - | ||||||
89 | #endif | - | ||||||
90 | - | |||||||
91 | if (!qdbus_loadLibDBus()) { | - | ||||||
92 | d = 0; | - | ||||||
93 | return; | - | ||||||
94 | } | - | ||||||
95 | - | |||||||
96 | emit QDBusConnectionManager::instance()->serverRequested(address, this); | - | ||||||
97 | QObject::connect(d, SIGNAL(newServerConnection(QDBusConnectionPrivate*)), | - | ||||||
98 | this, SLOT(_q_newConnection(QDBusConnectionPrivate*)), Qt::QueuedConnection); | - | ||||||
99 | } | - | ||||||
100 | - | |||||||
101 | /*! | - | ||||||
102 | Destructs a QDBusServer | - | ||||||
103 | */ | - | ||||||
104 | QDBusServer::~QDBusServer() | - | ||||||
105 | { | - | ||||||
106 | QWriteLocker locker(&d->lock); | - | ||||||
107 | if (QDBusConnectionManager::instance()) {
| 0-20 | ||||||
108 | QMutexLocker locker(&QDBusConnectionManager::instance()->mutex); | - | ||||||
109 | Q_FOREACHfor (const QString &name ,: qAsConst(d->serverConnectionNames) {)) | - | ||||||
110 | QDBusConnectionManager::instance()->removeConnection(name);} executed 158 times by 6 tests: QDBusConnectionManager::instance()->removeConnection(name); Executed by:
| 158 | ||||||
111 | d->serverConnectionNames.clear(); | - | ||||||
112 | } executed 20 times by 6 tests: end of block Executed by:
| 20 | ||||||
113 | d->serverObject = Q_NULLPTR; | - | ||||||
114 | d->ref.store(0); | - | ||||||
115 | d->deleteLater(); | - | ||||||
116 | } executed 20 times by 6 tests: end of block Executed by:
| 20 | ||||||
117 | - | |||||||
118 | /*! | - | ||||||
119 | Returns \c true if this QDBusServer object is connected. | - | ||||||
120 | - | |||||||
121 | If it isn't connected, you need to call the constructor again. | - | ||||||
122 | */ | - | ||||||
123 | bool QDBusServer::isConnected() const | - | ||||||
124 | { | - | ||||||
125 | return d && d->server && q_dbus_server_get_is_connected(d->server); | - | ||||||
126 | } | - | ||||||
127 | - | |||||||
128 | /*! | - | ||||||
129 | Returns the last error that happened in this server. | - | ||||||
130 | - | |||||||
131 | This function is provided for low-level code. | - | ||||||
132 | */ | - | ||||||
133 | QDBusError QDBusServer::lastError() const | - | ||||||
134 | { | - | ||||||
135 | return d ? d->lastError : QDBusError(QDBusError::Disconnected, QDBusUtil::disconnectedErrorMessage()); | - | ||||||
136 | } | - | ||||||
137 | - | |||||||
138 | /*! | - | ||||||
139 | Returns the address this server is associated with. | - | ||||||
140 | */ | - | ||||||
141 | QString QDBusServer::address() const | - | ||||||
142 | { | - | ||||||
143 | QString addr; | - | ||||||
144 | if (d && d->server) { | - | ||||||
145 | char *c = q_dbus_server_get_address(d->server); | - | ||||||
146 | addr = QString::fromUtf8(c); | - | ||||||
147 | q_dbus_free(c); | - | ||||||
148 | } | - | ||||||
149 | - | |||||||
150 | return addr; | - | ||||||
151 | } | - | ||||||
152 | - | |||||||
153 | /*! | - | ||||||
154 | \since 5.3 | - | ||||||
155 | - | |||||||
156 | If \a value is set to true, an incoming connection can proceed even if the | - | ||||||
157 | connecting client is not authenticated as a user. | - | ||||||
158 | - | |||||||
159 | By default, this value is false. | - | ||||||
160 | - | |||||||
161 | \sa isAnonymousAuthenticationAllowed() | - | ||||||
162 | */ | - | ||||||
163 | void QDBusServer::setAnonymousAuthenticationAllowed(bool value) | - | ||||||
164 | { | - | ||||||
165 | d->anonymousAuthenticationAllowed = value; | - | ||||||
166 | } | - | ||||||
167 | - | |||||||
168 | /*! | - | ||||||
169 | \since 5.3 | - | ||||||
170 | - | |||||||
171 | Returns true if anonymous authentication is allowed. | - | ||||||
172 | - | |||||||
173 | \sa setAnonymousAuthenticationAllowed() | - | ||||||
174 | */ | - | ||||||
175 | bool QDBusServer::isAnonymousAuthenticationAllowed() const | - | ||||||
176 | { | - | ||||||
177 | return d->anonymousAuthenticationAllowed; | - | ||||||
178 | } | - | ||||||
179 | - | |||||||
180 | /*! | - | ||||||
181 | \fn void QDBusServer::newConnection(const QDBusConnection &connection) | - | ||||||
182 | - | |||||||
183 | This signal is emitted when a new client connection \a connection is | - | ||||||
184 | established to the server. | - | ||||||
185 | */ | - | ||||||
186 | - | |||||||
187 | QT_END_NAMESPACE | - | ||||||
188 | - | |||||||
189 | #include "moc_qdbusserver.cpp" | - | ||||||
190 | - | |||||||
191 | #endif // QT_NO_DBUS | - | ||||||
Source code | Switch to Preprocessed file |