- Added CDBusServer into Blackcore library
- Added DBus server and client sample
This commit is contained in:
Roland Winklmeier
2013-07-22 22:44:00 +02:00
parent 1c5293f38f
commit 40abcf4c19
28 changed files with 729 additions and 1 deletions

View File

@@ -1,5 +1,5 @@
# GUI is required for the matrix classes
QT += network
QT += network dbus
TARGET = blackcore
TEMPLATE = lib

View File

@@ -0,0 +1,56 @@
#include <QDebug>
#include "dbusserver.h"
namespace BlackCore
{
// TODO:
// - Change constructor to use address from the config file
// - Ammend debug message according to the final result in the forum discussion
CDBusServer::CDBusServer(QObject *parent) :
QObject(parent), m_busServer("tcp:host=127.0.0.1,port=6668", parent)
{
if (!m_busServer.isConnected())
{
qWarning() << m_busServer.lastError().message();
}
else
{
qDebug() << "Server is running on" << m_busServer.address();
}
connect(&m_busServer, &QDBusServer::newConnection, this, &CDBusServer::newConnection);
}
void CDBusServer::newConnection(const QDBusConnection & connection)
{
QMap<QString, QObject*>::ConstIterator i = m_objects.begin();
QDBusConnection newConnection(connection);
m_DBusConnections.insert(newConnection.name(), newConnection);
qDebug() << "New Connection from: " << newConnection.name();
while (i != m_objects.end())
{
qDebug() << "Adding " << i.key() << "to the new connection.";
newConnection.registerObject(i.key(), i.value());
++i;
}
}
void CDBusServer::addObject(const QString &name, QObject *object)
{
m_objects.insert(name, object);
}
void CDBusServer::printError()
{
qWarning() << m_busServer.lastError().name();
}
} // namespace BlackCore

View File

@@ -0,0 +1,51 @@
#ifndef BLACKCORE_DBUSSERVER_H
#define BLACKCORE_DBUSSERVER_H
#include <QObject>
#include <QtDBus/QDBusServer>
#include <QtDBus/QDBusError>
#include <QtDBus/QDBusConnection>
#include <QStringList>
#include <QMap>
namespace BlackCore
{
class CDBusServer : public QObject
{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "org.vatsim.pilotClient")
private:
QDBusServer m_busServer; //!< QDBusServer implementation
QMap<QString, QObject*> m_objects; //!< Mapping of all exposed objects
QMap<QString, QDBusConnection> m_DBusConnections; //!< Mapping of all DBusConnection objects
public:
/*!
* \brief Constructor
* \param parent
*/
CDBusServer(QObject *parent = 0);
/*!
* \brief Adds a QObject to be exposed to DBus
* \param name
* \param object
*/
void addObject(const QString &name, QObject *object);
void printError();
public slots:
void newConnection(const QDBusConnection & connection);
};
} // namespace BlackCore
#endif // BLACKCORE_DBUSSERVER_H