Loading...
Searching...
No Matches
JsonRpcClient Class Reference

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

`#include <molequeue/client/jsonrpcclient.h>`

Inheritance diagram for JsonRpcClient:

## Public Slots

bool | connectToServer (const QString &serverName)
void | flush ()
| flush Flush all pending messages to the server.
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_=nullptr)
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

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>
MoleQueue::JsonRpcClient *client = new MoleQueue::JsonRpcClient(this);
client->connectToServer("MyRpcServer");
QJsonObject request(client->emptyRequest());
request["method"] = QLatin1String("listQueues");
client->sendRequest(request);
Avogadro::MoleQueue::JsonRpcClient
The JsonRpcClient class is used by clients to submit calls to an RPC server using JSON-RPC 2....
Definition jsonrpcclient.h:44
Avogadro::MoleQueue::JsonRpcClient::emptyRequest
QJsonObject emptyRequest()
Avogadro::MoleQueue::JsonRpcClient::sendRequest
bool sendRequest(const QJsonObject &request)
Avogadro::MoleQueue::JsonRpcClient::connectToServer
bool connectToServer(const QString &serverName)

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

## isConnected()

bool isConnected | ( |  | ) | const

Query if the client is connected to a server.

Returns
  True if connected, false if not.

## serverName()

QString serverName | ( |  | ) | const

Returns
  The server name that the client is connected to.

## connectToServer

bool connectToServer | ( | const QString & | serverName | ) |

slot

Connect to the server.

Parameters

  serverName | Name of the socket to connect to.

## flush

void flush | ( |  | ) |

slot

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.

## emptyRequest

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.

## sendRequest

bool sendRequest | ( | const QJsonObject & | request | ) |

slot

Send the Json request to the RPC server.

Parameters

  request | The JSON-RPC 2.0 request object.

Returns
  True on success, false on failure.

## readPacket

void readPacket | ( | const QByteArray | message | ) |

protected slot

Read incoming packets of data from the server.

## readSocket

void readSocket | ( |  | ) |

protected slot

Read incoming data, interpret JSON stream.

## connectionStateChanged

void connectionStateChanged | ( |  | ) |

signal

Emitted when the connection state changes.

## resultReceived

void resultReceived | ( | QJsonObject | message | ) |

signal

Emitted when a result is received.

## notificationReceived

void notificationReceived | ( | QJsonObject | message | ) |

signal

Emitted when a notification is received.

## errorReceived

void errorReceived | ( | QJsonObject | message | ) |

signal

Emitted when an error response is received.

## badPacketReceived

void badPacketReceived | ( | QString | error | ) |

signal

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

## newPacket

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:

- jsonrpcclient.h