winss
Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | List of all members
winss::SuperviseTmpl< TMutex, TProcess > Class Template Reference

The supervisor class template. More...

#include <supervise.hpp>

Collaboration diagram for winss::SuperviseTmpl< TMutex, TProcess >:
Collaboration graph
[legend]

Public Member Functions

 SuperviseTmpl (winss::NotOwningPtr< winss::WaitMultiplexer > multiplexer, const fs::path &service_dir)
 Supervise constructor. More...
 
 SuperviseTmpl (const SuperviseTmpl &)=delete
 No copy. More...
 
 SuperviseTmpl (SuperviseTmpl &&)=delete
 No move. More...
 
virtual const SuperviseStateGetState () const
 Gets the current supervisor state. More...
 
virtual void AddListener (winss::NotOwningPtr< winss::SuperviseListener > listener)
 Adds a supervisor listener to the list of listeners. More...
 
virtual void Up ()
 Signals the supervisor to go into the up state. More...
 
virtual void Once ()
 Signals the supervisor to be in the up state and when the process exits then leave it down. More...
 
virtual void OnceAtMost ()
 Signals the supervisor to only run one if it is already running. More...
 
virtual void Down ()
 Signals the supervisor to be in the down state. More...
 
virtual void Kill ()
 Kills the supervised process. More...
 
virtual void Term ()
 Sends a CTRL+BREAK to the supervised process. More...
 
virtual void Exit ()
 Signals the supervisor to exit. More...
 
SuperviseTmploperator= (const SuperviseTmpl &)=delete
 No copy. More...
 
SuperviseTmploperator= (SuperviseTmpl &&)=delete
 No move. More...
 

Static Public Attributes

static const int kMutexTaken = 100
 Service dir in use error. More...
 
static const int kFatalExitCode = 111
 Something went wrong. More...
 
static const int kSignaledExitCode = 256
 Signaled to exit. More...
 
static const int kDownExitCode = 125
 Signal down. More...
 
static const DWORD kCommandTimeout = 5000
 Default timeout 5s. More...
 
static const DWORD kBusyWait = 1000
 Busy wait 1s. More...
 
static const DWORD kRunFailedWait = 10000
 Run failed wait 10s. More...
 
static constexpr const char kMutexName [10] = "supervise"
 Mutex name. More...
 
static constexpr const char kRunFile [4] = "run"
 Run file. More...
 
static constexpr const char kFinishFile [7] = "finish"
 Finish file. More...
 
static constexpr const char kDownFile [5] = "down"
 Down file. More...
 
static constexpr const char kEnvDir [4] = "env"
 Env directory. More...
 
static constexpr const char kTimeoutFinishFile [15] = "timeout-finish"
 Timeout finish file. More...
 
static constexpr const char kTimeoutGroup [10] = "supervise"
 The timeout group for the multiplexer. More...
 
static constexpr const char kRunExitCodeEnvName [24]
 The environment variable to set with the exit code. More...
 

Protected Member Functions

virtual void Init ()
 Initializes the supervisor. More...
 
virtual DWORD GetFinishTimeout () const
 Gets the finish timeout value. More...
 
virtual bool Start (const std::string &file_name)
 Starts the process defined in the given file. More...
 
virtual bool StartRun ()
 Starts the run file process. More...
 
virtual bool StartFinish ()
 Starts the finish file process. More...
 
virtual void NotifyAll (winss::SuperviseNotification notification)
 Notify all the listeners with the given event. More...
 
virtual void Triggered (bool timeout)
 Event triggered handler. More...
 
virtual bool Complete ()
 Tests exiting value. More...
 
virtual void Stop ()
 Signal the supervisor to exit. More...
 

Protected Attributes

winss::NotOwningPtr< winss::WaitMultiplexermultiplexer
 The event multiplexer for the supervisor. More...
 
TMutex mutex
 The supervisor global mutex. More...
 
TProcess process
 The supervised process. More...
 
fs::path service_dir
 The service directory. More...
 
SuperviseState state {}
 The current supervised state. More...
 
std::vector< winss::NotOwningPtr< winss::SuperviseListener > > listeners
 The supervisor listeners. More...
 
int exiting = 0
 The exiting state. More...
 
bool waiting = false
 The waiting state. More...
 

Detailed Description

template<typename TMutex, typename TProcess>
class winss::SuperviseTmpl< TMutex, TProcess >

The supervisor class template.

Template Parameters
TMutexThe mutex implementation type.
TProcessThe process implementation type.

Constructor & Destructor Documentation

template<typename TMutex , typename TProcess >
winss::SuperviseTmpl< TMutex, TProcess >::SuperviseTmpl ( winss::NotOwningPtr< winss::WaitMultiplexer multiplexer,
const fs::path &  service_dir 
)
inline

Supervise constructor.

Parameters
multiplexerThe shared multiplexer.
service_dirThe service directory.

References winss::WaitMultiplexer::AddInitCallback(), and winss::WaitMultiplexer::AddStopCallback().

template<typename TMutex , typename TProcess >
winss::SuperviseTmpl< TMutex, TProcess >::SuperviseTmpl ( const SuperviseTmpl< TMutex, TProcess > &  )
delete

