From 840cfaabed6d8ac57baec741639c6b1fe9760d1a Mon Sep 17 00:00:00 2001 From: Thulinma Date: Wed, 11 Jun 2014 17:58:49 +0200 Subject: [PATCH] Added support for arrays of requests in totals/clients API calls. --- src/controller/controller.cpp | 16 ++++++++++++++-- src/controller/controller_statistics.cpp | 16 ++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/controller/controller.cpp b/src/controller/controller.cpp index ac3577d4..5754bb42 100644 --- a/src/controller/controller.cpp +++ b/src/controller/controller.cpp @@ -696,10 +696,22 @@ int main(int argc, char ** argv){ Controller::Storage["log"].null(); } if (Request.isMember("clients")){ - Controller::fillClients(Request["clients"], Response["clients"]); + if (Request["clients"].isArray()){ + for (unsigned int i = 0; i < Request["clients"].size(); ++i){ + Controller::fillClients(Request["clients"][i], Response["clients"][i]); + } + }else{ + Controller::fillClients(Request["clients"], Response["clients"]); + } } if (Request.isMember("totals")){ - Controller::fillTotals(Request["totals"], Response["totals"]); + if (Request["totals"].isArray()){ + for (unsigned int i = 0; i < Request["totals"].size(); ++i){ + Controller::fillTotals(Request["totals"][i], Response["totals"][i]); + } + }else{ + Controller::fillTotals(Request["totals"], Response["totals"]); + } } } diff --git a/src/controller/controller_statistics.cpp b/src/controller/controller_statistics.cpp index 02a5c38a..2dcb60c7 100644 --- a/src/controller/controller_statistics.cpp +++ b/src/controller/controller_statistics.cpp @@ -104,6 +104,13 @@ bool Controller::hasViewers(std::string streamName){ /// "time": 1234567 /// } /// ~~~~~~~~~~~~~~~ +/// OR +/// ~~~~~~~~~~~~~~~{.js} +/// [ +/// {},//request object as above +/// {}//repeat the structure as many times as wanted +/// ] +/// ~~~~~~~~~~~~~~~ /// and are responded to as: /// ~~~~~~~~~~~~~~~{.js} /// { @@ -115,6 +122,7 @@ bool Controller::hasViewers(std::string streamName){ /// "data": [[x, y, z], [x, y, z], [x, y, z]] /// } /// ~~~~~~~~~~~~~~~ +/// In case of the second method, the response is an array in the same order as the requests. void Controller::fillClients(JSON::Value & req, JSON::Value & rep){ //first, figure out the timestamp wanted long long int reqTime = 0; @@ -288,6 +296,13 @@ class totalsData { /// "end": 1234567 /// } /// ~~~~~~~~~~~~~~~ +/// OR +/// ~~~~~~~~~~~~~~~{.js} +/// [ +/// {},//request object as above +/// {}//repeat the structure as many times as wanted +/// ] +/// ~~~~~~~~~~~~~~~ /// and are responded to as: /// ~~~~~~~~~~~~~~~{.js} /// { @@ -303,6 +318,7 @@ class totalsData { /// "data": [[x, y, z], [x, y, z], [x, y, z]] /// } /// ~~~~~~~~~~~~~~~ +/// In case of the second method, the response is an array in the same order as the requests. void Controller::fillTotals(JSON::Value & req, JSON::Value & rep){ //first, figure out the timestamps wanted long long int reqStart = 0;