From: Felix Domke Date: Tue, 12 Jul 2005 14:00:01 +0000 (+0000) Subject: - add eUsePtr for eDVBChannels X-Git-Tag: 2.6.0~5811 X-Git-Url: https://git.cweiske.de/enigma2.git/commitdiff_plain/e39c12fcbf218f0964782a48d6e66145e1ce5039 - add eUsePtr for eDVBChannels --- diff --git a/lib/base/smartptr.h b/lib/base/smartptr.h index 159eeb2c..7e441ab2 100644 --- a/lib/base/smartptr.h +++ b/lib/base/smartptr.h @@ -66,6 +66,81 @@ public: }; +template +class eUsePtr +{ +protected: + T *ptr; +public: + T &operator*() { return *ptr; } + eUsePtr(): ptr(0) + { + } + eUsePtr(T *c): ptr(c) + { + if (c) + { + c->AddRef(); + c->AddUse(); + } + } + eUsePtr(const eUsePtr &c) + { + ptr=c.ptr; + if (ptr) + { + ptr->AddRef(); + ptr->AddUse(); + } + } + eUsePtr &operator=(T *c) + { + if (c) + { + c->AddRef(); + c->AddUse(); + } + if (ptr) + { + ptr->ReleaseUse(); + ptr->Release(); + } + ptr=c; + return *this; + } + + eUsePtr &operator=(eUsePtr &c) + { + if (c.ptr) + { + c.ptr->AddRef(); + c.ptr->AddUse(); + } + if (ptr) + { + ptr->ReleaseUse(); + ptr->Release(); + } + ptr=c.ptr; + return *this; + } + + ~eUsePtr() + { + if (ptr) + { + ptr->ReleaseUse(); + ptr->Release(); + } + } + + T* grabRef() { if (!ptr) return 0; ptr->AddRef(); ptr->AddUse(); return ptr; } + T* &ptrref() { assert(!ptr); return ptr; } + T* operator->() const { assert(ptr); return ptr; } + operator T*() const { return this->ptr; } +}; + + #ifndef SWIG template diff --git a/lib/components/scan.cpp b/lib/components/scan.cpp index c46bb4a8..cfbff6d8 100644 --- a/lib/components/scan.cpp +++ b/lib/components/scan.cpp @@ -86,7 +86,7 @@ int eComponentScan::start() fet.hierarchy = eDVBFrontendParametersTerrestrial::Hierarchy::HNone; fe->setDVBT(fet); #endif - ePtr channel; + eUsePtr channel; if (mgr->allocateRawChannel(channel)) { diff --git a/lib/dvb/dvb.cpp b/lib/dvb/dvb.cpp index f1f5580a..35849b4c 100644 --- a/lib/dvb/dvb.cpp +++ b/lib/dvb/dvb.cpp @@ -240,7 +240,7 @@ RESULT eDVBResourceManager::getChannelList(ePtr &list) } -RESULT eDVBResourceManager::allocateChannel(const eDVBChannelID &channelid, ePtr &channel) +RESULT eDVBResourceManager::allocateChannel(const eDVBChannelID &channelid, eUsePtr &channel) { /* first, check if a channel is already existing. */ @@ -289,7 +289,7 @@ RESULT eDVBResourceManager::allocateChannel(const eDVBChannelID &channelid, ePtr return 0; } -RESULT eDVBResourceManager::allocateRawChannel(ePtr &channel) +RESULT eDVBResourceManager::allocateRawChannel(eUsePtr &channel) { ePtr fe; @@ -383,6 +383,11 @@ void eDVBChannel::frontendStateChanged(iDVBFrontend*fe) { eDebug("fe state changed!"); int state, ourstate = 0; + + /* if we are already in shutdown, don't change state. */ + if (m_state == state_release) + return; + if (fe->getState(state)) return; @@ -408,6 +413,20 @@ void eDVBChannel::frontendStateChanged(iDVBFrontend*fe) } } +void eDVBChannel::AddUse() +{ + ++m_use_count; +} + +void eDVBChannel::ReleaseUse() +{ + if (!--m_use_count) + { + m_state = state_release; + m_stateChanged(this); + } +} + RESULT eDVBChannel::setChannel(const eDVBChannelID &channelid) { if (m_channel_id) diff --git a/lib/dvb/dvb.h b/lib/dvb/dvb.h index 34c55492..bb9e2689 100644 --- a/lib/dvb/dvb.h +++ b/lib/dvb/dvb.h @@ -156,8 +156,8 @@ public: }; /* allocate channel... */ - RESULT allocateChannel(const eDVBChannelID &channelid, ePtr &channel); - RESULT allocateRawChannel(ePtr &channel); + RESULT allocateChannel(const eDVBChannelID &channelid, eUsePtr &channel); + RESULT allocateRawChannel(eUsePtr &channel); RESULT allocatePVRChannel(int caps); RESULT connectChannelAdded(const Slot1 &channelAdded, ePtr &connection); @@ -182,6 +182,11 @@ private: void frontendStateChanged(iDVBFrontend*fe); ePtr m_conn_frontendStateChanged; + + /* use count */ + oRefCount m_use_count; + void AddUse(); + void ReleaseUse(); public: eDVBChannel(eDVBResourceManager *mgr, eDVBAllocatedFrontend *frontend, eDVBAllocatedDemux *demux); virtual ~eDVBChannel(); diff --git a/lib/dvb/pmt.h b/lib/dvb/pmt.h index 136c1673..d86d1ac9 100644 --- a/lib/dvb/pmt.h +++ b/lib/dvb/pmt.h @@ -18,7 +18,7 @@ class eDVBServicePMTHandler: public Object eAUTable > m_PMT; eAUTable > m_PAT; - ePtr m_channel; + eUsePtr m_channel; ePtr m_resourceManager; ePtr m_demux; diff --git a/lib/dvb/scan.h b/lib/dvb/scan.h index bfd3add9..fb6b56f4 100644 --- a/lib/dvb/scan.h +++ b/lib/dvb/scan.h @@ -20,7 +20,7 @@ private: eDVBNamespace buildNamespace(eOriginalNetworkID onid, eTransportStreamID tsid, unsigned long hash); /* scan resources */ - ePtr m_channel; + eUsePtr m_channel; ePtr m_demux; /* infrastructure */