summaryrefslogtreecommitdiffstats
path: root/src/Common
diff options
context:
space:
mode:
Diffstat (limited to 'src/Common')
-rw-r--r--src/Common/CMakeLists.txt27
-rw-r--r--src/Common/RequestHandlerGroup.h46
-rw-r--r--src/Common/RequestHandlers/CMakeLists.txt4
-rw-r--r--src/Common/RequestManager.cpp25
-rw-r--r--src/Common/RequestManager.h50
-rw-r--r--src/Common/Requests/CMakeLists.txt11
6 files changed, 133 insertions, 30 deletions
diff --git a/src/Common/CMakeLists.txt b/src/Common/CMakeLists.txt
index de6dfc7..25c3dee 100644
--- a/src/Common/CMakeLists.txt
+++ b/src/Common/CMakeLists.txt
@@ -6,9 +6,28 @@ include_directories(${INCLUDES})
link_directories(${LTDL_LIBRARY_DIR})
add_library(Common
- Base64Encoder.cpp ClientConnection.cpp ConfigEntry.cpp
- ConfigManager.cpp Connection.cpp Initializable.cpp Logger.cpp LogManager.cpp
- ModuleManager.cpp Request.cpp RequestHandler.cpp RequestManager.cpp SystemManager.cpp
- Tokenizer.cpp XmlPacket.cpp
+ Base64Encoder.cpp Base64Encoder.h
+ ClientConnection.cpp ClientConnection.h
+ ConfigEntry.cpp ConfigEntry.h
+ ConfigManager.cpp ConfigManager.h
+ Configurable.h
+ Connection.cpp Connection.h
+ Initializable.cpp Initializable.h
+ GroupInfo.h
+ HostInfo.h
+ Logger.cpp Logger.h
+ LoggerBase.h
+ LogManager.cpp LogManager.h
+ ModuleManager.cpp ModuleManager.h
+ RemoteLogger.h
+ Request.cpp Request.h
+ RequestHandler.cpp RequestHandler.h
+ RequestHandlerGroup.h
+ RequestManager.cpp RequestManager.h
+ SystemBackend.h
+ SystemManager.cpp SystemManager.h
+ Tokenizer.cpp Tokenizer.h
+ UserInfo.h
+ XmlPacket.cpp XmlPacket.h
)
target_link_libraries(Common RequestHandlers Requests Net ${LIBXML2_LIBRARIES} ${LTDL_LIBRARIES})
diff --git a/src/Common/RequestHandlerGroup.h b/src/Common/RequestHandlerGroup.h
new file mode 100644
index 0000000..c9f57eb
--- /dev/null
+++ b/src/Common/RequestHandlerGroup.h
@@ -0,0 +1,46 @@
+/*
+ * RequestHandlerGroup.h
+ *
+ * Copyright (C) 2009 Matthias Schiffer <matthias@gamezock.de>
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef MAD_COMMON_REQUESTHANDLERGROUP_H_
+#define MAD_COMMON_REQUESTHANDLERGROUP_H_
+
+#include "RequestHandler.h"
+
+#include <set>
+#include <string>
+
+namespace Mad {
+namespace Common {
+
+class RequestHandlerGroup {
+ protected:
+ RequestHandlerGroup() {}
+
+ public:
+ virtual const std::set<std::string>& getPacketTypes() = 0;
+
+ virtual boost::shared_ptr<RequestHandler> createRequestHandler(const std::string &type) = 0;
+ virtual ~RequestHandlerGroup() {}
+};
+
+}
+
+}
+
+#endif /* MAD_COMMON_REQUESTHANDLERGROUP_H_ */
diff --git a/src/Common/RequestHandlers/CMakeLists.txt b/src/Common/RequestHandlers/CMakeLists.txt
index f774e14..5788ada 100644
--- a/src/Common/RequestHandlers/CMakeLists.txt
+++ b/src/Common/RequestHandlers/CMakeLists.txt
@@ -1,6 +1,8 @@
include_directories(${INCLUDES})
add_library(RequestHandlers STATIC
- DisconnectRequestHandler.cpp FSInfoRequestHandler.cpp StatusRequestHandler.cpp
+ DisconnectRequestHandler.cpp DisconnectRequestHandler.h
+ FSInfoRequestHandler.cpp FSInfoRequestHandler.h
+ StatusRequestHandler.cpp StatusRequestHandler.h
)
target_link_libraries(RequestHandlers Common)
diff --git a/src/Common/RequestManager.cpp b/src/Common/RequestManager.cpp
index 3785b3f..b443292 100644
--- a/src/Common/RequestManager.cpp
+++ b/src/Common/RequestManager.cpp
@@ -108,21 +108,24 @@ void RequestManager::receiveHandler(Connection *connection, boost::shared_ptr<co
return;
}
- std::map<std::string, boost::shared_ptr<RequestHandlerFactory> >::iterator factoryIt = requestHandlerFactories.find(packet->getType());
- if(factoryIt != requestHandlerFactories.end()) {
- {
- boost::upgrade_to_unique_lock<boost::shared_mutex> upgradeLock(lock);
+ std::map<std::string, boost::shared_ptr<RequestHandlerGroup> >::iterator rgh = requestHandlerGroups.find(packet->getType());
+ if(rgh != requestHandlerGroups.end()) {
+ request = rgh->second->createRequestHandler(packet->getType());
- request = factoryIt->second->createRequestHandler();
- requestMap.addRequest(connection, requestId, request);
- request->connectSignalFinished(boost::bind(&RequestManager::handleRequestFinished, this, connection, requestId));
+ if(request) {
+ {
+ boost::upgrade_to_unique_lock<boost::shared_mutex> upgradeLock(lock);
- }
+ requestMap.addRequest(connection, requestId, request);
+ request->connectSignalFinished(boost::bind(&RequestManager::handleRequestFinished, this, connection, requestId));
- lock.unlock();
- Net::ThreadManager::get()->pushWork(boost::bind(&RequestHandler::handlePacket, request, packet));
+ }
- return;
+ lock.unlock();
+ Net::ThreadManager::get()->pushWork(boost::bind(&RequestHandler::handlePacket, request, packet));
+
+ return;
+ }
}
lock.unlock();
diff --git a/src/Common/RequestManager.h b/src/Common/RequestManager.h
index 07a7c05..e66b0c1 100644
--- a/src/Common/RequestManager.h
+++ b/src/Common/RequestManager.h
@@ -21,6 +21,7 @@
#define MAD_COMMON_REQUESTMANAGER_H_
#include "Request.h"
+#include "RequestHandlerGroup.h"
#include <map>
#include <memory>
@@ -69,18 +70,20 @@ class RequestManager : boost::noncopyable {
- class RequestHandlerFactory {
- protected:
- RequestHandlerFactory() {}
+ template<class T> class RequestHandlerFactory : public RequestHandlerGroup {
+ private:
+ std::set<std::string> types;
public:
- virtual boost::shared_ptr<RequestHandler> createRequestHandler() = 0;
- virtual ~RequestHandlerFactory() {}
- };
+ RequestHandlerFactory(const std::string &type) {
+ types.insert(type);
+ }
- template<class T> class SpecificRequestHandlerFactory : public RequestHandlerFactory {
- public:
- virtual boost::shared_ptr<RequestHandler> createRequestHandler() {
+ virtual const std::set<std::string>& getPacketTypes() {
+ return types;
+ }
+
+ virtual boost::shared_ptr<RequestHandler> createRequestHandler(const std::string &type _UNUSED_PARAMETER_) {
return boost::shared_ptr<RequestHandler>(new T());
}
};
@@ -94,7 +97,7 @@ class RequestManager : boost::noncopyable {
bool server;
boost::uint16_t lastRequestId;
- std::map<std::string, boost::shared_ptr<RequestHandlerFactory> > requestHandlerFactories;
+ std::map<std::string, boost::shared_ptr<RequestHandlerGroup> > requestHandlerGroups;
boost::uint16_t _getRequestId() {
return lastRequestId+=2;
@@ -141,14 +144,35 @@ class RequestManager : boost::noncopyable {
requestMap.unregisterConnection(connection);
}
- template <class T> void registerPacketType(const std::string &type) {
+ void registerRequestHandlerGroup(boost::shared_ptr<RequestHandlerGroup> requestHandlerGroup) {
boost::lock_guard<boost::shared_mutex> lock(mutex);
- requestHandlerFactories.insert(std::make_pair(type, boost::shared_ptr<SpecificRequestHandlerFactory<T> >(new SpecificRequestHandlerFactory<T>())));
+
+ const std::set<std::string> &types = requestHandlerGroup->getPacketTypes();
+ for(std::set<std::string>::const_iterator type = types.begin(); type != types.end(); ++type)
+ requestHandlerGroups.insert(std::make_pair(*type, requestHandlerGroup));
+ }
+
+ void unregisterRequestHandlerGroup(boost::shared_ptr<RequestHandlerGroup> requestHandlerGroup) {
+ boost::lock_guard<boost::shared_mutex> lock(mutex);
+
+ const std::set<std::string> &types = requestHandlerGroup->getPacketTypes();
+ for(std::set<std::string>::const_iterator type = types.begin(); type != types.end(); ++type) {
+ std::map<std::string, boost::shared_ptr<RequestHandlerGroup> >::iterator it = requestHandlerGroups.find(*type);
+
+ if(it == requestHandlerGroups.end() || it->second != requestHandlerGroup)
+ continue;
+
+ requestHandlerGroups.erase(it);
+ }
+ }
+
+ template <class T> void registerPacketType(const std::string &type) {
+ registerRequestHandlerGroup(boost::shared_ptr<RequestHandlerFactory<T> >(new RequestHandlerFactory<T>(type)));
}
void unregisterPacketType(const std::string &type) {
boost::lock_guard<boost::shared_mutex> lock(mutex);
- requestHandlerFactories.erase(type);
+ requestHandlerGroups.erase(type);
}
bool sendRequest(Connection *connection, boost::shared_ptr<Request> request);
diff --git a/src/Common/Requests/CMakeLists.txt b/src/Common/Requests/CMakeLists.txt
index ef1d4d9..b6ff90c 100644
--- a/src/Common/Requests/CMakeLists.txt
+++ b/src/Common/Requests/CMakeLists.txt
@@ -1,6 +1,15 @@
include_directories(${INCLUDES})
add_library(Requests STATIC
- DisconnectRequest.cpp GroupUserListRequest.cpp IdentifyRequest.cpp SimpleRequest.cpp UserGroupListRequest.cpp UserInfoRequest.cpp
+ DisconnectRequest.cpp DisconnectRequest.h
+ FSInfoRequest.h
+ GroupListRequest.h
+ GroupUserListRequest.cpp GroupUserListRequest.h
+ IdentifyRequest.cpp IdentifyRequest.h
+ SimpleRequest.cpp SimpleRequest.h
+ StatusRequest.h
+ UserGroupListRequest.cpp UserGroupListRequest.h
+ UserInfoRequest.cpp UserInfoRequest.h
+ UserListRequest.h
)
target_link_libraries(Requests ${KRB5_LIBRARIES})