Files
redAcore/WatchdogCore.cpp
Charl Wentzel aaf3c59727 Important Updates:
- DataTreeCore:
  - Allow types float, int & bool to be read as strings with GetStr()
- LogCore:
  - Add comments to Logging parameters
- WatchDogCore:
  - Call CSelectableCore::Process() in Process() to manage connect
- SelectableCore:
  - Allow SetSocketHandle() to be called if Handle already set as socket
  - added strlcase() method to convert string to lower case
  - Update Handle structure:
    - renamed Address -> HostName
    - renamed PortNo -> PortName
    - added AddressList for all resolved addresses
    - added AddressInfo for active address
  - Add ResolveAddress() method
    - Domain name and protocol port resolving with GetAddrInfo()
  - JSON updated:
    - domain name can be provided instead of IP address
    - protocol can be specified instead of Port No, e.g. "HTTP" / "SSH"
  - Resolve address before connect, or use next resolved address
2017-07-22 09:40:17 +02:00

100 lines
2.4 KiB
C++

/*
* WatchdogCore.cpp
*
* Created on: July 2017
* Author: wentzelc
*/
// redA Libraries
#include "ApplicationCore.h"
#include "WatchdogCore.h"
// Standard C/C++ Libraries
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
//---------------------------------------------------------------------------
// Global vars
extern char * ProcessName;
//extern CApplication * Application;
//---------------------------------------------------------------------------
CWatchdogCore::CWatchdogCore( const char * pName ) :
CSelectableCore( pName, "WatchdogClient" )
{
// Create protocol
Protocol = new CLiteProtocol( 50, '\x01', '\x02', '\x00' );
Protocol->CreateCommand( ProcessName, pName, "ping" );
// Start timer
PingInterval = 500;
SetStartTime( &PingTimer );
// Handle
Ping = NULL;
}
//---------------------------------------------------------------------------
CWatchdogCore::~CWatchdogCore()
{
// Destroy Protocol
if (Protocol)
delete Protocol;
}
//---------------------------------------------------------------------------
bool CWatchdogCore::LoadConfigData()
{
// Call Previous load config
CSelectableCore::LoadConfigData();
// Set Auto Mange
SetInterval( DataTree->GetInt( ConfigMember, "Parameters/PingInterval", 500, true ));
return true;
}
//---------------------------------------------------------------------------
bool CWatchdogCore::SetInterval( int pPingInterval )
{
PingInterval = pPingInterval;
return true;
}
//---------------------------------------------------------------------------
bool CWatchdogCore::Init()
{
// Create handle and set reference, if not done
if (!(Ping = GetHandle( "Ping" )))
Ping = CreateHandle( "Ping", false );
// Previous init
return CSelectableCore::Init();
}
//---------------------------------------------------------------------------
bool CWatchdogCore::Process()
{
// Manage socket connections
CSelectableCore::Process();
// Watchdog ping
if (Timeout( PingTimer, PingInterval ))
{
// Send command
Input( Ping->Name, Protocol->GetCommandStr(), Protocol->GetCommandLen() );
// Reset timer
SetStartTime( &PingTimer );
}
return false;
}
//---------------------------------------------------------------------------