batchioman.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 printVersion(Json::Value root);
  57. std::string printLogin(Json::Value root);
  58. std::string printSignup(Json::Value root);
  59. std::string printPutdata(Json::Value root);
  60. std::string printGetdata(Json::Value root);
  61. std::string printListdata(Json::Value root);
  62. std::string printHead(Json::Value root);
  63. std::string printDeletefile(Json::Value root);
  64. std::string printQueue(Json::Value root);
  65. std::string printDequeue(Json::Value root);
  66. std::string printDeleteme(Json::Value root);
  67. std::string printKeyfile(Json::Value root);
  68. std::string printClosekey(Json::Value root);
  69. std::string printNotifications(Json::Value root);
  70. public:
  71. /**
  72. * Constructor and destructor
  73. */
  74. BatchIoMan(bool usessl, bool beverbose, string batchpath);
  75. ~BatchIoMan();
  76. bool init();
  77. void run();
  78. protected:
  79. /**
  80. * Specific implementations for printing messages
  81. */
  82. void printMessage(std::string msg, OutMsgType type);
  83. void printWelcomeMessage();
  84. void handleInCmdResponse(CmdMan::CmdRet cmdret);
  85. void handleOutCmdResponse(CmdMan::CmdRet cmdret, std::vector<std::string> &toput);
  86. /**
  87. * Return the specific prompt strings for IoMan prompts
  88. */
  89. std::string getCmdPrompt();
  90. };
  91. #endif