diff options
| author | Felix Domke <tmbinc@elitedvb.net> | 2005-07-12 14:00:01 +0000 |
|---|---|---|
| committer | Felix Domke <tmbinc@elitedvb.net> | 2005-07-12 14:00:01 +0000 |
| commit | e39c12fcbf218f0964782a48d6e66145e1ce5039 (patch) | |
| tree | 24e8efbaa96d7c180fd750a38078fbc19c066eae | |
| parent | 98c4b5bb004e9297bffa8e1c3572572741fda933 (diff) | |
| download | enigma2-e39c12fcbf218f0964782a48d6e66145e1ce5039.tar.gz enigma2-e39c12fcbf218f0964782a48d6e66145e1ce5039.zip | |
- add eUsePtr for eDVBChannels
| -rw-r--r-- | lib/base/smartptr.h | 75 | ||||
| -rw-r--r-- | lib/components/scan.cpp | 2 | ||||
| -rw-r--r-- | lib/dvb/dvb.cpp | 23 | ||||
| -rw-r--r-- | lib/dvb/dvb.h | 9 | ||||
| -rw-r--r-- | lib/dvb/pmt.h | 2 | ||||
| -rw-r--r-- | lib/dvb/scan.h | 2 |
6 files changed, 106 insertions, 7 deletions
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 T> +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<T> &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<class T> 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<iDVBChannel> channel; + eUsePtr<iDVBChannel> 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<iDVBChannelList> &list) } -RESULT eDVBResourceManager::allocateChannel(const eDVBChannelID &channelid, ePtr<iDVBChannel> &channel) +RESULT eDVBResourceManager::allocateChannel(const eDVBChannelID &channelid, eUsePtr<iDVBChannel> &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<iDVBChannel> &channel) +RESULT eDVBResourceManager::allocateRawChannel(eUsePtr<iDVBChannel> &channel) { ePtr<eDVBAllocatedFrontend> 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<iDVBChannel> &channel); - RESULT allocateRawChannel(ePtr<iDVBChannel> &channel); + RESULT allocateChannel(const eDVBChannelID &channelid, eUsePtr<iDVBChannel> &channel); + RESULT allocateRawChannel(eUsePtr<iDVBChannel> &channel); RESULT allocatePVRChannel(int caps); RESULT connectChannelAdded(const Slot1<void,eDVBChannel*> &channelAdded, ePtr<eConnection> &connection); @@ -182,6 +182,11 @@ private: void frontendStateChanged(iDVBFrontend*fe); ePtr<eConnection> 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<eTable<ProgramMapTable> > m_PMT; eAUTable<eTable<ProgramAssociationTable> > m_PAT; - ePtr<iDVBChannel> m_channel; + eUsePtr<iDVBChannel> m_channel; ePtr<eDVBResourceManager> m_resourceManager; ePtr<iDVBDemux> 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<iDVBChannel> m_channel; + eUsePtr<iDVBChannel> m_channel; ePtr<iDVBDemux> m_demux; /* infrastructure */ |
