1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- #ifndef IOMAN_H
- #define IOMAN_H
- #include "cmdman.h"
- #include "fileman.h"
- #include <boost/asio.hpp>
- #include <condition_variable>
- #include <mutex>
- #include <string>
- #include <thread>
- #include <vector>
- using boost::asio::ip::tcp;
- class IoMan {
- /* this is technically private and protected stuff which needs to be public
- * for the readline callback */
- public:
- std::mutex localmutex;
- enum OutMsgType { normal, error, debug };
- virtual void printMessage(std::string msg, OutMsgType type);
- bool runmain;
- std::vector<std::string> localinput;
- std::condition_variable localcv;
- std::mutex mainmutex;
- 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;
- std::mutex inputmutex, networkmutex, responsemutex;
- bool runinput, runnetwork, runresponse;
- std::vector<Json::Value> netinput;
- std::mutex netmutex;
- std::condition_variable netcv;
- /*
- 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;
- std::mutex initmutex;
- std::condition_variable initcv;
- bool startlist;
- protected:
- std::mutex msgmutex;
- 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
|