NRP Core  1.4.1
ProcessLauncher< PROCESS_LAUNCHER, LAUNCHER_TYPE, LAUNCHER_COMMANDS > Class Template Reference

Base class for all process launchers. More...

#include <process_launcher.h>

Inheritance diagram for ProcessLauncher< PROCESS_LAUNCHER, LAUNCHER_TYPE, LAUNCHER_COMMANDS >:
ProcessLauncherInterface PtrTemplates< ProcessLauncherInterface >

Public Member Functions

 ProcessLauncher ()
 
 ~ProcessLauncher () override=default
 
ProcessLauncherInterface::unique_ptr createLauncher (int logFD=-1) override
 Create a new process launcher. More...
 
std::string launcherName () const override final
 Get name of launcher. More...
 
pid_t launchProcess (nlohmann::json procConfig, bool appendParentEnv=true) override final
 Fork a new process. Will read environment variables and start params from procConfig. More...
 
pid_t stopProcess (unsigned int killWait) override final
 Stop a running process. More...
 
- Public Member Functions inherited from ProcessLauncherInterface
virtual ~ProcessLauncherInterface ()=default
 
virtual ENGINE_RUNNING_STATUS getProcessStatus ()
 Get the current process status. If status cannot be retrieved, return ENGINE_RUNNING_STATUS::UNKNOWN. More...
 
LaunchCommandInterfacelaunchCommand () const
 Get Launch Command. If launchProcess has not yet been called, return nullptr. More...
 
void setFileDescriptor (int logFD)
 Sets the file descriptor that will be used by the launched process to write stdout and stderror. More...
 

Static Public Attributes

static constexpr auto LauncherType = LAUNCHER_TYPE
 
- Static Public Attributes inherited from ProcessLauncherInterface
static constexpr auto UNKNOWN = LaunchCommandInterface::ENGINE_RUNNING_STATUS::UNKNOWN
 
static constexpr auto RUNNING = LaunchCommandInterface::ENGINE_RUNNING_STATUS::RUNNING
 
static constexpr auto STOPPED = LaunchCommandInterface::ENGINE_RUNNING_STATUS::STOPPED
 

Additional Inherited Members

- Public Types inherited from ProcessLauncherInterface
using ENGINE_RUNNING_STATUS = LaunchCommandInterface::ENGINE_RUNNING_STATUS
 
- Public Types inherited from PtrTemplates< ProcessLauncherInterface >
using shared_ptr = std::shared_ptr< ProcessLauncherInterface >
 
using const_shared_ptr = std::shared_ptr< const ProcessLauncherInterface >
 
using unique_ptr = std::unique_ptr< ProcessLauncherInterface >
 
using const_unique_ptr = std::unique_ptr< const ProcessLauncherInterface >
 
- Static Protected Member Functions inherited from ProcessLauncherInterface
static bool checkEnvVar (const std::string &envVar)
 Checks given Environment variable for correctness (Should contain an '=' character) More...
 
static std::tuple< std::string, std::string > splitEnvVar (const std::string &envVar)
 Split Environment variable string into variable name and value. More...
 
- Protected Attributes inherited from ProcessLauncherInterface
LaunchCommandInterface::unique_ptr _launchCmd = nullptr
 Launch Command. More...
 
int _logFD = -1
 File descriptor to route stdout and stderror outputs in launched process. More...
 

Detailed Description

template<class PROCESS_LAUNCHER, const char * LAUNCHER_TYPE, class ... LAUNCHER_COMMANDS>
class ProcessLauncher< PROCESS_LAUNCHER, LAUNCHER_TYPE, LAUNCHER_COMMANDS >

Base class for all process launchers.

Template Parameters
PROCESS_LAUNCHERFinal class derived from ProcessLauncher
LAUNCHER_TYPELauncher Type as string

Constructor & Destructor Documentation

◆ ProcessLauncher()

template<class PROCESS_LAUNCHER , const char * LAUNCHER_TYPE, class ... LAUNCHER_COMMANDS>
ProcessLauncher< PROCESS_LAUNCHER, LAUNCHER_TYPE, LAUNCHER_COMMANDS >::ProcessLauncher ( )
inline

◆ ~ProcessLauncher()

template<class PROCESS_LAUNCHER , const char * LAUNCHER_TYPE, class ... LAUNCHER_COMMANDS>
ProcessLauncher< PROCESS_LAUNCHER, LAUNCHER_TYPE, LAUNCHER_COMMANDS >::~ProcessLauncher ( )
overridedefault

Member Function Documentation

◆ createLauncher()

template<class PROCESS_LAUNCHER , const char * LAUNCHER_TYPE, class ... LAUNCHER_COMMANDS>
ProcessLauncherInterface::unique_ptr ProcessLauncher< PROCESS_LAUNCHER, LAUNCHER_TYPE, LAUNCHER_COMMANDS >::createLauncher ( int  logFD = -1)
inlineoverridevirtual

Create a new process launcher.

Parameters
logFDFile descriptor to route stdout and stderror outputs in launched process

Implements ProcessLauncherInterface.

◆ launcherName()

template<class PROCESS_LAUNCHER , const char * LAUNCHER_TYPE, class ... LAUNCHER_COMMANDS>
std::string ProcessLauncher< PROCESS_LAUNCHER, LAUNCHER_TYPE, LAUNCHER_COMMANDS >::launcherName ( ) const
inlinefinaloverridevirtual

Get name of launcher.

Implements ProcessLauncherInterface.

◆ launchProcess()

template<class PROCESS_LAUNCHER , const char * LAUNCHER_TYPE, class ... LAUNCHER_COMMANDS>
pid_t ProcessLauncher< PROCESS_LAUNCHER, LAUNCHER_TYPE, LAUNCHER_COMMANDS >::launchProcess ( nlohmann::json  procConfig,
bool  appendParentEnv = true 
)
inlinefinaloverridevirtual

Fork a new process. Will read environment variables and start params from procConfig.

Parameters
procConfigProcess Configuration. Env variables and start params take precedence over envParams and startParams
appendParentEnvShould parent env variables be appended to child process
Returns
Returns Process ID of child process on success

Implements ProcessLauncherInterface.

◆ stopProcess()

template<class PROCESS_LAUNCHER , const char * LAUNCHER_TYPE, class ... LAUNCHER_COMMANDS>
pid_t ProcessLauncher< PROCESS_LAUNCHER, LAUNCHER_TYPE, LAUNCHER_COMMANDS >::stopProcess ( unsigned int  killWait)
inlinefinaloverridevirtual

Stop a running process.

Parameters
killWaitTime (in seconds) to wait for process to quit by itself before force killing it. 0 means it will wait indefinitely
Returns
Returns child PID on success, negative value on error

Implements ProcessLauncherInterface.

Member Data Documentation

◆ LauncherType

template<class PROCESS_LAUNCHER , const char * LAUNCHER_TYPE, class ... LAUNCHER_COMMANDS>
constexpr auto ProcessLauncher< PROCESS_LAUNCHER, LAUNCHER_TYPE, LAUNCHER_COMMANDS >::LauncherType = LAUNCHER_TYPE
staticconstexpr

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