summaryrefslogtreecommitdiffstats
path: root/src/Common
diff options
context:
space:
mode:
Diffstat (limited to 'src/Common')
-rw-r--r--src/Common/ClientConnection.cpp6
-rw-r--r--src/Common/ClientConnection.h6
-rw-r--r--src/Common/Connection.cpp7
-rw-r--r--src/Common/Connection.h4
-rw-r--r--src/Common/Exception.cpp63
-rw-r--r--src/Common/Exception.h61
-rw-r--r--src/Common/LogManager.cpp1
-rw-r--r--src/Common/LogManager.h7
-rw-r--r--src/Common/Makefile.am8
-rw-r--r--src/Common/Makefile.in17
-rw-r--r--src/Common/Request.cpp4
-rw-r--r--src/Common/Request.h10
-rw-r--r--src/Common/RequestHandler.h4
-rw-r--r--src/Common/RequestHandlers/DisconnectRequestHandler.cpp4
-rw-r--r--src/Common/RequestHandlers/FSInfoRequestHandler.cpp6
-rw-r--r--src/Common/RequestHandlers/StatusRequestHandler.cpp4
-rw-r--r--src/Common/RequestManager.cpp2
-rw-r--r--src/Common/Requests/DisconnectRequest.cpp4
-rw-r--r--src/Common/Requests/GSSAPIAuthRequest.cpp17
-rw-r--r--src/Common/ThreadManager.cpp153
-rw-r--r--src/Common/ThreadManager.h105
21 files changed, 52 insertions, 441 deletions
diff --git a/src/Common/ClientConnection.cpp b/src/Common/ClientConnection.cpp
index e030bfc..0e080fd 100644
--- a/src/Common/ClientConnection.cpp
+++ b/src/Common/ClientConnection.cpp
@@ -27,11 +27,11 @@ ClientConnection::ClientConnection() : connection(new Net::ClientConnection) {
connection->signalReceive().connect(sigc::mem_fun(this, &ClientConnection::receive));
}
-bool ClientConnection::send(const Net::Packet &packet) {
- return connection->send(packet);
+void ClientConnection::send(const Net::Packet &packet) {
+ connection->send(packet);
}
-void ClientConnection::connect(const Net::IPAddress &address, bool daemon) throw(Common::Exception) {
+void ClientConnection::connect(const Net::IPAddress &address, bool daemon) throw(Net::Exception) {
connection->connect(address, daemon);
}
diff --git a/src/Common/ClientConnection.h b/src/Common/ClientConnection.h
index 7e422b0..28a7016 100644
--- a/src/Common/ClientConnection.h
+++ b/src/Common/ClientConnection.h
@@ -21,7 +21,7 @@
#define MAD_COMMON_CLIENTCONNECTION_H_
#include "Connection.h"
-#include "Exception.h"
+#include <Net/Exception.h>
namespace Mad {
@@ -37,13 +37,13 @@ class ClientConnection : public Connection {
Net::ClientConnection *connection;
protected:
- virtual bool send(const Net::Packet &packet);
+ virtual void send(const Net::Packet &packet);
public:
ClientConnection();
virtual ~ClientConnection() {}
- void connect(const Net::IPAddress &address, bool daemon = false) throw(Common::Exception);
+ void connect(const Net::IPAddress &address, bool daemon = false) throw(Net::Exception);
bool isConnecting() const;
bool isConnected() const;
diff --git a/src/Common/Connection.cpp b/src/Common/Connection.cpp
index b4e5db4..cde3fc2 100644
--- a/src/Common/Connection.cpp
+++ b/src/Common/Connection.cpp
@@ -20,16 +20,19 @@
#include "Connection.h"
#include "XmlPacket.h"
+#include <sigc++/bind.h>
namespace Mad {
namespace Common {
void Connection::receive(const Net::Packet &packet) {
+ // receive() will be called by FdManager (main thread)
+ // -> let the ThreadManager call the handler in the worker thread
signal(XmlPacket(packet), packet.getRequestId());
}
-bool Connection::sendPacket(const XmlPacket &packet, uint16_t requestId) {
- return send(packet.encode(requestId));
+void Connection::sendPacket(const XmlPacket &packet, uint16_t requestId) {
+ send(packet.encode(requestId));
}
}
diff --git a/src/Common/Connection.h b/src/Common/Connection.h
index 860c044..7bcb92b 100644
--- a/src/Common/Connection.h
+++ b/src/Common/Connection.h
@@ -50,12 +50,12 @@ class Connection {
void receive(const Net::Packet &packet);
- virtual bool send(const Net::Packet &packet) = 0;
+ virtual void send(const Net::Packet &packet) = 0;
public:
virtual ~Connection() {}
- bool sendPacket(const XmlPacket &packet, uint16_t requestId);
+ void sendPacket(const XmlPacket &packet, uint16_t requestId);
sigc::signal<void, const XmlPacket&, uint16_t> signalReceive() const {
return signal;
diff --git a/src/Common/Exception.cpp b/src/Common/Exception.cpp
deleted file mode 100644
index 67eb1d9..0000000
--- a/src/Common/Exception.cpp
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Exception.cpp
- *
- * Copyright (C) 2008 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/>.
- */
-
-#include "Exception.h"
-
-#include <cstring>
-#include <gnutls/gnutls.h>
-
-namespace Mad {
-namespace Common {
-
-std::string Exception::strerror() const {
- std::string ret;
-
- if(!where.empty())
- ret = where + ": ";
-
- switch(errorCode) {
- case SUCCESS:
- return ret + "Success";
- case UNEXPECTED_PACKET:
- return ret + "An unexpected packet was received";
- case INVALID_ACTION:
- return ret + "The action is invalid";
- case NOT_AVAILABLE:
- return ret + "Not available";
- case NOT_FINISHED:
- return ret + "Not finished";
- case NOT_IMPLEMENTED:
- return ret + "Not implemented";
- case INTERNAL_ERRNO:
- return ret + std::strerror(subCode);
- case INTERNAL_GNUTLS:
- return ret + "GnuTLS error: " + gnutls_strerror(subCode);
- case INVALID_ADDRESS:
- return ret + "Invalid address";
- case ALREADY_IDENTIFIED:
- return ret + "The host is already identified";
- case UNKNOWN_DAEMON:
- return ret + "The daemon is unknown";
- default:
- return ret + "Unknown error";
- }
-}
-
-}
-}
diff --git a/src/Common/Exception.h b/src/Common/Exception.h
deleted file mode 100644
index 7b86fbd..0000000
--- a/src/Common/Exception.h
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Exception.h
- *
- * Copyright (C) 2008 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_EXCEPTION_H_
-#define MAD_COMMON_EXCEPTION_H_
-
-#include <string>
-
-namespace Mad {
-namespace Common {
-
-class Exception {
- public:
- enum ErrorCode {
- SUCCESS = 0x0000, UNEXPECTED_PACKET = 0x0001, INVALID_ACTION = 0x0002, NOT_AVAILABLE = 0x0003, NOT_FINISHED = 0x0004, NOT_IMPLEMENTED = 0x0005,
- INTERNAL_ERRNO = 0x0010, INTERNAL_GNUTLS = 0x0011,
- INVALID_ADDRESS = 0x0020,
- ALREADY_IDENTIFIED = 0x0030, UNKNOWN_DAEMON = 0x0031
- };
-
- private:
- std::string where;
-
- ErrorCode errorCode;
- long subCode;
- long subSubCode;
-
- public:
- Exception(const std::string &where0, ErrorCode errorCode0, long subCode0 = 0, long subSubCode0 = 0)
- : where(where0), errorCode(errorCode0), subCode(subCode0), subSubCode(subSubCode0) {}
- Exception(ErrorCode errorCode0, long subCode0 = 0, long subSubCode0 = 0) : errorCode(errorCode0), subCode(subCode0), subSubCode(subSubCode0) {}
- virtual ~Exception() {}
-
- const std::string& getWhere() const {return where;}
- ErrorCode getErrorCode() const {return errorCode;}
- long getSubCode() const {return subCode;}
- long getSubSubCode() const {return subSubCode;}
-
- std::string strerror() const;
-};
-
-}
-}
-
-#endif /* MAD_COMMON_EXCEPTION_H_ */
diff --git a/src/Common/LogManager.cpp b/src/Common/LogManager.cpp
index 22c688f..5741d38 100644
--- a/src/Common/LogManager.cpp
+++ b/src/Common/LogManager.cpp
@@ -19,7 +19,6 @@
#include "LogManager.h"
#include "ConfigEntry.h"
-#include "ThreadManager.h"
#include <iostream>
diff --git a/src/Common/LogManager.h b/src/Common/LogManager.h
index 34a4689..1e10e0b 100644
--- a/src/Common/LogManager.h
+++ b/src/Common/LogManager.h
@@ -33,13 +33,16 @@
#include "glthread/cond.h"
namespace Mad {
-namespace Common {
+namespace Net {
class ThreadManager;
+}
+
+namespace Common {
class LogManager : public Configurable {
private:
- friend class ThreadManager;
+ friend class Net::ThreadManager;
typedef LoggerBase::MessageCategory MessageCategory;
typedef LoggerBase::MessageLevel MessageLevel;
diff --git a/src/Common/Makefile.am b/src/Common/Makefile.am
index 60184d4..e50461a 100644
--- a/src/Common/Makefile.am
+++ b/src/Common/Makefile.am
@@ -2,14 +2,14 @@ SUBDIRS = Requests RequestHandlers
noinst_LTLIBRARIES = libcommon.la
libcommon_la_SOURCES = ActionManager.cpp ClientConnection.cpp ConfigEntry.cpp ConfigManager.cpp \
- Connection.cpp Exception.cpp Initializable.cpp Logger.cpp LogManager.cpp \
+ Connection.cpp Initializable.cpp Logger.cpp LogManager.cpp \
ModuleManager.cpp Request.cpp RequestManager.cpp SystemManager.cpp \
- ThreadManager.cpp Tokenizer.cpp XmlPacket.cpp
+ Tokenizer.cpp XmlPacket.cpp
libcommon_la_LIBADD = Requests/librequests.la RequestHandlers/librequesthandlers.la ../../lib/libgnu.la
libcommon_la_LDFLAGS = $(LTLIBMULTITHREAD) $(LTLIBTHREAD)
noinst_HEADERS = ActionManager.h ClientConnection.h ConfigEntry.h ConfigManager.h \
- Configurable.h Connection.h Exception.h HostInfo.h Initializable.h Logger.h \
+ Configurable.h Connection.h HostInfo.h Initializable.h Logger.h \
LoggerBase.h LogManager.h ModuleManager.h RemoteLogger.h Request.h \
RequestHandler.h RequestManager.h SystemBackend.h SystemManager.h \
- ThreadManager.h Tokenizer.h UserInfo.h XmlPacket.h
+ Tokenizer.h UserInfo.h XmlPacket.h
diff --git a/src/Common/Makefile.in b/src/Common/Makefile.in
index 541090d..915c3bb 100644
--- a/src/Common/Makefile.in
+++ b/src/Common/Makefile.in
@@ -62,10 +62,9 @@ LTLIBRARIES = $(noinst_LTLIBRARIES)
libcommon_la_DEPENDENCIES = Requests/librequests.la \
RequestHandlers/librequesthandlers.la ../../lib/libgnu.la
am_libcommon_la_OBJECTS = ActionManager.lo ClientConnection.lo \
- ConfigEntry.lo ConfigManager.lo Connection.lo Exception.lo \
- Initializable.lo Logger.lo LogManager.lo ModuleManager.lo \
- Request.lo RequestManager.lo SystemManager.lo ThreadManager.lo \
- Tokenizer.lo XmlPacket.lo
+ ConfigEntry.lo ConfigManager.lo Connection.lo Initializable.lo \
+ Logger.lo LogManager.lo ModuleManager.lo Request.lo \
+ RequestManager.lo SystemManager.lo Tokenizer.lo XmlPacket.lo
libcommon_la_OBJECTS = $(am_libcommon_la_OBJECTS)
libcommon_la_LINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=link $(CXXLD) $(AM_CXXFLAGS) \
@@ -284,17 +283,17 @@ top_srcdir = @top_srcdir@
SUBDIRS = Requests RequestHandlers
noinst_LTLIBRARIES = libcommon.la
libcommon_la_SOURCES = ActionManager.cpp ClientConnection.cpp ConfigEntry.cpp ConfigManager.cpp \
- Connection.cpp Exception.cpp Initializable.cpp Logger.cpp LogManager.cpp \
+ Connection.cpp Initializable.cpp Logger.cpp LogManager.cpp \
ModuleManager.cpp Request.cpp RequestManager.cpp SystemManager.cpp \
- ThreadManager.cpp Tokenizer.cpp XmlPacket.cpp
+ Tokenizer.cpp XmlPacket.cpp
libcommon_la_LIBADD = Requests/librequests.la RequestHandlers/librequesthandlers.la ../../lib/libgnu.la
libcommon_la_LDFLAGS = $(LTLIBMULTITHREAD) $(LTLIBTHREAD)
noinst_HEADERS = ActionManager.h ClientConnection.h ConfigEntry.h ConfigManager.h \
- Configurable.h Connection.h Exception.h HostInfo.h Initializable.h Logger.h \
+ Configurable.h Connection.h HostInfo.h Initializable.h Logger.h \
LoggerBase.h LogManager.h ModuleManager.h RemoteLogger.h Request.h \
RequestHandler.h RequestManager.h SystemBackend.h SystemManager.h \
- ThreadManager.h Tokenizer.h UserInfo.h XmlPacket.h
+ Tokenizer.h UserInfo.h XmlPacket.h
all: all-recursive
@@ -352,7 +351,6 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ConfigEntry.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ConfigManager.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Connection.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Exception.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Initializable.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/LogManager.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Logger.Plo@am__quote@
@@ -360,7 +358,6 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Request.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/RequestManager.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/SystemManager.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ThreadManager.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Tokenizer.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/XmlPacket.Plo@am__quote@
diff --git a/src/Common/Request.cpp b/src/Common/Request.cpp
index bc37708..5f4c201 100644
--- a/src/Common/Request.cpp
+++ b/src/Common/Request.cpp
@@ -24,11 +24,11 @@ namespace Common {
void Request::handlePacket(const XmlPacket &packet) {
if(packet.getType() == "Error") {
- finishWithError(Common::Exception(packet["Where"], packet["ErrorCode"], packet["SubCode"], packet["SubSubCode"]));
+ finishWithError(Net::Exception(packet["Where"], packet["ErrorCode"], packet["SubCode"], packet["SubSubCode"]));
return;
}
else if(packet.getType() != "OK") {
- finishWithError(Exception(Exception::UNEXPECTED_PACKET));
+ finishWithError(Net::Exception(Net::Exception::UNEXPECTED_PACKET));
return; // TODO Logging
}
diff --git a/src/Common/Request.h b/src/Common/Request.h
index 7048a4e..7ab2816 100644
--- a/src/Common/Request.h
+++ b/src/Common/Request.h
@@ -21,7 +21,7 @@
#define MAD_COMMON_XMLREQUEST_H_
#include "RequestHandler.h"
-#include "Exception.h"
+#include <Net/Exception.h>
#include <memory>
#include <sigc++/adaptors/hide.h>
@@ -36,27 +36,27 @@ class Request : public RequestHandler {
sigc::signal<void,const Request&> finished;
std::auto_ptr<XmlPacket> res;
- Exception exp;
+ Net::Exception exp;
public:
typedef sigc::slot<void,const Request&> slot_type;
protected:
Request(Connection *connection, uint16_t requestId, slot_type slot)
- : RequestHandler(connection, requestId), exp(Exception::NOT_FINISHED) {
+ : RequestHandler(connection, requestId), exp(Net::Exception::NOT_FINISHED) {
finished.connect(slot);
finished.connect(sigc::hide(signalFinished().make_slot()));
}
void finish(std::auto_ptr<XmlPacket> result) {res = result; finished(*this);}
void finish(const XmlPacket& result) {res.reset(new XmlPacket(result)); finished(*this);}
- void finishWithError(const Exception &e) {exp = e; finished(*this);}
+ void finishWithError(const Net::Exception &e) {exp = e; finished(*this);}
virtual void sendRequest() = 0;
virtual void handlePacket(const XmlPacket &packet);
public:
- const XmlPacket& getResult() const throw(Exception) {
+ const XmlPacket& getResult() const throw(Net::Exception) {
if(res.get())
return *res;
diff --git a/src/Common/RequestHandler.h b/src/Common/RequestHandler.h
index a0922a7..e3ac19f 100644
--- a/src/Common/RequestHandler.h
+++ b/src/Common/RequestHandler.h
@@ -56,8 +56,8 @@ class RequestHandler {
return requestId;
}
- bool sendPacket(const XmlPacket &packet) {
- return connection->sendPacket(packet, requestId);
+ void sendPacket(const XmlPacket &packet) {
+ connection->sendPacket(packet, requestId);
}
virtual void handlePacket(const XmlPacket &packet) = 0;
diff --git a/src/Common/RequestHandlers/DisconnectRequestHandler.cpp b/src/Common/RequestHandlers/DisconnectRequestHandler.cpp
index 9204f43..fa2ad88 100644
--- a/src/Common/RequestHandlers/DisconnectRequestHandler.cpp
+++ b/src/Common/RequestHandlers/DisconnectRequestHandler.cpp
@@ -18,7 +18,7 @@
*/
#include "DisconnectRequestHandler.h"
-#include "../Exception.h"
+#include <Net/Exception.h>
#include "../Logger.h"
namespace Mad {
@@ -31,7 +31,7 @@ void DisconnectRequestHandler::handlePacket(const XmlPacket &packet) {
XmlPacket ret;
ret.setType("Error");
- ret.add("ErrorCode", Exception::UNEXPECTED_PACKET);
+ ret.add("ErrorCode", Net::Exception::UNEXPECTED_PACKET);
sendPacket(ret);
diff --git a/src/Common/RequestHandlers/FSInfoRequestHandler.cpp b/src/Common/RequestHandlers/FSInfoRequestHandler.cpp
index 7421ad2..fc98730 100644
--- a/src/Common/RequestHandlers/FSInfoRequestHandler.cpp
+++ b/src/Common/RequestHandlers/FSInfoRequestHandler.cpp
@@ -18,7 +18,7 @@
*/
#include "FSInfoRequestHandler.h"
-#include "../Exception.h"
+#include <Net/Exception.h>
#include "../Logger.h"
namespace Mad {
@@ -31,7 +31,7 @@ void FSInfoRequestHandler::handlePacket(const XmlPacket &packet) {
XmlPacket ret;
ret.setType("Error");
- ret.add("ErrorCode", Exception::UNEXPECTED_PACKET);
+ ret.add("ErrorCode", Net::Exception::UNEXPECTED_PACKET);
sendPacket(ret);
@@ -44,7 +44,7 @@ void FSInfoRequestHandler::handlePacket(const XmlPacket &packet) {
if(!SystemManager::get()->getFSInfo(sigc::mem_fun(this, &FSInfoRequestHandler::fsInfoHandler))) {
XmlPacket ret;
ret.setType("Error");
- ret.add("ErrorCode", Exception::NOT_IMPLEMENTED);
+ ret.add("ErrorCode", Net::Exception::NOT_IMPLEMENTED);
sendPacket(ret);
diff --git a/src/Common/RequestHandlers/StatusRequestHandler.cpp b/src/Common/RequestHandlers/StatusRequestHandler.cpp
index 1464f71..0cfe025 100644
--- a/src/Common/RequestHandlers/StatusRequestHandler.cpp
+++ b/src/Common/RequestHandlers/StatusRequestHandler.cpp
@@ -18,7 +18,7 @@
*/
#include "StatusRequestHandler.h"
-#include "../Exception.h"
+#include <Net/Exception.h>
#include "../SystemBackend.h"
#include "../Logger.h"
@@ -32,7 +32,7 @@ void StatusRequestHandler::handlePacket(const XmlPacket &packet) {
XmlPacket ret;
ret.setType("Error");
- ret.add("ErrorCode", Exception::UNEXPECTED_PACKET);
+ ret.add("ErrorCode", Net::Exception::UNEXPECTED_PACKET);
sendPacket(ret);
diff --git a/src/Common/RequestManager.cpp b/src/Common/RequestManager.cpp
index 1edf778..08be0a9 100644
--- a/src/Common/RequestManager.cpp
+++ b/src/Common/RequestManager.cpp
@@ -96,7 +96,7 @@ void RequestManager::receiveHandler(Connection *connection, const XmlPacket &pac
XmlPacket ret;
ret.setType("Error");
- ret.add("ErrorCode", Exception::UNEXPECTED_PACKET);
+ ret.add("ErrorCode", Net::Exception::UNEXPECTED_PACKET);
connection->sendPacket(ret, requestId);
}
diff --git a/src/Common/Requests/DisconnectRequest.cpp b/src/Common/Requests/DisconnectRequest.cpp
index 248f8b1..3fac25b 100644
--- a/src/Common/Requests/DisconnectRequest.cpp
+++ b/src/Common/Requests/DisconnectRequest.cpp
@@ -32,11 +32,11 @@ void DisconnectRequest::sendRequest() {
void DisconnectRequest::handlePacket(const XmlPacket &packet) {
if(packet.getType() == "Error") {
- finishWithError(Common::Exception(packet["Where"], packet["ErrorCode"], packet["SubCode"], packet["SubSubCode"]));
+ finishWithError(Net::Exception(packet["Where"], packet["ErrorCode"], packet["SubCode"], packet["SubSubCode"]));
return;
}
else if(packet.getType() != "OK") {
- finishWithError(Exception(Exception::UNEXPECTED_PACKET));
+ finishWithError(Net::Exception(Net::Exception::UNEXPECTED_PACKET));
return; // TODO Logging
}
diff --git a/src/Common/Requests/GSSAPIAuthRequest.cpp b/src/Common/Requests/GSSAPIAuthRequest.cpp
index f10bf9b..ffc7939 100644
--- a/src/Common/Requests/GSSAPIAuthRequest.cpp
+++ b/src/Common/Requests/GSSAPIAuthRequest.cpp
@@ -68,17 +68,14 @@ void GSSAPIAuthRequest::sendRequest() {
ret.setType("AuthGSSAPI");
ret.addBinary("authToken", buffer.value, buffer.length);
- if(!sendPacket(ret)) {
- gss_release_buffer(&minStat, &buffer);
- return;
- }
+ sendPacket(ret);
gss_release_buffer(&minStat, &buffer);
}
void GSSAPIAuthRequest::handlePacket(const XmlPacket &packet) {
if(packet.getType() != "AuthGSSAPI") {
- finishWithError(Exception(Exception::UNEXPECTED_PACKET));
+ finishWithError(Net::Exception(Net::Exception::UNEXPECTED_PACKET));
return; // TODO Logging
}
@@ -112,10 +109,7 @@ void GSSAPIAuthRequest::handlePacket(const XmlPacket &packet) {
ret.setType("AuthGSSAPI");
ret.addBinary("authToken", sendBuffer.value, sendBuffer.length);
- if(!sendPacket(ret)) {
- gss_release_buffer(&minStat, &sendBuffer);
- return;
- }
+ sendPacket(ret);
gss_release_buffer(&minStat, &sendBuffer);
}
@@ -153,10 +147,7 @@ void GSSAPIAuthRequest::handlePacket(const XmlPacket &packet) {
ret.setType("AuthGSSAPI");
ret.addBinary("authToken", sendBuffer.value, sendBuffer.length);
- if(!sendPacket(ret)) {
- gss_release_buffer(&minStat, &sendBuffer);
- return;
- }
+ sendPacket(ret);
gss_release_buffer(&minStat, &sendBuffer);
diff --git a/src/Common/ThreadManager.cpp b/src/Common/ThreadManager.cpp
deleted file mode 100644
index c0f4d74..0000000
--- a/src/Common/ThreadManager.cpp
+++ /dev/null
@@ -1,153 +0,0 @@
-/*
- * ThreadManager.cpp
- *
- * 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/>.
- */
-
-#include "ThreadManager.h"
-
-#include <sigc++/bind.h>
-
-namespace Mad {
-namespace Common {
-
-ThreadManager ThreadManager::threadManager;
-
-
-void ThreadManager::workerFunc() {
- while(true) {
- gl_lock_lock(runLock);
-
- if(!running || !isThisWorkerThread()) {
- gl_lock_unlock(runLock);
- return;
- }
-
- gl_lock_unlock(runLock);
-
- gl_lock_lock(workLock);
- while(work.empty()) {
- gl_cond_wait(workCond, workLock);
-
- if(!running) {
- gl_lock_unlock(workLock);
- return;
- }
- }
-
- sigc::slot<void> nextWork = work.front();
- work.pop();
-
- gl_lock_unlock(workLock);
-
- nextWork();
- }
-
- // And let the new worker thread join us...
- pushWork(sigc::bind(sigc::mem_fun(this, &ThreadManager::threadFinished), (gl_thread_t)gl_thread_self()));
-}
-
-void ThreadManager::detach() {
- if(!isThisMainThread()) {
- Logger::log(Logger::CRITICAL, "Tried to detach main thread! This is just WRONG!");
- return;
- }
-
- gl_lock_lock(runLock);
- bool isRunning = running;
- gl_lock_unlock(runLock);
- if(!isRunning) // There's no point in creating a new worker thread when we aren't running anymore
- return;
-
- gl_lock_lock(threadLock);
-
- if(workerThread == (gl_thread_t)gl_thread_self()) {// Already detached?
- threads.insert(workerThread);
- workerThread = gl_thread_create(&ThreadManager::workerStart, 0);
- }
-
- gl_lock_unlock(threadLock);
-}
-
-void ThreadManager::pushWork(const sigc::slot<void> &newWork) {
- gl_lock_lock(workLock);
-
- work.push(newWork);
-
- gl_cond_signal(workCond);
- gl_lock_unlock(workLock);
-}
-
-
-void ThreadManager::doInit() {
- gl_lock_init(threadLock);
- gl_lock_init(runLock);
- gl_lock_init(workLock);
- gl_cond_init(workCond);
-
- running = true;
-
- gl_lock_lock(threadLock);
-
- mainThread = (gl_thread_t)gl_thread_self();
- workerThread = gl_thread_create(&ThreadManager::workerStart, 0);
- loggerThread = gl_thread_create(&ThreadManager::loggerStart, 0);
-
- gl_lock_unlock(threadLock);
-}
-
-void ThreadManager::doDeinit() {
- if(!isThisMainThread()) {
- // TODO Critical error!!!
- return;
- }
-
- gl_lock_lock(runLock);
- gl_lock_lock(workLock);
-
- running = false;
- gl_cond_signal(workCond);
-
- gl_lock_unlock(workLock);
- gl_lock_unlock(runLock);
-
- // We don't have to lock threadLock as detach() won't change workerThread when running is false
- gl_thread_join(workerThread, 0);
-
- // Now wait for all detached threads
- gl_lock_lock(threadLock);
- while(!threads.empty()) {
- gl_thread_t thread = *threads.begin();
- gl_lock_unlock(threadLock);
-
- gl_thread_join(thread, 0);
-
- gl_lock_lock(threadLock);
- threads.erase(thread);
- }
- gl_lock_unlock(threadLock);
-
- LogManager::get()->stopLoggerThread();
- gl_thread_join(loggerThread, 0);
-
- gl_cond_destroy(workCond);
- gl_lock_destroy(workLock);
- gl_lock_destroy(runLock);
- gl_lock_destroy(threadLock);
-}
-
-}
-}
diff --git a/src/Common/ThreadManager.h b/src/Common/ThreadManager.h
deleted file mode 100644
index 6e8616f..0000000
--- a/src/Common/ThreadManager.h
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * ThreadManager.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_THREADMANAGER_H_
-#define MAD_COMMON_THREADMANAGER_H_
-
-#include <config.h>
-
-#include "Initializable.h"
-#include "LogManager.h"
-
-#include <queue>
-#include <set>
-#include <sigc++/slot.h>
-
-#include "glthread/thread.h"
-#include "glthread/lock.h"
-#include "glthread/cond.h"
-
-namespace Mad {
-namespace Common {
-
-class ThreadManager : public Initializable {
- private:
- gl_thread_t mainThread, workerThread, loggerThread;
- std::set<gl_thread_t> threads;
-
- gl_lock_t threadLock;
-
- gl_lock_t runLock;
- bool running;
-
- gl_lock_t workLock;
- gl_cond_t workCond;
- std::queue<sigc::slot<void> > work;
-
- static ThreadManager threadManager;
-
- ThreadManager() {}
-
- static void* workerStart(void*) {
- threadManager.workerFunc();
- return 0;
- }
-
- static void* loggerStart(void*) {
- LogManager::get()->loggerThread();
- return 0;
- }
-
- void workerFunc();
-
- void threadFinished(gl_thread_t thread) {
- gl_lock_lock(threadLock);
- threads.erase(thread);
- gl_lock_unlock(threadLock);
-
- gl_thread_join(thread, 0);
- }
-
- protected:
- virtual void doInit();
- virtual void doDeinit();
-
- public:
- bool isThisMainThread() {
- return (mainThread == (gl_thread_t)gl_thread_self());
- }
-
- bool isThisWorkerThread() {
- gl_lock_lock(threadLock);
- bool ret = (workerThread == (gl_thread_t)gl_thread_self());
- gl_lock_unlock(threadLock);
- return ret;
- }
-
- void detach();
-
- void pushWork(const sigc::slot<void> &newWork);
-
- static ThreadManager* get() {
- return &threadManager;
- }
-};
-
-}
-}
-
-#endif /* MAD_COMMON_THREADMANAGER_H_ */