batchioman.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #ifndef BATCHIOMAN_H
  2. #define BATCHIOMAN_H
  3. #include "ioman.h"
  4. #include <fstream>
  5. #include <string>
  6. #include <vector>
  7. /**
  8. * @class BatchIoMan
  9. *
  10. * Provides specific implementations of IoMan outputs and prompts
  11. * for unattended sessions
  12. */
  13. class BatchIoMan : public IoMan {
  14. private:
  15. /**
  16. * Map containing pointers to the appropriate member functions for printing
  17. * formatted json output
  18. */
  19. map<string, std::string (BatchIoMan::*)(Json::Value)> printmap;
  20. /**
  21. * Class-wide json functionality
  22. */
  23. Json::CharReader *reader;
  24. Json::StreamWriterBuilder wbuilder;
  25. string jsonerror;
  26. std::ofstream normalout;
  27. std::ofstream errorout;
  28. std::ofstream debugout;
  29. std::ifstream batchin;
  30. /**
  31. * Mutex for synchronized message output
  32. */
  33. std::recursive_mutex msgmutex;
  34. bool getnextline;
  35. bool verbose;
  36. string filepath;
  37. std::mutex linemutex;
  38. std::condition_variable linecv;
  39. /**
  40. * Format and pretty print json for logfile output
  41. */
  42. std::string printJson(Json::Value root);
  43. /**
  44. * Method prototypes for printing json output
  45. */
  46. /* printing commands go here */
  47. std::string printError(Json::Value root);
  48. std::string printConnect(Json::Value root);
  49. std::string printHelp(Json::Value root);
  50. std::string printStatus(Json::Value root);
  51. std::string printExtendedstatus(Json::Value root);
  52. std::string printDisconnect(Json::Value root);
  53. std::string printPut(Json::Value root);
  54. std::string printGet(Json::Value root);
  55. std::string printList(Json::Value root);
  56. std::string printExtendedlist(Json::Value root);
  57. std::string printVersion(Json::Value root);
  58. std::string printLogin(Json::Value root);
  59. std::string printSignup(Json::Value root);
  60. std::string printPutdata(Json::Value root);
  61. std::string printGetdata(Json::Value root);
  62. std::string printListdata(Json::Value root);
  63. std::string printHead(Json::Value root);
  64. std::string printDeletefile(Json::Value root);
  65. std::string printQueue(Json::Value root);
  66. std::string printDequeue(Json::Value root);
  67. std::string printDeleteme(Json::Value root);
  68. std::string printKeyfile(Json::Value root);
  69. std::string printClosekey(Json::Value root);
  70. std::string printNotifications(Json::Value root);
  71. public:
  72. /**
  73. * Constructor and destructor
  74. */
  75. BatchIoMan(bool usessl, bool beverbose, string batchpath);
  76. ~BatchIoMan();
  77. bool init();
  78. void run();
  79. protected:
  80. /**
  81. * Specific implementations for printing messages
  82. */
  83. void printMessage(std::string msg, OutMsgType type);
  84. void printWelcomeMessage();
  85. void handleInCmdResponse(CmdMan::CmdRet cmdret);
  86. void handleOutCmdResponse(CmdMan::CmdRet cmdret, std::vector<std::string> &toput);
  87. /**
  88. * Return the specific prompt strings for IoMan prompts
  89. */
  90. std::string getCmdPrompt();
  91. };
  92. #endif