Senzing C++ SDK
C++ SDK for Senzing v4, patterned after the official C# SDK
Loading...
Searching...
No Matches
SzCoreEnvironment.hpp
Go to the documentation of this file.
1// SzCoreEnvironment.hpp -- native-backed SzEnvironment implementation + builder.
2//
3// Ports core/SzCoreEnvironment.cs. Owns one lazily-created, cached instance of
4// each subsystem, guarded by a mutex. Get* accessors call EnsureActive() (which
5// throws SzEnvironmentDestroyedException after Destroy()) and return a non-owning
6// reference to the env-owned subsystem.
7//
8// All accessors are implemented: GetProduct, GetEngine, GetConfigManager,
9// GetDiagnostic, plus Destroy, IsDestroyed, GetActiveConfigID, and Reinitialize.
10#ifndef SENZING_SDK_CORE_SZCOREENVIRONMENT_HPP
11#define SENZING_SDK_CORE_SZCOREENVIRONMENT_HPP
12
13#include <cstdint>
14#include <memory>
15#include <mutex>
16#include <optional>
17#include <string>
18
20
21namespace senzing::sdk::core {
22
23class SzCoreProduct;
24class SzCoreConfigManager;
25class SzCoreDiagnostic;
26class SzCoreEngine;
27
29class SzCoreEnvironment final : public SzEnvironment {
30public:
32 static constexpr const char* kDefaultInstanceName = "Senzing Instance";
34 static constexpr const char* kDefaultSettings = "{ }";
35
37 class Builder {
38 public:
39 Builder& InstanceName(const std::string& instanceName);
40 Builder& Settings(const std::string& settings);
41 Builder& VerboseLogging(bool verboseLogging);
45 Builder& ConfigID(int64_t configID);
46 std::unique_ptr<SzCoreEnvironment> Build();
47
48 private:
49 std::string instanceName_{kDefaultInstanceName};
50 std::string settings_{kDefaultSettings};
51 bool verboseLogging_{false};
52 std::optional<int64_t> configID_;
53 };
54
57
63
65
68
69 // ---- SzEnvironment ----
70 SzProduct& GetProduct() override;
71 SzEngine& GetEngine() override;
74 int64_t GetActiveConfigID() override;
75 void Reinitialize(int64_t configID) override;
76 void Destroy() override;
77 bool IsDestroyed() override;
78
79 // ---- Internal accessors used by owned subsystems ----
80 [[nodiscard]] const std::string& GetInstanceName() const noexcept;
81 [[nodiscard]] const std::string& GetSettings() const noexcept;
82 [[nodiscard]] bool IsVerboseLogging() const noexcept;
83
90 [[nodiscard]] std::optional<int64_t> GetConfigID() const noexcept;
91
99
100private:
101 SzCoreEnvironment(std::string instanceName, std::string settings,
102 bool verboseLogging, std::optional<int64_t> configID);
103
106 void EnsureActiveLocked() const;
107
111 SzCoreEngine& EnsureEngine();
112
113 std::string instanceName_;
114 std::string settings_;
115 bool verboseLogging_;
116 std::optional<int64_t> configID_;
117
118 mutable std::mutex monitor_;
119 bool destroyed_{false};
120
121 // Per-process singleton enforcement (mirrors C# active-instance pattern).
122 static std::mutex s_classMutex_;
123 static SzCoreEnvironment* s_activeInstance_;
124
125 std::unique_ptr<SzCoreProduct> coreProduct_;
126 std::unique_ptr<SzCoreConfigManager> coreConfigManager_;
127 std::unique_ptr<SzCoreDiagnostic> coreDiagnostic_;
128 std::unique_ptr<SzCoreEngine> coreEngine_;
129};
130
131} // namespace senzing::sdk::core
132
133#endif // SENZING_SDK_CORE_SZCOREENVIRONMENT_HPP
Manages persisted Senzing configurations and the default config registry.
Definition SzConfigManager.hpp:18
Diagnostic operations against the Senzing repository.
Definition SzDiagnostic.hpp:11
The core Senzing entity-resolution engine.
Definition SzEngine.hpp:28
Factory + lifecycle for the Senzing SDK subsystems.
Definition SzEnvironment.hpp:20
Provides access to the Senzing product version and license metadata.
Definition SzProduct.hpp:10
Core implementation of SzEngine backed by the native Sz_* module.
Definition SzCoreEngine.hpp:27
Fluent builder for constructing an SzCoreEnvironment.
Definition SzCoreEnvironment.hpp:37
Builder & VerboseLogging(bool verboseLogging)
Builder & InstanceName(const std::string &instanceName)
Builder & Settings(const std::string &settings)
std::unique_ptr< SzCoreEnvironment > Build()
Builder & ConfigID(int64_t configID)
Pins an explicit configuration ID for native initialization (mirrors C# AbstractBuilder....
Core implementation of SzEnvironment backed by the native libSz modules.
Definition SzCoreEnvironment.hpp:29
bool IsDestroyed() override
Returns true once Destroy() has been initiated/completed.
static constexpr const char * kDefaultSettings
Default settings when none are supplied (mirrors C#).
Definition SzCoreEnvironment.hpp:34
static constexpr const char * kDefaultInstanceName
Default native instance name when none is supplied (mirrors C#).
Definition SzCoreEnvironment.hpp:32
static Builder NewBuilder()
Creates a new builder.
const std::string & GetSettings() const noexcept
SzEngine & GetEngine() override
Returns the env-owned SzEngine (lazily created).
void Destroy() override
Destroys the environment and all owned subsystems. Idempotent.
int64_t GetActiveConfigID() override
Returns the currently active configuration ID.
SzCoreEnvironment & operator=(const SzCoreEnvironment &)=delete
const std::string & GetInstanceName() const noexcept
std::optional< int64_t > GetConfigID() const noexcept
The explicit configuration ID this environment is pinned to, or std::nullopt to use the repository's ...
static SzCoreEnvironment * GetActiveInstance()
The single active environment instance for this process, or nullptr if none is active.
SzConfigManager & GetConfigManager() override
Returns the env-owned SzConfigManager (lazily created).
SzProduct & GetProduct() override
Returns the env-owned SzProduct (lazily created).
void Reinitialize(int64_t configID) override
Reinitializes the engine/diagnostic with the given configuration ID.
SzCoreEnvironment(const SzCoreEnvironment &)=delete
bool IsVerboseLogging() const noexcept
SzDiagnostic & GetDiagnostic() override
Returns the env-owned SzDiagnostic (lazily created).
void EnsureActive()
Locks the environment mutex and throws SzEnvironmentDestroyedException if this environment has been d...
Definition SzCoreConfig.hpp:20