1
0
mirror of https://github.com/VDR4Arch/vdr.git synced 2023-10-10 13:36:52 +02:00

Fixed handling remote timers

This commit is contained in:
Klaus Schmidinger 2015-09-14 13:23:06 +02:00
parent bfc3f1f4b2
commit 8a09e90f02
3 changed files with 62 additions and 52 deletions

108
menu.c
View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: menu.c 4.11 2015/09/13 13:54:27 kls Exp $ * $Id: menu.c 4.12 2015/09/14 13:22:49 kls Exp $
*/ */
#include "menu.h" #include "menu.h"
@ -1068,67 +1068,54 @@ static bool RemoteTimerError(const cTimer *Timer)
return false; // convenience return code return false; // convenience return code
} }
bool cMenuEditTimer::HandleRemoteModifications(cTimer *OldTimer, cTimer *NewTimer) static bool HandleRemoteModifications(cTimer *NewTimer, cTimer *OldTimer = NULL)
{ {
cStringList Response; cStringList Response;
if (OldTimer->Local()) { if (!OldTimer || OldTimer->Local() || !OldTimer->Id()) {
if (NewTimer->Local()) { // timer stays local, nothing to do if (NewTimer->Local()) { // timer stays local, nothing to do
if (OldTimer && OldTimer->Id())
isyslog("modified timer %s", *NewTimer->ToDescr());
else
isyslog("added timer %s", *NewTimer->ToDescr());
} }
else { // timer is moved from local to remote else { // timer is new, or moved from local to remote
if (NewTimer->Recording())
NewTimer->SetRecording(false); // in case it was recording on the local machine
if (!ExecSVDRPCommand(NewTimer->Remote(), cString::sprintf("NEWT %s", *NewTimer->ToText(true)), &Response) || SVDRPCode(Response[0]) != 250) if (!ExecSVDRPCommand(NewTimer->Remote(), cString::sprintf("NEWT %s", *NewTimer->ToText(true)), &Response) || SVDRPCode(Response[0]) != 250)
return RemoteTimerError(NewTimer); return RemoteTimerError(NewTimer);
int RemoteId = atoi(SVDRPValue(Response[0])); int RemoteId = atoi(SVDRPValue(Response[0]));
if (RemoteId <= 0) if (RemoteId <= 0)
return RemoteTimerError(NewTimer); return RemoteTimerError(NewTimer);
cRecordControls::Stop(OldTimer);
NewTimer->SetId(RemoteId); NewTimer->SetId(RemoteId);
isyslog("moved timer %s to %d@%s", *OldTimer->ToDescr(), NewTimer->Id(), NewTimer->Remote()); if (OldTimer && OldTimer->Id()) {
if (OldTimer->Recording())
cRecordControls::Stop(OldTimer);
isyslog("moved timer %d to %s", OldTimer->Id(), *NewTimer->ToDescr());
}
else
isyslog("added timer %s", *NewTimer->ToDescr());
} }
} }
else if (NewTimer->Local()) { // timer is moved from remote to local else if (NewTimer->Local()) { // timer is moved from remote to local
if (OldTimer->Id()) { // its an existing timer if (!ExecSVDRPCommand(OldTimer->Remote(), cString::sprintf("DELT %d", OldTimer->Id()), &Response) || SVDRPCode(Response[0]) != 250)
if (!ExecSVDRPCommand(OldTimer->Remote(), cString::sprintf("DELT %d", OldTimer->Id()), &Response) || SVDRPCode(Response[0]) != 250) return RemoteTimerError(OldTimer);
return RemoteTimerError(OldTimer);
}
NewTimer->SetId(cTimers::NewTimerId()); NewTimer->SetId(cTimers::NewTimerId());
if (NewTimer->Recording()) NewTimer->ClrFlags(tfRecording); // in case it was recording on the remote machine
NewTimer->SetRecording(false); // in case it was recording on the remote machine
isyslog("moved timer %d@%s to %s", OldTimer->Id(), OldTimer->Remote(), *NewTimer->ToDescr()); isyslog("moved timer %d@%s to %s", OldTimer->Id(), OldTimer->Remote(), *NewTimer->ToDescr());
} }
else if (strcmp(OldTimer->Remote(), NewTimer->Remote()) == 0) { // timer stays remote on same machine else if (strcmp(OldTimer->Remote(), NewTimer->Remote()) == 0) { // timer stays remote on same machine
if (OldTimer->Id()) { // its an existing timer if (!ExecSVDRPCommand(OldTimer->Remote(), cString::sprintf("MODT %d %s", OldTimer->Id(), *NewTimer->ToText(true)), &Response) || SVDRPCode(Response[0]) != 250)
if (!ExecSVDRPCommand(OldTimer->Remote(), cString::sprintf("MODT %d %s", OldTimer->Id(), *NewTimer->ToText(true)), &Response) || SVDRPCode(Response[0]) != 250) return RemoteTimerError(NewTimer);
return RemoteTimerError(NewTimer); isyslog("modified timer %s", *NewTimer->ToDescr());
isyslog("modified timer %s", *NewTimer->ToDescr());
}
else { // its a new timer
if (!ExecSVDRPCommand(NewTimer->Remote(), cString::sprintf("NEWT %s", *NewTimer->ToText(true)), &Response) || SVDRPCode(Response[0]) != 250)
return RemoteTimerError(NewTimer);
int RemoteId = atoi(SVDRPValue(Response[0]));
if (RemoteId <= 0)
return RemoteTimerError(NewTimer);
NewTimer->SetId(RemoteId);
isyslog("added timer %s", *NewTimer->ToDescr());
}
} }
else { // timer is moved from one remote machine to an other else { // timer is moved from one remote machine to an other
if (NewTimer->Recording())
NewTimer->SetRecording(false); // in case it was recording on the remote machine
if (!ExecSVDRPCommand(NewTimer->Remote(), cString::sprintf("NEWT %s", *NewTimer->ToText(true)), &Response) || SVDRPCode(Response[0]) != 250) if (!ExecSVDRPCommand(NewTimer->Remote(), cString::sprintf("NEWT %s", *NewTimer->ToText(true)), &Response) || SVDRPCode(Response[0]) != 250)
return RemoteTimerError(NewTimer); return RemoteTimerError(NewTimer);
int RemoteId = atoi(SVDRPValue(Response[0])); int RemoteId = atoi(SVDRPValue(Response[0]));
if (RemoteId <= 0) if (RemoteId <= 0)
return RemoteTimerError(NewTimer); return RemoteTimerError(NewTimer);
NewTimer->SetId(RemoteId); NewTimer->SetId(RemoteId);
if (OldTimer->Id()) { // its an existing timer if (!ExecSVDRPCommand(OldTimer->Remote(), cString::sprintf("DELT %d", OldTimer->Id()), &Response) || SVDRPCode(Response[0]) != 250)
if (!ExecSVDRPCommand(OldTimer->Remote(), cString::sprintf("DELT %d", OldTimer->Id()), &Response) || SVDRPCode(Response[0]) != 250) return RemoteTimerError(OldTimer);
return RemoteTimerError(OldTimer); isyslog("moved timer %d@%s to %s", OldTimer->Id(), OldTimer->Remote(), *NewTimer->ToDescr());
isyslog("moved timer %d@%s to %s", OldTimer->Id(), OldTimer->Remote(), *NewTimer->ToDescr());
}
else // its a new timer
isyslog("added timer %s", *NewTimer->ToDescr());
} }
return true; return true;
} }
@ -1155,14 +1142,22 @@ eOSState cMenuEditTimer::ProcessKey(eKeys Key)
if (!*data.file) if (!*data.file)
strcpy(data.file, data.Channel()->ShortName(true)); strcpy(data.file, data.Channel()->ShortName(true));
data.SetRemote(*remote ? remote : NULL); data.SetRemote(*remote ? remote : NULL);
if (!HandleRemoteModifications(timer, &data))
return osContinue;
*timer = data;
if (addIfConfirmed) { if (addIfConfirmed) {
*timer = data;
Timers->Add(timer); Timers->Add(timer);
addedTimer = timer; addedTimer = timer;
if (!HandleRemoteModifications(timer)) {
// must add the timer before HandleRemoteModifications to get proper log messages with timer ids
Timers->Del(timer);
addedTimer = NULL;
return osContinue;
}
}
else {
if (!HandleRemoteModifications(&data, timer))
return osContinue;
*timer = data;
} }
isyslog("timer %s %s (%s)", *timer->ToDescr(), addIfConfirmed ? "added" : "modified", timer->HasFlags(tfActive) ? "active" : "inactive");
LOCK_SCHEDULES_READ; LOCK_SCHEDULES_READ;
timer->SetEventFromSchedule(Schedules); timer->SetEventFromSchedule(Schedules);
timer->Matches(); timer->Matches();
@ -1348,9 +1343,9 @@ eOSState cMenuTimers::OnOff(void)
RefreshCurrent(); RefreshCurrent();
DisplayCurrent(true); DisplayCurrent(true);
if (Timer->FirstDay()) if (Timer->FirstDay())
isyslog("timer %s first day set to %s", *Timer->ToDescr(), *Timer->PrintFirstDay()); isyslog("set first day of timer %s to %s", *Timer->ToDescr(), *Timer->PrintFirstDay());
else else
isyslog("timer %s %sactivated", *Timer->ToDescr(), Timer->HasFlags(tfActive) ? "" : "de"); isyslog("%sactivated timer %s", Timer->HasFlags(tfActive) ? "" : "de", *Timer->ToDescr());
} }
timersStateKey.Remove(Timer != NULL); timersStateKey.Remove(Timer != NULL);
return osContinue; return osContinue;
@ -1367,7 +1362,10 @@ eOSState cMenuTimers::New(void)
{ {
if (HasSubMenu()) if (HasSubMenu())
return osContinue; return osContinue;
return AddSubMenu(new cMenuEditTimer(new cTimer, true)); cTimer *Timer = new cTimer;
if (*Setup.SVDRPDefaultHost)
Timer->SetRemote(Setup.SVDRPDefaultHost);
return AddSubMenu(new cMenuEditTimer(Timer, true));
} }
eOSState cMenuTimers::Delete(void) eOSState cMenuTimers::Delete(void)
@ -1699,6 +1697,8 @@ eOSState cMenuWhatsOn::Record(void)
return AddSubMenu(new cMenuEditTimer(Timer)); return AddSubMenu(new cMenuEditTimer(Timer));
} }
cTimer *Timer = new cTimer(item->event); cTimer *Timer = new cTimer(item->event);
if (*Setup.SVDRPDefaultHost)
Timer->SetRemote(Setup.SVDRPDefaultHost);
if (cTimer *t = Timers->GetTimer(Timer)) { if (cTimer *t = Timers->GetTimer(Timer)) {
delete Timer; delete Timer;
Timer = t; Timer = t;
@ -1708,7 +1708,11 @@ eOSState cMenuWhatsOn::Record(void)
return AddSubMenu(new cMenuEditTimer(Timer, true)); return AddSubMenu(new cMenuEditTimer(Timer, true));
Timers->Add(Timer); Timers->Add(Timer);
Timers->SetModified(); Timers->SetModified();
isyslog("timer %s added (active)", *Timer->ToDescr()); if (!HandleRemoteModifications(Timer)) {
// must add the timer before HandleRemoteModifications to get proper log messages with timer ids
Timers->Del(Timer);
delete Timer;
}
} }
if (HasSubMenu()) if (HasSubMenu())
CloseSubMenu(); CloseSubMenu();
@ -1977,6 +1981,8 @@ eOSState cMenuSchedule::Record(void)
return AddSubMenu(new cMenuEditTimer(Timer)); return AddSubMenu(new cMenuEditTimer(Timer));
} }
cTimer *Timer = new cTimer(item->event); cTimer *Timer = new cTimer(item->event);
if (*Setup.SVDRPDefaultHost)
Timer->SetRemote(Setup.SVDRPDefaultHost);
if (cTimer *t = Timers->GetTimer(Timer)) { if (cTimer *t = Timers->GetTimer(Timer)) {
delete Timer; delete Timer;
Timer = t; Timer = t;
@ -1986,7 +1992,11 @@ eOSState cMenuSchedule::Record(void)
return AddSubMenu(new cMenuEditTimer(Timer, true)); return AddSubMenu(new cMenuEditTimer(Timer, true));
Timers->Add(Timer); Timers->Add(Timer);
Timers->SetModified(); Timers->SetModified();
isyslog("timer %s added (active)", *Timer->ToDescr()); if (!HandleRemoteModifications(Timer)) {
// must add the timer before HandleRemoteModifications to get proper log messages with timer ids
Timers->Del(Timer);
delete Timer;
}
} }
if (HasSubMenu()) if (HasSubMenu())
CloseSubMenu(); CloseSubMenu();
@ -3069,8 +3079,8 @@ eOSState cMenuRecordings::Delete(void)
Timer->Skip(); Timer->Skip();
cRecordControls::Process(Timers, time(NULL)); cRecordControls::Process(Timers, time(NULL));
if (Timer->IsSingleEvent()) { if (Timer->IsSingleEvent()) {
isyslog("deleting timer %s", *Timer->ToDescr());
Timers->Del(Timer); Timers->Del(Timer);
isyslog("deleted timer %s", *Timer->ToDescr());
} }
} }
} }
@ -5248,8 +5258,8 @@ void cRecordControls::Stop(const char *InstantId)
cTimer *Timer = RecordControls[i]->Timer(); cTimer *Timer = RecordControls[i]->Timer();
RecordControls[i]->Stop(); RecordControls[i]->Stop();
if (Timer) { if (Timer) {
isyslog("deleting timer %s", *Timer->ToDescr());
Timers->Del(Timer); Timers->Del(Timer);
isyslog("deleted timer %s", *Timer->ToDescr());
} }
break; break;
} }
@ -5461,9 +5471,9 @@ void cReplayControl::Stop(void)
cTimer *Timer = rc->Timer(); cTimer *Timer = rc->Timer();
rc->Stop(false); // don't execute user command rc->Stop(false); // don't execute user command
if (Timer) { if (Timer) {
isyslog("deleting timer %s", *Timer->ToDescr());
Timers->Del(Timer); Timers->Del(Timer);
Timers->SetModified(); Timers->SetModified();
isyslog("deleted timer %s", *Timer->ToDescr());
} }
} }
cDvbPlayerControl::Stop(); cDvbPlayerControl::Stop();

