1010class WsjcppJsonRpc20Error ;
1111class WsjcppJsonRpc20UserSession ;
1212class WsjcppJsonRpc20ParamDef ;
13- class WsjcppJsonRpc20WebSocket ;
13+ class WsjcppJsonRpc20WebSocketClient ;
1414class WsjcppJsonRpc20WebSocketServer ;
1515class WsjcppJsonRpc20ParamDef ;
1616class WsjcppJsonRpc20Request ;
@@ -94,15 +94,21 @@ class WsjcppJsonRpc20UserSession {
9494};
9595
9696// ---------------------------------------------------------------------
97- // WsjcppJsonRpc20WebSocket
97+ // WsjcppJsonRpc20WebSocketClient
9898
9999class WsjcppJsonRpc20WebSocketClient {
100100 public:
101101 WsjcppJsonRpc20WebSocketClient ();
102102 void setUserSession (WsjcppJsonRpc20UserSession *pUserSession);
103103 WsjcppJsonRpc20UserSession *getUserSession ();
104104 void unsetUserSession ();
105-
105+ virtual void onDisconnected () = 0;
106+ virtual std::string getPeerIpAddress () = 0;
107+ virtual int getPeerPort () = 0;
108+ virtual std::string getRequestUrl () = 0;
109+
110+ virtual void sendTextMessage (const std::string &sTextMessage ) = 0;
111+
106112 protected:
107113 std::string TAG;
108114
@@ -112,26 +118,27 @@ class WsjcppJsonRpc20WebSocketClient {
112118
113119// ---------------------------------------------------------------------
114120// WsjcppJsonRpc20WebSocketServer
115- /*
121+
116122class WsjcppJsonRpc20WebSocketServer {
117123 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;
128- virtual void sendToAll(const nlohmann::json& jsonMessage) = 0;
129- virtual void sendToOne(WsjcppJsonRpc20WebSocket *pClient, const nlohmann::json &jsonMessage) = 0;
130- virtual int getConnectedUsers() = 0;
131- virtual void setWsjcppJsonRpc20UserSession(WsjcppJsonRpc20WebSocket *pClient, WsjcppJsonRpc20UserSession *pUserSession) = 0;
132- virtual WsjcppJsonRpc20UserSession *getWsjcppJsonRpc20UserSession(WsjcppJsonRpc20WebSocket *pClient) = 0;
124+ WsjcppJsonRpc20WebSocketServer ();
125+
126+
127+ void onWebSocketConnected (void *pClient, WsjcppJsonRpc20WebSocketClient *pWebSocketClient);
128+ void onWebSocketDisconnected (void *pClient);
129+ int getConnectedClients ();
130+ // TODO int getConnectedUsers();
131+
132+ WsjcppJsonRpc20WebSocketClient *findWebSocketClient (void *pClient);
133+ void sendMessageToAll (const nlohmann::json& jsonMessage);
134+ void sendMessageToOne (WsjcppJsonRpc20WebSocketClient *pClient, const nlohmann::json &jsonMessage);
135+
136+ protected:
137+ std::string TAG;
138+
139+ private:
140+ std::map<void *, WsjcppJsonRpc20WebSocketClient *> m_mapClients;
133141};
134- */
135142
136143/* !
137144 * WsjcppJsonRpc20ParamDef - helper api for define input params and descrip it for docs.
@@ -221,7 +228,6 @@ class WsjcppJsonRpc20Request {
221228 std::string command();
222229 bool hasCommand();
223230 void sendMessageError(const std::string &cmd, WsjcppJsonRpc20Error error);
224- void sendMessageSuccess(const std::string &cmd, nlohmann::json& jsonResponse);
225231 void sendResponse(nlohmann::json& jsonResult);
226232
227233 // bool validateInputParameters(Error &error, CmdHandlerBase *pCmdHandler);
@@ -322,4 +328,4 @@ class WsjcppJsonRpc20ServerApi : public WsjcppJsonRpc20Base {
322328 virtual void handle(WsjcppJsonRpc20Request *pRequest);
323329};
324330*/
325- #endif // WSJCPP_JSONRPC20
331+ #endif // WSJCPP_JSONRPC20
0 commit comments