diff options
author | randomdan <randomdan@localhost> | 2014-03-13 19:42:07 +0000 |
---|---|---|
committer | randomdan <randomdan@localhost> | 2014-03-13 19:42:07 +0000 |
commit | ab1eee942e75874739ce5f0b4ba289aac5cc3faf (patch) | |
tree | 6e43828794fe0c0c5c9921ec1911695b67357c50 /p2pvr/daemon/maintenance.cpp | |
parent | Expose more of the interface (diff) | |
download | p2pvr-ab1eee942e75874739ce5f0b4ba289aac5cc3faf.tar.bz2 p2pvr-ab1eee942e75874739ce5f0b4ba289aac5cc3faf.tar.xz p2pvr-ab1eee942e75874739ce5f0b4ba289aac5cc3faf.zip |
Restructure into more sensibly arranged libs
Diffstat (limited to 'p2pvr/daemon/maintenance.cpp')
-rw-r--r-- | p2pvr/daemon/maintenance.cpp | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/p2pvr/daemon/maintenance.cpp b/p2pvr/daemon/maintenance.cpp new file mode 100644 index 0000000..3475544 --- /dev/null +++ b/p2pvr/daemon/maintenance.cpp @@ -0,0 +1,97 @@ +#include <pch.hpp> +#include <logger.h> +#include <thread> +#include "maintenance.h" +#include <Ice/Ice.h> +#include "bindTimerTask.h" +#include <linux/dvb/frontend.h> +#include <cxxabi.h> + +time_t Maintenance::periodUpdateNetwork; +time_t Maintenance::periodUpdateServices; +time_t Maintenance::periodUpdateEvents; + +DECLARE_OPTIONS(Maintenance, "P2PVR Maintenance options") +("p2pvr.maintenance.periodUpdateNetwork", Options::value(&periodUpdateNetwork, 86400 * 7), + "Period between automated updates of DVB network (1 week)") +("p2pvr.maintenance.periodUpdateServices", Options::value(&periodUpdateServices, 86400 * 7), + "Period between automated updates of DVB services (1 week)") +("p2pvr.maintenance.periodUpdateEvents", Options::value(&periodUpdateEvents, 3600 * 12), + "Period between automated updates of DVB events (12 hours)") +END_OPTIONS(Maintenance); + +Maintenance::Maintenance(Ice::ObjectAdapterPtr a, IceUtil::TimerPtr t) : + adapter(a), + timer(t), + clientCheck(new BindTimerTask(boost::bind(&Maintenance::ScheduledUpdate, this))), + lastUpdateNetwork(0), + lastUpdateServices(0), + lastUpdateEvents(0), + updateRunning(false) +{ + timer->scheduleRepeated(clientCheck, IceUtil::Time::seconds(5 * 60)); +#ifdef NDEBUG + ScheduledUpdate(); +#endif +} + +void +Maintenance::UpdateAll(const Ice::Current & ice) +{ + UpdateAll(FE_OFDM, ice); + UpdateAll(FE_QPSK, ice); + UpdateAll(FE_ATSC, ice); + UpdateAll(FE_QAM, ice); +} + +void +Maintenance::UpdateAll(short type, const Ice::Current & ice) +{ + UpdateNetwork(type, ice); + UpdateServices(type, ice); + UpdateProgramAssociations(type, ice); + UpdateProgramMaps(type, ice); + UpdateEvents(type, ice); +} + +void +Maintenance::ScheduledUpdate() +{ + Logger()->messagebf(LOG_DEBUG, "%s: triggered", __PRETTY_FUNCTION__); + if (!updateRunning) { + std::thread update([this] { + try { + ScopeObject notRunning([this]{ updateRunning = false; }); + updateRunning = true; + auto si = P2PVR::MaintenancePrx::checkedCast(adapter->createProxy(adapter->getCommunicator()->stringToIdentity("Maintenance"))); + time_t now = time(NULL); + if (lastUpdateNetwork < now - periodUpdateNetwork) { + Logger()->messagebf(LOG_INFO, "%s: updating network", __PRETTY_FUNCTION__); + si->UpdateNetwork(FE_OFDM); + time(&lastUpdateNetwork); + } + if (lastUpdateServices < now - periodUpdateServices) { + Logger()->messagebf(LOG_INFO, "%s: updating services", __PRETTY_FUNCTION__); + si->UpdateServices(FE_OFDM); + time(&lastUpdateServices); + } + if (lastUpdateEvents < now - periodUpdateEvents) { + Logger()->messagebf(LOG_INFO, "%s: updating events", __PRETTY_FUNCTION__); + si->UpdateEvents(FE_OFDM); + time(&lastUpdateEvents); + } + Logger()->messagebf(LOG_DEBUG, "%s: completed", __PRETTY_FUNCTION__); + } + catch (const std::exception & ex) { + char * buf = __cxxabiv1::__cxa_demangle(typeid(ex).name(), NULL, NULL, NULL); + Logger()->messagebf(LOG_ERR, "%s: failed %s: %s", __PRETTY_FUNCTION__, buf, ex.what()); + free(buf); + } + catch (...) { + Logger()->messagebf(LOG_ERR, "%s: failed (unknown exception)", __PRETTY_FUNCTION__); + } + }); + update.detach(); + } +} + |