Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,21 +122,21 @@ openfeature::OpenFeatureAPI& api = openfeature::OpenFeatureAPI::GetInstance();
// Set a global evaluation context
openfeature::EvaluationContext global_ctx = openfeature::EvaluationContext::Builder()
.WithAttribute("region", "us-east-1")
.build();
.Build();
api.SetEvaluationContext(global_ctx);

// Set a client-level evaluation context
std::shared_ptr<openfeature::Client> client = api.GetClient();
openfeature::EvaluationContext client_ctx = openfeature::EvaluationContext::Builder()
.WithAttribute("app_version", "1.0.5")
.build();
.Build();
client->SetEvaluationContext(client_ctx);

// Provide an invocation-level evaluation context
openfeature::EvaluationContext req_ctx = openfeature::EvaluationContext::Builder()
.WithTargetingKey("session-id-12345")
.WithAttribute("email", "user@example.com")
.build();
.Build();

bool flag_value = client->GetBooleanValue("some-flag", false, req_ctx);
```
Expand Down
44 changes: 44 additions & 0 deletions openfeature/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,28 @@ cc_library(
],
)

cc_library(
name = "hook_support",
srcs = ["hook_support.cpp"],
hdrs = ["hook_support.h"],
include_prefix = "openfeature",
deps = [
":error_code",
":evaluation_context",
":evaluation_options",
":flag_evaluation_details",
":flag_type_value",
":general_hook",
":global_hook_manager",
":hook_context",
":hook_data",
":hook_hints",
":metadata",
":provider",
":reason",
],
)

cc_library(
name = "client_api",
srcs = ["client_api.cpp"],
Expand All @@ -63,18 +85,26 @@ cc_library(
deps = [
":client",
":evaluation_context",
":evaluation_options",
":features",
":flag_evaluation_details",
":flag_metadata",
":flag_type_value",
":general_hook",
":global_context_manager",
":global_hook_manager",
":hook_context",
":hook_data",
":hook_hints",
":hook_support",
":metadata",
":provider",
":provider_repository",
":provider_status",
":reason",
":resolution_details",
":value",
"//openfeature/exceptions:open_feature_exceptions"
],
)

Expand All @@ -89,6 +119,9 @@ cc_library(
hdrs = ["evaluation_context.h"],
srcs = ["evaluation_context.cpp"],
include_prefix = "openfeature",
deps = [
":value",
],
)

cc_library(
Expand Down Expand Up @@ -164,6 +197,16 @@ cc_library(
],
)

cc_library(
name = "global_hook_manager",
srcs = ["global_hook_manager.cpp"],
hdrs = ["global_hook_manager.h"],
include_prefix = "openfeature",
deps = [
":general_hook",
],
)

cc_library(
name = "hook_context",
srcs = ["hook_context.cpp"],
Expand Down Expand Up @@ -227,6 +270,7 @@ cc_library(
":client_api",
":evaluation_context",
":global_context_manager",
":global_hook_manager",
":metadata",
":openfeature",
":provider",
Expand Down
13 changes: 7 additions & 6 deletions openfeature/client_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <utility>

#include "openfeature/flag_metadata.h"
#include "openfeature/flag_type_value.h"
#include "openfeature/global_context_manager.h"
#include "openfeature/reason.h"

Expand All @@ -11,7 +12,7 @@ namespace openfeature {
ClientAPI::ClientAPI(ProviderRepository& repository, std::string_view domain)
: provider_repository_(repository),
domain_(domain),
evaluation_context_(EvaluationContext::Builder().build()) {}
evaluation_context_(EvaluationContext::Builder().Build()) {}

Metadata ClientAPI::GetMetadata() { return Metadata{domain_}; }

Expand Down Expand Up @@ -306,7 +307,7 @@ std::unique_ptr<BoolResolutionDetails> ClientAPI::EvaluateBooleanFlag(
const std::optional<EvaluationContext>& ctx,
const std::optional<EvaluationOptions>& options) {
return this->EvaluateFlag<BoolResolutionDetails>(
default_value, ctx, options,
flag_key, FlagValueType::kBoolean, default_value, ctx, options,
[&](const std::shared_ptr<FeatureProvider>& provider,
const EvaluationContext& merged_ctx) {
return provider->GetBooleanEvaluation(flag_key, default_value,
Expand All @@ -320,7 +321,7 @@ std::unique_ptr<StringResolutionDetails> ClientAPI::EvaluateStringFlag(
const std::optional<EvaluationOptions>& options) {
std::string default_str(default_value);
return this->EvaluateFlag<StringResolutionDetails>(
default_str, ctx, options,
flag_key, FlagValueType::kString, default_str, ctx, options,
[&](const std::shared_ptr<FeatureProvider>& provider,
const EvaluationContext& merged_ctx) {
return provider->GetStringEvaluation(flag_key, default_value,
Expand All @@ -333,7 +334,7 @@ std::unique_ptr<IntResolutionDetails> ClientAPI::EvaluateIntegerFlag(
const std::optional<EvaluationContext>& ctx,
const std::optional<EvaluationOptions>& options) {
return this->EvaluateFlag<IntResolutionDetails>(
default_value, ctx, options,
flag_key, FlagValueType::kInteger, default_value, ctx, options,
[&](const std::shared_ptr<FeatureProvider>& provider,
const EvaluationContext& merged_ctx) {
return provider->GetIntegerEvaluation(flag_key, default_value,
Expand All @@ -346,7 +347,7 @@ std::unique_ptr<DoubleResolutionDetails> ClientAPI::EvaluateDoubleFlag(
const std::optional<EvaluationContext>& ctx,
const std::optional<EvaluationOptions>& options) {
return this->EvaluateFlag<DoubleResolutionDetails>(
default_value, ctx, options,
flag_key, FlagValueType::kDouble, default_value, ctx, options,
[&](const std::shared_ptr<FeatureProvider>& provider,
const EvaluationContext& merged_ctx) {
return provider->GetDoubleEvaluation(flag_key, default_value,
Expand All @@ -359,7 +360,7 @@ std::unique_ptr<ObjectResolutionDetails> ClientAPI::EvaluateObjectFlag(
const std::optional<EvaluationContext>& ctx,
const std::optional<EvaluationOptions>& options) {
return this->EvaluateFlag<ObjectResolutionDetails>(
default_value, ctx, options,
flag_key, FlagValueType::kObject, default_value, ctx, options,
[&](const std::shared_ptr<FeatureProvider>& provider,
const EvaluationContext& merged_ctx) {
return provider->GetObjectEvaluation(flag_key, default_value,
Expand Down
Loading