summaryrefslogtreecommitdiff
path: root/switchtimer.c
diff options
context:
space:
mode:
authorChristian Wieninger <winni@debian.(none)>2007-11-11 15:40:28 +0100
committerChristian Wieninger <winni@debian.(none)>2007-11-11 15:40:28 +0100
commit8d4f8607dc1558ce73eb4c376bdbf78ddb65da83 (patch)
treed0c5dde81a36ab2e8a2edc7c1e6922556518b312 /switchtimer.c
downloadvdr-plugin-epgsearch-8d4f8607dc1558ce73eb4c376bdbf78ddb65da83.tar.gz
vdr-plugin-epgsearch-8d4f8607dc1558ce73eb4c376bdbf78ddb65da83.tar.bz2
Initial commit
Diffstat (limited to 'switchtimer.c')
-rw-r--r--switchtimer.c170
1 files changed, 170 insertions, 0 deletions
diff --git a/switchtimer.c b/switchtimer.c
new file mode 100644
index 0000000..7293ad2
--- /dev/null
+++ b/switchtimer.c
@@ -0,0 +1,170 @@
+/*
+Copyright (C) 2004-2007 Christian Wieninger
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+
+The author can be reached at cwieninger@gmx.de
+
+The project's page is at http://winni.vdr-developer.org/epgsearch
+*/
+
+#include "switchtimer.h"
+#include "epgsearchtools.h"
+
+cSwitchTimers SwitchTimers;
+
+// -- cSwitchTimer -----------------------------------------------------------------
+cSwitchTimer::cSwitchTimer(void)
+{
+ event = NULL;
+ switchMinsBefore = 1;
+ announceOnly = false;
+ unmute = 0;
+}
+
+cSwitchTimer::cSwitchTimer(const cEvent* Event, int SwitchMinsBefore, int AnnounceOnly, int Unmute)
+{
+ event = Event;
+ switchMinsBefore = SwitchMinsBefore;
+ announceOnly = AnnounceOnly;
+ unmute = Unmute;
+}
+
+bool cSwitchTimer::Parse(const char *s)
+{
+ char *line;
+ char *pos;
+ char *pos_next;
+ int parameter = 1;
+ int valuelen;
+#define MAXVALUELEN (10 * MaxFileName)
+
+ char value[MAXVALUELEN];
+
+ cChannel* channel = NULL;
+ unsigned int eventID = 0;
+ time_t startTime=0;
+
+ pos = line = strdup(s);
+ pos_next = pos + strlen(pos);
+ if (*pos_next == '\n') *pos_next = 0;
+ while (*pos) {
+ while (*pos == ' ') pos++;
+ if (*pos) {
+ if (*pos != ':') {
+ pos_next = strchr(pos, ':');
+ if (!pos_next)
+ pos_next = pos + strlen(pos);
+ valuelen = pos_next - pos + 1;
+ if (valuelen > MAXVALUELEN)
+ valuelen = MAXVALUELEN;
+ strn0cpy(value, pos, valuelen);
+ pos = pos_next;
+ switch (parameter) {
+ case 1:
+ channel = Channels.GetByChannelID(tChannelID::FromString(value), true, true);
+ break;
+ case 2:
+ eventID = atoi(value);
+ break;
+ case 3:
+ startTime = atol(value);
+ break;
+ case 4:
+ switchMinsBefore = atoi(value);
+ break;
+ case 5:
+ announceOnly = atoi(value);
+ break;
+ case 6:
+ unmute = atoi(value);
+ break;
+ } //switch
+ }
+ parameter++;
+ }
+ if (*pos) pos++;
+ } //while
+
+ time_t now = time(NULL);
+ event = NULL;
+ if (startTime > now && channel)
+ {
+ cSchedulesLock schedulesLock;
+ const cSchedules* schedules = cSchedules::Schedules(schedulesLock);
+ const cSchedule *Schedule = schedules->GetSchedule(channel->GetChannelID());
+ if (Schedule)
+ {
+ event = Schedule->GetEvent(eventID, startTime);
+ if (!event)
+ event = Schedule->GetEventAround(startTime);
+ }
+ }
+ free(line);
+ return (parameter >= 3) ? true : false;
+}
+
+const char *cSwitchTimer::ToText(bool& ignore)
+{
+ ignore = false;
+ if (!event)
+ {
+ ignore = true;
+ return NULL;
+ }
+ cChannel *channel = Channels.GetByChannelID(event->ChannelID(), true, true);
+ if (!channel) return NULL;
+ char* buffer = NULL;
+ asprintf(&buffer, "%s:%u:%ld:%d:%d:%d", CHANNELSTRING(channel), event->EventID(), event->StartTime(), switchMinsBefore, announceOnly?1:0, unmute?1:0);
+ return buffer;
+}
+
+bool cSwitchTimer::Save(FILE *f)
+{
+ bool ignore = false;
+ const char* buffer = ToText(ignore);
+ if (!ignore)
+ return fprintf(f, "%s\n", buffer) > 0;
+ return true;
+}
+
+
+cSwitchTimer* cSwitchTimers::InSwitchList(const cEvent* event)
+{
+ if (!event) return false;
+ cMutexLock SwitchTimersLock(this);
+ cSwitchTimer* switchTimer = SwitchTimers.First();
+ while (switchTimer)
+ {
+ if (switchTimer->event == event)
+ return switchTimer;
+ switchTimer = SwitchTimers.Next(switchTimer);
+ }
+ return NULL;
+}
+
+bool cSwitchTimers::Exists(const cSwitchTimer* SwitchTimer)
+{
+ cMutexLock SwitchTimersLock(this);
+ cSwitchTimer* switchTimer = SwitchTimers.First();
+ while (switchTimer)
+ {
+ if (switchTimer == SwitchTimer)
+ return true;
+ switchTimer = SwitchTimers.Next(switchTimer);
+ }
+ return false;
+}