iomanager.hpp 931 B

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