#ifndef CMDMAN_H #define CMDMAN_H #include "fileman.h" #include #include #include #include using std::map; using std::string; using std::vector; /** * @class CmdMan * * A class that provides handling of user provided commands as well as * commands as provided by json responses from a server. */ class CmdMan { public: /** * Type of message returned in CmdRet. * notsend - do not send anything to the server * send - send something to the server * error - an error occured, do not send to the server * close - terminate the connection * seton - contextually change state, used for version check and login */ enum rettype { notsend, send, error, close, seton }; /** * Response to user or command input * * string is to be handled depending on type */ struct CmdRet { rettype type; string msg; }; /** * Constructor and destructor */ CmdMan(FileMan &fm); ~CmdMan(); /** * Executes a user provided command with optional arguments */ CmdRet execute(string cmd, vector args); /** * Handles a server provided response json */ CmdRet handle(Json::Value root); /** * Internal json reader */ Json::CharReader *reader; private: /** * internal json writer and error string member */ Json::StreamWriterBuilder wbuilder; string jsonerror; /** * FileMan instance used to file commands */ FileMan &fileman; /** * Maps containing pointers to the appropriate member functions for executing * or handling commands */ map)> execmap; map handlemap; /** * Map containing help strings to show to a user */ map helpmap; /** * State used to internally format received json to allow easy handling using * handlemap */ bool dologin, doversion; /** * Help strings and method prototypes for commands to be used by a user */ /* 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); /** * Method prototypes for commands used internally */ /* internal execute commands */ CmdRet cmdVersion(vector args); CmdRet cmdLogin(vector args); CmdRet cmdPutdata(vector args); CmdRet cmdGetdata(vector args); CmdRet cmdListdata(vector args); /** * Method prototypes for handling json responses */ /* handle commands go here */ CmdRet handleStatus(Json::Value); CmdRet handleClose(Json::Value); CmdRet handlePut(Json::Value); CmdRet handleGet(Json::Value); CmdRet handleList(Json::Value); CmdRet handlePutdata(Json::Value); CmdRet handleGetdata(Json::Value); CmdRet handleListdata(Json::Value); CmdRet handleVersion(Json::Value); CmdRet handleLogin(Json::Value); }; #endif