Go to the documentation of this file.
   22 #ifndef PROCESS_LAUNCHER_H 
   23 #define PROCESS_LAUNCHER_H 
   40         static constexpr 
auto UNKNOWN = LaunchCommandInterface::ENGINE_RUNNING_STATUS::UNKNOWN;
 
   41         static constexpr 
auto RUNNING = LaunchCommandInterface::ENGINE_RUNNING_STATUS::RUNNING;
 
   42         static constexpr 
auto STOPPED = LaunchCommandInterface::ENGINE_RUNNING_STATUS::STOPPED;
 
   70         virtual pid_t 
stopProcess(
unsigned int killWait) = 0;
 
   77         {   
return this->
_launchCmd ? this->
_launchCmd->getProcessStatus() : ENGINE_RUNNING_STATUS::UNKNOWN;    }
 
  103         static std::tuple<std::string,std::string> 
splitEnvVar(
const std::string &envVar);
 
  122 template<
class PROCESS_LAUNCHER,
const char *LAUNCHER_TYPE, 
class ...LAUNCHER_COMMANDS>
 
  130             static_assert((std::is_base_of_v<LaunchCommandInterface, LAUNCHER_COMMANDS> && ...) ,
"Parameter LAUNCHER_COMMANDS must derive from LaunchCommandInterface");
 
  131             static_assert((std::is_convertible_v<const volatile LAUNCHER_COMMANDS*, const volatile LaunchCommandInterface*> && ...),
"Parameter LAUNCHER_COMMANDS must be convertible to LaunchCommandInterface");
 
  139             launcher->setFileDescriptor(logFD);
 
  152             if constexpr (
sizeof...(LAUNCHER_COMMANDS) == 0)
 
  153             {   
throw noLauncherFound(launcherConfig.at(
"LaunchType"));  }
 
  155             this->
_launchCmd = ProcessLauncher::findLauncher<LAUNCHER_COMMANDS...>(launcherConfig.at(
"LaunchType"));
 
  156             return this->
_launchCmd->launchProcess(launcherConfig, procConfig.at(
"ProcCmd"),
 
  157                                                    procConfig.contains(
"ProcEnvParams") ? procConfig.at(
"ProcEnvParams").get<std::vector<std::string>>() : std::vector<std::string>(),
 
  158                                                    procConfig.contains(
"ProcStartParams") ? procConfig.at(
"ProcStartParams").get<std::vector<std::string>>() : std::vector<std::string>(),
 
  164         {   
return this->
_launchCmd->stopProcess(killWait);   }
 
  167         template<
class LAUNCH_CMD, 
class ...REST>
 
  170             if(std::string(LAUNCH_CMD::LaunchType) == launchCmd)
 
  174                 if constexpr (
sizeof...(REST) > 0)
 
  175                 {   
return findLauncher<REST...>(launchCmd);    }
 
  177                 {   
throw noLauncherFound(launchCmd);   }
 
  181         static inline std::runtime_error noLauncherFound(
const std::string &launchCmd)
 
  182         {   
return std::runtime_error(
"Unable to find launcher with name \"" + launchCmd + 
"\"");   }
 
  185 #endif // PROCESS_LAUNCHER_H 
  
 
virtual pid_t stopProcess(unsigned int killWait)=0
Stop a running process.
 
virtual std::string launcherName() const =0
Get name of launcher.
 
Functions for all process launchers.
Definition: process_launcher.h:34
 
std::unique_ptr< ProcessLauncherInterface > unique_ptr
Definition: ptr_templates.h:34
 
void validateJson(nlohmann::json &instance, std::string schema_path, bool addPatch)
Validates a json object using a given json schema.
Definition: json_schema_utils.cpp:65
 
ProcessLauncher()
Definition: process_launcher.h:129
 
pid_t launchProcess(nlohmann::json procConfig, bool appendParentEnv=true) override final
Fork a new process. Will read environment variables and start params from procConfig.
Definition: process_launcher.h:146
 
std::string launcherName() const override final
Get name of launcher.
Definition: process_launcher.h:143
 
~ProcessLauncher() override=default
 
LaunchCommandInterface * launchCommand() const
Get Launch Command. If launchProcess has not yet been called, return nullptr.
Definition: process_launcher.cpp:26
 
LaunchCommandInterface::unique_ptr _launchCmd
Launch Command.
Definition: process_launcher.h:108
 
pid_t stopProcess(unsigned int killWait) override final
Stop a running process.
Definition: process_launcher.h:163
 
Definition: launch_command.h:32
 
Definition: ptr_templates.h:28
 
int _logFD
File descriptor to route stdout and stderror outputs in launched process.
Definition: process_launcher.h:113
 
Base class for all process launchers.
Definition: process_launcher.h:123
 
static bool checkEnvVar(const std::string &envVar)
Checks given Environment variable for correctness (Should contain an '=' character)
Definition: process_launcher.cpp:29
 
static constexpr auto LauncherType
Definition: process_launcher.h:127
 
ProcessLauncherInterface::unique_ptr createLauncher(int logFD=-1) override
Create a new process launcher.
Definition: process_launcher.h:136
 
ENGINE_RUNNING_STATUS
Engine Process status.
Definition: launch_command.h:39
 
static constexpr auto STOPPED
Definition: process_launcher.h:42
 
static constexpr auto UNKNOWN
Definition: process_launcher.h:40
 
static constexpr auto RUNNING
Definition: process_launcher.h:41
 
virtual ProcessLauncherInterface::unique_ptr createLauncher(int logFD=-1)=0
Create a new process launcher.
 
static std::tuple< std::string, std::string > splitEnvVar(const std::string &envVar)
Split Environment variable string into variable name and value.
Definition: process_launcher.cpp:32
 
virtual pid_t launchProcess(nlohmann::json procConfig, bool appendParentEnv=true)=0
Fork a new process. Will read environment variables and start params from procConfig.
 
void setFileDescriptor(int logFD)
Sets the file descriptor that will be used by the launched process to write stdout and stderror.
Definition: process_launcher.cpp:41
 
virtual ENGINE_RUNNING_STATUS getProcessStatus()
Get the current process status. If status cannot be retrieved, return ENGINE_RUNNING_STATUS::UNKNOWN.
Definition: process_launcher.h:76
 
virtual ~ProcessLauncherInterface()=default
 
nlohmann::json json
Definition: engine_json_server.cpp:31