template class ProcessLauncher

Overview

Base class for all process launchers. More…

#include <process_launcher.h>

template <
    class PROCESS_LAUNCHER,
    const char* LAUNCHER_TYPE,
    class ... LAUNCHER_COMMANDS
>
class ProcessLauncher: public ProcessLauncherInterface {
public:
    // fields

    static constexpr auto LauncherType = LAUNCHER_TYPE;

    // methods

    virtual ProcessLauncherInterface::unique_ptr createLauncher(int logFD = -1);
    virtual std::string launcherName() const;

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

    virtual pid_t stopProcess(unsigned int killWait);
};

// direct descendants

class ProcessLauncherBasic;

Inherited Members

public:
    // typedefs

    typedef std::shared_ptr<T> shared_ptr;
    typedef std::shared_ptr<const T> const_shared_ptr;
    typedef std::unique_ptr<T> unique_ptr;
    typedef std::unique_ptr<const T> const_unique_ptr;
    typedef LaunchCommandInterface::ENGINE_RUNNING_STATUS ENGINE_RUNNING_STATUS;

    // fields

    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;

    // methods

    virtual std::string launcherName() const = 0;
    virtual ProcessLauncherInterface::unique_ptr createLauncher(int logFD = -1) = 0;

    virtual pid_t launchProcess(
        nlohmann::json procConfig,
        bool appendParentEnv = true
    ) = 0;

    virtual pid_t stopProcess(unsigned int killWait) = 0;
    virtual ENGINE_RUNNING_STATUS getProcessStatus();
    LaunchCommandInterface* launchCommand() const;
    void setFileDescriptor(int logFD);

Detailed Documentation

Base class for all process launchers.

Parameters:

PROCESS_LAUNCHER

Final class derived from ProcessLauncher

LAUNCHER_TYPE

Launcher Type as string

Methods

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

Create a new process launcher.

Parameters:

logFD

File descriptor to route stdout and stderror outputs in launched process

virtual std::string launcherName() const

Get name of launcher.

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

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

Parameters:

procConfig

Process Configuration. Env variables and start params take precedence over envParams and startParams

appendParentEnv

Should parent env variables be appended to child process

Returns:

Returns Process ID of child process on success

virtual pid_t stopProcess(unsigned int killWait)

Stop a running process.

Parameters:

killWait

Time (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