|
@@ -13,82 +13,141 @@
|
|
|
|
|
|
using boost::asio::ip::tcp;
|
|
|
|
|
|
+/**
|
|
|
+ * @class IoMan
|
|
|
+ *
|
|
|
+ * Input/Output manager
|
|
|
+ *
|
|
|
+ * Provides the glue logic for getting user and network input
|
|
|
+ * as well as providing user and network output
|
|
|
+ */
|
|
|
class IoMan {
|
|
|
/* this is technically private and protected stuff which needs to be public
|
|
|
* for the readline callback */
|
|
|
public:
|
|
|
- std::mutex localmutex;
|
|
|
+ /**
|
|
|
+ * Type of message to be output
|
|
|
+ */
|
|
|
enum OutMsgType { normal, error, debug };
|
|
|
+ /**
|
|
|
+ * Output msg to the user, treating it as type
|
|
|
+ */
|
|
|
virtual void printMessage(std::string msg, OutMsgType type);
|
|
|
+ /**
|
|
|
+ * Flag wether to keep the main thread running
|
|
|
+ * Matching mutex to provide syncthonizes access
|
|
|
+ */
|
|
|
bool runmain;
|
|
|
+ std::mutex mainmutex;
|
|
|
+ /**
|
|
|
+ * Vector to hold input generated/fetched locally (e.g. from the user)
|
|
|
+ * Matching condition variable to wake up waiting threads
|
|
|
+ * Matching mutex to provide synchronized access
|
|
|
+ */
|
|
|
+ std::mutex localmutex;
|
|
|
std::vector<std::string> localinput;
|
|
|
std::condition_variable localcv;
|
|
|
- std::mutex mainmutex;
|
|
|
|
|
|
private:
|
|
|
+ /**
|
|
|
+ * Internal state to provide class-wide asio networking functionality
|
|
|
+ */
|
|
|
boost::asio::io_service ios;
|
|
|
- boost::asio::streambuf sendbuf;
|
|
|
boost::asio::streambuf recvbuf;
|
|
|
boost::system::error_code errcode;
|
|
|
tcp::socket *tcpsock;
|
|
|
+ /**
|
|
|
+ * The IP and port to connect to
|
|
|
+ * Flag telling wether one is connected
|
|
|
+ */
|
|
|
std::string ipstring;
|
|
|
int port;
|
|
|
bool connected;
|
|
|
+ /**
|
|
|
+ * Instances of CmdMan and FileMan to process user input and handle File I/O
|
|
|
+ */
|
|
|
CmdMan cmdman;
|
|
|
FileMan fileman;
|
|
|
|
|
|
- /*
|
|
|
- 3 threads: handleinput, handlenetwork, handleresponse
|
|
|
- */
|
|
|
+ /**
|
|
|
+ * Thread handles for processing local and network input as well as generating
|
|
|
+ * responses to both Matching mutexes for the flags wether the threads should
|
|
|
+ * keep running Function prototypes for the main thread functions
|
|
|
+ */
|
|
|
std::thread tinput, tnetwork, tresponse;
|
|
|
std::mutex inputmutex, networkmutex, responsemutex;
|
|
|
bool runinput, runnetwork, runresponse;
|
|
|
+ void networkMain();
|
|
|
+ void inputMain();
|
|
|
+ void responseMain();
|
|
|
|
|
|
+ /**
|
|
|
+ * Vector to hold preprocessed input from the network
|
|
|
+ * Matching condition variable to wake up waiting threads
|
|
|
+ * Matching mutex to provide synchronized access
|
|
|
+ */
|
|
|
std::vector<Json::Value> netinput;
|
|
|
std::mutex netmutex;
|
|
|
std::condition_variable netcv;
|
|
|
|
|
|
- /*
|
|
|
- to be put elsewhere
|
|
|
- */
|
|
|
+ /**
|
|
|
+ * Class-wide json functionality
|
|
|
+ */
|
|
|
Json::CharReader *reader;
|
|
|
Json::StreamWriterBuilder wbuilder;
|
|
|
string jsonerror;
|
|
|
|
|
|
- void networkMain();
|
|
|
- void inputMain();
|
|
|
- void responseMain();
|
|
|
-
|
|
|
+ /**
|
|
|
+ * Enum for internal login and version state
|
|
|
+ * Variables for keeping said state
|
|
|
+ * Matching mutex and condition variable
|
|
|
+ */
|
|
|
enum Status { off, on, err };
|
|
|
-
|
|
|
Status versionstatus;
|
|
|
Status loginstatus;
|
|
|
std::mutex initmutex;
|
|
|
std::condition_variable initcv;
|
|
|
|
|
|
- bool startlist;
|
|
|
-
|
|
|
protected:
|
|
|
+ /**
|
|
|
+ * mutex
|
|
|
+ */
|
|
|
std::mutex msgmutex;
|
|
|
|
|
|
+ /**
|
|
|
+ * Prompt messages for readline prompt
|
|
|
+ */
|
|
|
virtual void printWelcomeMessage() = 0;
|
|
|
virtual std::string getCmdPrompt() = 0;
|
|
|
virtual std::string getUserPrompt() = 0;
|
|
|
virtual std::string getPassPrompt() = 0;
|
|
|
|
|
|
public:
|
|
|
- // Basic constructor
|
|
|
+ /**
|
|
|
+ * Constructor and destructor
|
|
|
+ */
|
|
|
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
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Establish connection to server and perform vesion check
|
|
|
+ * Return true if successful, false otherwise
|
|
|
+ */
|
|
|
bool init();
|
|
|
|
|
|
- // tries to establish connection, returns error string if applicable
|
|
|
+ /**
|
|
|
+ * Main loop, call init first
|
|
|
+ */
|
|
|
+ void run();
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Establish connection to server
|
|
|
+ * Return true if successful, false otherwise
|
|
|
+ */
|
|
|
bool connect();
|
|
|
- // disconnect from server
|
|
|
+ /**
|
|
|
+ * Disconnect from a connected server
|
|
|
+ */
|
|
|
void disconnect();
|
|
|
};
|
|
|
|