aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Macnak <natsu@google.com>2024-02-26 17:01:26 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2024-02-26 17:01:26 +0000
commitc916a325de71eedd8ebfb6181a54ab248a281fa8 (patch)
tree43c27b302b2e976453c40598199e84fc7f23a7be
parent89246dfb3358794e55c9777650aa4ea065211435 (diff)
parenteecdb3d3c118ff96c1e93f825887239aa4b631bb (diff)
downloadaemu-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.cpp23
-rw-r--r--host-common/include/host-common/feature_control.h1
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