77#include < iostream>
88#include < algorithm>
99
10- /* !
11- * WsjcppJsonRpc20Error - helper class for errors
12- * */
10+ class WsjcppJsonRpc20Error ;
11+ class WsjcppJsonRpc20UserSession ;
12+ class WsjcppJsonRpc20ParamDef ;
13+ class WsjcppJsonRpc20WebSocket ;
14+ class WsjcppJsonRpc20WebSocketServer ;
15+ class WsjcppJsonRpc20ParamDef ;
16+ class WsjcppJsonRpc20Request ;
17+ class WsjcppJsonRpc20BaseHandler ;
18+ class WsjcppJsonRpc20 ;
19+
20+ // ---------------------------------------------------------------------
21+ // WsjcppJsonRpc20Error
1322
1423// must be this json:
1524// {"jsonrpc": "2.0", "error": {"code": -32600, "message": "Invalid Request."}, "id": null}
@@ -24,9 +33,8 @@ class WsjcppJsonRpc20Error {
2433 int m_nErrorCode;
2534};
2635
27- /* !
28- * WsjcppJsonRpc20Session - user data session
29- * */
36+ // ---------------------------------------------------------------------
37+ // WsjcppJsonRpc20Session
3038
3139class WsjcppJsonRpc20UserSession {
3240 public:
@@ -85,20 +93,45 @@ class WsjcppJsonRpc20UserSession {
8593 nlohmann::json m_jsonSessionCustom;
8694};
8795
88- /* !
89- * IWebSocketServer -
90- * */
96+ // ---------------------------------------------------------------------
97+ // WsjcppJsonRpc20WebSocket
9198
92- /* class IWebSocketServer {
99+ class WsjcppJsonRpc20WebSocketClient {
93100 public:
94- // virtual void sendMessage(QWebSocket *pClient, const nlohmann::json& jsonResponse) = 0;
95- // virtual void sendMessageError(QWebSocket *pClient, const std::string &sCmd, const std::string & sM, WsjcppError error) = 0;
101+ WsjcppJsonRpc20WebSocketClient ();
102+ void setUserSession (WsjcppJsonRpc20UserSession *pUserSession);
103+ WsjcppJsonRpc20UserSession *getUserSession ();
104+ void unsetUserSession ();
105+
106+ protected:
107+ std::string TAG;
108+
109+ private:
110+ WsjcppJsonRpc20UserSession *m_pUserSession;
111+ };
112+
113+ // ---------------------------------------------------------------------
114+ // WsjcppJsonRpc20WebSocketServer
115+ /*
116+ class WsjcppJsonRpc20WebSocketServer {
117+ public:
118+ virtual void sendMessage(
119+ WsjcppJsonRpc20WebSocket *pClient,
120+ const nlohmann::json& jsonResponse
121+ ) = 0;
122+ virtual void sendMessageError(
123+ WsjcppJsonRpc20WebSocket *pClient,
124+ const std::string &sCmd,
125+ const std::string & sM,
126+ WsjcppJsonRpc20Error error
127+ ) = 0;
96128 virtual void sendToAll(const nlohmann::json& jsonMessage) = 0;
97- // virtual void sendToOne(QWebSocket *pClient, const nlohmann::json &jsonMessage) = 0;
129+ virtual void sendToOne(WsjcppJsonRpc20WebSocket *pClient, const nlohmann::json &jsonMessage) = 0;
98130 virtual int getConnectedUsers() = 0;
99- // virtual void setWsjcppJsonRpc20UserSession(QWebSocket *pClient, WsjcppJsonRpc20UserSession *pUserSession) = 0;
100- // virtual WsjcppJsonRpc20UserSession *getWsjcppJsonRpc20UserSession(QWebSocket *pClient) = 0;
101- };*/
131+ virtual void setWsjcppJsonRpc20UserSession(WsjcppJsonRpc20WebSocket *pClient, WsjcppJsonRpc20UserSession *pUserSession) = 0;
132+ virtual WsjcppJsonRpc20UserSession *getWsjcppJsonRpc20UserSession(WsjcppJsonRpc20WebSocket *pClient) = 0;
133+ };
134+ */
102135
103136/* !
104137 * WsjcppJsonRpc20ParamDef - helper api for define input params and descrip it for docs.
@@ -160,14 +193,18 @@ class WsjcppJsonRpc20ParamDef {
160193};
161194
162195// ---------------------------------------------------------------------
163-
196+ // WsjcppJsonRpc20Request
164197/*
165198class WsjcppJsonRpc20Request {
166199 public:
167- WsjcppJsonRpc20Request(void *pClient, IWebSocketServer *pWebSocketServer, nlohmann::json &jsonRequest_);
168- void *client();
200+ WsjcppJsonRpc20Request(
201+ WsjcppJsonRpc20WebSocket *pClient,
202+ WsjcppJsonRpc20WebSocketServer *pWebSocketServer,
203+ nlohmann::json &jsonRequest_
204+ );
205+ WsjcppJsonRpc20WebSocket *client();
169206 std::string getIpAddress();
170- IWebSocketServer *server();
207+ WsjcppJsonRpc20WebSocketServer *server();
171208 WsjcppJsonRpc20UserSession *getUserSession();
172209 bool isAdmin();
173210 bool isUser();
@@ -191,7 +228,7 @@ class WsjcppJsonRpc20Request {
191228 private:
192229 std::string TAG;
193230 void *m_pClient;
194- IWebSocketServer *m_pServer;
231+ WsjcppJsonRpc20WebSocketServer *m_pServer;
195232 WsjcppJsonRpc20UserSession *m_pWsjcppJsonRpc20UserSession;
196233 nlohmann::json m_jsonRequest;
197234 std::string m_sMessageId;
@@ -203,9 +240,8 @@ class WsjcppJsonRpc20Request {
203240/* !
204241 * Api handler Base
205242 * */
206-
207243/*
208- class WsjcppJsonRpc20Base {
244+ class WsjcppJsonRpc20BaseHandler {
209245
210246 public:
211247 WsjcppJsonRpc20Base(const std::string &sMethod, const std::string &sDescription);
@@ -253,7 +289,9 @@ class WsjcppJsonRpc20Base {
253289 bool m_bAccessUser;
254290 bool m_bAccessAdmin;
255291};
292+
256293*/
294+
257295// extern std::map<std::string, WsjcppJsonRpc20Base*> *g_pWsjcppJsonRpc20BaseList;
258296
259297/* !
@@ -264,7 +302,7 @@ class WsjcppJsonRpc20 {
264302 public:
265303 static void initGlobalVariables();
266304 static void addHandler(const std::string &sName, WsjcppJsonRpc20Base* pCmdHandler);
267- static WsjcppJsonRpc20Base *findJsonRpc20(const std::string &sCmd );
305+ static WsjcppJsonRpc20Base *findJsonRpc20(const std::string &sMethod );
268306};
269307
270308// RegistryWsjcppJsonRpc20
0 commit comments