// // Copyright © 2017 Arm Ltd. All rights reserved. // SPDX-License-Identifier: MIT // #pragma once #include #include #include #include #include namespace { template struct ConvStringTo; template<> struct ConvStringTo { static float Func(std::string s) { return std::stof(s); } }; template<> struct ConvStringTo { static int Func(std::string s) { return std::stoi(s); } }; template<> struct ConvStringTo { static bool Func(std::string s) { return !!std::stoi(s); } }; template void GetCapabilitiesProperties([[maybe_unused]]void* cookie, [[maybe_unused]]const char *name, [[maybe_unused]]const char *value, [[maybe_unused]]uint32_t serial) { T &prop = *reinterpret_cast(cookie); prop = ConvStringTo::Func(std::string(value)); } template T ParseSystemProperty(const char* name, T defaultValue) { try { const prop_info *pInfo = __system_property_find(name); if (!pInfo) { ALOGW("ArmnnDriver::ParseSystemProperty(): Could not find property [%s].", name); } else { T property; __system_property_read_callback(pInfo, &GetCapabilitiesProperties, &property); std::stringstream messageBuilder; messageBuilder << "ArmnnDriver::ParseSystemProperty(): Setting [" << name << "]=[" << property << "]."; ALOGD("%s", messageBuilder.str().c_str()); return property; } } catch(const std::invalid_argument& e) { ALOGD("ArmnnDriver::ParseSystemProperty(): Property [%s] has invalid data type.", name); } catch(const std::out_of_range& e) { ALOGD("ArmnnDriver::ParseSystemProperty(): Property [%s] out of range for the data type.", name); } catch (...) { ALOGD("ArmnnDriver::ParseSystemProperty(): Unexpected exception reading system " "property [%s].", name); } std::stringstream messageBuilder; messageBuilder << "ArmnnDriver::ParseSystemProperty(): Falling back to default value [" << defaultValue << "]"; ALOGD("%s", messageBuilder.str().c_str()); return defaultValue; } } //namespace