|
@@ -33,6 +33,8 @@ IoMan::IoMan(char *ipcstring) : cmdman(fileman) {
|
|
|
runinput = false;
|
|
|
runresponse = false;
|
|
|
startlist = false;
|
|
|
+ versionstatus = off;
|
|
|
+ loginstatus = off;
|
|
|
}
|
|
|
|
|
|
IoMan::~IoMan() {
|
|
@@ -49,6 +51,16 @@ IoMan::~IoMan() {
|
|
|
}
|
|
|
|
|
|
delete tcpsock;
|
|
|
+ delete reader;
|
|
|
+}
|
|
|
+
|
|
|
+void IoMan::printNormalMessage(string nouse) {
|
|
|
+}
|
|
|
+
|
|
|
+void IoMan::printErrorMessage(string nouse) {
|
|
|
+}
|
|
|
+
|
|
|
+void IoMan::printDebugMessage(string nouse) {
|
|
|
}
|
|
|
|
|
|
bool IoMan::connect() {
|
|
@@ -89,8 +101,10 @@ bool IoMan::init() {
|
|
|
printDebugMessage("IoMan::Init() versioncheck");
|
|
|
|
|
|
localmutex.lock();
|
|
|
+ printDebugMessage(string(__PRETTY_FUNCTION__) + string(" get localmutex"));
|
|
|
localinput.push_back("version " + protocolVersion);
|
|
|
localmutex.unlock();
|
|
|
+ printDebugMessage(string(__PRETTY_FUNCTION__) + string(" release localmutex"));
|
|
|
|
|
|
printDebugMessage("IoMan::Init() begin");
|
|
|
|
|
@@ -116,12 +130,14 @@ bool IoMan::init() {
|
|
|
|
|
|
void IoMan::networkMain() {
|
|
|
vector<Json::Value> toput;
|
|
|
- const char *recvjson;
|
|
|
+ char *recvjson;
|
|
|
Json::Value root;
|
|
|
- unsigned int jsonsize;
|
|
|
+ unsigned int jsonsize, readsize;
|
|
|
|
|
|
printDebugMessage("IoMan::networkMain() begin");
|
|
|
while(runnetwork) {
|
|
|
+ std::this_thread::yield();
|
|
|
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
|
|
/*
|
|
|
read from network until \n
|
|
|
try to parse json
|
|
@@ -134,16 +150,19 @@ void IoMan::networkMain() {
|
|
|
*/
|
|
|
|
|
|
// read from network
|
|
|
- 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"));
|
|
|
if (errcode && errcode != boost::asio::error::eof) {
|
|
|
printErrorMessage("IoMan::networkMain() couldnt read json data\n" + errcode.message());
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- recvjson = boost::asio::buffer_cast<const char *>(recvbuf.data());
|
|
|
+ recvjson = (char *)(boost::asio::buffer_cast<const char *>(recvbuf.data()));
|
|
|
while(strchr(recvjson, '\n')) {
|
|
|
// parse
|
|
|
- jsonsize = strchr(recvjson, '\n') - recvjson;
|
|
|
+ jsonsize = strchr(recvjson, '\n') - recvjson + 1;
|
|
|
+
|
|
|
+ printDebugMessage(string(__PRETTY_FUNCTION__) + string(" found jsondata ") + string(recvjson));
|
|
|
|
|
|
if (!reader->parse(recvjson, recvjson + jsonsize, &root, &jsonerror)) {
|
|
|
printErrorMessage("IoMan::networkMain() couldnt parse json data: " + jsonerror);
|
|
@@ -151,15 +170,27 @@ void IoMan::networkMain() {
|
|
|
continue;
|
|
|
}
|
|
|
recvbuf.consume(jsonsize);
|
|
|
+ readsize -= jsonsize;
|
|
|
+
|
|
|
+ printDebugMessage(string(__PRETTY_FUNCTION__) + string(" remaining recvbuf ") + string(boost::asio::buffer_cast<const char *>(recvbuf.data())));
|
|
|
|
|
|
+ for(int i = 0; i < jsonsize; i++) recvjson++;
|
|
|
// store locally
|
|
|
toput.push_back(root);
|
|
|
}
|
|
|
|
|
|
- // put into global vector
|
|
|
- netmutex.lock();
|
|
|
- netinput.insert(netinput.end(), toput.begin(), toput.end());
|
|
|
- netmutex.unlock();
|
|
|
+ if(toput.size()){
|
|
|
+ // put into global vector
|
|
|
+ netmutex.lock();
|
|
|
+ printDebugMessage(string(__PRETTY_FUNCTION__) + string(" get netmutex"));
|
|
|
+ netinput.insert(netinput.end(), toput.begin(), toput.end());
|
|
|
+ netmutex.unlock();
|
|
|
+ printDebugMessage(string(__PRETTY_FUNCTION__) + string(" release netmutex"));
|
|
|
+ }
|
|
|
+
|
|
|
+ // clean up local stuff
|
|
|
+ toput = vector<Json::Value>();
|
|
|
+ recvbuf.consume(readsize);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -173,6 +204,8 @@ void IoMan::inputMain() {
|
|
|
|
|
|
printDebugMessage("IoMan::inputMain() begin");
|
|
|
while(runinput) {
|
|
|
+ std::this_thread::yield();
|
|
|
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
|
|
/*
|
|
|
get inputmutex
|
|
|
read all input vector into local vector
|
|
@@ -185,12 +218,14 @@ void IoMan::inputMain() {
|
|
|
// read into local vector
|
|
|
if(localinput.size()) {
|
|
|
localmutex.lock();
|
|
|
+ printDebugMessage(string(__PRETTY_FUNCTION__) + string(" has localmutex"));
|
|
|
toprocess = vector<string>(localinput);
|
|
|
localinput = vector<string>();
|
|
|
localmutex.unlock();
|
|
|
+ printDebugMessage(string(__PRETTY_FUNCTION__) + string(" release localmutex"));
|
|
|
}
|
|
|
|
|
|
- printDebugMessage(string("have ") + std::to_string(toprocess.size()) + string(" commands"));
|
|
|
+ // printDebugMessage(string("have ") + std::to_string(toprocess.size()) + string(" commands"));
|
|
|
|
|
|
// process
|
|
|
for(string cmd : toprocess) {
|
|
@@ -202,7 +237,7 @@ void IoMan::inputMain() {
|
|
|
}
|
|
|
else {
|
|
|
command = cmd.substr(0, index);
|
|
|
- index++;
|
|
|
+ //~ index++;
|
|
|
while(true) {
|
|
|
// find first char thats not a space
|
|
|
while(cmd[index] == ' ') {
|
|
@@ -235,7 +270,7 @@ void IoMan::inputMain() {
|
|
|
goto end_tokenizing;
|
|
|
}
|
|
|
else {
|
|
|
- args.push_back(cmd.substr(1, index));
|
|
|
+ args.push_back(cmd.substr(0, index));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -265,6 +300,9 @@ void IoMan::inputMain() {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ // clean up local stuff
|
|
|
+ toprocess = vector<string>();
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -275,6 +313,8 @@ void IoMan::responseMain() {
|
|
|
|
|
|
printDebugMessage("IoMan::responseMain() begin");
|
|
|
while(runresponse) {
|
|
|
+ std::this_thread::yield();
|
|
|
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
|
|
/*
|
|
|
get networkmutex
|
|
|
read all network vector into local vector
|
|
@@ -293,9 +333,11 @@ void IoMan::responseMain() {
|
|
|
// read into local vector
|
|
|
if(netinput.size()) {
|
|
|
netmutex.lock();
|
|
|
+ printDebugMessage(string(__PRETTY_FUNCTION__) + string(" get netmutex"));
|
|
|
toprocess = vector<Json::Value>(netinput);
|
|
|
netinput = vector<Json::Value>();
|
|
|
netmutex.unlock();
|
|
|
+ printDebugMessage(string(__PRETTY_FUNCTION__) + string(" release netmutex"));
|
|
|
}
|
|
|
|
|
|
// process jsons
|
|
@@ -336,10 +378,18 @@ void IoMan::responseMain() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // put new commands into global vector
|
|
|
- localmutex.lock();
|
|
|
- localinput.insert(localinput.end(), toput.begin(), toput.end());
|
|
|
- localmutex.unlock();
|
|
|
+ if(toput.size()) {
|
|
|
+ // put new commands into global vector
|
|
|
+ localmutex.lock();
|
|
|
+ printDebugMessage(string(__PRETTY_FUNCTION__) + string(" get localmutex"));
|
|
|
+ localinput.insert(localinput.end(), toput.begin(), toput.end());
|
|
|
+ localmutex.unlock();
|
|
|
+ printDebugMessage(string(__PRETTY_FUNCTION__) + string(" release localmutex"));
|
|
|
+ }
|
|
|
+
|
|
|
+ // clean up local stuff
|
|
|
+ toprocess = vector<Json::Value>();
|
|
|
+ toput = vector<string>();
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -365,8 +415,10 @@ void IoMan::run() {
|
|
|
printDebugMessage("IoMan::run() login");
|
|
|
|
|
|
localmutex.lock();
|
|
|
+ printDebugMessage(string(__PRETTY_FUNCTION__) + string(" get localmutex"));
|
|
|
localinput.push_back("login " + string(user) + " " + string(pass));
|
|
|
localmutex.unlock();
|
|
|
+ printDebugMessage(string(__PRETTY_FUNCTION__) + string(" release localmutex"));
|
|
|
free(user);
|
|
|
free(pass);
|
|
|
|
|
@@ -400,8 +452,10 @@ void IoMan::run() {
|
|
|
add_history(line);
|
|
|
|
|
|
localmutex.lock();
|
|
|
+ printDebugMessage(string(__PRETTY_FUNCTION__) + string(" get localmutex"));
|
|
|
localinput.push_back(line);
|
|
|
localmutex.unlock();
|
|
|
+ printDebugMessage(string(__PRETTY_FUNCTION__) + string(" release localmutex"));
|
|
|
|
|
|
if(!connected) break;
|
|
|
}
|