UTILLib 2.0
Common C++ library with utilities.
Loading...
Searching...
No Matches
util::supervise::ISuperviseApplication Class Reference

Supervise an executable application. More...

#include <isuperviseapplication.h>

Public Member Functions

virtual ~ISuperviseApplication ()=default
 Default destructor.
void Name (std::string name)
 Name of the application.
const std::string & Name () const
 Name of the application.
void Path (std::string path)
 Path to the executable.
const std::string & Path () const
 Path to the executable.
void Arguments (std::string arguments)
 Command line arguments to use at startup.
const std::string & Arguments () const
 Command line arguments.
void Startup (ApplicationStartup startup)
 Startup mode for the application.
ApplicationStartup Startup () const
 Startup mode for the application.
void Priority (ApplicationPriority priority)
 Defines the priority for the executable.
ApplicationPriority Priority () const
 Returns the executable priority.
void ShowWindow (bool show)
 Sets to true if a window should be shown.
bool ShowWindow () const
 True if window should be shown.
void StartupDelay (uint32_t delay)
 Initial startup delay in seconds.
uint32_t StartupDelay () const
 Returns the startup delay in seconds.
void MaxRestarts (uint32_t max_restarts)
 Sets maximum number of restarts.
uint32_t MaxRestarts () const
 Maximum number of restarts.
void InService (bool in_service)
 Starts or stops the executable.
bool InService () const
 Returns true if the executable should be started.
uint32_t NofRestarts () const
 Returns number of restarts.
bool Operable () const
 Returns true if the executable is running.
ApplicationState State () const
 Returns the state of the supervisor.
virtual void Start ()
 Initialize and start the supervisor.
virtual void Stop ()
 Stops the supervisor.
virtual void Poll ()
 Poll the supervisor.
void ReadConfig (const xml::IXmlNode &application_node)
 Reads in the configuration.
void SaveConfig (xml::IXmlNode &root_node) const
 Saves the application configuration.

Protected Member Functions

void IncrementNofRestarts ()
 Increment number of restarts.
void ResetNofRestarts ()
 Reset number of restarts..
void Operable (bool operable)
 Sets the operable property.
void State (ApplicationState state)
 Sets the supervisor state.
std::vector< std::string > ParseCommandLine () const
 Convert the command line into an array of arguments.

Detailed Description

The class supervise an external executable application. It start, supervise and stop the application. The application startup mode controls how the application is supervised.

In the Manual mode, the application is started when it is taken in-service by a remote application. If it is taken out-of-service, it stops. If it exit before it is taken out-of-service, the state is set to ApplicationState::Ready.

In the Once mode, the application only run once at startup. It is very similar to the Manual mode but it is set to in-service at startup.

In the Automatic mode, the application is started at startup and then checked that it is running. If the application stops, it will be restarted. Note that the restart is delayed 2-10 seconds. If number of restarts reach a maximum limit, it will stop restarting and a critical log event will be generated.

Member Function Documentation

◆ Arguments() [1/2]

const std::string & util::supervise::ISuperviseApplication::Arguments ( ) const
inlinenodiscard
Returns
Command line arguments.

◆ Arguments() [2/2]

void util::supervise::ISuperviseApplication::Arguments ( std::string arguments)
inline
Parameters
argumentsCommand line arguments

◆ InService() [1/2]

bool util::supervise::ISuperviseApplication::InService ( ) const
inlinenodiscard
Returns
True if the executable should be started.

◆ InService() [2/2]

void util::supervise::ISuperviseApplication::InService ( bool in_service)
inline
Parameters
in_serviceIf true, starts the executable. False stops the executable.

◆ MaxRestarts() [1/2]

uint32_t util::supervise::ISuperviseApplication::MaxRestarts ( ) const
inlinenodiscard
Returns
Max restarts.

◆ MaxRestarts() [2/2]

void util::supervise::ISuperviseApplication::MaxRestarts ( uint32_t max_restarts)
inline
Parameters
max_restartsMax restarts.

◆ Name() [1/2]

const std::string & util::supervise::ISuperviseApplication::Name ( ) const
inlinenodiscard
Returns
Name of the application.

