iomanager.hpp 918 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #ifndef IOMANAGER_HPP
  2. #define IOMANAGER_HPP
  3. #include "global.hpp"
  4. #include <string>
  5. #include <boost/asio.hpp>
  6. #include <json/json.h>
  7. #define BLOCKSIZE 8
  8. using boost::asio::ip::tcp;
  9. class IoManager {
  10. protected:
  11. boost::asio::io_service ios;
  12. tcp::socket *tcpsock;
  13. boost::system::error_code errcode;
  14. std::string ipstring;
  15. int port;
  16. std::string jsonerror;
  17. Json::CharReaderBuilder rbuilder;
  18. Json::CharReader* reader;
  19. Json::StreamWriterBuilder wbuilder;
  20. bool sendJson(Json::Value root);
  21. bool receiveJson(boost::asio::streambuf &recvbuf);
  22. bool parseJson(Json::Value *root, boost::asio::streambuf &recvbuf);
  23. public:
  24. // Basic constructor
  25. IoManager(char *ipcstring);
  26. // destructor to clean up all generic stuff
  27. ~IoManager();
  28. // enters loop to handle further interaction based on derived class
  29. virtual void run() = 0;
  30. // tries to establish connection, returns false on error
  31. bool connect();
  32. };
  33. #endif