diff options
Diffstat (limited to 'src/Common')
-rw-r--r-- | src/Common/Request/CoreStatusRequest.h | 82 | ||||
-rw-r--r-- | src/Common/Request/DisconnectRequest.h | 10 | ||||
-rw-r--r-- | src/Common/Request/Makefile.am | 2 | ||||
-rw-r--r-- | src/Common/Request/Makefile.in | 2 | ||||
-rw-r--r-- | src/Common/Util.h | 58 |
5 files changed, 93 insertions, 61 deletions
diff --git a/src/Common/Request/CoreStatusRequest.h b/src/Common/Request/CoreStatusRequest.h new file mode 100644 index 0000000..97f8318 --- /dev/null +++ b/src/Common/Request/CoreStatusRequest.h @@ -0,0 +1,82 @@ +/* + * CoreStatusRequest.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_REQUEST_CORESTATUSREQUEST_H_ +#define MAD_COMMON_REQUEST_CORESTATUSREQUEST_H_ + +#include "Request.h" +#include "../RequestManager.h" +#include <Net/Connection.h> +#include <Net/Packet.h> + +#include <sigc++/signal.h> + +namespace Mad { +namespace Common { +namespace Request { + +class CoreStatusRequest: public Request { + private: + sigc::signal<void> finished; + + CoreStatusRequest() {} + + public: + static bool send(Net::Connection *connection, RequestManager &requestManager, const sigc::slot<void> &callback) { + CoreStatusRequest *request = new CoreStatusRequest(); + + request->finished.connect(callback); + + if(requestManager.sendRequest(connection, request)) + return true; + + delete request; + return false; + } + + virtual bool sendRequest(Net::Connection *connection, unsigned short requestId) { + if(isSent()) + return false; + + if(!connection->send(Net::Packet(Net::Packet::TYPE_CORE_STATUS, requestId))) + return false; + + setSent(); + return true; + } + + virtual bool handlePacket(Net::Connection*, const Net::Packet &packet) { + if(isFinished()) + return false; + + if(packet.getType() != Net::Packet::TYPE_OK) + return false; // TODO Logging + + finished(); + + setFinished(); + return true; + } +}; + +} +} +} + +#endif /* MAD_COMMON_REQUEST_CORESTATUSREQUEST_H_ */ diff --git a/src/Common/Request/DisconnectRequest.h b/src/Common/Request/DisconnectRequest.h index 48256a7..c20a3d0 100644 --- a/src/Common/Request/DisconnectRequest.h +++ b/src/Common/Request/DisconnectRequest.h @@ -25,18 +25,24 @@ #include <Net/Connection.h> #include <Net/Packet.h> +#include <sigc++/signal.h> + namespace Mad { namespace Common { namespace Request { class DisconnectRequest: public Request { private: + sigc::signal<void> finished; + DisconnectRequest() {} public: - static bool send(Net::Connection *connection, RequestManager &requestManager) { + static bool send(Net::Connection *connection, RequestManager &requestManager, const sigc::slot<void> &callback) { DisconnectRequest *request = new DisconnectRequest(); + request->finished.connect(callback); + if(requestManager.sendRequest(connection, request)) return true; @@ -64,6 +70,8 @@ class DisconnectRequest: public Request { connection->disconnect(); + finished(); + setFinished(); return true; } diff --git a/src/Common/Request/Makefile.am b/src/Common/Request/Makefile.am index 64c5078..4c6ffd5 100644 --- a/src/Common/Request/Makefile.am +++ b/src/Common/Request/Makefile.am @@ -1 +1 @@ -noinst_HEADERS = DisconnectRequest.h GSSAPIAuthRequest.h IdentifyRequest.h Request.h +noinst_HEADERS = CoreStatusRequest.h DisconnectRequest.h GSSAPIAuthRequest.h IdentifyRequest.h Request.h diff --git a/src/Common/Request/Makefile.in b/src/Common/Request/Makefile.in index bf7652c..8d53cc0 100644 --- a/src/Common/Request/Makefile.in +++ b/src/Common/Request/Makefile.in @@ -162,7 +162,7 @@ sysconfdir = @sysconfdir@ target_alias = @target_alias@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ -noinst_HEADERS = DisconnectRequest.h GSSAPIAuthRequest.h IdentifyRequest.h Request.h +noinst_HEADERS = CoreStatusRequest.h DisconnectRequest.h GSSAPIAuthRequest.h IdentifyRequest.h Request.h all: all-am .SUFFIXES: diff --git a/src/Common/Util.h b/src/Common/Util.h index 71d7b69..19f87b9 100644 --- a/src/Common/Util.h +++ b/src/Common/Util.h @@ -55,64 +55,6 @@ class Util { return str.substr(beg, end); } - - static std::vector<std::string> split(const std::string &str) { - std::vector<std::string> ret; - std::string temp; - bool quoteSingle = false, quoteDouble = false, escape = false; - - size_t beg = 0; - - for(size_t cur = 0; cur < str.length(); ++cur) { - if(!escape) { - if(str[cur] == ' ' && !quoteSingle && !quoteDouble) { - if(cur == beg && temp.empty()) { - ++beg; - } - else { - temp += str.substr(beg, cur-beg); - ret.push_back(temp); - temp.clear(); - beg = cur+1; - } - - continue; - } - - if(str[cur] == '"' && !quoteSingle) { - temp += str.substr(beg, cur-beg); - beg = cur+1; - - quoteDouble = !quoteDouble; - continue; - } - if(str[cur] == '\'' && !quoteDouble) { - temp += str.substr(beg, cur-beg); - beg = cur+1; - - quoteSingle = !quoteSingle; - continue; - } - - if(str[cur] == '\\') { - escape = true; - continue; - } - } - - if(escape && ((!quoteSingle && !quoteDouble) || (quoteSingle && str[cur] == '\'') || (quoteDouble && (str[cur] == '"' || str[cur] == '\\')))) { - temp += str.substr(beg, cur-beg-1); - beg = cur; - } - - escape = false; - } - - temp += str.substr(beg, std::string::npos); - ret.push_back(temp); - - return ret; - } }; } |