swift
Loading...
Searching...
No Matches
swift::misc::CDBusServer Class Reference

Custom DBusServer. More...

#include <dbusserver.h>

Inheritance diagram for swift::misc::CDBusServer:
[legend]

Public Types

enum  ServerMode { SERVERMODE_P2P , SERVERMODE_SESSIONBUS , SERVERMODE_SYSTEMBUS }
 Server mode. More...
Public Types inherited from QObject
enum  TimerId

Public Member Functions

 CDBusServer (const QString &address, QObject *parent=nullptr)
 Construct a server for the core service.
 CDBusServer (const QString &service, const QString &address, QObject *parent=nullptr)
 Construct a server for some arbitrary service.
 ~CDBusServer ()
 Destructor.
void addObject (const QString &name, QObject *object)
 Add a QObject to be exposed via DBus.
QDBusError lastQDBusServerError () const
 Last error.
const QDBusServer * qDBusServer () const
 DBus server (if using P2P).
bool hasQDBusServer () const
 True if using P2P.
void removeAllObjects ()
 Remove all objects added with addObject.
Public Member Functions inherited from QObject
QBindable< QString > bindableObjectName ()
 QObject (QObject *parent)
 QT_NO_CONTEXTLESS_CONNECT QT_NO_CONTEXTLESS_CONNECT
 QT_NO_NARROWING_CONVERSIONS_IN_CONNECT QT_NO_NARROWING_CONVERSIONS_IN_CONNECT
 Q_CLASSINFO (Name, Value)
 Q_EMIT Q_EMIT
 Q_ENUM (...)
 Q_ENUMS (...)
 Q_ENUM_NS (...)
 Q_FLAG (...)
 Q_FLAGS (...)
 Q_FLAG_NS (...)
 Q_GADGET Q_GADGET
 Q_GADGET_EXPORT (EXPORT_MACRO)
 Q_INTERFACES (...)
 Q_INVOKABLE Q_INVOKABLE
 Q_MOC_INCLUDE Q_MOC_INCLUDE
 Q_NAMESPACE Q_NAMESPACE
 Q_NAMESPACE_EXPORT (EXPORT_MACRO)
 Q_OBJECT Q_OBJECT
 Q_PROPERTY (...)
 Q_REVISION Q_REVISION
 Q_SET_OBJECT_NAME (Object)
 Q_SIGNAL Q_SIGNAL
 Q_SIGNALS Q_SIGNALS
 Q_SLOT Q_SLOT
 Q_SLOTS Q_SLOTS
T qobject_cast (QObject *object)
T qobject_cast (const QObject *object)
bool blockSignals (bool block)
virtual bool event (QEvent *e)
virtual bool eventFilter (QObject *watched, QEvent *event)
bool moveToThread (QThread *targetThread)
bool setProperty (const char *name, QVariant &&value)
bool setProperty (const char *name, const QVariant &value)
int startTimer (int interval, Qt::TimerType timerType)
int startTimer (std::chrono::nanoseconds interval, Qt::TimerType timerType)
void deleteLater ()
void destroyed (QObject *obj)
void installEventFilter (QObject *filterObj)
void killTimer (Qt::TimerId id)
void killTimer (int id)
void objectNameChanged (const QString &objectName)
void removeEventFilter (QObject *obj)
void setObjectName (QAnyStringView name)
void setObjectName (const QString &name)
void setParent (QObject *parent)
QList< QByteArray > dynamicPropertyNames () const const
QList< T > findChildren (QAnyStringView name, Qt::FindChildOptions options) const const
QList< T > findChildren (Qt::FindChildOptions options) const const
QList< T > findChildren (const QRegularExpression &re, Qt::FindChildOptions options) const const
QMetaObject::Connection connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const const
QObject * parent () const const
QString objectName () const const
QThread * thread () const const
QVariant property (const char *name) const const
T findChild (QAnyStringView name, Qt::FindChildOptions options) const const
T findChild (Qt::FindChildOptions options) const const
bool disconnect (const QObject *receiver, const char *method) const const
bool disconnect (const char *signal, const QObject *receiver, const char *method) const const
bool inherits (const char *className) const const
bool isQmlExposed () const const
bool isQuickItemType () const const
bool isWidgetType () const const
bool isWindowType () const const
bool signalsBlocked () const const
virtual const QMetaObject * metaObject () const const
const QObjectList & children () const const
void dumpObjectInfo () const const
void dumpObjectTree () const const

