#ifndef CMDMAN_H #define CMDMAN_H #include "fileman.h" #include #include #include #include using std::string; using std::vector; using std::map; class CmdMan { public: enum rettype { json, error, text }; struct CmdRet { rettype type; string msg; }; CmdMan(FileMan &fm); ~CmdMan(); // execute cmd with optional argument args, returns answer string // if cmd unknown, returns error string CmdRet execute(string cmd, vector args); CmdRet handle(Json::Value root); //~ bool sendJson(Json::Value root); //~ bool receiveJson(boost::asio::streambuf &recvbuf); //~ bool parseJson(Json::Value *root, boost::asio::streambuf &recvbuf); /* internal commands */ CmdRet cmdVersion(string); CmdRet cmdLogin(string, string); CmdRet cmdPutdata(); CmdRet cmdGetdata(); private: Json::CharReader* reader; Json::StreamWriterBuilder wbuilder; string jsonerror; FileMan &fileman; map)> execmap; map helpmap; map handlemap; /* execute command descriptions and methods go here */ const string descHelp = "print available commands"; CmdRet cmdHelp(vector args); const string descStatus = "request status from server"; CmdRet cmdStatus(vector args); const string descDisconnect = "disconnect from server"; CmdRet cmdDisconnect(vector args); const string descPut = "upload file to server and add to queue"; CmdRet cmdPut(vector args); const string descGet = "retrieve file from server"; CmdRet cmdGet(vector args); const string descList = "list files available on server"; CmdRet cmdList(vector args); /* handle commands go here */ CmdRet handleDefault(Json::Value); CmdRet handlePut(Json::Value); CmdRet handleGet(Json::Value); }; #endif