diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2017-07-30 18:28:41 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2017-07-30 18:28:41 +0100 |
commit | fe61ba505f3b1aa7401836a97dd32284f9932a74 (patch) | |
tree | 682d06a9f995216fd24cc60d555e6f2adbabefe5 /p2pvr/daemon | |
parent | Tidy SQL statements into sub-dirs (diff) | |
download | p2pvr-fe61ba505f3b1aa7401836a97dd32284f9932a74.tar.bz2 p2pvr-fe61ba505f3b1aa7401836a97dd32284f9932a74.tar.xz p2pvr-fe61ba505f3b1aa7401836a97dd32284f9932a74.zip |
Move everything out of the global namespace
Diffstat (limited to 'p2pvr/daemon')
38 files changed, 394 insertions, 267 deletions
diff --git a/p2pvr/daemon/daemon.cpp b/p2pvr/daemon/daemon.cpp index 6a62457..109086a 100644 --- a/p2pvr/daemon/daemon.cpp +++ b/p2pvr/daemon/daemon.cpp @@ -10,6 +10,7 @@ #include <tmdb-proxy.h> #include <icetrayService.h> +namespace P2PVR { // These configure external components and so they live here class P2PVRTMDb : public IceTray::Options { public: @@ -36,14 +37,14 @@ class P2PvrDaemon : public IceTray::Service { IceUtil::TimerPtr timer = new IceUtil::Timer(); auto db = getConnectionPool(ic, "postgresql", "postgres"); - auto localDevices = add<P2PVR::LocalDevices>(ic, adapter, new LocalDevices(adapter, timer), "Devices"); - auto globalDevices = add<P2PVR::Devices>(ic, adapter, new GlobalDevices(), "GlobalDevices"); - auto maintenance = add<P2PVR::Maintenance>(ic, adapter, new Maintenance(db, adapter, timer), "Maintenance"); - auto si = add<P2PVR::SI>(ic, adapter, new SI(db), "SI"); - auto schedules = add<P2PVR::Schedules>(ic, adapter, new Schedules(db), "Schedules"); - auto storage = add<P2PVR::Storage>(ic, adapter, new Storage(), "Storage"); - auto recorder = add<P2PVR::Recorder>(ic, adapter, new Recorder(adapter, timer), "Recorder"); - auto recordings = add<P2PVR::Recordings>(ic, adapter, new Recordings(db), "Recordings"); + auto localDevices = add<LocalDevices>(ic, adapter, new LocalDevicesI(adapter, timer), "Devices"); + auto globalDevices = add<Devices>(ic, adapter, new GlobalDevices(), "GlobalDevices"); + auto maintenance = add<Maintenance>(ic, adapter, new MaintenanceI(db, adapter, timer), "Maintenance"); + auto si = add<SI>(ic, adapter, new SII(db), "SI"); + auto schedules = add<Schedules>(ic, adapter, new SchedulesI(db), "Schedules"); + auto storage = add<Storage>(ic, adapter, new StorageI(), "Storage"); + auto recorder = add<Recorder>(ic, adapter, new RecorderI(adapter, timer), "Recorder"); + auto recordings = add<Recordings>(ic, adapter, new RecordingsI(db), "Recordings"); auto tmdb = add<TMDb::Proxy>(ic, adapter, new TMDb::Proxy(tmdbOpts->baseUrl, tmdbOpts->apikey), "TMDb"); } @@ -55,4 +56,5 @@ class P2PvrDaemon : public IceTray::Service { }; FACTORY(P2PvrDaemon, IceTray::ServiceFactory); +} diff --git a/p2pvr/daemon/globalDevices.cpp b/p2pvr/daemon/globalDevices.cpp index 4557fc6..0705415 100644 --- a/p2pvr/daemon/globalDevices.cpp +++ b/p2pvr/daemon/globalDevices.cpp @@ -3,6 +3,7 @@ namespace po = boost::program_options; +namespace P2PVR { GlobalDevices::Options::Options() : IceTray::Options("P2PVR Devices") { @@ -13,57 +14,57 @@ ICETRAY_OPTIONS(GlobalDevices::Options, "ICE address of remote device pools (<object>:<endpoint>)") ) -P2PVR::TunerPrx +TunerPrx GlobalDevices::GetTunerSpecific(const DVBSI::DeliveryPtr & delivery, const Ice::Current & ice) { auto ic = ice.adapter->getCommunicator(); for (const auto & pool : options->Devices) { try { - auto poolprx = P2PVR::DevicesPrx::checkedCast(ic->stringToProxy(pool)); + auto poolprx = DevicesPrx::checkedCast(ic->stringToProxy(pool)); return poolprx->GetTunerSpecific(delivery); } catch (...) { } } - throw P2PVR::NoSuitableDeviceAvailable(); + throw NoSuitableDeviceAvailable(); } -P2PVR::TunerPrx +TunerPrx GlobalDevices::GetTunerAny(const DVBSI::DeliveryPtr & delivery, const Ice::Current & ice) { auto ic = ice.adapter->getCommunicator(); for (const auto & pool : options->Devices) { try { - auto poolprx = P2PVR::DevicesPrx::checkedCast(ic->stringToProxy(pool)); + auto poolprx = DevicesPrx::checkedCast(ic->stringToProxy(pool)); return poolprx->GetTunerAny(delivery); } catch (...) { } } - throw P2PVR::NoSuitableDeviceAvailable(); + throw NoSuitableDeviceAvailable(); } -P2PVR::PrivateTunerPrx +PrivateTunerPrx GlobalDevices::GetPrivateTuner(short type, const Ice::Current & ice) { auto ic = ice.adapter->getCommunicator(); for (const auto & pool : options->Devices) { try { - auto poolprx = P2PVR::DevicesPrx::checkedCast(ic->stringToProxy(pool)); + auto poolprx = DevicesPrx::checkedCast(ic->stringToProxy(pool)); return poolprx->GetPrivateTuner(type); } catch (...) { } } - throw P2PVR::NoSuitableDeviceAvailable(); + throw NoSuitableDeviceAvailable(); } void -GlobalDevices::ReleaseTuner(const P2PVR::TunerPrx & tuner, const Ice::Current & ice) +GlobalDevices::ReleaseTuner(const TunerPrx & tuner, const Ice::Current & ice) { auto ic = ice.adapter->getCommunicator(); for (const auto & pool : options->Devices) { - auto poolprx = P2PVR::DevicesPrx::checkedCast(ic->stringToProxy(pool)); + auto poolprx = DevicesPrx::checkedCast(ic->stringToProxy(pool)); poolprx->ReleaseTuner(tuner); } } @@ -75,7 +76,7 @@ GlobalDevices::TunerCount(const Ice::Current & ice) auto ic = ice.adapter->getCommunicator(); for (const auto & pool : options->Devices) { try { - auto poolprx = P2PVR::DevicesPrx::checkedCast(ic->stringToProxy(pool)); + auto poolprx = DevicesPrx::checkedCast(ic->stringToProxy(pool)); total += poolprx->TunerCount(); } catch (...) { @@ -84,4 +85,5 @@ GlobalDevices::TunerCount(const Ice::Current & ice) } return total; } +} diff --git a/p2pvr/daemon/globalDevices.h b/p2pvr/daemon/globalDevices.h index cffb491..c5097b3 100644 --- a/p2pvr/daemon/globalDevices.h +++ b/p2pvr/daemon/globalDevices.h @@ -1,14 +1,15 @@ #ifndef GLOBALDEVICES_H #define GLOBALDEVICES_H -// Global devices implements a device collection (P2PVR::Devices) for any devices known +// Global devices implements a device collection (Devices) for any devices known // throughout the system through other Devices interfaces #include <dvb.h> #include <options.h> #include <visibility.h> -class DLL_PUBLIC GlobalDevices : public P2PVR::Devices { +namespace P2PVR { +class DLL_PUBLIC GlobalDevices : public Devices { public: class Options : public IceTray::Options { public: @@ -19,15 +20,16 @@ class DLL_PUBLIC GlobalDevices : public P2PVR::Devices { std::vector<std::string> Devices; }; - P2PVR::TunerPrx GetTunerSpecific(const DVBSI::DeliveryPtr &, const Ice::Current &); - P2PVR::TunerPrx GetTunerAny(const DVBSI::DeliveryPtr &, const Ice::Current &); - P2PVR::PrivateTunerPrx GetPrivateTuner(short type, const Ice::Current &); - void ReleaseTuner(const P2PVR::TunerPrx &, const Ice::Current &); + TunerPrx GetTunerSpecific(const DVBSI::DeliveryPtr &, const Ice::Current &); + TunerPrx GetTunerAny(const DVBSI::DeliveryPtr &, const Ice::Current &); + PrivateTunerPrx GetPrivateTuner(short type, const Ice::Current &); + void ReleaseTuner(const TunerPrx &, const Ice::Current &); int TunerCount(const Ice::Current &); private: IceTray::OptionsResolver<Options> options; }; +} #endif diff --git a/p2pvr/daemon/icetraySupport.cpp b/p2pvr/daemon/icetraySupport.cpp new file mode 100644 index 0000000..8f81ec4 --- /dev/null +++ b/p2pvr/daemon/icetraySupport.cpp @@ -0,0 +1,10 @@ +#include "icetraySupport.h" +#include "commonHelpers.h" + +template<> +void +IceTray::AbstractDatabaseClient::bind1<Common::DateTime>(int x, DB::Command * cmd, const Common::DateTime & dt) +{ + cmd->bindParamT(x, *dt); +} + diff --git a/p2pvr/daemon/icetraySupport.h b/p2pvr/daemon/icetraySupport.h new file mode 100644 index 0000000..4174665 --- /dev/null +++ b/p2pvr/daemon/icetraySupport.h @@ -0,0 +1,14 @@ +#ifndef P2PVR_ICETRAY_SUPPORT_H +#define P2PVR_ICETRAY_SUPPORT_H + +#include <abstractDatabaseClient.h> +#include <common.h> + +namespace IceTray { + template<> + void + AbstractDatabaseClient::bind1<Common::DateTime>(int x, DB::Command * cmd, const Common::DateTime &); +} + +#endif + diff --git a/p2pvr/daemon/maintenance.cpp b/p2pvr/daemon/maintenance.cpp index 23eef15..6abad00 100644 --- a/p2pvr/daemon/maintenance.cpp +++ b/p2pvr/daemon/maintenance.cpp @@ -9,8 +9,9 @@ namespace po = boost::program_options; -Maintenance::Options::Options() : IceTray::Options("P2PVR Maintenance options") { } -ICETRAY_OPTIONS(Maintenance::Options, +namespace P2PVR { +MaintenanceI::Options::Options() : IceTray::Options("P2PVR Maintenance options") { } +ICETRAY_OPTIONS(MaintenanceI::Options, ("p2pvr.maintenance.periodUpdateNetwork", po::value(&periodUpdateNetwork)->default_value(86400 * 7), "Period between automated updates of DVB network (1 week)") ("p2pvr.maintenance.periodUpdateServices", po::value(&periodUpdateServices)->default_value(86400 * 7), @@ -21,13 +22,13 @@ ICETRAY_OPTIONS(Maintenance::Options, "Perform the maintenance circle on start-up (false)") ); -IceTray::Logging::LoggerPtr Maintenance::logger(LOGMANAGER()->getLogger<Maintenance>()); +IceTray::Logging::LoggerPtr MaintenanceI::logger(LOGMANAGER()->getLogger<MaintenanceI>()); -Maintenance::Maintenance(IceTray::DatabasePoolPtr db, Ice::ObjectAdapterPtr a, IceUtil::TimerPtr t) : +MaintenanceI::MaintenanceI(IceTray::DatabasePoolPtr db, Ice::ObjectAdapterPtr a, IceUtil::TimerPtr t) : IceTray::AbstractDatabaseClient(db), adapter(a), timer(t), - clientCheck(new BindTimerTask(boost::bind(&Maintenance::ScheduledUpdate, this))), + clientCheck(new BindTimerTask(boost::bind(&MaintenanceI::ScheduledUpdate, this))), lastUpdateNetwork(0), lastUpdateServices(0), lastUpdateEvents(0), @@ -42,7 +43,7 @@ Maintenance::Maintenance(IceTray::DatabasePoolPtr db, Ice::ObjectAdapterPtr a, I } void -Maintenance::UpdateAll(const Ice::Current & ice) +MaintenanceI::UpdateAll(const Ice::Current & ice) { UpdateAll(FE_OFDM, ice); UpdateAll(FE_QPSK, ice); @@ -51,7 +52,7 @@ Maintenance::UpdateAll(const Ice::Current & ice) } void -Maintenance::UpdateAll(short type, const Ice::Current & ice) +MaintenanceI::UpdateAll(short type, const Ice::Current & ice) { UpdateNetwork(type, ice); UpdateServices(ice); @@ -59,7 +60,7 @@ Maintenance::UpdateAll(short type, const Ice::Current & ice) } void -Maintenance::ScheduledUpdate() +MaintenanceI::ScheduledUpdate() { logger->messagebf(LOG::DEBUG, "%s: triggered", __PRETTY_FUNCTION__); if (!updateRunning) { @@ -97,4 +98,5 @@ Maintenance::ScheduledUpdate() update.detach(); } } +} diff --git a/p2pvr/daemon/maintenance.h b/p2pvr/daemon/maintenance.h index c941d06..5299139 100644 --- a/p2pvr/daemon/maintenance.h +++ b/p2pvr/daemon/maintenance.h @@ -8,7 +8,8 @@ #include <logger.h> #include <visibility.h> -class DLL_PUBLIC Maintenance : public P2PVR::Maintenance, public IceTray::AbstractDatabaseClient { +namespace P2PVR { +class DLL_PUBLIC MaintenanceI : public Maintenance, public IceTray::AbstractDatabaseClient { public: class Options : public IceTray::Options { public: @@ -20,7 +21,7 @@ class DLL_PUBLIC Maintenance : public P2PVR::Maintenance, public IceTray::Abstra bool scanOnStart; }; - Maintenance(IceTray::DatabasePoolPtr db, Ice::ObjectAdapterPtr, IceUtil::TimerPtr); + MaintenanceI(IceTray::DatabasePoolPtr db, Ice::ObjectAdapterPtr, IceUtil::TimerPtr); void UpdateAll(const Ice::Current &); void UpdateAll(short type, const Ice::Current &); @@ -43,6 +44,7 @@ class DLL_PUBLIC Maintenance : public P2PVR::Maintenance, public IceTray::Abstra IceTray::OptionsResolver<Options> options; static IceTray::Logging::LoggerPtr logger; }; +} #endif diff --git a/p2pvr/daemon/maintenance/events.cpp b/p2pvr/daemon/maintenance/events.cpp index 0f4cf4e..8a642f9 100644 --- a/p2pvr/daemon/maintenance/events.cpp +++ b/p2pvr/daemon/maintenance/events.cpp @@ -9,9 +9,10 @@ #include <slicer/modelPartsTypes.impl.h> #include "sql/maintenance/pruneEvents.sql.h" -class SiEventsStream : public Slicer::Stream<DVBSI::EventPtr> { +namespace P2PVR { +class SiEventsStream : public Slicer::Stream<::DVBSI::EventPtr> { private: - class SiEventsHandler : public SiEpgParser { + class SiEventsHandler : public DVBSI::SiEpgParser { public: SiEventsHandler(const Consumer & c, IceTray::Logging::LoggerPtr l) : consumer(c), @@ -19,7 +20,7 @@ class SiEventsStream : public Slicer::Stream<DVBSI::EventPtr> { { } - bool HandleTable(DVBSI::EventPtr e) override + bool HandleTable(::DVBSI::EventPtr e) override { logger->messagebf(LOG::DEBUG, "Service Id: %d Program Id: %d Title: %s Time: %s - %s", e->ServiceId, e->EventId, e->Title, e->StartTime, e->StopTime); @@ -42,8 +43,8 @@ class SiEventsStream : public Slicer::Stream<DVBSI::EventPtr> { void Produce(const Consumer & ch) override { auto ic = ice.adapter->getCommunicator(); - auto devs = P2PVR::DevicesPrx::checkedCast(ice.adapter->createProxy(ic->stringToIdentity("GlobalDevices"))); - auto si = P2PVR::SIPrx::checkedCast(ice.adapter->createProxy(ic->stringToIdentity("SI"))); + auto devs = DevicesPrx::checkedCast(ice.adapter->createProxy(ic->stringToIdentity("GlobalDevices"))); + auto si = SIPrx::checkedCast(ice.adapter->createProxy(ic->stringToIdentity("SI"))); if (!devs || !si) { throw std::runtime_error("bad proxy(s)"); } @@ -55,7 +56,7 @@ class SiEventsStream : public Slicer::Stream<DVBSI::EventPtr> { logger->messagebf(LOG::DEBUG, "%s: Getting a tuner", __PRETTY_FUNCTION__); auto tuner = devs->GetTunerAny(delivery); logger->messagebf(LOG::DEBUG, "%s: Fetching events", __PRETTY_FUNCTION__); - TemporaryIceAdapterObject<P2PVR::RawDataClient> parser(ice.adapter, new SiEventsHandler(ch, logger)); + TemporaryIceAdapterObject<RawDataClient> parser(ice.adapter, new SiEventsHandler(ch, logger)); tuner->SendEventInformation(parser); devs->ReleaseTuner(tuner); @@ -66,10 +67,8 @@ class SiEventsStream : public Slicer::Stream<DVBSI::EventPtr> { const IceTray::Logging::LoggerPtr logger; }; -MODELPARTFORSTREAM(SiEventsStream); - void -Maintenance::UpdateEvents(const Ice::Current & ice) +MaintenanceI::UpdateEvents(const Ice::Current & ice) { auto dbc = db->get(); auto ic = ice.adapter->getCommunicator(); @@ -84,10 +83,13 @@ Maintenance::UpdateEvents(const Ice::Current & ice) Slicer::SerializeAny<Slicer::SqlTablePatchSerializer>(stream, dbc.get(), tp); - P2PVR::sql::maintenance::pruneEvents.modify(dbc.get())->execute(); + sql::maintenance::pruneEvents.modify(dbc.get())->execute(); logger->messagebf(LOG::INFO, "%s: Updated events", __PRETTY_FUNCTION__); - auto sch = P2PVR::SchedulesPrx::checkedCast(ice.adapter->createProxy(ic->stringToIdentity("Schedules"))); + auto sch = SchedulesPrx::checkedCast(ice.adapter->createProxy(ic->stringToIdentity("Schedules"))); sch->DoReschedule(); } +} + +MODELPARTFORSTREAM(P2PVR::SiEventsStream); diff --git a/p2pvr/daemon/maintenance/network.cpp b/p2pvr/daemon/maintenance/network.cpp index 4b03f6d..56f3754 100644 --- a/p2pvr/daemon/maintenance/network.cpp +++ b/p2pvr/daemon/maintenance/network.cpp @@ -6,7 +6,8 @@ #include <db/sqlInsertSerializer.h> #include <db/sqlTablePatchSerializer.h> -class SiNetworkInformationMerger : public SiNetworkInformationParser { +namespace P2PVR { +class SiNetworkInformationMerger : public DVBSI::SiNetworkInformationParser { public: SiNetworkInformationMerger(DB::Connection * d, IceTray::Logging::LoggerPtr l) : dbc(d), @@ -14,7 +15,7 @@ class SiNetworkInformationMerger : public SiNetworkInformationParser { { } - bool HandleTable(DVBSI::NetworkPtr n) + bool HandleTable(::DVBSI::NetworkPtr n) { logger->messagebf(LOG::DEBUG, "Network Id: %d Name: %s", n->NetworkId, *n->Name); for (const auto & ts : n->TransportStreams) { @@ -35,11 +36,11 @@ class SiNetworkInformationMerger : public SiNetworkInformationParser { mergeTransportStreams.dest = "transportstreams"; Slicer::SerializeAny<Slicer::SqlTablePatchSerializer>(n->TransportStreams, dbc, mergeTransportStreams); - mergeDelivery<DVBSI::TerrestrialDeliveryPtr, &DVBSI::NetworkTransportStream::Terrestrial>("delivery_dvbt", n); - mergeDelivery<DVBSI::SatelliteDeliveryPtr, &DVBSI::NetworkTransportStream::Satellite>("delivery_dvbs", n); - mergeDelivery<DVBSI::CableDeliveryPtr, &DVBSI::NetworkTransportStream::Cable>("delivery_dvbc", n); + mergeDelivery<::DVBSI::TerrestrialDeliveryPtr, &::DVBSI::NetworkTransportStream::Terrestrial>("delivery_dvbt", n); + mergeDelivery<::DVBSI::SatelliteDeliveryPtr, &::DVBSI::NetworkTransportStream::Satellite>("delivery_dvbs", n); + mergeDelivery<::DVBSI::CableDeliveryPtr, &::DVBSI::NetworkTransportStream::Cable>("delivery_dvbc", n); - DVBSI::NetworkServiceList services; + ::DVBSI::NetworkServiceList services; for (const auto & ts : n->TransportStreams) { for (const auto & s : ts->Services) { services.push_back(s); @@ -52,8 +53,9 @@ class SiNetworkInformationMerger : public SiNetworkInformationParser { return false; } private: - template <class Delivery, Delivery DVBSI::NetworkTransportStream::*member> - void mergeDelivery(const std::string & table, DVBSI::NetworkPtr n) + typedef ::DVBSI::NetworkTransportStream NTS; + template <class Delivery, Delivery NTS::*member> + void mergeDelivery(const std::string & table, ::DVBSI::NetworkPtr n) { DB::TablePatch tp; tp.dest = table; @@ -70,14 +72,14 @@ class SiNetworkInformationMerger : public SiNetworkInformationParser { }; void -Maintenance::UpdateNetwork(short type, const Ice::Current & ice) +MaintenanceI::UpdateNetwork(short type, const Ice::Current & ice) { auto dbc = db->get(); auto ic = ice.adapter->getCommunicator(); - auto devs = P2PVR::DevicesPrx::checkedCast(ice.adapter->createProxy(ic->stringToIdentity("GlobalDevices"))); - auto si = P2PVR::SIPrx::checkedCast(ice.adapter->createProxy(ic->stringToIdentity("SI"))); + auto devs = DevicesPrx::checkedCast(ice.adapter->createProxy(ic->stringToIdentity("GlobalDevices"))); + auto si = SIPrx::checkedCast(ice.adapter->createProxy(ic->stringToIdentity("SI"))); auto siparser = new SiNetworkInformationMerger(dbc.get(), logger); - TemporaryIceAdapterObject<P2PVR::RawDataClient> parser(ice.adapter, siparser); + TemporaryIceAdapterObject<RawDataClient> parser(ice.adapter, siparser); if (!devs) { throw std::runtime_error("bad proxy(s)"); @@ -87,14 +89,14 @@ Maintenance::UpdateNetwork(short type, const Ice::Current & ice) auto transport = si->GetDeliveryForSi(); if (transport) { - P2PVR::TunerPrx tuner; + TunerPrx tuner; try { tuner = devs->GetTunerAny(transport); tuner->SendNetworkInformation(parser); devs->ReleaseTuner(tuner); return; } - catch (const P2PVR::NoSuitableDeviceAvailable &) { + catch (const NoSuitableDeviceAvailable &) { logger->messagebf(LOG::WARNING, "%s: Failed to get a suitable tuner", __PRETTY_FUNCTION__); throw; } @@ -114,4 +116,5 @@ Maintenance::UpdateNetwork(short type, const Ice::Current & ice) tuner->ScanAndSendNetworkInformation(parser); devs->ReleaseTuner(tuner); } +} diff --git a/p2pvr/daemon/maintenance/services.cpp b/p2pvr/daemon/maintenance/services.cpp index 315ca0e..e04c200 100644 --- a/p2pvr/daemon/maintenance/services.cpp +++ b/p2pvr/daemon/maintenance/services.cpp @@ -7,7 +7,8 @@ #include <db/sqlTablePatchSerializer.h> #include <tablepatch.h> -class SiServicesMerger : public SiServicesParser { +namespace P2PVR { +class SiServicesMerger : public DVBSI::SiServicesParser { public: SiServicesMerger(IceTray::Logging::LoggerPtr l, DB::Connection * d) : logger(l), @@ -15,7 +16,7 @@ class SiServicesMerger : public SiServicesParser { { } - bool HandleTable(DVBSI::TransportStreamPtr ts) + bool HandleTable(::DVBSI::TransportStreamPtr ts) { logger->messagebf(LOG::DEBUG, "Transport Stream Id: %d Original Network Id: %s", ts->TransportStreamId, ts->OriginalNetworkId); for (const auto & s : ts->Services) { @@ -39,11 +40,11 @@ class SiServicesMerger : public SiServicesParser { }; void -Maintenance::UpdateServices(const Ice::Current & ice) +MaintenanceI::UpdateServices(const Ice::Current & ice) { auto ic = ice.adapter->getCommunicator(); - auto devs = P2PVR::DevicesPrx::checkedCast(ice.adapter->createProxy(ic->stringToIdentity("GlobalDevices"))); - auto si = P2PVR::SIPrx::checkedCast(ice.adapter->createProxy(ic->stringToIdentity("SI"))); + auto devs = DevicesPrx::checkedCast(ice.adapter->createProxy(ic->stringToIdentity("GlobalDevices"))); + auto si = SIPrx::checkedCast(ice.adapter->createProxy(ic->stringToIdentity("SI"))); if (!devs || !si) { throw std::runtime_error("bad proxy(s)"); @@ -51,7 +52,7 @@ Maintenance::UpdateServices(const Ice::Current & ice) auto dbc = db->get(); auto siparser = new SiServicesMerger(logger, dbc.get()); - TemporaryIceAdapterObject<P2PVR::RawDataClient> parser(ice.adapter, siparser); + TemporaryIceAdapterObject<RawDataClient> parser(ice.adapter, siparser); auto delivery = si->GetDeliveryForSi(); if (!delivery) { @@ -66,4 +67,5 @@ Maintenance::UpdateServices(const Ice::Current & ice) logger->messagebf(LOG::INFO, "%s: Updated service list", __PRETTY_FUNCTION__); devs->ReleaseTuner(tuner); } +} diff --git a/p2pvr/daemon/muxedFileSink.cpp b/p2pvr/daemon/muxedFileSink.cpp index ff6ec35..ff431bc 100644 --- a/p2pvr/daemon/muxedFileSink.cpp +++ b/p2pvr/daemon/muxedFileSink.cpp @@ -6,6 +6,7 @@ #include <boost/algorithm/string/split.hpp> #include <boost/algorithm/string/classification.hpp> +namespace P2PVR { class MuxerFailure : public P2PVR::DataHandlingException { }; MuxedFileSink::MuxedFileSink(const boost::filesystem::path & t, const std::string & cmd) : @@ -123,4 +124,5 @@ MuxedFileSink::ReadMuxer(int waitTime) const } } } +} diff --git a/p2pvr/daemon/muxedFileSink.h b/p2pvr/daemon/muxedFileSink.h index d252372..d91e106 100644 --- a/p2pvr/daemon/muxedFileSink.h +++ b/p2pvr/daemon/muxedFileSink.h @@ -8,6 +8,7 @@ #include <processPipes.h> #include <logger.h> +namespace P2PVR { class MuxedFileSink : public P2PVR::RawDataClient { public: MuxedFileSink(const boost::filesystem::path & target, const std::string & cmd); @@ -25,6 +26,7 @@ class MuxedFileSink : public P2PVR::RawDataClient { IceTray::Logging::LoggerPtr logger; }; +} #endif diff --git a/p2pvr/daemon/recorder.cpp b/p2pvr/daemon/recorder.cpp index 548ad11..28e89ee 100644 --- a/p2pvr/daemon/recorder.cpp +++ b/p2pvr/daemon/recorder.cpp @@ -13,21 +13,22 @@ namespace po = boost::program_options; -Recorder::Options::Options() : +namespace P2PVR { +RecorderI::Options::Options() : IceTray::Options("P2PVR Recorder options") { } -ICETRAY_OPTIONS(Recorder::Options, +ICETRAY_OPTIONS(RecorderI::Options, ("p2pvr.recorder.extension", po::value(&extension)->default_value("mp4"), "File extension to save with (default: mp4)") ("p2pvr.recorder.muxercommand", po::value(&muxerCommand)->default_value("/usr/bin/ffmpeg -f mpegts -i - -f dvd -codec copy -"), "Command to perform TS->PS muxing (default: '/usr/bin/ffmpeg -f mpegts -i - -f dvd -codec copy -')") ); -IceTray::Logging::LoggerPtr Recorder::logger(LOGMANAGER()->getLogger<Recorder>()); +IceTray::Logging::LoggerPtr RecorderI::logger(LOGMANAGER()->getLogger<RecorderI>()); -Recorder::Recorder(Ice::ObjectAdapterPtr a, IceUtil::TimerPtr t) : +RecorderI::RecorderI(Ice::ObjectAdapterPtr a, IceUtil::TimerPtr t) : adapter(a), timer(t) { @@ -36,15 +37,15 @@ Recorder::Recorder(Ice::ObjectAdapterPtr a, IceUtil::TimerPtr t) : } void -Recorder::RefreshSchedules(const Ice::Current &) +RecorderI::RefreshSchedules(const Ice::Current &) { std::lock_guard<std::mutex> g(lock); for (auto & t : pendingRecordings) { timer->cancel(t); } pendingRecordings.clear(); - auto schedules = P2PVR::SchedulesPrx::checkedCast(adapter->createProxy(adapter->getCommunicator()->stringToIdentity("Schedules"))); - auto si = P2PVR::SIPrx::checkedCast(adapter->createProxy(adapter->getCommunicator()->stringToIdentity("SI"))); + auto schedules = SchedulesPrx::checkedCast(adapter->createProxy(adapter->getCommunicator()->stringToIdentity("Schedules"))); + auto si = SIPrx::checkedCast(adapter->createProxy(adapter->getCommunicator()->stringToIdentity("SI"))); for (const auto & s : schedules->GetScheduledToRecord()) { if (std::find_if(currentRecordings.begin(), currentRecordings.end(), [&s](const CurrentPtr & c) { return s->ScheduleId == c->schedule->ScheduleId && s->EventUid == c->event->EventUid; @@ -56,7 +57,7 @@ Recorder::RefreshSchedules(const Ice::Current &) auto service = si->GetService(event->ServiceId); auto startIn = std::max<time_t>((*event->StartTime - *schedule->Early - boost::posix_time::second_clock::universal_time()).total_seconds(), 0); - IceUtil::TimerTaskPtr startTimer = new BindTimerTask(boost::bind(&Recorder::StartRecording, this, schedule, service, event)); + IceUtil::TimerTaskPtr startTimer = new BindTimerTask(boost::bind(&RecorderI::StartRecording, this, schedule, service, event)); timer->schedule(startTimer, IceUtil::Time::seconds(startIn)); pendingRecordings.push_back(startTimer); logger->messagebf(LOG::DEBUG, "Recording %s scheduled for %s seconds", event->Title, startIn); @@ -64,21 +65,21 @@ Recorder::RefreshSchedules(const Ice::Current &) } void -Recorder::StartRecording(P2PVR::SchedulePtr schedule, DVBSI::ServicePtr service, P2PVR::EventPtr event) +RecorderI::StartRecording(SchedulePtr schedule, ::DVBSI::ServicePtr service, EventPtr event) { std::lock_guard<std::mutex> g(lock); - auto storage = P2PVR::StoragePrx::checkedCast(adapter->createProxy(adapter->getCommunicator()->stringToIdentity("Storage"))); - auto recordings = P2PVR::RecordingsPrx::checkedCast(adapter->createProxy(adapter->getCommunicator()->stringToIdentity("Recordings"))); - auto devices = P2PVR::DevicesPrx::checkedCast(adapter->createProxy(adapter->getCommunicator()->stringToIdentity("GlobalDevices"))); - auto si = P2PVR::SIPrx::checkedCast(adapter->createProxy(adapter->getCommunicator()->stringToIdentity("SI"))); + auto storage = StoragePrx::checkedCast(adapter->createProxy(adapter->getCommunicator()->stringToIdentity("Storage"))); + auto recordings = RecordingsPrx::checkedCast(adapter->createProxy(adapter->getCommunicator()->stringToIdentity("Recordings"))); + auto devices = DevicesPrx::checkedCast(adapter->createProxy(adapter->getCommunicator()->stringToIdentity("GlobalDevices"))); + auto si = SIPrx::checkedCast(adapter->createProxy(adapter->getCommunicator()->stringToIdentity("SI"))); auto id = boost::lexical_cast<std::string>(boost::uuids::random_generator()()); auto store = storage->OpenForWrite(id); AdHoc::ScopeExit _store(NULL, NULL, [this,&store,&storage,&id]() { storage->Close(store); storage->Delete(id); }); auto target = store; - P2PVR::RawDataClientPrx muxer; + RawDataClientPrx muxer; if (!options->muxerCommand.empty()) { - muxer = P2PVR::RawDataClientPrx::checkedCast(adapter->addWithUUID(new Muxer(store, options->muxerCommand))); + muxer = RawDataClientPrx::checkedCast(adapter->addWithUUID(new Muxer(store, options->muxerCommand))); target = muxer; } AdHoc::ScopeExit _muxer(NULL, NULL, [this,&muxer]() { if (muxer) adapter->remove(muxer->ice_getIdentity()); }); @@ -89,18 +90,18 @@ Recorder::StartRecording(P2PVR::SchedulePtr schedule, DVBSI::ServicePtr service, event->Title, event->StartTime, event->StopTime, service->Name ? *service->Name : "<no name>", service->ServiceId); - recordings->NewRecording(new P2PVR::Recording(0, storage->ice_toString(), id, schedule->ScheduleId, event->EventUid)); + recordings->NewRecording(new Recording(0, storage->ice_toString(), id, schedule->ScheduleId, event->EventUid)); auto newCurrent = CurrentPtr(new Current({muxer, store, ss, schedule, service, event, IceUtil::TimerTaskPtr()})); currentRecordings.insert(newCurrent); auto stopIn = (*event->StopTime + *schedule->Late - boost::posix_time::second_clock::universal_time()).total_seconds(); - newCurrent->stopTimer = new BindTimerTask(boost::bind(&Recorder::StopRecording, this, newCurrent)); + newCurrent->stopTimer = new BindTimerTask(boost::bind(&RecorderI::StopRecording, this, newCurrent)); timer->schedule(newCurrent->stopTimer, IceUtil::Time::seconds(stopIn)); logger->messagebf(LOG::DEBUG, "Recording %s scheduled stop in %s seconds", event->Title, stopIn); } void -Recorder::StopRecording(CurrentPtr c) +RecorderI::StopRecording(CurrentPtr c) { std::lock_guard<std::mutex> g(lock); logger->messagebf(LOG::DEBUG, "Stopping %s", c->event->Title); @@ -109,8 +110,9 @@ Recorder::StopRecording(CurrentPtr c) adapter->remove(c->muxer->ice_getIdentity()); } currentRecordings.erase(c); - auto storage = P2PVR::StoragePrx::checkedCast(adapter->createProxy(adapter->getCommunicator()->stringToIdentity("Storage"))); + auto storage = StoragePrx::checkedCast(adapter->createProxy(adapter->getCommunicator()->stringToIdentity("Storage"))); storage->Close(c->store); logger->messagebf(LOG::DEBUG, "Stopped %s", c->event->Title); } +} diff --git a/p2pvr/daemon/recorder.h b/p2pvr/daemon/recorder.h index e6ff42a..6effb07 100644 --- a/p2pvr/daemon/recorder.h +++ b/p2pvr/daemon/recorder.h @@ -10,7 +10,8 @@ #include <visibility.h> #include <logger.h> -class DLL_PUBLIC Recorder : public P2PVR::Recorder { +namespace P2PVR { +class DLL_PUBLIC RecorderI : public Recorder { public: class Options : public IceTray::Options { public: @@ -26,23 +27,23 @@ class DLL_PUBLIC Recorder : public P2PVR::Recorder { class Current { public: - P2PVR::RawDataClientPrx muxer; - P2PVR::RawDataClientPrx store; + RawDataClientPrx muxer; + RawDataClientPrx store; ServiceStreamerPtr stream; - P2PVR::SchedulePtr schedule; - DVBSI::ServicePtr service; - P2PVR::EventPtr event; + SchedulePtr schedule; + ::DVBSI::ServicePtr service; + EventPtr event; IceUtil::TimerTaskPtr stopTimer; }; typedef boost::shared_ptr<Current> CurrentPtr; typedef std::set<CurrentPtr> Currents; - Recorder(Ice::ObjectAdapterPtr a, IceUtil::TimerPtr); + RecorderI(Ice::ObjectAdapterPtr a, IceUtil::TimerPtr); void RefreshSchedules(const Ice::Current &); private: - DLL_PRIVATE void StartRecording(P2PVR::SchedulePtr schedule, DVBSI::ServicePtr service, P2PVR::EventPtr event); + DLL_PRIVATE void StartRecording(SchedulePtr schedule, ::DVBSI::ServicePtr service, EventPtr event); DLL_PRIVATE void StopRecording(CurrentPtr); Ice::ObjectAdapterPtr adapter; @@ -55,6 +56,7 @@ class DLL_PUBLIC Recorder : public P2PVR::Recorder { IceTray::OptionsResolver<Options> options; static IceTray::Logging::LoggerPtr logger; }; +} #endif diff --git a/p2pvr/daemon/recordings.cpp b/p2pvr/daemon/recordings.cpp index 5570d4c..6efa78c 100644 --- a/p2pvr/daemon/recordings.cpp +++ b/p2pvr/daemon/recordings.cpp @@ -7,15 +7,16 @@ #include <sql/recordings/deleteById.sql.h> #include <sql/recordings/getAll.sql.h> -IceTray::Logging::LoggerPtr Recordings::logger(LOGMANAGER()->getLogger<Recordings>()); +namespace P2PVR { +IceTray::Logging::LoggerPtr RecordingsI::logger(LOGMANAGER()->getLogger<RecordingsI>()); -Recordings::Recordings(IceTray::DatabasePoolPtr db) : +RecordingsI::RecordingsI(IceTray::DatabasePoolPtr db) : IceTray::AbstractDatabaseClient(db) { } Ice::Int -Recordings::NewRecording(const P2PVR::RecordingPtr & r, const Ice::Current &) +RecordingsI::NewRecording(const RecordingPtr & r, const Ice::Current &) { auto dbc = db->get(); logger->messagebf(LOG::INFO, "%s: Creating new recording %s at %s", __PRETTY_FUNCTION__, r->Guid, r->StorageAddress); @@ -26,19 +27,20 @@ Recordings::NewRecording(const P2PVR::RecordingPtr & r, const Ice::Current &) } void -Recordings::DeleteRecording(int id, const Ice::Current &) +RecordingsI::DeleteRecording(int id, const Ice::Current &) { auto dbc = db->get(); logger->messagebf(LOG::INFO, "%s: Deleting recording Id: %d", __PRETTY_FUNCTION__, id); - auto del = P2PVR::sql::recordings::deleteById.modify(dbc.get()); + auto del = sql::recordings::deleteById.modify(dbc.get()); del->bindParamI(0, id); del->execute(); } -P2PVR::RecordingList -Recordings::GetRecordings(const Ice::Current &) +RecordingList +RecordingsI::GetRecordings(const Ice::Current &) { logger->message(LOG::DEBUG, __PRETTY_FUNCTION__); - return fetch<P2PVR::RecordingList>(P2PVR::sql::recordings::getAll); + return fetch<RecordingList>(sql::recordings::getAll); +} } diff --git a/p2pvr/daemon/recordings.h b/p2pvr/daemon/recordings.h index 1182ff6..4c3a54b 100644 --- a/p2pvr/daemon/recordings.h +++ b/p2pvr/daemon/recordings.h @@ -7,17 +7,19 @@ #include <logger.h> #include <abstractDatabaseClient.h> -class DLL_PUBLIC Recordings : public P2PVR::Recordings, public IceTray::AbstractDatabaseClient { +namespace P2PVR { +class DLL_PUBLIC RecordingsI : public Recordings, public IceTray::AbstractDatabaseClient { public: - Recordings(IceTray::DatabasePoolPtr db); + RecordingsI(IceTray::DatabasePoolPtr db); - Ice::Int NewRecording(const P2PVR::RecordingPtr & rec, const Ice::Current &); + Ice::Int NewRecording(const RecordingPtr & rec, const Ice::Current &); void DeleteRecording(int recordingId, const Ice::Current &); - P2PVR::RecordingList GetRecordings(const Ice::Current &); + RecordingList GetRecordings(const Ice::Current &); private: static IceTray::Logging::LoggerPtr logger; }; +} #endif diff --git a/p2pvr/daemon/schedulers/bitDumbScheduler.cpp b/p2pvr/daemon/schedulers/bitDumbScheduler.cpp index 10955e5..1c10105 100644 --- a/p2pvr/daemon/schedulers/bitDumbScheduler.cpp +++ b/p2pvr/daemon/schedulers/bitDumbScheduler.cpp @@ -1,5 +1,6 @@ #include "../schedules.h" +namespace P2PVR { class TheBitDumbScheduler : public EpisodeGroup { public: TheBitDumbScheduler(const Episodes & eps) : @@ -51,4 +52,5 @@ class TheBitDumbScheduler : public EpisodeGroup { }; NAMEDFACTORY("BitDumb", TheBitDumbScheduler, EpisodeGroupFactory); +} diff --git a/p2pvr/daemon/schedules.cpp b/p2pvr/daemon/schedules.cpp index 389a979..4fd2054 100644 --- a/p2pvr/daemon/schedules.cpp +++ b/p2pvr/daemon/schedules.cpp @@ -19,14 +19,15 @@ namespace po = boost::program_options; -IceTray::Logging::LoggerPtr Schedules::logger(LOGMANAGER()->getLogger<Schedules>()); +namespace P2PVR { +IceTray::Logging::LoggerPtr SchedulesI::logger(LOGMANAGER()->getLogger<SchedulesI>()); -Schedules::Options::Options() : +SchedulesI::Options::Options() : IceTray::Options("P2PVR Scheduler options") { } -ICETRAY_OPTIONS(Schedules::Options, +ICETRAY_OPTIONS(SchedulesI::Options, ("p2pvr.scheduler.algorithm", po::value(&SchedulerAlgorithm)->default_value("BitDumb"), "Implementation of episode group scheduler problem solver") ) @@ -163,13 +164,13 @@ EpisodeGroup::SuggestWithFeedback(const Showings & showings) } } -Schedules::Schedules(IceTray::DatabasePoolPtr db) : +SchedulesI::SchedulesI(IceTray::DatabasePoolPtr db) : IceTray::AbstractDatabaseClient(db) { } void -Schedules::GetEpisodeIntersects(Episodes & all, Episodes & grouped) +SchedulesI::GetEpisodeIntersects(Episodes & all, Episodes & grouped) { for (Episodes::iterator aei = all.begin(); aei != all.end(); aei++) { const auto & ae = *aei; @@ -190,14 +191,14 @@ Schedules::GetEpisodeIntersects(Episodes & all, Episodes & grouped) } void -Schedules::DoReschedule(const Ice::Current & ice) +SchedulesI::DoReschedule(const Ice::Current & ice) { auto ic = ice.adapter->getCommunicator(); auto devs = P2PVR::DevicesPrx::checkedCast(ice.adapter->createProxy(ic->stringToIdentity("GlobalDevices"))); unsigned int tunerCount = devs->TunerCount(); // Load list from database - auto episodes = fetch<P2PVR::ScheduleCandidates>(P2PVR::sql::schedules::getCandidates); + auto episodes = fetch<ScheduleCandidates>(P2PVR::sql::schedules::getCandidates); Episodes scheduleList; Showings allShowings; @@ -298,7 +299,7 @@ Schedules::DoReschedule(const Ice::Current & ice) } void -Schedules::DeleteSchedule(int id, const Ice::Current & ice) +SchedulesI::DeleteSchedule(int id, const Ice::Current & ice) { auto dbc = db->get(); auto del = P2PVR::sql::schedules::deleteById.modify(dbc.get()); @@ -308,14 +309,14 @@ Schedules::DeleteSchedule(int id, const Ice::Current & ice) } P2PVR::ScheduleList -Schedules::GetSchedules(const Ice::Current &) +SchedulesI::GetSchedules(const Ice::Current &) { logger->message(LOG::DEBUG, __PRETTY_FUNCTION__); return fetch<P2PVR::ScheduleList>(P2PVR::sql::schedules::selectAll); } P2PVR::SchedulePtr -Schedules::GetSchedule(int id, const Ice::Current &) +SchedulesI::GetSchedule(int id, const Ice::Current &) { logger->messagebf(LOG::DEBUG, "%s(%d)", __PRETTY_FUNCTION__, id); auto schedules = fetch<P2PVR::ScheduleList>(P2PVR::sql::schedules::selectById, id); @@ -324,14 +325,14 @@ Schedules::GetSchedule(int id, const Ice::Current &) } P2PVR::ScheduledToRecordList -Schedules::GetScheduledToRecord(const Ice::Current &) +SchedulesI::GetScheduledToRecord(const Ice::Current &) { logger->message(LOG::DEBUG, __PRETTY_FUNCTION__); return fetch<P2PVR::ScheduledToRecordList>(P2PVR::sql::schedules::scheduledToRecord); } Ice::Int -Schedules::NewSchedule(const P2PVR::SchedulePtr & s, const Ice::Current & ice) +SchedulesI::NewSchedule(const P2PVR::SchedulePtr & s, const Ice::Current & ice) { auto dbc = db->get(); Slicer::SerializeAny<Slicer::SqlFetchIdInsertSerializer>(s, dbc.get(), "schedules"); @@ -340,12 +341,13 @@ Schedules::NewSchedule(const P2PVR::SchedulePtr & s, const Ice::Current & ice) } void -Schedules::UpdateSchedule(const P2PVR::SchedulePtr & s, const Ice::Current & ice) +SchedulesI::UpdateSchedule(const P2PVR::SchedulePtr & s, const Ice::Current & ice) { auto dbc = db->get(); Slicer::SerializeAny<Slicer::SqlUpdateSerializer>(s, dbc.get(), "schedules"); DoReschedule(ice); } +} -INSTANTIATEFACTORY(EpisodeGroup, const Episodes &); +INSTANTIATEFACTORY(P2PVR::EpisodeGroup, const P2PVR::Episodes &); diff --git a/p2pvr/daemon/schedules.h b/p2pvr/daemon/schedules.h index 1acf69f..558c127 100644 --- a/p2pvr/daemon/schedules.h +++ b/p2pvr/daemon/schedules.h @@ -9,6 +9,7 @@ #include <intrusivePtrBase.h> #include <logger.h> +namespace P2PVR { typedef boost::posix_time::ptime datetime; class Episode; @@ -64,7 +65,7 @@ class EpisodeGroup { Showings selected; }; -class DLL_PUBLIC Schedules : public P2PVR::Schedules, public IceTray::AbstractDatabaseClient { +class DLL_PUBLIC SchedulesI : public Schedules, public IceTray::AbstractDatabaseClient { public: class Options : public IceTray::Options { public: @@ -75,14 +76,14 @@ class DLL_PUBLIC Schedules : public P2PVR::Schedules, public IceTray::AbstractDa std::string SchedulerAlgorithm; }; - Schedules(IceTray::DatabasePoolPtr); + SchedulesI(IceTray::DatabasePoolPtr); void DeleteSchedule(int id, const Ice::Current &); - P2PVR::SchedulePtr GetSchedule(int id, const Ice::Current &); - P2PVR::ScheduleList GetSchedules(const Ice::Current &); - P2PVR::ScheduledToRecordList GetScheduledToRecord(const Ice::Current &); - Ice::Int NewSchedule(const P2PVR::SchedulePtr &, const Ice::Current &); - void UpdateSchedule(const P2PVR::SchedulePtr &, const Ice::Current &); + SchedulePtr GetSchedule(int id, const Ice::Current &); + ScheduleList GetSchedules(const Ice::Current &); + ScheduledToRecordList GetScheduledToRecord(const Ice::Current &); + Ice::Int NewSchedule(const SchedulePtr &, const Ice::Current &); + void UpdateSchedule(const SchedulePtr &, const Ice::Current &); void DoReschedule(const Ice::Current &); protected: @@ -95,6 +96,7 @@ class DLL_PUBLIC Schedules : public P2PVR::Schedules, public IceTray::AbstractDa typedef AdHoc::Factory<EpisodeGroup, const Episodes &> EpisodeGroupFactory; typedef boost::shared_ptr<EpisodeGroup> EpisodeGroupPtr; +} #endif diff --git a/p2pvr/daemon/si.cpp b/p2pvr/daemon/si.cpp index bee7fa7..f8a49be 100644 --- a/p2pvr/daemon/si.cpp +++ b/p2pvr/daemon/si.cpp @@ -21,47 +21,48 @@ #include "sql/si/eventsInRange.sql.h" #include "sql/si/eventSearch.sql.h" -IceTray::Logging::LoggerPtr SI::logger(LOGMANAGER()->getLogger<SI>()); +namespace P2PVR { +IceTray::Logging::LoggerPtr SII::logger(LOGMANAGER()->getLogger<SII>()); -SI::SI(IceTray::DatabasePoolPtr db) : +SII::SII(IceTray::DatabasePoolPtr db) : IceTray::AbstractDatabaseClient(db) { } DVBSI::Networks -SI::GetNetworks(const Ice::Current &) +SII::GetNetworks(const Ice::Current &) { logger->message(LOG::DEBUG, __PRETTY_FUNCTION__); - return fetch<DVBSI::Networks>(P2PVR::sql::si::allNetworks); + return fetch<DVBSI::Networks>(sql::si::allNetworks); } -P2PVR::Deliveries -SI::GetAllDeliveries(const Ice::Current &) +Deliveries +SII::GetAllDeliveries(const Ice::Current &) { logger->message(LOG::DEBUG, __PRETTY_FUNCTION__); - auto rtn = fetch<P2PVR::Deliveries>("delivery_type", P2PVR::sql::si::allDeliveries); + auto rtn = fetch<Deliveries>("delivery_type", sql::si::allDeliveries); logger->messagebf(LOG::DEBUG, "%s: Found %d delivery methods", __PRETTY_FUNCTION__, rtn.size()); return rtn; } DVBSI::DeliveryPtr -SI::GetDeliveryForTransport(int id, const Ice::Current&) +SII::GetDeliveryForTransport(int id, const Ice::Current&) { try { logger->messagef(LOG::DEBUG, "%s(%d)", __PRETTY_FUNCTION__, id); - return fetch<DVBSI::DeliveryPtr>("delivery_type", P2PVR::sql::si::deliveryForTransport, id); + return fetch<DVBSI::DeliveryPtr>("delivery_type", sql::si::deliveryForTransport, id); } catch (const Slicer::NoRowsReturned &) { - throw P2PVR::NotFound(); + throw NotFound(); } } DVBSI::DeliveryPtr -SI::GetDeliveryForSi(const Ice::Current&) +SII::GetDeliveryForSi(const Ice::Current&) { try { logger->message(LOG::DEBUG, __PRETTY_FUNCTION__); - return fetch<DVBSI::DeliveryPtr>("delivery_type", P2PVR::sql::si::serviceNextUsed); + return fetch<DVBSI::DeliveryPtr>("delivery_type", sql::si::serviceNextUsed); } catch (const Slicer::NoRowsReturned &) { return NULL; @@ -69,101 +70,89 @@ SI::GetDeliveryForSi(const Ice::Current&) } DVBSI::DeliveryPtr -SI::GetDeliveryForService(int id, const Ice::Current&) +SII::GetDeliveryForService(int id, const Ice::Current&) { try { logger->messagef(LOG::DEBUG, "%s(%d)", __PRETTY_FUNCTION__, id); - return fetch<DVBSI::DeliveryPtr>("delivery_type", P2PVR::sql::si::deliveryForService, id); + return fetch<DVBSI::DeliveryPtr>("delivery_type", sql::si::deliveryForService, id); } catch (const Slicer::NoRowsReturned &) { - throw P2PVR::NotFound(); + throw NotFound(); } } DVBSI::ServiceList -SI::GetServices(const Ice::Current&) +SII::GetServices(const Ice::Current&) { logger->message(LOG::DEBUG, __PRETTY_FUNCTION__); - return fetch<DVBSI::ServiceList>(P2PVR::sql::si::servicesSelectAll); + return fetch<DVBSI::ServiceList>(sql::si::servicesSelectAll); } DVBSI::ServicePtr -SI::GetService(int id, const Ice::Current&) +SII::GetService(int id, const Ice::Current&) { logger->messagef(LOG::DEBUG, "%s(%d)", __PRETTY_FUNCTION__, id); - auto rtn = fetch<DVBSI::ServiceList>(P2PVR::sql::si::servicesSelectById, id); - if (rtn.empty()) throw P2PVR::NotFound(); + auto rtn = fetch<DVBSI::ServiceList>(sql::si::servicesSelectById, id); + if (rtn.empty()) throw NotFound(); return rtn.front(); } -P2PVR::Events -SI::GetEvents(const P2PVR::IntSequence & eventUids, const Ice::Current &) +Events +SII::GetEvents(const IntSequence & eventUids, const Ice::Current &) { logger->message(LOG::DEBUG, __PRETTY_FUNCTION__); - P2PVR::Events rtn; + Events rtn; for (const auto & uid : eventUids) { - auto list = fetch<P2PVR::Events>(P2PVR::sql::si::eventByUid, uid); + auto list = fetch<Events>(sql::si::eventByUid, uid); std::copy(list.begin(), list.end(), std::back_inserter(rtn)); } - if (rtn.size() != eventUids.size()) throw P2PVR::NotFound(); + if (rtn.size() != eventUids.size()) throw NotFound(); return rtn; } -P2PVR::EventPtr -SI::GetEvent(int serviceId, int eventId, const Ice::Current &) +EventPtr +SII::GetEvent(int serviceId, int eventId, const Ice::Current &) { logger->messagef(LOG::DEBUG, "%s(s=%d, e=%d)", __PRETTY_FUNCTION__, serviceId, eventId); - auto rtn = fetch<P2PVR::Events>(P2PVR::sql::si::eventById, serviceId, eventId); - if (rtn.empty()) throw P2PVR::NotFound(); + auto rtn = fetch<Events>(sql::si::eventById, serviceId, eventId); + if (rtn.empty()) throw NotFound(); return rtn.front(); } -P2PVR::Events -SI::EventsOnNow(const Ice::Current &) +Events +SII::EventsOnNow(const Ice::Current &) { logger->message(LOG::DEBUG, __PRETTY_FUNCTION__); - return fetch<P2PVR::Events>(P2PVR::sql::si::eventsOnNow); + return fetch<Events>(sql::si::eventsOnNow); } -namespace IceTray { - template<> - void - AbstractDatabaseClient::bind1<Common::DateTime>(int x, DB::Command * cmd, const Common::DateTime &); -} - -template<> -void -IceTray::AbstractDatabaseClient::bind1<Common::DateTime>(int x, DB::Command * cmd, const Common::DateTime & dt) -{ - cmd->bindParamT(x, *dt); -} - -P2PVR::Events -SI::EventsInRange(const Common::DateTime & from, const Common::DateTime & to, const Ice::Current &) +Events +SII::EventsInRange(const Common::DateTime & from, const Common::DateTime & to, const Ice::Current &) { logger->messagebf(LOG::DEBUG, "%s([%s]-[%s])", from, to, __PRETTY_FUNCTION__); - return fetch<P2PVR::Events>(P2PVR::sql::si::eventsInRange, from, to); + return fetch<Events>(sql::si::eventsInRange, from, to); } -P2PVR::Events -SI::EventSearch(const IceUtil::Optional<std::string> & keywords, const IceUtil::Optional<Ice::Int> & serviceId, const IceUtil::Optional<Common::DateTime> & from, const IceUtil::Optional<Common::DateTime> & to, const Ice::Current &) +Events +SII::EventSearch(const IceUtil::Optional<std::string> & keywords, const IceUtil::Optional<Ice::Int> & serviceId, const IceUtil::Optional<Common::DateTime> & from, const IceUtil::Optional<Common::DateTime> & to, const Ice::Current &) { logger->messagebf(LOG::DEBUG, "%s(keywords=%s,serviceId=%s,from=%s,to=%s)", keywords, serviceId, from, to, __PRETTY_FUNCTION__); - return fetch<P2PVR::Events>(P2PVR::sql::si::eventSearch, from, to, serviceId, serviceId, keywords, keywords, keywords, keywords); + return fetch<Events>(sql::si::eventSearch, from, to, serviceId, serviceId, keywords, keywords, keywords, keywords); } -P2PVR::Events -SI::EventsInSchedules(const Ice::Current &) +Events +SII::EventsInSchedules(const Ice::Current &) { logger->message(LOG::DEBUG, __PRETTY_FUNCTION__); - return fetch<P2PVR::Events>(P2PVR::sql::si::eventsInSchedules); + return fetch<Events>(sql::si::eventsInSchedules); } -P2PVR::Events -SI::EventsInSchedule(int scheduleId, const Ice::Current &) +Events +SII::EventsInSchedule(int scheduleId, const Ice::Current &) { logger->messagebf(LOG::DEBUG, "%s(%d)", scheduleId, __PRETTY_FUNCTION__); - return fetch<P2PVR::Events>(P2PVR::sql::si::eventsInSchedule, scheduleId); + return fetch<Events>(sql::si::eventsInSchedule, scheduleId); +} } diff --git a/p2pvr/daemon/si.h b/p2pvr/daemon/si.h index c9080ab..4ee7629 100644 --- a/p2pvr/daemon/si.h +++ b/p2pvr/daemon/si.h @@ -6,12 +6,13 @@ #include <visibility.h> #include <logger.h> -class DLL_PUBLIC SI : public P2PVR::SI, public IceTray::AbstractDatabaseClient { +namespace P2PVR { +class DLL_PUBLIC SII : public SI, public IceTray::AbstractDatabaseClient { public: - SI(IceTray::DatabasePoolPtr); + SII(IceTray::DatabasePoolPtr); DVBSI::Networks GetNetworks(const Ice::Current &); - P2PVR::Deliveries GetAllDeliveries(const Ice::Current &); + Deliveries GetAllDeliveries(const Ice::Current &); DVBSI::DeliveryPtr GetDeliveryForService(int id, const Ice::Current &); DVBSI::DeliveryPtr GetDeliveryForTransport(int id, const Ice::Current &); DVBSI::DeliveryPtr GetDeliveryForSi(const Ice::Current &); @@ -19,16 +20,17 @@ class DLL_PUBLIC SI : public P2PVR::SI, public IceTray::AbstractDatabaseClient { DVBSI::ServiceList GetServices(const Ice::Current &); DVBSI::ServicePtr GetService(int id, const Ice::Current &); - P2PVR::Events GetEvents(const P2PVR::IntSequence & eventUids, const Ice::Current &); - P2PVR::EventPtr GetEvent(int serviceId, int eventId, const Ice::Current &); - P2PVR::Events EventsOnNow(const Ice::Current &); - P2PVR::Events EventsInSchedules(const Ice::Current &); - P2PVR::Events EventsInSchedule(int scheduleId, const Ice::Current &); - P2PVR::Events EventsInRange(const Common::DateTime &, const Common::DateTime &, const Ice::Current &); - P2PVR::Events EventSearch(const IceUtil::Optional<std::string> & keywords, const IceUtil::Optional<Ice::Int> & serviceId, const IceUtil::Optional<Common::DateTime> & from, const IceUtil::Optional<Common::DateTime> & to, const Ice::Current &); + Events GetEvents(const IntSequence & eventUids, const Ice::Current &); + EventPtr GetEvent(int serviceId, int eventId, const Ice::Current &); + Events EventsOnNow(const Ice::Current &); + Events EventsInSchedules(const Ice::Current &); + Events EventsInSchedule(int scheduleId, const Ice::Current &); + Events EventsInRange(const Common::DateTime &, const Common::DateTime &, const Ice::Current &); + Events EventSearch(const IceUtil::Optional<std::string> & keywords, const IceUtil::Optional<Ice::Int> & serviceId, const IceUtil::Optional<Common::DateTime> & from, const IceUtil::Optional<Common::DateTime> & to, const Ice::Current &); static IceTray::Logging::LoggerPtr logger; }; +} #endif diff --git a/p2pvr/daemon/storage.cpp b/p2pvr/daemon/storage.cpp index e443699..51c1924 100644 --- a/p2pvr/daemon/storage.cpp +++ b/p2pvr/daemon/storage.cpp @@ -8,32 +8,33 @@ namespace fs = boost::filesystem; namespace po = boost::program_options; -Storage::Options::Options() : +namespace P2PVR { +StorageI::Options::Options() : IceTray::Options("P2PVR Storage options") { } -ICETRAY_OPTIONS(Storage::Options, +ICETRAY_OPTIONS(StorageI::Options, ("p2pvr.storage.muxercommand", po::value(&muxerCommand)->default_value("/usr/bin/ffmpeg -i - -f mp4 -y ${TARGET}"), "Command to perform TS->PS muxing (default: '/usr/bin/ffmpeg -i - -f mp4 -y ${TARGET}')") ("p2pvr.storage.root", po::value(&root)->default_value("recordings"), "Root folder in which to store recordings") ); -IceTray::Logging::LoggerPtr Storage::logger(LOGMANAGER()->getLogger<Storage>()); +IceTray::Logging::LoggerPtr StorageI::logger(LOGMANAGER()->getLogger<StorageI>()); -P2PVR::RawDataClientPrx -Storage::OpenForWrite(const std::string & id, const Ice::Current & ice) +RawDataClientPrx +StorageI::OpenForWrite(const std::string & id, const Ice::Current & ice) { fs::create_directories(options->root); fs::path path = options->root / id; - P2PVR::RawDataClient * target; + RawDataClient * target; if (options->muxerCommand.empty()) { auto fd = open(path.string().c_str(), O_WRONLY | O_CREAT | O_EXCL, 0664); if (fd < 0) { logger->messagebf(LOG::ERR, "%s: Failed to open file for reading at %s (%d:%s)", __PRETTY_FUNCTION__, path, errno, strerror(errno)); - throw P2PVR::StorageException(path.string(), strerror(errno)); + throw StorageException(path.string(), strerror(errno)); } target = new FileSink(fd); } @@ -46,13 +47,13 @@ Storage::OpenForWrite(const std::string & id, const Ice::Current & ice) } void -Storage::Close(const P2PVR::RawDataClientPrx & file, const Ice::Current &) +StorageI::Close(const RawDataClientPrx & file, const Ice::Current &) { openFiles.erase(std::find_if(openFiles.begin(), openFiles.end(), [&file](const OpenFilePtr & of) { return *of == file; })); } void -Storage::Delete(const std::string & id, const Ice::Current &) +StorageI::Delete(const std::string & id, const Ice::Current &) { fs::path path = options->root / id; logger->messagebf(LOG::INFO, "%s: Deleting %s", __PRETTY_FUNCTION__, path); @@ -60,25 +61,25 @@ Storage::Delete(const std::string & id, const Ice::Current &) } void -Storage::Send(const std::string & id, const P2PVR::RawDataClientPrx & target, Ice::Long start, Ice::Long len, const Ice::Current &) +StorageI::Send(const std::string & id, const RawDataClientPrx & target, Ice::Long start, Ice::Long len, const Ice::Current &) { fs::path path = options->root / id; auto fd = open(path.string().c_str(), O_RDONLY | O_LARGEFILE); if (fd < 0) { logger->messagebf(LOG::ERR, "%s: Failed to open file for reading at %s (%d:%s)", __PRETTY_FUNCTION__, path, errno, strerror(errno)); - throw P2PVR::StorageException(path.string(), strerror(errno)); + throw StorageException(path.string(), strerror(errno)); } lseek(fd, start, SEEK_SET); auto end = std::min<off_t>(fs::file_size(path), start + len); while (start < end) { - P2PVR::Data buf(16 * 1024); + Data buf(16 * 1024); auto r = read(fd, &buf.front(), std::min<size_t>(buf.size(), end - start)); if (r < 0) { logger->messagebf(LOG::ERR, "%s: Failed to read file %s (%d:%s)", __PRETTY_FUNCTION__, path, errno, strerror(errno)); close(fd); - throw P2PVR::StorageException(path.string(), strerror(errno)); + throw StorageException(path.string(), strerror(errno)); } if (target->NewData(buf)) { close(fd); @@ -90,14 +91,15 @@ Storage::Send(const std::string & id, const P2PVR::RawDataClientPrx & target, Ic } Ice::Long -Storage::FileSize(const std::string & id, const Ice::Current &) +StorageI::FileSize(const std::string & id, const Ice::Current &) { fs::path path = options->root / id; try { return fs::file_size(path); } catch (...) { - throw P2PVR::StorageException(path.string(), "Couldn't get file size"); + throw StorageException(path.string(), "Couldn't get file size"); } } +} diff --git a/p2pvr/daemon/storage.h b/p2pvr/daemon/storage.h index d66a5d3..4a2b389 100644 --- a/p2pvr/daemon/storage.h +++ b/p2pvr/daemon/storage.h @@ -10,7 +10,8 @@ #include <visibility.h> #include <logger.h> -class DLL_PUBLIC Storage : public P2PVR::Storage { +namespace P2PVR { +class DLL_PUBLIC StorageI : public Storage { public: class Options : public IceTray::Options { public: @@ -22,19 +23,20 @@ class DLL_PUBLIC Storage : public P2PVR::Storage { boost::filesystem::path root; }; - P2PVR::RawDataClientPrx OpenForWrite(const std::string &, const Ice::Current &) override; - void Close(const P2PVR::RawDataClientPrx & file, const Ice::Current &) override; + RawDataClientPrx OpenForWrite(const std::string &, const Ice::Current &) override; + void Close(const RawDataClientPrx & file, const Ice::Current &) override; void Delete(const std::string &, const Ice::Current &) override; Ice::Long FileSize(const std::string &, const Ice::Current &) override; - void Send(const std::string &, const P2PVR::RawDataClientPrx & target, Ice::Long start, Ice::Long len, const Ice::Current &) override; + void Send(const std::string &, const RawDataClientPrx & target, Ice::Long start, Ice::Long len, const Ice::Current &) override; protected: - typedef TemporaryIceAdapterObject<P2PVR::RawDataClient> OpenFile; + typedef TemporaryIceAdapterObject<RawDataClient> OpenFile; typedef boost::shared_ptr<OpenFile> OpenFilePtr; typedef std::set<OpenFilePtr> OpenFiles; OpenFiles openFiles; IceTray::OptionsResolver<Options> options; static IceTray::Logging::LoggerPtr logger; }; +} #endif diff --git a/p2pvr/daemon/unittests/mockDefs.cpp b/p2pvr/daemon/unittests/mockDefs.cpp index d810719..49066da 100644 --- a/p2pvr/daemon/unittests/mockDefs.cpp +++ b/p2pvr/daemon/unittests/mockDefs.cpp @@ -1,6 +1,8 @@ #include "mockDefs.h" #include <definedDirs.h> +namespace P2PVR { +namespace Testing { SchemaOnlyMockDatabase::SchemaOnlyMockDatabase() : PQ::Mock("user=postgres dbname=postgres", "postgres", { rootDir.parent_path().parent_path() / "datasources" / "schema.sql" }) @@ -23,14 +25,16 @@ StandardMockDatabasePlusOffset::StandardMockDatabasePlusOffset() : } TestClient::TestClient() : - localDevices(getProxy<P2PVR::LocalDevicesPrx>("Devices")), - devices(getProxy<P2PVR::DevicesPrx>("GlobalDevices")), - maint(getProxy<P2PVR::MaintenancePrx>("Maintenance")), - si(getProxy<P2PVR::SIPrx>("SI")), - schedules(getProxy<P2PVR::SchedulesPrx>("Schedules")), - storage(getProxy<P2PVR::StoragePrx>("Storage")), - recorder(getProxy<P2PVR::RecorderPrx>("Recorder")), - recordings(getProxy<P2PVR::RecordingsPrx>("Recordings")) + localDevices(getProxy<LocalDevicesPrx>("Devices")), + devices(getProxy<DevicesPrx>("GlobalDevices")), + maint(getProxy<MaintenancePrx>("Maintenance")), + si(getProxy<SIPrx>("SI")), + schedules(getProxy<SchedulesPrx>("Schedules")), + storage(getProxy<StoragePrx>("Storage")), + recorder(getProxy<RecorderPrx>("Recorder")), + recordings(getProxy<RecordingsPrx>("Recordings")) { } +} +} diff --git a/p2pvr/daemon/unittests/mockDefs.h b/p2pvr/daemon/unittests/mockDefs.h index 6675c2f..2874ef1 100644 --- a/p2pvr/daemon/unittests/mockDefs.h +++ b/p2pvr/daemon/unittests/mockDefs.h @@ -6,6 +6,8 @@ #include <dryice.h> #include <p2pvr.h> +namespace P2PVR { +namespace Testing { #define DECLAREMOCK(Name) class DLL_PUBLIC Name : public PQ::Mock, public IceTray::DryIce { public: Name(); } DECLAREMOCK(SchemaOnlyMockDatabase); @@ -18,15 +20,17 @@ class DLL_PUBLIC TestClient : public IceTray::DryIceClient { public: TestClient(); - P2PVR::LocalDevicesPrx localDevices; - P2PVR::DevicesPrx devices; - P2PVR::MaintenancePrx maint; - P2PVR::SIPrx si; - P2PVR::SchedulesPrx schedules; - P2PVR::StoragePrx storage; - P2PVR::RecorderPrx recorder; - P2PVR::RecordingsPrx recordings; + LocalDevicesPrx localDevices; + DevicesPrx devices; + MaintenancePrx maint; + SIPrx si; + SchedulesPrx schedules; + StoragePrx storage; + RecorderPrx recorder; + RecordingsPrx recordings; }; +} +} #endif diff --git a/p2pvr/daemon/unittests/mockDevices.cpp b/p2pvr/daemon/unittests/mockDevices.cpp index 777d5d3..f0ec930 100644 --- a/p2pvr/daemon/unittests/mockDevices.cpp +++ b/p2pvr/daemon/unittests/mockDevices.cpp @@ -2,22 +2,24 @@ #include <mockTuner.h> #include <Ice/ObjectAdapter.h> -P2PVR::TunerPrx MockDevices::GetTunerSpecific(const DVBSI::DeliveryPtr&, const Ice::Current & ice) +namespace P2PVR { +namespace Testing { +TunerPrx MockDevices::GetTunerSpecific(const DVBSI::DeliveryPtr&, const Ice::Current & ice) { - return P2PVR::PrivateTunerPrx::checkedCast(ice.adapter->addWithUUID(new MockTuner())); + return PrivateTunerPrx::checkedCast(ice.adapter->addWithUUID(new MockTuner())); } -P2PVR::TunerPrx MockDevices::GetTunerAny(const DVBSI::DeliveryPtr&, const Ice::Current & ice) +TunerPrx MockDevices::GetTunerAny(const DVBSI::DeliveryPtr&, const Ice::Current & ice) { - return P2PVR::PrivateTunerPrx::checkedCast(ice.adapter->addWithUUID(new MockTuner())); + return PrivateTunerPrx::checkedCast(ice.adapter->addWithUUID(new MockTuner())); } -P2PVR::PrivateTunerPrx MockDevices::GetPrivateTuner(Ice::Short, const Ice::Current & ice) +PrivateTunerPrx MockDevices::GetPrivateTuner(Ice::Short, const Ice::Current & ice) { - return P2PVR::PrivateTunerPrx::checkedCast(ice.adapter->addWithUUID(new MockTuner())); + return PrivateTunerPrx::checkedCast(ice.adapter->addWithUUID(new MockTuner())); } -void MockDevices::ReleaseTuner(const P2PVR::TunerPrx & tuner, const Ice::Current & ice) +void MockDevices::ReleaseTuner(const TunerPrx & tuner, const Ice::Current & ice) { ice.adapter->remove(tuner->ice_getIdentity()); } @@ -26,4 +28,6 @@ Ice::Int MockDevices::TunerCount(const Ice::Current&) { return 1; } +} +} diff --git a/p2pvr/daemon/unittests/mockDevices.h b/p2pvr/daemon/unittests/mockDevices.h index f6e4c43..be04772 100644 --- a/p2pvr/daemon/unittests/mockDevices.h +++ b/p2pvr/daemon/unittests/mockDevices.h @@ -4,14 +4,18 @@ #include <dvb.h> #include <visibility.h> -class DLL_PUBLIC MockDevices : public P2PVR::Devices { +namespace P2PVR { +namespace Testing { +class DLL_PUBLIC MockDevices : public Devices { public: - P2PVR::TunerPrx GetTunerSpecific(const DVBSI::DeliveryPtr&, const Ice::Current & ice) override; - P2PVR::TunerPrx GetTunerAny(const DVBSI::DeliveryPtr&, const Ice::Current & ice) override; - P2PVR::PrivateTunerPrx GetPrivateTuner(Ice::Short, const Ice::Current & ice) override; - void ReleaseTuner(const P2PVR::TunerPrx & tuner, const Ice::Current & ice) override; + TunerPrx GetTunerSpecific(const DVBSI::DeliveryPtr&, const Ice::Current & ice) override; + TunerPrx GetTunerAny(const DVBSI::DeliveryPtr&, const Ice::Current & ice) override; + PrivateTunerPrx GetPrivateTuner(Ice::Short, const Ice::Current & ice) override; + void ReleaseTuner(const TunerPrx & tuner, const Ice::Current & ice) override; Ice::Int TunerCount(const Ice::Current&) override; }; +} +} #endif diff --git a/p2pvr/daemon/unittests/mockRecorder.cpp b/p2pvr/daemon/unittests/mockRecorder.cpp index 0796aba..0420e69 100644 --- a/p2pvr/daemon/unittests/mockRecorder.cpp +++ b/p2pvr/daemon/unittests/mockRecorder.cpp @@ -1,8 +1,11 @@ #include "mockRecorder.h" +namespace P2PVR { +namespace Testing { void MockRecorder::RefreshSchedules(const Ice::Current &) { - +} +} } diff --git a/p2pvr/daemon/unittests/mockRecorder.h b/p2pvr/daemon/unittests/mockRecorder.h index d76904d..b52020b 100644 --- a/p2pvr/daemon/unittests/mockRecorder.h +++ b/p2pvr/daemon/unittests/mockRecorder.h @@ -4,10 +4,14 @@ #include <p2pvr.h> #include <visibility.h> -class DLL_PUBLIC MockRecorder : public P2PVR::Recorder { +namespace P2PVR { +namespace Testing { +class DLL_PUBLIC MockRecorder : public Recorder { public: void RefreshSchedules(const Ice::Current &) override; }; +} +} #endif diff --git a/p2pvr/daemon/unittests/mockScheduler.cpp b/p2pvr/daemon/unittests/mockScheduler.cpp index 193630d..b19673c 100644 --- a/p2pvr/daemon/unittests/mockScheduler.cpp +++ b/p2pvr/daemon/unittests/mockScheduler.cpp @@ -1,5 +1,7 @@ #include "mockScheduler.h" +namespace P2PVR { +namespace Testing { void MockScheduler::DoReschedule(const::Ice::Current &) { @@ -38,4 +40,6 @@ void MockScheduler::UpdateSchedule(const::P2PVR::SchedulePtr &, const::Ice::Current &) { } +} +} diff --git a/p2pvr/daemon/unittests/mockScheduler.h b/p2pvr/daemon/unittests/mockScheduler.h index c3640f6..f718363 100644 --- a/p2pvr/daemon/unittests/mockScheduler.h +++ b/p2pvr/daemon/unittests/mockScheduler.h @@ -4,16 +4,20 @@ #include <p2pvr.h> #include <visibility.h> -class DLL_PUBLIC MockScheduler : public P2PVR::Schedules { +namespace P2PVR { +namespace Testing { +class DLL_PUBLIC MockScheduler : public Schedules { public: void DoReschedule(const ::Ice::Current&) override; void DeleteSchedule(Ice::Int, const Ice::Current&) override; - P2PVR::SchedulePtr GetSchedule(::Ice::Int, const ::Ice::Current&) override; - P2PVR::ScheduleList GetSchedules(const ::Ice::Current&) override; - P2PVR::ScheduledToRecordList GetScheduledToRecord(const ::Ice::Current&) override; - Ice::Int NewSchedule(const ::P2PVR::SchedulePtr&, const ::Ice::Current&) override; - void UpdateSchedule(const ::P2PVR::SchedulePtr&, const ::Ice::Current&) override; + SchedulePtr GetSchedule(::Ice::Int, const ::Ice::Current&) override; + ScheduleList GetSchedules(const ::Ice::Current&) override; + ScheduledToRecordList GetScheduledToRecord(const ::Ice::Current&) override; + Ice::Int NewSchedule(const SchedulePtr&, const ::Ice::Current&) override; + void UpdateSchedule(const SchedulePtr&, const ::Ice::Current&) override; }; +} +} #endif diff --git a/p2pvr/daemon/unittests/testErrorHandling.cpp b/p2pvr/daemon/unittests/testErrorHandling.cpp index b04c78c..3758aff 100644 --- a/p2pvr/daemon/unittests/testErrorHandling.cpp +++ b/p2pvr/daemon/unittests/testErrorHandling.cpp @@ -16,6 +16,12 @@ #include <temporaryIceAdapterObject.h> #include "mockDefs.h" +using namespace P2PVR; +using namespace P2PVR::Testing; +using namespace P2PVR::DVBSI; + +namespace P2PVR { +namespace Testing { class Core : public StandardMockDatabase { public: Core() @@ -24,25 +30,25 @@ class Core : public StandardMockDatabase { } }; -class TestDataClient : public P2PVR::RawDataClient { +class TestDataClient : public RawDataClient { public: - virtual bool NewData(const P2PVR::Data &, const Ice::Current &) override + virtual bool NewData(const Data &, const Ice::Current &) override { return false; } }; -class FailingTestClient : public P2PVR::RawDataClient { +class FailingTestClient : public RawDataClient { public: - bool NewData(const P2PVR::Data &, const Ice::Current &) override + bool NewData(const Data &, const Ice::Current &) override { - throw P2PVR::DataHandlingException(); + throw DataHandlingException(); } }; class TestNetworkParser : public SiNetworkInformationParser { public: - bool HandleTable(DVBSI::NetworkPtr) override + bool HandleTable(::DVBSI::NetworkPtr) override { return false; } @@ -50,11 +56,13 @@ class TestNetworkParser : public SiNetworkInformationParser { class FailingTestNetworkParser : public SiNetworkInformationParser { public: - bool HandleTable(DVBSI::NetworkPtr) override + bool HandleTable(::DVBSI::NetworkPtr) override { - throw P2PVR::DataHandlingException(); + throw DataHandlingException(); } }; +} +} BOOST_GLOBAL_FIXTURE( Core ); @@ -65,7 +73,7 @@ BOOST_AUTO_TEST_CASE(TestRawDataClient) BOOST_TEST_CHECKPOINT("Setup"); auto del = si->GetDeliveryForSi(); auto gd = devices->GetTunerAny(del); - TemporaryIceAdapterObject<P2PVR::RawDataClient> a(getAdapter(), new TestDataClient()); + TemporaryIceAdapterObject<RawDataClient> a(getAdapter(), new TestDataClient()); BOOST_TEST_CHECKPOINT("Make successful call"); gd->SendNetworkInformation(a); } @@ -75,7 +83,7 @@ BOOST_AUTO_TEST_CASE(TestParser) BOOST_TEST_CHECKPOINT("Setup"); auto del = si->GetDeliveryForSi(); auto gd = devices->GetTunerAny(del); - TemporaryIceAdapterObject<P2PVR::RawDataClient> a(getAdapter(), new TestNetworkParser()); + TemporaryIceAdapterObject<RawDataClient> a(getAdapter(), new TestNetworkParser()); BOOST_TEST_CHECKPOINT("Make successful call"); gd->SendNetworkInformation(a); } @@ -85,9 +93,9 @@ BOOST_AUTO_TEST_CASE(TestRawDataClientWithError) BOOST_TEST_CHECKPOINT("Setup"); auto del = si->GetDeliveryForSi(); auto gd = devices->GetTunerAny(del); - TemporaryIceAdapterObject<P2PVR::RawDataClient> a(getAdapter(), new FailingTestClient()); + TemporaryIceAdapterObject<RawDataClient> a(getAdapter(), new FailingTestClient()); BOOST_TEST_CHECKPOINT("Make failing call"); - BOOST_REQUIRE_THROW(gd->SendNetworkInformation(a), P2PVR::DataHandlingException); + BOOST_REQUIRE_THROW(gd->SendNetworkInformation(a), DataHandlingException); } BOOST_AUTO_TEST_CASE(TestParserWithError) @@ -95,9 +103,9 @@ BOOST_AUTO_TEST_CASE(TestParserWithError) BOOST_TEST_CHECKPOINT("Setup"); auto del = si->GetDeliveryForSi(); auto gd = devices->GetTunerAny(del); - TemporaryIceAdapterObject<P2PVR::RawDataClient> a(getAdapter(), new FailingTestNetworkParser()); + TemporaryIceAdapterObject<RawDataClient> a(getAdapter(), new FailingTestNetworkParser()); BOOST_TEST_CHECKPOINT("Make failing call"); - BOOST_REQUIRE_THROW(gd->SendNetworkInformation(a), P2PVR::DataHandlingException); + BOOST_REQUIRE_THROW(gd->SendNetworkInformation(a), DataHandlingException); } BOOST_AUTO_TEST_SUITE_END() diff --git a/p2pvr/daemon/unittests/testMaint.cpp b/p2pvr/daemon/unittests/testMaint.cpp index e02abae..10e0293 100644 --- a/p2pvr/daemon/unittests/testMaint.cpp +++ b/p2pvr/daemon/unittests/testMaint.cpp @@ -18,6 +18,11 @@ #include "commonHelpers.h" #include <slicer/slicer.h> +using namespace P2PVR; +using namespace P2PVR::Testing; + +namespace P2PVR { +namespace Testing { class TestService : public SchemaOnlyMockDatabase { public: TestService() @@ -26,6 +31,8 @@ class TestService : public SchemaOnlyMockDatabase { replace("Schedules", new MockScheduler()); } }; +} +} BOOST_GLOBAL_FIXTURE( TestService ); diff --git a/p2pvr/daemon/unittests/testRecording.cpp b/p2pvr/daemon/unittests/testRecording.cpp index ca15447..e4dc6c1 100644 --- a/p2pvr/daemon/unittests/testRecording.cpp +++ b/p2pvr/daemon/unittests/testRecording.cpp @@ -19,6 +19,11 @@ #include "temporaryIceAdapterObject.h" #include <slicer/slicer.h> +using namespace P2PVR; +using namespace P2PVR::Testing; + +namespace P2PVR { +namespace Testing { class TestService : public StandardMockDatabase { public: TestService() @@ -28,11 +33,11 @@ class TestService : public StandardMockDatabase { } }; -class MockTarget : public P2PVR::RawDataClient { +class MockTarget : public RawDataClient { public: MockTarget() : bytesReceived(0) { } - bool NewData(const P2PVR::Data & data, const Ice::Current &) override + bool NewData(const Data & data, const Ice::Current &) override { bytesReceived += data.size(); return false; @@ -40,6 +45,8 @@ class MockTarget : public P2PVR::RawDataClient { unsigned int bytesReceived; }; +} +} BOOST_GLOBAL_FIXTURE( TestService ); @@ -49,7 +56,7 @@ BOOST_AUTO_TEST_CASE( streamServiceToTarget ) { BOOST_TEST_CHECKPOINT("Create mock target"); IceUtil::Handle<MockTarget> target = new MockTarget(); - TemporaryIceAdapterObject<P2PVR::RawDataClient> targetPrx(getAdapter(), target); + TemporaryIceAdapterObject<RawDataClient> targetPrx(getAdapter(), target); BOOST_TEST_CHECKPOINT("Create service streamer"); auto ss = ServiceStreamerPtr(new ServiceStreamer(4170, targetPrx, devices, si, getAdapter())); diff --git a/p2pvr/daemon/unittests/testRecordings.cpp b/p2pvr/daemon/unittests/testRecordings.cpp index de28c8b..b12c984 100644 --- a/p2pvr/daemon/unittests/testRecordings.cpp +++ b/p2pvr/daemon/unittests/testRecordings.cpp @@ -15,6 +15,9 @@ #include <boost/lexical_cast.hpp> #include "mockDefs.h" +using namespace P2PVR; +using namespace P2PVR::Testing; + BOOST_GLOBAL_FIXTURE( StandardMockDatabase ); BOOST_FIXTURE_TEST_SUITE( RecCore, TestClient ) diff --git a/p2pvr/daemon/unittests/testSched.cpp b/p2pvr/daemon/unittests/testSched.cpp index aab5102..badf35c 100644 --- a/p2pvr/daemon/unittests/testSched.cpp +++ b/p2pvr/daemon/unittests/testSched.cpp @@ -17,6 +17,11 @@ #include <commonHelpers.h> #include "mockDefs.h" +using namespace P2PVR; +using namespace P2PVR::Testing; + +namespace P2PVR { +namespace Testing { class TestService : public StandardMockDatabasePlusOffset { public: TestService() @@ -25,6 +30,8 @@ class TestService : public StandardMockDatabasePlusOffset { replace("Recorder", new MockRecorder()); } }; +} +} BOOST_GLOBAL_FIXTURE( TestService ); diff --git a/p2pvr/daemon/unittests/testSi.cpp b/p2pvr/daemon/unittests/testSi.cpp index 55998f9..73f92f3 100644 --- a/p2pvr/daemon/unittests/testSi.cpp +++ b/p2pvr/daemon/unittests/testSi.cpp @@ -14,6 +14,9 @@ #include <boost/lexical_cast.hpp> #include "mockDefs.h" +using namespace P2PVR; +using namespace P2PVR::Testing; + BOOST_GLOBAL_FIXTURE( StandardMockDatabase ); BOOST_FIXTURE_TEST_SUITE( SiCore, TestClient ) diff --git a/p2pvr/daemon/unittests/testStorage.cpp b/p2pvr/daemon/unittests/testStorage.cpp index 9e15662..ebbddcc 100644 --- a/p2pvr/daemon/unittests/testStorage.cpp +++ b/p2pvr/daemon/unittests/testStorage.cpp @@ -13,7 +13,12 @@ #include <definedDirs.h> #include "mockDefs.h" +using namespace P2PVR; +using namespace P2PVR::Testing; + const boost::filesystem::path storageRootDir = "/tmp/ut/p2pvr/recordings"; +namespace P2PVR { +namespace Testing { class TestService : public PQ::Mock, public IceTray::DryIce { public: TestService() : @@ -26,6 +31,8 @@ class TestService : public PQ::Mock, public IceTray::DryIce { { } }; +} +} BOOST_GLOBAL_FIXTURE( TestService ); |