cmdman.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #ifndef CMDMAN_H
  2. #define CMDMAN_H
  3. #include "fileman.h"
  4. #include <json/json.h>
  5. #include <string>
  6. #include <vector>
  7. #include <map>
  8. using std::string;
  9. using std::vector;
  10. using std::map;
  11. class CmdMan {
  12. public:
  13. enum rettype { json, error, text };
  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. //~ bool sendJson(Json::Value root);
  25. //~ bool receiveJson(boost::asio::streambuf &recvbuf);
  26. //~ bool parseJson(Json::Value *root, boost::asio::streambuf &recvbuf);
  27. /* internal commands */
  28. CmdRet cmdVersion(string);
  29. CmdRet cmdLogin(string, string);
  30. CmdRet cmdPutdata();
  31. CmdRet cmdGetdata();
  32. private:
  33. Json::CharReader* reader;
  34. Json::StreamWriterBuilder wbuilder;
  35. string jsonerror;
  36. FileMan &fileman;
  37. map<string,CmdRet(CmdMan::*)(vector<string>)> execmap;
  38. map<string,string> helpmap;
  39. map<string,CmdRet(CmdMan::*)(Json::Value)> handlemap;
  40. /* execute command descriptions and methods go here */
  41. const string descHelp = "print available commands";
  42. CmdRet cmdHelp(vector<string> args);
  43. const string descStatus = "request status from server";
  44. CmdRet cmdStatus(vector<string> args);
  45. const string descDisconnect = "disconnect from server";
  46. CmdRet cmdDisconnect(vector<string> args);
  47. const string descPut = "upload file to server and add to queue";
  48. CmdRet cmdPut(vector<string> args);
  49. const string descGet = "retrieve file from server";
  50. CmdRet cmdGet(vector<string> args);
  51. const string descList = "list files available on server";
  52. CmdRet cmdList(vector<string> args);
  53. /* handle commands go here */
  54. CmdRet handleDefault(Json::Value);
  55. CmdRet handlePut(Json::Value);
  56. CmdRet handleGet(Json::Value);
  57. };
  58. #endif