Static Public Member Functions

static const QString & coreServiceName ()
 Default service name.
static const QString & coreServiceName (const QDBusConnection &connection)
 Service name, empty if is P2P connection.
static const QStringList & getLogCategories ()
 Log categories.
static const QDBusConnection & defaultConnection ()
 Default connection.
static const QString & sessionBusAddress ()
 Address denoting a session bus server.
static const QString & systemBusAddress ()
 Address denoting a system bus server.
static QDBusConnection connectToDBus (const QString &dbusAddress, const QString &name={})
 Connect to DBus.
static void disconnectFromDBus (const QDBusConnection &connection, const QString &dBusAddress)
 Disconnect from Bus/Peer to peer.
static QString p2pAddress (const QString &host, const QString &port="")
 Address denoting a P2P server at the given host and port.
static const QString & p2pConnectionName ()
 P2P connection name.
static QString normalizeAddress (const QString &address)
 Turn something like 127.0.0.1:45000 into "tcp:host=127.0.0.1,port=45000".
static ServerMode modeOfAddress (QString address)
 Return the server mode of the given address.
static const QString & modeToString (ServerMode mode)
 Mode to string.
static bool isQtDBusAddress (const QString &address)
 True if a valid Qt DBus address, e.g. "unix:tmpdir=/tmp", "tcp:host=127.0.0.1,port=45000".
static bool isSessionOrSystemAddress (const QString &address)
 True if address is session or system bus address.
static bool isP2PAddress (const QString &address)
 False if address is session or system bus address.
static bool isP2PConnection (const QDBusConnection &connection)
 False if address is session or system bus connection.
static bool dBusAddressToHostAndPort (const QString &dbusAddress, QString &o_host, int &o_port)
 Extract host and port from a DBus address.
static bool dBusAddressToHostAndPort (const QString &dbusAddress, QString &o_host, QString &o_port)
 Extract host and port from a DBus address.
static bool isQtDefaultConnection (const QDBusConnection &connection)
 Is the given connection one of the default connections?
static bool isDBusAvailable (const QString &host, int port, int timeoutMs=1500)
 Is there a DBus server running at the given address?
static bool isDBusAvailable (const QString &host, int port, QString &message, int timeoutMs=1500)
 Is there a DBus server running at the given address?
static bool isDBusAvailable (const QString &dbusAddress, QString &message, int timeoutMs=1500)
 Is there a DBus server running at the given address?
static bool isDBusAvailable (const QString &dbusAddress, int timeoutMs=1500)
 Is there a DBus server running at the given address?
Static Public Member Functions inherited from QObject
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, Functor functor)
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *context, Functor functor, Qt::ConnectionType type)
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType type)
QMetaObject::Connection connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type)
QMetaObject::Connection connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QString tr (const char *sourceText, const char *disambiguation, int n)
bool disconnect (const QMetaObject::Connection &connection)
bool disconnect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method)
bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method)
bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method)

Additional Inherited Members

Public Attributes inherited from QObject
typedef QObjectList
 Invalid
Protected Member Functions inherited from QObject
virtual void childEvent (QChildEvent *event)
virtual void connectNotify (const QMetaMethod &signal)
virtual void customEvent (QEvent *event)
virtual void disconnectNotify (const QMetaMethod &signal)
virtual void timerEvent (QTimerEvent *event)
QObject * sender () const const
bool isSignalConnected (const QMetaMethod &signal) const const
int receivers (const char *signal) const const
int senderSignalIndex () const const
Properties inherited from QObject
 objectName

Detailed Description

Custom DBusServer.

