123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- #ifndef CMDMAN_H
- #define CMDMAN_H
- #include "fileman.h"
- #include <json/json.h>
- #include <string>
- #include <vector>
- #include <map>
- using std::string;
- using std::vector;
- using std::map;
- class CmdMan {
- public:
- enum rettype { notsend, send, error, startlist, stoplist, close, seton };
- 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<string> args);
- CmdRet handle(Json::Value root);
-
- Json::CharReader* reader;
-
- private:
-
- Json::StreamWriterBuilder wbuilder;
- string jsonerror;
- FileMan &fileman;
- map<string,CmdRet(CmdMan::*)(vector<string>)> execmap;
- map<string,string> helpmap;
- map<string,CmdRet(CmdMan::*)(Json::Value)> handlemap;
- bool dologin, doversion;
-
- /* execute command descriptions and methods go here */
- const string descHelp = "print available commands";
- CmdRet cmdHelp(vector<string> args);
- const string descStatus = "request status from server";
- CmdRet cmdStatus(vector<string> args);
- const string descDisconnect = "disconnect from server";
- CmdRet cmdDisconnect(vector<string> args);
- const string descPut = "upload file to server and add to queue";
- CmdRet cmdPut(vector<string> args);
- const string descGet = "retrieve file from server";
- CmdRet cmdGet(vector<string> args);
- const string descList = "list files available on server";
- CmdRet cmdList(vector<string> args);
-
- /* internal execute commands */
- CmdRet cmdVersion(vector<string> args);
- CmdRet cmdLogin(vector<string> args);
- CmdRet cmdPutdata(vector<string> args);
- CmdRet cmdGetdata(vector<string> args);
-
- /* handle commands go here */
- CmdRet handleStatus(Json::Value);
- CmdRet handleClose(Json::Value);
- CmdRet handlePut(Json::Value);
- CmdRet handleGet(Json::Value);
- CmdRet handlePutdata(Json::Value);
- CmdRet handleGetdata(Json::Value);
- CmdRet handleList(Json::Value);
- CmdRet handleVersion(Json::Value);
- CmdRet handleLogin(Json::Value);
- };
- #endif
|