Home · All Classes · alphabetical Classes List · Modules · Functions ·

QxtRPCPeer Class Reference
[Network]

Transmits Qt signals over a network connection. More...

Public Types

Public Slots

Signals

Public Member Functions

Protected Member Functions


Detailed Description

Transmits Qt signals over a network connection.

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

QxtRPCPeer can operate in peer-to-peer mode (that is, one-to-one) or client-server (that is, one-to-many) mode. In peer or server mode, QxtRPCPeer can listen for and accept incoming connections. In peer or client mode, QxtRPCPeer can connect to a listening peer or server.

All data types used in attached signals and slots must be declared and registered with QMetaType using Q_DECLARE_METATYPE and qRegisterMetaType, and they must have stream operators registered with qRegisterMetaTypeStreamOperators.

The limits on the number of parameters passed to call() and related functions are a restriction of Qt, which limits parameters on a signal or slot to 10.


Member Enumeration Documentation

enum QxtRPCPeer::RPCTypes

This enum is used with the setRPCType() to describe the role played in a connection. It is also returned by rpcType().

Enumerator:
Server  Listen for clients and accept multiple connections.
Client  Connect to a server.
Peer  Listen for a connection or connect to a peer.



Constructor & Destructor Documentation

QxtRPCPeer::QxtRPCPeer ( QObject *  parent = 0 )

Creates a QxtRPCPeer object with the given parent.



Member Function Documentation

void QxtRPCPeer::setRPCType ( RPCTypes  type )

Sets the RPC type.

Attempting to change the RPC type while listening or connected will be ignored with a warning.


QxtRPCPeer::RPCTypes QxtRPCPeer::rpcType ( ) const

Returns the current RPC type.


void QxtRPCPeer::connect ( QHostAddress  addr, int  port = 80 )

Connects to the specified peer or server on the selected port.

When the connection is complete, the peerConnected() signal will be emitted. If an error occurs, the peerError() signal will be emitted.


bool QxtRPCPeer::listen ( QHostAddress  iface = QHostAddress::Any, int  port = 80 )

Listens on the specified interface on the specified port for connections.

Attempting to listen while in Client mode or while connected in Peer mode will be ignored with a warning. In Peer mode, only one connection can be active at a time. Additional incoming connections while connected to a peer will be dropped. When a peer connects, the peerConnected() signal will be emitted. In Server mode, multiple connections can be active at a time. Each client that connects will be provided a unique ID, included in the clientConnected() signal that will be emitted.


void QxtRPCPeer::disconnectPeer ( quint64  id = -1 )

Disconnects from a server, client, or peer.

Servers must provide a client ID, provided by the clientConnected() signal; clients and peers must not.


void QxtRPCPeer::disconnectAll ( )

Disconnects from all clients, or from the server or peer.


void QxtRPCPeer::stopListening ( )

Stops listening for connections. Any connections still open will remain connected.


QList< quint64 > QxtRPCPeer::clients ( ) const

Returns a list of client IDs for all connected clients.


void QxtRPCPeer::attachSignal ( QObject *  sender, const char *  signal, QString  rpcFunction = QString() )

Attaches the given signal.

When the attached signal is emitted, 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().


void QxtRPCPeer::attachSlot ( QString  rpcFunction, QObject *  recv, const char *  slot )

Attaches 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().

Note:
In Server mode, the first parameter of the slot must be int id. The parameters of the signal follow. For example, SIGNAL(mySignal(QString)) from the client connects to SLOT(mySlot(int, QString)) on the server.


void QxtRPCPeer::detachObject ( QObject *  obj )

Detaches all signals and slots for the given object.


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

Sends the signal fn with the given parameter list to the server or peer.

This function accepts up to 9 QVariant parameters.

The receiver is not obligated to act upon the signal. If no server or peer is connected, the call is ignored. In particular, this function does nothing in Server mode.


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

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

This function accepts up to 8 QVariant parameters.

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.


void QxtRPCPeer::callClient ( quint64  id, QString  fn, QVariant  p1 = QVariant(), QVariant  p2 = QVariant(), QVariant  p3 = QVariant(), QVariant  p4 = QVariant(), QVariant  p5 = QVariant(), QVariant  p6 = QVariant(), QVariant  p7 = QVariant(), QVariant  p8 = QVariant() ) [slot]

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

This function accepts up to 8 QVariant parameters.

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.


void QxtRPCPeer::callClientsExcept ( quint64  id, QString  fn, QVariant  p1 = QVariant(), QVariant  p2 = QVariant(), QVariant  p3 = QVariant(), QVariant  p4 = QVariant(), QVariant  p5 = QVariant(), QVariant  p6 = QVariant(), QVariant  p7 = QVariant(), QVariant  p8 = QVariant() ) [slot]

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

This function accepts up to 8 QVariant parameters.

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.


void QxtRPCPeer::detachSender ( ) [slot]

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


void QxtRPCPeer::peerConnected ( ) [signal]

This signal is emitted after a successful connection to or from a peer or server.


void QxtRPCPeer::clientConnected ( quint64  id ) [signal]

This signal is emitted after a successful connection from a client.

The given ID is used for disconnectPeer(), callClient(), and related functions.


void QxtRPCPeer::peerDisconnected ( ) [signal]

This signal is emitted when a peer or server is disconnected.


void QxtRPCPeer::clientDisconnected ( quint64  id ) [signal]

This signal is emitted when a client disconnects. The given ID is no longer valid.


void QxtRPCPeer::peerError ( QAbstractSocket::SocketError  ) [signal]

This signal is emitted whenever an error occurs on a socket.

Currently, no information about the socket that raised the error is available.


QByteArray QxtRPCPeer::serialize ( QString  fn, QVariant  p1, QVariant  p2, QVariant  p3, QVariant  p4, QVariant  p5, QVariant  p6, QVariant  p7, QVariant  p8, QVariant  p9 ) const [protected, virtual]

Serializes a signal into a form suitable for transmitting over the network.

Reimplement this function in a subclass to allow QxtRPCPeer to use a different protocol.


QPair< QString, QList< QVariant > > QxtRPCPeer::deserialize ( QByteArray &  data ) [protected, virtual]

Deserializes network data into a signal name and a list of parameters.

Reimplement this function in a subclass to allow QxtRPCPeer to understand a different protocol. If you reimplement it, be sure to remove the processed portion of the data from the reference parameter. Return "qMakePair(QString(), QList<QVariant>())" if the deserialized data doesn't invoke a signal.


bool QxtRPCPeer::canDeserialize ( const QByteArray &  buffer ) const [protected, virtual]

Indicates whether the data currently received from the network can be deserialized.

The default behavior of this function returns true if the buffer contains a newline character.

Reimplement this function in a subclass to allow QxtRPCPeer to understand a different protocol.



(c) 2007A.Picciani and A.Higerd LGPL
libqxt 0.2