No copy.

template<typename TMutex , typename TProcess >
winss::SuperviseTmpl< TMutex, TProcess >::SuperviseTmpl ( SuperviseTmpl< TMutex, TProcess > &&  )
delete

No move.

Member Function Documentation

template<typename TMutex , typename TProcess >
virtual void winss::SuperviseTmpl< TMutex, TProcess >::AddListener ( winss::NotOwningPtr< winss::SuperviseListener listener)
inlinevirtual

Adds a supervisor listener to the list of listeners.

Parameters
[in]listenerThe listener to add.

Referenced by winss::SuperviseController::SuperviseController().

template<typename TMutex , typename TProcess >
virtual bool winss::SuperviseTmpl< TMutex, TProcess >::Complete ( )
inlineprotectedvirtual

Tests exiting value.

When the exiting value is 1 it will signal the multiplexer to stop and notify the listeners that the supervisor is about exit.

Returns
True if exiting otherwise false.

References winss::EXIT, winss::WaitMultiplexer::IsStopping(), and winss::WaitMultiplexer::Stop().

template<typename TMutex , typename TProcess >
virtual void winss::SuperviseTmpl< TMutex, TProcess >::Down ( )
inlinevirtual

Signals the supervisor to be in the down state.

template<typename TMutex , typename TProcess >
virtual void winss::SuperviseTmpl< TMutex, TProcess >::Exit ( )
inlinevirtual

Signals the supervisor to exit.

template<typename TMutex , typename TProcess >
virtual DWORD winss::SuperviseTmpl< TMutex, TProcess >::GetFinishTimeout ( ) const
inlineprotectedvirtual

Gets the finish timeout value.

This will read the finish-timeout file if it exists.

Returns
The finish timeout in milliseconds.

References FILESYSTEM.

template<typename TMutex , typename TProcess >
virtual const SuperviseState& winss::SuperviseTmpl< TMutex, TProcess >::GetState ( ) const
inlinevirtual

Gets the current supervisor state.

Returns
The supervisor state.
template<typename TMutex , typename TProcess >
virtual void winss::SuperviseTmpl< TMutex, TProcess >::Init ( )
inlineprotectedvirtual

Initializes the supervisor.

References FILESYSTEM, winss::START, and winss::WaitMultiplexer::Stop().

template<typename TMutex , typename TProcess >
virtual void winss::SuperviseTmpl< TMutex, TProcess >::Kill ( )
inlinevirtual

Kills the supervised process.

template<typename TMutex , typename TProcess >
virtual void winss::SuperviseTmpl< TMutex, TProcess >::NotifyAll ( winss::SuperviseNotification  notification)
inlineprotectedvirtual

Notify all the listeners with the given event.

Parameters
[in]notificationThe notification event.

References winss::END, and winss::RUN.

template<typename TMutex , typename TProcess >
virtual void winss::SuperviseTmpl< TMutex, TProcess >::Once ( )
inlinevirtual

Signals the supervisor to be in the up state and when the process exits then leave it down.

template<typename TMutex , typename TProcess >
virtual void winss::SuperviseTmpl< TMutex, TProcess >::OnceAtMost ( )
inlinevirtual

Signals the supervisor to only run one if it is already running.

template<typename TMutex , typename TProcess >
SuperviseTmpl& winss::SuperviseTmpl< TMutex, TProcess >::operator= ( const SuperviseTmpl< TMutex, TProcess > &  )
delete

No copy.

template<typename TMutex , typename TProcess >
SuperviseTmpl& winss::SuperviseTmpl< TMutex, TProcess >::operator= ( SuperviseTmpl< TMutex, TProcess > &&  )
delete

No move.

template<typename TMutex , typename TProcess >
virtual bool winss::SuperviseTmpl< TMutex, TProcess >::Start ( const std::string &  file_name)
inlineprotectedvirtual

Starts the process defined in the given file.

Parameters
[in]file_nameThe file which contains the process and arguments.
Returns
True if the process started otherwise false.

References winss::ProcessParams::env, winss::Utils::ExpandEnvironmentVariables(), and FILESYSTEM.

template<typename TMutex , typename TProcess >
virtual bool winss::SuperviseTmpl< TMutex, TProcess >::StartFinish ( )
inlineprotectedvirtual

Starts the finish file process.

Returns
True if the process started otherwise false.

References winss::WaitMultiplexer::AddTimeoutCallback(), winss::WaitMultiplexer::AddTriggeredCallback(), and WINDOWS.

template<typename TMutex , typename TProcess >
virtual bool winss::SuperviseTmpl< TMutex, TProcess >::StartRun ( )
inlineprotectedvirtual

Starts the run file process.

Returns
True if the process started otherwise false.

References winss::WaitMultiplexer::AddTriggeredCallback(), winss::RUN, and WINDOWS.

template<typename TMutex , typename TProcess >
virtual void winss::SuperviseTmpl< TMutex, TProcess >::Stop ( )
inlineprotectedvirtual

Signal the supervisor to exit.

