]> git.vomp.tv Git - jsonserver.git/commitdiff
Add tuner-status call
authorChris Tallon <chris@vomp.tv>
Sat, 12 Dec 2015 23:30:35 +0000 (23:30 +0000)
committerChris Tallon <chris@vomp.tv>
Sat, 12 Dec 2015 23:30:35 +0000 (23:30 +0000)
handler.c [changed mode: 0644->0755]
handler.h

old mode 100644 (file)
new mode 100755 (executable)
index 144434d..2af3c2c
--- a/handler.c
+++ b/handler.c
@@ -84,7 +84,7 @@ int jsonserver_request_handler(struct mg_connection *conn)
   else if (!strcmp(wvrequest, "timerset")) success = jsonserver_timerset(js, postData);
   else if (!strcmp(wvrequest, "timersetactive")) success = jsonserver_timersetactive(js, postData);
   else if (!strcmp(wvrequest, "timerisrecording")) success = jsonserver_timerisrecording(js, postData);
-
+  else if (!strcmp(wvrequest, "tunersstatus")) success = jsonserver_tunersstatus(js, postData);
   
   if (!success) return 0; // the specific handler failed badly
 
@@ -1286,3 +1286,89 @@ bool jsonserver_timerisrecording(Json::Value& js, const char* postData)
   js["Error"] = "Timer not found";
   return true;
 }
+
+bool jsonserver_tunersstatus(Json::Value& js, const char* postData)
+{
+  Log* log = Log::getInstance();
+  log->log("JSONServer", Log::DEBUG, "tunerstatus");
+  
+  js["NumDevices"] = cDevice::NumDevices();
+
+  Json::Value jsdevices(Json::arrayValue);
+  
+  for (int i = 0; i < cDevice::NumDevices(); i++)
+  {
+    Json::Value oneDevice;
+    cDevice *d = cDevice::GetDevice(i);
+    oneDevice["Number"] = d->DeviceNumber();
+    oneDevice["Type"] = (const char*)d->DeviceType();
+    oneDevice["Name"] = (const char*)d->DeviceName();
+    oneDevice["IsPrimary"] = d->IsPrimaryDevice();
+
+    const cChannel* cchannel = d->GetCurrentlyTunedTransponder();
+    if (cchannel)
+    {
+      oneDevice["Frequency"] = cchannel->Frequency();
+      oneDevice["SignalStrength"] = d->SignalStrength();
+      oneDevice["SignalQuality"] = d->SignalQuality();
+
+    }
+    else
+    {
+      oneDevice["Frequency"] = 0;
+      oneDevice["SignalStrength"] = 0;
+      oneDevice["SignalQuality"] = 0;
+    }
+    
+    jsdevices.append(oneDevice);
+  }
+  
+  js["Devices"] = jsdevices;
+
+
+  Json::Value jstimers(Json::arrayValue);
+  int numTimers = Timers.Count();
+  cTimer* timer;
+  for (int i = 0; i < numTimers; i++)
+  {
+    timer = Timers.Get(i);
+
+    if (timer->Recording())
+    {
+      Json::Value oneTimer;
+      oneTimer["Recording"] = timer->Recording();
+      oneTimer["StartTime"] = (int)timer->StartTime();
+      oneTimer["StopTime"] = (int)timer->StopTime();
+      oneTimer["File"] = timer->File();
+
+      cRecordControl* crc = cRecordControls::GetRecordControl(timer);
+      if (crc)
+      {
+        cDevice* crcd = crc->Device();
+        oneTimer["DeviceNumber"] = crcd->DeviceNumber();
+      }
+      else
+      {
+        oneTimer["DeviceNumber"] = Json::Value::null;
+      }
+
+      const cChannel* channel = timer->Channel();
+      if (channel)
+      {
+        oneTimer["ChannelName"] = channel->Name();
+      }
+      else
+      {
+        oneTimer["ChannelName"] = Json::Value::null;
+      }
+
+      jstimers.append(oneTimer);
+    }
+      
+  }
+  js["CurrentRecordings"] = jstimers;
+
+  
+  js["Result"] = true;
+  return true;
+}
index aa3159dbbb5cc8f1f702922e45f6b020d5920add..4d39a25681faea74c0ab11f0159510336029a620 100644 (file)
--- a/handler.h
+++ b/handler.h
@@ -25,6 +25,7 @@ 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);
 bool jsonserver_timerisrecording(Json::Value& js, const char* postData);
+bool jsonserver_tunersstatus(Json::Value& js, const char* postData);
 
 const cEvent* jsonserver_getEvent(Json::Value& js, int channelNumber, int eventID, int aroundTime);
 cTimer* jsonserver_findTimer(const char* rChannelID, const char* rName, const char* rStartTime, const char* rStopTime, const char* rWeekDays);