Home · Modules · Classes · Namespaces · Functions

QxtRPCService Class Reference
[QxtCore module]

The QxtRPCService class transmits Qt signals over a QIODevice More...

    #include <QxtRPCService>

Inherits QObject.

Inherited by QxtRPCPeer.

Public Functions

Public Slots

Additional Inherited Members


Detailed Description

The QxtRPCService class transmits Qt signals over a QIODevice

QxtRPCService is a tool that encapsulates Qt signals and transmits them over a QIODevice. The signal is subsequently re-emitted on the receiving end of the connection.

QxtRPCService can act as a client or a server. When acting as a server, it uses a QxtAbstractConnectionManager to accept connections. When acting as a client, the application should provide an already-connected QIODevice to the setDevice() function.

All data types used in attached signals and slots must be declared and registered with QMetaType using Q_DECLARE_METATYPE and qRegisterMetaType. Additional requirements may be imposed by the QxtAbstractSignalSerializer subclass in use; the default (QxtDataStreamSignalSerializer) requires that they have stream operators registered with qRegisterMetaTypeStreamOperators.

Due to a restriction of Qt's signals and slots mechanism, the number of parameters that can be passed to call() and its related functions, as well as the number of parameters to any signal or slot attached to QxtRPCService, is limited to 8.


Member Function Documentation

QxtRPCService::QxtRPCService ( QObject * parent = 0 )

Creates a QxtRPCService object with the given parent.

QxtRPCService::QxtRPCService ( QIODevice * device, QObject * parent = 0 )

Creates a QxtRPCService object with the given parent and connects it to the specified I/O device.

The I/O device must already be opened for reading and writing.

QxtRPCService::~QxtRPCService ()   [virtual]

Destroys the QxtRPCService object.

bool QxtRPCService::attachSignal ( QObject * sender, const char * signal, const QString & rpcFunction = QString() )

Attaches the given signal.

When the attached signal is emitted by sender, it will be transmitted to all connected servers, clients, or peers. If an optional rpcFunction is provided, it will be used in place of the name of the transmitted signal. Use the SIGNAL() macro to specify the signal, just as you would for QObject::connect().

Like QObject::connect(), attachSignal() returns false if the connection cannot be established.

bool QxtRPCService::attachSlot ( const QString & rpcFunction, QObject * recv, const char * slot, Qt::ConnectionType type = Qt::AutoConnection )

Attaches an RPC function to the given slot.

When a signal with the name given by rpcFunction is received from the network, the attached slot is executed. Use the SLOT() macro to specify the slot, just as you would for QObject::connect().

Like QObject::connect(), attachSlot() returns false if the connection cannot be established. Also like QObject::connect(), a signal may be used as a slot; invocation will cause the signal to be emitted.

Note: When acting like a server, the first parameter of the slot must be <b>quint64 id</b>. The parameters of the incoming signal follow. For example, SIGNAL(mySignal(QString)) from the client connects to SLOT(mySlot(quint64, QString)) on the server.

void QxtRPCService::call ( QString fn, const QVariant & p1 = QVariant(), const QVariant & p2 = QVariant(), const QVariant & p3 = QVariant(), const QVariant & p4 = QVariant(), const QVariant & p5 = QVariant(), const QVariant & p6 = QVariant(), const QVariant & p7 = QVariant(), const QVariant & p8 = QVariant() )   [slot]

Sends the signal fn with the given parameter list to the server, or to all connected clients.

The receiver is not obligated to act upon the signal. If no clients are connected, and if not communicating with a server, this function does nothing.

void QxtRPCService::call ( QList<quint64> ids, QString fn, const QVariant & p1 = QVariant(), const QVariant & p2 = QVariant(), const QVariant & p3 = QVariant(), const QVariant & p4 = QVariant(), const QVariant & p5 = QVariant(), const QVariant & p6 = QVariant(), const QVariant & p7 = QVariant(), const QVariant & p8 = QVariant() )   [slot]

Sends the signal fn with the given parameter list to the provided list of clients.

The receivers are not obligated to act upon the signal. If no client is connected with a provided ID, the ID is ignored with a warning. If acting as a client, this function does nothing.