◆ Name() [2/2]

void util::supervise::ISuperviseApplication::Name ( std::string name)
inline

The name is a property that is used internally for identification of the application. The name is used when generating logs and events.

Parameters
nameName of the application.

◆ NofRestarts()

uint32_t util::supervise::ISuperviseApplication::NofRestarts ( ) const
inlinenodiscard
Returns
Number of restarts.

◆ Operable() [1/2]

bool util::supervise::ISuperviseApplication::Operable ( ) const
inlinenodiscard
Returns
True if the application is running normally.

◆ Operable() [2/2]

void util::supervise::ISuperviseApplication::Operable ( bool operable)
inlineprotected
Parameters
operableTrue if operable.

◆ ParseCommandLine()

std::vector< std::string > util::supervise::ISuperviseApplication::ParseCommandLine ( ) const
protected
Returns
List of arguments.

◆ Path() [1/2]

const std::string & util::supervise::ISuperviseApplication::Path ( ) const
inlinenodiscard
Returns
Path to the executable.

◆ Path() [2/2]

void util::supervise::ISuperviseApplication::Path ( std::string path)
inline

The path to the executable. If only the executable name is set, the class will search for the executable in known paths.

Parameters
pathPath to the executable.

◆ Priority() [1/2]

ApplicationPriority util::supervise::ISuperviseApplication::Priority ( ) const
inlinenodiscard
Returns
Executable priority.

◆ Priority() [2/2]

void util::supervise::ISuperviseApplication::Priority ( ApplicationPriority priority)
inline
Parameters
priorityExecutable priority.

◆ ReadConfig()

void util::supervise::ISuperviseApplication::ReadConfig ( const xml::IXmlNode & application_node)
Parameters
application_nodeThe application XML node.

◆ SaveConfig()

void util::supervise::ISuperviseApplication::SaveConfig ( xml::IXmlNode & root_node) const
Parameters
root_nodeThe root XML node.

◆ ShowWindow() [1/2]

bool util::supervise::ISuperviseApplication::ShowWindow ( ) const
inlinenodiscard
Returns
True if window should be shown.

◆ ShowWindow() [2/2]

void util::supervise::ISuperviseApplication::ShowWindow ( bool show)
inline

Set to true if the window should be shown. In reality, this option is dependent on which user that was logged in. For example, a service user doesn't own any desktop to show any window in.

Parameters
showTrue if window should be shown.

◆ Startup() [1/2]

ApplicationStartup util::supervise::ISuperviseApplication::Startup ( ) const
inlinenodiscard
Returns
Startup mode enumerate.

◆ Startup() [2/2]

void util::supervise::ISuperviseApplication::Startup ( ApplicationStartup startup)
inline

The startup mode is set to each application and defines how it start, stop and being supervised.

In the Manual mode, the application is started when it is taken in-service by a remote application. If it is taken out-of-service, it stops. If it exit before it is taken out-of-service, the state is set to ApplicationState::Ready.

In the Once mode, the application only run once at startup. It is very similar to the Manual mode but it is set to in-service at startup.

In the Automatic mode, the application is started at startup and then checked that it is running. If the application stops, it will be restarted. Note that the restart is delayed 2-10 seconds. If number of restarts reach a maximum limit, it will stop restarting and a critical log event will be generated.

Parameters
startup

◆ StartupDelay() [1/2]

uint32_t util::supervise::ISuperviseApplication::StartupDelay ( ) const
inlinenodiscard
Returns
Startup delay in seconds.

◆ StartupDelay() [2/2]

void util::supervise::ISuperviseApplication::StartupDelay ( uint32_t delay)
inline

Delay in seconds that the first start is delayed.

Parameters
delayStartup delay in seconds.

◆ State() [1/2]

ApplicationState util::supervise::ISuperviseApplication::State ( ) const
inlinenodiscard
Returns
State of the supervisor.

◆ State() [2/2]

void util::supervise::ISuperviseApplication::State ( ApplicationState state)
inlineprotected
Parameters
stateNew state.

The documentation for this class was generated from the following file: