summaryrefslogtreecommitdiff
path: root/p2pvr/daemon/maintenance.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2017-07-30 00:15:33 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2017-07-30 00:15:33 +0100
commitadd5644f64c86b635b62d560187c993aa7072b76 (patch)
tree70aaf1ae49ef4f27c4b20809250d5f5d63921d0e /p2pvr/daemon/maintenance.cpp
parentSingle definition of glibmm (diff)
downloadp2pvr-add5644f64c86b635b62d560187c993aa7072b76.tar.bz2
p2pvr-add5644f64c86b635b62d560187c993aa7072b76.tar.xz
p2pvr-add5644f64c86b635b62d560187c993aa7072b76.zip
BIG migration from Project2 based to IceTray/Slicer :D
Diffstat (limited to 'p2pvr/daemon/maintenance.cpp')
-rw-r--r--p2pvr/daemon/maintenance.cpp90
1 files changed, 45 insertions, 45 deletions
diff --git a/p2pvr/daemon/maintenance.cpp b/p2pvr/daemon/maintenance.cpp
index f6878ec..23eef15 100644
--- a/p2pvr/daemon/maintenance.cpp
+++ b/p2pvr/daemon/maintenance.cpp
@@ -1,4 +1,3 @@
-#include <pch.hpp>
#include <logger.h>
#include <thread>
#include "maintenance.h"
@@ -6,24 +5,26 @@
#include "bindTimerTask.h"
#include <linux/dvb/frontend.h>
#include <cxxabi.h>
+#include <scopeExit.h>
-time_t Maintenance::periodUpdateNetwork;
-time_t Maintenance::periodUpdateServices;
-time_t Maintenance::periodUpdateEvents;
-bool Maintenance::scanOnStart;
+namespace po = boost::program_options;
-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)")
-("p2pvr.maintenance.scanOnStart", Options::value(&scanOnStart, false),
- "Perform the maintenance circle on start-up (false)")
-END_OPTIONS(Maintenance);
+Maintenance::Options::Options() : IceTray::Options("P2PVR Maintenance options") { }
+ICETRAY_OPTIONS(Maintenance::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),
+ "Period between automated updates of DVB services (1 week)")
+ ("p2pvr.maintenance.periodUpdateEvents", po::value(&periodUpdateEvents)->default_value(3600 * 12),
+ "Period between automated updates of DVB events (12 hours)")
+ ("p2pvr.maintenance.scanOnStart", po::value(&scanOnStart)->default_value(false),
+ "Perform the maintenance circle on start-up (false)")
+);
-Maintenance::Maintenance(Ice::ObjectAdapterPtr a, IceUtil::TimerPtr t) :
+IceTray::Logging::LoggerPtr Maintenance::logger(LOGMANAGER()->getLogger<Maintenance>());
+
+Maintenance::Maintenance(IceTray::DatabasePoolPtr db, Ice::ObjectAdapterPtr a, IceUtil::TimerPtr t) :
+ IceTray::AbstractDatabaseClient(db),
adapter(a),
timer(t),
clientCheck(new BindTimerTask(boost::bind(&Maintenance::ScheduledUpdate, this))),
@@ -35,7 +36,7 @@ Maintenance::Maintenance(Ice::ObjectAdapterPtr a, IceUtil::TimerPtr t) :
if (timer) {
timer->scheduleRepeated(clientCheck, IceUtil::Time::seconds(5 * 60));
}
- if (scanOnStart) {
+ if (options->scanOnStart) {
ScheduledUpdate();
}
}
@@ -60,40 +61,39 @@ Maintenance::UpdateAll(short type, const Ice::Current & ice)
void
Maintenance::ScheduledUpdate()
{
- Logger()->messagebf(LOG_DEBUG, "%s: triggered", __PRETTY_FUNCTION__);
+ logger->messagebf(LOG::DEBUG, "%s: triggered", __PRETTY_FUNCTION__);
if (!updateRunning) {
std::thread update([this] {
- try {
+ try {
AdHoc::ScopeExit 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();
- time(&lastUpdateServices);
- }
- if (lastUpdateEvents < now - periodUpdateEvents) {
- Logger()->messagebf(LOG_INFO, "%s: updating events", __PRETTY_FUNCTION__);
- si->UpdateEvents();
- time(&lastUpdateEvents);
- }
- Logger()->messagebf(LOG_DEBUG, "%s: completed", __PRETTY_FUNCTION__);
+ updateRunning = true;
+ time_t now = time(NULL);
+ if (lastUpdateNetwork < now - options->periodUpdateNetwork) {
+ logger->messagebf(LOG::INFO, "%s: updating network", __PRETTY_FUNCTION__);
+ this->UpdateNetwork(FE_OFDM, Ice::Current());
+ time(&lastUpdateNetwork);
}
- 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);
+ if (lastUpdateServices < now - options->periodUpdateServices) {
+ logger->messagebf(LOG::INFO, "%s: updating services", __PRETTY_FUNCTION__);
+ this->UpdateServices(Ice::Current());
+ time(&lastUpdateServices);
}
- catch (...) {
- Logger()->messagebf(LOG_ERR, "%s: failed (unknown exception)", __PRETTY_FUNCTION__);
+ if (lastUpdateEvents < now - options->periodUpdateEvents) {
+ logger->messagebf(LOG::INFO, "%s: updating events", __PRETTY_FUNCTION__);
+ this->UpdateEvents(Ice::Current());
+ 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();
}
}