nx_server_plugin_sdk 1.0 Server Plugin 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 struct LibContextEntryPoint
100 {
101 static constexpr char kFuncName[] = "nxLibContext";
102 using Func = decltype(&nxLibContext);
103 };
104
119 extern "C" NX_SDK_API const char* nxSdkVersion();
120 struct SdkVersionEntryPoint
121 {
122 static constexpr char kFuncName[] = "nxSdkVersion";
123 using Func = decltype(&nxSdkVersion);
124 };
125
137 extern "C" NX_SDK_API void nxSetUnitTestOptions(const IStringMap* options);
138 struct SetUnitTestOptionsEntryPoint
139 {
140 static constexpr char kFuncName[] = "nxSetUnitTestOptions";
141 using Func = decltype(&nxSetUnitTestOptions);
142 };
143
144 } // namespace nx::sdk
nx::sdk::LibContext::setRefCountableRegistry
virtual void setRefCountableRegistry(IRefCountableRegistry *refCountableRegistry) override
Definition: lib_context.cpp:31
nx::sdk::IStringMap
Definition: i_string_map.h:9
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::SetUnitTestOptionsEntryPoint
Definition: lib_context.h:138
nx::sdk::LibContextEntryPoint
Definition: lib_context.h:99
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
nx::sdk::SdkVersionEntryPoint
Definition: lib_context.h:120