/* * 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 #include #include #include #include namespace Mad { namespace Common { class Connection; } namespace Client { class SystemCommands; class UserCommands; class CommandParser { private: friend class SystemCommands; friend class UserCommands; struct Command { const char* commands[3]; const char* cmdline; const char* desc; const char* longdesc; boost::function2, Common::Connection*> function; }; static const Command commands[]; static CommandParser commandParser; Common::Connection *connection; bool disconnect; static const Command* findCommand(const std::string& command); static void printUsage(const std::string& command); static std::map parseHostList(const std::vector &args, bool mustBeActive = false); static void helpCommand(const std::vector &args, Common::Connection *connection); static void listHostsCommand(const std::vector &args, Common::Connection *connection); static void exitCommand(const std::vector &args, Common::Connection *connection); CommandParser() : connection(0), disconnect(false) {} public: static CommandParser *get() { return &commandParser; } Common::Connection *getConnection() const { return connection; } void setConnection(Common::Connection *con) { connection = con; } bool parse(const std::string &cmd); void requestDisconnect() { exitCommand(std::vector(), connection); } bool willDisconnect() const { return disconnect; } }; } } #endif /* MAD_CLIENT_COMMANDPARSER_H_ */