]> git.vomp.tv Git - jsonserver.git/commitdiff
Add call to toggle timer active status
authorChris Tallon <chris@vomp.tv>
Mon, 27 May 2013 14:00:42 +0000 (15:00 +0100)
committerChris Tallon <chris@vomp.tv>
Mon, 27 May 2013 14:00:42 +0000 (15:00 +0100)
handler.c
handler.h

index 7be3028b9f6ac3479f86ddc0f7a7266eca19bcb8..54a09697f95e5ee6b3f01a886423319789a5c0de 100644 (file)
--- 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;
+}
index a208a3be45f6fa7a2ebf3aa1481b32237ddf1a75..8d1a6fabcf4b33652001aa4222cc96ec525c3217 100644 (file)
--- 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