1
0
mirror of https://github.com/rofafor/vdr-plugin-satip.git synced 2023-10-10 13:37:42 +02:00

Add support for activating/deactivating server on-the-fly.

This commit is contained in:
Rolf Ahrenberg 2016-06-22 22:27:53 +03:00
parent 7289da9f41
commit bc481bcc4d
5 changed files with 43 additions and 6 deletions

View File

@ -356,6 +356,13 @@ cString cSatipDiscover::GetServerList(void)
return serversM.List();
}
void cSatipDiscover::ActivateServer(cSatipServer *serverP, bool onOffP)
{
debug16("%s (, %d)", __PRETTY_FUNCTION__, onOffP);
cMutexLock MutexLock(&mutexM);
serversM.Activate(serverP, onOffP);
}
void cSatipDiscover::AttachServer(cSatipServer *serverP, int deviceIdP, int transponderP)
{
debug16("%s (, %d, %d)", __PRETTY_FUNCTION__, deviceIdP, transponderP);

View File

@ -88,6 +88,7 @@ public:
cSatipServer *GetServer(cSatipServer *serverP);
cSatipServers *GetServers(void);
cString GetServerString(cSatipServer *serverP);
void ActivateServer(cSatipServer *serverP, bool onOffP);
void AttachServer(cSatipServer *serverP, int deviceIdP, int transponderP);
void DetachServer(cSatipServer *serverP, int deviceIdP, int transponderP);
bool IsServerQuirk(cSatipServer *serverP, int quirkP);

View File

@ -88,6 +88,7 @@ cSatipServer::cSatipServer(const char *addressP, const int portP, const char *mo
portM(portP),
quirkM(eSatipQuirkNone),
hasCiM(false),
activeM(true),
createdM(time(NULL)),
lastSeenM(0)
{
@ -297,11 +298,11 @@ cSatipServer *cSatipServers::Find(int sourceP)
cSatipServer *cSatipServers::Assign(int deviceIdP, int sourceP, int transponderP, int systemP)
{
for (cSatipServer *s = First(); s; s = Next(s)) {
for (cSatipServer *s = First(); s && s->IsActive(); s = Next(s)) {
if (s->Matches(deviceIdP, sourceP, systemP, transponderP))
return s;
}
for (cSatipServer *s = First(); s; s = Next(s)) {
for (cSatipServer *s = First(); s && s->IsActive(); s = Next(s)) {
if (s->Assign(deviceIdP, sourceP, systemP, transponderP))
return s;
}
@ -319,6 +320,16 @@ cSatipServer *cSatipServers::Update(cSatipServer *serverP)
return NULL;
}
void cSatipServers::Activate(cSatipServer *serverP, bool onOffP)
{
for (cSatipServer *s = First(); s; s = Next(s)) {
if (s == serverP) {
s->Activate(onOffP);
break;
}
}
}
void cSatipServers::Attach(cSatipServer *serverP, int deviceIdP, int transponderP)
{
for (cSatipServer *s = First(); s; s = Next(s)) {
@ -413,7 +424,7 @@ cString cSatipServers::List(void)
{
cString list = "";
for (cSatipServer *s = First(); s; s = Next(s))
list = cString::sprintf("%s%s|%s|%s\n", *list, s->Address(), s->Model(), s->Description());
list = cString::sprintf("%s%c %s|%s|%s\n", *list, s->IsActive() ? '+' : '-', s->Address(), s->Model(), s->Description());
return list;
}

View File

@ -62,6 +62,7 @@ private:
int portM;
int quirkM;
bool hasCiM;
bool activeM;
time_t createdM;
cTimeMs lastSeenM;
@ -87,6 +88,7 @@ public:
int GetModulesDVBT2(void);
int GetModulesDVBC(void);
int GetModulesDVBC2(void);
void Activate(bool onOffP) { activeM = onOffP; }
const char *Address(void) { return *addressM; }
const char *Model(void) { return *modelM; }
const char *Description(void) { return *descriptionM; }
@ -95,6 +97,7 @@ public:
bool Quirk(int quirkP) { return ((quirkP & eSatipQuirkMask) & quirkM); }
bool HasQuirk(void) { return (quirkM != eSatipQuirkNone); }
bool HasCI(void) { return hasCiM; }
bool IsActive(void) { return activeM; }
void Update(void) { lastSeenM.Set(); }
uint64_t LastSeen(void) { return lastSeenM.Elapsed(); }
time_t Created(void) { return createdM; }
@ -108,6 +111,7 @@ public:
cSatipServer *Find(int sourceP);
cSatipServer *Assign(int deviceIdP, int sourceP, int transponderP, int systemP);
cSatipServer *Update(cSatipServer *serverP);
void Activate(cSatipServer *serverP, bool onOffP);
void Attach(cSatipServer *serverP, int deviceIdP, int transponderP);
void Detach(cSatipServer *serverP, int deviceIdP, int transponderP);
bool IsQuirk(cSatipServer *serverP, int quirkP);

20
setup.c
View File

@ -86,6 +86,8 @@ eOSState cSatipEditSrcItem::ProcessKey(eKeys Key)
class cSatipServerInfo : public cOsdMenu
{
private:
cSatipServer *serverM;
int activeM;
cString addressM;
cString modelM;
cString descriptionM;
@ -101,6 +103,8 @@ public:
cSatipServerInfo::cSatipServerInfo(cSatipServer *serverP)
: cOsdMenu(tr("SAT>IP Server"), 20),
serverM(serverP),
activeM(serverP && serverP->IsActive()),
addressM(serverP ? serverP->Address() : "---"),
modelM(serverP ? serverP->Model() : "---"),
descriptionM(serverP ? serverP->Description() : "---"),
@ -118,6 +122,7 @@ cSatipServerInfo::~cSatipServerInfo()
void cSatipServerInfo::Setup(void)
{
Add(new cMenuEditBoolItem(trVDR("Active"), &activeM));
Add(new cOsdItem(cString::sprintf("%s:\t%s", tr("Address"), *addressM), osUnknown, false));
Add(new cOsdItem(cString::sprintf("%s:\t%s", tr("Model"), *modelM), osUnknown, false));
Add(new cOsdItem(cString::sprintf("%s:\t%s", tr("Description"), *descriptionM), osUnknown, false));
@ -127,6 +132,7 @@ void cSatipServerInfo::Setup(void)
eOSState cSatipServerInfo::ProcessKey(eKeys keyP)
{
int oldActive = activeM;
eOSState state = cOsdMenu::ProcessKey(keyP);
if (state == osUnknown) {
@ -135,6 +141,12 @@ eOSState cSatipServerInfo::ProcessKey(eKeys keyP)
default: state = osContinue; break;
}
}
if (keyP != kNone && oldActive != activeM) {
cSatipDiscover::GetInstance()->ActivateServer(serverM, activeM);
Setup();
}
return state;
}
@ -155,7 +167,7 @@ cSatipServerItem::cSatipServerItem(cSatipServer *serverP)
{
SetSelectable(true);
// Must begin with a '#' character!
SetText(*cString::sprintf("# %s (%s)\t%s", serverM->Address(), serverM->Model(), serverM->Description()));
SetText(*cString::sprintf("%s %s (%s)\t%s", serverM->IsActive() ? "+" : "-", serverM->Address(), serverM->Model(), serverM->Description()));
}
void cSatipServerItem::SetMenuItem(cSkinDisplayMenu *displayMenuP, int indexP, bool currentP, bool selectableP)
@ -468,10 +480,12 @@ eOSState cSatipPluginSetup::ProcessKey(eKeys keyP)
int oldNumDisabledFilters = numDisabledFiltersM;
eOSState state = cMenuSetupPage::ProcessKey(keyP);
// Ugly hack with hardcoded '#' character :(
// Ugly hack with hardcoded '+/-' characters :(
const char *p = Get(Current())->Text();
if (!hadSubMenu && !HasSubMenu() && (*p == '#') && (keyP == kOk))
if (!hadSubMenu && !HasSubMenu() && p && (*p == '+' || *p == '-') && (keyP == kOk))
return DeviceInfo();
if (hadSubMenu && !HasSubMenu())
Setup();
if (state == osUnknown) {
switch (keyP) {