This class implements a custom DBusServer for DBus peer connections, but can also be used with session or system bus. For session/system bus this class represents no real server, but more a wrapper for QDBusConnection and object registration.

Definition at line 33 of file dbusserver.h.

Member Enumeration Documentation

◆ ServerMode

Server mode.

Definition at line 48 of file dbusserver.h.

Constructor & Destructor Documentation

◆ CDBusServer() [1/2]

swift::misc::CDBusServer::CDBusServer ( const QString & address,
QObject * parent = nullptr )
inline

Construct a server for the core service.

Definition at line 56 of file dbusserver.h.

◆ CDBusServer() [2/2]

swift::misc::CDBusServer::CDBusServer ( const QString & service,
const QString & address,
QObject * parent = nullptr )

Construct a server for some arbitrary service.

Definition at line 20 of file dbusserver.cpp.

◆ ~CDBusServer()

swift::misc::CDBusServer::~CDBusServer ( )

Destructor.

Definition at line 95 of file dbusserver.cpp.

Member Function Documentation

◆ addObject()

void swift::misc::CDBusServer::addObject ( const QString & name,
QObject * object )

Add a QObject to be exposed via DBus.

Definition at line 247 of file dbusserver.cpp.

◆ connectToDBus()

QDBusConnection swift::misc::CDBusServer::connectToDBus ( const QString & dbusAddress,
const QString & name = {} )
static

Connect to DBus.

Definition at line 361 of file dbusserver.cpp.

◆ coreServiceName() [1/2]

const QString & swift::misc::CDBusServer::coreServiceName ( )
static

Default service name.

Definition at line 101 of file dbusserver.cpp.

◆ coreServiceName() [2/2]

const QString & swift::misc::CDBusServer::coreServiceName ( const QDBusConnection & connection)
static

Service name, empty if is P2P connection.

Definition at line 107 of file dbusserver.cpp.

◆ dBusAddressToHostAndPort() [1/2]

bool swift::misc::CDBusServer::dBusAddressToHostAndPort ( const QString & dbusAddress,
QString & o_host,
int & o_port )
static

Extract host and port from a DBus address.

Definition at line 130 of file dbusserver.cpp.

◆ dBusAddressToHostAndPort() [2/2]

bool swift::misc::CDBusServer::dBusAddressToHostAndPort ( const QString & dbusAddress,
QString & o_host,
QString & o_port )
static

Extract host and port from a DBus address.

Definition at line 174 of file dbusserver.cpp.

◆ defaultConnection()

const QDBusConnection & swift::misc::CDBusServer::defaultConnection ( )
static

Default connection.

Definition at line 343 of file dbusserver.cpp.

◆ disconnectFromDBus()

void swift::misc::CDBusServer::disconnectFromDBus ( const QDBusConnection & connection,
const QString & dBusAddress )
static

Disconnect from Bus/Peer to peer.

Definition at line 381 of file dbusserver.cpp.

◆ getLogCategories()

const QStringList & swift::misc::CDBusServer::getLogCategories ( )
static

Log categories.

Definition at line 113 of file dbusserver.cpp.

◆ hasQDBusServer()

bool swift::misc::CDBusServer::hasQDBusServer ( ) const

True if using P2P.

Definition at line 322 of file dbusserver.cpp.

◆ isDBusAvailable() [1/4]

bool swift::misc::CDBusServer::isDBusAvailable ( const QString & dbusAddress,
int timeoutMs = 1500 )
static

Is there a DBus server running at the given address?

Note
This is an incomplete test showing too optimistic results for session DBus

Definition at line 547 of file dbusserver.cpp.

◆ isDBusAvailable() [2/4]

bool swift::misc::CDBusServer::isDBusAvailable ( const QString & dbusAddress,
QString & message,
int timeoutMs = 1500 )
static

Is there a DBus server running at the given address?

Note
This is an incomplete test showing too optimistic results for session DBus

Definition at line 522 of file dbusserver.cpp.

◆ isDBusAvailable() [3/4]

bool swift::misc::CDBusServer::isDBusAvailable ( const QString & host,
int port,
int timeoutMs = 1500 )
static

