const char* kTizenFeaturePlatformVersionName = "http://tizen.org/feature/platform.version.name";
} // namespace
-PlatformResult SystemInfoDeviceCapability::GetValueBool(const char* key, bool* value) {
+CapabilitiesMap<bool> SystemInfoDeviceCapability::bool_capabilities =
+ SystemInfoDeviceCapability::InitializeBoolCapabilities();
+CapabilitiesMap<int> SystemInfoDeviceCapability::int_capabilities =
+ SystemInfoDeviceCapability::InitializeIntCapabilities();
+CapabilitiesMap<std::string> SystemInfoDeviceCapability::string_capabilities =
+ SystemInfoDeviceCapability::InitializeStringCapabilities();
+
+CapabilitiesMap<bool> SystemInfoDeviceCapability::InitializeBoolCapabilities() {
+ ScopeLogger();
+ CapabilitiesMap<bool> result;
+
+ result[kTizenFeatureBluetoothAlwaysOn] = SystemInfoDeviceCapability::IsBluetoothAlwaysOn;
+ result[kTizenFeatureScreen] = SystemInfoDeviceCapability::IsScreen;
+ result[kTizenFeaturePlatformNativeOspCompatible] =
+ SystemInfoDeviceCapability::IsNativeOspCompatible;
+
+ return result;
+};
+
+CapabilitiesMap<int> SystemInfoDeviceCapability::InitializeIntCapabilities() {
+ ScopeLogger();
+ CapabilitiesMap<int> result;
+ result[kTizenFeatureCpuFrequency] = SystemInfoDeviceCapability::GetPlatformCoreCpuFrequency;
+
+ return result;
+};
+
+CapabilitiesMap<std::string> SystemInfoDeviceCapability::InitializeStringCapabilities() {
+ ScopeLogger();
+ CapabilitiesMap<std::string> result;
+ result[kTizenFeatureOpenglesTextureFormat] = SystemInfoDeviceCapability::GetOpenglesTextureFormat;
+ result[kTizenFeatureCoreApiVersion] = SystemInfoDeviceCapability::GetNativeAPIVersion;
+ result[kTizenFeaturePlatfromCoreCpuArch] = SystemInfoDeviceCapability::GetPlatfomCoreCpuArch;
+ result[kTizenFeaturePlatfromCoreFpuArch] = SystemInfoDeviceCapability::GetPlatfomCoreFpuArch;
+ result[kTizenFeatureProfile] = SystemInfoDeviceCapability::GetProfile;
+ result[kTizenFeaturePlatformNativeApiVersion] = SystemInfoDeviceCapability::GetNativeAPIVersion;
+ result[kTizenFeaturePlatformVersionName] = SystemInfoDeviceCapability::GetPlatformVersionName;
+
+ return result;
+};
+
+common::PlatformResult SystemInfoDeviceCapability::CheckCapabilityType(
+ const std::string& key, system_info_type_e* capability_type) {
+ ScopeLogger();
+ // checking 'hardcoded' map first
+ if (bool_capabilities.find(key) != bool_capabilities.end()) {
+ *capability_type = SYSTEM_INFO_BOOL;
+ } else if (int_capabilities.find(key) != int_capabilities.end()) {
+ *capability_type = SYSTEM_INFO_INT;
+ } else if (string_capabilities.find(key) != string_capabilities.end()) {
+ *capability_type = SYSTEM_INFO_STRING;
+ } else {
+ // checking platform capabilities database
+ int res = system_info_get_platform_type(key.c_str(), capability_type);
+ if (SYSTEM_INFO_ERROR_NONE != res) {
+ res = system_info_get_custom_type(key.c_str(), capability_type);
+ if (SYSTEM_INFO_ERROR_NONE != res) {
+ return LogAndCreateResult(ErrorCode::NOT_SUPPORTED_ERR,
+ "Value for given key was not found");
+ }
+ }
+ }
+ return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult GetValueBoolNative(const char* key, bool* value) {
ScopeLogger();
bool platform_result = false;
int ret = system_info_get_platform_bool(key, &platform_result);
return PlatformResult(ErrorCode::NO_ERROR);
}
-PlatformResult SystemInfoDeviceCapability::GetValueInt(const char* key, int* value) {
+PlatformResult SystemInfoDeviceCapability::GetValueBool(const char* key, bool* value) {
+ ScopeLogger();
+ // check 'hardcoded' keys
+ auto it = bool_capabilities.find(key);
+ if (bool_capabilities.end() != it) {
+ return it->second(value);
+ }
+
+ // check 'database' keys
+ return GetValueBoolNative(key, value);
+}
+
+PlatformResult GetValueIntNative(const char* key, int* value) {
ScopeLogger();
int platform_result = 0;
int ret = system_info_get_platform_int(key, &platform_result);
return PlatformResult(ErrorCode::NO_ERROR);
}
-PlatformResult SystemInfoDeviceCapability::GetValueString(const char* key, std::string* str_value) {
+PlatformResult SystemInfoDeviceCapability::GetValueInt(const char* key, int* value) {
+ ScopeLogger();
+ // check 'hardcoded' keys
+ auto it = int_capabilities.find(key);
+ if (int_capabilities.end() != it) {
+ return it->second(value);
+ }
+
+ // check 'database' keys
+ return GetValueIntNative(key, value);
+}
+
+PlatformResult GetValueStringNative(const char* key, std::string* str_value) {
ScopeLogger();
char* value = nullptr;
return PlatformResult(ErrorCode::NO_ERROR);
}
-static PlatformResult CheckStringCapability(const std::string& key, std::string* value,
- bool* fetched) {
- ScopeLogger();
- *fetched = false;
- if (kTizenFeatureOpenglesTextureFormat == key) {
- PlatformResult ret = SystemInfoDeviceCapability::GetOpenglesTextureFormat(value);
- if (ret.IsError()) {
- return ret;
- }
- } else if (kTizenFeatureCoreApiVersion == key) {
- PlatformResult ret = SystemInfoDeviceCapability::GetNativeAPIVersion(value);
- if (ret.IsError()) {
- return ret;
- }
- } else if (key == kTizenFeaturePlatfromCoreCpuArch) {
- PlatformResult ret = SystemInfoDeviceCapability::GetPlatfomCoreCpuArch(value);
- if (ret.IsError()) {
- return ret;
- }
- } else if (kTizenFeaturePlatfromCoreFpuArch == key) {
- PlatformResult ret = SystemInfoDeviceCapability::GetPlatfomCoreFpuArch(value);
- if (ret.IsError()) {
- return ret;
- }
- } else if (kTizenFeatureProfile == key) {
- PlatformResult ret = SystemInfoDeviceCapability::GetProfile(value);
- if (ret.IsError()) {
- return ret;
- }
- } else if (kTizenFeaturePlatformNativeApiVersion == key) {
- PlatformResult ret = SystemInfoDeviceCapability::GetNativeAPIVersion(value);
- if (ret.IsError()) {
- return ret;
- }
- } else if (kTizenFeaturePlatformVersionName == key) {
- PlatformResult ret = SystemInfoDeviceCapability::GetPlatformVersionName(value);
- if (ret.IsError()) {
- return ret;
- }
- } else {
- size_t prefix_len = strlen("http://");
- if (key.length() <= prefix_len) {
- return LogAndCreateResult(ErrorCode::NOT_SUPPORTED_ERR, "Value for given key was not found");
- }
- PlatformResult ret =
- SystemInfoDeviceCapability::GetValueString(key.substr(prefix_len).c_str(), value);
- if (ret.IsError()) {
- return PlatformResult(ErrorCode::NO_ERROR);
- }
- }
- *fetched = true;
- return PlatformResult(ErrorCode::NO_ERROR);
-}
-
-static PlatformResult CheckBoolCapability(const std::string& key, bool* bool_value, bool* fetched) {
+PlatformResult SystemInfoDeviceCapability::GetValueString(const char* key, std::string* str_value) {
ScopeLogger();
- *fetched = false;
- if (kTizenFeatureBluetoothAlwaysOn == key) {
- *bool_value = SystemInfoDeviceCapability::IsBluetoothAlwaysOn();
- *fetched = true;
- } else if (kTizenFeatureScreen == key) {
- *bool_value = SystemInfoDeviceCapability::IsScreen();
- *fetched = true;
- } else if (kTizenFeaturePlatformNativeOspCompatible == key) {
- PlatformResult ret = SystemInfoDeviceCapability::IsNativeOspCompatible(bool_value);
- if (ret.IsError()) {
- return ret;
- }
- *fetched = true;
- } else {
- size_t prefix_len = strlen("http://");
- if (key.length() <= prefix_len) {
- return LogAndCreateResult(ErrorCode::NOT_SUPPORTED_ERR, "Value for given key was not found");
- }
- PlatformResult ret =
- SystemInfoDeviceCapability::GetValueBool(key.substr(prefix_len).c_str(), bool_value);
- if (ret.IsSuccess()) {
- *fetched = true;
- }
+ // check 'hardcoded' keys
+ auto it = string_capabilities.find(key);
+ if (string_capabilities.end() != it) {
+ return it->second(str_value);
}
- return PlatformResult(ErrorCode::NO_ERROR);
-}
-static PlatformResult CheckIntCapability(const std::string& key, std::string* value,
- bool* fetched) {
- ScopeLogger();
- int result = 0;
- if (key == kTizenFeatureCpuFrequency) {
- PlatformResult ret = SystemInfoDeviceCapability::GetPlatformCoreCpuFrequency(&result);
- if (ret.IsError()) {
- *fetched = false;
- return ret;
- }
- } else {
- size_t prefix_len = strlen("http://");
- if (key.length() <= prefix_len) {
- return LogAndCreateResult(ErrorCode::NOT_SUPPORTED_ERR, "Value for given key was not found");
- }
- PlatformResult ret =
- SystemInfoDeviceCapability::GetValueInt(key.substr(prefix_len).c_str(), &result);
- if (ret.IsError()) {
- *fetched = false;
- return PlatformResult(ErrorCode::NO_ERROR);
- }
- }
- *value = std::to_string(result);
- *fetched = true;
- return PlatformResult(ErrorCode::NO_ERROR);
+ // check 'database' keys
+ return GetValueStringNative(key, str_value);
}
PlatformResult SystemInfoDeviceCapability::GetCapability(const std::string& key,
ScopeLogger();
picojson::object& result_obj = result->get<picojson::object>();
- std::string value = "";
std::string type = "";
bool bool_value = false;
- bool is_fetched = false;
+ int int_value = 0;
+ std::string string_value = "";
+
+ system_info_type_e capability_type = SYSTEM_INFO_BOOL;
- PlatformResult ret = CheckBoolCapability(key, &bool_value, &is_fetched);
+ PlatformResult ret = CheckCapabilityType(key, &capability_type);
if (ret.IsError()) {
return ret;
}
- if (is_fetched) {
+ LoggerD("Capability %s is %d type", key.c_str(), capability_type);
+
+ if (SYSTEM_INFO_BOOL == capability_type) {
type = "bool";
- } else {
- ret = CheckIntCapability(key, &value, &is_fetched);
+ PlatformResult ret = GetValueBool(key.c_str(), &bool_value);
if (ret.IsError()) {
return ret;
}
- if (is_fetched) {
- type = "int";
- } else {
- ret = CheckStringCapability(key, &value, &is_fetched);
- if (ret.IsError()) {
- return ret;
- }
- if (is_fetched) {
- type = "string";
- }
+ } else if (SYSTEM_INFO_INT == capability_type) {
+ type = "int";
+ PlatformResult ret = GetValueInt(key.c_str(), &int_value);
+ if (ret.IsError()) {
+ return ret;
+ }
+ } else if (SYSTEM_INFO_STRING == capability_type) {
+ type = "string";
+ PlatformResult ret = GetValueString(key.c_str(), &string_value);
+ if (ret.IsError()) {
+ return ret;
}
}
if (type == "bool") {
result_obj.insert(std::make_pair("value", picojson::value(bool_value)));
- } else if (type == "string" || type == "int") {
- result_obj.insert(std::make_pair("value", picojson::value(value)));
+ } else if (type == "int") {
+ result_obj.insert(std::make_pair("value", picojson::value(std::to_string(int_value))));
+ } else if (type == "string") {
+ result_obj.insert(std::make_pair("value", picojson::value(string_value)));
} else {
return LogAndCreateResult(ErrorCode::NOT_SUPPORTED_ERR, "Value for given key was not found");
}
ScopeLogger();
std::string input_keyboard_layout = "";
PlatformResult ret =
- GetValueString("tizen.org/feature/input.keyboard.layout", &input_keyboard_layout);
+ GetValueStringNative("tizen.org/feature/input.keyboard.layout", &input_keyboard_layout);
if (ret.IsError()) {
return ret;
}
bool input_keyboard = false;
- ret = GetValueBool("tizen.org/feature/input.keyboard", &input_keyboard);
+ ret = GetValueBoolNative("tizen.org/feature/input.keyboard", &input_keyboard);
if (ret.IsError()) {
return ret;
}
PlatformResult SystemInfoDeviceCapability::GetOpenglesTextureFormat(std::string* result) {
ScopeLogger();
bool bool_result = false;
- PlatformResult ret = GetValueBool("tizen.org/feature/opengles", &bool_result);
+ PlatformResult ret = GetValueBoolNative("tizen.org/feature/opengles", &bool_result);
if (!bool_result) {
// this exception is converted to "Undefined" value in JS layer
std::string log_msg = "OpenGL-ES is not supported";
}
std::string texture_format = "";
- ret = GetValueBool("tizen.org/feature/opengles.texture_format.utc", &bool_result);
+ ret = GetValueBoolNative("tizen.org/feature/opengles.texture_format.utc", &bool_result);
if (ret.IsError()) {
return ret;
}
texture_format += kOpenglesTextureUtc;
}
- ret = GetValueBool("tizen.org/feature/opengles.texture_format.ptc", &bool_result);
+ ret = GetValueBoolNative("tizen.org/feature/opengles.texture_format.ptc", &bool_result);
if (ret.IsError()) {
return ret;
}
texture_format += kOpenglesTexturePtc;
}
- ret = GetValueBool("tizen.org/feature/opengles.texture_format.etc", &bool_result);
+ ret = GetValueBoolNative("tizen.org/feature/opengles.texture_format.etc", &bool_result);
if (ret.IsError()) {
return ret;
}
texture_format += kOpenglesTextureEtc;
}
- ret = GetValueBool("tizen.org/feature/opengles.texture_format.3dc", &bool_result);
+ ret = GetValueBoolNative("tizen.org/feature/opengles.texture_format.3dc", &bool_result);
if (ret.IsError()) {
return ret;
}
texture_format += kOpenglesTexture3dc;
}
- ret = GetValueBool("tizen.org/feature/opengles.texture_format.atc", &bool_result);
+ ret = GetValueBoolNative("tizen.org/feature/opengles.texture_format.atc", &bool_result);
if (ret.IsError()) {
return ret;
}
texture_format += kOpenglesTextureAtc;
}
- ret = GetValueBool("tizen.org/feature/opengles.texture_format.pvrtc", &bool_result);
+ ret = GetValueBoolNative("tizen.org/feature/opengles.texture_format.pvrtc", &bool_result);
if (ret.IsError()) {
return ret;
}
bool bool_result = false;
std::string arch = "";
- PlatformResult ret =
- SystemInfoDeviceCapability::GetValueString("tizen.org/feature/platform.core.cpu.arch", &arch);
+ PlatformResult ret = GetValueStringNative("tizen.org/feature/platform.core.cpu.arch", &arch);
if (ret.IsError()) {
- LoggerE("GetValueString Error");
+ LoggerE("GetValueStringNative Error");
}
- ret = GetValueBool("tizen.org/feature/platform.core.cpu.arch.armv6", &bool_result);
+ ret = GetValueBoolNative("tizen.org/feature/platform.core.cpu.arch.armv6", &bool_result);
if (ret.IsError()) {
return ret;
}
result = kPlatformCoreArmv6;
}
- ret = GetValueBool("tizen.org/feature/platform.core.cpu.arch.armv7", &bool_result);
+ ret = GetValueBoolNative("tizen.org/feature/platform.core.cpu.arch.armv7", &bool_result);
if (ret.IsError()) {
return ret;
}
}
}
- ret = GetValueBool("tizen.org/feature/platform.core.cpu.arch.x86", &bool_result);
+ ret = GetValueBoolNative("tizen.org/feature/platform.core.cpu.arch.x86", &bool_result);
if (ret.IsError()) {
return ret;
}
ScopeLogger();
std::string result;
bool bool_result = false;
- PlatformResult ret = GetValueBool("tizen.org/feature/platform.core.fpu.arch.sse2", &bool_result);
+ PlatformResult ret =
+ GetValueBoolNative("tizen.org/feature/platform.core.fpu.arch.sse2", &bool_result);
if (ret.IsError()) {
return ret;
}
result = kPlatformCoreSse2;
}
- ret = GetValueBool("tizen.org/feature/platform.core.fpu.arch.sse3", &bool_result);
+ ret = GetValueBoolNative("tizen.org/feature/platform.core.fpu.arch.sse3", &bool_result);
if (ret.IsError()) {
return ret;
}
result += kPlatformCoreSse3;
}
- ret = GetValueBool("tizen.org/feature/platform.core.fpu.arch.ssse3", &bool_result);
+ ret = GetValueBoolNative("tizen.org/feature/platform.core.fpu.arch.ssse3", &bool_result);
if (ret.IsError()) {
return ret;
}
result += kPlatformCoreSsse3;
}
- ret = GetValueBool("tizen.org/feature/platform.core.fpu.arch.vfpv2", &bool_result);
+ ret = GetValueBoolNative("tizen.org/feature/platform.core.fpu.arch.vfpv2", &bool_result);
if (ret.IsError()) {
return ret;
}
result += kPlatformCoreVfpv2;
}
- ret = GetValueBool("tizen.org/feature/platform.core.fpu.arch.vfpv3", &bool_result);
+ ret = GetValueBoolNative("tizen.org/feature/platform.core.fpu.arch.vfpv3", &bool_result);
if (ret.IsError()) {
return ret;
}
result += kPlatformCoreVfpv3;
}
- ret = GetValueBool("tizen.org/feature/platform.core.fpu.arch.vfpv4", &bool_result);
+ ret = GetValueBoolNative("tizen.org/feature/platform.core.fpu.arch.vfpv4", &bool_result);
if (ret.IsError()) {
return ret;
}
PlatformResult SystemInfoDeviceCapability::GetProfile(std::string* return_value) {
ScopeLogger();
std::string profile = "";
- PlatformResult ret = GetValueString("tizen.org/feature/profile", &profile);
+ PlatformResult ret = GetValueStringNative("tizen.org/feature/profile", &profile);
if (ret.IsError()) {
return ret;
}
return PlatformResult(ErrorCode::NO_ERROR);
}
-bool SystemInfoDeviceCapability::IsBluetoothAlwaysOn() {
+PlatformResult SystemInfoDeviceCapability::IsBluetoothAlwaysOn(bool* return_value) {
ScopeLogger();
#ifdef PROFILE_MOBILE_FULL
- return false;
+ *return_value = false;
#elif PROFILE_MOBILE
- return false;
+ *return_value = false;
#elif PROFILE_WEARABLE
- return false;
+ *return_value = false;
#elif PROFILE_TV
- return true;
+ *return_value = true;
#else
- return false;
+ *return_value = false;
#endif
+ return PlatformResult(ErrorCode::NO_ERROR);
}
-bool SystemInfoDeviceCapability::IsScreen() {
- return true;
+PlatformResult SystemInfoDeviceCapability::IsScreen(bool* return_value) {
+ *return_value = true;
+ return PlatformResult(ErrorCode::NO_ERROR);
}
#define MODEL_NAME "http://tizen.org/system/model_name"
PlatformResult SystemInfoDeviceCapability::IsNativeOspCompatible(bool* result) {
ScopeLogger();
- return GetValueBool(kTizenFeaturePlatformNativeOspCompatible, result);
+ return GetValueBoolNative(kTizenFeaturePlatformNativeOspCompatible, result);
}
PlatformResult SystemInfoDeviceCapability::GetNativeAPIVersion(std::string* return_value) {
ScopeLogger();
- return GetValueString(kTizenFeaturePlatformNativeApiVersion, return_value);
+ return GetValueStringNative(kTizenFeaturePlatformNativeApiVersion, return_value);
}
PlatformResult SystemInfoDeviceCapability::GetPlatformVersionName(std::string* result) {
// Because of lack of 'http://tizen.org/feature/platform.version.name'
// key on platform we use 'http://tizen.org/system/platform.name'.
- return GetValueString("tizen.org/system/platform.name", result);
+ return GetValueStringNative("tizen.org/system/platform.name", result);
}
} // namespace systeminfo