winss
|
The supervisor class template. More...
#include <supervise.hpp>
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 SuperviseState & | GetState () 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... | |
SuperviseTmpl & | operator= (const SuperviseTmpl &)=delete |
No copy. More... | |
SuperviseTmpl & | operator= (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::WaitMultiplexer > | multiplexer |
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... | |
The supervisor class template.
TMutex | The mutex implementation type. |
TProcess | The process implementation type. |
|
inline |
Supervise constructor.
multiplexer | The shared multiplexer. |
service_dir | The service directory. |
References winss::WaitMultiplexer::AddInitCallback(), and winss::WaitMultiplexer::AddStopCallback().
|
delete |
No copy.
|
delete |
No move.
|
inlinevirtual |
Adds a supervisor listener to the list of listeners.
[in] | listener | The listener to add. |
Referenced by winss::SuperviseController::SuperviseController().
|
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.
References winss::EXIT, winss::WaitMultiplexer::IsStopping(), and winss::WaitMultiplexer::Stop().
|
inlinevirtual |
Signals the supervisor to be in the down state.
|
inlinevirtual |
Signals the supervisor to exit.
|
inlineprotectedvirtual |
Gets the finish timeout value.
This will read the finish-timeout file if it exists.
References FILESYSTEM.
|
inlinevirtual |
Gets the current supervisor state.
|
inlineprotectedvirtual |
Initializes the supervisor.
References FILESYSTEM, winss::START, and winss::WaitMultiplexer::Stop().
|
inlinevirtual |
Kills the supervised process.
|
inlineprotectedvirtual |
Notify all the listeners with the given event.
[in] | notification | The notification event. |
References winss::END, and winss::RUN.
|
inlinevirtual |
Signals the supervisor to be in the up state and when the process exits then leave it down.
|
inlinevirtual |
Signals the supervisor to only run one if it is already running.
|
delete |
No copy.
|
delete |
No move.
|
inlineprotectedvirtual |
Starts the process defined in the given file.
[in] | file_name | The file which contains the process and arguments. |
References winss::ProcessParams::env, winss::Utils::ExpandEnvironmentVariables(), and FILESYSTEM.
|
inlineprotectedvirtual |
Starts the finish file process.
References winss::WaitMultiplexer::AddTimeoutCallback(), winss::WaitMultiplexer::AddTriggeredCallback(), and WINDOWS.
|
inlineprotectedvirtual |
Starts the run file process.
References winss::WaitMultiplexer::AddTriggeredCallback(), winss::RUN, and WINDOWS.
|
inlineprotectedvirtual |
Signal the supervisor to exit.
|
inlinevirtual |
Sends a CTRL+BREAK to the supervised process.
|
inlineprotectedvirtual |
Event triggered handler.
This will step the state machine forward.
[in] | timeout | If the event was a timeout event. |
References winss::WaitMultiplexer::AddTimeoutCallback(), winss::BROKEN, winss::END, winss::FINISHED, and winss::WaitMultiplexer::RemoveTimeoutCallback().
|
inlinevirtual |
Signals the supervisor to go into the up state.
|
protected |
The exiting state.
|
static |
Busy wait 1s.
|
static |
Default timeout 5s.
|
static |
Signal down.
|
static |
Down file.
|
static |
Env directory.
|
static |
Something went wrong.
|
static |
Finish file.
Referenced by winss::SuperviseStateFile::Notify().
|
static |
Mutex name.
|
static |
Service dir in use error.
|
static |
The environment variable to set with the exit code.
|
static |
Run failed wait 10s.
|
static |
Run file.
Referenced by winss::SuperviseStateFile::Notify().
|
static |
Signaled to exit.
|
static |
Timeout finish file.
|
static |
The timeout group for the multiplexer.
|
protected |
The supervisor listeners.
|
protected |
The event multiplexer for the supervisor.
|
protected |
The supervisor global mutex.
|
protected |
The supervised process.
|
protected |
The service directory.
|
protected |
The current supervised state.
|
protected |
The waiting state.