Is there a DBus server running at the given address?

Note
This is an incomplete test showing too optimistic results for session DBus

Definition at line 511 of file dbusserver.cpp.

◆ isDBusAvailable() [4/4]

bool swift::misc::CDBusServer::isDBusAvailable ( const QString & host,
int port,
QString & message,
int timeoutMs = 1500 )
static

Is there a DBus server running at the given address?

Note
This is an incomplete test showing too optimistic results for session DBus

Definition at line 517 of file dbusserver.cpp.

◆ isP2PAddress()

bool swift::misc::CDBusServer::isP2PAddress ( const QString & address)
static

False if address is session or system bus address.

Definition at line 119 of file dbusserver.cpp.

◆ isP2PConnection()

bool swift::misc::CDBusServer::isP2PConnection ( const QDBusConnection & connection)
static

False if address is session or system bus connection.

Definition at line 121 of file dbusserver.cpp.

◆ isQtDBusAddress()

bool swift::misc::CDBusServer::isQtDBusAddress ( const QString & address)
static

True if a valid Qt DBus address, e.g. "unix:tmpdir=/tmp", "tcp:host=127.0.0.1,port=45000".

Definition at line 188 of file dbusserver.cpp.

◆ isQtDefaultConnection()

bool swift::misc::CDBusServer::isQtDefaultConnection ( const QDBusConnection & connection)
static

Is the given connection one of the default connections?

Definition at line 182 of file dbusserver.cpp.

◆ isSessionOrSystemAddress()

bool swift::misc::CDBusServer::isSessionOrSystemAddress ( const QString & address)
static

True if address is session or system bus address.

Remarks
actually swift does NOT support system DBus anymore

Definition at line 193 of file dbusserver.cpp.

◆ lastQDBusServerError()

QDBusError swift::misc::CDBusServer::lastQDBusServerError ( ) const

Last error.

Definition at line 311 of file dbusserver.cpp.

◆ modeOfAddress()

CDBusServer::ServerMode swift::misc::CDBusServer::modeOfAddress ( QString address)
static

Return the server mode of the given address.

Definition at line 478 of file dbusserver.cpp.

◆ modeToString()

const QString & swift::misc::CDBusServer::modeToString ( CDBusServer::ServerMode mode)
static

Mode to string.

Definition at line 495 of file dbusserver.cpp.

◆ normalizeAddress()

QString swift::misc::CDBusServer::normalizeAddress ( const QString & address)
static

Turn something like 127.0.0.1:45000 into "tcp:host=127.0.0.1,port=45000".

Note
Handles also "session" and "system" as valid address while CDBusServer::p2pAddress is for P2P addresses only.

Definition at line 447 of file dbusserver.cpp.

◆ p2pAddress()

QString swift::misc::CDBusServer::p2pAddress ( const QString & host,
const QString & port = "" )
static

Address denoting a P2P server at the given host and port.

Remarks
Port number may be embedding in the host string after a colon.
Returns
p2p address like "tcp:host=foo.bar.com,port=1234"

Definition at line 394 of file dbusserver.cpp.

◆ p2pConnectionName()

const QString & swift::misc::CDBusServer::p2pConnectionName ( )
static

P2P connection name.

Definition at line 441 of file dbusserver.cpp.

◆ qDBusServer()

const QDBusServer * swift::misc::CDBusServer::qDBusServer ( ) const

DBus server (if using P2P).

Definition at line 320 of file dbusserver.cpp.

◆ removeAllObjects()

void swift::misc::CDBusServer::removeAllObjects ( )

Remove all objects added with addObject.

Definition at line 324 of file dbusserver.cpp.

◆ sessionBusAddress()

const QString & swift::misc::CDBusServer::sessionBusAddress ( )
static

Address denoting a session bus server.

Definition at line 349 of file dbusserver.cpp.

◆ systemBusAddress()

const QString & swift::misc::CDBusServer::systemBusAddress ( )
static

Address denoting a system bus server.

Definition at line 355 of file dbusserver.cpp.


The documentation for this class was generated from the following files: