summaryrefslogtreecommitdiff
path: root/p2pvr/daemon/globalDevices.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'p2pvr/daemon/globalDevices.cpp')
-rw-r--r--p2pvr/daemon/globalDevices.cpp86
1 files changed, 86 insertions, 0 deletions
diff --git a/p2pvr/daemon/globalDevices.cpp b/p2pvr/daemon/globalDevices.cpp
new file mode 100644
index 0000000..4368cea
--- /dev/null
+++ b/p2pvr/daemon/globalDevices.cpp
@@ -0,0 +1,86 @@
+#include <pch.hpp>
+#include "globalDevices.h"
+#include <Ice/Ice.h>
+
+std::vector<std::string> GlobalDevices::Devices;
+
+DECLARE_OPTIONS(GlobalDevices, "P2PVR Devices")
+("p2pvr.globaldevices.carddaemon",
+ Options::functions(
+ [](const VariableType & df) { Devices.push_back(df); },
+ []{ Devices.clear(); }),
+ "ICE address of remote device pools (<adapter>:<endpoint>)")
+END_OPTIONS(GlobalDevices);
+
+P2PVR::TunerPrx
+GlobalDevices::GetTunerSpecific(const DVBSI::DeliveryPtr & delivery, const Ice::Current & ice)
+{
+ auto ic = ice.adapter->getCommunicator();
+ BOOST_FOREACH(const auto & pool, Devices) {
+ try {
+ auto poolprx = P2PVR::DevicesPrx::checkedCast(ic->stringToProxy(pool));
+ return poolprx->GetTunerSpecific(delivery);
+ }
+ catch (...) {
+ }
+ }
+ throw P2PVR::NoSuitableDeviceAvailable();
+}
+
+P2PVR::TunerPrx
+GlobalDevices::GetTunerAny(short type, const DVBSI::DeliveryPtr & delivery, const Ice::Current & ice)
+{
+ auto ic = ice.adapter->getCommunicator();
+ BOOST_FOREACH(const auto & pool, Devices) {
+ try {
+ auto poolprx = P2PVR::DevicesPrx::checkedCast(ic->stringToProxy(pool));
+ return poolprx->GetTunerAny(type, delivery);
+ }
+ catch (...) {
+ }
+ }
+ throw P2PVR::NoSuitableDeviceAvailable();
+}
+
+P2PVR::PrivateTunerPrx
+GlobalDevices::GetPrivateTuner(short type, const Ice::Current & ice)
+{
+ auto ic = ice.adapter->getCommunicator();
+ BOOST_FOREACH(const auto & pool, Devices) {
+ try {
+ auto poolprx = P2PVR::DevicesPrx::checkedCast(ic->stringToProxy(pool));
+ return poolprx->GetPrivateTuner(type);
+ }
+ catch (...) {
+ }
+ }
+ throw P2PVR::NoSuitableDeviceAvailable();
+}
+
+void
+GlobalDevices::ReleaseTuner(const P2PVR::TunerPrx & tuner, const Ice::Current & ice)
+{
+ auto ic = ice.adapter->getCommunicator();
+ BOOST_FOREACH(const auto & pool, Devices) {
+ auto poolprx = P2PVR::DevicesPrx::checkedCast(ic->stringToProxy(pool));
+ poolprx->ReleaseTuner(tuner);
+ }
+}
+
+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;
+}
+