Skip to content

Commit 0b7ffe2

Browse files
committed
Fixed
1 parent faec881 commit 0b7ffe2

File tree

2 files changed

+49
-15
lines changed

2 files changed

+49
-15
lines changed

src/wsjcpp_jsonrpc20.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,37 @@
11
#include "wsjcpp_jsonrpc20.h"
22
#include <wsjcpp_core.h>
33

4+
/*!
5+
* WsjcppJsonRpc20Error -
6+
* */
7+
8+
WsjcppJsonRpc20Error::WsjcppJsonRpc20Error(int nErrorCode, const std::string &sErrorMessage) {
9+
m_nErrorCode = nErrorCode;
10+
m_sErrorMessage = sErrorMessage;
11+
}
12+
13+
// ---------------------------------------------------------------------
14+
15+
int WsjcppJsonRpc20Error::getErrorCode() {
16+
return m_nErrorCode;
17+
}
18+
19+
// ---------------------------------------------------------------------
20+
21+
std::string WsjcppJsonRpc20Error::getErrorMessage() {
22+
return m_sErrorMessage;
23+
}
24+
25+
// ---------------------------------------------------------------------
26+
27+
nlohmann::json WsjcppJsonRpc20Error::toJson() {
28+
nlohmann::json jsonRet;
29+
jsonRet["code"] = m_nErrorCode;
30+
jsonRet["message"] = m_sErrorMessage;
31+
return jsonRet;
32+
// {"jsonrpc": "2.0", "error": {"code": -32600, "message": "Invalid Request."}, "id": null}
33+
}
34+
435
// ---------------------------------------------------------------------
536

637
/*!

src/wsjcpp_jsonrpc20.h

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class WsjcppJsonRpc20Error {
1818
WsjcppJsonRpc20Error(int nErrorCode, const std::string &sErrorMessage);
1919
int getErrorCode();
2020
std::string getErrorMessage();
21+
nlohmann::json toJson();
2122
private:
2223
std::string m_sErrorMessage;
2324
int m_nErrorCode;
@@ -159,10 +160,10 @@ class WsjcppJsonRpc20ParamDef {
159160

160161
// ---------------------------------------------------------------------
161162

162-
class ModelRequest {
163+
class WsjcppJsonRpc20Request {
163164
public:
164-
ModelRequest(/*QWebSocket *pClient,*/ IWebSocketServer *pWebSocketServer, nlohmann::json &jsonRequest_);
165-
// QWebSocket *client();
165+
WsjcppJsonRpc20Request(void *pClient, IWebSocketServer *pWebSocketServer, nlohmann::json &jsonRequest_);
166+
void *client();
166167
std::string getIpAddress();
167168
IWebSocketServer *server();
168169
WsjcppJsonRpc20UserSession *getUserSession();
@@ -187,7 +188,7 @@ class ModelRequest {
187188
// bool validateInputParameters(Error &error, CmdHandlerBase *pCmdHandler);
188189
private:
189190
std::string TAG;
190-
// QWebSocket *m_pClient;
191+
void *m_pClient;
191192
IWebSocketServer *m_pServer;
192193
WsjcppJsonRpc20UserSession *m_pWsjcppJsonRpc20UserSession;
193194
nlohmann::json m_jsonRequest;
@@ -204,25 +205,27 @@ class ModelRequest {
204205
class WsjcppJsonRpc20Base {
205206

206207
public:
207-
WsjcppJsonRpc20Base(const std::string &sCmd, const std::string &sDescription);
208-
virtual std::string cmd();
209-
virtual std::string description();
210-
std::string activatedFromVersion();
211-
std::string deprecatedFromVersion();
212-
bool accessUnauthorized();
213-
bool accessUser();
214-
bool accessAdmin();
215-
bool checkAccess(ModelRequest *pRequest);
208+
WsjcppJsonRpc20Base(const std::string &sMethod, const std::string &sDescription);
209+
virtual std::string getMethodName() const;
210+
virtual std::string getDescription() const;
211+
std::string getActivatedFromVersion() const;
212+
std::string getDeprecatedFromVersion() const;
213+
bool getAccessUnauthorized() const;
214+
bool getAccessUser() const;
215+
bool getAccessTester() const;
216+
bool getAccessAdmin() const;
217+
bool checkAccess(const WsjcppJsonRpc20Request *pRequest) const;
216218

217219
virtual const std::vector<WsjcppJsonRpc20ParamDef> &inputs();
218-
virtual void handle(ModelRequest *pRequest) = 0;
220+
virtual void handle(WsjcppJsonRpc20Request *pRequest) = 0;
219221

220222
// virtual void done(nlohmann::json jsonResponse);
221223
// virtual void fail(int nCode, const std::string &sErrorMessage);
222224

223225
protected:
224226
void setAccessUnauthorized(bool bAccess);
225227
void setAccessUser(bool bAccess);
228+
void setAccessTester(bool bAccess);
226229
void setAccessAdmin(bool bAccess);
227230
void setActivatedFromVersion(const std::string &sActivatedFromVersion);
228231
void setDeprecatedFromVersion(const std::string &sDeprecatedFromVersion);
@@ -275,7 +278,7 @@ class WsjcppJsonRpc20ServerApi : public WsjcppJsonRpc20Base {
275278

276279
public:
277280
WsjcppJsonRpc20ServerApi();
278-
virtual void handle(ModelRequest *pRequest);
281+
virtual void handle(WsjcppJsonRpc20Request *pRequest);
279282
};
280283

281284
#endif // WSJCPP_JSONRPC20

0 commit comments

Comments
 (0)