Example #1
0
//------------------------------------------------------------
bool CTimerManager::listEvents(CTimerEventMap &Events)
{
	if(!&Events)
		return false;
	Events.clear();
	if(getInstance()->events.size() > 0)
	{
		CTimerEventMap::iterator pos = getInstance()->events.begin();
		for(int i = 0;pos != getInstance()->events.end();pos++,i++)
			Events[pos->second->eventID] = pos->second;
		return true;
	}
	else
		return false;
}
//------------------------------------------------------------
bool CTimerManager::listEvents(CTimerEventMap &Events)
{
	if(!&Events)
		return false;

	pthread_mutex_lock(&tm_eventsMutex);

	Events.clear();
	for (CTimerEventMap::iterator pos = events.begin(); pos != events.end(); ++pos)
	{
		pos->second->Refresh();
		Events[pos->second->eventID] = pos->second;
	}
	pthread_mutex_unlock(&tm_eventsMutex);
	return true;
}
Example #3
0
bool parse_command(CBasicMessage::Header &rmsg, int connfd)
{
//	CTimerEvent_NextProgram::EventMap::iterator it = NULL;
	CTimerEventMap events;
	CTimerdMsg::commandModifyTimer msgModifyTimer;
	CTimerdMsg::responseGetSleeptimer rspGetSleeptimer;
	CTimerd::responseGetTimer resp;
	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;
			CTimerManager::getInstance()->lockEvents();
			if (CTimerManager::getInstance()->listEvents(events))
			{
				for (pos = events.begin(); pos != events.end(); ++pos)
				{
					dprintf("ID: %u type: %u\n", pos->second->eventID, pos->second->eventType);
					if (pos->second->eventType == CTimerd::TIMER_SLEEPTIMER &&
					    pos->second->eventState != CTimerd::TIMERSTATE_TERMINATED)
					{
						rspGetSleeptimer.eventID = pos->second->eventID;
						break;
					}
				}
			}
			CTimerManager::getInstance()->unlockEvents();
			CBasicServer::send_data(connfd, &rspGetSleeptimer, sizeof(rspGetSleeptimer));
			break;

		case CTimerdMsg::CMD_GETTIMER:						// timer daten abfragen
			CTimerdMsg::commandGetTimer msgGetTimer;
			CBasicServer::receive_data(connfd,&msgGetTimer, sizeof(msgGetTimer));
			CTimerManager::getInstance()->lockEvents();
			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)
					{
						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);
					}
				}
			}
			CTimerManager::getInstance()->unlockEvents();
			CBasicServer::send_data(connfd, &resp, sizeof(CTimerd::responseGetTimer));
			break;

		case CTimerdMsg::CMD_GETTIMERLIST:
			CTimerdMsg::generalInteger responseInteger;
			CTimerManager::getInstance()->lockEvents();
			responseInteger.number = (CTimerManager::getInstance()->listEvents(events)) ? events.size() : 0;

			if (CBasicServer::send_data(connfd, &responseInteger, sizeof(responseInteger)) == true)
			{
				for (CTimerEventMap::iterator it = events.begin(); it != events.end(); ++it)
				{
					CTimerEvent *event = it->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));
				}
			}
			CTimerManager::getInstance()->unlockEvents();
			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ü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)
					{
						if(evInfo.recordingSafety)
						{
							int pre;
							CTimerManager::getInstance()->getZaptoSafety(pre);
							msgAddTimer.announceTime -= pre;
							msgAddTimer.alarmTime -= pre;
						}
						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;
		case CTimerdMsg::CMD_SETZAPTOSAFETY:				  // umschaltkorrektur setzen
			{
				CTimerdMsg::commandZaptoSafety data;
				CBasicServer::receive_data(connfd,&data, sizeof(data));
				CTimerManager::getInstance()->setZaptoSafety(data.pre);
			}
			break;
		case CTimerdMsg::CMD_GETZAPTOSAFETY:				  // umschaltkorrektur lesen
			{
				CTimerdMsg::commandZaptoSafety data;
				CTimerManager::getInstance()->getZaptoSafety(data.pre);
				CBasicServer::send_data(connfd, &data, sizeof(data));
			}
			break;
		default:
			dprintf("unknown command\n");
	}
	return true;
}
Example #4
0
void parse_command(int connfd, CBasicMessage::Header * rmessage)
{

	if(rmessage->version!=CTimerd::ACTVERSION)
	{
		dperror("command with unknown version\n");
		return;
	}

//	CTimerEvent_NextProgram::EventMap::iterator it = NULL;
	CTimerEventMap events;
	CTimerd::commandModifyTimer msgModifyTimer;
	CTimerd::responseGetSleeptimer rspGetSleeptimer;
	CTimerEventMap::iterator pos;
	switch(rmessage->cmd)
	{
		
		case CTimerd::CMD_REGISTEREVENT :
			CTimerManager::getInstance()->getEventServer()->registerEvent( connfd );
			break;

		case CTimerd::CMD_UNREGISTEREVENT :
			CTimerManager::getInstance()->getEventServer()->unRegisterEvent( connfd );
			break;

		case CTimerd::CMD_GETSLEEPTIMER:
			rspGetSleeptimer.eventID = 0;
			if(CTimerManager::getInstance()->listEvents(events))
			{
				if(events.size() > 0)
				{
					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;
						}
					}
				}
			}
			write( connfd, &rspGetSleeptimer, sizeof(rspGetSleeptimer));
			break;

		case CTimerd::CMD_GETTIMER:						// timer daten abfragen
			CTimerd::commandGetTimer msgGetTimer;
			CTimerd::responseGetTimer resp;
			read(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;

					if(event->eventType == CTimerd::TIMER_STANDBY)
						resp.standby_on = static_cast<CTimerEvent_Standby*>(event)->standby_on;
					else if(event->eventID == CTimerd::TIMER_NEXTPROGRAM)
					{
						resp.epgID = static_cast<CTimerEvent_NextProgram*>(event)->eventInfo.epgID;
						resp.channel_id = static_cast<CTimerEvent_NextProgram*>(event)->eventInfo.channel_id;
					}
					else if(event->eventID == CTimerd::TIMER_RECORD)
					{
						resp.epgID = static_cast<CTimerEvent_Record*>(event)->eventInfo.epgID;
						resp.channel_id = static_cast<CTimerEvent_Record*>(event)->eventInfo.channel_id;
						resp.apid = static_cast<CTimerEvent_Record*>(event)->eventInfo.apid;
					}
					else if(event->eventID == CTimerd::TIMER_ZAPTO)
					{
						resp.epgID = static_cast<CTimerEvent_Zapto*>(event)->eventInfo.epgID;
						resp.channel_id = static_cast<CTimerEvent_Zapto*>(event)->eventInfo.channel_id;
					}
					else if(event->eventID == CTimerd::TIMER_REMIND)
					{
						memset(resp.message, 0, sizeof(resp.message));
						strncpy(resp.message, static_cast<CTimerEvent_Remind*>(event)->message, sizeof(resp.message)-1);
					}
				}
			}
			write( connfd, &resp, sizeof(CTimerd::responseGetTimer));
			break;

		case CTimerd::CMD_GETTIMERLIST:				// liste aller timer 
			if(CTimerManager::getInstance()->listEvents(events))
			{
				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;
					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.channel_id = static_cast<CTimerEvent_NextProgram*>(event)->eventInfo.channel_id;
					}
					else if(event->eventType == CTimerd::TIMER_RECORD)
					{
						resp.epgID = static_cast<CTimerEvent_Record*>(event)->eventInfo.epgID;
						resp.channel_id = static_cast<CTimerEvent_Record*>(event)->eventInfo.channel_id;
						resp.apid = static_cast<CTimerEvent_Record*>(event)->eventInfo.apid;
					}
					else if(event->eventType == CTimerd::TIMER_ZAPTO)
					{
						resp.epgID = static_cast<CTimerEvent_Zapto*>(event)->eventInfo.epgID;
						resp.channel_id = static_cast<CTimerEvent_Zapto*>(event)->eventInfo.channel_id;
					}
					else if(event->eventType == CTimerd::TIMER_REMIND)
					{
						strcpy(resp.message, static_cast<CTimerEvent_Remind*>(event)->message);
					}
					write( connfd, &resp, sizeof(CTimerd::responseGetTimer));
				}
			}
			break;

		case CTimerd::CMD_RESCHEDULETIMER:			// event nach vorne oder hinten schieben
			{
				read(connfd,&msgModifyTimer, sizeof(msgModifyTimer));
				int ret=CTimerManager::getInstance()->rescheduleEvent(msgModifyTimer.eventID,msgModifyTimer.announceTime,msgModifyTimer.alarmTime, msgModifyTimer.stopTime);
				CTimerd::responseStatus rspStatus;
				rspStatus.status = (ret!=0);
				write( connfd, &rspStatus, sizeof(rspStatus));
				break;
			}

		case CTimerd::CMD_MODIFYTIMER:				// neue zeiten setzen
			{
				read(connfd,&msgModifyTimer, sizeof(msgModifyTimer));
				int ret=CTimerManager::getInstance()->modifyEvent(msgModifyTimer.eventID,msgModifyTimer.announceTime,msgModifyTimer.alarmTime, msgModifyTimer.stopTime,
																				  msgModifyTimer.eventRepeat );
				CTimerd::responseStatus rspStatus;
				rspStatus.status = (ret!=0);
				write( connfd, &rspStatus, sizeof(rspStatus));
				break;
			}

		case CTimerd::CMD_ADDTIMER:						// neuen timer hinzufügen
			CTimerd::commandAddTimer msgAddTimer;
			read(connfd,&msgAddTimer, sizeof(msgAddTimer));

			CTimerd::responseAddTimer rspAddTimer;
			CTimerEvent* event;
			CTimerd::EventInfo evInfo;
			switch(msgAddTimer.eventType)
			{
				case CTimerd::TIMER_STANDBY :
					CTimerd::commandSetStandby standby;
					read( connfd, &standby, sizeof(CTimerd::commandSetStandby));

					event = new CTimerEvent_Standby(
															 msgAddTimer.announceTime,
															 msgAddTimer.alarmTime,
															 standby.standby_on,
															 msgAddTimer.eventRepeat);
					rspAddTimer.eventID = CTimerManager::getInstance()->addEvent( event);
					break;

				case CTimerd::TIMER_SHUTDOWN :
					event = new CTimerEvent_Shutdown(
															  msgAddTimer.announceTime,
															  msgAddTimer.alarmTime,
															  msgAddTimer.eventRepeat);
					rspAddTimer.eventID = CTimerManager::getInstance()->addEvent( event);
					break;

				case CTimerd::TIMER_SLEEPTIMER :
					event = new CTimerEvent_Sleeptimer(
																 msgAddTimer.announceTime,
																 msgAddTimer.alarmTime,
																 msgAddTimer.eventRepeat);
					rspAddTimer.eventID = CTimerManager::getInstance()->addEvent( event);
					break;

				case CTimerd::TIMER_RECORD :
					read( connfd, &evInfo, sizeof(CTimerd::EventInfo));
					event = new CTimerEvent_Record(
															msgAddTimer.announceTime,
															msgAddTimer.alarmTime,
															msgAddTimer.stopTime,
															evInfo.channel_id,
															evInfo.epgID,
															evInfo.apid,
															msgAddTimer.eventRepeat);
					rspAddTimer.eventID = CTimerManager::getInstance()->addEvent( event);
					break;

				case CTimerd::TIMER_ZAPTO :
					read( connfd, &evInfo, sizeof(CTimerd::EventInfo));
					if(evInfo.channel_id > 0)
					{
						event = new CTimerEvent_Zapto(
															  msgAddTimer.announceTime,
															  msgAddTimer.alarmTime,
															  evInfo.channel_id,
															  evInfo.epgID,
															  msgAddTimer.eventRepeat);
						rspAddTimer.eventID = CTimerManager::getInstance()->addEvent( event);
					}
					break;

				case CTimerd::TIMER_NEXTPROGRAM :
//					CTimerd::EventInfo evInfo;
					read( connfd, &evInfo, sizeof(CTimerd::EventInfo));
/*
					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 :
					CTimerd::commandRemind remind;
					read( connfd, &remind, sizeof(CTimerd::commandRemind));
					event = new CTimerEvent_Remind(msgAddTimer.announceTime,
															 msgAddTimer.alarmTime,
															 remind.message,
															 msgAddTimer.eventRepeat);
					rspAddTimer.eventID = CTimerManager::getInstance()->addEvent( event);
					break;

				default:
					printf("[timerd] Unknown TimerType\n");
			}

			write( connfd, &rspAddTimer, sizeof(rspAddTimer));

			break;
		case CTimerd::CMD_REMOVETIMER:						//	timer entfernen
			dprintf("TIMERD: command remove\n");
			CTimerd::commandRemoveTimer msgRemoveTimer;
			read(connfd,&msgRemoveTimer, sizeof(msgRemoveTimer));
			dprintf("TIMERD: command remove %d\n",msgRemoveTimer.eventID );
			CTimerManager::getInstance()->removeEvent( msgRemoveTimer.eventID);
			break;

		case CTimerd::CMD_TIMERDAVAILABLE:					// testen ob server läuft ;)
			{
				CTimerd::responseAvailable rspAvailable;
				rspAvailable.available = true;
				write( connfd, &rspAvailable, sizeof(rspAvailable));
			}
			break;
		case CTimerd::CMD_SHUTDOWN:
			{
				bool ret=CTimerManager::getInstance()->shutdown();
				CTimerd::responseStatus rspStatus;
				rspStatus.status = ret;
				write( connfd, &rspStatus, sizeof(rspStatus));
				doLoop=false;
			}
			break;
		case CTimerd::CMD_SETAPID:				  // apid setzen
			{
				CTimerd::commandSetAPid data;
				read(connfd,&data, sizeof(data));
				CTimerManager::getInstance()->modifyEvent(data.eventID , data.apid );
			}
			break;
		default:
			dprintf("unknown command\n");
	}
}