NRP Core  1.4.1
ProcessLauncherInterface Class Referenceabstract

Functions for all process launchers. More...

#include <process_launcher.h>

Inheritance diagram for ProcessLauncherInterface:
PtrTemplates< ProcessLauncherInterface > ProcessLauncher< PROCESS_LAUNCHER, LAUNCHER_TYPE, LAUNCHER_COMMANDS > ProcessLauncher< ProcessLauncherBasic, Basic, BasicFork, DockerLauncher, EmptyLaunchCommand > ProcessLauncherBasic

Public Types

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 >
 

Public Member Functions

virtual ~ProcessLauncherInterface ()=default
 
virtual std::string launcherName () const =0
 Get name of launcher. More...
 
virtual ProcessLauncherInterface::unique_ptr createLauncher (int logFD=-1)=0
 Create a new process launcher. More...
 
virtual pid_t launchProcess (nlohmann::json procConfig, bool appendParentEnv=true)=0
 Fork a new process. Will read environment variables and start params from procConfig. More...
 
virtual pid_t stopProcess (unsigned int killWait)=0
 Stop a running process. More...
 
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 UNKNOWN = LaunchCommandInterface::ENGINE_RUNNING_STATUS::UNKNOWN
 
static constexpr auto RUNNING = LaunchCommandInterface::ENGINE_RUNNING_STATUS::RUNNING
 
static constexpr auto STOPPED = LaunchCommandInterface::ENGINE_RUNNING_STATUS::STOPPED
 

Static Protected Member Functions

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

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

Functions for all process launchers.

Member Typedef Documentation

◆ ENGINE_RUNNING_STATUS

Constructor & Destructor Documentation

◆ ~ProcessLauncherInterface()

virtual ProcessLauncherInterface::~ProcessLauncherInterface ( )
virtualdefault

Member Function Documentation

◆ checkEnvVar()

bool ProcessLauncherInterface::checkEnvVar ( const std::string &  envVar)
staticprotected

Checks given Environment variable for correctness (Should contain an '=' character)

Parameters
envVarVariable to check
Returns
Returns true if valid, false otherwise

◆ createLauncher()

virtual ProcessLauncherInterface::unique_ptr ProcessLauncherInterface::createLauncher ( int  logFD = -1)
pure virtual

Create a new process launcher.

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

Implemented in ProcessLauncher< PROCESS_LAUNCHER, LAUNCHER_TYPE, LAUNCHER_COMMANDS >, and ProcessLauncher< ProcessLauncherBasic, Basic, BasicFork, DockerLauncher, EmptyLaunchCommand >.

◆ getProcessStatus()

virtual ENGINE_RUNNING_STATUS ProcessLauncherInterface::getProcessStatus ( )
inlinevirtual

Get the current process status. If status cannot be retrieved, return ENGINE_RUNNING_STATUS::UNKNOWN.

Returns
Returns status as enum ProcessLauncherInterface::ENGINE_RUNNING_STATUS

◆ launchCommand()

LaunchCommandInterface * ProcessLauncherInterface::launchCommand ( ) const

Get Launch Command. If launchProcess has not yet been called, return nullptr.

◆ launcherName()

virtual std::string ProcessLauncherInterface::launcherName ( ) const
pure virtual

◆ launchProcess()

virtual pid_t ProcessLauncherInterface::launchProcess ( nlohmann::json  procConfig,
bool  appendParentEnv = true 
)
pure virtual

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

Implemented in ProcessLauncher< PROCESS_LAUNCHER, LAUNCHER_TYPE, LAUNCHER_COMMANDS >, and ProcessLauncher< ProcessLauncherBasic, Basic, BasicFork, DockerLauncher, EmptyLaunchCommand >.

◆ setFileDescriptor()

void ProcessLauncherInterface::setFileDescriptor ( int  logFD)

Sets the file descriptor that will be used by the launched process to write stdout and stderror.

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

◆ splitEnvVar()

std::tuple< std::string, std::string > ProcessLauncherInterface::splitEnvVar ( const std::string &  envVar)
staticprotected

Split Environment variable string into variable name and value.

Parameters
envVarString to split. Should have the form <VAR_NAME>=<VAR_VALUE>
Returns
Returns tuple. First value is VAR_NAME, second one is VAR_VALUE. If envVar has an invalid form, returns an empty string for both values

◆ stopProcess()

virtual pid_t ProcessLauncherInterface::stopProcess ( unsigned int  killWait)
pure virtual

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

Implemented in ProcessLauncher< PROCESS_LAUNCHER, LAUNCHER_TYPE, LAUNCHER_COMMANDS >, and ProcessLauncher< ProcessLauncherBasic, Basic, BasicFork, DockerLauncher, EmptyLaunchCommand >.

Member Data Documentation

◆ _launchCmd

LaunchCommandInterface::unique_ptr ProcessLauncherInterface::_launchCmd = nullptr
protected

Launch Command.

◆ _logFD

int ProcessLauncherInterface::_logFD = -1
protected

File descriptor to route stdout and stderror outputs in launched process.

◆ RUNNING

constexpr auto ProcessLauncherInterface::RUNNING = LaunchCommandInterface::ENGINE_RUNNING_STATUS::RUNNING
staticconstexpr

◆ STOPPED

constexpr auto ProcessLauncherInterface::STOPPED = LaunchCommandInterface::ENGINE_RUNNING_STATUS::STOPPED
staticconstexpr

◆ UNKNOWN

constexpr auto ProcessLauncherInterface::UNKNOWN = LaunchCommandInterface::ENGINE_RUNNING_STATUS::UNKNOWN
staticconstexpr

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