nx_metadata_sdk 1.0 Metadata SDK

lib_context.h
1 // Copyright 2018-present Network Optix, Inc. Licensed under MPL 2.0: www.mozilla.org/MPL/2.0/
2
3 #pragma once
4
5 #include <map>
6 #include <memory>
7 #include <mutex>
8 #include <string>
9
10 #include <nx/sdk/i_string_map.h>
11
12 #include <nx/sdk/helpers/i_ref_countable_registry.h>
13
14 namespace nx {
15 namespace sdk {
16
23 class ILibContext
24 {
25 public:
26 virtual ~ILibContext() = default;
27
28 virtual void setName(const char* name) = 0;
29 virtual void setRefCountableRegistry(IRefCountableRegistry* refCountableRegistry) = 0;
30 };
31
38 class LibContext final: public ILibContext
39 {
40 public:
45 virtual void setName(const char* name) override;
46
52 virtual void setRefCountableRegistry(IRefCountableRegistry* refCountableRegistry) override;
53
54 const std::string& name() const { return m_name; }
55
57 IRefCountableRegistry* refCountableRegistry() const { return m_refCountableRegistry.get(); }
58
59 private:
60 static constexpr const char *kDefaultName = "unnamed_lib_context";
61 std::string m_name = kDefaultName;
62 std::unique_ptr<IRefCountableRegistry> m_refCountableRegistry;
63 std::mutex m_mutex;
64 };
65
66 //-------------------------------------------------------------------------------------------------
67
72 LibContext& libContext();
73
78 const char* sdkVersion();
79
84 std::map<std::string, std::string>& unitTestOptions();
85
86 #if !defined(NX_SDK_API)
87 #if !defined(NX_PLUGIN_API)
88 #error "Either NX_SDK_API or NX_PLUGIN_API macro should be defined to export a function."
89 #endif
90 #define NX_SDK_API NX_PLUGIN_API
91 #endif
92
100 extern "C" NX_SDK_API ILibContext* nxLibContext();
101 static constexpr const char* kNxLibContextFuncName = "nxLibContext";
102 typedef ILibContext* (*NxLibContextFunc)();
103
118 extern "C" NX_SDK_API const char* nxSdkVersion();
119 static constexpr const char* kNxSdkVersionFuncName = "nxSdkVersion";
120 typedef const char* (*NxSdkVersionFunc)();
121
133 extern "C" NX_SDK_API void nxSetUnitTestOptions(const IStringMap* options);
134 static constexpr const char* kNxSetUnitTestOptionsFuncName = "nxSetUnitTestOptions";
135 typedef void (*NxSetUnitTestOptionsFunc)(const IStringMap* options);
136
137 } // namespace sdk
138 } // namespace nx
nx::sdk::LibContext::setRefCountableRegistry
virtual void setRefCountableRegistry(IRefCountableRegistry *refCountableRegistry) override
Definition: lib_context.cpp:31
nx::sdk::IRefCountableRegistry
Definition: i_ref_countable_registry.h:26
nx::sdk::LibContext::setName
virtual void setName(const char *name) override
Definition: lib_context.cpp:11
nx
Definition: apple_utils.h:6
nx::sdk::LibContext
Definition: lib_context.h:38
nx::sdk::LibContext::refCountableRegistry
IRefCountableRegistry * refCountableRegistry() const
Definition: lib_context.h:57
nx::sdk::ILibContext
Definition: lib_context.h:23