Include stream statuses in reports to GB, erase internal buffer of statistics and do not re-write config twice per minute anymore. Also, default make target is now client, instead of release-install.

This commit is contained in:
Thulinma 2012-01-03 16:12:40 +01:00
parent 7ee6500c3b
commit ab4035bf02
2 changed files with 11 additions and 5 deletions

View file

@ -32,6 +32,7 @@
#define UPLINK_INTERVAL 30 #define UPLINK_INTERVAL 30
Socket::Server API_Socket; ///< Main connection socket. Socket::Server API_Socket; ///< Main connection socket.
std::map<std::string, int> lastBuffer; ///< Last moment of contact with all buffers.
/// Basic signal handler. Disconnects the server_socket if it receives /// Basic signal handler. Disconnects the server_socket if it receives
/// a SIGINT, SIGHUP or SIGTERM signal, but does nothing for SIGPIPE. /// a SIGINT, SIGHUP or SIGTERM signal, but does nothing for SIGPIPE.
@ -319,10 +320,16 @@ void startStream(std::string name, Json::Value & data){
} }
void CheckAllStreams(Json::Value & data){ void CheckAllStreams(Json::Value & data){
unsigned int currTime = time(0);
for (Json::ValueIterator jit = data.begin(); jit != data.end(); jit++){ for (Json::ValueIterator jit = data.begin(); jit != data.end(); jit++){
if (!Util::Procs::isActive(jit.memberName())){ if (!Util::Procs::isActive(jit.memberName())){
startStream(jit.memberName(), data[jit.memberName()]); startStream(jit.memberName(), data[jit.memberName()]);
} }
if (currTime - lastBuffer[jit.memberName()] > 5){
data[jit.memberName()]["online"] = 0;
}else{
data[jit.memberName()]["online"] = 1;
}
} }
} }
@ -425,6 +432,7 @@ int main(int argc, char ** argv){
Response["streams"] = Storage["streams"]; Response["streams"] = Storage["streams"];
Response["log"] = Storage["log"]; Response["log"] = Storage["log"];
Response["statistics"] = Storage["statistics"]; Response["statistics"] = Storage["statistics"];
Response["now"] = (unsigned int)lastuplink;
uplink->H.Clean(); uplink->H.Clean();
uplink->H.SetBody("command="+HTTP::Parser::urlencode(Response.toStyledString())); uplink->H.SetBody("command="+HTTP::Parser::urlencode(Response.toStyledString()));
uplink->H.BuildRequest(); uplink->H.BuildRequest();
@ -454,6 +462,7 @@ int main(int argc, char ** argv){
if (JsonParse.parse(it->Received().substr(0, newlines), Request, false)){ if (JsonParse.parse(it->Received().substr(0, newlines), Request, false)){
if (Request.isMember("totals") && Request["totals"].isMember("buffer")){ if (Request.isMember("totals") && Request["totals"].isMember("buffer")){
std::string thisbuffer = Request["totals"]["buffer"].asString(); std::string thisbuffer = Request["totals"]["buffer"].asString();
lastBuffer[thisbuffer] = time(0);
Storage["statistics"][thisbuffer]["curr"] = Request["curr"]; Storage["statistics"][thisbuffer]["curr"] = Request["curr"];
std::stringstream st; std::stringstream st;
st << Request["totals"]["now"].asUInt(); st << Request["totals"]["now"].asUInt();
@ -521,11 +530,8 @@ int main(int argc, char ** argv){
if (Request.isMember("streams")){CheckStreams(Request["streams"], Storage["streams"]);} if (Request.isMember("streams")){CheckStreams(Request["streams"], Storage["streams"]);}
if (Request.isMember("clearstatlogs")){ if (Request.isMember("clearstatlogs")){
Storage["log"].clear(); Storage["log"].clear();
/// \todo Uncomment this line after testing. Storage["statistics"].clear();
//Storage["statistics"].clear();
} }
//Log("UPLK", "Received data from uplink.");
//WriteFile("config.json", Storage.toStyledString());
} }
} }
}else{ }else{

View file

@ -1,4 +1,4 @@
default: release-install default: client
.PHONY: client client-debug client-clean clean release-install debug-install docs .PHONY: client client-debug client-clean clean release-install debug-install docs
client-debug: client-debug: