Changeset 1523
- Timestamp:
- 07/19/05 02:18:39 (3 years ago)
- Files:
-
- hydranode/hncore/plugins/cgcomm/src/cgcomm.cpp (modified) (3 diffs)
- hydranode/hncore/plugins/cgcomm/src/client.cpp (modified) (5 diffs)
- hydranode/hncore/plugins/cgcomm/src/sub_auth.cpp (modified) (1 diff)
- hydranode/hncore/plugins/cgcomm/src/sub_config.cpp (modified) (1 diff)
- hydranode/hncore/plugins/cgcomm/src/sub_download.cpp (modified) (1 diff)
- hydranode/hncore/plugins/cgcomm/src/sub_ext.cpp (modified) (1 diff)
- hydranode/hncore/plugins/cgcomm/src/sub_hasher.cpp (modified) (1 diff)
- hydranode/hncore/plugins/cgcomm/src/sub_log.cpp (modified) (1 diff)
- hydranode/hncore/plugins/cgcomm/src/sub_plugins.cpp (modified) (1 diff)
- hydranode/hncore/plugins/cgcomm/src/sub_search.cpp (modified) (1 diff)
- hydranode/hncore/plugins/cgcomm/src/sub_shared.cpp (modified) (1 diff)
- hydranode/hncore/plugins/cgcomm/src/subsysbase.cpp (modified) (2 diffs)
- hydranode/include/hncore/cgcomm/client.h (modified) (2 diffs)
- hydranode/include/hncore/cgcomm/sub_auth.h (modified) (1 diff)
- hydranode/include/hncore/cgcomm/sub_config.h (modified) (1 diff)
- hydranode/include/hncore/cgcomm/sub_download.h (modified) (1 diff)
- hydranode/include/hncore/cgcomm/sub_ext.h (modified) (1 diff)
- hydranode/include/hncore/cgcomm/sub_hasher.h (modified) (1 diff)
- hydranode/include/hncore/cgcomm/sub_log.h (modified) (1 diff)
- hydranode/include/hncore/cgcomm/sub_plugins.h (modified) (1 diff)
- hydranode/include/hncore/cgcomm/sub_search.h (modified) (1 diff)
- hydranode/include/hncore/cgcomm/sub_shared.h (modified) (1 diff)
- hydranode/include/hncore/cgcomm/subsysbase.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
hydranode/hncore/plugins/cgcomm/src/cgcomm.cpp
r1501 r1523 25 25 26 26 IMPLEMENT_MODULE(ModMain); 27 27 28 bool ModMain::onInit() { 28 29 logMsg("Initializing Core/GUI communication..."); … … 35 36 return true; 36 37 } 38 37 39 int ModMain::onExit() { 38 40 m_listener->destroy(); … … 40 42 } 41 43 42 void ModMain::onIncoming(SocketServer *sock, SocketEvent evt) {44 void ModMain::onIncoming(SocketServer *sock, SocketEvent) { 43 45 Client *c = new Client(sock->accept()); 44 46 c->getEventTable().addHandler(c, this, &ModMain::onClientEvent); 45 47 m_clients.insert(c); 46 48 } 49 47 50 void ModMain::onClientEvent(Client *c, int evt) { 48 51 if (evt == EVT_DESTROY) { hydranode/hncore/plugins/cgcomm/src/client.cpp
r1501 r1523 35 35 36 36 Client::Client(SocketClient *sock) : m_socket(sock) { 37 m_subMap[SUB_AUTH ].reset(new Subsystem::Auth (m_socket)); 38 m_subMap[SUB_SEARCH ].reset(new Subsystem::Search (m_socket)); 39 m_subMap[SUB_DOWNLOAD].reset(new Subsystem::Download(m_socket)); 40 m_subMap[SUB_SHARED ].reset(new Subsystem::Shared (m_socket)); 41 m_subMap[SUB_CONFIG ].reset(new Subsystem::Config (m_socket)); 42 m_subMap[SUB_HASHER ].reset(new Subsystem::Hasher (m_socket)); 43 m_subMap[SUB_PLUGINS ].reset(new Subsystem::Plugins (m_socket)); 44 m_subMap[SUB_LOG ].reset(new Subsystem::Log (m_socket)); 45 m_subMap[SUB_EXT ].reset(new Subsystem::Ext (m_socket)); 37 boost::function<void (const std::string&)> sendFunc; 38 sendFunc = boost::bind(&Client::sendData, this, _1); 39 40 m_subMap[SUB_AUTH ].reset(new Subsystem::Auth (sendFunc)); 41 m_subMap[SUB_SEARCH ].reset(new Subsystem::Search (sendFunc)); 42 m_subMap[SUB_DOWNLOAD].reset(new Subsystem::Download(sendFunc)); 43 m_subMap[SUB_SHARED ].reset(new Subsystem::Shared (sendFunc)); 44 m_subMap[SUB_CONFIG ].reset(new Subsystem::Config (sendFunc)); 45 m_subMap[SUB_HASHER ].reset(new Subsystem::Hasher (sendFunc)); 46 m_subMap[SUB_PLUGINS ].reset(new Subsystem::Plugins (sendFunc)); 47 m_subMap[SUB_LOG ].reset(new Subsystem::Log (sendFunc)); 48 m_subMap[SUB_EXT ].reset(new Subsystem::Ext (sendFunc)); 46 49 47 50 m_socket->getEventTable().addHandler( … … 51 54 52 55 void Client::parse(const std::string &data) { 53 m_ buffer.append(data);54 while (m_ buffer.size() >= 4) {55 std::istringstream tmp(m_ buffer);56 m_inBuf.append(data); 57 while (m_inBuf.size() >= 4) { 58 std::istringstream tmp(m_inBuf); 56 59 uint8_t subsys = Utils::getVal<uint8_t>(tmp); 57 60 uint16_t size = Utils::getVal<uint16_t>(tmp); 58 if (m_ buffer.size() < size + 3u) {61 if (m_inBuf.size() < size + 3u) { 59 62 return; 60 63 } 61 std::istringstream packet(m_ buffer.substr(3, size));64 std::istringstream packet(m_inBuf.substr(3, size)); 62 65 Iter it = m_subMap.find(subsys); 63 66 if (it == m_subMap.end()) { … … 70 73 (*it).second->handle(packet); 71 74 } 72 m_ buffer.erase(0, size + 3);75 m_inBuf.erase(0, size + 3); 73 76 } 74 77 } … … 79 82 *sock >> buf; 80 83 return parse(buf); 84 } else if (evt == SOCK_WRITE) { 85 uint32_t ret = m_socket->write(m_outBuf.data(),m_outBuf.size()); 86 if (ret < m_outBuf.size()) { 87 m_outBuf.erase(0, ret); 88 } 81 89 } else if (evt == SOCK_LOST || evt == SOCK_TIMEOUT || evt == SOCK_ERR) { 82 90 destroy(); … … 89 97 } 90 98 99 void Client::sendData(const std::string &data) { 100 if (m_outBuf.size()) { 101 m_outBuf.append(data); 102 } else { 103 uint32_t ret = m_socket->write(data.data(), data.size()); 104 if (ret < data.size()) { 105 m_outBuf.append(data.substr(ret)); 106 } 107 } 108 } 109 91 110 } // namespace CGComm 92 111 hydranode/hncore/plugins/cgcomm/src/sub_auth.cpp
r1501 r1523 23 23 namespace Subsystem { 24 24 25 Auth::Auth(SocketClient *sock) : SubSysBase(sock, SUB_AUTH) {} 26 void Auth::handle(std::istream &i) {} 25 Auth::Auth( 26 boost::function<void (const std::string&)> sendFunc 27 ) : SubSysBase(SUB_AUTH, sendFunc) {} 28 29 void Auth::handle(std::istream &) {} 27 30 28 31 } hydranode/hncore/plugins/cgcomm/src/sub_config.cpp
r1501 r1523 23 23 namespace Subsystem { 24 24 25 Config::Config(SocketClient *sock) : SubSysBase(sock, SUB_CONFIG) {} 26 void Config::handle(std::istream &i) {} 25 Config::Config( 26 boost::function<void (const std::string&)> sendFunc 27 ) : SubSysBase(SUB_CONFIG, sendFunc) {} 28 29 void Config::handle(std::istream &) {} 27 30 28 31 } hydranode/hncore/plugins/cgcomm/src/sub_download.cpp
r1501 r1523 27 27 namespace Subsystem { 28 28 29 Download::Download(SocketClient *sock) : SubSysBase(sock, SUB_DOWNLOAD) {} 29 Download::Download( 30 boost::function<void (const std::string&)> sendFunc 31 ) : SubSysBase(SUB_DOWNLOAD, sendFunc) {} 32 30 33 void Download::handle(std::istream &i) { 31 34 uint8_t oc = Utils::getVal<uint8_t>(i); hydranode/hncore/plugins/cgcomm/src/sub_ext.cpp
r1501 r1523 23 23 namespace Subsystem { 24 24 25 Ext::Ext(SocketClient *sock) : SubSysBase(sock, SUB_EXT) {} 26 void Ext::handle(std::istream &i) {} 25 Ext::Ext( 26 boost::function<void (const std::string&)> sendFunc 27 ) : SubSysBase(SUB_EXT, sendFunc) {} 27 28 29 void Ext::handle(std::istream &) {} 28 30 29 31 } hydranode/hncore/plugins/cgcomm/src/sub_hasher.cpp
r1501 r1523 23 23 namespace Subsystem { 24 24 25 Hasher::Hasher(SocketClient *sock) : SubSysBase(sock, SUB_HASHER) {} 26 void Hasher::handle(std::istream &i) {} 25 Hasher::Hasher( 26 boost::function<void (const std::string&)> sendFunc 27 ) : SubSysBase(SUB_HASHER, sendFunc) {} 28 29 void Hasher::handle(std::istream &) {} 27 30 28 31 } hydranode/hncore/plugins/cgcomm/src/sub_log.cpp
r1501 r1523 23 23 namespace Subsystem { 24 24 25 Log::Log(SocketClient *sock) : SubSysBase(sock, SUB_LOG) {} 26 void Log::handle(std::istream &i) {} 25 Log::Log( 26 boost::function<void (const std::string&)> sendFunc 27 ) : SubSysBase(SUB_LOG, sendFunc) {} 28 29 void Log::handle(std::istream &) {} 27 30 28 31 } hydranode/hncore/plugins/cgcomm/src/sub_plugins.cpp
r1501 r1523 24 24 namespace Subsystem { 25 25 26 Plugins::Plugins(SocketClient *sock) : SubSysBase(sock, SUB_PLUGINS) {} 27 void Plugins::handle(std::istream &i) {} 26 Plugins::Plugins( 27 boost::function<void (const std::string&)> sendFunc 28 ) : SubSysBase(SUB_PLUGINS, sendFunc) {} 29 30 void Plugins::handle(std::istream &) {} 28 31 29 32 } hydranode/hncore/plugins/cgcomm/src/sub_search.cpp
r1501 r1523 28 28 namespace Subsystem { 29 29 30 Search::Search(SocketClient *sock) : SubSysBase(sock, SUB_SEARCH), 31 m_lastResultCount() {} 30 Search::Search( 31 boost::function<void (const std::string&)> sendFunc 32 ) : SubSysBase(SUB_SEARCH, sendFunc), m_lastResultCount() {} 32 33 33 34 void Search::handle(std::istream &i) { hydranode/hncore/plugins/cgcomm/src/sub_shared.cpp
r1501 r1523 23 23 namespace Subsystem { 24 24 25 Shared::Shared(SocketClient *sock) : SubSysBase(sock, SUB_SHARED) {} 26 void Shared::handle(std::istream &i) {} 25 Shared::Shared( 26 boost::function<void (const std::string&)> sendFunc 27 ) : SubSysBase(SUB_SHARED, sendFunc) {} 28 29 void Shared::handle(std::istream &) {} 27 30 28 31 } hydranode/hncore/plugins/cgcomm/src/subsysbase.cpp
r1501 r1523 25 25 namespace CGComm { 26 26 27 SubSysBase::SubSysBase(SocketClient *sock, uint8_t subCode) 28 : m_socket(sock), m_subCode(subCode) {} 27 SubSysBase::SubSysBase( 28 uint8_t subCode, boost::function<void (const std::string&)> sendFunc 29 ) : sendData(sendFunc), m_subCode(subCode) {} 29 30 30 31 SubSysBase::~SubSysBase() {} … … 35 36 Utils::putVal<uint16_t>(tmp, data.size()); // packet size 36 37 Utils::putVal<std::string>(tmp, data.data(), data.size()); 37 uint32_t ret = m_socket->write(tmp.str().data(), tmp.str().size());38 sendData(tmp.str()); 38 39 } 39 40 hydranode/include/hncore/cgcomm/client.h
r1510 r1523 25 25 26 26 namespace CGComm { 27 27 28 class SubSysBase; 29 28 30 enum ClientEvents { 29 31 EVT_DESTROY … … 35 37 36 38 Client(SocketClient *sock); 37 38 39 void destroy(); 39 40 private: 40 41 void parse(const std::string &data); 41 42 void onSocketEvent(SocketClient *sock, SocketEvent evt); 43 void sendData(const std::string &data); 42 44 43 45 typedef std::map<uint8_t, boost::shared_ptr<SubSysBase> > SubMap; 44 SubMap m_subMap;45 46 typedef SubMap::iterator Iter; 46 47 47 std::string m_buffer; 48 SubMap m_subMap; 49 std::string m_inBuf; 50 std::string m_outBuf; 48 51 SocketClient *m_socket; 49 52 }; hydranode/include/hncore/cgcomm/sub_auth.h
r1510 r1523 26 26 class Auth : public SubSysBase { 27 27 public: 28 Auth( SocketClient *sock);28 Auth(boost::function<void (const std::string&)> sendFunc); 29 29 virtual void handle(std::istream &i); 30 30 }; hydranode/include/hncore/cgcomm/sub_config.h
r1510 r1523 26 26 class Config : public SubSysBase { 27 27 public: 28 Config( SocketClient *sock);28 Config(boost::function<void (const std::string&)> sendFunc); 29 29 virtual void handle(std::istream &i); 30 30 }; hydranode/include/hncore/cgcomm/sub_download.h
r1510 r1523 27 27 class Download : public SubSysBase { 28 28 public: 29 Download( SocketClient *sock);29 Download(boost::function<void (const std::string&)> sendFunc); 30 30 virtual void handle(std::istream &i); 31 31 private: hydranode/include/hncore/cgcomm/sub_ext.h
r1510 r1523 28 28 class Ext : public SubSysBase { 29 29 public: 30 Ext( SocketClient *sock);30 Ext(boost::function<void (const std::string&)> sendFunc); 31 31 virtual void handle(std::istream &i); 32 32 }; hydranode/include/hncore/cgcomm/sub_hasher.h
r1510 r1523 27 27 class Hasher : public SubSysBase { 28 28 public: 29 Hasher( SocketClient *sock);29 Hasher(boost::function<void (const std::string&)> sendFunc); 30 30 virtual void handle(std::istream &i); 31 31 }; hydranode/include/hncore/cgcomm/sub_log.h
r1507 r1523 26 26 class Log : public SubSysBase { 27 27 public: 28 Log( SocketClient *sock);28 Log(boost::function<void (const std::string&)> sendFunc); 29 29 virtual void handle(std::istream &i); 30 30 }; hydranode/include/hncore/cgcomm/sub_plugins.h
r1510 r1523 27 27 class Plugins : public SubSysBase { 28 28 public: 29 Plugins( SocketClient *sock);29 Plugins(boost::function<void (const std::string&)> sendFunc); 30 30 virtual void handle(std::istream &i); 31 31 }; hydranode/include/hncore/cgcomm/sub_search.h
r1510 r1523 29 29 class Search : public SubSysBase { 30 30 public: 31 Search( SocketClient *sock);31 Search(boost::function<void (const std::string&)> sendFunc); 32 32 virtual void handle(std::istream &i); 33 33 private: hydranode/include/hncore/cgcomm/sub_shared.h
r1510 r1523 27 27 class Shared : public SubSysBase { 28 28 public: 29 Shared( SocketClient *sock);29 Shared(boost::function<void (const std::string&)> sendFunc); 30 30 virtual void handle(std::istream &i); 31 31 }; hydranode/include/hncore/cgcomm/subsysbase.h
r1510 r1523 27 27 class SubSysBase { 28 28 public: 29 SubSysBase(SocketClient *c, uint8_t subCode); 29 SubSysBase( 30 uint8_t subCode, 31 boost::function<void (const std::string&)> sendFunc 32 ); 33 30 34 virtual ~SubSysBase(); 31 35 virtual void handle(std::istream&) = 0; 32 36 void sendPacket(const std::string &packet); 33 37 private: 34 SocketClient *m_socket; // socket to write data to 38 // function used to send data 39 boost::function<void (const std::string&)> sendData; 35 40 uint8_t m_subCode; // subsystem code 36 41 };
