Torc  0.1
torcrpcrequest.h
Go to the documentation of this file.
1 #ifndef TORCRPCREQUEST_H
2 #define TORCRPCREQUEST_H
3 
4 // Qt
5 #include <QList>
6 #include <QMutex>
7 #include <QVariant>
8 #include <QJsonObject>
9 
10 // Torc
11 #include "http/torcwebsocket.h"
12 #include "torcreferencecounted.h"
13 
15 {
16  public:
17  enum State
18  {
19  None = (0 << 0),
20  RequestSent = (1 << 0),
21  ReplyReceived = (1 << 1),
22  Cancelled = (1 << 2),
23  TimedOut = (1 << 3),
24  Errored = (1 << 4),
25  Result = (1 << 5)
26  };
27 
28  public:
29  TorcRPCRequest(const QString &Method, QObject *Parent);
30  explicit TorcRPCRequest(const QString &Method);
31  TorcRPCRequest(TorcWebSocketReader::WSSubProtocol Protocol, const QByteArray &Data, QObject *Parent, bool Authenticated);
32 
33  bool IsNotification (void) const;
34  void NotifyParent (void);
35  void SetParent (QObject *Parent);
37 
38  void AddState (int State);
39  void SetID (int ID);
40  void AddParameter (const QString &Name, const QVariant &Value);
41  void AddPositionalParameter (const QVariant &Value);
42  void SetReply (const QVariant &Reply);
43 
44  int GetState (void) const;
45  int GetID (void) const;
46  QString GetMethod (void) const;
47  QObject* GetParent (void) const;
48  const QVariant& GetReply (void) const;
49  const QList<QPair<QString,QVariant> >&
50  GetParameters (void) const;
51  const QList<QVariant>&
52  GetPositionalParameters(void) const;
53  QByteArray& GetData (void);
54 
55  private:
56  explicit TorcRPCRequest(const QJsonObject &Object, QObject *Parent, bool Authenticated);
57  ~TorcRPCRequest();
58  Q_DISABLE_COPY(TorcRPCRequest)
59 
60  void ParseJSONObject (const QJsonObject &Object);
61  void ProcessNullContent (bool HasMethod);
62  void ProcessBatchCall (const QJsonArray &Array);
63 
64 
65  private:
66  bool m_authenticated;
67  bool m_notification;
68  int m_state;
69  int m_id;
70  QString m_method;
71  QObject *m_parent;
72  QMutex *m_parentLock;
73  bool m_validParent;
74  QList<QPair<QString,QVariant> > m_parameters;
75  QList<QVariant> m_positionalParameters;
76  QByteArray m_serialisedData;
77  QVariant m_reply;
78 };
79 
80 Q_DECLARE_METATYPE(TorcRPCRequest*)
81 
82 #endif // TORCRPCREQUEST_H
TorcRPCRequest(const QString &Method, QObject *Parent)
Creates an RPC request owned by the given Parent.
A reference counting implementation.
QByteArray & GetData(void)
int GetID(void) const
void SetParent(QObject *Parent)
Set the parent for the request.
void AddState(int State)
Progress the state for this request.
A class encapsulating a Remote Procedure Call.
void NotifyParent(void)
Signal to the parent that the request is ready (but may be errored).
QString GetMethod(void) const
int GetState(void) const
void AddPositionalParameter(const QVariant &Value)
Add a positional parameter.
const QList< QVariant > & GetPositionalParameters(void) const
bool IsNotification(void) const
QByteArray & SerialiseRequest(TorcWebSocketReader::WSSubProtocol Protocol)
Serialise the request for the given protocol.
const QList< QPair< QString, QVariant > > & GetParameters(void) const
const QVariant & GetReply(void) const
void SetReply(const QVariant &Reply)
QObject * GetParent(void) const
void AddParameter(const QString &Name, const QVariant &Value)
Add Parameter and value to list of call parameters.
void SetID(int ID)
Set the unique ID for this request.