From 9bb13e962d591e2e143eb956e870e4238fff5b3a Mon Sep 17 00:00:00 2001 From: randomdan Date: Tue, 10 Dec 2013 22:19:15 +0000 Subject: Extend interface to support getting a tuner device count --- p2pvr/ice/p2pvr.ice | 2 ++ p2pvr/lib/globalDevices.cpp | 17 +++++++++++++++++ p2pvr/lib/globalDevices.h | 1 + p2pvr/lib/localDevices.cpp | 7 +++++++ p2pvr/lib/localDevices.h | 1 + 5 files changed, 28 insertions(+) diff --git a/p2pvr/ice/p2pvr.ice b/p2pvr/ice/p2pvr.ice index 8835511..1db9cf3 100644 --- a/p2pvr/ice/p2pvr.ice +++ b/p2pvr/ice/p2pvr.ice @@ -232,6 +232,8 @@ module P2PVR { PrivateTuner * GetPrivateTuner(short type, long until); // Release a tuner when no longer required. idempotent void ReleaseTuner(Tuner * t); + // Count available tuners + idempotent int TunerCount(); }; interface LocalDevices extends Devices { diff --git a/p2pvr/lib/globalDevices.cpp b/p2pvr/lib/globalDevices.cpp index 8dfe77d..a21fe1f 100644 --- a/p2pvr/lib/globalDevices.cpp +++ b/p2pvr/lib/globalDevices.cpp @@ -57,3 +57,20 @@ GlobalDevices::ReleaseTuner(const P2PVR::TunerPrx & tuner, const Ice::Current & } } +int +GlobalDevices::TunerCount(const Ice::Current & ice) +{ + int total = 0; + auto ic = ice.adapter->getCommunicator(); + BOOST_FOREACH(const auto & pool, Devices) { + try { + auto poolprx = P2PVR::DevicesPrx::checkedCast(ic->stringToProxy(pool)); + total += poolprx->TunerCount(); + } + catch (...) { + // Not available, don't count 'em + } + } + return total; +} + diff --git a/p2pvr/lib/globalDevices.h b/p2pvr/lib/globalDevices.h index 0cf9636..8f2acd9 100644 --- a/p2pvr/lib/globalDevices.h +++ b/p2pvr/lib/globalDevices.h @@ -13,6 +13,7 @@ class GlobalDevices : public P2PVR::Devices { 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 &); void ReleaseTuner(const P2PVR::TunerPrx &, const Ice::Current &); + int TunerCount(const Ice::Current &); INITOPTIONS; private: diff --git a/p2pvr/lib/localDevices.cpp b/p2pvr/lib/localDevices.cpp index 5bb2b61..51eed31 100644 --- a/p2pvr/lib/localDevices.cpp +++ b/p2pvr/lib/localDevices.cpp @@ -153,6 +153,13 @@ LocalDevices::ReleaseTuner(const P2PVR::TunerPrx & tuner, const Ice::Current & i } } +int +LocalDevices::TunerCount(const Ice::Current &) +{ + std::lock_guard g(lock); + return devices.size(); +} + void LocalDevices::Scan(const Ice::Current &) { diff --git a/p2pvr/lib/localDevices.h b/p2pvr/lib/localDevices.h index 9e62525..7185dde 100644 --- a/p2pvr/lib/localDevices.h +++ b/p2pvr/lib/localDevices.h @@ -17,6 +17,7 @@ class LocalDevices : public P2PVR::LocalDevices { 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 &); void ReleaseTuner(const P2PVR::TunerPrx &, const Ice::Current &); + int TunerCount(const Ice::Current &); void Scan(const Ice::Current &); void Add(const std::string & frontend, const Ice::Current &); -- cgit v1.2.3