/* * CommandParser.h * * Copyright (C) 2008 Matthias Schiffer * * 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 . */ #ifndef MAD_CLIENT_COMMANDPARSER_H_ #define MAD_CLIENT_COMMANDPARSER_H_ #include #include #include namespace Mad { namespace Common { class RequestManager; } namespace Net { class Connection; namespace Packets { class HostStatusPacket; } } namespace Client { class CommandParser { private: struct Command { const char* commands[3]; const char* cmdline; const char* desc; const char* longdesc; void (CommandParser::*funcPtr) (const std::vector &args); }; static const Command commands[]; sigc::signal finished; Common::RequestManager *requestManager; Net::Connection *connection; unsigned int activeRequests; bool disconnect; bool split(const std::string &str, std::vector &ret); const Command* findCommand(const std::string& command); void printUsage(const std::string& command); void helpCommand(const std::vector &args); void statusCommand(const std::vector&); void exitCommand(const std::vector&); void coreStatusRequestFinished(const Net::Packets::HostStatusPacket &packet); void requestFinished() { activeRequests--; finished(); } public: CommandParser(Common::RequestManager *requestManager0, Net::Connection *connection0) : requestManager(requestManager0), connection(connection0), activeRequests(0), disconnect(false) {} bool requestsActive() {return (activeRequests > 0);} bool willDisconnect() {return disconnect;} bool parse(const std::string &cmd); void requestDisconnect() { exitCommand(std::vector()); } sigc::signal signalFinished() const {return finished;} }; } } #endif /* MAD_CLIENT_COMMANDPARSER_H_ */