swift
Public Types | Public Member Functions | Static Public Member Functions | List of all members
swift::misc::CDBusServer Class Reference

Custom DBusServer. More...

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

Public Types

enum  ServerMode { SERVERMODE_P2P , SERVERMODE_SESSIONBUS , SERVERMODE_SYSTEMBUS }
 Server mode.
 

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.
 
virtual ~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.
 

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. More...
 
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". More...
 
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. More...
 
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? More...
 
static bool isDBusAvailable (const QString &host, int port, QString &message, int timeoutMs=1500)
 Is there a DBus server running at the given address? More...
 
static bool isDBusAvailable (const QString &dbusAddress, QString &message, int timeoutMs=1500)
 Is there a DBus server running at the given address? More...
 
static bool isDBusAvailable (const QString &dbusAddress, int timeoutMs=1500)
 Is there a DBus server running at the given address? More...
 

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 Function Documentation

◆ 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 481 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 456 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 445 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 451 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 178 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 405 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 358 of file dbusserver.cpp.


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