123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- #ifndef IOMAN_H
- #define IOMAN_H
- #include "cmdman.h"
- #include "fileman.h"
- #include <boost/asio.hpp>
- #include <string>
- #include <thread>
- #include <mutex>
- #include <vector>
- using boost::asio::ip::tcp;
- #define BLOCKSIZE 8
- class IoMan {
- private:
- boost::asio::io_service ios;
- boost::asio::streambuf sendbuf;
- boost::asio::streambuf recvbuf;
- boost::system::error_code errcode;
- tcp::socket *tcpsock;
- std::string ipstring;
- int port;
- bool connected;
- CmdMan cmdman;
- FileMan fileman;
- /*
- 3 threads: handleinput, handlenetwork, handleresponse
- */
- std::thread tinput, tnetwork, tresponse;
- bool runmain, runinput, runnetwork, runresponse;
- std::vector<Json::Value> netinput;
- std::vector<std::string> localinput;
- std::mutex netmutex, localmutex;
-
- /*
- to be put elsewhere
- */
- Json::CharReader* reader;
- Json::StreamWriterBuilder wbuilder;
- string jsonerror;
-
- void networkMain();
- void inputMain();
- void responseMain();
-
- enum Status { off, on, err };
-
- Status versionstatus;
- Status loginstatus;
-
- bool startlist;
- protected:
- virtual void printNormalMessage(std::string msg);
- virtual void printErrorMessage(std::string msg);
- virtual void printDebugMessage(std::string msg);
- virtual void printWelcomeMessage() = 0;
- virtual std::string getCmdPrompt() = 0;
- virtual std::string getUserPrompt() = 0;
- virtual std::string getPassPrompt() = 0;
- public:
- // Basic constructor
- IoMan(char *ipcstring);
- // destructor to clean up all generic stuff
- ~IoMan();
- // enters loop to handle further interaction based on derived class
- void run();
- // setup stuff
- bool init();
- // tries to establish connection, returns error string if applicable
- bool connect();
- // disconnect from server
- void disconnect();
-
- };
- #endif
|