Blue Brain BioExplorer
EngineFactory.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2024, EPFL/Blue Brain Project
3  *
4  * The Blue Brain BioExplorer is a tool for scientists to extract and analyse
5  * scientific data from visualization
6  *
7  * This file is part of Blue Brain BioExplorer <https://github.com/BlueBrain/BioExplorer>
8  *
9  * This library is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU Lesser General Public License version 3.0 as published
11  * by the Free Software Foundation.
12  *
13  * This library is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with this library; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22 
23 #include "EngineFactory.h"
24 
28 
29 #if (PLATFORM_USE_OSPRAY)
31 #endif
32 
33 namespace core
34 {
36 std::map<std::string, std::string> SUPPORTED_ENGINES = {{ENGINE_OSPRAY, "OSPRayEngine"},
37  {ENGINE_OPTIX_6, "OptiX6Engine"}};
38 
39 typedef Engine* (*CreateFuncType)(int, const char**, ParametersManager&);
40 
41 EngineFactory::EngineFactory(const int argc, const char** argv, ParametersManager& parametersManager)
42  : _argc{argc}
43  , _argv{argv}
44  , _parametersManager{parametersManager}
45 {
46 }
47 
48 Engine* EngineFactory::create(const std::string& name)
49 {
50  const auto it = SUPPORTED_ENGINES.find(name);
51 
52  if (it == SUPPORTED_ENGINES.end())
53  CORE_THROW("Unsupported engine: " + name);
54 
55  const auto libraryName = (*it).second;
56  if (_engines.count(libraryName) == 0)
57  return _loadEngine(libraryName.c_str(), _argc, _argv);
58  return _engines[libraryName].get();
59 }
60 
61 Engine* EngineFactory::_loadEngine(const std::string& name, int argc, const char* argv[])
62 {
63  try
64  {
65  DynamicLib library(name);
66  auto createSym = library.getSymbolAddress("core_engine_create");
67  if (!createSym)
68  {
69  throw std::runtime_error(std::string("Plugin '") + name + "' is not a valid Core engine; missing " +
70  "core_engine_create()");
71  }
72 
73  CreateFuncType createFunc = (CreateFuncType)createSym;
74  if (auto plugin = createFunc(argc, argv, _parametersManager))
75  {
76  _engines.emplace(name, std::unique_ptr<Engine>(plugin));
77  _libs.push_back(std::move(library));
78  CORE_INFO("Loaded engine '" << name << "'");
79  return plugin;
80  }
81  }
82  catch (const std::runtime_error& exc)
83  {
84  CORE_ERROR("Failed to load engine " << std::quoted(name) << ": " << exc.what());
85  }
86  return nullptr;
87 }
88 } // namespace core
EngineFactory(int argc, const char **argv, ParametersManager &parametersManager)
Constructor.
Engine * create(const std::string &name)
Create an instance of the engine corresponding the given name. If the name is incorrect,...
Provides an abstract implementation of a ray-tracing engine.
Definition: Engine.h:59
std::map< std::string, std::string > SUPPORTED_ENGINES
Engine *(* CreateFuncType)(int, const char **, ParametersManager &)
#define CORE_THROW(__msg)
Definition: Logs.h:42
#define CORE_INFO(__msg)
Definition: Logs.h:33
#define CORE_ERROR(__msg)
Definition: Logs.h:31