TACOS/include/sta/tacos/watchdog.hpp

74 lines
1.4 KiB
C++

#ifndef STA_TACOS_WATCHDOG_HPP
#define STA_TACOS_WATCHDOG_HPP
#include <sta/config.hpp>
#ifdef STA_TACOS_WATCHDOG_ENABLED
#ifndef STA_TACOS_WATCHDOG_PRIORITY
# error "TACOS watchdog priority was not specified!"
#endif // STA_TACOS_WATCHDOG_PRIORITY
#ifndef STA_TACOS_WATCHDOG_FREQUENCY
# error "TACOS watchdog frequency was not specified!"
#endif // STA_TACOS_WATCHDOG_FREQUENCY
#include <sta/tacos/thread.hpp>
namespace sta
{
namespace tacos
{
/**
* @brief Watchdog class for TACOS using singleton pattern.
*
*/
class Watchdog: public TacosThread
{
public:
/**
* @brief Getter for the singleton instance. Constructs the instance if no exists.
*
* @return Watchdog*
*/
static Watchdog* instance()
{
static CGuard g;
if (!_instance)
{
// Create the watchdog singleton instance.
Watchdog::_instance = new Watchdog();
}
return _instance;
}
void func() override;
private:
static Watchdog* _instance;
class CGuard
{
public:
~CGuard()
{
if( NULL != Watchdog::_instance )
{
delete Watchdog::_instance;
Watchdog::_instance = NULL;
}
}
};
Watchdog(const Watchdog&);
Watchdog();
};
} // namespace tacos
} // namespace sta
#endif // STA_TACOS_WATCHDOG_ENABLED
#endif // STA_TACOS_WATCHDOG_HPP