From: Rafal Galka Date: Thu, 21 May 2015 10:54:50 +0000 (+0200) Subject: [SystemInfo] Replace internal keys with appropriate API X-Git-Tag: submit/tizen_tv/20150603.064601^2~75 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=679cc3cb15236647411930a8e99374c008bece7f;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [SystemInfo] Replace internal keys with appropriate API Change-Id: If3295f8b8d2aa4baef6c12bb70ee8de1cb6ef07e --- diff --git a/src/systeminfo/systeminfo-utils.cpp b/src/systeminfo/systeminfo-utils.cpp index f767ce86..b176aec7 100644 --- a/src/systeminfo/systeminfo-utils.cpp +++ b/src/systeminfo/systeminfo-utils.cpp @@ -17,13 +17,13 @@ #include "systeminfo-utils.h" #include "systeminfo/systeminfo_instance.h" +#include #include #include #include #include #include -#include #include #include @@ -76,7 +76,7 @@ const std::string MEMORY_STATE_NORMAL = "NORMAL"; const std::string MEMORY_STATE_WARNING = "WARNING"; const int MEMORY_TO_BYTE = 1024; const int BASE_GATHERING_INTERVAL = 100; -const double DISPLAY_INCH_TO_MILLIMETER = 25.4; +const double DISPLAY_INCH_TO_MILLIMETER = 2.54; } using namespace common; @@ -1504,23 +1504,6 @@ static PlatformResult GetRuntimeInfoString(runtime_info_key_e key, std::string& return PlatformResult(ErrorCode::UNKNOWN_ERR, error_msg); } -static PlatformResult GetSystemValueString(system_info_key_e key, std::string& platform_string) { - char* platform_c_string; - if (SYSTEM_INFO_ERROR_NONE - == system_info_get_value_string(key, &platform_c_string)) { - if (platform_c_string) { - LoggerD("Build platfrom string %s", platform_c_string); - platform_string = platform_c_string; - free(platform_c_string); - return PlatformResult(ErrorCode::NO_ERROR); - } - } - - const char* error_msg = "Error when retrieving value from platform API"; - LoggerE("%s", error_msg); - return PlatformResult(ErrorCode::UNKNOWN_ERR, error_msg); -} - PlatformResult GetVconfInt(const char *key, int &value) { if (0 == vconf_get_int(key, &value)) { return PlatformResult(ErrorCode::NO_ERROR); @@ -1734,20 +1717,20 @@ PlatformResult SysteminfoUtils::ReportCpu(picojson::object& out) { PlatformResult SysteminfoUtils::ReportDisplay(picojson::object& out) { int screenWidth = 0; int screenHeight = 0; - unsigned long dotsPerInchWidth = 0; - unsigned long dotsPerInchHeight = 0; + int dotsPerInchWidth = 0; + int dotsPerInchHeight = 0; double physicalWidth = 0; double physicalHeight = 0; double scaledBrightness; // FETCH RESOLUTION - if (SYSTEM_INFO_ERROR_NONE != system_info_get_value_int( - SYSTEM_INFO_KEY_SCREEN_WIDTH, &screenWidth)) { + if (SYSTEM_INFO_ERROR_NONE != system_info_get_platform_int( + "tizen.org/feature/screen.width", &screenWidth)) { LoggerE("Cannot get value of screen width"); return PlatformResult(ErrorCode::UNKNOWN_ERR, "Cannot get value of screen width"); } - if (SYSTEM_INFO_ERROR_NONE != system_info_get_value_int( - SYSTEM_INFO_KEY_SCREEN_HEIGHT, &screenHeight)) { + if (SYSTEM_INFO_ERROR_NONE != system_info_get_platform_int( + "tizen.org/feature/screen.height", &screenHeight)) { LoggerE("Cannot get value of screen height"); return PlatformResult(ErrorCode::UNKNOWN_ERR, "Cannot get value of screen height"); } @@ -1766,7 +1749,7 @@ PlatformResult SysteminfoUtils::ReportDisplay(picojson::object& out) { //FETCH PHYSICAL WIDTH if (dotsPerInchWidth != 0 && screenWidth != 0) { - physicalWidth = DISPLAY_INCH_TO_MILLIMETER * screenWidth / dotsPerInchWidth; + physicalWidth = (screenWidth / dotsPerInchWidth) * DISPLAY_INCH_TO_MILLIMETER; } else { std::string log_msg = "Failed to get physical screen width value"; LoggerE("%s, screenWidth : %d, dotsPerInchWidth: %d", log_msg.c_str(), @@ -1775,7 +1758,7 @@ PlatformResult SysteminfoUtils::ReportDisplay(picojson::object& out) { //FETCH PHYSICAL HEIGHT if (dotsPerInchHeight != 0 && screenHeight != 0) { - physicalHeight = DISPLAY_INCH_TO_MILLIMETER * screenHeight / dotsPerInchHeight; + physicalHeight = (screenHeight / dotsPerInchHeight) * DISPLAY_INCH_TO_MILLIMETER; } else { std::string log_msg = "Failed to get physical screen height value"; LoggerE("%s, screenHeight : %d, dotsPerInchHeight: %d", log_msg.c_str(), @@ -1887,17 +1870,20 @@ PlatformResult SysteminfoUtils::ReportDeviceOrientation(picojson::object& out) { PlatformResult SysteminfoUtils::ReportBuild(picojson::object& out) { std::string model = ""; - PlatformResult ret = SystemInfoDeviceCapability::GetValueString("tizen.org/system/model_name", &model); + PlatformResult ret = SystemInfoDeviceCapability::GetValueString( + "tizen.org/system/model_name", &model); if (ret.IsError()) { return ret; } std::string manufacturer = ""; - ret = GetSystemValueString(SYSTEM_INFO_KEY_MANUFACTURER, manufacturer); + ret = SystemInfoDeviceCapability::GetValueString( + "tizen.org/system/manufacturer", &manufacturer); if (ret.IsError()) { return ret; } std::string buildVersion = ""; - ret = GetSystemValueString(SYSTEM_INFO_KEY_BUILD_STRING, buildVersion); + ret = SystemInfoDeviceCapability::GetValueString( + "tizen.org/system/build.string", &buildVersion); if (ret.IsError()) { return ret; } @@ -3033,17 +3019,20 @@ bool SystemInfoDeviceCapability::IsScreen() PlatformResult SystemInfoDeviceCapability::GetPlatformCoreCpuFrequency(int* return_value) { LoggerD("Entered"); - double freq = 0; - int ret = 0; - ret = system_info_get_value_double(SYSTEM_INFO_KEY_CORE_CPU_FREQ, &freq); - if (ret != SYSTEM_INFO_ERROR_NONE) { - LoggerE("Failed to get cpu frequency: %d", ret); - return PlatformResult(ErrorCode::UNKNOWN_ERR, "Failed to get cpu frequency"); - } else { - LoggerD("cpu frequency : %d", freq); - *return_value = static_cast(freq); + std::string freq; + std::ifstream cpuinfo_max_freq("/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq"); + if (!cpuinfo_max_freq.is_open()) { + LoggerE("Failed to get cpu frequency"); + return PlatformResult(ErrorCode::UNKNOWN_ERR, "Unable to open file"); } + + getline(cpuinfo_max_freq, freq); + cpuinfo_max_freq.close(); + + LoggerD("cpu frequency : %s", freq.c_str()); + *return_value = std::stoi(freq) / 1000; // unit: MHz + return PlatformResult(ErrorCode::NO_ERROR); }