Qt 4.8
qdbusserver.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtDBus module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qdbusserver.h"
43 #include "qdbusconnection_p.h"
45 
46 #ifndef QT_NO_DBUS
47 
49 
66 QDBusServer::QDBusServer(const QString &address, QObject *parent)
67  : QObject(parent)
68 {
69  if (address.isEmpty())
70  return;
71 
72  if (!qdbus_loadLibDBus()) {
73  d = 0;
74  return;
75  }
76  d = new QDBusConnectionPrivate(this);
77 
78  QObject::connect(d, SIGNAL(newServerConnection(QDBusConnection)),
80 
82  d->setServer(q_dbus_server_listen(address.toUtf8().constData(), error), error);
83 }
84 
89 {
94  }
96  }
97 }
98 
105 {
106  return d && d->server && q_dbus_server_get_is_connected(d->server);
107 }
108 
115 {
116  return d->lastError;
117 }
118 
123 {
124  QString addr;
125  if (d && d->server) {
126  char *c = q_dbus_server_get_address(d->server);
127  addr = QString::fromUtf8(c);
128  q_dbus_free(c);
129  }
130 
131  return addr;
132 }
133 
145 
146 #endif // QT_NO_DBUS
QDBusError lastError() const
Returns the last error that happened in this server.
void setServer(DBusServer *server, const QDBusErrorInternal &error)
unsigned char c[8]
Definition: qnumeric_p.h:62
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
void removeConnection(const QString &name)
QDBusServer(const QString &address=QLatin1String("unix:tmpdir=/tmp"), QObject *parent=0)
Constructs a QDBusServer with the given address, and the given parent.
Definition: qdbusserver.cpp:66
QByteArray toUtf8() const Q_REQUIRED_RESULT
Returns a UTF-8 representation of the string as a QByteArray.
Definition: qstring.cpp:4074
#define error(msg)
QDBusConnectionPrivate * d
Definition: qdbusserver.h:76
The QDBusError class represents an error received from the D-Bus bus or from remote applications foun...
Definition: qdbuserror.h:60
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
QString address() const
Returns the address this server is associated with.
static QDBusConnectionManager * instance()
#define SIGNAL(a)
Definition: qobjectdefs.h:227
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
const char * name
static QString fromUtf8(const char *, int size=-1)
Returns a QString initialized with the first size bytes of the UTF-8 string str.
Definition: qstring.cpp:4302
virtual ~QDBusServer()
Destructs a QDBusServer.
Definition: qdbusserver.cpp:88
void clear()
Removes all items from the list.
Definition: qlist.h:764
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
bool isConnected() const
Returns true if this QDBusServer object is connected.
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
The QDBusConnection class represents a connection to the D-Bus bus daemon.
void newConnection(const QDBusConnection &connection)
This signal is emitted when a new client connection connection is established to the server...
bool qdbus_loadLibDBus()
#define Q_FOREACH(variable, container)
Same as foreach(variable, container).
Definition: qglobal.h:2435