NAP
modulemanager.h
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4 
5 #pragma once
6 
7 // Local Includes
8 #include "projectinfo.h"
9 
10 // External Includes
11 #include <utility/module.h>
12 #include <utility/errorstate.h>
13 #include <rtti/typeinfo.h>
14 #include <string>
15 #include <vector>
16 #include <assert.h>
17 
18 namespace nap
19 {
20  // Forward Declares
21  class Core;
22  class ModuleManager;
23 
28  class NAPAPI Module final
29  {
30  friend class ModuleManager;
31  public:
32  Module() = default;
33 
34  // Copy is not allowed
35  Module(Module&) = delete;
36 
37  // Copy assignment is not allowed
38  Module& operator=(const Module&) = delete;
39 
40  // Move is not allowed
41  Module(Module&&) = delete;
42 
43  // Move assignment is not allowed
44  Module& operator=(Module&&) = delete;
45 
49  const std::string& getName() const { return mName; }
50 
54  const ModuleDescriptor& getDescriptor() const { assert(mDescriptor != nullptr); return *mDescriptor; }
55 
59  const ModuleInfo& getInformation() const { assert(mInfo != nullptr); return *mInfo; }
60 
66  std::string findAsset(const std::string& name) const;
67 
72  const rtti::TypeInfo getServiceType() const { return mService; }
73 
74  private:
75  std::string mName;
76  ModuleDescriptor* mDescriptor = nullptr;
77  std::unique_ptr<ModuleInfo> mInfo = nullptr;
78  void* mHandle = nullptr;
79  rtti::TypeInfo mService = rtti::TypeInfo::empty();
80  };
81 
82 
86  class NAPAPI ModuleManager final
87  {
88  friend class Core;
89  public:
90  // Constructor
91  ModuleManager(Core& core);
92 
93  // Destructor
94  ~ModuleManager();
95 
96  // Copy is not allowed
97  ModuleManager(ModuleManager&) = delete;
98 
99  // Copy assignment is not allowed
100  ModuleManager& operator=(const ModuleManager&) = delete;
101 
102  // Move is not allowed
103  ModuleManager(ModuleManager&&) = delete;
104 
105  // Move assignment is not allowed
106  ModuleManager& operator=(ModuleManager&&) = delete;
107 
114  bool loadModules(const ProjectInfo& projectInfo, utility::ErrorState& error);
115 
119  std::vector<nap::Module*> getModules() const;
120 
126  const Module* findModule(const std::string& moduleName) const;
127 
133  const Module* findModule(const nap::rtti::TypeInfo& serviceType) const;
134 
139  template<typename T>
140  const Module* findModule() const { return findModule(RTTI_OF(T)); }
141 
142  private:
151  bool sourceModule(const ProjectInfo& projectinfo, const std::string& moduleName, utility::ErrorState& err);
152 
153  std::vector<std::unique_ptr<Module>> mModules; // The loaded modules
154  Core& mCore; // Core
155  };
156 }
nap::ModuleDescriptor
Definition: utility/src/utility/module.h:17
nap::Module::getInformation
const ModuleInfo & getInformation() const
Definition: modulemanager.h:59
nap::utility::ErrorState
Definition: errorstate.h:19
nap::Core
Definition: core.h:82
nap::Module::getName
const std::string & getName() const
Definition: modulemanager.h:49
nap::ModuleManager::findModule
const Module * findModule() const
Definition: modulemanager.h:140
nap::ModuleManager
Definition: modulemanager.h:86
nap::ModuleInfo
Definition: projectinfo.h:204
nap
Definition: templateapp.h:17
nap::rtti::TypeInfo
rttr::type TypeInfo
Definition: typeinfo.h:140
nap::Module::getServiceType
const rtti::TypeInfo getServiceType() const
Definition: modulemanager.h:72
nap::ProjectInfo
Definition: projectinfo.h:53
nap::Module
Definition: modulemanager.h:28
nap::Module::getDescriptor
const ModuleDescriptor & getDescriptor() const
Definition: modulemanager.h:54