]> git.vomp.tv Git - jsonserver.git/commitdiff
Stop a recording timer from a recording point of view
authorChris Tallon <chris@vomp.tv>
Mon, 8 Apr 2013 17:54:54 +0000 (18:54 +0100)
committerChris Tallon <chris@vomp.tv>
Mon, 8 Apr 2013 17:54:54 +0000 (18:54 +0100)
handler.c
handler.h

index 9d955fc1ddda1446903cea37e8c96d2596424ba5..c3c1a20c076fc8b49a2035421639a50164dfc3f3 100644 (file)
--- a/handler.c
+++ b/handler.c
@@ -71,6 +71,7 @@ int jsonserver_request_handler(struct mg_connection *conn)
   else if (!strcmp(wvrequest, "recinfo")) success = jsonserver_recinfo(js, postData);
   else if (!strcmp(wvrequest, "recdel")) success = jsonserver_recdel(js, postData);
   else if (!strcmp(wvrequest, "recmove")) success = jsonserver_recmove(js, postData);
+  else if (!strcmp(wvrequest, "recstop")) success = jsonserver_recstop(js, postData);
   else if (!strcmp(wvrequest, "channellist")) success = jsonserver_channellist(js);
   else if (!strcmp(wvrequest, "channelschedule")) success = jsonserver_channelschedule(js, postData);
   else if (!strcmp(wvrequest, "timerlist")) success = jsonserver_timerlist(js);
@@ -241,6 +242,64 @@ bool jsonserver_recinfo(Json::Value& js, const char* postData)
   return true;
 }
 
+bool jsonserver_recstop(Json::Value& js, const char* postData)
+{
+  Log* log = Log::getInstance();
+  log->log("JSONServer", Log::DEBUG, "recstop");
+  
+  char reqfilename[1000];
+  int mgv1 = mg_get_var(postData, strlen(postData), "filename", reqfilename, 1000);
+  if (mgv1 == -1)
+  {
+    log->log("JSONServer", Log::ERR, "Could not decode filename");
+    js["Result"] = false;
+    js["Error"] = "Could not decode filename";
+    return true;
+  }
+  
+  log->log("JSONServer", Log::DEBUG, "%s", reqfilename);
+  
+  cRecordings Recordings;
+  Recordings.Load(); // probably have to do this
+  cRecording *recording = Recordings.GetByName(reqfilename);
+  
+  if (!recording)
+  {
+    log->log("JSONServer", Log::ERR, "recstop found no recording");
+    js["Result"] = false;
+    return true;
+  }
+
+  cRecordControl *rc = cRecordControls::GetRecordControl(recording->FileName());
+  if (!rc)
+  {
+    log->log("JSONServer", Log::ERR, "recstop - not currently recording");
+    js["Result"] = false;
+    return true;
+  }
+
+  if (Timers.BeingEdited())
+  {
+    log->log("JSONServer", Log::ERR, "recstop - timers being edited elsewhere");
+    js["Result"] = false;
+    return true;
+  }
+
+  cTimer* timer = rc->Timer();
+  if (!timer)
+  {
+    log->log("JSONServer", Log::ERR, "recstop - timer not found");
+    js["Result"] = false;
+    return true;
+  }
+  
+  timer->ClrFlags(tfActive);
+  Timers.SetModified();
+  
+  js["Result"] = true;
+  return true;
+}  
+  
 bool jsonserver_recdel(Json::Value& js, const char* postData)
 {
   Log* log = Log::getInstance();
index e58993a87056493917e8c15d4bbe797457e08b1c..6cdd1ed5220319712e1474385ce2d7fa910df1ea 100644 (file)
--- a/handler.h
+++ b/handler.h
@@ -10,6 +10,7 @@ bool jsonserver_reclist(Json::Value& js);
 bool jsonserver_recinfo(Json::Value& js, const char* postData);
 bool jsonserver_recdel(Json::Value& js, const char* postData);
 bool jsonserver_recmove(Json::Value& js, const char* postData);
+bool jsonserver_recstop(Json::Value& js, const char* postData);
 bool jsonserver_channellist(Json::Value& js);
 bool jsonserver_channelschedule(Json::Value& js, const char* postData);
 bool jsonserver_timerlist(Json::Value& js);