diff --git a/device.c b/device.c index 81fcd96..6eb25cf 100644 --- a/device.c +++ b/device.c @@ -328,7 +328,7 @@ bool cSatipDevice::SetChannelDevice(const cChannel *channelP, bool liveViewP) return false; } cString address; - cSatipServer *server = cSatipDiscover::GetInstance()->AssignServer(channelP->Source(), channelP->Transponder(), dtp.System()); + cSatipServer *server = cSatipDiscover::GetInstance()->AssignServer(deviceIndexM, channelP->Source(), channelP->Transponder(), dtp.System()); if (!server) { debug9("%s No suitable server found [device %u]", __PRETTY_FUNCTION__, deviceIndexM); return false; diff --git a/discover.c b/discover.c index c846699..2a77325 100644 --- a/discover.c +++ b/discover.c @@ -269,11 +269,11 @@ int cSatipDiscover::GetServerCount(void) return serversM.Count(); } -cSatipServer *cSatipDiscover::AssignServer(int sourceP, int transponderP, int systemP) +cSatipServer *cSatipDiscover::AssignServer(int deviceIdP, int sourceP, int transponderP, int systemP) { - debug16("%s (%d, %d, %d)", __PRETTY_FUNCTION__, sourceP, transponderP, systemP); + debug16("%s (%d, %d, %d, %d)", __PRETTY_FUNCTION__, deviceIdP, sourceP, transponderP, systemP); cMutexLock MutexLock(&mutexM); - return serversM.Assign(sourceP, transponderP, systemP); + return serversM.Assign(deviceIdP, sourceP, transponderP, systemP); } cSatipServer *cSatipDiscover::GetServer(int sourceP) @@ -311,11 +311,18 @@ cString cSatipDiscover::GetServerList(void) return serversM.List(); } -void cSatipDiscover::UseServer(cSatipServer *serverP, int transponderP, bool onOffP) +void cSatipDiscover::AttachServer(cSatipServer *serverP, int deviceIdP, int transponderP) { - debug16("%s (, %d, %d)", __PRETTY_FUNCTION__, transponderP, onOffP); + debug16("%s (, %d, %d)", __PRETTY_FUNCTION__, deviceIdP, transponderP); cMutexLock MutexLock(&mutexM); - serversM.Use(serverP, transponderP, onOffP); + serversM.Attach(serverP, deviceIdP, transponderP); +} + +void cSatipDiscover::DetachServer(cSatipServer *serverP, int deviceIdP, int transponderP) +{ + debug16("%s (, %d, %d)", __PRETTY_FUNCTION__, deviceIdP, transponderP); + cMutexLock MutexLock(&mutexM); + serversM.Detach(serverP, deviceIdP, transponderP); } bool cSatipDiscover::IsServerQuirk(cSatipServer *serverP, int quirkP) diff --git a/discover.h b/discover.h index 59ebf8c..4984080 100644 --- a/discover.h +++ b/discover.h @@ -74,12 +74,13 @@ public: virtual ~cSatipDiscover(); void TriggerScan(void) { probeIntervalM.Set(0); } int GetServerCount(void); - cSatipServer *AssignServer(int sourceP, int transponderP, int systemP); + cSatipServer *AssignServer(int deviceIdP, int sourceP, int transponderP, int systemP); cSatipServer *GetServer(int sourceP); cSatipServer *GetServer(cSatipServer *serverP); cSatipServers *GetServers(void); cString GetServerString(cSatipServer *serverP); - void UseServer(cSatipServer *serverP, int transponderP, bool onOffP); + void AttachServer(cSatipServer *serverP, int deviceIdP, int transponderP); + void DetachServer(cSatipServer *serverP, int deviceIdP, int transponderP); bool IsServerQuirk(cSatipServer *serverP, int quirkP); bool HasServerCI(cSatipServer *serverP); cString GetServerAddress(cSatipServer *serverP); diff --git a/server.c b/server.c index ecb9eaf..3d79e36 100644 --- a/server.c +++ b/server.c @@ -17,8 +17,8 @@ cSatipFrontend::cSatipFrontend(const int indexP, const char *descriptionP) : indexM(indexP), transponderM(0), - descriptionM(descriptionP), - usedM(false) + deviceIdM(-1), + descriptionM(descriptionP) { } @@ -28,21 +28,21 @@ cSatipFrontend::~cSatipFrontend() // --- cSatipFrontends -------------------------------------------------------- -bool cSatipFrontends::Matches(int transponderP) +bool cSatipFrontends::Matches(int deviceIdP, int transponderP) { for (cSatipFrontend *f = First(); f; f = Next(f)) { - if (f->IsUsed() && (f->Transponder() == transponderP)) + if (f->Attached() && (f->Transponder() == transponderP)) return true; } return false; } -bool cSatipFrontends::Assign(int transponderP) +bool cSatipFrontends::Assign(int deviceIdP, int transponderP) { cSatipFrontend *tmp = First(); // Prefer any unused one for (cSatipFrontend *f = First(); f; f = Next(f)) { - if (!f->IsUsed()) { + if (!f->Attached()) { tmp = f; break; } @@ -54,12 +54,24 @@ bool cSatipFrontends::Assign(int transponderP) return false; } -bool cSatipFrontends::Use(int transponderP, bool onOffP) +bool cSatipFrontends::Attach(int deviceIdP, int transponderP) { for (cSatipFrontend *f = First(); f; f = Next(f)) { if (f->Transponder() == transponderP) { - f->Use(onOffP); - debug9("%s (%d, %d) %s/#%d", __PRETTY_FUNCTION__, transponderP, onOffP, *f->Description(), f->Index()); + f->Attach(deviceIdP); + debug9("%s (%d, %d) %s/#%d", __PRETTY_FUNCTION__, deviceIdP, transponderP, *f->Description(), f->Index()); + return true; + } + } + return false; +} + +bool cSatipFrontends::Detach(int deviceIdP, int transponderP) +{ + for (cSatipFrontend *f = First(); f; f = Next(f)) { + if (f->Transponder() == transponderP) { + f->Detach(deviceIdP); + debug9("%s (%d, %d) %s/#%d", __PRETTY_FUNCTION__, deviceIdP, transponderP, *f->Description(), f->Index()); return true; } } @@ -156,22 +168,22 @@ int cSatipServer::Compare(const cListObject &listObjectP) const return result; } -bool cSatipServer::Assign(int sourceP, int systemP, int transponderP) +bool cSatipServer::Assign(int deviceIdP, int sourceP, int systemP, int transponderP) { bool result = false; if (cSource::IsType(sourceP, 'S')) - result = frontendsM[eSatipFrontendDVBS2].Assign(transponderP); + result = frontendsM[eSatipFrontendDVBS2].Assign(deviceIdP, transponderP); else if (cSource::IsType(sourceP, 'T')) { if (systemP) - result = frontendsM[eSatipFrontendDVBT2].Assign(transponderP); + result = frontendsM[eSatipFrontendDVBT2].Assign(deviceIdP, transponderP); else - result = frontendsM[eSatipFrontendDVBT].Assign(transponderP) || frontendsM[eSatipFrontendDVBT2].Assign(transponderP); + result = frontendsM[eSatipFrontendDVBT].Assign(deviceIdP, transponderP) || frontendsM[eSatipFrontendDVBT2].Assign(deviceIdP, transponderP); } else if (cSource::IsType(sourceP, 'C')) { if (systemP) - result = frontendsM[eSatipFrontendDVBC2].Assign(transponderP); + result = frontendsM[eSatipFrontendDVBC2].Assign(deviceIdP, transponderP); else - result = frontendsM[eSatipFrontendDVBC].Assign(transponderP) || frontendsM[eSatipFrontendDVBC2].Assign(transponderP); + result = frontendsM[eSatipFrontendDVBC].Assign(deviceIdP, transponderP) || frontendsM[eSatipFrontendDVBC2].Assign(deviceIdP, transponderP); } return result; } @@ -187,30 +199,38 @@ bool cSatipServer::Matches(int sourceP) return false; } -bool cSatipServer::Matches(int sourceP, int systemP, int transponderP) +bool cSatipServer::Matches(int deviceIdP, int sourceP, int systemP, int transponderP) { bool result = false; if (cSource::IsType(sourceP, 'S')) - result = frontendsM[eSatipFrontendDVBS2].Matches(transponderP); + result = frontendsM[eSatipFrontendDVBS2].Matches(deviceIdP, transponderP); else if (cSource::IsType(sourceP, 'T')) { if (systemP) - result = frontendsM[eSatipFrontendDVBT2].Matches(transponderP); + result = frontendsM[eSatipFrontendDVBT2].Matches(deviceIdP, transponderP); else - result = frontendsM[eSatipFrontendDVBT].Matches(transponderP) || frontendsM[eSatipFrontendDVBT2].Matches(transponderP); + result = frontendsM[eSatipFrontendDVBT].Matches(deviceIdP, transponderP) || frontendsM[eSatipFrontendDVBT2].Matches(deviceIdP, transponderP); } else if (cSource::IsType(sourceP, 'C')) { if (systemP) - result = frontendsM[eSatipFrontendDVBC2].Matches(transponderP); + result = frontendsM[eSatipFrontendDVBC2].Matches(deviceIdP, transponderP); else - result = frontendsM[eSatipFrontendDVBC].Matches(transponderP) || frontendsM[eSatipFrontendDVBC2].Matches(transponderP); + result = frontendsM[eSatipFrontendDVBC].Matches(deviceIdP, transponderP) || frontendsM[eSatipFrontendDVBC2].Matches(deviceIdP, transponderP); } return result; } -void cSatipServer::Use(int transponderP, bool onOffP) +void cSatipServer::Attach(int deviceIdP, int transponderP) { for (int i = 0; i < eSatipFrontendCount; ++i) { - if (frontendsM[i].Use(transponderP, onOffP)) + if (frontendsM[i].Attach(deviceIdP, transponderP)) + return; + } +} + +void cSatipServer::Detach(int deviceIdP, int transponderP) +{ + for (int i = 0; i < eSatipFrontendCount; ++i) { + if (frontendsM[i].Detach(deviceIdP, transponderP)) return; } } @@ -260,14 +280,14 @@ cSatipServer *cSatipServers::Find(int sourceP) return NULL; } -cSatipServer *cSatipServers::Assign(int sourceP, int transponderP, int systemP) +cSatipServer *cSatipServers::Assign(int deviceIdP, int sourceP, int transponderP, int systemP) { for (cSatipServer *s = First(); s; s = Next(s)) { - if (s->Matches(sourceP, systemP, transponderP)) + if (s->Matches(deviceIdP, sourceP, systemP, transponderP)) return s; } for (cSatipServer *s = First(); s; s = Next(s)) { - if (s->Assign(sourceP, systemP, transponderP)) + if (s->Assign(deviceIdP, sourceP, systemP, transponderP)) return s; } return NULL; @@ -284,11 +304,21 @@ cSatipServer *cSatipServers::Update(cSatipServer *serverP) return NULL; } -void cSatipServers::Use(cSatipServer *serverP, int transponderP, bool onOffP) +void cSatipServers::Attach(cSatipServer *serverP, int deviceIdP, int transponderP) { for (cSatipServer *s = First(); s; s = Next(s)) { if (s == serverP) { - s->Use(transponderP, onOffP); + s->Attach(deviceIdP, transponderP); + break; + } + } +} + +void cSatipServers::Detach(cSatipServer *serverP, int deviceIdP, int transponderP) +{ + for (cSatipServer *s = First(); s; s = Next(s)) { + if (s == serverP) { + s->Detach(deviceIdP, transponderP); break; } } diff --git a/server.h b/server.h index cdd70e8..59f003d 100644 --- a/server.h +++ b/server.h @@ -16,15 +16,16 @@ class cSatipFrontend : public cListObject { private: int indexM; int transponderM; + int deviceIdM; cString descriptionM; - bool usedM; public: cSatipFrontend(const int indexP, const char *descriptionP); virtual ~cSatipFrontend(); - void Use(bool onOffP) { usedM = onOffP; } + void Attach(int deviceIdP) { deviceIdM = deviceIdP; } + void Detach(int deviceIdP) { if (deviceIdP == deviceIdM) deviceIdM = -1; } cString Description(void) { return descriptionM; } - bool IsUsed(void) { return usedM; } + bool Attached(void) { return (deviceIdM >= 0); } int Index(void) { return indexM; } int Transponder(void) { return transponderM; } void SetTransponder(int transponderP) { transponderM = transponderP; } @@ -34,9 +35,10 @@ public: class cSatipFrontends : public cList { public: - bool Matches(int transponderP); - bool Assign(int transponderP); - bool Use(int transponderP, bool onOffP); + bool Matches(int deviceIdP, int transponderP); + bool Assign(int deviceIdP, int transponderP); + bool Attach(int deviceIdP, int transponderP); + bool Detach(int deviceIdP, int transponderP); }; // --- cSatipServer ----------------------------------------------------------- @@ -72,10 +74,11 @@ public: cSatipServer(const char *addressP, const char *modelP, const char *descriptionP); virtual ~cSatipServer(); virtual int Compare(const cListObject &listObjectP) const; - bool Assign(int sourceP, int systemP, int transponderP); + bool Assign(int deviceIdP, int sourceP, int systemP, int transponderP); bool Matches(int sourceP); - bool Matches(int sourceP, int systemP, int transponderP); - void Use(int transponderP, bool onOffP); + bool Matches(int deviceIdP, int sourceP, int systemP, int transponderP); + void Attach(int deviceIdP, int transponderP); + void Detach(int deviceIdP, int transponderP); int GetModulesDVBS2(void); int GetModulesDVBT(void); int GetModulesDVBT2(void); @@ -99,9 +102,10 @@ class cSatipServers : public cList { public: cSatipServer *Find(cSatipServer *serverP); cSatipServer *Find(int sourceP); - cSatipServer *Assign(int sourceP, int transponderP, int systemP); + cSatipServer *Assign(int deviceIdP, int sourceP, int transponderP, int systemP); cSatipServer *Update(cSatipServer *serverP); - void Use(cSatipServer *serverP, int transponderP, bool onOffP); + void Attach(cSatipServer *serverP, int deviceIdP, int transponderP); + void Detach(cSatipServer *serverP, int deviceIdP, int transponderP); bool IsQuirk(cSatipServer *serverP, int quirkP); bool HasCI(cSatipServer *serverP); void Cleanup(uint64_t intervalMsP = 0); diff --git a/tuner.c b/tuner.c index f861ced..c498158 100644 --- a/tuner.c +++ b/tuner.c @@ -25,8 +25,8 @@ cSatipTuner::cSatipTuner(cSatipDeviceIf &deviceP, unsigned int packetLenP) rtcpM(*this), streamAddrM(""), streamParamM(""), - currentServerM(NULL, 0), - nextServerM(NULL, 0), + currentServerM(NULL, deviceP.GetId(), 0), + nextServerM(NULL, deviceP.GetId(), 0), mutexM(), reConnectM(), keepAliveM(), @@ -205,7 +205,7 @@ bool cSatipTuner::Connect(void) currentServerM = nextServerM; nextServerM.Reset(); } - currentServerM.Use(true); + currentServerM.Attach(); return true; } } @@ -237,7 +237,7 @@ bool cSatipTuner::Disconnect(void) signalQualityM = -1; frontendIdM = -1; - currentServerM.Use(false); + currentServerM.Detach(); statusUpdateM.Set(0); timeoutM = eMinKeepAliveIntervalMs; pmtPidM = -1; diff --git a/tuner.h b/tuner.h index f471eaa..8ef0beb 100644 --- a/tuner.h +++ b/tuner.h @@ -53,21 +53,23 @@ class cSatipTunerServer { private: cSatipServer *serverM; + int deviceIdM; int transponderM; public: - cSatipTunerServer(cSatipServer *serverP, const int transponderP) : serverM(serverP), transponderM(transponderP) {} + cSatipTunerServer(cSatipServer *serverP, const int deviceIdP, const int transponderP) : serverM(serverP), deviceIdM(deviceIdP), transponderM(transponderP) {} ~cSatipTunerServer() {} - cSatipTunerServer(const cSatipTunerServer &objP) { serverM = NULL; transponderM = 0; } - cSatipTunerServer& operator= (const cSatipTunerServer &objP) { serverM = objP.serverM; transponderM = objP.transponderM; return *this; } + cSatipTunerServer(const cSatipTunerServer &objP) { serverM = NULL; deviceIdM = -1; transponderM = 0; } + cSatipTunerServer& operator= (const cSatipTunerServer &objP) { serverM = objP.serverM; deviceIdM = objP.deviceIdM; transponderM = objP.transponderM; return *this; } bool IsValid(void) { return !!serverM; } bool IsQuirk(int quirkP) { return (serverM && cSatipDiscover::GetInstance()->IsServerQuirk(serverM, quirkP)); } bool HasCI(void) { return (serverM && cSatipDiscover::GetInstance()->HasServerCI(serverM)); } - void Use(bool onOffP) { if (serverM) cSatipDiscover::GetInstance()->UseServer(serverM, transponderM, onOffP); } + void Attach(void) { if (serverM) cSatipDiscover::GetInstance()->AttachServer(serverM, deviceIdM, transponderM); } + void Detach(void) { if (serverM) cSatipDiscover::GetInstance()->DetachServer(serverM, deviceIdM, transponderM); } void Set(cSatipServer *serverP, const int transponderP) { serverM = serverP; transponderM = transponderP; } void Reset(void) { serverM = NULL; transponderM = 0; } cString GetAddress(void) { return serverM ? cSatipDiscover::GetInstance()->GetServerAddress(serverM) : ""; } - cString GetInfo(void) { return cString::sprintf("server=%s transponder=%d", serverM ? "assigned" : "null", transponderM); } + cString GetInfo(void) { return cString::sprintf("server=%s deviceid=%d transponder=%d", serverM ? "assigned" : "null", deviceIdM, transponderM); } }; class cSatipTuner : public cThread, public cSatipTunerStatistics, public cSatipTunerIf