[SystemInfo] Replace internal keys with appropriate API
authorRafal Galka <r.galka@samsung.com>
Thu, 21 May 2015 10:54:50 +0000 (12:54 +0200)
committerRafal Galka <r.galka@samsung.com>
Thu, 21 May 2015 10:54:50 +0000 (12:54 +0200)
Change-Id: If3295f8b8d2aa4baef6c12bb70ee8de1cb6ef07e

src/systeminfo/systeminfo-utils.cpp

index f767ce8684753915d690a704c8d40209dc1786c9..b176aec70ce8ef7ba455dd1c40a76a7bf431295c 100644 (file)
 #include "systeminfo-utils.h"
 #include "systeminfo/systeminfo_instance.h"
 
+#include <fstream>
 #include <sstream>
 #include <memory>
 #include <mutex>
 
 #include <runtime_info.h>
 #include <system_info.h>
-#include <system_info_internal.h>
 #include <sys/statfs.h>
 
 #include <vconf.h>
@@ -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<int>(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);
 }