3
menu.h
View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: menu.h 4.3 2015/09/13 12:27:50 kls Exp $ * $Id: menu.h 4.4 2015/09/13 14:17:56 kls Exp $
*/ */
#ifndef __MENU_H #ifndef __MENU_H
@ -85,7 +85,6 @@ private:
eOSState SetFolder(void); eOSState SetFolder(void);
void SetFirstDayItem(void); void SetFirstDayItem(void);
void SetHelpKeys(void); void SetHelpKeys(void);
bool HandleRemoteModifications(cTimer *OldTimer, cTimer *NewTimer);
public: public:
cMenuEditTimer(cTimer *Timer, bool New = false); cMenuEditTimer(cTimer *Timer, bool New = false);
virtual ~cMenuEditTimer(); virtual ~cMenuEditTimer();

View File

@ -10,7 +10,7 @@
* and interact with the Video Disk Recorder - or write a full featured * and interact with the Video Disk Recorder - or write a full featured
* graphical interface that sits on top of an SVDRP connection. * graphical interface that sits on top of an SVDRP connection.
* *
* $Id: svdrp.c 4.8 2015/09/13 13:57:51 kls Exp $ * $Id: svdrp.c 4.9 2015/09/14 13:23:06 kls Exp $
*/ */
#include "svdrp.h" #include "svdrp.h"
@ -2000,6 +2000,7 @@ void cSVDRPServer::CmdNEWT(const char *Option)
cTimer *Timer = new cTimer; cTimer *Timer = new cTimer;
if (Timer->Parse(Option)) { if (Timer->Parse(Option)) {
LOCK_TIMERS_WRITE; LOCK_TIMERS_WRITE;
Timer->ClrFlags(tfRecording);
Timers->Add(Timer); Timers->Add(Timer);
isyslog("SVDRP < %s added timer %s", *connection, *Timer->ToDescr()); isyslog("SVDRP < %s added timer %s", *connection, *Timer->ToDescr());
Reply(250, "%d %s", Timer->Id(), *Timer->ToText(true)); Reply(250, "%d %s", Timer->Id(), *Timer->ToText(true));