From ab4035bf0244b333c2d2ccf62f8f0428c0b633cb Mon Sep 17 00:00:00 2001 From: Thulinma Date: Tue, 3 Jan 2012 16:12:40 +0100 Subject: [PATCH] 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. --- DDV_Controller/main.cpp | 14 ++++++++++---- Makefile | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/DDV_Controller/main.cpp b/DDV_Controller/main.cpp index a5709f5e..5190d35b 100644 --- a/DDV_Controller/main.cpp +++ b/DDV_Controller/main.cpp @@ -32,6 +32,7 @@ #define UPLINK_INTERVAL 30 Socket::Server API_Socket; ///< Main connection socket. +std::map lastBuffer; ///< Last moment of contact with all buffers. /// Basic signal handler. Disconnects the server_socket if it receives /// 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){ + unsigned int currTime = time(0); for (Json::ValueIterator jit = data.begin(); jit != data.end(); jit++){ if (!Util::Procs::isActive(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["log"] = Storage["log"]; Response["statistics"] = Storage["statistics"]; + Response["now"] = (unsigned int)lastuplink; uplink->H.Clean(); uplink->H.SetBody("command="+HTTP::Parser::urlencode(Response.toStyledString())); uplink->H.BuildRequest(); @@ -454,6 +462,7 @@ int main(int argc, char ** argv){ if (JsonParse.parse(it->Received().substr(0, newlines), Request, false)){ if (Request.isMember("totals") && Request["totals"].isMember("buffer")){ std::string thisbuffer = Request["totals"]["buffer"].asString(); + lastBuffer[thisbuffer] = time(0); Storage["statistics"][thisbuffer]["curr"] = Request["curr"]; std::stringstream st; 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("clearstatlogs")){ 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{ diff --git a/Makefile b/Makefile index 47f7f1bf..c1e7386b 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -default: release-install +default: client .PHONY: client client-debug client-clean clean release-install debug-install docs client-debug: