From 9cefa63b4ea98f3b359720b219992eff24c02942 Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Mon, 27 May 2013 15:00:42 +0100 Subject: [PATCH] Add call to toggle timer active status --- handler.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++---- handler.h | 1 + 2 files changed, 67 insertions(+), 4 deletions(-) diff --git a/handler.c b/handler.c index 7be3028..54a0969 100644 --- a/handler.c +++ b/handler.c @@ -81,7 +81,8 @@ int jsonserver_request_handler(struct mg_connection *conn) else if (!strcmp(wvrequest, "timerlist")) success = jsonserver_timerlist(js); else if (!strcmp(wvrequest, "timerdel")) success = jsonserver_timerdel(js, postData); else if (!strcmp(wvrequest, "timerset")) success = jsonserver_timerset(js, postData); - + else if (!strcmp(wvrequest, "timersetactive")) success = jsonserver_timersetactive(js, postData); + if (!success) return 0; // the specific handler failed badly // Now js will be filled @@ -451,7 +452,7 @@ bool jsonserver_recmove(Json::Value& js, const char* postData) // Find the foldername log->log("JSONServer", Log::DEBUG, "j = %u, strlenvd = %u", j, strlen(VideoDirectory)); - if (j > strlen(VideoDirectory)) // Rec is in a subfolder now + if (j > (int)strlen(VideoDirectory)) // Rec is in a subfolder now { for(m = j-1; m >= 0; m--) { @@ -610,7 +611,7 @@ bool jsonserver_channellist(Json::Value& js) Json::Value jschannels; - int type; +// int type; for (cChannel *channel = Channels.First(); channel; channel = Channels.Next(channel)) { if (!channel->GroupSep()) @@ -770,7 +771,7 @@ bool jsonserver_getscheduleevent(Json::Value& js, const char* postData) return true; } - cEvent* event = Schedule->GetEvent(eventID); + const cEvent* event = Schedule->GetEvent(eventID); if (!event) { log->log("JSONServer", Log::ERR, "Could not find requested event: %i", eventID); @@ -814,6 +815,7 @@ bool jsonserver_timerlist(Json::Value& js) oneTimer["Priority"] = timer->Priority(); oneTimer["Lifetime"] = timer->Lifetime(); oneTimer["ChannelNumber"] = timer->Channel()->Number(); + oneTimer["ChannelID"] = (const char *)timer->Channel()->GetChannelID().ToString(); oneTimer["StartTime"] = (int)timer->StartTime(); oneTimer["StopTime"] = (int)timer->StopTime(); oneTimer["Day"] = (int)timer->Day(); @@ -933,3 +935,63 @@ bool jsonserver_timerset(Json::Value& js, const char* postData) return true; } +bool jsonserver_timersetactive(Json::Value& js, const char* postData) +{ + Log* log = Log::getInstance(); + log->log("JSONServer", Log::DEBUG, "timersetactive"); + + char tChannelID[30]; int mgv1 = mg_get_var(postData, strlen(postData), "ChannelID", tChannelID, 30); + char tStartTime[15]; int mgv2 = mg_get_var(postData, strlen(postData), "StartTime", tStartTime, 15); + char tStopTime[15]; int mgv3 = mg_get_var(postData, strlen(postData), "StopTime", tStopTime, 15); + char tNewActive[15]; int mgv4 = mg_get_var(postData, strlen(postData), "SetActive", tNewActive, 15); + + if ( (mgv1 == -1) || (mgv2 == -1) || (mgv3 == -1) || (mgv4 == -1) ) + { + log->log("JSONServer", Log::ERR, "request mgvs: %i %i %i %i", mgv1, mgv2, mgv3, mgv4); + js["Result"] = false; + js["Error"] = "Bad request parameters"; + return true; + } + + log->log("JSONServer", Log::DEBUG, "timersetactive: %s %s %s %s", tChannelID, tStartTime, tStopTime, tNewActive); + + int StartTime = atoi(tStartTime); + int StopTime = atoi(tStopTime); + + cTimer *timer; + int numTimers = Timers.Count(); + for (int i = 0; i < numTimers; i++) + { + timer = Timers.Get(i); + if ( (strcmp(timer->Channel()->GetChannelID().ToString(), tChannelID) == 0) + && (timer->StartTime() == StartTime) + && (timer->StopTime() == StopTime) + ) + { + // Found + + if (strcmp(tNewActive, "true") == 0) + { + timer->SetFlags(tfActive); + } + else if (strcmp(tNewActive, "false") == 0) + { + timer->ClrFlags(tfActive); + } + else + { + js["Result"] = false; + js["Error"] = "Bad request parameters"; + return true; + } + Timers.SetModified(); + + js["Result"] = true; + return true; + } + } + + js["Result"] = false; + js["Error"] = "Timer not found"; + return true; +} diff --git a/handler.h b/handler.h index a208a3b..8d1a6fa 100644 --- a/handler.h +++ b/handler.h @@ -19,6 +19,7 @@ bool jsonserver_getscheduleevent(Json::Value& js, const char* postData); bool jsonserver_timerlist(Json::Value& js); bool jsonserver_timerdel(Json::Value& js, const char* postData); bool jsonserver_timerset(Json::Value& js, const char* postData); +bool jsonserver_timersetactive(Json::Value& js, const char* postData); #endif -- 2.39.2