#ifndef __APPLICATION__H_ #define __APPLICATION__H_ #include #include #include #include "Command.h" class IAbsServer; class Pad; class ISocket; #define SEND(__sock__,__msg__) {std::ostringstream os; os << __msg__ <<"\n"; (__sock__).write(os.str());} class Application; class Pad; class CommandLog : public std::ostringstream { public: CommandLog() : std::ostringstream(){ error=0; message="success"; } virtual ~CommandLog(){} void set(int err=0, const std::string& msg=""){ error=err; message=msg; } void write(ISocket& sock, const std::string& append=""); int error; std::string message; }; typedef Command::CommandReturn (*CommandCallback)(Application&, Pad&, std::vector&, CommandLog&); class CommandHandler { public: CommandHandler(const std::string& s, CommandCallback c, const std::string& h){ name=s; command=c; help=h; } virtual ~CommandHandler(){} std::string name; std::string help; CommandCallback command; }; class Application { public: Application(); virtual ~Application(); void process_next_command(int=1); void process(); Pad& operator[](int); Pad& operator[](const std::string&); Pad& get_pad(int=-1); Pad& get_pad(const std::string& = ""); void remove_pad(int); void remove_pad(const std::string&); int add_pad(Pad*); int add_pad(const std::string&); bool has_pad(const std::string&); Pad& set_pad(int); Pad& set_pad(const std::string&); void add_command(const std::string&, CommandCallback, const std::string&); void help(CommandLog&); int pad_count() const {return m_pads.size();} bool load_pad_configuration(const std::string&); bool load_pad_definition(const std::string&); int get_id(const std::string&); protected: Command::CommandReturn _call(Command&, ISocket&); void _process_one(); void _auto_load_pad(); std::vector > m_pads; int m_pad_last_id; IAbsServer* m_server; Pad* m_current; int m_current_index; std::vector m_callbacks; }; #endif