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