cmdman.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #ifndef CMDMAN_H
  2. #define CMDMAN_H
  3. #include "fileman.h"
  4. #include <json/json.h>
  5. #include <map>
  6. #include <string>
  7. #include <vector>
  8. using std::map;
  9. using std::string;
  10. using std::vector;
  11. class CmdMan {
  12. public:
  13. enum rettype { notsend, send, error, startlist, stoplist, close, seton };
  14. struct CmdRet {
  15. rettype type;
  16. string msg;
  17. };
  18. CmdMan(FileMan &fm);
  19. ~CmdMan();
  20. // execute cmd with optional argument args, returns answer string
  21. // if cmd unknown, returns error string
  22. CmdRet execute(string cmd, vector<string> args);
  23. CmdRet handle(Json::Value root);
  24. Json::CharReader *reader;
  25. private:
  26. Json::StreamWriterBuilder wbuilder;
  27. string jsonerror;
  28. FileMan &fileman;
  29. map<string, CmdRet (CmdMan::*)(vector<string>)> execmap;
  30. map<string, string> helpmap;
  31. map<string, CmdRet (CmdMan::*)(Json::Value)> handlemap;
  32. bool dologin, doversion;
  33. /* execute command descriptions and methods go here */
  34. const string descHelp = "print available commands";
  35. CmdRet cmdHelp(vector<string> args);
  36. const string descStatus = "request status from server";
  37. CmdRet cmdStatus(vector<string> args);
  38. const string descDisconnect = "disconnect from server";
  39. CmdRet cmdDisconnect(vector<string> args);
  40. const string descPut = "upload file to server and add to queue";
  41. CmdRet cmdPut(vector<string> args);
  42. const string descGet = "retrieve file from server";
  43. CmdRet cmdGet(vector<string> args);
  44. const string descList = "list files available on server";
  45. CmdRet cmdList(vector<string> args);
  46. /* internal execute commands */
  47. CmdRet cmdVersion(vector<string> args);
  48. CmdRet cmdLogin(vector<string> args);
  49. CmdRet cmdPutdata(vector<string> args);
  50. CmdRet cmdGetdata(vector<string> args);
  51. CmdRet cmdListdata(vector<string> args);
  52. /* handle commands go here */
  53. CmdRet handleStatus(Json::Value);
  54. CmdRet handleClose(Json::Value);
  55. CmdRet handlePut(Json::Value);
  56. CmdRet handleGet(Json::Value);
  57. CmdRet handleList(Json::Value);
  58. CmdRet handlePutdata(Json::Value);
  59. CmdRet handleGetdata(Json::Value);
  60. CmdRet handleListdata(Json::Value);
  61. CmdRet handleVersion(Json::Value);
  62. CmdRet handleLogin(Json::Value);
  63. };
  64. #endif