batchioman.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #ifndef BATCHIOMAN_H
  2. #define BATCHIOMAN_H
  3. #include "ioman.h"
  4. #include <fstream>
  5. #include <vector>
  6. #include <string>
  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. std::mutex linemutex;
  36. std::condition_variable linecv;
  37. /**
  38. * Format and pretty print json for logfile output
  39. */
  40. std::string printJson(Json::Value root);
  41. /**
  42. * Method prototypes for printing json output
  43. */
  44. /* printing commands go here */
  45. std::string printError(Json::Value root);
  46. std::string printConnect(Json::Value root);
  47. std::string printHelp(Json::Value root);
  48. std::string printStatus(Json::Value root);
  49. std::string printDisconnect(Json::Value root);
  50. std::string printPut(Json::Value root);
  51. std::string printGet(Json::Value root);
  52. std::string printList(Json::Value root);
  53. std::string printVersion(Json::Value root);
  54. std::string printLogin(Json::Value root);
  55. std::string printSignup(Json::Value root);
  56. std::string printPutdata(Json::Value root);
  57. std::string printGetdata(Json::Value root);
  58. std::string printListdata(Json::Value root);
  59. std::string printHead(Json::Value root);
  60. std::string printDeletefile(Json::Value root);
  61. std::string printDeleteme(Json::Value root);
  62. std::string printKeyfile(Json::Value root);
  63. std::string printClosekey(Json::Value root);
  64. public:
  65. /**
  66. * Constructor and destructor
  67. */
  68. BatchIoMan(char *ipcstring);
  69. BatchIoMan(char *ipcstring, bool usessl, string batchpath);
  70. ~BatchIoMan();
  71. bool init();
  72. void run();
  73. protected:
  74. /**
  75. * Specific implementations for printing messages
  76. */
  77. void printMessage(std::string msg, OutMsgType type);
  78. void printWelcomeMessage();
  79. void handleInCmdResponse(CmdMan::CmdRet cmdret);
  80. void handleOutCmdResponse(CmdMan::CmdRet cmdret, std::vector<std::string> &toput);
  81. /**
  82. * Return the specific prompt strings for IoMan prompts
  83. */
  84. std::string getCmdPrompt();
  85. };
  86. #endif