void QxtRPCService::call ( quint64 id, QString fn, const QVariant & p1 = QVariant(), const QVariant & p2 = QVariant(), const QVariant & p3 = QVariant(), const QVariant & p4 = QVariant(), const QVariant & p5 = QVariant(), const QVariant & p6 = QVariant(), const QVariant & p7 = QVariant(), const QVariant & p8 = QVariant() )   [slot]

Sends the signal fn with the given parameter list to the specified client.

The receiver is not obligated to act upon the signal. If no client with the given ID is connected, the call will be ignored with a warning. If acting as a client, this function does nothing.

void QxtRPCService::callExcept ( quint64 id, QString fn, const QVariant & p1 = QVariant(), const QVariant & p2 = QVariant(), const QVariant & p3 = QVariant(), const QVariant & p4 = QVariant(), const QVariant & p5 = QVariant(), const QVariant & p6 = QVariant(), const QVariant & p7 = QVariant(), const QVariant & p8 = QVariant() )   [slot]

Sends the signal fn with the given parameter list to all connected clients except for the client specified.

The receiver is not obligated to act upon the signal. This function is useful for rebroadcasting a signal from one client to all other connected clients. If acting as a client, this function does nothing.

QList<quint64> QxtRPCService::clients () const

Returns a list of client IDs for all connected clients.

QxtAbstractConnectionManager * QxtRPCService::connectionManager () const

Returns the connection manager used to accept incoming connections.

See also setConnectionManager().

void QxtRPCService::detachObject ( QObject * obj )

Detaches all signals and slots for the given object obj.

void QxtRPCService::detachSender ()   [slot]

Detaches all signals and slots for the object that emitted the signal connected to detachSender().

void QxtRPCService::detachSignals ( QObject * obj )

Detaches all signals for the given object obj.

void QxtRPCService::detachSlots ( QObject * obj )

* Detaches all slots for the given object obj.

QIODevice * QxtRPCService::device () const

When operating as a client, returns the QIODevice connected to the server. When operating as a server, or if not connected to a server, returns NULL.

See also setDevice() and takeDevice().

void QxtRPCService::disconnectAll ()   [slot]

Disconnects all clients, or disconnects from the server.

void QxtRPCService::disconnectClient ( quint64 id )   [slot]

Disconnects a client with id using the attached connection manager.

If connected to a server, this function is ignored with a warning.

void QxtRPCService::disconnectServer ()   [slot]

Disconnects from the server. The QIODevice is deleted. Use takeDevice() to disconnect from the server without deleting the device.

If not connected to a server, for instance if acting as a server, this function is ignored with a warning.

See also device() and takeDevice().

bool QxtRPCService::isClient () const

Returns true if the QxtRPCService is currently communicating with a server. It is possible for both isServer() and isClient() to return false if the connection manager is not accepting connections, no clients are connected, and no QIODevice is set for a server.

See also isServer().

bool QxtRPCService::isServer () const

Returns true if the connection manager is accepting connections or if any clients are currently connected. It is possible for both isServer() and isClient() to return false if the connection manager is not accepting connections, no clients are connected, and no QIODevice is set for a server.

See also isClient().

QxtAbstractSignalSerializer * QxtRPCService::serializer () const

Returns the signal serializer used to encode signals before transmission.

See also setSerializer().

void QxtRPCService::setConnectionManager ( QxtAbstractConnectionManager * manager )

Sets the connection manager used to accept incoming connections. The existing manager will be deleted and the provided manager will be reparented to the QxtRPCService.

See also connectionManager().

void QxtRPCService::setDevice ( QIODevice * dev )

Begins communicating with a server through the provided QIODevice dev. If called while acting as a server, this function is ignored with a warning. If called while another device is set, the original QIODevice is deleted. The provided device will be reparented to the QxtRPCService.

Note that because QIODevice is a generic interface, QxtRPCService cannot provide signals when this device is disconnected or has low-level errors. Connect to the QIODevice subclass's signals directly if you need this information.

See also device().

void QxtRPCService::setSerializer ( QxtAbstractSignalSerializer * serializer )

Sets the signal serializer used to encode signals before transmission. The existing serializer will be deleted.

See also serializer().

QIODevice * QxtRPCService::takeDevice ()

When operating as a client, returns the QIODevice used to communicate with the server. After this function is called, the QxtRPCService will no longer be connected and device() will return NULL. When operating as a server, or if not connected to a server, this function returns NULL without any other effect.

See also device().


Copyright © 2007-2011 Qxt Foundation
Qxt 0.6.2