|
@@ -54,13 +54,7 @@ IoMan::~IoMan() {
|
|
delete reader;
|
|
delete reader;
|
|
}
|
|
}
|
|
|
|
|
|
-void IoMan::printNormalMessage(string nouse) {
|
|
+void IoMan::printMessage(string nouse, OutMsgType nouse2) {
|
|
-}
|
|
|
|
-
|
|
|
|
-void IoMan::printErrorMessage(string nouse) {
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-void IoMan::printDebugMessage(string nouse) {
|
|
|
|
}
|
|
}
|
|
|
|
|
|
bool IoMan::connect() {
|
|
bool IoMan::connect() {
|
|
@@ -69,11 +63,11 @@ bool IoMan::connect() {
|
|
ep = new tcp::endpoint(boost::asio::ip::address::from_string(ipstring), 1234);
|
|
ep = new tcp::endpoint(boost::asio::ip::address::from_string(ipstring), 1234);
|
|
|
|
|
|
|
|
|
|
- printDebugMessage("IoMan::connect() connecting to " + ipstring);
|
|
+ printMessage("IoMan::connect() connecting to " + ipstring, debug);
|
|
tcpsock->connect(*ep, errcode);
|
|
tcpsock->connect(*ep, errcode);
|
|
if (errcode) {
|
|
if (errcode) {
|
|
delete ep;
|
|
delete ep;
|
|
- printErrorMessage("IoMan::connect() couldnt connect to " + ipstring + "\n" + errcode.message());
|
|
+ printMessage("IoMan::connect() couldnt connect to " + ipstring + "\n" + errcode.message(), error);
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
connected = true;
|
|
connected = true;
|
|
@@ -83,7 +77,7 @@ bool IoMan::connect() {
|
|
|
|
|
|
|
|
|
|
void IoMan::disconnect() {
|
|
void IoMan::disconnect() {
|
|
- printDebugMessage("IoMan::disconnect()");
|
|
+ printMessage("IoMan::disconnect()", debug);
|
|
tcpsock->close();
|
|
tcpsock->close();
|
|
connected = false;
|
|
connected = false;
|
|
}
|
|
}
|
|
@@ -94,19 +88,19 @@ bool IoMan::init() {
|
|
string work;
|
|
string work;
|
|
Json::Value root;
|
|
Json::Value root;
|
|
|
|
|
|
- printDebugMessage("IoMan::Init() begin");
|
|
+ printMessage("IoMan::Init() begin", debug);
|
|
|
|
|
|
if(!connect()) return false;
|
|
if(!connect()) return false;
|
|
|
|
|
|
- printDebugMessage("IoMan::Init() versioncheck");
|
|
+ printMessage("IoMan::Init() versioncheck", debug);
|
|
|
|
|
|
localmutex.lock();
|
|
localmutex.lock();
|
|
- printDebugMessage(string(__PRETTY_FUNCTION__) + string(" get localmutex"));
|
|
+ printMessage(string(__PRETTY_FUNCTION__) + string(" get localmutex"), debug);
|
|
localinput.push_back("version " + protocolVersion);
|
|
localinput.push_back("version " + protocolVersion);
|
|
localmutex.unlock();
|
|
localmutex.unlock();
|
|
- printDebugMessage(string(__PRETTY_FUNCTION__) + string(" release localmutex"));
|
|
+ printMessage(string(__PRETTY_FUNCTION__) + string(" release localmutex"), debug);
|
|
|
|
|
|
- printDebugMessage("IoMan::Init() begin");
|
|
+ printMessage("IoMan::Init() begin", debug);
|
|
|
|
|
|
runnetwork = true;
|
|
runnetwork = true;
|
|
runinput = true;
|
|
runinput = true;
|
|
@@ -134,7 +128,7 @@ void IoMan::networkMain() {
|
|
Json::Value root;
|
|
Json::Value root;
|
|
unsigned int jsonsize, readsize;
|
|
unsigned int jsonsize, readsize;
|
|
|
|
|
|
- printDebugMessage("IoMan::networkMain() begin");
|
|
+ printMessage("IoMan::networkMain() begin", debug);
|
|
while(runnetwork) {
|
|
while(runnetwork) {
|
|
std::this_thread::yield();
|
|
std::this_thread::yield();
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
|
@@ -151,10 +145,10 @@ void IoMan::networkMain() {
|
|
|
|
|
|
|
|
|
|
readsize = boost::asio::read_until(*tcpsock, recvbuf, '\n', errcode);
|
|
readsize = boost::asio::read_until(*tcpsock, recvbuf, '\n', errcode);
|
|
- printDebugMessage(string(__PRETTY_FUNCTION__) + string(" asio::read() ok ") + std::to_string(readsize));
|
|
+ printMessage(string(__PRETTY_FUNCTION__) + string(" asio::read() ok ") + std::to_string(readsize), debug);
|
|
-
|
|
+
|
|
if (errcode && errcode != boost::asio::error::eof) {
|
|
if (errcode && errcode != boost::asio::error::eof) {
|
|
- printErrorMessage("IoMan::networkMain() couldnt read json data\n" + errcode.message());
|
|
+ printMessage("IoMan::networkMain() couldnt read json data\n" + errcode.message(), error);
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
if(!readsize) break;
|
|
if(!readsize) break;
|
|
@@ -164,17 +158,17 @@ void IoMan::networkMain() {
|
|
|
|
|
|
jsonsize = strchr(recvjson, '\n') - recvjson + 1;
|
|
jsonsize = strchr(recvjson, '\n') - recvjson + 1;
|
|
|
|
|
|
- printDebugMessage(string(__PRETTY_FUNCTION__) + string(" found jsondata ") + string(recvjson));
|
|
+ printMessage(string(__PRETTY_FUNCTION__) + string(" found jsondata ") + string(recvjson), debug);
|
|
|
|
|
|
if (!reader->parse(recvjson, recvjson + jsonsize, &root, &jsonerror)) {
|
|
if (!reader->parse(recvjson, recvjson + jsonsize, &root, &jsonerror)) {
|
|
- printErrorMessage("IoMan::networkMain() couldnt parse json data: " + jsonerror);
|
|
+ printMessage("IoMan::networkMain() couldnt parse json data: " + jsonerror, error);
|
|
recvbuf.consume(jsonsize);
|
|
recvbuf.consume(jsonsize);
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
recvbuf.consume(jsonsize);
|
|
recvbuf.consume(jsonsize);
|
|
readsize -= jsonsize;
|
|
readsize -= jsonsize;
|
|
|
|
|
|
- printDebugMessage(string(__PRETTY_FUNCTION__) + string(" remaining recvbuf ") + string(boost::asio::buffer_cast<const char *>(recvbuf.data())));
|
|
+ printMessage(string(__PRETTY_FUNCTION__) + string(" remaining recvbuf ") + string(boost::asio::buffer_cast<const char *>(recvbuf.data())), debug);
|
|
|
|
|
|
for(int i = 0; i < jsonsize; i++) recvjson++;
|
|
for(int i = 0; i < jsonsize; i++) recvjson++;
|
|
|
|
|
|
@@ -184,10 +178,10 @@ void IoMan::networkMain() {
|
|
if(toput.size()){
|
|
if(toput.size()){
|
|
|
|
|
|
netmutex.lock();
|
|
netmutex.lock();
|
|
- printDebugMessage(string(__PRETTY_FUNCTION__) + string(" get netmutex"));
|
|
+ printMessage(string(__PRETTY_FUNCTION__) + string(" get netmutex"), debug);
|
|
netinput.insert(netinput.end(), toput.begin(), toput.end());
|
|
netinput.insert(netinput.end(), toput.begin(), toput.end());
|
|
netmutex.unlock();
|
|
netmutex.unlock();
|
|
- printDebugMessage(string(__PRETTY_FUNCTION__) + string(" release netmutex"));
|
|
+ printMessage(string(__PRETTY_FUNCTION__) + string(" release netmutex"), debug);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -204,7 +198,7 @@ void IoMan::inputMain() {
|
|
|
|
|
|
size_t prev, index, quot;
|
|
size_t prev, index, quot;
|
|
|
|
|
|
- printDebugMessage("IoMan::inputMain() begin");
|
|
+ printMessage("IoMan::inputMain() begin", debug);
|
|
while(runinput) {
|
|
while(runinput) {
|
|
std::this_thread::yield();
|
|
std::this_thread::yield();
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
|
@@ -220,14 +214,14 @@ void IoMan::inputMain() {
|
|
|
|
|
|
if(localinput.size()) {
|
|
if(localinput.size()) {
|
|
localmutex.lock();
|
|
localmutex.lock();
|
|
- printDebugMessage(string(__PRETTY_FUNCTION__) + string(" has localmutex"));
|
|
+ printMessage(string(__PRETTY_FUNCTION__) + string(" has localmutex"), debug);
|
|
toprocess = vector<string>(localinput);
|
|
toprocess = vector<string>(localinput);
|
|
localinput = vector<string>();
|
|
localinput = vector<string>();
|
|
localmutex.unlock();
|
|
localmutex.unlock();
|
|
- printDebugMessage(string(__PRETTY_FUNCTION__) + string(" release localmutex"));
|
|
+ printMessage(string(__PRETTY_FUNCTION__) + string(" release localmutex"), debug);
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
+
|
|
|
|
|
|
|
|
|
|
for(string cmd : toprocess) {
|
|
for(string cmd : toprocess) {
|
|
@@ -284,20 +278,20 @@ void IoMan::inputMain() {
|
|
|
|
|
|
switch(cmdret.type) {
|
|
switch(cmdret.type) {
|
|
case CmdMan::rettype::send: {
|
|
case CmdMan::rettype::send: {
|
|
- printDebugMessage("IoMan::inputMain() sending json \"" + cmdret.msg + "\"");
|
|
+ printMessage("IoMan::inputMain() sending json \"" + cmdret.msg + "\"", debug);
|
|
boost::asio::write(*tcpsock, buffer(cmdret.msg + "\n"), errcode);
|
|
boost::asio::write(*tcpsock, buffer(cmdret.msg + "\n"), errcode);
|
|
if (errcode) {
|
|
if (errcode) {
|
|
- printErrorMessage("IoMan::inputMain() couldnt send json data\n" + errcode.message() + "\n");
|
|
+ printMessage("IoMan::inputMain() couldnt send json data\n" + errcode.message() + "\n", error);
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
case CmdMan::rettype::notsend: {
|
|
case CmdMan::rettype::notsend: {
|
|
- printNormalMessage(cmdret.msg);
|
|
+ printMessage(cmdret.msg, normal);
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
case CmdMan::rettype::error: {
|
|
case CmdMan::rettype::error: {
|
|
- printErrorMessage(cmdret.msg);
|
|
+ printMessage(cmdret.msg, error);
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -313,7 +307,7 @@ void IoMan::responseMain() {
|
|
vector<string> toput;
|
|
vector<string> toput;
|
|
CmdMan::CmdRet cmdret;
|
|
CmdMan::CmdRet cmdret;
|
|
|
|
|
|
- printDebugMessage("IoMan::responseMain() begin");
|
|
+ printMessage("IoMan::responseMain() begin", debug);
|
|
while(runresponse) {
|
|
while(runresponse) {
|
|
std::this_thread::yield();
|
|
std::this_thread::yield();
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
|
@@ -335,11 +329,11 @@ void IoMan::responseMain() {
|
|
|
|
|
|
if(netinput.size()) {
|
|
if(netinput.size()) {
|
|
netmutex.lock();
|
|
netmutex.lock();
|
|
- printDebugMessage(string(__PRETTY_FUNCTION__) + string(" get netmutex"));
|
|
+ printMessage(string(__PRETTY_FUNCTION__) + string(" get netmutex"), debug);
|
|
toprocess = vector<Json::Value>(netinput);
|
|
toprocess = vector<Json::Value>(netinput);
|
|
netinput = vector<Json::Value>();
|
|
netinput = vector<Json::Value>();
|
|
netmutex.unlock();
|
|
netmutex.unlock();
|
|
- printDebugMessage(string(__PRETTY_FUNCTION__) + string(" release netmutex"));
|
|
+ printMessage(string(__PRETTY_FUNCTION__) + string(" release netmutex"), debug);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -362,7 +356,7 @@ void IoMan::responseMain() {
|
|
case CmdMan::rettype::error: {
|
|
case CmdMan::rettype::error: {
|
|
if(versionstatus == off) versionstatus = err;
|
|
if(versionstatus == off) versionstatus = err;
|
|
else if(loginstatus == off) loginstatus = err;
|
|
else if(loginstatus == off) loginstatus = err;
|
|
- printErrorMessage(cmdret.msg);
|
|
+ printMessage(cmdret.msg, error);
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
case CmdMan::rettype::seton: {
|
|
case CmdMan::rettype::seton: {
|
|
@@ -370,7 +364,7 @@ void IoMan::responseMain() {
|
|
else loginstatus = on;
|
|
else loginstatus = on;
|
|
}
|
|
}
|
|
case CmdMan::rettype::notsend: {
|
|
case CmdMan::rettype::notsend: {
|
|
- printNormalMessage(cmdret.msg);
|
|
+ printMessage(cmdret.msg, normal);
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
case CmdMan::rettype::send: {
|
|
case CmdMan::rettype::send: {
|
|
@@ -383,10 +377,10 @@ void IoMan::responseMain() {
|
|
if(toput.size()) {
|
|
if(toput.size()) {
|
|
|
|
|
|
localmutex.lock();
|
|
localmutex.lock();
|
|
- printDebugMessage(string(__PRETTY_FUNCTION__) + string(" get localmutex"));
|
|
+ printMessage(string(__PRETTY_FUNCTION__) + string(" get localmutex"), debug);
|
|
localinput.insert(localinput.end(), toput.begin(), toput.end());
|
|
localinput.insert(localinput.end(), toput.begin(), toput.end());
|
|
localmutex.unlock();
|
|
localmutex.unlock();
|
|
- printDebugMessage(string(__PRETTY_FUNCTION__) + string(" release localmutex"));
|
|
+ printMessage(string(__PRETTY_FUNCTION__) + string(" release localmutex"), debug);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -396,7 +390,7 @@ void IoMan::responseMain() {
|
|
}
|
|
}
|
|
|
|
|
|
void IoMan::run() {
|
|
void IoMan::run() {
|
|
- printDebugMessage("IoMan::run() begin");
|
|
+ printMessage("IoMan::run() begin", debug);
|
|
char *line = NULL, *user = NULL, *pass = NULL;
|
|
char *line = NULL, *user = NULL, *pass = NULL;
|
|
vector<string> tokens;
|
|
vector<string> tokens;
|
|
string work, command;
|
|
string work, command;
|
|
@@ -407,20 +401,20 @@ void IoMan::run() {
|
|
|
|
|
|
while(!user) {
|
|
while(!user) {
|
|
user = readline(getUserPrompt().c_str());
|
|
user = readline(getUserPrompt().c_str());
|
|
- printErrorMessage("Using user: " + string(user));
|
|
+ printMessage("Using user: " + string(user), error);
|
|
}
|
|
}
|
|
while(!pass) {
|
|
while(!pass) {
|
|
pass = readline(getPassPrompt().c_str());
|
|
pass = readline(getPassPrompt().c_str());
|
|
- printErrorMessage("Using pass: " + string(pass));
|
|
+ printMessage("Using pass: " + string(pass), error);
|
|
}
|
|
}
|
|
|
|
|
|
- printDebugMessage("IoMan::run() login");
|
|
+ printMessage("IoMan::run() login", debug);
|
|
|
|
|
|
localmutex.lock();
|
|
localmutex.lock();
|
|
- printDebugMessage(string(__PRETTY_FUNCTION__) + string(" get localmutex"));
|
|
+ printMessage(string(__PRETTY_FUNCTION__) + string(" get localmutex"), debug);
|
|
localinput.push_back("login " + string(user) + " " + string(pass));
|
|
localinput.push_back("login " + string(user) + " " + string(pass));
|
|
localmutex.unlock();
|
|
localmutex.unlock();
|
|
- printDebugMessage(string(__PRETTY_FUNCTION__) + string(" release localmutex"));
|
|
+ printMessage(string(__PRETTY_FUNCTION__) + string(" release localmutex"), debug);
|
|
free(user);
|
|
free(user);
|
|
free(pass);
|
|
free(pass);
|
|
|
|
|
|
@@ -456,10 +450,10 @@ void IoMan::run() {
|
|
add_history(line);
|
|
add_history(line);
|
|
|
|
|
|
localmutex.lock();
|
|
localmutex.lock();
|
|
- printDebugMessage(string(__PRETTY_FUNCTION__) + string(" get localmutex"));
|
|
+ printMessage(string(__PRETTY_FUNCTION__) + string(" get localmutex"), debug);
|
|
localinput.push_back(line);
|
|
localinput.push_back(line);
|
|
localmutex.unlock();
|
|
localmutex.unlock();
|
|
- printDebugMessage(string(__PRETTY_FUNCTION__) + string(" release localmutex"));
|
|
+ printMessage(string(__PRETTY_FUNCTION__) + string(" release localmutex"), debug);
|
|
|
|
|
|
if(!connected) break;
|
|
if(!connected) break;
|
|
}
|
|
}
|