From b9a4cfc507aee4e0d00eee8f514cfc448041fc0a Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Sun, 2 Jul 2017 20:39:45 +0100 Subject: [PATCH] Add download-all-EPG call --- handler.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ handler.h | 1 + 2 files changed, 49 insertions(+) diff --git a/handler.c b/handler.c index 1876f41..cb2acce 100644 --- a/handler.c +++ b/handler.c @@ -88,6 +88,7 @@ int jsonserver_request_handler(struct mg_connection *conn) else if (!strcmp(wvrequest, "timeredit")) success = jsonserver_timeredit(js, postData); else if (!strcmp(wvrequest, "tunersstatus")) success = jsonserver_tunersstatus(js, postData); else if (!strcmp(wvrequest, "epgsearchsame")) success = jsonserver_epgsearchsame(js, postData); + else if (!strcmp(wvrequest, "epgdownload")) success = jsonserver_epgdownload(js, postData); if (!success) return 0; // the specific handler failed badly @@ -1699,3 +1700,50 @@ bool jsonserver_epgsearchsame(Json::Value& js, const char* postData) js["Result"] = true; return true; } + +bool jsonserver_epgdownload(Json::Value& js, const char* postData) +{ + Log* log = Log::getInstance(); + log->log("JSONServer", Log::DEBUG, "channelschedule '%s'", postData); + + cSchedulesLock MutexLock; + const cSchedules *Schedules = cSchedules::Schedules(MutexLock); + + if (!Schedules) + { + log->log("JSONServer", Log::ERR, "Could not get Schedules object"); + js["Result"] = false; + js["Error"] = "Internal schedules error (1)"; + return true; + } + + Json::Value jsevents(Json::arrayValue); + + for (cChannel* channel = Channels.First(); channel; channel = Channels.Next(channel)) + { + if (channel->GroupSep()) continue; + + const cSchedule *Schedule = Schedules->GetSchedule(channel->GetChannelID()); + if (!Schedule) continue; + + + for (const cEvent* event = Schedule->Events()->First(); event; event = Schedule->Events()->Next(event)) + { + Json::Value oneEvent; + oneEvent["ChannelNumber"] = channel->Number(); + oneEvent["ChannelID"] = (const char*)event->ChannelID().ToString(); + oneEvent["ID"] = event->EventID(); + oneEvent["Time"] = (Json::UInt)event->StartTime(); + oneEvent["Duration"] = event->Duration(); + oneEvent["Title"] = event->Title() ? event->Title() : ""; + oneEvent["ShortText"] = event->ShortText() ? event->ShortText() : ""; + oneEvent["HasTimer"] = event->HasTimer(); + oneEvent["Description"] = event->Description() ? event->Description() : ""; + jsevents.append(oneEvent); + } + } + + js["Result"] = true; + js["Events"] = jsevents; + return true; +} diff --git a/handler.h b/handler.h index f7e1f57..c7836b8 100644 --- a/handler.h +++ b/handler.h @@ -29,6 +29,7 @@ bool jsonserver_timerisrecording(Json::Value& js, const char* postData); bool jsonserver_timeredit(Json::Value& js, const char* postData); bool jsonserver_tunersstatus(Json::Value& js, const char* postData); bool jsonserver_epgsearchsame(Json::Value& js, const char* postData); +bool jsonserver_epgdownload(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); -- 2.39.5