diff options
author | Jason Macnak <natsu@google.com> | 2024-02-26 17:01:26 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2024-02-26 17:01:26 +0000 |
commit | c916a325de71eedd8ebfb6181a54ab248a281fa8 (patch) | |
tree | 43c27b302b2e976453c40598199e84fc7f23a7be | |
parent | 89246dfb3358794e55c9777650aa4ea065211435 (diff) | |
parent | eecdb3d3c118ff96c1e93f825887239aa4b631bb (diff) | |
download | aemu-c916a325de71eedd8ebfb6181a54ab248a281fa8.tar.gz |
Add a name->feature lookup method am: eecdb3d3c1
Original change: https://android-review.googlesource.com/c/platform/hardware/google/aemu/+/2971714
Change-Id: I377c87f29c7acbc0598aaf70246de548eb8cb78b
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r-- | host-common/feature_control.cpp | 23 | ||||
-rw-r--r-- | host-common/include/host-common/feature_control.h | 1 |
2 files changed, 24 insertions, 0 deletions
diff --git a/host-common/feature_control.cpp b/host-common/feature_control.cpp index 37b92d4..ce01c8b 100644 --- a/host-common/feature_control.cpp +++ b/host-common/feature_control.cpp @@ -97,3 +97,26 @@ const char* feature_name(Feature feature) { return it->second.c_str(); } + + +Feature feature_from_name(const char* name) { + if (name == nullptr) { + return kFeature_unknown; + } + + static const std::unordered_map<std::string, Feature>* const sNameToFeature = [] { + return new std::unordered_map<std::string, Feature>({ +#define FEATURE_CONTROL_ITEM(item, idx) { #item, kFeature_##item }, +#include "FeatureControlDefHost.h" +#include "FeatureControlDefGuest.h" +#undef FEATURE_CONTROL_ITEM + }); + }(); + + auto it = sNameToFeature->find(std::string(name)); + if (it == sNameToFeature->end()) { + return kFeature_unknown; + } + + return it->second; +}
\ No newline at end of file diff --git a/host-common/include/host-common/feature_control.h b/host-common/include/host-common/feature_control.h index 07746af..6e466d4 100644 --- a/host-common/include/host-common/feature_control.h +++ b/host-common/include/host-common/feature_control.h @@ -51,5 +51,6 @@ void feature_set_if_not_overridden_or_guest_disabled(Feature feature, bool enabl void feature_update_from_server(); const char* feature_name(Feature feature); +Feature feature_from_name(const char* name); ANDROID_END_HEADER |