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/helpers/i_ref_countable_registry.h>
11 #include <nx/sdk/i_string_map.h>
12
13 namespace nx::sdk {
14
21 class ILibContext
22 {
23 public:
24 virtual ~ILibContext() = default;
25
26 virtual void setName(const char* name) = 0;
27 virtual void setRefCountableRegistry(IRefCountableRegistry* refCountableRegistry) = 0;
28 };
29
36 class LibContext final: public ILibContext
37 {
38 public:
43 virtual void setName(const char* name) override;
44
50 virtual void setRefCountableRegistry(IRefCountableRegistry* refCountableRegistry) override;
51
52 const std::string& name() const { return m_name; }
53
55 IRefCountableRegistry* refCountableRegistry() const { return m_refCountableRegistry.get(); }
56
57 private:
58 static constexpr const char *kDefaultName = "unnamed_lib_context";
59 std::string m_name = kDefaultName;
60 std::unique_ptr<IRefCountableRegistry> m_refCountableRegistry;
61 std::mutex m_mutex;
62 };
63
64 //-------------------------------------------------------------------------------------------------
65
70 LibContext& libContext();
71
76 const char* sdkVersion();
77
82 std::map<std::string, std::string>& unitTestOptions();
83
84 #if !defined(NX_SDK_API)
85 #if !defined(NX_PLUGIN_API)
86 #error "Either NX_SDK_API or NX_PLUGIN_API macro should be defined to export a function."
87 #endif
88 #define NX_SDK_API NX_PLUGIN_API
89 #endif
90
98 extern "C" NX_SDK_API ILibContext* nxLibContext();
99 static constexpr const char* kNxLibContextFuncName = "nxLibContext";
100 typedef ILibContext* (*NxLibContextFunc)();
101
116 extern "C" NX_SDK_API const char* nxSdkVersion();
117 static constexpr const char* kNxSdkVersionFuncName = "nxSdkVersion";
118 typedef const char* (*NxSdkVersionFunc)();
119
131 extern "C" NX_SDK_API void nxSetUnitTestOptions(const IStringMap* options);
132 static constexpr const char* kNxSetUnitTestOptionsFuncName = "nxSetUnitTestOptions";
133 typedef void (*NxSetUnitTestOptionsFunc)(const IStringMap* options);
134
135 } // namespace nx::sdk
nx::sdk::LibContext::setRefCountableRegistry
virtual void setRefCountableRegistry(IRefCountableRegistry *refCountableRegistry) override
Definition: lib_context.cpp:31
nx::sdk::IRefCountableRegistry
Definition: i_ref_countable_registry.h:25
nx::sdk::LibContext::setName
virtual void setName(const char *name) override
Definition: lib_context.cpp:11
nx::sdk
Definition: device_agent.h:12
nx::sdk::LibContext
Definition: lib_context.h:36
nx::sdk::LibContext::refCountableRegistry
IRefCountableRegistry * refCountableRegistry() const
Definition: lib_context.h:55
nx::sdk::ILibContext
Definition: lib_context.h:21