NAP
utility/src/utility/module.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 "dllexport.h"
9 
10 // External includes
11 #include <string>
12 
35 namespace nap
36 {
37  constexpr int moduleAPIVersion = 1;
38  constexpr const char* moduleCoreName = "napcore";
39 
45  {
46  int mAPIVersion; // The version of the module API this module was built against. Must be the first member.
47  const char* mID; // The ID (name) of the module
48  const char* mVersion; // The version of the module
49  const char* mService; // The service associated with the module
50  };
51 
56  inline std::string getModuleDescriptorSymbolName(const std::string& moduleName) { return moduleName + "_mod_descriptor"; }
57 }
58 
59 
61 // Macros
63 
64 #ifdef NAP_SHARED_LIBRARY
65  // Module descriptor helper macros
66  #define NAP_MODULE_CONCAT(x,y) x ## y
67  #define NAP_MODULE_UNIQUE_NAME(x,y) NAP_MODULE_CONCAT(x,y)
68  #define NAP_MODULE_ADD_NS(x) nap::x
69 
70  // Module descriptor symbol name without namespace
71  #define NAP_MODULE_SYMBOL_NAME NAP_MODULE_UNIQUE_NAME(MODULE_NAME, _mod_descriptor)
72 
73  // Module descriptor handle (pointer) with namespace
74  #define NAP_MODULE_DESCIPTOR_HANDLE &NAP_MODULE_ADD_NS(NAP_MODULE_SYMBOL_NAME)
75 #else
76  #define NAP_MODULE_DESCIPTOR_HANDLE nullptr
77 #endif // NAP_SHARED_LIBRARY
78 
79 namespace nap
80 {
85  #define NAP_MODULE(moduleID, moduleVersion) \
86  extern "C" \
87  { \
88  NAPAPI nap::ModuleDescriptor NAP_MODULE_SYMBOL_NAME = \
89  { \
90  nap::moduleAPIVersion, \
91  moduleID, \
92  moduleVersion, \
93  nullptr \
94  }; \
95  }
96 
101  #define NAP_SERVICE_MODULE(moduleID, moduleVersion, moduleService) \
102  extern "C" \
103  { \
104  NAPAPI nap::ModuleDescriptor NAP_MODULE_SYMBOL_NAME = \
105  { \
106  nap::moduleAPIVersion, \
107  moduleID, \
108  moduleVersion, \
109  moduleService \
110  }; \
111  }
112 
117  extern "C"
118  {
119  #ifdef NAP_MODULE_SYMBOL_NAME
120  extern nap::ModuleDescriptor NAP_MODULE_SYMBOL_NAME;
121  #endif // NAP_MODULE_DECLARATION
122  }
123 }
nap::ModuleDescriptor::mAPIVersion
int mAPIVersion
Definition: utility/src/utility/module.h:46
nap::ModuleDescriptor::mID
const char * mID
Definition: utility/src/utility/module.h:47
nap::ModuleDescriptor
Definition: utility/src/utility/module.h:44
nap::ModuleDescriptor::mVersion
const char * mVersion
Definition: utility/src/utility/module.h:48
nap::moduleCoreName
constexpr const char * moduleCoreName
Core module name id.
Definition: utility/src/utility/module.h:38
nap::moduleAPIVersion
constexpr int moduleAPIVersion
Current module API version.
Definition: utility/src/utility/module.h:37
nap::ModuleDescriptor::mService
const char * mService
Definition: utility/src/utility/module.h:49
nap::getModuleDescriptorSymbolName
std::string getModuleDescriptorSymbolName(const std::string &moduleName)
Definition: utility/src/utility/module.h:56
nap
Definition: templateapp.h:17