NRP Core  1.4.1
process_launcher_manager.h
Go to the documentation of this file.
1 /* * NRP Core - Backend infrastructure to synchronize simulations
2  *
3  * Copyright 2020-2023 NRP Team
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * This project has received funding from the European Union’s Horizon 2020
18  * Framework Programme for Research and Innovation under the Specific Grant
19  * Agreement No. 945539 (Human Brain Project SGA3).
20  */
21 
22 #ifndef PROCESS_LAUNCHER_MANAGER_H
23 #define PROCESS_LAUNCHER_MANAGER_H
24 
28 
29 #include <iostream>
30 #include <map>
31 
35 template<class ...PROCESS_LAUNCHERS>
37  : public PtrTemplates<ProcessLauncherManager<PROCESS_LAUNCHERS...> >
38 {
39  public:
43  ProcessLauncherManager(int logFD = -1) :
44  _logFD(logFD)
45  { this->registerProcessLauncher<PROCESS_LAUNCHERS...>(); }
46  ~ProcessLauncherManager() = default;
47 
48  // Delete copy and move constructors
51 
54 
60  ProcessLauncherInterface::unique_ptr createProcessLauncher(const std::string &launcherType) const
61  {
62  NRP_LOGGER_TRACE("{} called", __FUNCTION__);
63  //ProcessLauncherManager *const manager = ProcessLauncherManager::getInstance();
64 
65  const auto launcherIterator = this->_processLaunchers.find(launcherType);
66  if(launcherIterator == this->_processLaunchers.end())
67  throw NRPException::logCreate("Could not find process launcher of type \"" + launcherType + "\"");
68 
69  return launcherIterator->second->createLauncher(_logFD);
70  }
71 
73  { this->_processLaunchers.emplace(launcher->launcherName(), std::move(launcher)); }
74 
75  private:
76 
80  std::map<std::string, ProcessLauncherInterface::unique_ptr> _processLaunchers;
81 
85  int _logFD = -1;
86 
92  template<class PROCESS_LAUNCHER, class ...REST>
93  void registerProcessLauncher()
94  {
95  static_assert(std::is_base_of_v<ProcessLauncherInterface, PROCESS_LAUNCHER> && std::is_convertible_v<const volatile PROCESS_LAUNCHER*, const volatile ProcessLauncherInterface*>,"Parameter PROCESS_LAUNCHER must derive from ProcessLauncherInterface");
96 
97  NRP_LOGGER_TRACE("{} called", __FUNCTION__);
98 
99  ProcessLauncherInterface::unique_ptr launcher(new PROCESS_LAUNCHER());
100  this->registerProcessLauncher(std::move(launcher));
101 
102  if constexpr (sizeof... (REST) > 0)
103  { this->registerProcessLauncher<REST...>(); }
104  }
105 };
106 
111 
114 
115 
116 #endif // PROCESS_LAUNCHER_MANAGER_H
process_launcher_basic.h
ProcessLauncherManager
Class to manage process managers.
Definition: process_launcher_manager.h:36
ProcessLauncherManager::ProcessLauncherManager
ProcessLauncherManager(int logFD=-1)
Constructor. Registers all Process Launchers for further use.
Definition: process_launcher_manager.h:43
PtrTemplates< ProcessLauncherInterface >::unique_ptr
std::unique_ptr< ProcessLauncherInterface > unique_ptr
Definition: ptr_templates.h:34
process_launcher.h
nrp_exceptions.h
ProcessLauncherManager::~ProcessLauncherManager
~ProcessLauncherManager()=default
PtrTemplates< ProcessLauncherManager< PROCESS_LAUNCHERS... > >::const_shared_ptr
std::shared_ptr< const ProcessLauncherManager< PROCESS_LAUNCHERS... > > const_shared_ptr
Definition: ptr_templates.h:32
ProcessLauncherManager::registerProcessLauncher
void registerProcessLauncher(ProcessLauncherInterface::unique_ptr &&launcher)
Definition: process_launcher_manager.h:72
ProcessLauncherManager::createProcessLauncher
ProcessLauncherInterface::unique_ptr createProcessLauncher(const std::string &launcherType) const
Create a new process launcher.
Definition: process_launcher_manager.h:60
PtrTemplates
Definition: ptr_templates.h:28
MainProcessLauncherManagerConstSharedPtr
MainProcessLauncherManager::const_shared_ptr MainProcessLauncherManagerConstSharedPtr
Definition: process_launcher_manager.h:113
NRPException::logCreate
static EXCEPTION logCreate(LOG_EXCEPTION_T &exception, const std::string &msg, NRPLogger::spdlog_out_fcn_t spdlogCall=NRPLogger::critical)
Definition: nrp_exceptions.h:73
ProcessLauncherManager::operator=
ProcessLauncherManager & operator=(ProcessLauncherManager &&)=delete
MainProcessLauncherManagerSharedPtr
MainProcessLauncherManager::shared_ptr MainProcessLauncherManagerSharedPtr
Definition: process_launcher_manager.h:112
PtrTemplates< ProcessLauncherManager< PROCESS_LAUNCHERS... > >::shared_ptr
std::shared_ptr< ProcessLauncherManager< PROCESS_LAUNCHERS... > > shared_ptr
Definition: ptr_templates.h:31
NRP_LOGGER_TRACE
#define NRP_LOGGER_TRACE(...)
trace log macro. It is voided by defining \PRODUCTION_RELEASE
Definition: nrp_logger.h:39