summaryrefslogtreecommitdiff
path: root/daemons/gptp/linux/src/watchdog.cpp
blob: 1406fb55efc3b319fa59bd76ddf3ef4f30bd133a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "watchdog.hpp"
#include "avbts_osthread.hpp"
#include "gptp_log.hpp"
#include <systemd/sd-daemon.h>


OSThreadExitCode watchdogUpdateThreadFunction(void *arg)
{
	SystemdWatchdogHandler *watchdog = (SystemdWatchdogHandler*) arg;
	watchdog->run_update();
	return osthread_ok;
}


SystemdWatchdogHandler::SystemdWatchdogHandler()
{
	GPTP_LOG_INFO("Creating Systemd watchdog handler.");
	LinuxTimerFactory timer_factory = LinuxTimerFactory();
	timer = timer_factory.createTimer();
}

SystemdWatchdogHandler::~SystemdWatchdogHandler()
{
	//Do nothing
}

long unsigned int
SystemdWatchdogHandler::getSystemdWatchdogInterval(int *result)
{
	long unsigned int watchdog_interval; //in microseconds
	*result = sd_watchdog_enabled(0, &watchdog_interval);
	return watchdog_interval;
}

void SystemdWatchdogHandler::run_update()
{
	while(1)
	{
		GPTP_LOG_DEBUG("NOTIFYING WATCHDOG.");
		sd_notify(0, "WATCHDOG=1");
		GPTP_LOG_DEBUG("GOING TO SLEEP %lld", update_interval);
		timer->sleep(update_interval);
		GPTP_LOG_DEBUG("WATCHDOG WAKE UP");
	}
}