diff options
Diffstat (limited to 'src/Common')
-rw-r--r-- | src/Common/ConfigManager.cpp | 3 | ||||
-rw-r--r-- | src/Common/ConfigManager.h | 12 | ||||
-rw-r--r-- | src/Common/RequestHandler.h | 2 | ||||
-rw-r--r-- | src/Common/RequestHandlers/IdentifyRequestHandler.cpp | 3 | ||||
-rw-r--r-- | src/Common/RequestManager.cpp | 3 | ||||
-rw-r--r-- | src/Common/RequestManager.h | 22 | ||||
-rw-r--r-- | src/Common/Requests/DisconnectRequest.cpp | 4 | ||||
-rw-r--r-- | src/Common/Requests/DisconnectRequest.h | 5 | ||||
-rw-r--r-- | src/Common/Requests/GSSAPIAuthRequest.cpp | 4 | ||||
-rw-r--r-- | src/Common/Requests/GSSAPIAuthRequest.h | 2 | ||||
-rw-r--r-- | src/Common/Requests/IdentifyRequest.cpp | 8 | ||||
-rw-r--r-- | src/Common/Requests/IdentifyRequest.h | 5 | ||||
-rw-r--r-- | src/Common/SystemBackend.cpp | 2 | ||||
-rw-r--r-- | src/Common/SystemBackend.h | 8 |
14 files changed, 56 insertions, 27 deletions
diff --git a/src/Common/ConfigManager.cpp b/src/Common/ConfigManager.cpp index a363862..76227b4 100644 --- a/src/Common/ConfigManager.cpp +++ b/src/Common/ConfigManager.cpp @@ -27,6 +27,9 @@ namespace Mad { namespace Common { +std::auto_ptr<ConfigManager> ConfigManager::configManager; + + bool ConfigManager::loadFile(const std::string &filename) { std::ifstream file(filename.c_str()); std::vector<std::string> section; diff --git a/src/Common/ConfigManager.h b/src/Common/ConfigManager.h index 5c94614..91126ca 100644 --- a/src/Common/ConfigManager.h +++ b/src/Common/ConfigManager.h @@ -22,16 +22,24 @@ #include <string> #include <vector> +#include <memory> namespace Mad { namespace Common { class ConfigManager { + private: + static std::auto_ptr<ConfigManager> configManager; + protected: ConfigManager() { initBackends(); } + static void setConfigManager(ConfigManager *configManager0) { + configManager = std::auto_ptr<ConfigManager>(configManager0); + } + virtual bool parseLine(const std::vector<std::string> §ion, const std::string &key, const std::string &value = std::string()) = 0; bool loadFile(const std::string &filename); @@ -40,6 +48,10 @@ class ConfigManager { public: virtual ~ConfigManager() {} + + static ConfigManager *getConfigManager() { + return configManager.get(); + } }; } diff --git a/src/Common/RequestHandler.h b/src/Common/RequestHandler.h index a6995ec..4a72bd5 100644 --- a/src/Common/RequestHandler.h +++ b/src/Common/RequestHandler.h @@ -29,6 +29,8 @@ class Packet; namespace Common { +class RequestManager; + class RequestHandler { private: bool finished; diff --git a/src/Common/RequestHandlers/IdentifyRequestHandler.cpp b/src/Common/RequestHandlers/IdentifyRequestHandler.cpp index 791eadd..d17c3b2 100644 --- a/src/Common/RequestHandlers/IdentifyRequestHandler.cpp +++ b/src/Common/RequestHandlers/IdentifyRequestHandler.cpp @@ -32,7 +32,8 @@ bool IdentifyRequestHandler::handlePacket(Net::Connection *connection, const Net return false; // TODO Logging // TODO Require authentication - // TODO Save identity information + + connection->setName(std::string((const char*)packet.getData(), packet.getLength())); if(!connection->send(Net::Packet(Net::Packet::OK, packet.getRequestId()))) return false; diff --git a/src/Common/RequestManager.cpp b/src/Common/RequestManager.cpp index 7075229..93bbea5 100644 --- a/src/Common/RequestManager.cpp +++ b/src/Common/RequestManager.cpp @@ -27,6 +27,9 @@ namespace Mad { namespace Common { +std::auto_ptr<RequestManager> RequestManager::requestManager; + + RequestHandler* RequestManager::RequestMap::findRequest(uint16_t id) { iterator it = find(id); if(it == end()) diff --git a/src/Common/RequestManager.h b/src/Common/RequestManager.h index 2ca10e7..795f277 100644 --- a/src/Common/RequestManager.h +++ b/src/Common/RequestManager.h @@ -22,7 +22,10 @@ #include "RequestHandler.h" #include <Net/Connection.h> + #include <map> +#include <memory> + namespace Mad { namespace Common { @@ -68,9 +71,7 @@ class RequestManager { } }; - // Prevent shallow copy - RequestManager(const RequestManager &o); - RequestManager& operator=(const RequestManager &o); + static std::auto_ptr<RequestManager> requestManager; std::map<Net::Connection*,RequestMap*> requestMaps; uint16_t requestId; @@ -81,9 +82,23 @@ class RequestManager { return requestId+=2; } + // Prevent shallow copy + RequestManager(const RequestManager &o); + RequestManager& operator=(const RequestManager &o); + + RequestManager(bool core); + void receiveHandler(Net::Connection *connection, const Net::Packet &packet); public: + static void init(bool core) { + requestManager = std::auto_ptr<RequestManager>(new RequestManager(core)); + } + + static RequestManager* getRequestManager() { + return requestManager.get(); + } + void registerConnection(Net::Connection *connection); void unregisterConnection(Net::Connection *connection); @@ -95,7 +110,6 @@ class RequestManager { bool sendRequest(Net::Connection *connection, Request *request); - RequestManager(bool core); virtual ~RequestManager(); }; diff --git a/src/Common/Requests/DisconnectRequest.cpp b/src/Common/Requests/DisconnectRequest.cpp index 2652af2..0b6e3bc 100644 --- a/src/Common/Requests/DisconnectRequest.cpp +++ b/src/Common/Requests/DisconnectRequest.cpp @@ -24,12 +24,12 @@ namespace Mad { namespace Common { namespace Requests { -bool DisconnectRequest::send(Net::Connection *connection, RequestManager &requestManager, const sigc::slot<void> &callback) { +bool DisconnectRequest::send(Net::Connection *connection, const sigc::slot<void> &callback) { DisconnectRequest *request = new DisconnectRequest(); request->finished.connect(callback); - if(requestManager.sendRequest(connection, request)) + if(Mad::Common::RequestManager::getRequestManager()->sendRequest(connection, request)) return true; delete request; diff --git a/src/Common/Requests/DisconnectRequest.h b/src/Common/Requests/DisconnectRequest.h index a569d8f..6c87f85 100644 --- a/src/Common/Requests/DisconnectRequest.h +++ b/src/Common/Requests/DisconnectRequest.h @@ -26,9 +26,6 @@ namespace Mad { namespace Common { - -class RequestManager; - namespace Requests { class DisconnectRequest : public Request { @@ -38,7 +35,7 @@ class DisconnectRequest : public Request { DisconnectRequest() {} public: - static bool send(Net::Connection *connection, RequestManager &requestManager, const sigc::slot<void> &callback); + static bool send(Net::Connection *connection, const sigc::slot<void> &callback); virtual bool sendRequest(Net::Connection *connection, uint16_t requestId); virtual bool handlePacket(Net::Connection *connection, const Net::Packet &packet); diff --git a/src/Common/Requests/GSSAPIAuthRequest.cpp b/src/Common/Requests/GSSAPIAuthRequest.cpp index 1874064..705db41 100644 --- a/src/Common/Requests/GSSAPIAuthRequest.cpp +++ b/src/Common/Requests/GSSAPIAuthRequest.cpp @@ -37,10 +37,10 @@ GSSAPIAuthRequest::~GSSAPIAuthRequest() { gss_release_name(&minStat, &gssServiceName); } -bool GSSAPIAuthRequest::send(Net::Connection *connection, RequestManager &requestManager, const std::string &serviceName0) { +bool GSSAPIAuthRequest::send(Net::Connection *connection, const std::string &serviceName0) { GSSAPIAuthRequest *request = new GSSAPIAuthRequest(serviceName0); - if(requestManager.sendRequest(connection, request)) + if(Mad::Common::RequestManager::getRequestManager()->sendRequest(connection, request)) return true; delete request; diff --git a/src/Common/Requests/GSSAPIAuthRequest.h b/src/Common/Requests/GSSAPIAuthRequest.h index a4a2f17..e9a200e 100644 --- a/src/Common/Requests/GSSAPIAuthRequest.h +++ b/src/Common/Requests/GSSAPIAuthRequest.h @@ -46,7 +46,7 @@ class GSSAPIAuthRequest : public Request { public: virtual ~GSSAPIAuthRequest(); - static bool send(Net::Connection *connection, RequestManager &requestManager, const std::string &serviceName0); + static bool send(Net::Connection *connection, const std::string &serviceName0); virtual bool sendRequest(Net::Connection *connection, uint16_t requestId); virtual bool handlePacket(Net::Connection *connection, const Net::Packet &packet); diff --git a/src/Common/Requests/IdentifyRequest.cpp b/src/Common/Requests/IdentifyRequest.cpp index 18b515f..54d49e2 100644 --- a/src/Common/Requests/IdentifyRequest.cpp +++ b/src/Common/Requests/IdentifyRequest.cpp @@ -25,10 +25,10 @@ namespace Mad { namespace Common { namespace Requests { -bool IdentifyRequest::send(Net::Connection *connection, RequestManager &requestManager, const std::string &hostname0) { +bool IdentifyRequest::send(Net::Connection *connection, const std::string &hostname0) { IdentifyRequest *request = new IdentifyRequest(hostname0); - if(requestManager.sendRequest(connection, request)) + if(RequestManager::getRequestManager()->sendRequest(connection, request)) return true; delete request; @@ -53,8 +53,8 @@ bool IdentifyRequest::handlePacket(Net::Connection*, const Net::Packet &packet) if(packet.getType() != Net::Packet::OK) return false; // TODO Logging - setFinished(); - return true; + setFinished(); + return true; } } diff --git a/src/Common/Requests/IdentifyRequest.h b/src/Common/Requests/IdentifyRequest.h index 9fb45d9..0b783e4 100644 --- a/src/Common/Requests/IdentifyRequest.h +++ b/src/Common/Requests/IdentifyRequest.h @@ -25,9 +25,6 @@ namespace Mad { namespace Common { - -class RequestManager; - namespace Requests { class IdentifyRequest : public Request { @@ -37,7 +34,7 @@ class IdentifyRequest : public Request { std::string hostname; public: - static bool send(Net::Connection *connection, RequestManager &requestManager, const std::string &hostname0); + static bool send(Net::Connection *connection, const std::string &hostname0); virtual bool sendRequest(Net::Connection *connection, uint16_t requestId); virtual bool handlePacket(Net::Connection*, const Net::Packet &packet); diff --git a/src/Common/SystemBackend.cpp b/src/Common/SystemBackend.cpp index 8b9aa0d..c9be525 100644 --- a/src/Common/SystemBackend.cpp +++ b/src/Common/SystemBackend.cpp @@ -22,7 +22,7 @@ namespace Mad { namespace Common { -SystemBackend *SystemBackend::backend = new SystemBackend(); +std::auto_ptr<SystemBackend> SystemBackend::backend(new SystemBackend()); } } diff --git a/src/Common/SystemBackend.h b/src/Common/SystemBackend.h index 6929c8d..19b0715 100644 --- a/src/Common/SystemBackend.h +++ b/src/Common/SystemBackend.h @@ -21,20 +21,20 @@ #define MAD_COMMON_SYSTEMBACKEND_H_ #include <stdint.h> +#include <memory> namespace Mad { namespace Common { class SystemBackend { private: - static SystemBackend *backend; + static std::auto_ptr<SystemBackend> backend; protected: SystemBackend() {} static void setBackend(SystemBackend *backend0) { - delete backend; - backend = backend0; + backend = std::auto_ptr<SystemBackend>(backend0); } public: @@ -63,7 +63,7 @@ class SystemBackend { } static SystemBackend *getBackend() { - return backend; + return backend.get(); } }; |