our current experimental Neutrino branch

git-svn-id: file:///home/bas/coolstream_public_svn/THIRDPARTY/applications/neutrino-experimental@27 e54a6e83-5905-42d5-8d5c-058d10e6a962
This commit is contained in:
mrcolor
2009-12-08 11:05:11 +00:00
commit bc5bd4154e
876 changed files with 193775 additions and 0 deletions

13
src/timerd/Makefile.am Normal file
View File

@@ -0,0 +1,13 @@
AM_CPPFLAGS = -fno-rtti -fno-exceptions
INCLUDES = \
-I$(top_srcdir)/src/zapit/include \
-I$(top_srcdir)/lib \
-I$(top_srcdir)/lib/libconfigfile \
-I$(top_srcdir)/lib/connection \
-I$(top_srcdir)/lib/libeventserver \
-I$(top_srcdir)/lib/xmltree
noinst_LIBRARIES = libtimerd.a
libtimerd_a_SOURCES = timerd.cpp timermanager.cpp

35
src/timerd/debug.h Normal file
View File

@@ -0,0 +1,35 @@
/*
Timer-Daemon - DBoxII-Project
Copyright (C) 2001 Steffen Hehn 'McClean'
Homepage: http://dbox.cyberphoria.org/
License: GPL
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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __timerd_debug__
#define __timerd_debug__
extern int timerd_debug;
#define dprintf(fmt, args...) {if(timerd_debug) printf( "[timerd] " fmt, ## args);}
#define dperror(str) {perror("[timerd] " str);}
#endif

125
src/timerd/doku.html Normal file
View File

@@ -0,0 +1,125 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Neutrino Timer Doku</title>
<meta http-equiv="content-type"
content="text/html; charset=ISO-8859-15">
</head>
<body>
<div align="center">
<h1><b>Neutrino Timer <20>bersicht</b></h1>
<div align="left">Dieses Dokument soll eine kleine <20>bersicht <20>ber die derzeit
in Neutrino implementierten Timer geben. Alle Timer werden im nicht fl<66>chtigen
Speicher gesichert, d.h. sie <20>berleben runterfahren, reset, Stromausfall,...
Timer k<>nnen entweder <20>ber die Timerliste in Neutrino oder <20>ber das Web-Interface
neu erstellt, ge<67>ndert und gel<65>scht werden. Record (Aufnahme) und Zapit(Umschalt)
- Timer k<>nnen ebenfalls in der EPG-Anzeige EPG bezogen erstellt werden.
<h3>Folgende Timertypen gibt es:</h3>
</div>
<div align="left"><b>ZAPTO </b>(Umschalt-Timer):<br>
Die Box schaltet zur Alarmzeit auf einen bestimmten Sender um.<br>
1 min. vor Umschalten kommt ein Hinweis.<br>
Ein Zapto Timer holt die Box auch aus dem Deep Standby (ca.3 min vor Beginn).
Die Box bleibt nach dem Umschalten an.<br>
<br>
<b>RECORD</b> (Aufnahme-Timer):<br>
Wie der Name schon sagt dient dieser Timer zur Zeitgesteuerten Aufnahme.
Dabei h<>ngt es vom konfigurierten Aufnahme-Device (derzeit VCR und Streamingserver)
ab, was die Box genau tut. Auf jeden Fall wird der Kanal zur Aufnahmezeit
umgeschalten. Bei Aufnahme-Timern ist es jetzt auch m<>glich eine APID (Kennung
eines Audiokanals) anzugeben (-&gt;Timer bearbeiten). <br>
<br>
Bei Streamingserver-Aufnahme bleibt die Box im Standby, wenn sie das vorher
war. War sie sich nicht im Standby befindet, ist w<>hrend der Aufnahme nur das Umschalten
auf andere K<>nale auf dem selben Transponder m<>glich.<br>
<br>
Bei VCR Aufnahme kommt die Box immer aus dem Standby. W<>hrend der Aufnahme
wird in den SCART-Modus geschalten. Dies hat mehrere Gr<47>nder:<br>
- Kontrolle der Aufnahme am Fernseher (man sieht am TV was der VCR wirklich
aufnimmt)<br>
- Unterd<72>ckung der Einblendungen<br>
- Versehentliches Umschalten ist nicht m<>glich<br>
Der Scart-Mode und auch die Aufnahme k<>nnen <20>ber die HOME-Taste abgebrochen
werden. Der Timer verweilt dann noch bis zum Timer-Ende in der Timerliste
und wird dann gel<65>scht, bzw. neu gestellt (periodische Timer)<br>
<br>
Einige Minuten vor Aufnahmebeginn erfolgt eine visuelle Erinnerung.<br>
Ein Record-Timer holt die Box aus dem Deep-Standby. Wennd er Record-Timer
die Box aus dem Deep-Standby geholt hat, programmiert er nach Aufnahmeende
automatisch einen Shutdown-Timer, wenn in den n<>chsten 10 min keine weitere
Aufnahme(Record) oder ein Umschalten (Zapto) ansteht. <br>
<br>
<b>SHUTDOWN</b> (Herunterfahren):<br>
Dieser Timer f<>hrt die Box in den Deep-Standby.<br>
1 min. vor dem Runterfahren erfolgt eine Einblendung, die es auch erm<72>glicht
den Shutdown abzubrechen.<br>
<br>
<b>STANDBY</b>:<br>
Je nach Konfiguration des Timers f<>hrt er die Box in den "normalen" Standby
bzw. holt sie aus dem normalen Standby raus. (nicht deep standby).<br>
1 min. vor dem Runterfahren erfolgt eine Einblendung, die es auch erm<72>glicht
den Shutdown abzubrechen.<br>
<br>
<b>SLEEPTIMER:<br>
</b>Der Sleeptimer f<>hrt die Box je nach Einstellung in den Standby oder
Deep-Standby.<br>
1 min. vor dem Runterfahren erfolgt eine Einblendung,<br>
Existiert die Datei /var/tuxbox/config/sleep.lirc so werden die darin enthaltenen
lirc-Kommandos gesendet (z.B. zum Auschalten des TV). Dazu muss lirc gestartet
und konfiguriert sein (siehe VCR Recording doku).
Syntax der sleep.lirc Datei (pro Zeile ein Kommando, es sind mehrere Kommandos m<>glich):
<PRE><device_name> <ir_code> (<dauer_in_ms>)
device_name: Name der Fernsteuerung im lirc-config file
ir_code: Name der Taste im lirc-config file
dauer_in_ms: Dauer in ms (1/1000 sec), die das Signal gesendet werden soll, optional,
falls nicht vorhanden, wird das Signal 1 mal gesendet
Bsp.: sony_tv standby 500
grundig power</pre>
<br>
<b>REMINDER </b>(Erinnerung)<b>:</b><br>
Dieser Timer blendet einen frei w<>hlbaren Hinweistext auf dem Bildschirm
ein. Ein Zeilenvorschub kann mittels des Zeichens "/" erreicht werden.
<b>EXEC_PLUGIN </b>(Erinnerung)<b>:</b><br>
Mit diesem Timer ist es m<>glich, ein Plugin ausf<73>hren zu lassen. Im Webinterface muss z.Zt. der Name
von Hand eingegeben werden, er entspricht dem Dateinamen des Plugins ohne Erweiterung.<br>
Bsp.: Dateiname des Plugins: myScript.sh -> Eingabe: myScript<br>
In Neutrino wird ein Auswahlfenster bereitgestellt.
<h3>Timer-Wiederholung:</h3>
Alle Timer k<>nnen auch periodisch programmiert werden. Folgende Wiederholungsm<73>glichkeiten
gibt es:<br>
<br>
ONCE (Einmalig):<br>
Timer wird einmal ausgef<65>hrt und danach gel<65>scht.<br>
<br>
DAILY (T<>glich):<br>
Der Timer wird jeden Tag zur selben Zeit ausgef<65>hrt.<br>
<br>
WEEKLY(W<>chentlich):<br>
Der Timer wird immer am selben Wochentag zur selben Uhrzeit ausgef<65>hrt.<br>
<br>
BIWEEKLY (2-w<>chentlich):<br>
Der Timer wird alle 2 Wochen am selben Wochentag zur selben Zeit ausgef<65>hrt.<br>
<br>
FOURWEEKLY (4-w<>chentlich):<br>
Der Timer wird alle 4 Wochen am selben Wochentag zur selben Zeit ausgef<65>hrt.<br>
<br>
MONTHLY (Monatlich):<br>
Der Timer wird jeden Monat am selben Tag des Monats zur selben Zeit ausgef<65>hrt,<br>
<br>
WEEKDAYS (an best. Wochentagen)<br>
Der Timer wird an bestimmten, vorher konfigurierten Wochentagen zur selben
Zeit ausgef<65>hrt. (Bsp. Mo-Fr 20.00 Uhr)<br>
<br>
<h3>Timer und "Deep-Standby":</h3>
Die Box wacht 3 min. vor Record oder Zapto-Timer aus dem Deep-Standby auf.
Nach der Aufnahme wird die Box dann <20>ber einen automatisch programmierten
Shutdown-Timer wieder runtergefahren, wenn in den n<>chsten 10 min. keine
weiter Aufnahme ansteht.<br>
<br>
<br>
<br>
</div>
</div>
</body>
</html>

481
src/timerd/timerd.cpp Normal file
View File

@@ -0,0 +1,481 @@
/*
Timer-Daemon - DBoxII-Project
Copyright (C) 2001 Steffen Hehn 'McClean'
Homepage: http://dbox.cyberphoria.org/
$Id: timerd.cpp,v 1.60 2006/02/28 21:51:00 zwen Exp $
License: GPL
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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <stdio.h>
#include <string.h>
#include <sstream>
#include <signal.h>
#include <unistd.h> /* fork */
#include <syscall.h>
#include <timermanager.h>
#include <debug.h>
#include <sectionsdclient/sectionsdclient.h>
#include <connection/basicserver.h>
#include <timerdclient/timerdmsg.h>
int timerd_debug = 0;
bool timerd_parse_command(CBasicMessage::Header &rmsg, int connfd)
{
// CTimerEvent_NextProgram::EventMap::iterator it = NULL;
CTimerEventMap events;
CTimerdMsg::commandModifyTimer msgModifyTimer;
CTimerdMsg::responseGetSleeptimer rspGetSleeptimer;
CTimerEventMap::iterator pos;
switch (rmsg.cmd)
{
case CTimerdMsg::CMD_REGISTEREVENT :
CTimerManager::getInstance()->getEventServer()->registerEvent(connfd);
break;
case CTimerdMsg::CMD_UNREGISTEREVENT :
CTimerManager::getInstance()->getEventServer()->unRegisterEvent(connfd);
break;
case CTimerdMsg::CMD_GETSLEEPTIMER:
rspGetSleeptimer.eventID = 0;
if (CTimerManager::getInstance()->listEvents(events))
{
for (pos = events.begin(); pos != events.end(); pos++)
{
printf("ID: %u type: %u\n",pos->second->eventID,pos->second->eventType);
if(pos->second->eventType == CTimerd::TIMER_SLEEPTIMER)
{
rspGetSleeptimer.eventID = pos->second->eventID;
break;
}
}
}
CBasicServer::send_data(connfd, &rspGetSleeptimer, sizeof(rspGetSleeptimer));
break;
case CTimerdMsg::CMD_GETTIMER: // timer daten abfragen
CTimerdMsg::commandGetTimer msgGetTimer;
CTimerd::responseGetTimer resp;
CBasicServer::receive_data(connfd,&msgGetTimer, sizeof(msgGetTimer));
if(CTimerManager::getInstance()->listEvents(events))
{
if(events[msgGetTimer.eventID])
{
CTimerEvent *event = events[msgGetTimer.eventID];
resp.eventID = event->eventID;
resp.eventState = event->eventState;
resp.eventType = event->eventType;
resp.eventRepeat = event->eventRepeat;
resp.announceTime = event->announceTime;
resp.alarmTime = event->alarmTime;
resp.stopTime = event->stopTime;
resp.repeatCount = event->repeatCount;
if(event->eventType == CTimerd::TIMER_STANDBY)
resp.standby_on = static_cast<CTimerEvent_Standby*>(event)->standby_on;
else if(event->eventType == CTimerd::TIMER_NEXTPROGRAM)
{
resp.epgID = static_cast<CTimerEvent_NextProgram*>(event)->eventInfo.epgID;
resp.epg_starttime = static_cast<CTimerEvent_NextProgram*>(event)->eventInfo.epg_starttime;
resp.channel_id = static_cast<CTimerEvent_NextProgram*>(event)->eventInfo.channel_id;
resp.apids = static_cast<CTimerEvent_Record*>(event)->eventInfo.apids;
}
else if(event->eventType == CTimerd::TIMER_RECORD)
{
CTimerEvent_Record* ev= static_cast<CTimerEvent_Record*>(event);
resp.epgID = ev->eventInfo.epgID;
resp.epg_starttime = ev->eventInfo.epg_starttime;
resp.channel_id = ev->eventInfo.channel_id;
resp.apids = ev->eventInfo.apids;
strcpy(resp.recordingDir, ev->recordingDir.substr(0,sizeof(resp.recordingDir)-1).c_str());
strcpy(resp.epgTitle, ev->epgTitle.substr(0,sizeof(resp.epgTitle)-1).c_str());
}
else if(event->eventType == CTimerd::TIMER_ZAPTO)
{
CTimerEvent_Zapto* ev= static_cast<CTimerEvent_Zapto*>(event);
resp.epgID = ev->eventInfo.epgID;
resp.epg_starttime = ev->eventInfo.epg_starttime;
resp.channel_id = ev->eventInfo.channel_id;
resp.apids = ev->eventInfo.apids;
strcpy(resp.epgTitle, ev->epgTitle.substr(0,sizeof(resp.epgTitle)-1).c_str());
}
else if(event->eventType == CTimerd::TIMER_REMIND)
{
memset(resp.message, 0, sizeof(resp.message));
strncpy(resp.message, static_cast<CTimerEvent_Remind*>(event)->message, sizeof(resp.message)-1);
}
else if (event->eventType == CTimerd::TIMER_EXEC_PLUGIN)
{
memset(resp.pluginName, 0, sizeof(resp.pluginName));
strncpy(resp.pluginName, static_cast<CTimerEvent_ExecPlugin*>(event)->name, sizeof(resp.message)-1);
}
}
}
CBasicServer::send_data(connfd, &resp, sizeof(CTimerd::responseGetTimer));
break;
case CTimerdMsg::CMD_GETTIMERLIST:
CTimerdMsg::generalInteger responseInteger;
responseInteger.number = (CTimerManager::getInstance()->listEvents(events)) ? events.size() : 0;
if (CBasicServer::send_data(connfd, &responseInteger, sizeof(responseInteger)) == true)
{
for(CTimerEventMap::iterator pos = events.begin();pos != events.end();pos++)
{
CTimerd::responseGetTimer resp;
CTimerEvent *event = pos->second;
resp.eventID = event->eventID;
resp.eventState = event->eventState;
resp.eventType = event->eventType;
resp.eventRepeat = event->eventRepeat;
resp.announceTime = event->announceTime;
resp.alarmTime = event->alarmTime;
resp.stopTime = event->stopTime;
resp.repeatCount = event->repeatCount;
if(event->eventType == CTimerd::TIMER_STANDBY)
resp.standby_on = static_cast<CTimerEvent_Standby*>(event)->standby_on;
else if(event->eventType == CTimerd::TIMER_NEXTPROGRAM)
{
resp.epgID = static_cast<CTimerEvent_NextProgram*>(event)->eventInfo.epgID;
resp.epg_starttime = static_cast<CTimerEvent_NextProgram*>(event)->eventInfo.epg_starttime;
resp.channel_id = static_cast<CTimerEvent_NextProgram*>(event)->eventInfo.channel_id;
resp.apids = static_cast<CTimerEvent_Record*>(event)->eventInfo.apids;
}
else if(event->eventType == CTimerd::TIMER_RECORD)
{
CTimerEvent_Record* ev= static_cast<CTimerEvent_Record*>(event);
resp.epgID = ev->eventInfo.epgID;
resp.epg_starttime = ev->eventInfo.epg_starttime;
resp.channel_id = ev->eventInfo.channel_id;
resp.apids = ev->eventInfo.apids;
strcpy(resp.recordingDir, ev->recordingDir.substr(0,sizeof(resp.recordingDir)-1).c_str());
strcpy(resp.epgTitle, ev->epgTitle.substr(0,sizeof(resp.epgTitle)-1).c_str());
}
else if(event->eventType == CTimerd::TIMER_ZAPTO)
{
CTimerEvent_Zapto* ev= static_cast<CTimerEvent_Zapto*>(event);
resp.epgID = ev->eventInfo.epgID;
resp.epg_starttime = ev->eventInfo.epg_starttime;
resp.channel_id = ev->eventInfo.channel_id;
resp.apids = ev->eventInfo.apids;
strcpy(resp.epgTitle, ev->epgTitle.substr(0,sizeof(resp.epgTitle)-1).c_str());
}
else if(event->eventType == CTimerd::TIMER_REMIND)
{
strcpy(resp.message, static_cast<CTimerEvent_Remind*>(event)->message);
}
else if(event->eventType == CTimerd::TIMER_EXEC_PLUGIN)
{
strcpy(resp.pluginName, static_cast<CTimerEvent_ExecPlugin*>(event)->name);
}
CBasicServer::send_data(connfd, &resp, sizeof(CTimerd::responseGetTimer));
}
}
break;
case CTimerdMsg::CMD_RESCHEDULETIMER: // event nach vorne oder hinten schieben
{
CBasicServer::receive_data(connfd,&msgModifyTimer, sizeof(msgModifyTimer));
int ret=CTimerManager::getInstance()->rescheduleEvent(msgModifyTimer.eventID,msgModifyTimer.announceTime,msgModifyTimer.alarmTime, msgModifyTimer.stopTime);
CTimerdMsg::responseStatus rspStatus;
rspStatus.status = (ret!=0);
CBasicServer::send_data(connfd, &rspStatus, sizeof(rspStatus));
break;
}
case CTimerdMsg::CMD_MODIFYTIMER: // neue zeiten setzen
{
CBasicServer::receive_data(connfd,&msgModifyTimer, sizeof(msgModifyTimer));
CTimerd::responseGetTimer data;
CTimerd::CTimerEventTypes *type = CTimerManager::getInstance()->getEventType(msgModifyTimer.eventID);
if (type)
{
switch (*type)
{
case CTimerd::TIMER_SHUTDOWN:
case CTimerd::TIMER_NEXTPROGRAM:
case CTimerd::TIMER_ZAPTO:
case CTimerd::TIMER_STANDBY:
case CTimerd::TIMER_REMIND:
case CTimerd::TIMER_SLEEPTIMER:
case CTimerd::TIMER_EXEC_PLUGIN:
case CTimerd::TIMER_IMMEDIATE_RECORD:
break;
case CTimerd::TIMER_RECORD:
{
CTimerdMsg::commandRecordDir rdir;
CBasicServer::receive_data(connfd,&rdir, sizeof(CTimerdMsg::commandRecordDir));
strcpy(data.recordingDir,rdir.recDir);
break;
}
default:
break;
}
}
int ret=CTimerManager::getInstance()->modifyEvent(msgModifyTimer.eventID,msgModifyTimer.announceTime,msgModifyTimer.alarmTime,
msgModifyTimer.stopTime,msgModifyTimer.repeatCount,msgModifyTimer.eventRepeat,
data);
CTimerdMsg::responseStatus rspStatus;
rspStatus.status = (ret!=0);
CBasicServer::send_data(connfd, &rspStatus, sizeof(rspStatus));
break;
}
case CTimerdMsg::CMD_ADDTIMER: // neuen timer hinzuf<75>gen
CTimerdMsg::commandAddTimer msgAddTimer;
CBasicServer::receive_data(connfd,&msgAddTimer, sizeof(msgAddTimer));
CTimerdMsg::responseAddTimer rspAddTimer;
CTimerEvent* event;
CTimerd::TransferEventInfo evInfo;
switch(msgAddTimer.eventType)
{
case CTimerd::TIMER_STANDBY :
CTimerdMsg::commandSetStandby standby;
CBasicServer::receive_data(connfd, &standby, sizeof(CTimerdMsg::commandSetStandby));
event = new CTimerEvent_Standby(
msgAddTimer.announceTime,
msgAddTimer.alarmTime,
standby.standby_on,
msgAddTimer.eventRepeat,
msgAddTimer.repeatCount);
rspAddTimer.eventID = CTimerManager::getInstance()->addEvent(event);
break;
case CTimerd::TIMER_SHUTDOWN :
event = new CTimerEvent_Shutdown(
msgAddTimer.announceTime,
msgAddTimer.alarmTime,
msgAddTimer.eventRepeat,
msgAddTimer.repeatCount);
rspAddTimer.eventID = CTimerManager::getInstance()->addEvent(event);
break;
case CTimerd::TIMER_SLEEPTIMER :
event = new CTimerEvent_Sleeptimer(
msgAddTimer.announceTime,
msgAddTimer.alarmTime,
msgAddTimer.eventRepeat,
msgAddTimer.repeatCount);
rspAddTimer.eventID = CTimerManager::getInstance()->addEvent(event);
break;
case CTimerd::TIMER_RECORD :
{
CTimerd::TransferRecordingInfo recInfo;
CBasicServer::receive_data(connfd, &recInfo, sizeof(CTimerd::TransferRecordingInfo));
if(recInfo.recordingSafety)
{
int pre,post;
CTimerManager::getInstance()->getRecordingSafety(pre,post);
msgAddTimer.announceTime -= pre;
msgAddTimer.alarmTime -= pre;
msgAddTimer.stopTime += post;
}
event = new CTimerEvent_Record(
msgAddTimer.announceTime,
msgAddTimer.alarmTime,
msgAddTimer.stopTime,
recInfo.channel_id,
recInfo.epgID,
recInfo.epg_starttime,
recInfo.apids,
msgAddTimer.eventRepeat,
msgAddTimer.repeatCount,
recInfo.recordingDir);
rspAddTimer.eventID = CTimerManager::getInstance()->addEvent(event);
break;
}
case CTimerd::TIMER_IMMEDIATE_RECORD :
CBasicServer::receive_data(connfd, &evInfo, sizeof(CTimerd::TransferEventInfo));
event = new CTimerEvent_Record(
msgAddTimer.announceTime,
msgAddTimer.alarmTime,
msgAddTimer.stopTime,
evInfo.channel_id,
evInfo.epgID,
evInfo.epg_starttime,
evInfo.apids,
msgAddTimer.eventRepeat,
msgAddTimer.repeatCount);
event->eventState = CTimerd::TIMERSTATE_ISRUNNING;
rspAddTimer.eventID = CTimerManager::getInstance()->addEvent(event);
break;
case CTimerd::TIMER_ZAPTO :
CBasicServer::receive_data(connfd, &evInfo, sizeof(CTimerd::TransferEventInfo));
if(evInfo.channel_id > 0)
{
event = new CTimerEvent_Zapto(
msgAddTimer.announceTime,
msgAddTimer.alarmTime,
evInfo.channel_id,
evInfo.epgID,
evInfo.epg_starttime,
msgAddTimer.eventRepeat,
msgAddTimer.repeatCount);
rspAddTimer.eventID = CTimerManager::getInstance()->addEvent(event);
}
break;
case CTimerd::TIMER_NEXTPROGRAM :
// CTimerd::EventInfo evInfo;
CBasicServer::receive_data(connfd, &evInfo, sizeof(CTimerd::TransferEventInfo));
/*
it = CTimerEvent_NextProgram::events.find(evInfo.uniqueKey);
if (it == CTimerEvent_NextProgram::events.end())
{
event = new CTimerEvent_NextProgram(
msgAddTimer.announceTime,
msgAddTimer.alarmTime,
msgAddTimer.stopTime,
msgAddTimer.eventRepeat);
static_cast<CTimerEvent_NextProgram*>(event)->eventInfo = evInfo;
CTimerEvent_NextProgram::events.insert(make_pair(static_cast<CTimerEvent_NextProgram*>(event)->eventInfo.uniqueKey, static_cast<CTimerEvent_NextProgram*>(event)));
rspAddTimer.eventID = CTimerManager::getInstance()->addEvent(event);
}
else
{
event = it->second;
static_cast<CTimerEvent_NextProgram*>(event)->eventInfo = evInfo;
event->alarmtime.tm_mon = msgAddTimer.month;
event->alarmtime.tm_mday = msgAddTimer.day;
event->alarmtime.tm_hour = msgAddTimer.hour;
event->alarmtime.tm_min = msgAddTimer.min;
rspAddTimer.eventID = event->eventID;
}
*/
break;
case CTimerd::TIMER_REMIND :
CTimerdMsg::commandRemind remind;
CBasicServer::receive_data(connfd, &remind, sizeof(CTimerdMsg::commandRemind));
event = new CTimerEvent_Remind(msgAddTimer.announceTime,
msgAddTimer.alarmTime,
remind.message,
msgAddTimer.eventRepeat,
msgAddTimer.repeatCount);
rspAddTimer.eventID = CTimerManager::getInstance()->addEvent(event);
break;
case CTimerd::TIMER_EXEC_PLUGIN :
CTimerdMsg::commandExecPlugin pluginMsg;
CBasicServer::receive_data(connfd, &pluginMsg, sizeof(CTimerdMsg::commandExecPlugin));
event = new CTimerEvent_ExecPlugin(msgAddTimer.announceTime,
msgAddTimer.alarmTime,
pluginMsg.name,
msgAddTimer.eventRepeat,
msgAddTimer.repeatCount);
rspAddTimer.eventID = CTimerManager::getInstance()->addEvent(event);
break;
default:
printf("[timerd] Unknown TimerType\n");
}
CBasicServer::send_data(connfd, &rspAddTimer, sizeof(rspAddTimer));
break;
case CTimerdMsg::CMD_REMOVETIMER: // timer entfernen
dprintf("TIMERD: command remove\n");
CTimerdMsg::commandRemoveTimer msgRemoveTimer;
CBasicServer::receive_data(connfd,&msgRemoveTimer, sizeof(msgRemoveTimer));
dprintf("TIMERD: command remove %d\n",msgRemoveTimer.eventID);
CTimerManager::getInstance()->removeEvent(msgRemoveTimer.eventID);
break;
case CTimerdMsg::CMD_STOPTIMER: // timer stoppen
dprintf("TIMERD: command stop\n");
CTimerdMsg::commandRemoveTimer msgStopTimer;
CBasicServer::receive_data(connfd,&msgStopTimer, sizeof(msgStopTimer));
dprintf("TIMERD: command stop %d\n",msgStopTimer.eventID);
CTimerManager::getInstance()->stopEvent(msgStopTimer.eventID);
break;
case CTimerdMsg::CMD_TIMERDAVAILABLE: // testen ob server l<>uft ;)
{
CTimerdMsg::responseAvailable rspAvailable;
rspAvailable.available = true;
CBasicServer::send_data(connfd, &rspAvailable, sizeof(rspAvailable));
}
break;
case CTimerdMsg::CMD_SHUTDOWN:
{
bool ret=CTimerManager::getInstance()->shutdown();
CTimerdMsg::responseStatus rspStatus;
rspStatus.status = ret;
CBasicServer::send_data(connfd, &rspStatus, sizeof(rspStatus));
return false;
}
break;
case CTimerdMsg::CMD_SETAPID: // apid setzen
{
CTimerdMsg::commandSetAPid data;
CBasicServer::receive_data(connfd,&data, sizeof(data));
CTimerManager::getInstance()->modifyEvent(data.eventID , data.apids);
}
break;
case CTimerdMsg::CMD_SETRECSAFETY: // aufnahmekorrektur setzen
{
CTimerdMsg::commandRecordingSafety data;
CBasicServer::receive_data(connfd,&data, sizeof(data));
CTimerManager::getInstance()->setRecordingSafety(data.pre , data.post);
}
break;
case CTimerdMsg::CMD_GETRECSAFETY: // aufnahmekorrektur lesen
{
CTimerdMsg::commandRecordingSafety data;
CTimerManager::getInstance()->getRecordingSafety(data.pre , data.post);
CBasicServer::send_data(connfd, &data, sizeof(data));
}
break;
default:
dprintf("unknown command\n");
}
return true;
}
int timerd_main_thread(void *data)
{
pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, 0);
printf("timerd startup, tid %ld\n", syscall(__NR_gettid));
CBasicServer timerd_server;
if (!timerd_server.prepare(TIMERD_UDS_NAME))
return -1;
// Start timer thread
CTimerManager::getInstance();
timerd_server.run(timerd_parse_command, CTimerdMsg::ACTVERSION);
printf("timerd shutdown complete\n");
return 0;
}

