11 #include <sys/system_properties.h>
19 struct ConvStringTo<float>
21 static float Func(std::string s) {
return std::stof(s); }
25 struct ConvStringTo<int>
27 static int Func(std::string s) {
return std::stoi(s); }
31 struct ConvStringTo<bool>
33 static bool Func(std::string s) {
return !!std::stoi(s); }
37 void GetCapabilitiesProperties([[maybe_unused]]
void* cookie,
38 [[maybe_unused]]
const char *name,
39 [[maybe_unused]]
const char *value,
40 [[maybe_unused]]uint32_t serial)
42 T &prop = *
reinterpret_cast<T*
>(cookie);
43 prop = ConvStringTo<T>::Func(std::string(value));
47 T ParseSystemProperty(
const char* name, T defaultValue)
51 const prop_info *pInfo = __system_property_find(name);
54 ALOGW(
"ArmnnDriver::ParseSystemProperty(): Could not find property [%s].", name);
58 __system_property_read_callback(pInfo, &GetCapabilitiesProperties<T>, &property);
59 std::stringstream messageBuilder;
60 messageBuilder <<
"ArmnnDriver::ParseSystemProperty(): Setting [" << name <<
"]=[" <<
property <<
"].";
61 ALOGD(
"%s", messageBuilder.str().c_str());
65 catch(
const std::invalid_argument& e)
67 ALOGD(
"ArmnnDriver::ParseSystemProperty(): Property [%s] has invalid data type.", name);
69 catch(
const std::out_of_range& e)
71 ALOGD(
"ArmnnDriver::ParseSystemProperty(): Property [%s] out of range for the data type.", name);
75 ALOGD(
"ArmnnDriver::ParseSystemProperty(): Unexpected exception reading system "
76 "property [%s].", name);
79 std::stringstream messageBuilder;
80 messageBuilder <<
"ArmnnDriver::ParseSystemProperty(): Falling back to default value [" << defaultValue <<
"]";
81 ALOGD(
"%s", messageBuilder.str().c_str());