12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- #ifndef CWebsocketServer_h
- #define CWebsocketServer_h
- #include "websocketpp/config/asio_no_tls.hpp"
- #include "websocketpp/config/asio.hpp"
- #include "websocketpp/server.hpp"
- #include "CMessage.h"
- #include "CWSCodec.h"
- #include "CSocketClient.h"
- #include "ISocketCallback.h"
- #include <boost/asio.hpp>
- #include <boost/thread/mutex.hpp>
- #include "baseEx.h"
- #include <functional>
- #include "EntitySessionManager.h"
- #include <memory>
- #include <vector>
- namespace Chromium{
- typedef websocketpp::server<websocketpp::config::asio> server;
- class CWebsocketServer : public ISocketCallback {
- public:
- CWebsocketServer(const char* strPath, CEntityBase* m_pEntity);
- void run();
- // socket callbacks
- void message_from_socket(CMessage& msg, unsigned int id);
-
- private:
- void message_handler(websocketpp::connection_hdl hdl, server::message_ptr msg);
- void deal_msg(std::string &payload, websocketpp::connection_hdl hdl);
- void open_handler(websocketpp::connection_hdl hdl);
- void close_handler(websocketpp::connection_hdl hdl);
- void do_run();
- void init_websocket();
- void init_entity_sessions();
- void do_sendJson(std::string js, int hdlID, unsigned int id);
- void do_sendJsonBroadcast(std::string js);
- std::string string_to_utf8(const std::string &str);
- void myTest();
- void updateMsgPool(std::string entityName, std::string &payload, websocketpp::connection_hdl hdl);
- void storeEntityWithCLass(std::string entityName, std::string entityClass);
- std::pair<bool, std::string> getEntityClass(std::string entityName);
- void do_sendJsonStartSession(std::string entityName, std::string entityClass);
- void do_relink();
- std::string restroreTransId(std::string payLoad);
- private:
- server m_wsserver;
- CWSCodec* m_serializer;
- CSocketClient* m_socket;
- EntitySessionManager* m_esm;
- boost::asio::io_service m_ios;
- std::map<unsigned int,websocketpp::connection_hdl> m_connection_hdls;
- std::map<std::string, std::vector<std::pair<websocketpp::connection_hdl, std::string>> > m_msg_pool;
- std::map<std::string, std::string> m_entityAndClass;
- //不知道为什么不能用map<string,map<>>,猜测应该是websocketpp::connection_hdl生成问题
- CEntityBase* m_pEntity;
- boost::mutex m_dealMsgLock;
- };
- }
- #endif
|