Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
42a776d
base data structures fot hook implementation.
NeaguGeorgiana23 Jul 7, 2026
e968609
fix linter
NeaguGeorgiana23 Jul 7, 2026
334ec2a
fix linter
NeaguGeorgiana23 Jul 7, 2026
f110e5c
Merge branch 'main' into define-hook-data-structures
NeaguGeorgiana23 Jul 7, 2026
5cc878b
Update BUILD file.
NeaguGeorgiana23 Jul 10, 2026
bd66430
Correct include guards.
NeaguGeorgiana23 Jul 10, 2026
5332610
feat: Add HookData class.
NeaguGeorgiana23 Jul 10, 2026
c8fc92d
fix linter
NeaguGeorgiana23 Jul 10, 2026
3f5f4de
fix linter
NeaguGeorgiana23 Jul 10, 2026
b0f3a15
fix linter
NeaguGeorgiana23 Jul 10, 2026
e9e8852
fix linter
NeaguGeorgiana23 Jul 10, 2026
e333df0
add HookContext structure.
NeaguGeorgiana23 Jul 13, 2026
c59de28
fix linter
NeaguGeorgiana23 Jul 13, 2026
45ca64a
fix linter
NeaguGeorgiana23 Jul 13, 2026
3b93d77
add Hooks class.
NeaguGeorgiana23 Jul 14, 2026
a4aa1c2
fix linter.
NeaguGeorgiana23 Jul 14, 2026
d7cd54a
fix linter.
NeaguGeorgiana23 Jul 14, 2026
d6ef2c6
fix linter.
NeaguGeorgiana23 Jul 14, 2026
a2f7fee
fix linter.
NeaguGeorgiana23 Jul 14, 2026
a91afca
appli agent suggestions.
NeaguGeorgiana23 Jul 14, 2026
c0482f7
Merge branch 'main' into hooks
NeaguGeorgiana23 Jul 14, 2026
a0ca155
Merge branch 'main' into hooks
NeaguGeorgiana23 Jul 14, 2026
06bd51c
Add EvaluationOpton struct.
NeaguGeorgiana23 Jul 15, 2026
b362223
fix linter.
NeaguGeorgiana23 Jul 15, 2026
6942c4e
update Provider class to allow getting hooks.
NeaguGeorgiana23 Jul 15, 2026
49bdc17
update all classes that inharit from FeatureProvider.
NeaguGeorgiana23 Jul 15, 2026
dab62a0
update BUILD files and imports.
NeaguGeorgiana23 Jul 15, 2026
ea6a463
update GlobalAPI with hook methods.
NeaguGeorgiana23 Jul 15, 2026
665914a
fix linter.
NeaguGeorgiana23 Jul 16, 2026
0bd0f58
fix linter.
NeaguGeorgiana23 Jul 16, 2026
153fc57
Merge branch 'main' of https://github.com/open-feature/cpp-sdk into u…
NeaguGeorgiana23 Aug 10, 2026
543edd0
Fix linter.
NeaguGeorgiana23 Aug 10, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions openfeature/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ cc_library(
hdrs = ["openfeature_api.h"],
include_prefix = "openfeature",
deps = [
":general_hook",
":client",
":client_api",
":evaluation_context",
Expand Down Expand Up @@ -249,6 +250,7 @@ cc_library(
hdrs = ["openfeature.h"],
include_prefix = "openfeature",
deps = [
":general_hook",
":client",
":evaluation_context",
":metadata",
Expand Down
2 changes: 1 addition & 1 deletion openfeature/flag_evaluation_details.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ using ObjectFlagEvaluationDetails = FlagEvaluationDetails<Value>;

} // namespace openfeature

#endif // CPP_SDK_INCLUDE_OPENFEATURE_FLAG_EVALUATION_DETAILS_H_
#endif // CPP_SDK_INCLUDE_OPENFEATURE_FLAG_EVALUATION_DETAILS_H_
2 changes: 1 addition & 1 deletion openfeature/hook.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,4 @@ using DoubleHook = Hook<double>;
using ObjectHook = Hook<Value>;
} // namespace openfeature

#endif // CPP_SDK_INCLUDE_OPENFEATURE_HOOK_H_
#endif // CPP_SDK_INCLUDE_OPENFEATURE_HOOK_H_
26 changes: 19 additions & 7 deletions openfeature/openfeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
#include <memory>
#include <shared_mutex>
#include <string_view>
#include <vector>

#include "openfeature/client.h"
#include "openfeature/evaluation_context.h"
#include "openfeature/general_hook.h"
#include "openfeature/metadata.h"
#include "openfeature/provider.h"

Expand Down Expand Up @@ -35,8 +37,9 @@ class OpenFeature {
// If the domain is empty then GetProvider returns the default provider
// otherwise it returns the provider for the domain. If this domain has no
// provider bound, it returns the default provider.
virtual std::shared_ptr<FeatureProvider> GetProvider() const = 0;
virtual std::shared_ptr<FeatureProvider> GetProvider(
std::string_view domain = "") const = 0;
std::string_view domain) const = 0;

virtual std::shared_ptr<Client> GetClient() = 0;

Expand All @@ -48,18 +51,27 @@ class OpenFeature {
// Gets the global evaluation context.
virtual EvaluationContext GetEvaluationContext() const = 0;

// Gets the metadata for a provider bound to a specific domain.
virtual Metadata GetProviderMetadata(std::string_view domain = "") const = 0;
// Gets the metadata for the default provider or a provider bound to a
// specific domain.
virtual Metadata GetProviderMetadata() const = 0;
virtual Metadata GetProviderMetadata(std::string_view domain) const = 0;

// Fetches the status of a provider for a domain. If the domain is not set or
// not found, it returns the default provider status.
virtual ProviderStatus GetProviderStatus(
std::string_view domain = "") const = 0;
virtual ProviderStatus GetProviderStatus() const = 0;
virtual ProviderStatus GetProviderStatus(std::string_view domain) const = 0;

// Adds one or more global hooks. Previously added hooks are not removed.
virtual void AddHooks(std::vector<std::shared_ptr<GeneralHook>> hooks) = 0;

// Adds a single hook to the global hook repository.
virtual void AddHook(std::shared_ptr<GeneralHook> hook) = 0;

// Retrieves all configured global hooks.
virtual std::vector<std::shared_ptr<GeneralHook>> GetHooks() const = 0;

// Shuts down all providers and resets the API to its initial state.
virtual void Shutdown() = 0;

// TODO: Add methods to add and get Hooks.
};

} // namespace openfeature
Expand Down
47 changes: 40 additions & 7 deletions openfeature/openfeature_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@

namespace openfeature {

OpenFeatureAPI::OpenFeatureAPI() {
// provider_repository_ is automatically constructed.
// It guarantees a NoopProvider is set by default.
// TODO: init hooks & events.
}
OpenFeatureAPI::OpenFeatureAPI() = default;

OpenFeatureAPI& OpenFeatureAPI::GetInstance() {
static OpenFeatureAPI instance;
Expand Down Expand Up @@ -43,6 +39,10 @@ void OpenFeatureAPI::SetProviderAndWait(
GlobalContextManager::GetInstance().GetGlobalEvaluationContext(), true);
}

std::shared_ptr<FeatureProvider> OpenFeatureAPI::GetProvider() const {
return GetProvider("");
}

std::shared_ptr<FeatureProvider> OpenFeatureAPI::GetProvider(
std::string_view domain) const {
return provider_repository_.GetProvider(domain);
Expand All @@ -63,20 +63,53 @@ EvaluationContext OpenFeatureAPI::GetEvaluationContext() const {
return GlobalContextManager::GetInstance().GetGlobalEvaluationContext();
}

Metadata OpenFeatureAPI::GetProviderMetadata() const {
return GetProviderMetadata("");
}

Metadata OpenFeatureAPI::GetProviderMetadata(std::string_view domain) const {
std::shared_ptr<FeatureProvider> provider =
provider_repository_.GetProvider(domain);
if (provider) {
return provider->GetMetadata();
}
return Metadata(); // Return empty metadata if provider not found
return {}; // Return empty metadata if provider not found
}

ProviderStatus OpenFeatureAPI::GetProviderStatus() const {
return GetProviderStatus("");
}

ProviderStatus OpenFeatureAPI::GetProviderStatus(
std::string_view domain) const {
return provider_repository_.GetProviderStatus(domain);
}

void OpenFeatureAPI::Shutdown() { provider_repository_.Shutdown(); }
void OpenFeatureAPI::AddHooks(std::vector<std::shared_ptr<GeneralHook>> hooks) {
std::unique_lock lock(hooks_mutex_);
hooks_.reserve(hooks_.size() + hooks.size());
for (auto& hook : hooks) {
if (hook != nullptr) {
hooks_.push_back(std::move(hook));
}
}
}

void OpenFeatureAPI::AddHook(std::shared_ptr<GeneralHook> hook) {
if (hook == nullptr) return;
std::unique_lock lock(hooks_mutex_);
hooks_.push_back(std::move(hook));
}

std::vector<std::shared_ptr<GeneralHook>> OpenFeatureAPI::GetHooks() const {
std::shared_lock lock(hooks_mutex_);
return hooks_;
}

void OpenFeatureAPI::Shutdown() {
provider_repository_.Shutdown();
std::unique_lock lock(hooks_mutex_);
hooks_.clear();
}

} // namespace openfeature
28 changes: 20 additions & 8 deletions openfeature/openfeature_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
#include <memory>
#include <shared_mutex>
#include <string_view>
#pragma endregion

#include "openfeature/client.h"
#include "openfeature/evaluation_context.h"
#include "openfeature/general_hook.h"
#include "openfeature/global_context_manager.h"
#include "openfeature/metadata.h"
#include "openfeature/openfeature.h"
Expand All @@ -19,7 +21,7 @@ namespace openfeature {
// library.
class OpenFeatureAPI : public OpenFeature {
public:
~OpenFeatureAPI() = default;
~OpenFeatureAPI() override = default;

// Get the singleton instance of the OpenFeatureAPI.
static OpenFeatureAPI& GetInstance();
Expand All @@ -43,8 +45,9 @@ class OpenFeatureAPI : public OpenFeature {
// If the domain is empty then GetProvider returns the default provider
// otherwise it returns the provider for the domain. If this domain has no
// provider bound, it returns the default provider.
std::shared_ptr<FeatureProvider> GetProvider() const override;
std::shared_ptr<FeatureProvider> GetProvider(
std::string_view domain = "") const override;
std::string_view domain) const override;

// Gets a client for the default domain.
std::shared_ptr<Client> GetClient() override;
Expand All @@ -60,21 +63,30 @@ class OpenFeatureAPI : public OpenFeature {

// Get metadata about the default provider if domain is empty
// or about a named provider if domain is provided.
Metadata GetProviderMetadata(std::string_view domain = "") const override;
Metadata GetProviderMetadata() const override;
Metadata GetProviderMetadata(std::string_view domain) const override;

// Fetches the status of a provider for a domain. If the domain is not set or
// not found, it returns the default provider status.
ProviderStatus GetProviderStatus(std::string_view domain = "") const override;
ProviderStatus GetProviderStatus() const override;
ProviderStatus GetProviderStatus(std::string_view domain) const override;

// Adds one or more global hooks. Previously added hooks are not removed.
void AddHooks(std::vector<std::shared_ptr<GeneralHook>> hooks) override;

// Adds a single hook to the global hook repository.
void AddHook(std::shared_ptr<GeneralHook> hook) override;

// Retrieves all configured global hooks.
std::vector<std::shared_ptr<GeneralHook>> GetHooks() const override;

// Shuts down all providers and resets the API to its initial state.
void Shutdown() override;

// TODO: Add methods to add and get Hooks.
// TODO: Add overload function for "GetClient()" to accept "Evaluation
// Options"

private:
ProviderRepository provider_repository_;
mutable std::shared_mutex hooks_mutex_;
std::vector<std::shared_ptr<GeneralHook>> hooks_;

OpenFeatureAPI();
};
Expand Down
2 changes: 2 additions & 0 deletions test/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ cc_test(
srcs = ["openfeature_api_test.cpp"],
deps = [
":mock_feature_provider",
"//openfeature:general_hook",
"//openfeature:hook",
"//openfeature:openfeature_api",
"@googletest//:gtest_main",
],
Expand Down
2 changes: 1 addition & 1 deletion test/hook_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,4 +327,4 @@ TEST_F(HookTest, TypedHookIgnoresMismatchedFlagTypes) {
EXPECT_FALSE(bool_hook.after_called);
}

} // namespace openfeature
} // namespace openfeature
Loading