Torc  0.1
Public Types | Public Member Functions | List of all members
TorcRPCRequest Class Reference

A class encapsulating a Remote Procedure Call. More...

#include <torcrpcrequest.h>

Inheritance diagram for TorcRPCRequest:
[legend]

Public Types

enum  State {
  None = (0 << 0), RequestSent = (1 << 0), ReplyReceived = (1 << 1), Cancelled = (1 << 2),
  TimedOut = (1 << 3), Errored = (1 << 4), Result = (1 << 5)
}
 

Public Member Functions

 TorcRPCRequest (const QString &Method, QObject *Parent)
 Creates an RPC request owned by the given Parent. More...
 
 TorcRPCRequest (const QString &Method)
 Creates a notification request for which no response is expected. More...
 
 TorcRPCRequest (TorcWebSocketReader::WSSubProtocol Protocol, const QByteArray &Data, QObject *Parent, bool Authenticated)
 Creates a request or response from the given raw data using the given protocol. More...
 
bool IsNotification (void) const
 
void NotifyParent (void)
 Signal to the parent that the request is ready (but may be errored). More...
 
void SetParent (QObject *Parent)
 Set the parent for the request. More...
 
QByteArray & SerialiseRequest (TorcWebSocketReader::WSSubProtocol Protocol)
 Serialise the request for the given protocol. More...
 
void AddState (int State)
 Progress the state for this request. More...
 
void SetID (int ID)
 Set the unique ID for this request. More...
 
void AddParameter (const QString &Name, const QVariant &Value)
 Add Parameter and value to list of call parameters. More...
 
void AddPositionalParameter (const QVariant &Value)
 Add a positional parameter. More...
 
void SetReply (const QVariant &Reply)
 
int GetState (void) const
 
int GetID (void) const
 
QString GetMethod (void) const
 
QObject * GetParent (void) const
 
const QVariant & GetReply (void) const
 
const QList< QPair< QString, QVariant > > & GetParameters (void) const
 
const QList< QVariant > & GetPositionalParameters (void) const
 
QByteArray & GetData (void)
 
- Public Member Functions inherited from TorcReferenceCounter
 TorcReferenceCounter (void)
 
virtual ~TorcReferenceCounter (void)=default
 
void UpRef (void)
 
virtual bool DownRef (void)
 
bool IsShared (void)
 

Additional Inherited Members

- Static Public Member Functions inherited from TorcReferenceCounter
static void EventLoopEnding (bool Ending)
 
- Protected Attributes inherited from TorcReferenceCounter
QAtomicInt m_refCount
 
- Static Protected Attributes inherited from TorcReferenceCounter
static bool m_eventLoopEnding = false
 

Detailed Description

A class encapsulating a Remote Procedure Call.

Remote Procedure Calls are currently only handled through TorcWebSocket.

Note
The underlying protocol is restricted to JSON-RPC.
See also
TorcWebSocket
TorcHTTPService

Definition at line 14 of file torcrpcrequest.h.

Member Enumeration Documentation

Enumerator
None 
RequestSent 
ReplyReceived 
Cancelled 
TimedOut 
Errored 
Result 

Definition at line 17 of file torcrpcrequest.h.

Constructor & Destructor Documentation

TorcRPCRequest::TorcRPCRequest ( const QString &  Method,
QObject *  Parent 
)

Creates an RPC request owned by the given Parent.

Parent will be notified when the request has been completed (or on error) and is responsible for cancelling the request if it is no longer required. Upon completion, error or cancellation, the parent must then DownRef the request to ensure it is deleted.

Definition at line 47 of file torcrpcrequest.cpp.

TorcRPCRequest::TorcRPCRequest ( const QString &  Method)
explicit

Creates a notification request for which no response is expected.

Notification requests are deleted after they have been sent.

Definition at line 68 of file torcrpcrequest.cpp.

TorcRPCRequest::TorcRPCRequest ( TorcWebSocketReader::WSSubProtocol  Protocol,
const QByteArray &  Data,
QObject *  Parent,
bool  Authenticated 
)

Creates a request or response from the given raw data using the given protocol.

Definition at line 106 of file torcrpcrequest.cpp.

Member Function Documentation

void TorcRPCRequest::AddParameter ( const QString &  Name,
const QVariant &  Value 
)

Add Parameter and value to list of call parameters.

Ideally this should check for duplicate parameter names but it is not a commonly used method, would be inneficient and the caller should control the duplication.

Definition at line 402 of file torcrpcrequest.cpp.

void TorcRPCRequest::AddPositionalParameter ( const QVariant &  Value)

Add a positional parameter.

Positional parameters are unnamed and ordered. They are only added if the normal (preferred) parameter list is empty.

Definition at line 412 of file torcrpcrequest.cpp.

void TorcRPCRequest::AddState ( int  State)

Progress the state for this request.

Note
Request state is incremental.

Definition at line 386 of file torcrpcrequest.cpp.

QByteArray & TorcRPCRequest::GetData ( void  )

Definition at line 457 of file torcrpcrequest.cpp.

int TorcRPCRequest::GetID ( void  ) const

Definition at line 427 of file torcrpcrequest.cpp.

QString TorcRPCRequest::GetMethod ( void  ) const

Definition at line 432 of file torcrpcrequest.cpp.

const QList< QPair< QString, QVariant > > & TorcRPCRequest::GetParameters ( void  ) const

Definition at line 447 of file torcrpcrequest.cpp.

QObject * TorcRPCRequest::GetParent ( void  ) const

Definition at line 437 of file torcrpcrequest.cpp.

const QList< QVariant > & TorcRPCRequest::GetPositionalParameters ( void  ) const

Definition at line 452 of file torcrpcrequest.cpp.

const QVariant & TorcRPCRequest::GetReply ( void  ) const

Definition at line 442 of file torcrpcrequest.cpp.

int TorcRPCRequest::GetState ( void  ) const

Definition at line 422 of file torcrpcrequest.cpp.

bool TorcRPCRequest::IsNotification ( void  ) const

Definition at line 306 of file torcrpcrequest.cpp.

void TorcRPCRequest::NotifyParent ( void  )

Signal to the parent that the request is ready (but may be errored).

Definition at line 312 of file torcrpcrequest.cpp.

QByteArray & TorcRPCRequest::SerialiseRequest ( TorcWebSocketReader::WSSubProtocol  Protocol)

Serialise the request for the given protocol.

Note
QJsonValue may not be flexbible enough for all types.

Definition at line 345 of file torcrpcrequest.cpp.

void TorcRPCRequest::SetID ( int  ID)

Set the unique ID for this request.

Definition at line 392 of file torcrpcrequest.cpp.

void TorcRPCRequest::SetParent ( QObject *  Parent)

Set the parent for the request.

Usually only used when a request is being cancelled by the parent and the parent is being deleted.

Definition at line 327 of file torcrpcrequest.cpp.

void TorcRPCRequest::SetReply ( const QVariant &  Reply)

Definition at line 417 of file torcrpcrequest.cpp.


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