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 | |
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
83 files changed, 792 insertions, 521 deletions
diff --git a/libtmdb/tmdb-proxy.h b/libtmdb/tmdb-proxy.h index c5490a3..472e522 100644 --- a/libtmdb/tmdb-proxy.h +++ b/libtmdb/tmdb-proxy.h @@ -1,9 +1,9 @@ #include <tmdb-api.h> #include "httpClient.h" +#include <visibility.h> -#pragma GCC visibility push(default) namespace TMDb { - class Proxy : public API, private HttpClient { + class DLL_PUBLIC Proxy : public API, private HttpClient { public: Proxy(const std::string & baseUrl, const std::string & apikey); @@ -15,5 +15,4 @@ namespace TMDb { TvSeriesPtr GetTvSeries(Ice::Int, const Ice::Current&) override; }; }; -#pragma GCC visibility pop diff --git a/p2pvr/carddaemon/carddaemon.cpp b/p2pvr/carddaemon/carddaemon.cpp index d48bb0c..f7889e8 100644 --- a/p2pvr/carddaemon/carddaemon.cpp +++ b/p2pvr/carddaemon/carddaemon.cpp @@ -4,14 +4,16 @@ #include <Ice/Communicator.h> #include <IceUtil/Timer.h> -class P2PvrCardDaemon : public IceTray::Service { +namespace P2PVR { +class CardDaemon : public IceTray::Service { public: void addObjects(const std::string &, const Ice::CommunicatorPtr & ic, const Ice::StringSeq &, const Ice::ObjectAdapterPtr & adapter) override { IceUtil::TimerPtr timer = new IceUtil::Timer(); - adapter->add(new LocalDevices(adapter, timer), ic->stringToIdentity("Devices")); + adapter->add(new LocalDevicesI(adapter, timer), ic->stringToIdentity("Devices")); } }; -FACTORY(P2PvrCardDaemon, IceTray::ServiceFactory); +FACTORY(CardDaemon, IceTray::ServiceFactory); +} 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 ); diff --git a/p2pvr/devices/frontend.cpp b/p2pvr/devices/frontend.cpp index c1d2c61..c368fda 100644 --- a/p2pvr/devices/frontend.cpp +++ b/p2pvr/devices/frontend.cpp @@ -4,6 +4,8 @@ #include <linux/dvb/frontend.h> #include <factory.impl.h> +namespace P2PVR { +namespace DVB { Frontend::Frontend(Tuner * t, int fd, const struct dvb_frontend_info & i, IceTray::Logging::LoggerPtr log) : tuner(t), frontendFD(fd), @@ -40,5 +42,7 @@ Frontend::FactoryKey(fe_type t) return stringbf("Frontend:%x", t); } -INSTANTIATEFACTORY(Frontend, Tuner *, int, const struct dvb_frontend_info &); +} +} +INSTANTIATEFACTORY(P2PVR::DVB::Frontend, P2PVR::DVB::Tuner *, int, const struct dvb_frontend_info &); diff --git a/p2pvr/devices/frontend.h b/p2pvr/devices/frontend.h index 51399b1..29180f4 100644 --- a/p2pvr/devices/frontend.h +++ b/p2pvr/devices/frontend.h @@ -6,6 +6,8 @@ #include <dvb.h> #include <logger.h> +namespace P2PVR { +namespace DVB { class Tuner; class Frontend { @@ -31,6 +33,8 @@ class Frontend { typedef AdHoc::Factory<Frontend, Tuner *, int, const struct dvb_frontend_info &> FrontendFactory; typedef boost::shared_ptr<Frontend> FrontendPtr; +} +} #endif diff --git a/p2pvr/devices/frontends/ofdm.cpp b/p2pvr/devices/frontends/ofdm.cpp index caa42a6..15602eb 100644 --- a/p2pvr/devices/frontends/ofdm.cpp +++ b/p2pvr/devices/frontends/ofdm.cpp @@ -6,10 +6,13 @@ #define FREQ_OFFSET_MIN 0 #define FREQ_OFFSET_MAX 4 -class Frontend_OFDM : public Frontend { +namespace P2PVR { +namespace DVB { +namespace Frontends { +class OFDM : public Frontend { public: - Frontend_OFDM(Tuner * t, int fd, const struct dvb_frontend_info & i) : - Frontend(t, fd, i, LOGMANAGER()->getLogger<Frontend_OFDM>()) + OFDM(Tuner * t, int fd, const struct dvb_frontend_info & i) : + Frontend(t, fd, i, LOGMANAGER()->getLogger<OFDM>()) { } @@ -156,5 +159,8 @@ class Frontend_OFDM : public Frontend { } }; -NAMEDFACTORY(Frontend::FactoryKey(FE_OFDM), Frontend_OFDM, FrontendFactory); +NAMEDFACTORY(Frontend::FactoryKey(FE_OFDM), OFDM, FrontendFactory); +} +} +} diff --git a/p2pvr/devices/localDevices.cpp b/p2pvr/devices/localDevices.cpp index cbe74a8..ac13a29 100644 --- a/p2pvr/devices/localDevices.cpp +++ b/p2pvr/devices/localDevices.cpp @@ -3,23 +3,24 @@ #include "tuner.h" #include "bindTimerTask.h" -LocalDevices::Devices LocalDevices::devices; -std::mutex LocalDevices::lock; +namespace P2PVR { +LocalDevicesI::Devices LocalDevicesI::devices; +std::mutex LocalDevicesI::lock; -LocalDevices::Options::Options() : +LocalDevicesI::Options::Options() : IceTray::Options("P2PVR Devices") { } -ICETRAY_OPTIONS(LocalDevices::Options, +ICETRAY_OPTIONS(LocalDevicesI::Options, ("p2pvr.localdevices.frontend", boost::program_options::value(&devices), "Frontend of DVB device(s) to use (/dev/dvb/adapterX/frontendY)") ); -IceTray::Logging::LoggerPtr LocalDevices::logger(LOGMANAGER()->getLogger<LocalDevices>()); +IceTray::Logging::LoggerPtr LocalDevicesI::logger(LOGMANAGER()->getLogger<LocalDevicesI>()); -LocalDevices::LocalDevices(Ice::ObjectAdapterPtr adapter, IceUtil::TimerPtr t) : +LocalDevicesI::LocalDevicesI(Ice::ObjectAdapterPtr adapter, IceUtil::TimerPtr t) : timer(t), - clientCheck(new BindTimerTask(boost::bind(&LocalDevices::ClientCheck, this, adapter))) + clientCheck(new BindTimerTask(boost::bind(&LocalDevicesI::ClientCheck, this, adapter))) { for (auto & device : options->devices) { devices.insert({ device, nullptr }); @@ -28,14 +29,14 @@ LocalDevices::LocalDevices(Ice::ObjectAdapterPtr adapter, IceUtil::TimerPtr t) : timer->scheduleRepeated(clientCheck, IceUtil::Time::seconds(30)); } -LocalDevices::~LocalDevices() +LocalDevicesI::~LocalDevicesI() { logger->message(LOG::DEBUG, __PRETTY_FUNCTION__); timer->cancel(clientCheck); } void -LocalDevices::ClientCheck(Ice::ObjectAdapterPtr adapter) +LocalDevicesI::ClientCheck(Ice::ObjectAdapterPtr adapter) { std::lock_guard<std::mutex> g(lock); for (auto & device : devices) { @@ -50,8 +51,8 @@ LocalDevices::ClientCheck(Ice::ObjectAdapterPtr adapter) } } -P2PVR::TunerPrx -LocalDevices::GetTunerSpecific(const DVBSI::DeliveryPtr & delivery, const Ice::Current & ice) +TunerPrx +LocalDevicesI::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); @@ -67,14 +68,14 @@ LocalDevices::GetTunerSpecific(const DVBSI::DeliveryPtr & delivery, const Ice::C if (openTuner == devices.end()) { logger->messagebf(LOG::DEBUG, "%s: None suitable and none free (frequency %d)", __PRETTY_FUNCTION__, delivery->Frequency); - throw P2PVR::NoSuitableDeviceAvailable(); + throw NoSuitableDeviceAvailable(); } logger->messagebf(LOG::DEBUG, "%s: Opening a sharable tuner (frequency %d, frontend %s)", __PRETTY_FUNCTION__, delivery->Frequency, openTuner->first); - P2PVR::PrivateTunerPtr t = new Tuner(openTuner->first); + PrivateTunerPtr t = new DVB::Tuner(openTuner->first); t->TuneTo(delivery, ice); - auto tuner = P2PVR::PrivateTunerPrx::checkedCast(ice.adapter->addWithUUID(t)); + auto tuner = PrivateTunerPrx::checkedCast(ice.adapter->addWithUUID(t)); openTuner->second = OpenTunerPtr(new OpenTuner(delivery, tuner, false)); logger->messagebf(LOG::DEBUG, "%s: Tuned, returning (frequency %d, frontend %s)", @@ -82,8 +83,8 @@ LocalDevices::GetTunerSpecific(const DVBSI::DeliveryPtr & delivery, const Ice::C return tuner; } -P2PVR::TunerPrx -LocalDevices::GetTunerAny(const DVBSI::DeliveryPtr & delivery, const Ice::Current & ice) +TunerPrx +LocalDevicesI::GetTunerAny(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__); @@ -99,14 +100,14 @@ LocalDevices::GetTunerAny(const DVBSI::DeliveryPtr & delivery, const Ice::Curren if (openTuner == devices.end()) { logger->messagebf(LOG::DEBUG, "%s: None suitable and none free (frequency %d)", __PRETTY_FUNCTION__, delivery->Frequency); - throw P2PVR::NoSuitableDeviceAvailable(); + throw NoSuitableDeviceAvailable(); } logger->messagebf(LOG::DEBUG, "%s: Opening a sharable tuner (frequency %d, frontend %s)", __PRETTY_FUNCTION__, delivery->Frequency, openTuner->first); - P2PVR::PrivateTunerPtr t = new Tuner(openTuner->first); + PrivateTunerPtr t = new DVB::Tuner(openTuner->first); t->TuneTo(delivery, ice); - auto tuner = P2PVR::PrivateTunerPrx::checkedCast(ice.adapter->addWithUUID(t)); + auto tuner = PrivateTunerPrx::checkedCast(ice.adapter->addWithUUID(t)); openTuner->second = OpenTunerPtr(new OpenTuner(delivery, tuner, false)); logger->messagebf(LOG::DEBUG, "%s: Tuned, returning (frequency %d, frontend %s)", @@ -114,27 +115,27 @@ LocalDevices::GetTunerAny(const DVBSI::DeliveryPtr & delivery, const Ice::Curren return tuner; } -P2PVR::PrivateTunerPrx -LocalDevices::GetPrivateTuner(short , const Ice::Current & ice) +PrivateTunerPrx +LocalDevicesI::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__); - throw P2PVR::NoSuitableDeviceAvailable(); + throw 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))); + auto tuner = PrivateTunerPrx::checkedCast(ice.adapter->addWithUUID(new DVB::Tuner(openTuner->first))); openTuner->second = OpenTunerPtr(new OpenTuner(NULL, tuner, true)); return tuner; } void -LocalDevices::ReleaseTuner(const P2PVR::TunerPrx & tuner, const Ice::Current & ice) +LocalDevicesI::ReleaseTuner(const TunerPrx & tuner, const Ice::Current & ice) { std::lock_guard<std::mutex> g(lock); logger->messagebf(LOG::DEBUG, "%s", __PRETTY_FUNCTION__); @@ -157,37 +158,38 @@ LocalDevices::ReleaseTuner(const P2PVR::TunerPrx & tuner, const Ice::Current & i } int -LocalDevices::TunerCount(const Ice::Current &) +LocalDevicesI::TunerCount(const Ice::Current &) { std::lock_guard<std::mutex> g(lock); return devices.size(); } void -LocalDevices::Scan(const Ice::Current &) +LocalDevicesI::Scan(const Ice::Current &) { std::lock_guard<std::mutex> g(lock); } void -LocalDevices::Add(const std::string & frontend, const Ice::Current &) +LocalDevicesI::Add(const std::string & frontend, const Ice::Current &) { std::lock_guard<std::mutex> g(lock); devices.insert(Devices::value_type(frontend, OpenTunerPtr())); } void -LocalDevices::Remove(const std::string & frontend, const Ice::Current &) +LocalDevicesI::Remove(const std::string & frontend, const Ice::Current &) { std::lock_guard<std::mutex> g(lock); devices.erase(frontend); } -LocalDevices::OpenTuner::OpenTuner(DVBSI::DeliveryPtr d, P2PVR::PrivateTunerPrx t, bool op) : +LocalDevicesI::OpenTuner::OpenTuner(DVBSI::DeliveryPtr d, PrivateTunerPrx t, bool op) : openedPrivate(op), delivery(d), tuner(t), clients(1) { } +} diff --git a/p2pvr/devices/localDevices.h b/p2pvr/devices/localDevices.h index 7bd97ee..0fd4ad2 100644 --- a/p2pvr/devices/localDevices.h +++ b/p2pvr/devices/localDevices.h @@ -1,7 +1,7 @@ #ifndef LOCALDEVICES_H #define LOCALDEVICES_H -// Local devices implements a device collection (P2PVR::Devices) for any devices physically +// Local devices implements a device collection (Devices) for any devices physically // attached to the local machine; that is, can be accessed directly through /dev/dvb/adapterX #include <dvb.h> @@ -11,7 +11,8 @@ #include <IceUtil/Timer.h> #include <logger.h> -class DLL_PUBLIC LocalDevices : public P2PVR::LocalDevices { +namespace P2PVR { +class DLL_PUBLIC LocalDevicesI : public LocalDevices { public: class Options : public IceTray::Options { public: @@ -22,13 +23,13 @@ class DLL_PUBLIC LocalDevices : public P2PVR::LocalDevices { std::vector<std::string> devices; }; - LocalDevices(Ice::ObjectAdapterPtr adapter, IceUtil::TimerPtr); - ~LocalDevices(); + LocalDevicesI(Ice::ObjectAdapterPtr adapter, IceUtil::TimerPtr); + ~LocalDevicesI(); - 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 &); void Scan(const Ice::Current &); @@ -45,11 +46,11 @@ class DLL_PUBLIC LocalDevices : public P2PVR::LocalDevices { class DLL_PRIVATE OpenTuner { public: - OpenTuner(DVBSI::DeliveryPtr, P2PVR::PrivateTunerPrx, bool); + OpenTuner(DVBSI::DeliveryPtr, PrivateTunerPrx, bool); const bool openedPrivate; const DVBSI::DeliveryPtr delivery; - const P2PVR::PrivateTunerPrx tuner; + const PrivateTunerPrx tuner; unsigned int clients; }; @@ -60,6 +61,7 @@ class DLL_PUBLIC LocalDevices : public P2PVR::LocalDevices { static IceTray::Logging::LoggerPtr logger; IceTray::OptionsResolver<Options> options; }; +} #endif diff --git a/p2pvr/devices/mockTuner.cpp b/p2pvr/devices/mockTuner.cpp index b040128..4430bc4 100644 --- a/p2pvr/devices/mockTuner.cpp +++ b/p2pvr/devices/mockTuner.cpp @@ -11,6 +11,8 @@ extern "C" { \ } \ static const Ice::ByteSeq resource(&resource##_start, &resource##_end); +namespace P2PVR { +namespace Testing { void MockTuner::LZMA_ASSERT(int ret_xz) { @@ -178,4 +180,6 @@ Ice::Long MockTuner::GetLastUsedTime(const Ice::Current&) { return time(NULL); } +} +} diff --git a/p2pvr/devices/mockTuner.h b/p2pvr/devices/mockTuner.h index 60372c9..73ab27c 100644 --- a/p2pvr/devices/mockTuner.h +++ b/p2pvr/devices/mockTuner.h @@ -7,23 +7,25 @@ #include <boost/thread.hpp> #include <logger.h> -class DLL_PUBLIC MockTuner : public P2PVR::PrivateTuner { +namespace P2PVR { +namespace Testing { +class DLL_PUBLIC MockTuner : public PrivateTuner { public: MockTuner(); void TuneTo(const DVBSI::DeliveryPtr &, const Ice::Current&); int GetStatus(const Ice::Current&); - void ScanAndSendNetworkInformation(const P2PVR::RawDataClientPrx & client, const Ice::Current&); - void SendNetworkInformation(const P2PVR::RawDataClientPrx & client, const Ice::Current&); - void SendBouquetAssociations(const P2PVR::RawDataClientPrx & client, const Ice::Current&); - void SendServiceDescriptions(const P2PVR::RawDataClientPrx & client, const Ice::Current&); - void SendProgramMap(Ice::Int pid, const P2PVR::RawDataClientPrx & client, const Ice::Current&); - void SendProgramAssociationTable(const P2PVR::RawDataClientPrx & client, const Ice::Current&); - void SendEventInformation(const P2PVR::RawDataClientPrx & client, const Ice::Current&); + void ScanAndSendNetworkInformation(const RawDataClientPrx & client, const Ice::Current&); + void SendNetworkInformation(const RawDataClientPrx & client, const Ice::Current&); + void SendBouquetAssociations(const RawDataClientPrx & client, const Ice::Current&); + void SendServiceDescriptions(const RawDataClientPrx & client, const Ice::Current&); + void SendProgramMap(Ice::Int pid, const RawDataClientPrx & client, const Ice::Current&); + void SendProgramAssociationTable(const RawDataClientPrx & client, const Ice::Current&); + void SendEventInformation(const RawDataClientPrx & client, const Ice::Current&); - int StartSendingTS(const P2PVR::PacketIds & pids, const P2PVR::RawDataClientPrx & client, const Ice::Current &); - int StartSendingSection(Ice::Int pid, const P2PVR::RawDataClientPrx & client, const Ice::Current &); + int StartSendingTS(const PacketIds & pids, const RawDataClientPrx & client, const Ice::Current &); + int StartSendingSection(Ice::Int pid, const RawDataClientPrx & client, const Ice::Current &); void StopSending(int handle, const Ice::Current &); Ice::Long GetLastUsedTime(const Ice::Current&); @@ -33,8 +35,8 @@ class DLL_PUBLIC MockTuner : public P2PVR::PrivateTuner { protected: static Ice::ByteSeq Decompress(const Ice::ByteSeq &); static void LZMA_ASSERT(int ret_xz); - void DecompressAndSendPackets(const Ice::ByteSeq &, const P2PVR::RawDataClientPrx &, const Ice::Current&) const; - void SendLoop(const P2PVR::RawDataClientPrx & t, const Ice::ByteSeq & dataxz, const Ice::Current & ice) const; + void DecompressAndSendPackets(const Ice::ByteSeq &, const RawDataClientPrx &, const Ice::Current&) const; + void SendLoop(const RawDataClientPrx & t, const Ice::ByteSeq & dataxz, const Ice::Current & ice) const; static int eventSet; std::map<int, boost::thread *> senders; @@ -42,6 +44,8 @@ class DLL_PUBLIC MockTuner : public P2PVR::PrivateTuner { static IceTray::Logging::LoggerPtr logger; }; +} +} #endif diff --git a/p2pvr/devices/tuner.cpp b/p2pvr/devices/tuner.cpp index 148790b..f65fc32 100644 --- a/p2pvr/devices/tuner.cpp +++ b/p2pvr/devices/tuner.cpp @@ -12,6 +12,8 @@ #include "tunerSendSi.h" #include "tunerSendTs.h" +namespace P2PVR { +namespace DVB { IceTray::Logging::LoggerPtr Tuner::logger = LOGMANAGER()->getLogger<Tuner>(); Tuner::Tuner(const boost::filesystem::path & df) : @@ -22,12 +24,12 @@ Tuner::Tuner(const boost::filesystem::path & df) : { int fd = open(deviceFrontend.string().c_str(), O_RDWR); if (fd < 0) { - throw P2PVR::DeviceError(deviceFrontend.string(), strerror(errno), errno); + throw DeviceError(deviceFrontend.string(), strerror(errno), errno); } try { struct dvb_frontend_info fe_info; if (ioctl(fd, FE_GET_INFO, &fe_info) < 0) { - throw P2PVR::DeviceError(deviceFrontend.string(), strerror(errno), errno); + throw DeviceError(deviceFrontend.string(), strerror(errno), errno); } frontend = FrontendPtr(FrontendFactory::createNew(Frontend::FactoryKey(fe_info.type), this, fd, fe_info)); } @@ -79,13 +81,13 @@ Tuner::OpenDemux() const { int demux = open((deviceRoot / "demux0").string().c_str(), O_RDWR | O_NONBLOCK); if (demux < 0) { - throw P2PVR::DeviceError(deviceRoot.string(), strerror(errno), errno); + throw DeviceError(deviceRoot.string(), strerror(errno), errno); } return demux; } void -Tuner::ScanAndSendNetworkInformation(const P2PVR::RawDataClientPrx & client, const Ice::Current & ice) +Tuner::ScanAndSendNetworkInformation(const RawDataClientPrx & client, const Ice::Current & ice) { time(&lastUsedTime); frontend->FrequencyScan([this, &client, &ice](long) { @@ -106,43 +108,43 @@ Tuner::ScanAndSendNetworkInformation(const P2PVR::RawDataClientPrx & client, con } void -Tuner::SendNetworkInformation(const P2PVR::RawDataClientPrx & client, const Ice::Current & ice) +Tuner::SendNetworkInformation(const RawDataClientPrx & client, const Ice::Current & ice) { SendPID(0x10, client, ice); } void -Tuner::SendBouquetAssociations(const P2PVR::RawDataClientPrx & client, const Ice::Current & ice) +Tuner::SendBouquetAssociations(const RawDataClientPrx & client, const Ice::Current & ice) { SendPID(0x11, client, ice); } void -Tuner::SendServiceDescriptions(const P2PVR::RawDataClientPrx & client, const Ice::Current & ice) +Tuner::SendServiceDescriptions(const RawDataClientPrx & client, const Ice::Current & ice) { SendPID(0x11, client, ice); } void -Tuner::SendProgramMap(Ice::Int pid, const P2PVR::RawDataClientPrx & client, const Ice::Current & ice) +Tuner::SendProgramMap(Ice::Int pid, const RawDataClientPrx & client, const Ice::Current & ice) { SendPID(pid, client, ice); } void -Tuner::SendProgramAssociationTable(const P2PVR::RawDataClientPrx & client, const Ice::Current & ice) +Tuner::SendProgramAssociationTable(const RawDataClientPrx & client, const Ice::Current & ice) { SendPID(0x00, client, ice); } void -Tuner::SendEventInformation(const P2PVR::RawDataClientPrx & client, const Ice::Current & ice) +Tuner::SendEventInformation(const RawDataClientPrx & client, const Ice::Current & ice) { SendPID(0x12, client, ice); } uint64_t -Tuner::SendPID(int pid, const P2PVR::RawDataClientPrx & client, const Ice::Current & ice) const +Tuner::SendPID(int pid, const RawDataClientPrx & client, const Ice::Current & ice) const { time(&lastUsedTime); logger->messagebf(LOG::DEBUG, "%s: pid = 0x%x", __PRETTY_FUNCTION__, pid); @@ -165,12 +167,12 @@ Tuner::RequestPID(int pid, int demux) const sctFilterParams.flags = DMX_IMMEDIATE_START; if (ioctl(demux, DMX_SET_FILTER, &sctFilterParams) < 0) { - throw P2PVR::DeviceError("demux", strerror(errno), errno); + throw DeviceError("demux", strerror(errno), errno); } } uint64_t -Tuner::ReadDemuxAndSend(int demux, const P2PVR::RawDataClientPrx & _client) const +Tuner::ReadDemuxAndSend(int demux, const RawDataClientPrx & _client) const { logger->messagebf(LOG::DEBUG, "%s: begin", __PRETTY_FUNCTION__); struct pollfd ufd; @@ -183,20 +185,20 @@ Tuner::ReadDemuxAndSend(int demux, const P2PVR::RawDataClientPrx & _client) cons switch (poll(&ufd, 1, options->DemuxReadTimeout)) { case -1: logger->messagebf(LOG::DEBUG, "%s: poll error reading demux (%d:%s)", __PRETTY_FUNCTION__, errno, strerror(errno)); - throw P2PVR::DeviceError("demux", strerror(errno), errno); + throw DeviceError("demux", strerror(errno), errno); case 0: auto status = frontend->GetStatus(); logger->messagebf(LOG::DEBUG, "%s: Timed out waiting for data (device status 0x%02x)", __PRETTY_FUNCTION__, status); - throw P2PVR::DeviceError("demux", "timeout", 0); + throw DeviceError("demux", "timeout", 0); } // Read it - P2PVR::Data buf(1 << 12); + Data buf(1 << 12); int nr = read(demux, &buf.front(), buf.size()); if (nr < 0) { logger->messagebf(LOG::DEBUG, "%s: error reading demux (%d:%s) status 0x%02x", __PRETTY_FUNCTION__, errno, strerror(errno), frontend->GetStatus()); - throw P2PVR::DeviceError("demux", strerror(errno), errno); + throw DeviceError("demux", strerror(errno), errno); } size_t n = nr; buf.resize(n); @@ -212,7 +214,7 @@ Tuner::ReadDemuxAndSend(int demux, const P2PVR::RawDataClientPrx & _client) cons } int -Tuner::StartSendingSection(int pid, const P2PVR::RawDataClientPrx & client, const Ice::Current &) +Tuner::StartSendingSection(int pid, const RawDataClientPrx & client, const Ice::Current &) { time(&lastUsedTime); logger->message(LOG::DEBUG, __PRETTY_FUNCTION__); @@ -226,12 +228,12 @@ Tuner::StartSendingSection(int pid, const P2PVR::RawDataClientPrx & client, cons } int -Tuner::StartSendingTS(const P2PVR::PacketIds & pids, const P2PVR::RawDataClientPrx & client, const Ice::Current & ice) +Tuner::StartSendingTS(const PacketIds & pids, const RawDataClientPrx & client, const Ice::Current & ice) { time(&lastUsedTime); logger->message(LOG::DEBUG, __PRETTY_FUNCTION__); if (pids.empty()) { - throw P2PVR::DeviceError("demux", "Packet Id list cannot be empty", 0); + throw DeviceError("demux", "Packet Id list cannot be empty", 0); } if (ice.con) { @@ -253,7 +255,7 @@ Tuner::StartSendingTS(const P2PVR::PacketIds & pids, const P2PVR::RawDataClientP if (ioctl(demux, DMX_SET_PES_FILTER, &pesFilterParams) < 0) { backgroundClients.erase(demux); logger->messagebf(LOG::ERR, "%s: DMX_SET_PES_FILTER failed (%d: %s)", __PRETTY_FUNCTION__, errno, strerror(errno)); - throw P2PVR::DeviceError("demux", strerror(errno), errno); + throw DeviceError("demux", strerror(errno), errno); } for (unsigned int x = 1; x < pids.size(); x += 1) { @@ -262,7 +264,7 @@ Tuner::StartSendingTS(const P2PVR::PacketIds & pids, const P2PVR::RawDataClientP if (ioctl(demux, DMX_ADD_PID, &p) < 0) { backgroundClients.erase(demux); logger->messagebf(LOG::ERR, "%s: DMX_ADD_PID failed (%d: %s)", __PRETTY_FUNCTION__, errno, strerror(errno)); - throw P2PVR::DeviceError("demux", strerror(errno), errno); + throw DeviceError("demux", strerror(errno), errno); } } @@ -270,7 +272,7 @@ Tuner::StartSendingTS(const P2PVR::PacketIds & pids, const P2PVR::RawDataClientP if (ioctl(demux, DMX_START) < 0) { backgroundClients.erase(demux); logger->messagebf(LOG::ERR, "%s: DMX_START failed (%d: %s)", __PRETTY_FUNCTION__, errno, strerror(errno)); - throw P2PVR::DeviceError("demux", strerror(errno), errno); + throw DeviceError("demux", strerror(errno), errno); } startSenderThread(); @@ -282,7 +284,7 @@ Tuner::setBufferSize(int demux, unsigned long size) { if (ioctl(demux, DMX_SET_BUFFER_SIZE, size)) { logger->messagebf(LOG::ERR, "%s: DMX_SET_BUFFER_SIZE to %d failed (%d: %s)", __PRETTY_FUNCTION__, size, errno, strerror(errno)); - throw P2PVR::DeviceError("demux", strerror(errno), errno); + throw DeviceError("demux", strerror(errno), errno); } logger->messagebf(LOG::DEBUG, "%s: DMX_SET_BUFFER_SIZE to %d", __PRETTY_FUNCTION__, size); } @@ -333,7 +335,7 @@ Tuner::senderThread() for (auto c = backgroundClients.begin(); c != backgroundClients.end(); ) { if (FD_ISSET(c->first, &rfds)) { // Read it - P2PVR::Data buf(1 << 16); + Data buf(1 << 16); int nr = read(c->first, &buf.front(), buf.size()); if (nr < 0) { logger->messagebf(LOG::DEBUG, "%s: read failed (%d:%s)", __PRETTY_FUNCTION__, errno, strerror(errno)); @@ -377,7 +379,7 @@ Tuner::GetLastUsedTime(const Ice::Current &) return lastUsedTime; } -Tuner::IDataSender::IDataSender(const P2PVR::RawDataClientPrx & c) : +Tuner::IDataSender::IDataSender(const RawDataClientPrx & c) : _packetsSent(0), client(c) { @@ -412,4 +414,6 @@ ICETRAY_OPTIONS(Tuner::Options, ("p2pvr.tuner.demuxstreambuffersize", po::value(&DemuxStreamBufferSize)->default_value(1024*1024), "Kernel buffer size for demux stream data (bytes, default 1MB)") ) +} +} diff --git a/p2pvr/devices/tuner.h b/p2pvr/devices/tuner.h index 42f2948..e170002 100644 --- a/p2pvr/devices/tuner.h +++ b/p2pvr/devices/tuner.h @@ -13,20 +13,26 @@ #include <options.h> #include <logger.h> -class Tuner : public P2PVR::PrivateTuner { +namespace P2PVR { +namespace DVB { +namespace Frontends { + class OFDM; +} + +class Tuner : public PrivateTuner { public: class IDataSender { public: - IDataSender(const P2PVR::RawDataClientPrx &); + IDataSender(const RawDataClientPrx &); virtual ~IDataSender() = 0; - virtual void NewData(const P2PVR::Data &) = 0; + virtual void NewData(const Data &) = 0; virtual bool IsFinished() = 0; uint64_t PacketsSent() const; protected: uint64_t _packetsSent; - const P2PVR::RawDataClientPrx client; + const RawDataClientPrx client; }; typedef boost::shared_ptr<IDataSender> BackgroundClient; typedef std::map<int, BackgroundClient> BackgroundClients; @@ -38,25 +44,25 @@ class Tuner : public P2PVR::PrivateTuner { int GetStatus(const Ice::Current&); std::string Device() const; - void ScanAndSendNetworkInformation(const P2PVR::RawDataClientPrx & client, const Ice::Current&); - void SendNetworkInformation(const P2PVR::RawDataClientPrx & client, const Ice::Current&); - void SendBouquetAssociations(const P2PVR::RawDataClientPrx & client, const Ice::Current&); - void SendServiceDescriptions(const P2PVR::RawDataClientPrx & client, const Ice::Current&); - void SendProgramMap(Ice::Int pid, const P2PVR::RawDataClientPrx & client, const Ice::Current&); - void SendProgramAssociationTable(const P2PVR::RawDataClientPrx & client, const Ice::Current&); - void SendEventInformation(const P2PVR::RawDataClientPrx & client, const Ice::Current&); + void ScanAndSendNetworkInformation(const RawDataClientPrx & client, const Ice::Current&); + void SendNetworkInformation(const RawDataClientPrx & client, const Ice::Current&); + void SendBouquetAssociations(const RawDataClientPrx & client, const Ice::Current&); + void SendServiceDescriptions(const RawDataClientPrx & client, const Ice::Current&); + void SendProgramMap(Ice::Int pid, const RawDataClientPrx & client, const Ice::Current&); + void SendProgramAssociationTable(const RawDataClientPrx & client, const Ice::Current&); + void SendEventInformation(const RawDataClientPrx & client, const Ice::Current&); - int StartSendingTS(const P2PVR::PacketIds & pids, const P2PVR::RawDataClientPrx & client, const Ice::Current &); - int StartSendingSection(Ice::Int pid, const P2PVR::RawDataClientPrx & client, const Ice::Current &); + int StartSendingTS(const PacketIds & pids, const RawDataClientPrx & client, const Ice::Current &); + int StartSendingSection(Ice::Int pid, const RawDataClientPrx & client, const Ice::Current &); void StopSending(int handle, const Ice::Current &); Ice::Long GetLastUsedTime(const Ice::Current&); private: int OpenDemux() const; - uint64_t SendPID(int pid, const P2PVR::RawDataClientPrx & client, const Ice::Current &) const; + uint64_t SendPID(int pid, const RawDataClientPrx & client, const Ice::Current &) const; void RequestPID(int pid, int fd) const; - uint64_t ReadDemuxAndSend(int fd, const P2PVR::RawDataClientPrx & client) const; + uint64_t ReadDemuxAndSend(int fd, const RawDataClientPrx & client) const; void startSenderThread(); void senderThread(); static void setBufferSize(int fd, unsigned long bytes); @@ -86,9 +92,11 @@ class Tuner : public P2PVR::PrivateTuner { }; private: - friend class Frontend_OFDM; + friend class Frontends::OFDM; IceTray::OptionsResolver<Options> options; }; +} +} #endif diff --git a/p2pvr/devices/tunerSendSi.cpp b/p2pvr/devices/tunerSendSi.cpp index c8a8310..0215e47 100644 --- a/p2pvr/devices/tunerSendSi.cpp +++ b/p2pvr/devices/tunerSendSi.cpp @@ -3,9 +3,11 @@ #include <boost/crc.hpp> #include "siParsers/table.h" +namespace P2PVR { +namespace DVB { IceTray::Logging::LoggerPtr SendSi::logger(LOGMANAGER()->getLogger<SendSi>()); -SendSi::SendSi(const P2PVR::RawDataClientPrx & c) : +SendSi::SendSi(const RawDataClientPrx & c) : Tuner::IDataSender(c->ice_collocationOptimized(false)) { } @@ -15,7 +17,7 @@ SendSi::~SendSi() } void -SendSi::NewData(const P2PVR::Data & buf) +SendSi::NewData(const Data & buf) { if (!IsValidSection(buf)) { return; @@ -48,15 +50,15 @@ SendSi::IsFinished() } bool -SendSi::IsValidSection(const P2PVR::Data & buf) +SendSi::IsValidSection(const Data & buf) { auto n = buf.size(); - if (n < sizeof(SiTableHeader)) { + if (n < sizeof(DVBSI::SiTableHeader)) { logger->messagebf(LOG::WARNING, "Received data too small to be an SI table."); return false; } - auto * tab = (const SiTableHeader *)(&buf.front()); - size_t l = sizeof(SiTableHeaderBase) + HILO(tab->section_length); + auto * tab = (const DVBSI::SiTableHeader *)(&buf.front()); + size_t l = sizeof(DVBSI::SiTableHeaderBase) + HILO(tab->section_length); if (n < l) { logger->messagebf(LOG::WARNING, "Received data shorter than its defined length."); return false; @@ -73,10 +75,12 @@ SendSi::IsValidSection(const P2PVR::Data & buf) } bool -SendSi::crc32(const P2PVR::Data & buf) +SendSi::crc32(const Data & buf) { boost::crc_optimal<32, 0x0, 0xFFFFFFFF, 0x0, true, false> crc; crc.process_bytes(&buf.front(), buf.size()); return crc.checksum() == 0; } +} +} diff --git a/p2pvr/devices/tunerSendSi.h b/p2pvr/devices/tunerSendSi.h index 27d15af..8b146ff 100644 --- a/p2pvr/devices/tunerSendSi.h +++ b/p2pvr/devices/tunerSendSi.h @@ -4,6 +4,8 @@ #include "tuner.h" #include <logger.h> +namespace P2PVR { +namespace DVB { class SendSi : public Tuner::IDataSender { public: SendSi(const P2PVR::RawDataClientPrx &); @@ -20,6 +22,8 @@ class SendSi : public Tuner::IDataSender { bool finish; static IceTray::Logging::LoggerPtr logger; }; +} +} #endif diff --git a/p2pvr/devices/tunerSendTs.cpp b/p2pvr/devices/tunerSendTs.cpp index 6d4e3e1..8005311 100644 --- a/p2pvr/devices/tunerSendTs.cpp +++ b/p2pvr/devices/tunerSendTs.cpp @@ -1,6 +1,8 @@ #include "tunerSendTs.h" #include <logger.h> +namespace P2PVR { +namespace DVB { // ~64kb of TS packets #define TARGET_BUFFER_SIZE (350 * 188) // About the ICE message size limit @@ -8,7 +10,7 @@ IceTray::Logging::LoggerPtr SendTs::logger(LOGMANAGER()->getLogger<SendTs>()); -SendTs::SendTs(const P2PVR::RawDataClientPrx & c) : +SendTs::SendTs(const RawDataClientPrx & c) : Tuner::IDataSender(c->ice_collocationOptimized(false)) { buffer.reserve(TARGET_BUFFER_SIZE); @@ -30,7 +32,7 @@ SendTs::~SendTs() } void -SendTs::NewData(const P2PVR::Data & buf) +SendTs::NewData(const Data & buf) { buffer.insert(buffer.end(), buf.begin(), buf.end()); if (!async && buffer.size() >= TARGET_BUFFER_SIZE) { @@ -43,7 +45,7 @@ SendTs::sendBufferChunk() { if (buffer.size() > TARGET_BUFFER_LIMIT) { auto breakPoint = buffer.begin() + TARGET_BUFFER_LIMIT; - async = client->begin_NewData(P2PVR::Data(buffer.begin(), breakPoint)); + async = client->begin_NewData(Data(buffer.begin(), breakPoint)); buffer.erase(buffer.begin(), breakPoint); } else { @@ -74,5 +76,6 @@ SendTs::IsFinished() return true; } } - +} +} diff --git a/p2pvr/devices/tunerSendTs.h b/p2pvr/devices/tunerSendTs.h index 162248d..cd74198 100644 --- a/p2pvr/devices/tunerSendTs.h +++ b/p2pvr/devices/tunerSendTs.h @@ -4,6 +4,8 @@ #include "tuner.h" #include <logger.h> +namespace P2PVR { +namespace DVB { class SendTs : public Tuner::IDataSender { public: SendTs(const P2PVR::RawDataClientPrx &); @@ -19,6 +21,8 @@ class SendTs : public Tuner::IDataSender { P2PVR::Data buffer; static IceTray::Logging::LoggerPtr logger; }; +} +} #endif diff --git a/p2pvr/dvb/bindDataHandler.cpp b/p2pvr/dvb/bindDataHandler.cpp index cb4fd69..7b25b91 100644 --- a/p2pvr/dvb/bindDataHandler.cpp +++ b/p2pvr/dvb/bindDataHandler.cpp @@ -1,12 +1,16 @@ #include "bindDataHandler.h" +namespace P2PVR { +namespace DVBSI { BindDataHandler::BindDataHandler(const Callback & cb) : callBack(cb) { } -bool BindDataHandler::NewData(const P2PVR::Data & data, const Ice::Current &) +bool BindDataHandler::NewData(const Data & data, const Ice::Current &) { return callBack(data); } +} +} diff --git a/p2pvr/dvb/bindDataHandler.h b/p2pvr/dvb/bindDataHandler.h index bf2034a..acbe6df 100644 --- a/p2pvr/dvb/bindDataHandler.h +++ b/p2pvr/dvb/bindDataHandler.h @@ -5,16 +5,20 @@ #include <visibility.h> #include <dvb.h> -class DLL_PUBLIC BindDataHandler : public P2PVR::RawDataClient { +namespace P2PVR { +namespace DVBSI { +class DLL_PUBLIC BindDataHandler : public RawDataClient { public: - typedef boost::function<bool(const P2PVR::Data &)> Callback; + typedef boost::function<bool(const Data &)> Callback; BindDataHandler(const Callback & cb); - bool NewData(const P2PVR::Data & data, const Ice::Current &) override; + bool NewData(const Data & data, const Ice::Current &) override; private: const Callback callBack; }; +} +} #endif diff --git a/p2pvr/dvb/bindSiParserHandler.h b/p2pvr/dvb/bindSiParserHandler.h index a4813c2..d5fadf7 100644 --- a/p2pvr/dvb/bindSiParserHandler.h +++ b/p2pvr/dvb/bindSiParserHandler.h @@ -3,6 +3,8 @@ #include <boost/function.hpp> +namespace P2PVR { +namespace DVBSI { template <typename SIObject, typename Base> class BindSiParserHandler : public Base { public: @@ -20,6 +22,8 @@ class BindSiParserHandler : public Base { private: const Callback callBack; }; +} +} #endif diff --git a/p2pvr/dvb/siParsers/event.cpp b/p2pvr/dvb/siParsers/event.cpp index bea4747..6e290c0 100644 --- a/p2pvr/dvb/siParsers/event.cpp +++ b/p2pvr/dvb/siParsers/event.cpp @@ -10,6 +10,8 @@ #include <boost/tuple/tuple_comparison.hpp> #include "event.h" +namespace P2PVR { +namespace DVBSI { struct ShortEvent { char lang_code[3]; uint8_t event_name_length; @@ -73,7 +75,7 @@ static Glib::RefPtr<Glib::Regex> yearRegex = Glib::Regex::create("[[(]([0-9]{4}) static Glib::RefPtr<Glib::Regex> flagsRegex = Glib::Regex::create("[ []+([A-Z,]+)\\]"); void -SiEpgParser::parseDescriptor_ShortEvent(DVBSI::EventPtr current, const u_char * data) +SiEpgParser::parseDescriptor_ShortEvent(::DVBSI::EventPtr current, const u_char * data) { auto * evtdesc = reinterpret_cast<const struct ShortEvent *>(data); StrPtr title, subtitle, desc; @@ -168,7 +170,7 @@ SiEpgParser::parseDescriptor_ShortEvent(DVBSI::EventPtr current, const u_char * } void -SiEpgParser::parseDescriptor_Component(DVBSI::EventPtr current, const u_char * data) +SiEpgParser::parseDescriptor_Component(::DVBSI::EventPtr current, const u_char * data) { auto * dc = reinterpret_cast<const struct Component *>(data); @@ -189,7 +191,7 @@ SiEpgParser::parseDescriptor_Component(DVBSI::EventPtr current, const u_char * d } void -SiEpgParser::parseDescriptor_Content(DVBSI::EventPtr current, const u_char * data) +SiEpgParser::parseDescriptor_Content(::DVBSI::EventPtr current, const u_char * data) { auto nc = reinterpret_cast<const Content *>(data); current->Category = nc->content_nibble_level_1; @@ -198,7 +200,7 @@ SiEpgParser::parseDescriptor_Content(DVBSI::EventPtr current, const u_char * dat } void -SiEpgParser::parseDescriptor_ParentalRating(DVBSI::EventPtr current, const u_char * data) +SiEpgParser::parseDescriptor_ParentalRating(::DVBSI::EventPtr current, const u_char * data) { auto * pr = reinterpret_cast<const ParentalRating *>(data); switch (pr->rating) { @@ -219,7 +221,7 @@ SiEpgParser::CheckTableId(u_char tableId) const } bool -SiEpgParser::HandleTable(DVBSI::EitInformationPtr) +SiEpgParser::HandleTable(::DVBSI::EitInformationPtr) { return false; } @@ -236,13 +238,13 @@ operator<<(Common::DateTime & dt, const boost::posix_time::ptime & pt) } void -SiEpgParser::ParseSiTable(const EventInformation * eit, DVBSI::EitInformationPtr ei) +SiEpgParser::ParseSiTable(const EventInformation * eit, ::DVBSI::EitInformationPtr ei) { ei->ServiceId = ntohs(eit->header.content_id); ei->TransportStreamId = ntohs(eit->TransportStreamId); ei->OriginalNetworkId = ntohs(eit->OriginalNetworkId); LoopOver<EventDescriptor>(eit->data, HILO(eit->header.section_length) - 15, [this,ei](const EventDescriptor * ed) { - DVBSI::EventPtr e = new DVBSI::Event(); + ::DVBSI::EventPtr e = new ::DVBSI::Event(); e->EventId = ntohs(ed->EventId); e->ServiceId = ei->ServiceId; // <ew> @@ -261,4 +263,6 @@ SiEpgParser::ParseSiTable(const EventInformation * eit, DVBSI::EitInformationPtr HandleTable(e); }); } +} +} diff --git a/p2pvr/dvb/siParsers/event.h b/p2pvr/dvb/siParsers/event.h index 5baadd4..5c331be 100644 --- a/p2pvr/dvb/siParsers/event.h +++ b/p2pvr/dvb/siParsers/event.h @@ -5,6 +5,8 @@ #include <dvbsi.h> #include <visibility.h> +namespace P2PVR { +namespace DVBSI { struct EventInformation { SiTableHeader header; uint16_t TransportStreamId; @@ -14,23 +16,25 @@ struct EventInformation { u_char data[]; } __attribute__((packed)); -class DLL_PUBLIC SiEpgParser : public SiTableParser<EventInformation, DVBSI::EitInformationPtr, int> { +class DLL_PUBLIC SiEpgParser : public SiTableParser<EventInformation, ::DVBSI::EitInformationPtr, int> { protected: bool CheckTableId(u_char tableId) const; int SectionNumberShift() const { return 3; } uint8_t FirstTableId(const EventInformation * ei) { return (ei->header.tableid >= 0x60 ? 0x60 : 0x50); } uint8_t LastTableId(const EventInformation * ei) { return ei->LastTableId; } - void ParseSiTable(const EventInformation * eit, DVBSI::EitInformationPtr); - bool HandleTable(DVBSI::EitInformationPtr); - virtual bool HandleTable(DVBSI::EventPtr) = 0; + void ParseSiTable(const EventInformation * eit, ::DVBSI::EitInformationPtr); + bool HandleTable(::DVBSI::EitInformationPtr); + virtual bool HandleTable(::DVBSI::EventPtr) = 0; private: - DLL_PRIVATE static void parseStartTimeAndDuration(DVBSI::EventPtr, const u_char * data); - DLL_PRIVATE static void parseDescriptor_ShortEvent(DVBSI::EventPtr, const u_char * data); - DLL_PRIVATE static void parseDescriptor_Component(DVBSI::EventPtr, const u_char * data); - DLL_PRIVATE static void parseDescriptor_Content(DVBSI::EventPtr, const u_char * data); - DLL_PRIVATE static void parseDescriptor_ParentalRating(DVBSI::EventPtr, const u_char * data); + DLL_PRIVATE static void parseStartTimeAndDuration(::DVBSI::EventPtr, const u_char * data); + DLL_PRIVATE static void parseDescriptor_ShortEvent(::DVBSI::EventPtr, const u_char * data); + DLL_PRIVATE static void parseDescriptor_Component(::DVBSI::EventPtr, const u_char * data); + DLL_PRIVATE static void parseDescriptor_Content(::DVBSI::EventPtr, const u_char * data); + DLL_PRIVATE static void parseDescriptor_ParentalRating(::DVBSI::EventPtr, const u_char * data); }; +} +} #endif diff --git a/p2pvr/dvb/siParsers/network.cpp b/p2pvr/dvb/siParsers/network.cpp index b00ddeb..cca7e9f 100644 --- a/p2pvr/dvb/siParsers/network.cpp +++ b/p2pvr/dvb/siParsers/network.cpp @@ -4,6 +4,19 @@ #include <safeMapFind.h> #include <compileTimeFormatter.h> +namespace AdHoc { + StreamWriterT('x') { + template<typename ... Pn> + static void write(stream & s, const int & p, const Pn & ... pn) + { + s << std::hex << p; + StreamWriter::next(s, pn...); + } + }; +} + +namespace P2PVR { +namespace DVBSI { struct NetworkStreamsHeader { #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ u_char reserved1 :4; @@ -131,13 +144,13 @@ SiNetworkInformationParser::CheckTableId(u_char tableId) const } void -SiNetworkInformationParser::ParseSiTable(const struct NetworkInformation * nit, DVBSI::NetworkPtr n) +SiNetworkInformationParser::ParseSiTable(const struct NetworkInformation * nit, ::DVBSI::NetworkPtr n) { n->NetworkId = ntohs(nit->header.content_id); auto nsh = ParseDescriptors<NetworkStreamsHeader>(nit->data, HILO(nit->network_descriptor_length), 0x40, boost::bind(&SiNetworkInformationParser::parseDescriptor_NetworkName, n, _1, _2)); LoopOver<TransportStream>(nsh->data, HILO(nsh->transport_stream_loop_length), [this,n](const TransportStream * ts) { - DVBSI::NetworkTransportStreamPtr nts = new DVBSI::NetworkTransportStream(); + ::DVBSI::NetworkTransportStreamPtr nts = new ::DVBSI::NetworkTransportStream(); nts->TransportStreamId = ntohs(ts->transportStreamId); nts->NetworkId = n->NetworkId; nts->OriginalNetworkId = ntohs(ts->originalNetworkId); @@ -151,22 +164,11 @@ SiNetworkInformationParser::ParseSiTable(const struct NetworkInformation * nit, } void -SiNetworkInformationParser::parseDescriptor_NetworkName(DVBSI::NetworkPtr n, const u_char * p, size_t len) +SiNetworkInformationParser::parseDescriptor_NetworkName(::DVBSI::NetworkPtr n, const u_char * p, size_t len) { n->Name = *convert((const char *)p, len); } -namespace AdHoc { - StreamWriterT('x') { - template<typename ... Pn> - static void write(stream & s, const int & p, const Pn & ... pn) - { - s << std::hex << p; - StreamWriter::next(s, pn...); - } - }; -} - AdHocFormatter(WhatIsntSupported, "%? %x"); class NotSupported : public std::runtime_error { public: @@ -230,11 +232,11 @@ std::map<short, fe_transmit_mode_t> ttransmitmodes { SINOTSUPPORTED(TransmissionMode); void -SiNetworkInformationParser::parseDescriptor_TerrestrialDelivery(DVBSI::NetworkTransportStreamPtr nts, const u_char * data, size_t len) +SiNetworkInformationParser::parseDescriptor_TerrestrialDelivery(::DVBSI::NetworkTransportStreamPtr nts, const u_char * data, size_t len) { assert(len == sizeof(TerrestrialDeliveryDescriptor)); auto tdd = reinterpret_cast<const TerrestrialDeliveryDescriptor *>(data); - DVBSI::TerrestrialDeliveryPtr td = new DVBSI::TerrestrialDelivery; + ::DVBSI::TerrestrialDeliveryPtr td = new ::DVBSI::TerrestrialDelivery; td->Frequency = ((uint64_t)ntohl(tdd->Frequency)) * 10; td->TransportStreamId = nts->TransportStreamId; td->Bandwidth = AdHoc::safeMapLookup<BandwidthNotSupported>(tbandwidths, tdd->Bandwidth); @@ -252,11 +254,11 @@ SiNetworkInformationParser::parseDescriptor_TerrestrialDelivery(DVBSI::NetworkTr } void -SiNetworkInformationParser::parseDescriptor_CableDelivery(DVBSI::NetworkTransportStreamPtr nts, const u_char * data, size_t len) +SiNetworkInformationParser::parseDescriptor_CableDelivery(::DVBSI::NetworkTransportStreamPtr nts, const u_char * data, size_t len) { assert(len == sizeof(CableDeliveryDescriptor)); auto cdd = reinterpret_cast<const CableDeliveryDescriptor *>(data); - DVBSI::CableDeliveryPtr cd = new DVBSI::CableDelivery; + ::DVBSI::CableDeliveryPtr cd = new ::DVBSI::CableDelivery; cd->Frequency = ((uint64_t)ntohl(cdd->Frequency)) * 10; cd->TransportStreamId = nts->TransportStreamId; cd->FecOuter = cdd->FecOuter; @@ -267,11 +269,11 @@ SiNetworkInformationParser::parseDescriptor_CableDelivery(DVBSI::NetworkTranspor } void -SiNetworkInformationParser::parseDescriptor_SatelliteDelivery(DVBSI::NetworkTransportStreamPtr nts, const u_char * data, size_t len) +SiNetworkInformationParser::parseDescriptor_SatelliteDelivery(::DVBSI::NetworkTransportStreamPtr nts, const u_char * data, size_t len) { assert(len == sizeof(SatelliteDeliveryDescriptor)); auto sdd = reinterpret_cast<const SatelliteDeliveryDescriptor *>(data); - DVBSI::SatelliteDeliveryPtr sd = new DVBSI::SatelliteDelivery; + ::DVBSI::SatelliteDeliveryPtr sd = new ::DVBSI::SatelliteDelivery; sd->Frequency = ((uint64_t)ntohl(sdd->Frequency)) * 10; sd->TransportStreamId = nts->TransportStreamId; sd->OrbitalPosition = ntohs(sdd->OrbitalPosition); @@ -286,7 +288,7 @@ SiNetworkInformationParser::parseDescriptor_SatelliteDelivery(DVBSI::NetworkTran } void -SiNetworkInformationParser::parseDescriptor_ServiceList(DVBSI::NetworkTransportStreamPtr nts, const u_char * data, size_t len) +SiNetworkInformationParser::parseDescriptor_ServiceList(::DVBSI::NetworkTransportStreamPtr nts, const u_char * data, size_t len) { auto end = data + len; while (data < end) { @@ -295,5 +297,6 @@ SiNetworkInformationParser::parseDescriptor_ServiceList(DVBSI::NetworkTransportS data += sizeof(ServiceListDescriptor); } } - +} +} diff --git a/p2pvr/dvb/siParsers/network.h b/p2pvr/dvb/siParsers/network.h index fef11d0..fa2db82 100644 --- a/p2pvr/dvb/siParsers/network.h +++ b/p2pvr/dvb/siParsers/network.h @@ -5,6 +5,8 @@ #include <dvbsi.h> #include <visibility.h> +namespace P2PVR { +namespace DVBSI { struct NetworkInformation { SiTableHeader header; #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ @@ -18,18 +20,20 @@ struct NetworkInformation { u_char data[]; } __attribute__((packed)); -class DLL_PUBLIC SiNetworkInformationParser : public SiTableParser<NetworkInformation, DVBSI::NetworkPtr, u_char> { +class DLL_PUBLIC SiNetworkInformationParser : public SiTableParser<NetworkInformation, ::DVBSI::NetworkPtr, u_char> { protected: bool CheckTableId(u_char tableId) const; - void ParseSiTable(const struct NetworkInformation * nit, DVBSI::NetworkPtr); + void ParseSiTable(const struct NetworkInformation * nit, ::DVBSI::NetworkPtr); private: - DLL_PRIVATE static void parseDescriptor_NetworkName(DVBSI::NetworkPtr, const u_char *data, size_t len); - DLL_PRIVATE static void parseDescriptor_ServiceList(DVBSI::NetworkTransportStreamPtr, const u_char *data, size_t len); - DLL_PRIVATE static void parseDescriptor_TerrestrialDelivery(DVBSI::NetworkTransportStreamPtr, const u_char *data, size_t len); - DLL_PRIVATE static void parseDescriptor_SatelliteDelivery(DVBSI::NetworkTransportStreamPtr, const u_char *data, size_t len); - DLL_PRIVATE static void parseDescriptor_CableDelivery(DVBSI::NetworkTransportStreamPtr, const u_char *data, size_t len); + DLL_PRIVATE static void parseDescriptor_NetworkName(::DVBSI::NetworkPtr, const u_char *data, size_t len); + DLL_PRIVATE static void parseDescriptor_ServiceList(::DVBSI::NetworkTransportStreamPtr, const u_char *data, size_t len); + DLL_PRIVATE static void parseDescriptor_TerrestrialDelivery(::DVBSI::NetworkTransportStreamPtr, const u_char *data, size_t len); + DLL_PRIVATE static void parseDescriptor_SatelliteDelivery(::DVBSI::NetworkTransportStreamPtr, const u_char *data, size_t len); + DLL_PRIVATE static void parseDescriptor_CableDelivery(::DVBSI::NetworkTransportStreamPtr, const u_char *data, size_t len); }; +} +} #endif diff --git a/p2pvr/dvb/siParsers/programAssociation.cpp b/p2pvr/dvb/siParsers/programAssociation.cpp index 0add29e..c3faf3a 100644 --- a/p2pvr/dvb/siParsers/programAssociation.cpp +++ b/p2pvr/dvb/siParsers/programAssociation.cpp @@ -1,5 +1,7 @@ #include "programAssociation.h" +namespace P2PVR { +namespace DVBSI { struct ProgramAssociation { uint16_t program_number; #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ @@ -25,5 +27,6 @@ SiProgramAssociationParser::ParseSiTable(const ProgramAssociationSection * pas, (*pam)[ntohs(sd->program_number)] = HILO(sd->pid); }); } - +} +} diff --git a/p2pvr/dvb/siParsers/programAssociation.h b/p2pvr/dvb/siParsers/programAssociation.h index 3ef44f0..8588e3d 100644 --- a/p2pvr/dvb/siParsers/programAssociation.h +++ b/p2pvr/dvb/siParsers/programAssociation.h @@ -5,6 +5,8 @@ #include <dvbsi.h> #include <visibility.h> +namespace P2PVR { +namespace DVBSI { struct ProgramAssociationSection { SiTableHeader header; u_char data[]; @@ -18,6 +20,8 @@ class DLL_PUBLIC SiProgramAssociationParser : public SiTableParser<ProgramAssoci bool CheckTableId(u_char tableId) const; void ParseSiTable(const struct ProgramAssociationSection * pas, ProgramAssociationMapPtr); }; +} +} #endif diff --git a/p2pvr/dvb/siParsers/programMap.cpp b/p2pvr/dvb/siParsers/programMap.cpp index 448bda0..90bb8cf 100644 --- a/p2pvr/dvb/siParsers/programMap.cpp +++ b/p2pvr/dvb/siParsers/programMap.cpp @@ -1,6 +1,8 @@ #include "programMap.h" #include <boost/bind.hpp> +namespace P2PVR { +namespace DVBSI { struct ProgramMapStream { uint8_t stream_type; #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ @@ -30,12 +32,12 @@ SiProgramMapParser::CheckTableId(u_char tableId) const } void -SiProgramMapParser::ParseSiTable(const struct ProgramMap * pm, DVBSI::ProgramMapPtr pmp) +SiProgramMapParser::ParseSiTable(const struct ProgramMap * pm, ::DVBSI::ProgramMapPtr pmp) { pmp->ServiceId = ntohs(pm->header.content_id); auto pms = ParseDescriptors<ProgramMapStream>(pm->data, HILO(pm->program_info_len)); while (reinterpret_cast<const u_char*>(pms) < &pm->header.section_length_lo + HILO(pm->header.section_length) - 4) { - DVBSI::StreamPtr s = new DVBSI::Stream(); + ::DVBSI::StreamPtr s = new ::DVBSI::Stream(); s->Type = pms->stream_type; s->Id = HILO(pms->elementary_PID); s->ServiceId = pmp->ServiceId; @@ -44,3 +46,6 @@ SiProgramMapParser::ParseSiTable(const struct ProgramMap * pm, DVBSI::ProgramMap pms = ParseDescriptors<ProgramMapStream>(pms->data, HILO(pms->ES_info_length)); } } +} +} + diff --git a/p2pvr/dvb/siParsers/programMap.h b/p2pvr/dvb/siParsers/programMap.h index 14f0c8d..89f8633 100644 --- a/p2pvr/dvb/siParsers/programMap.h +++ b/p2pvr/dvb/siParsers/programMap.h @@ -5,6 +5,8 @@ #include <dvbsi.h> #include <visibility.h> +namespace P2PVR { +namespace DVBSI { struct ProgramMap { SiTableHeader header; #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ @@ -26,13 +28,13 @@ struct ProgramMap { u_char data[]; } __attribute__((packed)); -class DLL_PUBLIC SiProgramMapParser : public SiTableParser<ProgramMap, DVBSI::ProgramMapPtr, u_char> { +class DLL_PUBLIC SiProgramMapParser : public SiTableParser<ProgramMap, ::DVBSI::ProgramMapPtr, u_char> { protected: bool CheckTableId(u_char tableId) const; - void ParseSiTable(const struct ProgramMap * nit, DVBSI::ProgramMapPtr); + void ParseSiTable(const struct ProgramMap * nit, ::DVBSI::ProgramMapPtr); }; +} +} #endif - - diff --git a/p2pvr/dvb/siParsers/service.cpp b/p2pvr/dvb/siParsers/service.cpp index 56452e9..6f4e27b 100644 --- a/p2pvr/dvb/siParsers/service.cpp +++ b/p2pvr/dvb/siParsers/service.cpp @@ -1,6 +1,8 @@ #include "service.h" #include <boost/bind.hpp> +namespace P2PVR { +namespace DVBSI { struct ServiceDescriptor { uint16_t ServiceId; #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ @@ -32,12 +34,12 @@ SiServicesParser::CheckTableId(u_char tableId) const } void -SiServicesParser::ParseSiTable(const TransportStreamDescriptor * tsd, DVBSI::TransportStreamPtr ts) +SiServicesParser::ParseSiTable(const TransportStreamDescriptor * tsd, ::DVBSI::TransportStreamPtr ts) { ts->TransportStreamId = ntohs(tsd->header.content_id); ts->OriginalNetworkId = ntohs(tsd->original_network_id); LoopOver<ServiceDescriptor>(tsd->data, HILO(tsd->header.section_length) - 12, [this,ts](const ServiceDescriptor * sd) { - DVBSI::ServicePtr s = new DVBSI::Service(); + ::DVBSI::ServicePtr s = new ::DVBSI::Service(); s->ServiceId = ntohs(sd->ServiceId); s->TransportStreamId = ts->TransportStreamId; s->EitSchedule = sd->EitSchedule; @@ -52,7 +54,7 @@ SiServicesParser::ParseSiTable(const TransportStreamDescriptor * tsd, DVBSI::Tra } void -SiServicesParser::parseDescriptor_Service(DVBSI::ServicePtr s, const u_char * p, size_t) +SiServicesParser::parseDescriptor_Service(::DVBSI::ServicePtr s, const u_char * p, size_t) { s->Type = p[0]; if (p[1]) { @@ -62,8 +64,10 @@ SiServicesParser::parseDescriptor_Service(DVBSI::ServicePtr s, const u_char * p, } void -SiServicesParser::parseDescriptor_DefaultAuthority(DVBSI::ServicePtr s, const u_char * p, size_t len) +SiServicesParser::parseDescriptor_DefaultAuthority(::DVBSI::ServicePtr s, const u_char * p, size_t len) { s->DefaultAuthority = *convert((const char *)p, len); } +} +} diff --git a/p2pvr/dvb/siParsers/service.h b/p2pvr/dvb/siParsers/service.h index 64ec351..39dd9d7 100644 --- a/p2pvr/dvb/siParsers/service.h +++ b/p2pvr/dvb/siParsers/service.h @@ -5,6 +5,8 @@ #include <dvbsi.h> #include <visibility.h> +namespace P2PVR { +namespace DVBSI { struct TransportStreamDescriptor { SiTableHeader header; uint16_t original_network_id; @@ -12,15 +14,17 @@ struct TransportStreamDescriptor { u_char data[]; } __attribute__((packed)); -class DLL_PUBLIC SiServicesParser : public SiTableParser<TransportStreamDescriptor, DVBSI::TransportStreamPtr, int> { +class DLL_PUBLIC SiServicesParser : public SiTableParser<TransportStreamDescriptor, ::DVBSI::TransportStreamPtr, int> { protected: bool CheckTableId(u_char tableId) const; - void ParseSiTable(const struct TransportStreamDescriptor * nit, DVBSI::TransportStreamPtr); + void ParseSiTable(const struct TransportStreamDescriptor * nit, ::DVBSI::TransportStreamPtr); private: - DLL_PRIVATE static void parseDescriptor_Service(DVBSI::ServicePtr, const u_char *data, size_t len); - DLL_PRIVATE static void parseDescriptor_DefaultAuthority(DVBSI::ServicePtr, const u_char *data, size_t len); + DLL_PRIVATE static void parseDescriptor_Service(::DVBSI::ServicePtr, const u_char *data, size_t len); + DLL_PRIVATE static void parseDescriptor_DefaultAuthority(::DVBSI::ServicePtr, const u_char *data, size_t len); }; +} +} #endif diff --git a/p2pvr/dvb/siParsers/table.cpp b/p2pvr/dvb/siParsers/table.cpp index 455d0a4..40af5fb 100644 --- a/p2pvr/dvb/siParsers/table.cpp +++ b/p2pvr/dvb/siParsers/table.cpp @@ -3,6 +3,8 @@ #include <stdio.h> #include <glibmm.h> +namespace P2PVR { +namespace DVBSI { const std::string SiTableParserBase::ISO10646("ISO-10646"); const std::string SiTableParserBase::EitEncoding("ISO6937"); const std::string SiTableParserBase::UTF8("UTF8"); @@ -71,4 +73,6 @@ SiTableParserBase::convert(const char * txt, size_t len) } return boost::shared_ptr<Glib::ustring>(new Glib::ustring(utf8.get())); } +} +} diff --git a/p2pvr/dvb/siParsers/table.h b/p2pvr/dvb/siParsers/table.h index effcfa2..821bf93 100644 --- a/p2pvr/dvb/siParsers/table.h +++ b/p2pvr/dvb/siParsers/table.h @@ -20,6 +20,8 @@ typedef unsigned char u_char; #define HILO4(x) (x##4 << 24 | x##2 << 16 | x##3 << 8 | x##4) #define BcdCharToInt(x) (10*((x & 0xF0)>>4) + (x & 0xF)) +namespace P2PVR { +namespace DVBSI { class DLL_PUBLIC SiTableParserBase : public P2PVR::RawDataClient { public: const P2PVR::Data & CurrentRawData() const; @@ -210,6 +212,8 @@ class SiTableParser : public SiTableParserBase { private: mutable Contents contents; }; +} +} #endif diff --git a/p2pvr/dvb/unittests/createBroadcast.cpp b/p2pvr/dvb/unittests/createBroadcast.cpp index b910744..ee147f2 100644 --- a/p2pvr/dvb/unittests/createBroadcast.cpp +++ b/p2pvr/dvb/unittests/createBroadcast.cpp @@ -9,12 +9,12 @@ #include <linux/dvb/frontend.h> #include "serviceStreamerCore.h" #include "bindDataHandler.h" +#include <definedDirs.h> -#define XSTR(s) STR(s) -#define STR(s) #s -const boost::filesystem::path root(XSTR(ROOT)); +namespace P2PVR { +namespace Testing { -Ice::StringSeq params { +static Ice::StringSeq params { "--Ice.ThreadPool.Client.Size=5", "--Ice.ThreadPool.Client.SizeMax=10", "--Ice.ThreadPool.Server.Size=5", @@ -29,7 +29,7 @@ class Core { { adapter->activate(); - devs = P2PVR::DevicesPrx::checkedCast(ic->stringToProxy("Devices:tcp -h defiant -p 10000")); + devs = DevicesPrx::checkedCast(ic->stringToProxy("Devices:tcp -h defiant -p 10000")); BOOST_REQUIRE(devs); devs->ice_ping(); } @@ -39,7 +39,7 @@ class Core { ic->destroy(); } - P2PVR::DevicesPrx devs; + DevicesPrx devs; Ice::CommunicatorPtr ic; Ice::ObjectAdapterPtr adapter; @@ -47,29 +47,29 @@ class Core { class Sampler { public: - Sampler(int sid, P2PVR::DevicesPrx d, Ice::ObjectAdapterPtr a) : - patp(a, new BindDataHandler(boost::bind(&Sampler::Handle, this, _1, boost::ref(pat)))), - pmtp(a, new BindDataHandler(boost::bind(&Sampler::Handle, this, _1, boost::ref(pmt)))), - vidp(a, new BindDataHandler(boost::bind(&Sampler::Handle, this, _1, boost::ref(vid)))), + Sampler(int sid, DevicesPrx d, Ice::ObjectAdapterPtr a) : + patp(a, new DVBSI::BindDataHandler(boost::bind(&Sampler::Handle, this, _1, boost::ref(pat)))), + pmtp(a, new DVBSI::BindDataHandler(boost::bind(&Sampler::Handle, this, _1, boost::ref(pmt)))), + vidp(a, new DVBSI::BindDataHandler(boost::bind(&Sampler::Handle, this, _1, boost::ref(vid)))), ss(sid, patp, pmtp, vidp, d, a) { } - TemporaryIceAdapterObject<P2PVR::RawDataClient> patp; - TemporaryIceAdapterObject<P2PVR::RawDataClient> pmtp; - TemporaryIceAdapterObject<P2PVR::RawDataClient> vidp; + TemporaryIceAdapterObject<RawDataClient> patp; + TemporaryIceAdapterObject<RawDataClient> pmtp; + TemporaryIceAdapterObject<RawDataClient> vidp; ServiceStreamerCore ss; - typedef std::list<P2PVR::Data> Sampled; + typedef std::list<Data> Sampled; Sampled pat, pmt, vid; - bool Handle(const P2PVR::Data & data, Sampled & rec) + bool Handle(const Data & data, Sampled & rec) { rec.push_back(data); return false; } - void Start(DVBSI::DeliveryPtr transport) { ss.Start(transport); } + void Start(::DVBSI::DeliveryPtr transport) { ss.Start(transport); } void Stop() { ss.Stop(); } void Save(Ice::CommunicatorPtr ic) @@ -86,16 +86,18 @@ class Sampler { out->write(s); Ice::ByteSeq buf; out->finished(buf); - BOOST_TEST_MESSAGE(root); - auto outFile = fopen((root / fileName).string().c_str(), "w"); + BOOST_TEST_MESSAGE(rootDir); + auto outFile = fopen((rootDir / fileName).string().c_str(), "w"); BOOST_REQUIRE(outFile); BOOST_REQUIRE_EQUAL(1, fwrite(&buf.front(), buf.size(), 1, outFile)); BOOST_REQUIRE_EQUAL(0, fclose(outFile)); } }; +} +} -BOOST_FIXTURE_TEST_SUITE( X, Core ) +BOOST_FIXTURE_TEST_SUITE( X, P2PVR::Testing::Core ) BOOST_AUTO_TEST_CASE( broadcast_sample ) { @@ -111,7 +113,7 @@ BOOST_AUTO_TEST_CASE( broadcast_sample ) tuner->ice_ping(); BOOST_TEST_CHECKPOINT("Create sampler"); - Sampler sampler(4170, devs, adapter); + P2PVR::Testing::Sampler sampler(4170, devs, adapter); BOOST_TEST_CHECKPOINT("Start stream"); sampler.Start(transport); diff --git a/p2pvr/dvb/unittests/createSamples.cpp b/p2pvr/dvb/unittests/createSamples.cpp index f9909af..6c4ef5c 100644 --- a/p2pvr/dvb/unittests/createSamples.cpp +++ b/p2pvr/dvb/unittests/createSamples.cpp @@ -11,11 +11,10 @@ #include <siParsers/network.h> #include <siParsers/service.h> #include <siParsers/event.h> +#include <definedDirs.h> -#define XSTR(s) STR(s) -#define STR(s) #s -const boost::filesystem::path root(XSTR(ROOT)); - +namespace P2PVR { +namespace Testing { template <class Parser> static boost::tuple<Ice::CommunicatorPtr, Ice::ObjectAdapterPtr, Parser *> @@ -48,14 +47,14 @@ class SiSampleCollector : public Base { return false; } - bool NewData(const P2PVR::Data & bytes, const Ice::Current & ice) override + bool NewData(const Data & bytes, const Ice::Current & ice) override { std::lock_guard<std::mutex> g(lock); packets.push_back(bytes); - return SiTableParserBase::NewData(bytes, ice); + return DVBSI::SiTableParserBase::NewData(bytes, ice); } - std::list<P2PVR::Data> packets; + std::list<Data> packets; private: std::mutex lock; @@ -64,7 +63,7 @@ class SiSampleCollector : public Base { template <class Base, class Object> static void -CaptureAndSave(const boost::filesystem::path & fileName, const boost::function<void(P2PVR::TunerPrx, P2PVR::RawDataClientPrx)> & method) +CaptureAndSave(const boost::filesystem::path & fileName, const boost::function<void(TunerPrx, RawDataClientPrx)> & method) { auto icp = standardConfig<SiSampleCollector<Base, Object>>(); auto ic = boost::get<0>(icp); @@ -72,21 +71,21 @@ CaptureAndSave(const boost::filesystem::path & fileName, const boost::function<v auto p = boost::get<2>(icp); AdHoc::ScopeExit _([&ic]{ ic->destroy(); }); - auto devs = P2PVR::DevicesPrx::checkedCast(ic->stringToProxy("Devices:tcp -h defiant -p 10000")); - auto parser = P2PVR::RawDataClientPrx::checkedCast(adap->createProxy(ic->stringToIdentity("parser"))); + auto devs = DevicesPrx::checkedCast(ic->stringToProxy("Devices:tcp -h defiant -p 10000")); + auto parser = RawDataClientPrx::checkedCast(adap->createProxy(ic->stringToIdentity("parser"))); BOOST_REQUIRE(devs); devs->ice_ping(); BOOST_REQUIRE(parser); parser->ice_ping(); - DVBSI::TerrestrialDeliveryPtr transport = new DVBSI::TerrestrialDelivery { + ::DVBSI::TerrestrialDeliveryPtr transport = new ::DVBSI::TerrestrialDelivery { 4170, 682000000, 0, true, true, true, 3, 0, 2, 1, 0, 1, true }; BOOST_REQUIRE_EQUAL(transport->Frequency, 682000000); BOOST_REQUIRE_EQUAL(transport->TransmissionMode, 1); BOOST_TEST_CHECKPOINT("Acquire device"); - P2PVR::TunerPrx tuner = devs->GetTunerAny(transport); + TunerPrx tuner = devs->GetTunerAny(transport); BOOST_REQUIRE(tuner); tuner->ice_ping(); @@ -103,28 +102,34 @@ CaptureAndSave(const boost::filesystem::path & fileName, const boost::function<v out->write(p->packets); Ice::ByteSeq buf; out->finished(buf); - BOOST_TEST_MESSAGE(root); - auto outFile = fopen((root / fileName).string().c_str(), "w"); + BOOST_TEST_MESSAGE(rootDir); + auto outFile = fopen((rootDir / fileName).string().c_str(), "w"); BOOST_REQUIRE(outFile); BOOST_REQUIRE_EQUAL(1, fwrite(&buf.front(), buf.size(), 1, outFile)); BOOST_REQUIRE_EQUAL(0, fclose(outFile)); } +} +} + +using namespace P2PVR; +using namespace P2PVR::Testing; +using namespace P2PVR::DVBSI; BOOST_AUTO_TEST_CASE( network_sample ) { - CaptureAndSave<SiNetworkInformationParser, DVBSI::NetworkPtr>("network.dat", - [](P2PVR::TunerPrx t, P2PVR::RawDataClientPrx rdc) { t->SendNetworkInformation(rdc); }); + CaptureAndSave<SiNetworkInformationParser, ::DVBSI::NetworkPtr>("network.dat", + [](TunerPrx t, RawDataClientPrx rdc) { t->SendNetworkInformation(rdc); }); } BOOST_AUTO_TEST_CASE( services_sample ) { - CaptureAndSave<SiServicesParser, DVBSI::TransportStreamPtr>("services.dat", - [](P2PVR::TunerPrx t, P2PVR::RawDataClientPrx rdc) { t->SendServiceDescriptions(rdc); }); + CaptureAndSave<SiServicesParser, ::DVBSI::TransportStreamPtr>("services.dat", + [](TunerPrx t, RawDataClientPrx rdc) { t->SendServiceDescriptions(rdc); }); } BOOST_AUTO_TEST_CASE( events_sample ) { - CaptureAndSave<SiEpgParser, DVBSI::EventPtr>("events.dat", - [](P2PVR::TunerPrx t, P2PVR::RawDataClientPrx rdc) { t->SendEventInformation(rdc); }); + CaptureAndSave<SiEpgParser, ::DVBSI::EventPtr>("events.dat", + [](TunerPrx t, RawDataClientPrx rdc) { t->SendEventInformation(rdc); }); } diff --git a/p2pvr/lib/bindTimerTask.cpp b/p2pvr/lib/bindTimerTask.cpp index b3a0150..96a7854 100644 --- a/p2pvr/lib/bindTimerTask.cpp +++ b/p2pvr/lib/bindTimerTask.cpp @@ -1,5 +1,6 @@ #include "bindTimerTask.h" +namespace P2PVR { BindTimerTask::BindTimerTask(const Event & e) : event(e) { @@ -10,4 +11,5 @@ BindTimerTask::runTimerTask() { event(); } +} diff --git a/p2pvr/lib/bindTimerTask.h b/p2pvr/lib/bindTimerTask.h index f420ee0..3aff9d0 100644 --- a/p2pvr/lib/bindTimerTask.h +++ b/p2pvr/lib/bindTimerTask.h @@ -5,6 +5,7 @@ #include <IceUtil/Timer.h> #include <visibility.h> +namespace P2PVR { class DLL_PUBLIC BindTimerTask : public IceUtil::TimerTask { public: typedef boost::function<void()> Event; @@ -14,6 +15,7 @@ class DLL_PUBLIC BindTimerTask : public IceUtil::TimerTask { private: const Event event; }; +} #endif diff --git a/p2pvr/lib/fileHandle.cpp b/p2pvr/lib/fileHandle.cpp index 08575b3..e568f44 100644 --- a/p2pvr/lib/fileHandle.cpp +++ b/p2pvr/lib/fileHandle.cpp @@ -2,6 +2,7 @@ #include <unistd.h> #include <stdexcept> +namespace P2PVR { class InvalidFileHandle : public std::runtime_error { public: InvalidFileHandle() : std::runtime_error("Invalid file handle") { } @@ -24,4 +25,5 @@ FileHandle::operator int() const { return fd; } +} diff --git a/p2pvr/lib/fileHandle.h b/p2pvr/lib/fileHandle.h index 0a3b7fc..f2d6929 100644 --- a/p2pvr/lib/fileHandle.h +++ b/p2pvr/lib/fileHandle.h @@ -3,6 +3,7 @@ #include <visibility.h> +namespace P2PVR { class DLL_PUBLIC FileHandle { public: FileHandle(int fd); @@ -16,6 +17,7 @@ class DLL_PUBLIC FileHandle { private: const int fd; }; +} #endif diff --git a/p2pvr/lib/fileSink.cpp b/p2pvr/lib/fileSink.cpp index d3fda8f..295d550 100644 --- a/p2pvr/lib/fileSink.cpp +++ b/p2pvr/lib/fileSink.cpp @@ -1,5 +1,6 @@ #include "fileSink.h" +namespace P2PVR { FileSink::FileSink(const boost::filesystem::path & path) : file(fopen(path.string().c_str(), "w")) { @@ -18,9 +19,10 @@ FileSink::~FileSink() } bool -FileSink::NewData(const P2PVR::Data & data, const Ice::Current &) +FileSink::NewData(const Data & data, const Ice::Current &) { fwrite(&data.front(), data.size(), 1, file); return false; } +} diff --git a/p2pvr/lib/fileSink.h b/p2pvr/lib/fileSink.h index fbd469c..840f995 100644 --- a/p2pvr/lib/fileSink.h +++ b/p2pvr/lib/fileSink.h @@ -6,17 +6,19 @@ #include <dvb.h> #include <visibility.h> -class DLL_PUBLIC FileSink : public P2PVR::RawDataClient { +namespace P2PVR { +class DLL_PUBLIC FileSink : public RawDataClient { public: FileSink(const boost::filesystem::path & path); FileSink(int fd); ~FileSink(); - bool NewData(const P2PVR::Data & data, const Ice::Current &); + bool NewData(const Data & data, const Ice::Current &); private: FILE * const file; }; +} #endif diff --git a/p2pvr/lib/muxer.cpp b/p2pvr/lib/muxer.cpp index 1f306cd..b4a249c 100644 --- a/p2pvr/lib/muxer.cpp +++ b/p2pvr/lib/muxer.cpp @@ -6,11 +6,12 @@ #include <boost/algorithm/string/split.hpp> #include <boost/algorithm/string/classification.hpp> +namespace P2PVR { IceTray::Logging::LoggerPtr Muxer::log(LOGMANAGER()->getLogger<Muxer>()); -class MuxerFailure : public P2PVR::DataHandlingException { }; +class MuxerFailure : public DataHandlingException { }; -Muxer::Muxer(const P2PVR::RawDataClientPrx & t, const std::string & cmd) : +Muxer::Muxer(const RawDataClientPrx & t, const std::string & cmd) : target(t) { std::vector<std::string> params; @@ -31,7 +32,7 @@ Muxer::~Muxer() } bool -Muxer::NewData(const P2PVR::Data & data, const Ice::Current &) +Muxer::NewData(const Data & data, const Ice::Current &) { std::lock_guard<std::mutex> g(lock); for (size_t off = 0; off < data.size(); ) { @@ -96,7 +97,7 @@ Muxer::ReadMuxerAndSend(int waitTime) const else { bool closed = false; if (fd[0].revents & (POLLIN | POLLHUP)) { - P2PVR::Data buf(BUFSIZ); + Data buf(BUFSIZ); auto len = read(fds->fdOut(), &buf.front(), buf.size()); if (len == 0) { // ok, proc exit @@ -110,7 +111,7 @@ Muxer::ReadMuxerAndSend(int waitTime) const target->NewData(buf); } if (fd[1].revents & (POLLIN | POLLHUP)) { - P2PVR::Data buf(BUFSIZ); + Data buf(BUFSIZ); auto len = read(fds->fdError(), &buf.front(), buf.size()); if (len == 0) { // ok, proc exit @@ -132,4 +133,5 @@ Muxer::ReadMuxerAndSend(int waitTime) const } } } +} diff --git a/p2pvr/lib/muxer.h b/p2pvr/lib/muxer.h index 354f229..0888268 100644 --- a/p2pvr/lib/muxer.h +++ b/p2pvr/lib/muxer.h @@ -8,24 +8,26 @@ #include <visibility.h> #include <logger.h> -class DLL_PUBLIC Muxer : public P2PVR::RawDataClient { +namespace P2PVR { +class DLL_PUBLIC Muxer : public RawDataClient { public: - Muxer(const P2PVR::RawDataClientPrx & target, const std::string & cmd); + Muxer(const RawDataClientPrx & target, const std::string & cmd); ~Muxer(); - bool NewData(const P2PVR::Data &, const Ice::Current &); + bool NewData(const Data &, const Ice::Current &); private: DLL_PRIVATE bool ReadWaiting() const; DLL_PRIVATE bool ReadAvailable() const; DLL_PRIVATE bool ReadMuxerAndSend(int wait) const; - const P2PVR::RawDataClientPrx target; + const RawDataClientPrx target; typedef boost::shared_ptr<AdHoc::System::ProcessPipes> ProcessPipesPtr; ProcessPipesPtr fds; mutable std::mutex lock; static IceTray::Logging::LoggerPtr log; }; +} #endif diff --git a/p2pvr/lib/serviceStreamer.cpp b/p2pvr/lib/serviceStreamer.cpp index 2729ca0..7e99008 100644 --- a/p2pvr/lib/serviceStreamer.cpp +++ b/p2pvr/lib/serviceStreamer.cpp @@ -1,6 +1,7 @@ #include "serviceStreamer.h" -ServiceStreamer::ServiceStreamer(int sid, P2PVR::RawDataClientPrx t, const P2PVR::DevicesPrx & d, const P2PVR::SIPrx & s, const Ice::ObjectAdapterPtr & a) : +namespace P2PVR { +ServiceStreamer::ServiceStreamer(int sid, RawDataClientPrx t, const DevicesPrx & d, const SIPrx & s, const Ice::ObjectAdapterPtr & a) : ServiceStreamerCore(sid, t, t, t, d, a), si(s) { @@ -16,4 +17,5 @@ ServiceStreamer::Start() const auto transport = si->GetDeliveryForService(serviceId); ServiceStreamerCore::Start(transport); } +} diff --git a/p2pvr/lib/serviceStreamer.h b/p2pvr/lib/serviceStreamer.h index 230764e..bfed89a 100644 --- a/p2pvr/lib/serviceStreamer.h +++ b/p2pvr/lib/serviceStreamer.h @@ -4,18 +4,20 @@ #include "serviceStreamerCore.h" #include <visibility.h> +namespace P2PVR { class DLL_PUBLIC ServiceStreamer : public ServiceStreamerCore { public: - ServiceStreamer(int sid, P2PVR::RawDataClientPrx, const P2PVR::DevicesPrx & d, const P2PVR::SIPrx & s, const Ice::ObjectAdapterPtr & a); + ServiceStreamer(int sid, RawDataClientPrx, const DevicesPrx & d, const SIPrx & s, const Ice::ObjectAdapterPtr & a); ~ServiceStreamer(); void Start(); private: - P2PVR::SIPrx si; + SIPrx si; }; typedef boost::shared_ptr<ServiceStreamer> ServiceStreamerPtr; +} #endif diff --git a/p2pvr/lib/serviceStreamerCore.cpp b/p2pvr/lib/serviceStreamerCore.cpp index 2667569..c6f637c 100644 --- a/p2pvr/lib/serviceStreamerCore.cpp +++ b/p2pvr/lib/serviceStreamerCore.cpp @@ -2,17 +2,18 @@ #include <boost/bind.hpp> #include "bindSiParserHandler.h" +namespace P2PVR { IceTray::Logging::LoggerPtr ServiceStreamerCore::log(LOGMANAGER()->getLogger<ServiceStreamerCore>()); -ServiceStreamerCore::ServiceStreamerCore(int sid, P2PVR::RawDataClientPrx pat, P2PVR::RawDataClientPrx pmt, P2PVR::RawDataClientPrx ser, - P2PVR::DevicesPrx d, Ice::ObjectAdapterPtr a) : +ServiceStreamerCore::ServiceStreamerCore(int sid, RawDataClientPrx pat, RawDataClientPrx pmt, RawDataClientPrx ser, + DevicesPrx d, Ice::ObjectAdapterPtr a) : adapter(a), devs(d), patTarget(pat), pmtTarget(pmt), serTarget(ser), - patParser(adapter, new BindSiParserHandler<ProgramAssociationMapPtr, SiProgramAssociationParser>(boost::bind(&ServiceStreamerCore::HandlePAT, this, _1))), - pmtParser(adapter, new BindSiParserHandler<DVBSI::ProgramMapPtr, SiProgramMapParser>(boost::bind(&ServiceStreamerCore::HandlePMT, this, _1))), + patParser(adapter, new DVBSI::BindSiParserHandler<DVBSI::ProgramAssociationMapPtr, DVBSI::SiProgramAssociationParser>(boost::bind(&ServiceStreamerCore::HandlePAT, this, _1))), + pmtParser(adapter, new DVBSI::BindSiParserHandler<::DVBSI::ProgramMapPtr, DVBSI::SiProgramMapParser>(boost::bind(&ServiceStreamerCore::HandlePMT, this, _1))), serviceId(sid), patHandle(0), pmtStream(0), pmtHandle(0), serviceHandle(0) { @@ -24,7 +25,7 @@ ServiceStreamerCore::~ServiceStreamerCore() } bool -ServiceStreamerCore::HandlePAT(ProgramAssociationMapPtr pam) +ServiceStreamerCore::HandlePAT(DVBSI::ProgramAssociationMapPtr pam) { const auto p = pam->find(serviceId); if (p != pam->end() && p->second != pmtStream) { @@ -38,7 +39,7 @@ ServiceStreamerCore::HandlePAT(ProgramAssociationMapPtr pam) } bool -ServiceStreamerCore::HandlePMT(DVBSI::ProgramMapPtr pmp) +ServiceStreamerCore::HandlePMT(::DVBSI::ProgramMapPtr pmp) { Streams strms; for (const auto & s : pmp->Streams) { @@ -50,14 +51,14 @@ ServiceStreamerCore::HandlePMT(DVBSI::ProgramMapPtr pmp) streams = strms; log->messagebf(LOG::DEBUG, "%s: Got ProgramMap, switching to %d streams", __PRETTY_FUNCTION__, streams.size()); stopHandle(serviceHandle); - serviceHandle = tuner->StartSendingTS(P2PVR::PacketIds(streams.begin(), streams.end()), serTarget); + serviceHandle = tuner->StartSendingTS(PacketIds(streams.begin(), streams.end()), serTarget); } pmtTarget->NewData(pmtParser.Get()->CurrentRawData()); return false; } void -ServiceStreamerCore::Start(DVBSI::DeliveryPtr transport) +ServiceStreamerCore::Start(::DVBSI::DeliveryPtr transport) { tuner = devs->GetTunerSpecific(transport); patHandle = tuner->StartSendingSection(0, patParser); @@ -81,4 +82,5 @@ ServiceStreamerCore::stopHandle(int & handle) handle = 0; } } +} diff --git a/p2pvr/lib/serviceStreamerCore.h b/p2pvr/lib/serviceStreamerCore.h index 2654193..b53a656 100644 --- a/p2pvr/lib/serviceStreamerCore.h +++ b/p2pvr/lib/serviceStreamerCore.h @@ -11,28 +11,29 @@ #include <visibility.h> #include <logger.h> +namespace P2PVR { class DLL_PUBLIC ServiceStreamerCore { public: - ServiceStreamerCore(int sid, P2PVR::RawDataClientPrx, P2PVR::RawDataClientPrx, P2PVR::RawDataClientPrx, - P2PVR::DevicesPrx, Ice::ObjectAdapterPtr); + ServiceStreamerCore(int sid, RawDataClientPrx, RawDataClientPrx, RawDataClientPrx, + DevicesPrx, Ice::ObjectAdapterPtr); virtual ~ServiceStreamerCore(); - void Start(DVBSI::DeliveryPtr); + void Start(::DVBSI::DeliveryPtr); void Stop(); protected: - bool HandlePAT(ProgramAssociationMapPtr pam); - bool HandlePMT(DVBSI::ProgramMapPtr pmp); + bool HandlePAT(DVBSI::ProgramAssociationMapPtr pam); + bool HandlePMT(::DVBSI::ProgramMapPtr pmp); void stopHandle(int & handle); const Ice::ObjectAdapterPtr & adapter; - P2PVR::DevicesPrx devs; - P2PVR::RawDataClientPrx patTarget; - P2PVR::RawDataClientPrx pmtTarget; - P2PVR::RawDataClientPrx serTarget; - TemporaryIceAdapterObject<SiTableParserBase> patParser; - TemporaryIceAdapterObject<SiTableParserBase> pmtParser; - P2PVR::TunerPrx tuner; + DevicesPrx devs; + RawDataClientPrx patTarget; + RawDataClientPrx pmtTarget; + RawDataClientPrx serTarget; + TemporaryIceAdapterObject<DVBSI::SiTableParserBase> patParser; + TemporaryIceAdapterObject<DVBSI::SiTableParserBase> pmtParser; + TunerPrx tuner; int serviceId; int patHandle; @@ -44,6 +45,7 @@ class DLL_PUBLIC ServiceStreamerCore { static IceTray::Logging::LoggerPtr log; }; +} #endif diff --git a/p2pvr/lib/temporaryIceAdapterObject.h b/p2pvr/lib/temporaryIceAdapterObject.h index 0614066..a11da53 100644 --- a/p2pvr/lib/temporaryIceAdapterObject.h +++ b/p2pvr/lib/temporaryIceAdapterObject.h @@ -4,6 +4,7 @@ #include <Ice/ObjectAdapter.h> #include <visibility.h> +namespace P2PVR { template <typename Object> class DLL_PUBLIC TemporaryIceAdapterObject { public: @@ -58,6 +59,7 @@ class DLL_PUBLIC TemporaryIceAdapterObject { IceUtil::Handle<Object> object; typename Object::ProxyType proxy; }; +} #endif |