|
@@ -3,10 +3,11 @@
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
+#define DEBUGPRINT(x) debugprintfunc(x)
|
|
|
//~ #define DEBUGPRINT(x) std::cerr << x
|
|
|
-#define DEBUGPRINT(x)
|
|
|
+//~ #define DEBUGPRINT(x)
|
|
|
|
|
|
-CmdMan::CmdMan(FileMan &fm) : fileman(fm) {
|
|
|
+CmdMan::CmdMan(FileMan &fm, void (*dpf)(string)) : fileman(fm) {
|
|
|
|
|
|
/* setup json stuff */
|
|
|
Json::CharReaderBuilder rbuilder;
|
|
@@ -46,6 +47,8 @@ CmdMan::CmdMan(FileMan &fm) : fileman(fm) {
|
|
|
handlemap["list"] = &CmdMan::handleList;
|
|
|
handlemap["version"] = &CmdMan::handleVersion;
|
|
|
handlemap["login"] = &CmdMan::handleLogin;
|
|
|
+
|
|
|
+ debugprintfunc = dpf;
|
|
|
}
|
|
|
|
|
|
CmdMan::~CmdMan() { delete reader; }
|
|
@@ -53,7 +56,7 @@ CmdMan::~CmdMan() { delete reader; }
|
|
|
CmdMan::CmdRet CmdMan::cmdHelp(vector<string> args) {
|
|
|
CmdRet retval;
|
|
|
Json::Value root, arr;
|
|
|
- DEBUGPRINT(__PRETTY_FUNCTION__ << " begin" << std::endl);
|
|
|
+ DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
|
|
|
map<string, string>::iterator it;
|
|
|
root["command"] = "help";
|
|
|
for (it = helpmap.begin(); it != helpmap.end(); it++) {
|
|
@@ -67,7 +70,7 @@ CmdMan::CmdRet CmdMan::cmdHelp(vector<string> args) {
|
|
|
|
|
|
CmdMan::CmdRet CmdMan::cmdStatus(vector<string> args) {
|
|
|
CmdRet retval;
|
|
|
- DEBUGPRINT(__PRETTY_FUNCTION__ << " begin" << std::endl);
|
|
|
+ DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
|
|
|
Json::Value root;
|
|
|
root["command"] = "status";
|
|
|
retval.type = send;
|
|
@@ -78,7 +81,7 @@ CmdMan::CmdRet CmdMan::cmdStatus(vector<string> args) {
|
|
|
|
|
|
CmdMan::CmdRet CmdMan::cmdDisconnect(vector<string> args) {
|
|
|
CmdRet retval;
|
|
|
- DEBUGPRINT(__PRETTY_FUNCTION__ << " begin" << std::endl);
|
|
|
+ DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
|
|
|
Json::Value root;
|
|
|
root["command"] = "close";
|
|
|
retval.type = send;
|
|
@@ -89,7 +92,7 @@ CmdMan::CmdRet CmdMan::cmdDisconnect(vector<string> args) {
|
|
|
|
|
|
CmdMan::CmdRet CmdMan::cmdPut(vector<string> args) {
|
|
|
CmdRet retval;
|
|
|
- DEBUGPRINT(__PRETTY_FUNCTION__ << " begin" << std::endl);
|
|
|
+ DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
|
|
|
Json::Value root;
|
|
|
|
|
|
bool opened = fileman.openPut(args[0]);
|
|
@@ -111,7 +114,7 @@ CmdMan::CmdRet CmdMan::cmdPut(vector<string> args) {
|
|
|
|
|
|
CmdMan::CmdRet CmdMan::cmdPutdata(vector<string> args) {
|
|
|
CmdRet retval;
|
|
|
- DEBUGPRINT(__PRETTY_FUNCTION__ << " begin" << std::endl);
|
|
|
+ DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
|
|
|
Json::Value root;
|
|
|
|
|
|
root["command"] = "putdata";
|
|
@@ -129,7 +132,7 @@ CmdMan::CmdRet CmdMan::cmdPutdata(vector<string> args) {
|
|
|
|
|
|
CmdMan::CmdRet CmdMan::cmdGet(vector<string> args) {
|
|
|
CmdRet retval;
|
|
|
- DEBUGPRINT(__PRETTY_FUNCTION__ << " begin" << std::endl);
|
|
|
+ DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
|
|
|
Json::Value root;
|
|
|
|
|
|
bool opened = fileman.openGet(args[0]);
|
|
@@ -149,7 +152,7 @@ CmdMan::CmdRet CmdMan::cmdGet(vector<string> args) {
|
|
|
|
|
|
CmdMan::CmdRet CmdMan::cmdGetdata(vector<string> args) {
|
|
|
CmdRet retval;
|
|
|
- DEBUGPRINT(__PRETTY_FUNCTION__ << " begin" << std::endl);
|
|
|
+ DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
|
|
|
Json::Value root;
|
|
|
|
|
|
root["command"] = "getdata";
|
|
@@ -164,7 +167,7 @@ CmdMan::CmdRet CmdMan::cmdGetdata(vector<string> args) {
|
|
|
|
|
|
CmdMan::CmdRet CmdMan::cmdList(vector<string> args) {
|
|
|
CmdRet retval;
|
|
|
- DEBUGPRINT(__PRETTY_FUNCTION__ << " begin" << std::endl);
|
|
|
+ DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
|
|
|
Json::Value root;
|
|
|
|
|
|
bool opened = fileman.openList();
|
|
@@ -184,7 +187,7 @@ CmdMan::CmdRet CmdMan::cmdList(vector<string> args) {
|
|
|
|
|
|
CmdMan::CmdRet CmdMan::cmdListdata(vector<string> args) {
|
|
|
CmdRet retval;
|
|
|
- DEBUGPRINT(__PRETTY_FUNCTION__ << " begin" << std::endl);
|
|
|
+ DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
|
|
|
Json::Value root;
|
|
|
root["command"] = "listdata";
|
|
|
root["chunk"] = fileman.getListRemainingChunks();
|
|
@@ -196,12 +199,12 @@ CmdMan::CmdRet CmdMan::cmdListdata(vector<string> args) {
|
|
|
}
|
|
|
|
|
|
CmdMan::CmdRet CmdMan::execute(string cmd, vector<string> args) {
|
|
|
- DEBUGPRINT(__PRETTY_FUNCTION__ << " begin" << std::endl);
|
|
|
- DEBUGPRINT(__PRETTY_FUNCTION__ << " using command \"" << cmd
|
|
|
- << "\" with arguments [ ");
|
|
|
+ DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
|
|
|
+ DEBUGPRINT(string(__PRETTY_FUNCTION__) + " using command \"" + cmd +
|
|
|
+ "\" with arguments [ ");
|
|
|
for (string s : args)
|
|
|
- DEBUGPRINT(s << " ");
|
|
|
- DEBUGPRINT("]" << std::endl);
|
|
|
+ DEBUGPRINT(s + " ");
|
|
|
+ DEBUGPRINT("]\n");
|
|
|
map<string, CmdRet (CmdMan::*)(vector<string>)>::iterator it =
|
|
|
execmap.find(cmd);
|
|
|
string retmsg;
|
|
@@ -215,7 +218,7 @@ CmdMan::CmdRet CmdMan::execute(string cmd, vector<string> args) {
|
|
|
/* internal commands */
|
|
|
CmdMan::CmdRet CmdMan::cmdVersion(vector<string> args) {
|
|
|
CmdRet retval;
|
|
|
- DEBUGPRINT(__PRETTY_FUNCTION__ << " begin" << std::endl);
|
|
|
+ DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
|
|
|
Json::Value root;
|
|
|
root["version"] = protocolVersion;
|
|
|
retval.type = send;
|
|
@@ -228,7 +231,7 @@ CmdMan::CmdRet CmdMan::cmdVersion(vector<string> args) {
|
|
|
|
|
|
CmdMan::CmdRet CmdMan::cmdLogin(vector<string> args) {
|
|
|
CmdRet retval;
|
|
|
- DEBUGPRINT(__PRETTY_FUNCTION__ << " begin" << std::endl);
|
|
|
+ DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
|
|
|
Json::Value root;
|
|
|
root["user"] = args[0];
|
|
|
root["pass"] = args[1];
|
|
@@ -253,13 +256,13 @@ CmdMan::CmdRet CmdMan::cmdLogin(vector<string> args) {
|
|
|
*/
|
|
|
|
|
|
CmdMan::CmdRet CmdMan::handle(Json::Value root) {
|
|
|
- DEBUGPRINT(__PRETTY_FUNCTION__ << " begin" << std::endl);
|
|
|
+ DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
|
|
|
if (doversion)
|
|
|
root["command"] = "version";
|
|
|
else if (dologin)
|
|
|
root["command"] = "login";
|
|
|
- DEBUGPRINT(__PRETTY_FUNCTION__ << " using json" << std::endl
|
|
|
- << root << std::endl);
|
|
|
+ DEBUGPRINT(string(__PRETTY_FUNCTION__) + " using json\n" +
|
|
|
+ Json::writeString(wbuilder, root) + "\n");
|
|
|
string retmsg;
|
|
|
map<string, CmdRet (CmdMan::*)(Json::Value)>::iterator it =
|
|
|
handlemap.find(root["command"].asString());
|
|
@@ -273,7 +276,7 @@ CmdMan::CmdRet CmdMan::handle(Json::Value root) {
|
|
|
|
|
|
CmdMan::CmdRet CmdMan::handleStatus(Json::Value root) {
|
|
|
CmdRet retval;
|
|
|
- DEBUGPRINT(__PRETTY_FUNCTION__ << " begin" << std::endl);
|
|
|
+ DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
|
|
|
retval.type = print;
|
|
|
retval.msg = root;
|
|
|
|
|
@@ -282,7 +285,7 @@ CmdMan::CmdRet CmdMan::handleStatus(Json::Value root) {
|
|
|
|
|
|
CmdMan::CmdRet CmdMan::handleClose(Json::Value root) {
|
|
|
CmdRet retval;
|
|
|
- DEBUGPRINT(__PRETTY_FUNCTION__ << " begin" << std::endl);
|
|
|
+ DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
|
|
|
retval.type = close;
|
|
|
retval.msg = root;
|
|
|
|
|
@@ -295,7 +298,7 @@ CmdMan::CmdRet CmdMan::handlePut(Json::Value root) {
|
|
|
output["command"] = "put";
|
|
|
output["file"] = fileman.getPutName();
|
|
|
output["accept"] = false;
|
|
|
- DEBUGPRINT(__PRETTY_FUNCTION__ << " begin" << std::endl);
|
|
|
+ DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
|
|
|
|
|
|
if (!root["accept"].asBool()) {
|
|
|
retval.type = error;
|
|
@@ -310,7 +313,7 @@ CmdMan::CmdRet CmdMan::handlePut(Json::Value root) {
|
|
|
output["accept"] = true;
|
|
|
output["error"] = "";
|
|
|
retval.type = print | send;
|
|
|
- output["nextcommand"] = "putdata";
|
|
|
+ retval.nextcommand = "putdata";
|
|
|
}
|
|
|
retval.msg = output;
|
|
|
|
|
@@ -320,7 +323,7 @@ CmdMan::CmdRet CmdMan::handlePut(Json::Value root) {
|
|
|
CmdMan::CmdRet CmdMan::handlePutdata(Json::Value root) {
|
|
|
CmdRet retval;
|
|
|
Json::Value output;
|
|
|
- DEBUGPRINT(__PRETTY_FUNCTION__ << " begin" << std::endl);
|
|
|
+ DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
|
|
|
output["command"] = "putdata";
|
|
|
output["file"] = fileman.getPutName();
|
|
|
output["speed"] = 0.0f; // TODO
|
|
@@ -357,7 +360,7 @@ CmdMan::CmdRet CmdMan::handlePutdata(Json::Value root) {
|
|
|
fileman.closePut();
|
|
|
} else {
|
|
|
retval.type = print | send;
|
|
|
- output["nextcommand"] = "putdata";
|
|
|
+ retval.nextcommand = "putdata";
|
|
|
}
|
|
|
}
|
|
|
retval.msg = output;
|
|
@@ -370,7 +373,7 @@ CmdMan::CmdRet CmdMan::handleGet(Json::Value root) {
|
|
|
output["command"] = "get";
|
|
|
output["file"] = fileman.getGetName();
|
|
|
output["accept"] = false;
|
|
|
- DEBUGPRINT(__PRETTY_FUNCTION__ << " begin" << std::endl);
|
|
|
+ DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
|
|
|
|
|
|
if (!root["accept"].asBool()) {
|
|
|
retval.type = error;
|
|
@@ -384,7 +387,7 @@ CmdMan::CmdRet CmdMan::handleGet(Json::Value root) {
|
|
|
output["accept"] = true;
|
|
|
output["error"] = "";
|
|
|
retval.type = print | send;
|
|
|
- output["nextcommand"] = "getdata";
|
|
|
+ retval.nextcommand = "getdata";
|
|
|
}
|
|
|
retval.msg = output;
|
|
|
|
|
@@ -394,7 +397,7 @@ CmdMan::CmdRet CmdMan::handleGet(Json::Value root) {
|
|
|
CmdMan::CmdRet CmdMan::handleGetdata(Json::Value root) {
|
|
|
CmdRet retval;
|
|
|
Json::Value output;
|
|
|
- DEBUGPRINT(__PRETTY_FUNCTION__ << " begin" << std::endl);
|
|
|
+ DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
|
|
|
output["command"] = "getdata";
|
|
|
output["file"] = fileman.getGetName();
|
|
|
output["speed"] = 0.0f; // TODO
|
|
@@ -429,7 +432,7 @@ CmdMan::CmdRet CmdMan::handleGetdata(Json::Value root) {
|
|
|
fileman.closeGet();
|
|
|
} else {
|
|
|
retval.type = print | send;
|
|
|
- output["nextcommand"] = "getdata";
|
|
|
+ retval.nextcommand = "getdata";
|
|
|
}
|
|
|
}
|
|
|
retval.msg = output;
|
|
@@ -439,7 +442,7 @@ CmdMan::CmdRet CmdMan::handleGetdata(Json::Value root) {
|
|
|
CmdMan::CmdRet CmdMan::handleList(Json::Value root) {
|
|
|
CmdRet retval;
|
|
|
Json::Value output; // LOCALOUTPUT
|
|
|
- DEBUGPRINT(__PRETTY_FUNCTION__ << " begin" << std::endl);
|
|
|
+ DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
|
|
|
|
|
|
output["command"] = "list";
|
|
|
output["names"] = "";
|
|
@@ -452,7 +455,8 @@ CmdMan::CmdRet CmdMan::handleList(Json::Value root) {
|
|
|
} else {
|
|
|
fileman.setListChunks(root["chunks"].asInt());
|
|
|
retval.type = send;
|
|
|
- output["nextcommand"] = "listdata";
|
|
|
+ output["accept"] = true;
|
|
|
+ retval.nextcommand = "listdata";
|
|
|
}
|
|
|
|
|
|
retval.msg = output;
|
|
@@ -462,7 +466,7 @@ CmdMan::CmdRet CmdMan::handleList(Json::Value root) {
|
|
|
CmdMan::CmdRet CmdMan::handleListdata(Json::Value root) {
|
|
|
CmdRet retval;
|
|
|
Json::Value output, arr;
|
|
|
- DEBUGPRINT(__PRETTY_FUNCTION__ << " begin" << std::endl);
|
|
|
+ DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
|
|
|
vector<string> toadd;
|
|
|
|
|
|
output["command"] = "list";
|
|
@@ -496,7 +500,7 @@ CmdMan::CmdRet CmdMan::handleListdata(Json::Value root) {
|
|
|
fileman.closeList();
|
|
|
} else {
|
|
|
retval.type = print | send;
|
|
|
- output["nextcommand"] = "listdata";
|
|
|
+ retval.nextcommand = "listdata";
|
|
|
}
|
|
|
}
|
|
|
retval.msg = output;
|
|
@@ -506,7 +510,7 @@ CmdMan::CmdRet CmdMan::handleListdata(Json::Value root) {
|
|
|
CmdMan::CmdRet CmdMan::handleVersion(Json::Value root) {
|
|
|
CmdRet retval;
|
|
|
Json::Value output; // LOCALOUTPUT
|
|
|
- DEBUGPRINT(__PRETTY_FUNCTION__ << " begin" << std::endl);
|
|
|
+ DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
|
|
|
|
|
|
output["command"] = "version";
|
|
|
output["serverversion"] = root["version"].asString();
|
|
@@ -528,7 +532,7 @@ CmdMan::CmdRet CmdMan::handleVersion(Json::Value root) {
|
|
|
CmdMan::CmdRet CmdMan::handleLogin(Json::Value root) {
|
|
|
CmdRet retval;
|
|
|
Json::Value output; // LOCALOUTPUT
|
|
|
- DEBUGPRINT(__PRETTY_FUNCTION__ << " begin" << std::endl);
|
|
|
+ DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
|
|
|
|
|
|
output["command"] = "login";
|
|
|
|