};
+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>
fet.hierarchy = eDVBFrontendParametersTerrestrial::Hierarchy::HNone;
fe->setDVBT(fet);
#endif
- ePtr<iDVBChannel> channel;
+ eUsePtr<iDVBChannel> channel;
if (mgr->allocateRawChannel(channel))
{
}
-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. */
return 0;
}
-RESULT eDVBResourceManager::allocateRawChannel(ePtr<iDVBChannel> &channel)
+RESULT eDVBResourceManager::allocateRawChannel(eUsePtr<iDVBChannel> &channel)
{
ePtr<eDVBAllocatedFrontend> 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;
}
}
+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)
};
/* 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);
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();
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;
eDVBNamespace buildNamespace(eOriginalNetworkID onid, eTransportStreamID tsid, unsigned long hash);
/* scan resources */
- ePtr<iDVBChannel> m_channel;
+ eUsePtr<iDVBChannel> m_channel;
ePtr<iDVBDemux> m_demux;
/* infrastructure */