#pragma once #include "asio.hpp" #include using tcp = asio::ip::tcp; enum class TCP_REQUESTS { NA = 0, DOWNLOAD_DATA = 1, GET_STATUS = 2, GET_LOG_FILES }; namespace REQUEST { enum class INTENT { NA = 0, DOWNLOAD_DATA = 1, GET_STATUS = 2, INVALID }; INTENT assignInt(const unsigned int value); enum class CODE_RCV { SUCCESS = 0, FAILED, INVALID }; inline CODE_RCV intToRcv(const unsigned int); enum class CODE_SND { CONTINUING, FINISHED, INVALID }; template constexpr auto toUnderlyingType(E e) { return static_cast::type>(e); } } template constexpr auto toUnderlyingType(E e) { return static_cast::type>(e); } class IpTcpClient { private: std::string ip; unsigned int port; std::unique_ptr socket; asio::io_context context; tcp::resolver::results_type endpoints; std::stringstream inputStream; TCP_REQUESTS lastRequest; public: IpTcpClient(std::string targetIP, unsigned int targetPort); IpTcpClient(std::string targetIP, unsigned int targetPort, TCP_REQUESTS requestCode); //getter and setter std::stringstream& getInputStream() { return inputStream; } TCP_REQUESTS getLastRequestCode() const { return lastRequest; } //Client Routine void connect(); //send request code to server void sendRequest(const TCP_REQUESTS& code); //Wait until server responds size_t waitRead(); //Process the received data according to the requested data void processServerResponse(); };