diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2017-08-07 00:08:54 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2017-08-07 00:08:54 +0100 |
commit | 3e50a4e08541435dfb647be15173cd35ed52cd6c (patch) | |
tree | 3c72e4ed623897b3dc89577443cd19d286b2e7c1 | |
parent | Add ice_print to device error (diff) | |
download | p2pvr-3e50a4e08541435dfb647be15173cd35ed52cd6c.tar.bz2 p2pvr-3e50a4e08541435dfb647be15173cd35ed52cd6c.tar.xz p2pvr-3e50a4e08541435dfb647be15173cd35ed52cd6c.zip |
Have MockDevices extend DevicesI and simply intercept tuner creation with MockTuner
-rw-r--r-- | p2pvr/daemon/unittests/Jamfile.jam | 1 | ||||
-rw-r--r-- | p2pvr/daemon/unittests/mockDevices.cpp | 90 | ||||
-rw-r--r-- | p2pvr/daemon/unittests/mockDevices.h | 22 | ||||
-rw-r--r-- | p2pvr/daemon/unittests/testErrorHandling.cpp | 2 | ||||
-rw-r--r-- | p2pvr/daemon/unittests/testMaint.cpp | 2 | ||||
-rw-r--r-- | p2pvr/daemon/unittests/testRecording.cpp | 2 | ||||
-rw-r--r-- | p2pvr/daemon/unittests/testSched.cpp | 2 | ||||
-rw-r--r-- | p2pvr/devices/devices.cpp | 24 | ||||
-rw-r--r-- | p2pvr/devices/devices.h | 1 | ||||
-rw-r--r-- | p2pvr/devices/mockTuner.cpp | 2 |
10 files changed, 30 insertions, 118 deletions
diff --git a/p2pvr/daemon/unittests/Jamfile.jam b/p2pvr/daemon/unittests/Jamfile.jam index bb39bbb..eb4bf2e 100644 --- a/p2pvr/daemon/unittests/Jamfile.jam +++ b/p2pvr/daemon/unittests/Jamfile.jam @@ -39,6 +39,7 @@ lib testCommon : <library>dbppcore <library>dbpp-postgresql <library>../../devices//p2pvrMockTuner + <library>../../devices//p2pvrdevices <library>boost_system <library>boost_filesystem <implicit-dependency>../../ice diff --git a/p2pvr/daemon/unittests/mockDevices.cpp b/p2pvr/daemon/unittests/mockDevices.cpp index 3e04c85..12203b0 100644 --- a/p2pvr/daemon/unittests/mockDevices.cpp +++ b/p2pvr/daemon/unittests/mockDevices.cpp @@ -4,94 +4,16 @@ namespace P2PVR { namespace Testing { - void MockDevices::ScanAndSendNetworkInformation(const RawDataClientPrx & target, const ::Ice::Current & ice) + MockDevices::MockDevices(Ice::CommunicatorPtr c) : + ic(c) { - MockTuner mt(ice.adapter->getCommunicator()); - mt.ScanAndSendNetworkInformation(target); + devices.push_back("/dev/dvb/dummy"); } - void MockDevices::SendNetworkInformation(const ::DVBSI::DeliveryPtr & del, const RawDataClientPrx & target, const ::Ice::Current & ice) + TunerPtr + MockDevices::openTuner(const boost::filesystem::path &) const { - BOOST_ASSERT(del); - MockTuner mt(ice.adapter->getCommunicator()); - mt.SendNetworkInformation(target); - } - - void MockDevices::SendBouquetAssociations(const ::DVBSI::DeliveryPtr & del, const RawDataClientPrx & target, const ::Ice::Current & ice) - { - BOOST_ASSERT(del); - MockTuner mt(ice.adapter->getCommunicator()); - mt.SendBouquetAssociations(target); - } - - void MockDevices::SendServiceDescriptions(const ::DVBSI::DeliveryPtr & del, const RawDataClientPrx & target, const ::Ice::Current & ice) - { - BOOST_ASSERT(del); - MockTuner mt(ice.adapter->getCommunicator()); - mt.SendServiceDescriptions(target); - } - - void MockDevices::SendProgramAssociationTable(const ::DVBSI::DeliveryPtr & del, const RawDataClientPrx & target, const ::Ice::Current & ice) - { - BOOST_ASSERT(del); - MockTuner mt(ice.adapter->getCommunicator()); - mt.SendProgramAssociationTable(target); - } - - void MockDevices::SendProgramMap(const ::DVBSI::DeliveryPtr & del, ::Ice::Int pid, const RawDataClientPrx & target, const ::Ice::Current & ice) - { - BOOST_ASSERT(del); - MockTuner mt(ice.adapter->getCommunicator()); - mt.SendProgramMap(pid, target); - } - - void MockDevices::SendEventInformation(const ::DVBSI::DeliveryPtr & del, const RawDataClientPrx & target, const ::Ice::Current & ice) - { - BOOST_ASSERT(del); - MockTuner mt(ice.adapter->getCommunicator()); - mt.SendEventInformation(target); - } - - ::Ice::Int MockDevices::StartSendingTS(const ::DVBSI::DeliveryPtr & del, const PacketIds & pids, const RawDataClientPrx & target, const ::Ice::Current & ice) - { - BOOST_ASSERT(del); - TunerPtr tuner = new MockTuner(ice.adapter->getCommunicator()); - return bgOps.insert({ tuner->StartSendingTS(pids, target), tuner }).first->first; - } - - ::Ice::Int MockDevices::StartSendingSection(const ::DVBSI::DeliveryPtr & del, ::Ice::Int sid, const RawDataClientPrx & target, const ::Ice::Current & ice) - { - BOOST_ASSERT(del); - TunerPtr tuner = new MockTuner(ice.adapter->getCommunicator()); - return bgOps.insert({ tuner->StartSendingSection(sid, target), tuner }).first->first; - } - - void MockDevices::StopSending(::Ice::Int handle, const ::Ice::Current &) - { - BOOST_ASSERT(handle); - auto itr = bgOps.find(handle); - BOOST_ASSERT(itr != bgOps.end()); - BOOST_ASSERT(itr->second); - itr->second->StopSending(handle); - bgOps.erase(itr); - } - - - void MockDevices::Scan(const std::string &, const Ice::Current &) - { - } - - void MockDevices::Add(const std::string &, const Ice::Current &) - { - } - - void MockDevices::Remove(const std::string &, const Ice::Current &) - { - } - - ::Ice::Int MockDevices::TunerCount(const Ice::Current &) - { - return 1; + return new MockTuner(ic); } } } diff --git a/p2pvr/daemon/unittests/mockDevices.h b/p2pvr/daemon/unittests/mockDevices.h index bc0a22a..a9ed170 100644 --- a/p2pvr/daemon/unittests/mockDevices.h +++ b/p2pvr/daemon/unittests/mockDevices.h @@ -3,30 +3,18 @@ #include <dvb.h> #include <visibility.h> +#include <devices.h> namespace P2PVR { namespace Testing { - class DLL_PUBLIC MockDevices : public Tuners { + class DLL_PUBLIC MockDevices : public DevicesI { public: - virtual void ScanAndSendNetworkInformation(const RawDataClientPrx&, const ::Ice::Current&) override; - virtual void SendNetworkInformation(const ::DVBSI::DeliveryPtr&, const RawDataClientPrx&, const ::Ice::Current&) override; - virtual void SendBouquetAssociations(const ::DVBSI::DeliveryPtr&, const RawDataClientPrx&, const ::Ice::Current&) override; - virtual void SendServiceDescriptions(const ::DVBSI::DeliveryPtr&, const RawDataClientPrx&, const ::Ice::Current&) override; - virtual void SendProgramAssociationTable(const ::DVBSI::DeliveryPtr&, const RawDataClientPrx&, const ::Ice::Current&) override; - virtual void SendProgramMap(const ::DVBSI::DeliveryPtr&, ::Ice::Int, const RawDataClientPrx&, const ::Ice::Current&) override; - virtual void SendEventInformation(const ::DVBSI::DeliveryPtr&, const RawDataClientPrx&, const ::Ice::Current&) override; - virtual ::Ice::Int StartSendingTS(const ::DVBSI::DeliveryPtr&, const PacketIds&, const RawDataClientPrx&, const ::Ice::Current&) override; - virtual ::Ice::Int StartSendingSection(const ::DVBSI::DeliveryPtr&, ::Ice::Int, const RawDataClientPrx&, const ::Ice::Current&) override; - virtual void StopSending(::Ice::Int, const ::Ice::Current&) override; + MockDevices(Ice::CommunicatorPtr ic); - void Scan(const std::string & path, const Ice::Current &) override; - void Add(const std::string & frontend, const Ice::Current &) override; - void Remove(const std::string & frontend, const Ice::Current &) override; - ::Ice::Int TunerCount(const Ice::Current &) override; + TunerPtr openTuner(const boost::filesystem::path &) const override; private: - typedef std::map<::Ice::Int, TunerPtr> BackgroundOperations; - BackgroundOperations bgOps; + Ice::CommunicatorPtr ic; }; } } diff --git a/p2pvr/daemon/unittests/testErrorHandling.cpp b/p2pvr/daemon/unittests/testErrorHandling.cpp index 2ec1941..80af051 100644 --- a/p2pvr/daemon/unittests/testErrorHandling.cpp +++ b/p2pvr/daemon/unittests/testErrorHandling.cpp @@ -26,7 +26,7 @@ class Core : public StandardMockDatabase { public: Core() { - replace("Devices", new MockDevices()); + replace("Devices", new MockDevices(ic)); } }; diff --git a/p2pvr/daemon/unittests/testMaint.cpp b/p2pvr/daemon/unittests/testMaint.cpp index a1fc6fd..e918d74 100644 --- a/p2pvr/daemon/unittests/testMaint.cpp +++ b/p2pvr/daemon/unittests/testMaint.cpp @@ -27,7 +27,7 @@ class TestService : public SchemaOnlyMockDatabase { public: TestService() { - replace("Devices", new MockDevices()); + replace("Devices", new MockDevices(ic)); replace("Schedules", new MockScheduler()); } }; diff --git a/p2pvr/daemon/unittests/testRecording.cpp b/p2pvr/daemon/unittests/testRecording.cpp index fe81b7d..ae3a3a3 100644 --- a/p2pvr/daemon/unittests/testRecording.cpp +++ b/p2pvr/daemon/unittests/testRecording.cpp @@ -28,7 +28,7 @@ class TestService : public StandardMockDatabase { public: TestService() { - replace("Devices", new MockDevices()); + replace("Devices", new MockDevices(ic)); replace("Schedules", new MockScheduler()); } }; diff --git a/p2pvr/daemon/unittests/testSched.cpp b/p2pvr/daemon/unittests/testSched.cpp index 9f6881a..18e375c 100644 --- a/p2pvr/daemon/unittests/testSched.cpp +++ b/p2pvr/daemon/unittests/testSched.cpp @@ -26,7 +26,7 @@ class TestService : public StandardMockDatabasePlusOffset { public: TestService() { - replace("Devices", new MockDevices()); + replace("Devices", new MockDevices(ic)); replace("Recorder", new MockRecorder()); } }; diff --git a/p2pvr/devices/devices.cpp b/p2pvr/devices/devices.cpp index 420632d..8cd9a74 100644 --- a/p2pvr/devices/devices.cpp +++ b/p2pvr/devices/devices.cpp @@ -52,7 +52,9 @@ DevicesI::getTuner() } for (auto devItr = devices.begin(); devItr != devices.end(); devItr++) { try { - return openTuner(*devItr); + TunerPtr tuner = openTuner(*devItr); + devices.erase(devItr); + return tuner; } catch (...) { logger->messagebf(LOG::DEBUG, "%s: Failed to open device %s", __PRETTY_FUNCTION__, @@ -121,17 +123,17 @@ DevicesI::releaseTuner(const TunerPtr & tuner) Lock(lock); logger->messagebf(LOG::DEBUG, "%s", __PRETTY_FUNCTION__); auto openTuner = std::find_if(openDevices.begin(), openDevices.end(), [&tuner](const auto & ot) { - return ot.second->tuner == tuner; - }); - if (openTuner == openDevices.end()) { - logger->messagebf(LOG::DEBUG, "%s: Not one of mine", __PRETTY_FUNCTION__); - throw DeviceError(); + return ot.second->tuner == tuner; + }); + if (openTuner != openDevices.end()) { + openTuner->second->clients -= 1; + if (openTuner->second->clients == 0) { + openDevices.erase(openTuner); + devices.push_back(tuner->GetDevice()); + } } - logger->messagebf(LOG::DEBUG, "%s: Locally owned deivce %s", __PRETTY_FUNCTION__, openTuner->first); - openTuner->second->clients -= 1; - if (openTuner->second->clients == 0) { - openDevices.erase(openTuner); - devices.push_back(openTuner->second->tuner->GetDevice()); + else { + devices.push_back(tuner->GetDevice()); } } diff --git a/p2pvr/devices/devices.h b/p2pvr/devices/devices.h index d32971f..e575ce6 100644 --- a/p2pvr/devices/devices.h +++ b/p2pvr/devices/devices.h @@ -46,7 +46,6 @@ class DLL_PUBLIC DevicesI : public Tuners { protected: virtual TunerPtr openTuner(const boost::filesystem::path &) const; - private: typedef boost::function<DVBSI::DeliveryPtr()> DeliveryProvider; typedef boost::function<void(TunerPtr)> Target; typedef boost::shared_ptr<OpenTuner> OpenTunerPtr; diff --git a/p2pvr/devices/mockTuner.cpp b/p2pvr/devices/mockTuner.cpp index 1316b6d..9abcfbf 100644 --- a/p2pvr/devices/mockTuner.cpp +++ b/p2pvr/devices/mockTuner.cpp @@ -57,7 +57,7 @@ int MockTuner::GetStatus() std::string MockTuner::GetDevice() { - return 0; + return "/dev/dvb/dummy"; } Ice::ByteSeq MockTuner::Decompress(const Ice::ByteSeq & dataxz) |