1414
src/timerd/timermanager.cpp Normal file

File diff suppressed because it is too large Load Diff

252
src/timerd/timermanager.h Normal file
View File

@@ -0,0 +1,252 @@
/*
Timer-Daemon - DBoxII-Project
Copyright (C) 2001 Steffen Hehn 'McClean'
Homepage: http://dbox.cyberphoria.org/
$Id: timermanager.h,v 1.46 2006/02/28 21:51:00 zwen Exp $
License: GPL
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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __neutrino_timermanager__
#define __neutrino_timermanager__
#include <stdio.h>
#include <map>
#include <configfile.h>
#include <config.h>
#include <eventserver.h>
#include <timerdclient/timerdtypes.h>
#define CONFIGFILE CONFIGDIR "/timerd.conf"
class CTimerEvent
{
public:
int eventID; // event identifier
CTimerd::CTimerEventTypes eventType; // Type of event
CTimerd::CTimerEventStates eventState; // actual event state
CTimerd::CTimerEventStates previousState; // previous event state
CTimerd::CTimerEventRepeat eventRepeat;
uint32_t repeatCount; // how many times timer will be executed
// time values
time_t alarmTime; // event start time
time_t stopTime; // 0 = one time shot
time_t announceTime; // when should event be announced (0=none)
// CTimerEvent();
CTimerEvent( CTimerd::CTimerEventTypes evtype, int mon = 0, int day = 0, int hour = 0, int min = 0, CTimerd::CTimerEventRepeat evrepeat = CTimerd::TIMERREPEAT_ONCE, uint32_t repeatcount = 1);
CTimerEvent( CTimerd::CTimerEventTypes evtype, time_t announcetime, time_t alarmtime, time_t stoptime, CTimerd::CTimerEventRepeat evrepeat = CTimerd::TIMERREPEAT_ONCE, uint32_t repeatcount = 1);
CTimerEvent( CTimerd::CTimerEventTypes evtype, CConfigFile *config, int iId);
void setState(CTimerd::CTimerEventStates newstate){previousState = eventState; eventState = newstate;};
static int remain_min(const time_t t) {return (t - time(NULL)) / 60;};
void printEvent(void);
virtual void Reschedule();
virtual void fireEvent(){};
virtual void stopEvent(){};
virtual void announceEvent(){};
virtual void saveToConfig(CConfigFile *config);
virtual void Refresh(){};
virtual ~CTimerEvent(){};
};
typedef std::map<int, CTimerEvent*> CTimerEventMap;
class CTimerEvent_Shutdown : public CTimerEvent
{
public:
CTimerEvent_Shutdown( time_t announceTime, time_t alarmTime, CTimerd::CTimerEventRepeat evrepeat = CTimerd::TIMERREPEAT_ONCE, uint32_t repeatcount = 1) :
CTimerEvent(CTimerd::TIMER_SHUTDOWN, announceTime, alarmTime, (time_t) 0, evrepeat, repeatcount ){};
CTimerEvent_Shutdown(CConfigFile *config, int iId):
CTimerEvent(CTimerd::TIMER_SHUTDOWN, config, iId){};
virtual void fireEvent();
virtual void announceEvent();
};
class CTimerEvent_Sleeptimer : public CTimerEvent
{
public:
CTimerEvent_Sleeptimer( time_t announceTime, time_t alarmTime, CTimerd::CTimerEventRepeat evrepeat = CTimerd::TIMERREPEAT_ONCE, uint32_t repeatcount = 1) :
CTimerEvent(CTimerd::TIMER_SLEEPTIMER, announceTime, alarmTime, (time_t) 0,evrepeat,repeatcount ){};
CTimerEvent_Sleeptimer(CConfigFile *config, int iId):
CTimerEvent(CTimerd::TIMER_SLEEPTIMER, config, iId){};
virtual void fireEvent();
virtual void announceEvent();
};
class CTimerEvent_Standby : public CTimerEvent
{
public:
bool standby_on;
CTimerEvent_Standby(time_t announceTime,
time_t alarmTime,
bool sb_on,
CTimerd::CTimerEventRepeat evrepeat = CTimerd::TIMERREPEAT_ONCE,
uint32_t repeatcount = 1);
CTimerEvent_Standby(CConfigFile *config, int iId);
virtual void fireEvent();
virtual void saveToConfig(CConfigFile *config);
};
class CTimerEvent_Record : public CTimerEvent
{
public:
CTimerd::EventInfo eventInfo;
std::string recordingDir;
std::string epgTitle;
CTimerEvent_Record(time_t announceTime, time_t alarmTime, time_t stopTime,
t_channel_id channel_id,
event_id_t epgID = 0,
time_t epg_starttime = 0,
unsigned char apids = TIMERD_APIDS_STD,
CTimerd::CTimerEventRepeat evrepeat = CTimerd::TIMERREPEAT_ONCE,
uint32_t repeatcount = 1, const std::string recDir = "");
CTimerEvent_Record(CConfigFile *config, int iId);
virtual ~CTimerEvent_Record(){};
virtual CTimerd::CTimerEventTypes getEventType(void) const { return CTimerd::TIMER_RECORD; };
virtual void fireEvent();
virtual void announceEvent();
virtual void stopEvent();
virtual void saveToConfig(CConfigFile *config);
virtual void Reschedule();
void getEpgId();
virtual void Refresh();
};
class CTimerEvent_Zapto : public CTimerEvent_Record
{
public:
CTimerEvent_Zapto(time_t announceTime, time_t alarmTime,
t_channel_id channel_id,
event_id_t epgID = 0,
time_t epg_starttime = 0,
CTimerd::CTimerEventRepeat evrepeat = CTimerd::TIMERREPEAT_ONCE,
uint32_t repeatcount = 1):
CTimerEvent_Record(announceTime, alarmTime, (time_t) 0, channel_id, epgID, epg_starttime, 0, evrepeat,repeatcount)
{eventType = getEventType();};
CTimerEvent_Zapto(CConfigFile *config, int iId):
CTimerEvent_Record(config, iId)
{eventType = getEventType();};
virtual CTimerd::CTimerEventTypes getEventType(void) const { return CTimerd::TIMER_ZAPTO; };
virtual void fireEvent();
virtual void announceEvent();
virtual void stopEvent(){};
void getEpgId();
};
class CTimerEvent_NextProgram : public CTimerEvent
{
public:
CTimerd::EventInfo eventInfo;
CTimerEvent_NextProgram(time_t announceTime, time_t alarmTime, time_t stopTime,
t_channel_id channel_id,
event_id_t epgID = 0,
time_t epg_starttime = 0,
CTimerd::CTimerEventRepeat evrepeat = CTimerd::TIMERREPEAT_ONCE,
uint32_t repeatcount = 1);
CTimerEvent_NextProgram(CConfigFile *config, int iId);
virtual ~CTimerEvent_NextProgram(){};
virtual void fireEvent();
virtual void announceEvent();
virtual void saveToConfig(CConfigFile *config);
virtual void Reschedule();
};
class CTimerEvent_Remind : public CTimerEvent
{
public:
char message[REMINDER_MESSAGE_MAXLEN];
CTimerEvent_Remind(time_t announceTime,
time_t alarmTime,
const char * const msg,
CTimerd::CTimerEventRepeat evrepeat = CTimerd::TIMERREPEAT_ONCE,
uint32_t repeatcount = 1);
CTimerEvent_Remind(CConfigFile *config, int iId);
virtual void fireEvent();
virtual void saveToConfig(CConfigFile *config);
};
class CTimerEvent_ExecPlugin : public CTimerEvent
{
public:
char name[EXEC_PLUGIN_NAME_MAXLEN];
CTimerEvent_ExecPlugin(time_t announceTime,
time_t alarmTime,
const char * const plugin,
CTimerd::CTimerEventRepeat evrepeat = CTimerd::TIMERREPEAT_ONCE,
uint32_t repeatcount = 1);
CTimerEvent_ExecPlugin(CConfigFile *config, int iId);
virtual void fireEvent();
virtual void saveToConfig(CConfigFile *config);
};
class CTimerManager
{
//singleton
private:
void Init(void);
int eventID;
CEventServer *eventServer;
CTimerEventMap events;
pthread_t thrTimer;
bool m_saveEvents;
bool m_isTimeSet;
int m_extraTimeStart;
int m_extraTimeEnd;
char wakeup;
CTimerManager();
static void* timerThread(void *arg);
CTimerEvent *nextEvent();
public:
static CTimerManager* getInstance();
CEventServer* getEventServer() {return eventServer;};
int addEvent(CTimerEvent*,bool save = true);
bool removeEvent(int eventID);
bool stopEvent(int eventID);
CTimerEvent* getNextEvent();
bool listEvents(CTimerEventMap &Events);
CTimerd::CTimerEventTypes *getEventType(int eventID);
// int modifyEvent(int eventID, time_t announceTime, time_t alarmTime, time_t stopTime, uint32_t repeatcount, CTimerd::CTimerEventRepeat evrepeat = CTimerd::TIMERREPEAT_ONCE);
int modifyEvent(int eventID, time_t announceTime, time_t alarmTime, time_t stopTime, uint32_t repeatcount, CTimerd::CTimerEventRepeat evrepeat, CTimerd::responseGetTimer& data);
int modifyEvent(int eventID, unsigned char apids);
int rescheduleEvent(int eventID, time_t announceTime, time_t alarmTime, time_t stopTime);
void saveEventsToConfig();
void loadEventsFromConfig();
bool shutdown();
void shutdownOnWakeup(int currEventId);
void getRecordingSafety(int &pre, int &post){pre=m_extraTimeStart;post=m_extraTimeEnd;}
void setRecordingSafety(int pre, int post);
void loadRecordingSafety();
};
#endif