template<typename TMutex , typename TProcess >
virtual void winss::SuperviseTmpl< TMutex, TProcess >::Term ( )
inlinevirtual

Sends a CTRL+BREAK to the supervised process.

template<typename TMutex , typename TProcess >
virtual void winss::SuperviseTmpl< TMutex, TProcess >::Triggered ( bool  timeout)
inlineprotectedvirtual

Event triggered handler.

This will step the state machine forward.

Parameters
[in]timeoutIf the event was a timeout event.

References winss::WaitMultiplexer::AddTimeoutCallback(), winss::BROKEN, winss::END, winss::FINISHED, and winss::WaitMultiplexer::RemoveTimeoutCallback().

template<typename TMutex , typename TProcess >
virtual void winss::SuperviseTmpl< TMutex, TProcess >::Up ( )
inlinevirtual

Signals the supervisor to go into the up state.

Member Data Documentation

template<typename TMutex , typename TProcess >
int winss::SuperviseTmpl< TMutex, TProcess >::exiting = 0
protected

The exiting state.

template<typename TMutex , typename TProcess >
const DWORD winss::SuperviseTmpl< TMutex, TProcess >::kBusyWait = 1000
static

Busy wait 1s.

template<typename TMutex , typename TProcess >
const DWORD winss::SuperviseTmpl< TMutex, TProcess >::kCommandTimeout = 5000
static

Default timeout 5s.

template<typename TMutex , typename TProcess >
const int winss::SuperviseTmpl< TMutex, TProcess >::kDownExitCode = 125
static

Signal down.

template<typename TMutex , typename TProcess >
constexpr const char winss::SuperviseTmpl< TMutex, TProcess >::kDownFile[5] = "down"
static

Down file.

template<typename TMutex , typename TProcess >
constexpr const char winss::SuperviseTmpl< TMutex, TProcess >::kEnvDir[4] = "env"
static

Env directory.

template<typename TMutex , typename TProcess >
const int winss::SuperviseTmpl< TMutex, TProcess >::kFatalExitCode = 111
static

Something went wrong.

template<typename TMutex , typename TProcess >
constexpr const char winss::SuperviseTmpl< TMutex, TProcess >::kFinishFile[7] = "finish"
static

Finish file.

Referenced by winss::SuperviseStateFile::Notify().

template<typename TMutex , typename TProcess >
constexpr const char winss::SuperviseTmpl< TMutex, TProcess >::kMutexName[10] = "supervise"
static

Mutex name.

template<typename TMutex , typename TProcess >
const int winss::SuperviseTmpl< TMutex, TProcess >::kMutexTaken = 100
static

Service dir in use error.

template<typename TMutex , typename TProcess >
constexpr const char winss::SuperviseTmpl< TMutex, TProcess >::kRunExitCodeEnvName[24]
static
Initial value:
=
"SUPERVISE_RUN_EXIT_CODE"

The environment variable to set with the exit code.

template<typename TMutex , typename TProcess >
const DWORD winss::SuperviseTmpl< TMutex, TProcess >::kRunFailedWait = 10000
static

Run failed wait 10s.

template<typename TMutex , typename TProcess >
constexpr const char winss::SuperviseTmpl< TMutex, TProcess >::kRunFile[4] = "run"
static

Run file.

Referenced by winss::SuperviseStateFile::Notify().

template<typename TMutex , typename TProcess >
const int winss::SuperviseTmpl< TMutex, TProcess >::kSignaledExitCode = 256
static

Signaled to exit.

template<typename TMutex , typename TProcess >
constexpr const char winss::SuperviseTmpl< TMutex, TProcess >::kTimeoutFinishFile[15] = "timeout-finish"
static

Timeout finish file.

template<typename TMutex , typename TProcess >
constexpr const char winss::SuperviseTmpl< TMutex, TProcess >::kTimeoutGroup[10] = "supervise"
static

The timeout group for the multiplexer.

template<typename TMutex , typename TProcess >
std::vector<winss::NotOwningPtr<winss::SuperviseListener> > winss::SuperviseTmpl< TMutex, TProcess >::listeners
protected

The supervisor listeners.

template<typename TMutex , typename TProcess >
winss::NotOwningPtr<winss::WaitMultiplexer> winss::SuperviseTmpl< TMutex, TProcess >::multiplexer
protected

The event multiplexer for the supervisor.

template<typename TMutex , typename TProcess >
TMutex winss::SuperviseTmpl< TMutex, TProcess >::mutex
protected

The supervisor global mutex.

template<typename TMutex , typename TProcess >
TProcess winss::SuperviseTmpl< TMutex, TProcess >::process
protected

The supervised process.

template<typename TMutex , typename TProcess >
fs::path winss::SuperviseTmpl< TMutex, TProcess >::service_dir
protected

The service directory.

template<typename TMutex , typename TProcess >
SuperviseState winss::SuperviseTmpl< TMutex, TProcess >::state {}
protected

The current supervised state.

template<typename TMutex , typename TProcess >
bool winss::SuperviseTmpl< TMutex, TProcess >::waiting = false
protected

The waiting state.


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