MoleQueue  0.8.0
 All Classes Functions Variables Enumerations Enumerator Pages
Public Slots | Signals | Public Member Functions | Protected Slots | Protected Attributes | List of all members
JsonRpcClient Class Reference

#include <molequeue/client/jsonrpcclient.h>

Inheritance diagram for JsonRpcClient:

Public Slots

bool connectToServer (const QString &serverName)
 
void flush ()
 
QJsonObject emptyRequest ()
 
bool sendRequest (const QJsonObject &request)
 

Signals

void connectionStateChanged ()
 
void resultReceived (QJsonObject message)
 
void notificationReceived (QJsonObject message)
 
void errorReceived (QJsonObject message)
 
void badPacketReceived (QString error)
 
void newPacket (const QByteArray &packet)
 

Public Member Functions

 JsonRpcClient (QObject *parent_=0)
 
bool isConnected () const
 
QString serverName () const
 

Protected Slots

void readPacket (const QByteArray message)
 
void readSocket ()
 

Protected Attributes

unsigned int m_packetCounter
 
QLocalSocket * m_socket
 

Detailed Description

The JsonRpcClient class is used by clients to submit calls to an RPC server using JSON-RPC 2.0.

Author
Marcus D. Hanwell

Provides a simple Qt C++ API to make JSON-RPC 2.0 calls to an RPC server. To create a client connection and call a method the following should be done:

#include <molequeue/client/jsonrpcclient.h>
client->connectToServer("MyRpcServer");
QJsonObject request(client->emptyRequest());
request["method"] = QLatin1String("listQueues");
client->sendRequest(request);

You should connect to the appropriate signals in order to act on results, notifications and errors received in response to requests set using the client connection.

Member Function Documentation

bool isConnected ( ) const

Query if the client is connected to a server.

Returns
True if connected, false if not.
QString serverName ( ) const
Returns
The server name that the client is connected to.
bool connectToServer ( const QString &  serverName)
slot

Connect to the server.

Parameters
serverNameName of the socket to connect to.
void flush ( )
slot

flush Flush all pending messages to the server.

Warning
This should not need to be called if used in an event loop, as Qt will start writing to the socket as soon as control returns to the event loop.
QJsonObject emptyRequest ( )
slot

Use this function to construct an empty JSON-RPC 2.0 request, with a valid request id, JSON-RPC 2.0 key etc.

Returns
a standard empty JSON-RPC 2.0 packet, the method etc is empty.
bool sendRequest ( const QJsonObject &  request)
slot

Send the Json request to the RPC server.

Parameters
requestThe JSON-RPC 2.0 request object.
Returns
True on success, false on failure.
void readPacket ( const QByteArray  message)
protectedslot

Read incoming packets of data from the server.

void readSocket ( )
protectedslot

Read incoming data, interpret JSON stream.

void connectionStateChanged ( )
signal

Emitted when the connection state changes.

void resultReceived ( QJsonObject  message)
signal

Emitted when a result is received.

void notificationReceived ( QJsonObject  message)
signal

Emitted when a notification is received.

void errorReceived ( QJsonObject  message)
signal

Emitted when an error response is received.

void badPacketReceived ( QString  error)
signal

Emitted when a bad packet was received that the client could not parse.

void newPacket ( const QByteArray &  packet)
signal

Emitted when a new packet of data is received. This is handled internally, other classes should listen to resultReceived, notificationReceived, errorReceived, and badPacketReceived.


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