+bool eDVBResourceManager::canAllocateFrontend(ePtr<iDVBFrontendParameters> &feparm)
+{
+ ePtr<eDVBRegisteredFrontend> best;
+ int bestval = 0;
+
+ for (eSmartPtrList<eDVBRegisteredFrontend>::iterator i(m_frontend.begin()); i != m_frontend.end(); ++i)
+ if (!i->m_inuse)
+ {
+ int c = i->m_frontend->isCompatibleWith(feparm);
+ if (c > bestval)
+ bestval = c;
+ }
+
+ return bestval>0;
+}
+
+bool eDVBResourceManager::canAllocateChannel(const eDVBChannelID &channelid, const eDVBChannelID& ignore)
+{
+ /* first, check if a channel is already existing. */
+// eDebug("allocate channel.. %04x:%04x", channelid.transport_stream_id.get(), channelid.original_network_id.get());
+ for (std::list<active_channel>::iterator i(m_active_channels.begin()); i != m_active_channels.end(); ++i)
+ {
+// eDebug("available channel.. %04x:%04x", i->m_channel_id.transport_stream_id.get(), i->m_channel_id.original_network_id.get());
+ if (i->m_channel_id == channelid)
+ {
+// eDebug("found shared channel..");
+ return true;
+ }
+ }
+
+ int *decremented_fe_usecount=NULL;
+
+ for (std::list<active_channel>::iterator i(m_active_channels.begin()); i != m_active_channels.end(); ++i)
+ {
+// eDebug("available channel.. %04x:%04x", i->m_channel_id.transport_stream_id.get(), i->m_channel_id.original_network_id.get());
+ if (i->m_channel_id == ignore)
+ {
+ eDVBChannel *channel = (eDVBChannel*) &(*i->m_channel);
+ if (channel == &(*m_cached_channel) ? channel->getUseCount() == 2 : channel->getUseCount() == 1) // channel only used once..
+ {
+ ePtr<iDVBFrontend> fe;
+ if (!i->m_channel->getFrontend(fe))
+ {
+ for (eSmartPtrList<eDVBRegisteredFrontend>::iterator ii(m_frontend.begin()); ii != m_frontend.end(); ++ii)
+ {
+ if ( &(*fe) == &(*ii->m_frontend) )
+ {
+ --ii->m_inuse;
+ decremented_fe_usecount = &ii->m_inuse;
+ break;
+ }
+ }
+ }
+ }
+ break;
+ }
+ }
+
+ if (!m_list)
+ {
+ eDebug("no channel list set!");
+ return false;
+ }
+
+ ePtr<iDVBFrontendParameters> feparm;
+ if (m_list->getChannelFrontendData(channelid, feparm))
+ {
+ eDebug("channel not found!");
+ return false;
+ }
+
+ bool ret = canAllocateFrontend(feparm);
+
+ if (decremented_fe_usecount)
+ ++(*decremented_fe_usecount);
+
+ return ret;
+}
+