QJsonChannelCore
QJsonChannelMessage.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <QSharedDataPointer>
4 #include <QMetaType>
5 
6 #include <QJsonValue>
7 #include <QJsonObject>
8 #include <QJsonArray>
9 
10 #include "QJsonChannelGlobal.h"
11 
12 class QJsonChannelMessagePrivate;
13 
19 public:
22  QJsonChannelMessage& operator= (const QJsonChannelMessage& other);
24 
25  inline void swap (QJsonChannelMessage& other) {
26  qSwap (d, other.d);
27  }
28 
33  enum Type {
45  Discrovery
46  };
47 
55  static QJsonChannelMessage createRequest (const QString& method, const QJsonArray& params = QJsonArray ());
63  static QJsonChannelMessage createRequest (const QString& method, const QJsonValue& param);
71  static QJsonChannelMessage createRequest (const QString& method, const QJsonObject& namedParameters);
72 
80  static QJsonChannelMessage createNotification (const QString& method, const QJsonArray& params = QJsonArray ());
88  static QJsonChannelMessage createNotification (const QString& method, const QJsonValue& param);
96  static QJsonChannelMessage createNotification (const QString& method, const QJsonObject& namedParameters);
97 
104  QJsonChannelMessage createResponse (const QJsonValue& result) const;
105 
114  QJsonChannelMessage createErrorResponse (QJsonChannel::ErrorCode code, const QString& message = QString (), const QJsonValue& data = QJsonValue ()) const;
115 
121  QJsonChannelMessage::Type type () const;
122 
129  bool isValid () const;
130 
136  int id () const;
137 
138  // request
144  QString serviceName () const;
150  QString method () const;
156  QJsonValue params () const;
157 
158  // response
164  QJsonValue result () const;
165 
166  // error
172  int errorCode () const;
178  QString errorMessage () const;
184  QJsonValue errorData () const;
185 
191  QJsonObject toObject () const;
192 
199  static QJsonChannelMessage fromObject (const QJsonObject& object);
200 
206  QByteArray toJson () const;
213  static QJsonChannelMessage fromJson (const QByteArray& data);
214 
215  bool operator== (const QJsonChannelMessage& message) const;
216  inline bool operator!= (const QJsonChannelMessage& message) const {
217  return !(operator== (message));
218  }
219 
220 private:
221  friend class QJsonChannelMessagePrivate;
222  QSharedDataPointer<QJsonChannelMessagePrivate> d;
223 };
224 
226 Q_DECLARE_METATYPE (QJsonChannelMessage)
227 Q_DECLARE_SHARED (QJsonChannelMessage)
QJSONCHANNELCORE_EXPORT QDebug operator<<(QDebug, const QJsonChannelMessage &)
Representation of JSON-RPC message.
void swap(QJsonChannelMessage &other)
Error Response message.
#define QJSONCHANNELCORE_EXPORT