summaryrefslogtreecommitdiffstats
path: root/src/Common/RequestManager.h
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2008-07-09 01:27:56 +0200
committerMatthias Schiffer <matthias@gamezock.de>2008-07-09 01:27:56 +0200
commita0f9826c9f02909bc87e1a1d92eea1dca85f2ebc (patch)
treeca5b4728a755833f58c29ec2ce1306a6fdb4a750 /src/Common/RequestManager.h
parent1508969d508e41de824d1d1227be708136760cfa (diff)
downloadmad-a0f9826c9f02909bc87e1a1d92eea1dca85f2ebc.tar
mad-a0f9826c9f02909bc87e1a1d92eea1dca85f2ebc.zip
Kern und D?monen/Clients benutzen jetzt unterscheidbare Request IDs; au?erdem ein paar Bugfixes am Request-Code
Diffstat (limited to 'src/Common/RequestManager.h')
-rw-r--r--src/Common/RequestManager.h42
1 files changed, 35 insertions, 7 deletions
diff --git a/src/Common/RequestManager.h b/src/Common/RequestManager.h
index fde8f3e..543fb83 100644
--- a/src/Common/RequestManager.h
+++ b/src/Common/RequestManager.h
@@ -30,7 +30,14 @@ namespace Common {
class RequestManager {
private:
class RequestMap : private std::map<unsigned short,Request::Request*> {
+ private:
+ // Prevent shallow copy
+ RequestMap(const RequestMap &o);
+ RequestMap& operator=(const RequestMap &o);
+
public:
+ RequestMap() {}
+
~RequestMap() {
for(iterator it = begin(); it != end(); ++it)
delete it->second;
@@ -49,35 +56,56 @@ class RequestManager {
}
bool deleteRequest(unsigned short id) {
- return erase(id);
+ iterator it = find(id);
+ if(it == end())
+ return false;
+
+ delete it->second;
+
+ erase(it);
+ return true;
}
};
- std::map<Net::Connection*,RequestMap> requestMap;
+ // Prevent shallow copy
+ RequestManager(const RequestManager &o);
+ RequestManager& operator=(const RequestManager &o);
+
+ std::map<Net::Connection*,RequestMap*> requestMaps;
unsigned short requestId;
unsigned short getRequestId() {
- return requestId++;
+ return requestId+=2;
}
void receiveHandler(Net::Connection *connection, const Net::Packet &packet);
public:
void registerConnection(Net::Connection *connection) {
- requestMap.insert(std::make_pair(connection, RequestMap()));
+ requestMaps.insert(std::make_pair(connection, new RequestMap()));
connection->signalReceive().connect(sigc::mem_fun(this, &RequestManager::receiveHandler));
}
void unregisterConnection(Net::Connection *connection) {
- requestMap.erase(connection);
+ std::map<Net::Connection*,RequestMap*>::iterator it = requestMaps.find(connection);
+
+ if(it == requestMaps.end())
+ return;
+
+ delete it->second;
+
+ requestMaps.erase(it);
}
bool sendRequest(Net::Connection *connection, Request::Request *request);
- RequestManager() : requestId(0) {}
+ RequestManager(bool core) : requestId(core ? -2 : -1) {}
- virtual ~RequestManager() {}
+ virtual ~RequestManager() {
+ for(std::map<Net::Connection*,RequestMap*>::iterator it = requestMaps.begin(); it != requestMaps.end(); ++it)
+ delete it->second;
+ }
};
}