diff options
author | Christian Mueller <christian.ei.mueller@bmw.de> | 2012-05-21 19:00:35 +0200 |
---|---|---|
committer | christian mueller <christian.ei.mueller@bmw.de> | 2012-05-24 13:40:23 +0200 |
commit | 3f65139b2825e654dd0cc36d1cee055b7ac959d9 (patch) | |
tree | f9baf9833b8da138428c7ee295f6af7953c7085f /AudioManagerDaemon/src/CAmWatchdog.cpp | |
parent | a572fc87a811563f62b88116de699f803915383e (diff) | |
download | audiomanager-3f65139b2825e654dd0cc36d1cee055b7ac959d9.tar.gz |
* [GAM-24] Watchdog concept for the AudioManager. This patch introduces the watchdog functionality of the AudioManager. The function is based on the systemd watchdog functionality. The desired time intervals for checking the watchdog can be tweaked by the unit file for systemd. A sample unit file is added to the subdirectory cmake. Via Cmake build option, the watchdog functionality can be switched off.
If the development package from systemd is available it will use the lib that comes with it. If not, the default handler will be compiled along with the audiomanager and this one will be used.
Signed-off-by: Christian Mueller <christian.ei.mueller@bmw.de>
Diffstat (limited to 'AudioManagerDaemon/src/CAmWatchdog.cpp')
-rwxr-xr-x | AudioManagerDaemon/src/CAmWatchdog.cpp | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/AudioManagerDaemon/src/CAmWatchdog.cpp b/AudioManagerDaemon/src/CAmWatchdog.cpp new file mode 100755 index 0000000..61e0624 --- /dev/null +++ b/AudioManagerDaemon/src/CAmWatchdog.cpp @@ -0,0 +1,104 @@ +/** + * Copyright (C) 2012, BMW AG + * + * This file is part of GENIVI Project AudioManager. + * + * Contributions are licensed to the GENIVI Alliance under one or more + * Contribution License Agreements. + * + * \copyright + * This Source Code Form is subject to the terms of the + * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with + * this file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * + * \author Christian Mueller, christian.ei.mueller@bmw.de BMW 2011,2012 + * + * \file CAmWatchdog.cpp + * For further information see http://www.genivi.org/. + * + */ + +#include "CAmWatchdog.h" +#include <cassert> +#include <cstdlib> +#include <stdexcept> +#include "config.h" +#include "shared/CAmDltWrapper.h" + +#ifdef SYSTEMD_FOUND + #include <systemd/sd-daemon.h> +#else + #include "sd-daemon.h" +#endif + +namespace am +{ + +CAmWatchdog::CAmWatchdog(CAmSocketHandler* CAmSocketHandler) : + TimerCallback(this, &CAmWatchdog::timerCallback), // + mpCAmSocketHandler(CAmSocketHandler), // + mHandle(0) // +{ + assert(mpCAmSocketHandler); + + //first retrieve the timeout interval + int watchdogTimeout = atoi(getenv("WATCHDOG_USEC")); + + if (watchdogTimeout > 0) + { + timespec timeout; + logInfo("CAmWatchdog::CAmWatchdog setting watchdog timeout to ", watchdogTimeout, " museconds"); + + //calulate the half cycle as the right interval to trigger the watchdog. + timeout.tv_sec = watchdogTimeout / 2000000; + timeout.tv_nsec = (watchdogTimeout % 1000000) * 500; + + //add the timer here + if (mpCAmSocketHandler->addTimer(timeout, &TimerCallback, mHandle, NULL)) + { + logError("CAmWatchdog::CAmWatchdog failed to add timer"); + throw std::runtime_error("CAmWatchdog::CAmWatchdog failed to add timer"); + } + } + + else + { + logInfo("CAmWatchdog::CAmWatchdog watchdog timeout was ", watchdogTimeout, " museconds, no watchdog active"); + } +} + +CAmWatchdog::~CAmWatchdog() +{ + //remove the timer again. + mpCAmSocketHandler->removeTimer(mHandle); +} + +void CAmWatchdog::timerCallback(sh_timerHandle_t handle, void* userData) +{ + (void) userData; + int error(sd_notify(0, "WATCHDOG=1")); + if (error < 0) + { + logError("CAmWatchdog::timerCallback could not reset watchdog, error ", error); + throw std::runtime_error("CAmWatchdog::timerCallback could not reset watchdog"); + } + + mpCAmSocketHandler->restartTimer(handle); + logInfo("restarted watchdog "); +} + +void CAmWatchdog::startWatchdog() +{ + int error(sd_notify(0, "READY=1")); + if (error < 0) + { + logError("CAmWatchdog::startWatchdog could not start watchdog, error ", error); + throw std::runtime_error("CAmWatchdog::startWatchdog could not start watchdog"); + } + logInfo("READY=1 was sent to systemd"); +} + +} + +/* namespace am */ |