[2] | 1 | /****************************************************************************
|
---|
| 2 | **
|
---|
[846] | 3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
[561] | 4 | ** All rights reserved.
|
---|
| 5 | ** Contact: Nokia Corporation ([email protected])
|
---|
[2] | 6 | **
|
---|
| 7 | ** This file is part of the QtDBus module of the Qt Toolkit.
|
---|
| 8 | **
|
---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
| 10 | ** Commercial Usage
|
---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
| 14 | ** a written agreement between you and Nokia.
|
---|
| 15 | **
|
---|
| 16 | ** GNU Lesser General Public License Usage
|
---|
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
| 18 | ** General Public License version 2.1 as published by the Free Software
|
---|
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
| 20 | ** packaging of this file. Please review the following information to
|
---|
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
| 23 | **
|
---|
[561] | 24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
---|
[2] | 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 | **
|
---|
[561] | 36 | ** If you have questions regarding the use of this file, please contact
|
---|
| 37 | ** Nokia at [email protected].
|
---|
[2] | 38 | ** $QT_END_LICENSE$
|
---|
| 39 | **
|
---|
| 40 | ****************************************************************************/
|
---|
| 41 |
|
---|
| 42 | #include "qdbusserver.h"
|
---|
| 43 | #include "qdbusconnection_p.h"
|
---|
| 44 |
|
---|
[846] | 45 | #ifndef QT_NO_DBUS
|
---|
| 46 |
|
---|
[2] | 47 | QT_BEGIN_NAMESPACE
|
---|
| 48 |
|
---|
| 49 | /*!
|
---|
| 50 | \class QDBusServer
|
---|
| 51 | \inmodule QtDBus
|
---|
[846] | 52 | \internal
|
---|
[2] | 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)
|
---|
| 64 | {
|
---|
| 65 | if (!qdbus_loadLibDBus()) {
|
---|
| 66 | d = 0;
|
---|
| 67 | return;
|
---|
| 68 | }
|
---|
| 69 | d = new QDBusConnectionPrivate(this);
|
---|
| 70 |
|
---|
| 71 | if (address.isEmpty())
|
---|
| 72 | return;
|
---|
| 73 |
|
---|
[561] | 74 | QObject::connect(d, SIGNAL(newServerConnection(QDBusConnection)),
|
---|
| 75 | this, SIGNAL(newConnection(QDBusConnection)));
|
---|
[2] | 76 |
|
---|
| 77 | // server = q_dbus_server_listen( "unix:tmpdir=/tmp", &error);
|
---|
| 78 | QDBusErrorInternal error;
|
---|
| 79 | d->setServer(q_dbus_server_listen(address.toUtf8().constData(), error), error);
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 | /*!
|
---|
| 83 | Returns true if this QDBusServer object is connected.
|
---|
| 84 |
|
---|
| 85 | If it isn't connected, you need to call the constructor again.
|
---|
| 86 | */
|
---|
| 87 | bool QDBusServer::isConnected() const
|
---|
| 88 | {
|
---|
| 89 | return d && d->server && q_dbus_server_get_is_connected(d->server);
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | /*!
|
---|
| 93 | Returns the last error that happened in this server.
|
---|
| 94 |
|
---|
| 95 | This function is provided for low-level code.
|
---|
| 96 | */
|
---|
| 97 | QDBusError QDBusServer::lastError() const
|
---|
| 98 | {
|
---|
| 99 | return d->lastError;
|
---|
| 100 | }
|
---|
| 101 |
|
---|
| 102 | /*!
|
---|
[846] | 103 | Returns the address this server is associated with.
|
---|
[2] | 104 | */
|
---|
| 105 | QString QDBusServer::address() const
|
---|
| 106 | {
|
---|
| 107 | QString addr;
|
---|
| 108 | if (d && d->server) {
|
---|
| 109 | char *c = q_dbus_server_get_address(d->server);
|
---|
| 110 | addr = QString::fromUtf8(c);
|
---|
| 111 | q_dbus_free(c);
|
---|
| 112 | }
|
---|
| 113 |
|
---|
| 114 | return addr;
|
---|
| 115 | }
|
---|
| 116 | /*!
|
---|
| 117 | \fn void QDBusServer::newConnection(const QDBusConnection &connection)
|
---|
| 118 |
|
---|
| 119 | This signal is currently not used, but if and when it is
|
---|
| 120 | used, \a connection will be the new connection.
|
---|
| 121 | */
|
---|
| 122 |
|
---|
| 123 | QT_END_NAMESPACE
|
---|
[846] | 124 |
|
---|
| 125 | #endif // QT_NO_DBUS
|
---|