diff options
author | randomdan <randomdan@localhost> | 2014-01-13 19:06:53 +0000 |
---|---|---|
committer | randomdan <randomdan@localhost> | 2014-01-13 19:06:53 +0000 |
commit | d3383e74b2cea6f9d5a62016691fb41043c2d974 (patch) | |
tree | 7b886b910130a56aa2ca084901e371a7f71faedd | |
parent | Basic implementation of a recorder (diff) | |
download | p2pvr-d3383e74b2cea6f9d5a62016691fb41043c2d974.tar.bz2 p2pvr-d3383e74b2cea6f9d5a62016691fb41043c2d974.tar.xz p2pvr-d3383e74b2cea6f9d5a62016691fb41043c2d974.zip |
Remove junk for estimating device usage
Throw exception when no devices are available, don't return null
Don't iterate all transponders when getting network details
-rw-r--r-- | p2pvr/ice/dvb.ice | 10 | ||||
-rw-r--r-- | p2pvr/lib/globalDevices.cpp | 39 | ||||
-rw-r--r-- | p2pvr/lib/globalDevices.h | 6 | ||||
-rw-r--r-- | p2pvr/lib/localDevices.cpp | 23 | ||||
-rw-r--r-- | p2pvr/lib/localDevices.h | 9 | ||||
-rw-r--r-- | p2pvr/lib/maintenance/events.cpp | 2 | ||||
-rw-r--r-- | p2pvr/lib/maintenance/network.cpp | 21 | ||||
-rw-r--r-- | p2pvr/lib/maintenance/programAssociations.cpp | 2 | ||||
-rw-r--r-- | p2pvr/lib/maintenance/programMap.cpp | 2 | ||||
-rw-r--r-- | p2pvr/lib/maintenance/services.cpp | 2 | ||||
-rw-r--r-- | p2pvr/lib/serviceStreamer.cpp | 2 |
11 files changed, 61 insertions, 57 deletions
diff --git a/p2pvr/ice/dvb.ice b/p2pvr/ice/dvb.ice index d52c190..93dcd9b 100644 --- a/p2pvr/ice/dvb.ice +++ b/p2pvr/ice/dvb.ice @@ -9,6 +9,7 @@ module P2PVR { string Message; int Errno; }; + exception IncorrectDeliveryType { }; sequence<byte> Data; @@ -33,18 +34,21 @@ module P2PVR { int StartSendingSection(int pid, RawDataClient * client); idempotent void StopSending(int handle); }; + interface PrivateTuner extends Tuner { idempotent void TuneTo(DVBSI::Delivery d) throws DeviceError; idempotent void ScanAndSendNetworkInformation(RawDataClient * client) throws DeviceError; }; + exception NoSuitableDeviceAvailable { }; + interface Devices { // Get a tuner that is tuned to <del>, acquire and tune to <del> if required. - Tuner * GetTunerSpecific(DVBSI::Delivery del, long until); + Tuner * GetTunerSpecific(DVBSI::Delivery del); // Get any tuner that is tuned, acquire and tune to <del> if required. - Tuner * GetTunerAny(short type, DVBSI::Delivery del, long until); + Tuner * GetTunerAny(short type, DVBSI::Delivery del); // Get a private tuner, not shared or sharable - PrivateTuner * GetPrivateTuner(short type, long until); + PrivateTuner * GetPrivateTuner(short type); // Release a tuner when no longer required. idempotent void ReleaseTuner(Tuner * t); // Count available tuners diff --git a/p2pvr/lib/globalDevices.cpp b/p2pvr/lib/globalDevices.cpp index c99fcea..4368cea 100644 --- a/p2pvr/lib/globalDevices.cpp +++ b/p2pvr/lib/globalDevices.cpp @@ -13,39 +13,48 @@ DECLARE_OPTIONS(GlobalDevices, "P2PVR Devices") END_OPTIONS(GlobalDevices); P2PVR::TunerPrx -GlobalDevices::GetTunerSpecific(const DVBSI::DeliveryPtr & delivery, Ice::Long until, const Ice::Current & ice) +GlobalDevices::GetTunerSpecific(const DVBSI::DeliveryPtr & delivery, const Ice::Current & ice) { auto ic = ice.adapter->getCommunicator(); BOOST_FOREACH(const auto & pool, Devices) { - auto poolprx = P2PVR::DevicesPrx::checkedCast(ic->stringToProxy(pool)); - auto tuner = poolprx->GetTunerSpecific(delivery, until); - if (tuner) return tuner; + try { + auto poolprx = P2PVR::DevicesPrx::checkedCast(ic->stringToProxy(pool)); + return poolprx->GetTunerSpecific(delivery); + } + catch (...) { + } } - return NULL; + throw P2PVR::NoSuitableDeviceAvailable(); } P2PVR::TunerPrx -GlobalDevices::GetTunerAny(short type, const DVBSI::DeliveryPtr & delivery, Ice::Long until, const Ice::Current & ice) +GlobalDevices::GetTunerAny(short type, const DVBSI::DeliveryPtr & delivery, const Ice::Current & ice) { auto ic = ice.adapter->getCommunicator(); BOOST_FOREACH(const auto & pool, Devices) { - auto poolprx = P2PVR::DevicesPrx::checkedCast(ic->stringToProxy(pool)); - auto tuner = poolprx->GetTunerAny(type, delivery, until); - if (tuner) return tuner; + try { + auto poolprx = P2PVR::DevicesPrx::checkedCast(ic->stringToProxy(pool)); + return poolprx->GetTunerAny(type, delivery); + } + catch (...) { + } } - return NULL; + throw P2PVR::NoSuitableDeviceAvailable(); } P2PVR::PrivateTunerPrx -GlobalDevices::GetPrivateTuner(short type, Ice::Long until, const Ice::Current & ice) +GlobalDevices::GetPrivateTuner(short type, const Ice::Current & ice) { auto ic = ice.adapter->getCommunicator(); BOOST_FOREACH(const auto & pool, Devices) { - auto poolprx = P2PVR::DevicesPrx::checkedCast(ic->stringToProxy(pool)); - auto tuner = poolprx->GetPrivateTuner(type, until); - if (tuner) return tuner; + try { + auto poolprx = P2PVR::DevicesPrx::checkedCast(ic->stringToProxy(pool)); + return poolprx->GetPrivateTuner(type); + } + catch (...) { + } } - return NULL; + throw P2PVR::NoSuitableDeviceAvailable(); } void diff --git a/p2pvr/lib/globalDevices.h b/p2pvr/lib/globalDevices.h index 39b0677..da27c95 100644 --- a/p2pvr/lib/globalDevices.h +++ b/p2pvr/lib/globalDevices.h @@ -9,9 +9,9 @@ class GlobalDevices : public P2PVR::Devices { public: - P2PVR::TunerPrx GetTunerSpecific(const DVBSI::DeliveryPtr &, Ice::Long until, const Ice::Current &); - P2PVR::TunerPrx GetTunerAny(short type, const DVBSI::DeliveryPtr &, Ice::Long until, const Ice::Current &); - P2PVR::PrivateTunerPrx GetPrivateTuner(short type, Ice::Long until, const Ice::Current &); + P2PVR::TunerPrx GetTunerSpecific(const DVBSI::DeliveryPtr &, const Ice::Current &); + P2PVR::TunerPrx GetTunerAny(short type, const DVBSI::DeliveryPtr &, const Ice::Current &); + P2PVR::PrivateTunerPrx GetPrivateTuner(short type, const Ice::Current &); void ReleaseTuner(const P2PVR::TunerPrx &, const Ice::Current &); int TunerCount(const Ice::Current &); diff --git a/p2pvr/lib/localDevices.cpp b/p2pvr/lib/localDevices.cpp index 975af20..7a43a15 100644 --- a/p2pvr/lib/localDevices.cpp +++ b/p2pvr/lib/localDevices.cpp @@ -47,7 +47,7 @@ LocalDevices::ClientCheck(Ice::ObjectAdapterPtr adapter) } P2PVR::TunerPrx -LocalDevices::GetTunerSpecific(const DVBSI::DeliveryPtr & delivery, Ice::Long until, const Ice::Current & ice) +LocalDevices::GetTunerSpecific(const DVBSI::DeliveryPtr & delivery, const Ice::Current & ice) { std::lock_guard<std::mutex> g(lock); Logger()->messagebf(LOG_DEBUG, "%s: Searching for an open sharable tuner (frequency %d)", __PRETTY_FUNCTION__, delivery->Frequency); @@ -55,7 +55,6 @@ LocalDevices::GetTunerSpecific(const DVBSI::DeliveryPtr & delivery, Ice::Long un return ot.second && !ot.second->openedPrivate && ot.second->delivery && ot.second->delivery->Frequency == delivery->Frequency; }); if (openTuner != devices.end()) { - openTuner->second->until = std::max(openTuner->second->until, time(NULL) + until); openTuner->second->clients += 1; return openTuner->second->tuner; } @@ -64,7 +63,7 @@ LocalDevices::GetTunerSpecific(const DVBSI::DeliveryPtr & delivery, Ice::Long un if (openTuner == devices.end()) { Logger()->messagebf(LOG_DEBUG, "%s: None suitable and none free (frequency %d)", __PRETTY_FUNCTION__, delivery->Frequency); - return NULL; + throw P2PVR::NoSuitableDeviceAvailable(); } Logger()->messagebf(LOG_DEBUG, "%s: Opening a sharable tuner (frequency %d, frontend %s)", @@ -72,7 +71,7 @@ LocalDevices::GetTunerSpecific(const DVBSI::DeliveryPtr & delivery, Ice::Long un P2PVR::PrivateTunerPtr t = new Tuner(openTuner->first); t->TuneTo(delivery, ice); auto tuner = P2PVR::PrivateTunerPrx::checkedCast(ice.adapter->addWithUUID(t)); - openTuner->second = OpenTunerPtr(new OpenTuner(delivery, tuner, until, false)); + openTuner->second = OpenTunerPtr(new OpenTuner(delivery, tuner, false)); Logger()->messagebf(LOG_DEBUG, "%s: Tuned, returning (frequency %d, frontend %s)", __PRETTY_FUNCTION__, delivery->Frequency, openTuner->first); @@ -80,7 +79,7 @@ LocalDevices::GetTunerSpecific(const DVBSI::DeliveryPtr & delivery, Ice::Long un } P2PVR::TunerPrx -LocalDevices::GetTunerAny(short , const DVBSI::DeliveryPtr & delivery, Ice::Long until, const Ice::Current & ice) +LocalDevices::GetTunerAny(short , const DVBSI::DeliveryPtr & delivery, const Ice::Current & ice) { std::lock_guard<std::mutex> g(lock); Logger()->messagebf(LOG_DEBUG, "%s: Searching for an open sharable tuner any frequency", __PRETTY_FUNCTION__); @@ -88,7 +87,6 @@ LocalDevices::GetTunerAny(short , const DVBSI::DeliveryPtr & delivery, Ice::Long return ot.second && !ot.second->openedPrivate && ot.second->delivery; }); if (openTuner != devices.end()) { - openTuner->second->until = std::max(openTuner->second->until, time(NULL) + until); openTuner->second->clients += 1; return openTuner->second->tuner; } @@ -97,7 +95,7 @@ LocalDevices::GetTunerAny(short , const DVBSI::DeliveryPtr & delivery, Ice::Long if (openTuner == devices.end()) { Logger()->messagebf(LOG_DEBUG, "%s: None suitable and none free (frequency %d)", __PRETTY_FUNCTION__, delivery->Frequency); - return NULL; + throw P2PVR::NoSuitableDeviceAvailable(); } Logger()->messagebf(LOG_DEBUG, "%s: Opening a sharable tuner (frequency %d, frontend %s)", @@ -105,7 +103,7 @@ LocalDevices::GetTunerAny(short , const DVBSI::DeliveryPtr & delivery, Ice::Long P2PVR::PrivateTunerPtr t = new Tuner(openTuner->first); t->TuneTo(delivery, ice); auto tuner = P2PVR::PrivateTunerPrx::checkedCast(ice.adapter->addWithUUID(t)); - openTuner->second = OpenTunerPtr(new OpenTuner(delivery, tuner, until, false)); + openTuner->second = OpenTunerPtr(new OpenTuner(delivery, tuner, false)); Logger()->messagebf(LOG_DEBUG, "%s: Tuned, returning (frequency %d, frontend %s)", __PRETTY_FUNCTION__, delivery->Frequency, openTuner->first); @@ -113,20 +111,20 @@ LocalDevices::GetTunerAny(short , const DVBSI::DeliveryPtr & delivery, Ice::Long } P2PVR::PrivateTunerPrx -LocalDevices::GetPrivateTuner(short , Ice::Long until, const Ice::Current & ice) +LocalDevices::GetPrivateTuner(short , const Ice::Current & ice) { std::lock_guard<std::mutex> g(lock); Logger()->messagebf(LOG_DEBUG, "%s: Opening a private tuner", __PRETTY_FUNCTION__); auto openTuner = std::find_if(devices.begin(), devices.end(), [](const Devices::value_type & ot) { return !ot.second; }); if (openTuner == devices.end()) { Logger()->messagebf(LOG_DEBUG, "%s: None free", __PRETTY_FUNCTION__); - return NULL; + throw P2PVR::NoSuitableDeviceAvailable(); } Logger()->messagebf(LOG_DEBUG, "%s: Opening a private tuner (frontend %s)", __PRETTY_FUNCTION__, openTuner->first); auto tuner = P2PVR::PrivateTunerPrx::checkedCast(ice.adapter->addWithUUID(new Tuner(openTuner->first))); - openTuner->second = OpenTunerPtr(new OpenTuner(NULL, tuner, until, true)); + openTuner->second = OpenTunerPtr(new OpenTuner(NULL, tuner, true)); return tuner; } @@ -181,11 +179,10 @@ LocalDevices::Remove(const std::string & frontend, const Ice::Current &) devices.erase(frontend); } -LocalDevices::OpenTuner::OpenTuner(DVBSI::DeliveryPtr d, P2PVR::PrivateTunerPrx t, Ice::Long u, bool op) : +LocalDevices::OpenTuner::OpenTuner(DVBSI::DeliveryPtr d, P2PVR::PrivateTunerPrx t, bool op) : openedPrivate(op), delivery(d), tuner(t), - until(u), clients(1) { } diff --git a/p2pvr/lib/localDevices.h b/p2pvr/lib/localDevices.h index 2a23d7e..5521f8d 100644 --- a/p2pvr/lib/localDevices.h +++ b/p2pvr/lib/localDevices.h @@ -13,9 +13,9 @@ class LocalDevices : public P2PVR::LocalDevices { LocalDevices(Ice::ObjectAdapterPtr adapter, IceUtil::TimerPtr); ~LocalDevices(); - P2PVR::TunerPrx GetTunerSpecific(const DVBSI::DeliveryPtr &, Ice::Long until, const Ice::Current &); - P2PVR::TunerPrx GetTunerAny(short type, const DVBSI::DeliveryPtr &, Ice::Long until, const Ice::Current &); - P2PVR::PrivateTunerPrx GetPrivateTuner(short type, Ice::Long until, const Ice::Current &); + P2PVR::TunerPrx GetTunerSpecific(const DVBSI::DeliveryPtr &, const Ice::Current &); + P2PVR::TunerPrx GetTunerAny(short type, const DVBSI::DeliveryPtr &, const Ice::Current &); + P2PVR::PrivateTunerPrx GetPrivateTuner(short type, const Ice::Current &); void ReleaseTuner(const P2PVR::TunerPrx &, const Ice::Current &); int TunerCount(const Ice::Current &); @@ -34,13 +34,12 @@ class LocalDevices : public P2PVR::LocalDevices { class OpenTuner { public: - OpenTuner(DVBSI::DeliveryPtr, P2PVR::PrivateTunerPrx, Ice::Long, bool); + OpenTuner(DVBSI::DeliveryPtr, P2PVR::PrivateTunerPrx, bool); const bool openedPrivate; const DVBSI::DeliveryPtr delivery; const P2PVR::PrivateTunerPrx tuner; - Ice::Long until; unsigned int clients; }; typedef boost::shared_ptr<OpenTuner> OpenTunerPtr; diff --git a/p2pvr/lib/maintenance/events.cpp b/p2pvr/lib/maintenance/events.cpp index 308b726..94bb7ef 100644 --- a/p2pvr/lib/maintenance/events.cpp +++ b/p2pvr/lib/maintenance/events.cpp @@ -55,7 +55,7 @@ class SiEventsMerger : public IHaveSubTasks { } Logger()->messagebf(LOG_DEBUG, "%s: Getting a tuner", __PRETTY_FUNCTION__); - auto tuner = devs->GetTunerAny(type, deliveries.front(), time(NULL) + 600); + auto tuner = devs->GetTunerAny(type, deliveries.front()); Logger()->messagebf(LOG_DEBUG, "%s: Fetching events", __PRETTY_FUNCTION__); tuner->SendEventInformation(parser); devs->ReleaseTuner(tuner); diff --git a/p2pvr/lib/maintenance/network.cpp b/p2pvr/lib/maintenance/network.cpp index e947456..c472899 100644 --- a/p2pvr/lib/maintenance/network.cpp +++ b/p2pvr/lib/maintenance/network.cpp @@ -76,24 +76,19 @@ Maintenance::UpdateNetwork(short type, const Ice::Current & ice) throw std::runtime_error("bad proxy(s)"); } const auto transports = si->GetAllDeliveries(type); - // Attempt to just download fresh data - BOOST_FOREACH(const auto & transport, transports) { + if (!transports.empty()) { + const auto & transport = transports.front(); P2PVR::TunerPrx tuner; try { - tuner = devs->GetTunerAny(type, transport, time(NULL) + 300); - } - catch (...) { - Logger()->messagebf(LOG_WARNING, "%s: Failed to get a suitable tuner", __PRETTY_FUNCTION__); - continue; - } - if (!tuner) { - continue; - } - try { + tuner = devs->GetTunerAny(type, transport); tuner->SendNetworkInformation(parser); devs->ReleaseTuner(tuner); return; } + catch (const P2PVR::NoSuitableDeviceAvailable &) { + Logger()->messagebf(LOG_WARNING, "%s: Failed to get a suitable tuner", __PRETTY_FUNCTION__); + throw; + } catch (const std::exception & ex) { Logger()->messagebf(LOG_WARNING, "%s: Failed to fetch network information: %s", __PRETTY_FUNCTION__, ex.what()); devs->ReleaseTuner(tuner); @@ -106,7 +101,7 @@ Maintenance::UpdateNetwork(short type, const Ice::Current & ice) } } // If we can't do that, do a complete scan - auto tuner = devs->GetPrivateTuner(type, time(NULL) + 300); + auto tuner = devs->GetPrivateTuner(type); tuner->ScanAndSendNetworkInformation(parser); devs->ReleaseTuner(tuner); } diff --git a/p2pvr/lib/maintenance/programAssociations.cpp b/p2pvr/lib/maintenance/programAssociations.cpp index c859684..94a39be 100644 --- a/p2pvr/lib/maintenance/programAssociations.cpp +++ b/p2pvr/lib/maintenance/programAssociations.cpp @@ -55,7 +55,7 @@ Maintenance::UpdateProgramAssociations(short type, const Ice::Current & ice) BOOST_FOREACH(const auto & transport, deliveries) { try { Logger()->messagebf(LOG_DEBUG, "%s: Getting a tuner", __PRETTY_FUNCTION__); - auto tuner = devs->GetTunerSpecific(transport, time(NULL) + 300); + auto tuner = devs->GetTunerSpecific(transport); Logger()->messagebf(LOG_DEBUG, "%s: Fetching associations", __PRETTY_FUNCTION__); tuner->SendProgramAssociationTable(parser); Logger()->messagebf(LOG_INFO, "%s: Updated associations", __PRETTY_FUNCTION__); diff --git a/p2pvr/lib/maintenance/programMap.cpp b/p2pvr/lib/maintenance/programMap.cpp index f219e28..2a2793d 100644 --- a/p2pvr/lib/maintenance/programMap.cpp +++ b/p2pvr/lib/maintenance/programMap.cpp @@ -94,7 +94,7 @@ class SiProgramMapMerger : public IHaveSubTasks { Logger()->messagebf(LOG_DEBUG, "%s: Getting a tuner", __PRETTY_FUNCTION__); const auto transport = *std::find_if(deliveries.begin(), deliveries.end(), [freq](const DVBSI::DeliveryPtr & del) { return del->Frequency == freq; }); - tuner = devs->GetTunerSpecific(transport, time(NULL) + 10); + tuner = devs->GetTunerSpecific(transport); curFreq = freq; } diff --git a/p2pvr/lib/maintenance/services.cpp b/p2pvr/lib/maintenance/services.cpp index 06f2faf..d63ca2a 100644 --- a/p2pvr/lib/maintenance/services.cpp +++ b/p2pvr/lib/maintenance/services.cpp @@ -59,7 +59,7 @@ Maintenance::UpdateServices(short type, const Ice::Current & ice) } Logger()->messagebf(LOG_DEBUG, "%s: Getting a tuner", __PRETTY_FUNCTION__); - auto tuner = devs->GetTunerAny(type, deliveries.front(), time(NULL) + 90); + auto tuner = devs->GetTunerAny(type, deliveries.front()); Logger()->messagebf(LOG_DEBUG, "%s: Fetching service list", __PRETTY_FUNCTION__); tuner->SendServiceDescriptions(parser); Logger()->messagebf(LOG_INFO, "%s: Updated service list", __PRETTY_FUNCTION__); diff --git a/p2pvr/lib/serviceStreamer.cpp b/p2pvr/lib/serviceStreamer.cpp index eacf9c3..f7a7dc2 100644 --- a/p2pvr/lib/serviceStreamer.cpp +++ b/p2pvr/lib/serviceStreamer.cpp @@ -57,7 +57,7 @@ void ServiceStreamer::Start() { const auto transport = si->GetDeliveryForService(serviceId); - tuner = devs->GetTunerSpecific(transport, time(NULL) + 300); + tuner = devs->GetTunerSpecific(transport); patHandle = tuner->StartSendingSection(0, patParser); } |