[Systeminfo] Module reorganized
authorPiotr Kosko <p.kosko@samsung.com>
Wed, 26 Aug 2015 10:13:46 +0000 (12:13 +0200)
committerPiotr Kosko <p.kosko@samsung.com>
Tue, 8 Sep 2015 08:01:47 +0000 (10:01 +0200)
[Feature] Added class SysteminfoManger for future purposes.
  Implementation of SysteminfoDeviceCapability moved to own .cc and .h files.
  Implementation of getCapabilities and getCapability methods was moved to SysteminfoManager class.
  Small fix in implementation of check*Capability methods.

[Verification] TCT r37 pass rate 99.66%
Failed test is TC issue.

Change-Id: I9c34e0b1246519e8e179ba9d234accb46dfe2e49
Signed-off-by: Piotr Kosko <p.kosko@samsung.com>
src/systeminfo/systeminfo-utils.cpp
src/systeminfo/systeminfo-utils.h
src/systeminfo/systeminfo.gyp
src/systeminfo/systeminfo_device_capability.cc [new file with mode: 0644]
src/systeminfo/systeminfo_device_capability.h [new file with mode: 0644]
src/systeminfo/systeminfo_instance.cc
src/systeminfo/systeminfo_instance.h
src/systeminfo/systeminfo_manager.cc [new file with mode: 0644]
src/systeminfo/systeminfo_manager.h [new file with mode: 0644]

index abbfd78..7aef3f5 100644 (file)
@@ -88,33 +88,6 @@ static void SimMsisdnValueCallback(TapiHandle *handle, int result, void *data, v
 static void SimSpnValueCallback(TapiHandle *handle, int result, void *data, void *user_data);
 
 namespace {
-// device profile
-const char* kPlatformFull = "mobile-full";
-const char* kPlatformMobile = "mobile-web";
-const char* kPlatformWearable = "wearable";
-
-const char* kProfileFull = "MOBILE_FULL";
-const char* kProfileMobile = "MOBILE_WEB";
-const char* kProfileWearable = "WEARABLE";
-//opengles
-const char* kOpenglesTextureDelimiter = "/";
-const char* kOpenglesTextureUtc = "utc";
-const char* kOpenglesTexturePtc = "ptc";
-const char* kOpenglesTextureEtc = "etc";
-const char* kOpenglesTexture3dc = "3dc";
-const char* kOpenglesTextureAtc = "atc";
-const char* kOpenglesTexturePvrtc = "pvrtc";
-//core cpu arch
-const char* kPlatformCoreDelimiter = " | ";
-const char* kPlatformCoreArmv6 = "armv6";
-const char* kPlatformCoreArmv7 = "armv7";
-const char* kPlatformCoreX86 = "x86";
-//core fpu arch
-const char* kPlatformCoreSse2 = "sse2";
-const char* kPlatformCoreSse3 = "sse3";
-const char* kPlatformCoreSsse3 = "ssse3";
-const char* kPlatformCoreVfpv2 = "vfpv2";
-const char* kPlatformCoreVfpv3 = "vfpv3";
 const std::string kPropertyIdCpu = "CPU";
 //Battery
 const double kRemainingBatteryChargeMax = 100.0;
@@ -175,25 +148,6 @@ const char* kSimStatusSimLocked = "SIM_LOCKED";
 const char* kSimStatusNetworkLocked = "NETWORK_LOCKED";
 const char* kSimStatusUnknown = "UNKNOWN";
 
-///*for getCapability*/
-/*API feature*/
-/*Network feature*/
-const char* kTizenFeatureBluetoothAlwaysOn = "http://tizen.org/capability/network.bluetooth.always_on"; //TODO mobile/wearable: false, tv: true
-const char* kTizenFeatureOpenglesTextureFormat = "http://tizen.org/feature/opengles.texture_format";
-const char* kTizenFeatureCoreApiVersion = "http://tizen.org/feature/platform.core.api.version";
-const char* kTizenFeaturePlatfromCoreCpuArch = "http://tizen.org/feature/platform.core.cpu.arch";
-const char* kTizenFeaturePlatfromCoreFpuArch = "http://tizen.org/feature/platform.core.fpu.arch";
-/*profile feature*/
-const char* kTizenFeatureProfile = "http://tizen.org/feature/profile";
-/*Screen feature*/
-const char* kTizenFeatureScreen = "http://tizen.org/feature/screen";
-/*Sensor feature*/
-const char* kTizenFeatureCpuFrequency = "http://tizen.org/feature/platform.core.cpu.frequency";
-/*platform*/
-const char* kTizenFeaturePlatformNativeApiVersion = "tizen.org/feature/platform.native.api.version";
-const char* kTizenFeaturePlatformNativeOspCompatible = "tizen.org/feature/platform.native.osp_compatible";
-const char* kTizenFeaturePlatformVersionName = "http://tizen.org/feature/platform.version.name";
-
 static std::string parseWifiNetworkError(int error) {
   switch (error) {
     case WIFI_ERROR_NONE : return "WIFI_ERROR_NONE";
@@ -1635,66 +1589,6 @@ void OnWifiLevelChangedCb (wifi_rssi_level_e rssi_level, void *user_data)
 
 /////////////////////////// SysteminfoUtils ////////////////////////////////
 
-PlatformResult SystemInfoDeviceCapability::GetValueBool(const char *key, bool* value) {
-  bool platform_result = false;
-  int ret = system_info_get_platform_bool(key, &platform_result);
-  if (SYSTEM_INFO_ERROR_NONE != ret) {
-    ret = system_info_get_custom_bool(key, &platform_result);
-    if (SYSTEM_INFO_ERROR_NONE != ret) {
-      std::string log_msg = "Platform error while getting bool value: ";
-      log_msg += std::string(key) + " " + std::to_string(ret);
-      LoggerE("%s", log_msg.c_str());
-      return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg);
-    }
-  }
-
-  *value = platform_result;
-  LoggerD("value[%s]: %s", key, value ? "true" : "false");
-  return PlatformResult(ErrorCode::NO_ERROR);
-}
-
-PlatformResult SystemInfoDeviceCapability::GetValueInt(const char *key, int* value) {
-  int platform_result = 0;
-  int ret = system_info_get_platform_int(key, &platform_result);
-  if (SYSTEM_INFO_ERROR_NONE != ret) {
-    ret = system_info_get_custom_int(key, &platform_result);
-    if (SYSTEM_INFO_ERROR_NONE != ret) {
-      std::string log_msg = "Platform error while getting int value: ";
-      log_msg += std::string(key) + " " + std::to_string(ret);
-      LoggerE("%s", log_msg.c_str());
-      return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg);
-    }
-  }
-
-  *value = platform_result;
-  LoggerD("value[%s]: %d", key, value);
-  return PlatformResult(ErrorCode::NO_ERROR);
-}
-
-PlatformResult SystemInfoDeviceCapability::GetValueString(const char *key, std::string* str_value) {
-  char* value = nullptr;
-
-  int ret = system_info_get_platform_string(key, &value);
-  if (SYSTEM_INFO_ERROR_NONE != ret) {
-    ret = system_info_get_custom_string(key, &value);
-    if (SYSTEM_INFO_ERROR_NONE != ret) {
-      std::string log_msg = "Platform error while getting string value: ";
-      log_msg += std::string(key) + " " + std::to_string(ret);
-      LoggerE("%s", log_msg.c_str());
-      return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg);
-    }
-  }
-
-  if (value != nullptr) {
-    *str_value = value;
-    free(value);
-    value = nullptr;
-  }
-
-  LoggerD("value[%s]: %s", key, str_value->c_str());
-  return PlatformResult(ErrorCode::NO_ERROR);
-}
-
 static PlatformResult GetRuntimeInfoString(system_settings_key_e key, std::string& platform_string) {
   char* platform_c_string;
   int err = system_settings_get_value_string(key, &platform_c_string);
@@ -3013,475 +2907,5 @@ PlatformResult SysteminfoUtils::UnregisterCameraFlashListener()
   return system_info_listeners.UnregisterCameraFlashListener();
 }
 
-
-static PlatformResult CheckStringCapability(const std::string& key, std::string* value, bool* fetched)
-{
-  LoggerD("Entered CheckStringCapability");
-  *fetched = false;
-  if (kTizenFeatureOpenglesTextureFormat == key) {
-    PlatformResult ret = SystemInfoDeviceCapability::GetOpenglesTextureFormat(value);
-    if (ret.IsError()) {
-      return ret;
-    }
-  } else if (kTizenFeatureCoreApiVersion == key) {
-    *value = "2.3";
-  } 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 {
-    PlatformResult ret = SystemInfoDeviceCapability::GetValueString(key.substr(strlen("http://")).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)
-{
-  LoggerD("Entered CheckBoolCapability");
-  *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 {
-    PlatformResult ret = SystemInfoDeviceCapability::GetValueBool(
-        key.substr(strlen("http://")).c_str(), bool_value);
-    if (ret.IsSuccess()) {
-      *fetched = true;
-    }
-  }
-  return PlatformResult(ErrorCode::NO_ERROR);
-}
-
-static PlatformResult CheckIntCapability(const std::string& key, std::string* value,
-                                         bool* fetched)
-{
-  LoggerD("Entered CheckIntCapability");
-  int result = 0;
-  if (key == kTizenFeatureCpuFrequency) {
-    PlatformResult ret = SystemInfoDeviceCapability::GetPlatformCoreCpuFrequency(&result);
-    if (ret.IsError()) {
-      *fetched = false;
-      return ret;
-    }
-  } else {
-    PlatformResult ret = SystemInfoDeviceCapability::GetValueInt(
-        key.substr(strlen("http://")).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);
-}
-
-///////////////////////   SystemInfoDeviceCapability   //////////////////////////////////////
-PlatformResult SystemInfoDeviceCapability::GetCapability(const std::string& key,
-                                                          picojson::value& result)
-{
-  LoggerD("Entered");
-  picojson::object& result_obj = result.get<picojson::object>();
-
-  std::string value = "";
-  std::string type = "";
-  bool bool_value = false ;
-  bool is_fetched = false;
-
-  PlatformResult ret = CheckBoolCapability(key, &bool_value, &is_fetched);
-  if (ret.IsError()) {
-    return ret;
-  }
-  if (is_fetched) {
-    type = "bool";
-  } else {
-    ret = CheckIntCapability(key, &value, &is_fetched);
-    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";
-      }
-    }
-  }
-
-  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 {
-    LoggerD("Value for given key was not found");
-    return PlatformResult(ErrorCode::NOT_SUPPORTED_ERR, "Value for given key was not found");
-  }
-  result_obj.insert(std::make_pair("type", picojson::value(type)));
-
-  return PlatformResult(ErrorCode::NO_ERROR);
-}
-
-PlatformResult SystemInfoDeviceCapability::IsInputKeyboardLayout(bool* result) {
-  std::string input_keyboard_layout = "";
-  PlatformResult ret = GetValueString("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);
-  if (ret.IsError()) {
-    return ret;
-  }
-
-  // according to SystemInfo-DeviceCapabilities-dependency-table
-  // inputKeyboard   inputKeyboardLayout
-  //  O               O                   Possible
-  //  O               X                   Possible
-  //  X               X                   Possible
-  //  X               O                   Impossible
-
-  *result = input_keyboard ? !(input_keyboard_layout.empty()) : false;
-  return PlatformResult(ErrorCode::NO_ERROR);
-}
-
-PlatformResult SystemInfoDeviceCapability::GetOpenglesTextureFormat(std::string* result) {
-  bool bool_result = false;
-  PlatformResult ret = GetValueBool("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";
-    LoggerE("%s", log_msg.c_str());
-    return PlatformResult(ErrorCode::NOT_SUPPORTED_ERR, log_msg);
-  }
-  std::string texture_format = "";
-
-  ret = GetValueBool("tizen.org/feature/opengles.texture_format.utc", &bool_result);
-  if (ret.IsError()) {
-    return ret;
-  }
-  if (bool_result) {
-    texture_format += kOpenglesTextureUtc;
-  }
-
-  ret = GetValueBool("tizen.org/feature/opengles.texture_format.ptc", &bool_result);
-  if (ret.IsError()) {
-    return ret;
-  }
-  if (bool_result) {
-    if (!texture_format.empty()) {
-      texture_format += kOpenglesTextureDelimiter;
-    }
-    texture_format += kOpenglesTexturePtc;
-  }
-
-  ret = GetValueBool("tizen.org/feature/opengles.texture_format.etc", &bool_result);
-  if (ret.IsError()) {
-    return ret;
-  }
-  if (bool_result) {
-    if (!texture_format.empty()) {
-      texture_format += kOpenglesTextureDelimiter;
-    }
-    texture_format += kOpenglesTextureEtc;
-  }
-
-  ret = GetValueBool("tizen.org/feature/opengles.texture_format.3dc", &bool_result);
-  if (ret.IsError()) {
-    return ret;
-  }
-  if (bool_result) {
-    if (!texture_format.empty()) {
-      texture_format += kOpenglesTextureDelimiter;
-    }
-    texture_format += kOpenglesTexture3dc;
-  }
-
-  ret = GetValueBool("tizen.org/feature/opengles.texture_format.atc", &bool_result);
-  if (ret.IsError()) {
-    return ret;
-  }
-  if (bool_result) {
-    if (!texture_format.empty()) {
-      texture_format += kOpenglesTextureDelimiter;
-    }
-    texture_format += kOpenglesTextureAtc;
-  }
-
-  ret = GetValueBool("tizen.org/feature/opengles.texture_format.pvrtc", &bool_result);
-  if (ret.IsError()) {
-    return ret;
-  }
-  if (bool_result) {
-    if (!texture_format.empty()) {
-      texture_format += kOpenglesTextureDelimiter;
-    }
-    texture_format += kOpenglesTexturePvrtc;
-  }
-
-  if (texture_format.empty()) {
-    // this exception is converted to "Undefined" value in JS layer
-    std::string log_msg = "Platform error while getting OpenGL-ES texture format";
-    LoggerE("%s", log_msg.c_str());
-    return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg);
-  }
-  *result = texture_format;
-  return PlatformResult(ErrorCode::NO_ERROR);
-}
-
-PlatformResult SystemInfoDeviceCapability::GetPlatfomCoreCpuArch(std::string* return_value) {
-  std::string result;
-  bool bool_result = false;
-  PlatformResult ret = GetValueBool("tizen.org/feature/platform.core.cpu.arch.armv6", &bool_result);
-  if (ret.IsError()) {
-    return ret;
-  }
-  if (bool_result) {
-    result = kPlatformCoreArmv6;
-  }
-
-  ret = GetValueBool("tizen.org/feature/platform.core.cpu.arch.armv7", &bool_result);
-  if (ret.IsError()) {
-    return ret;
-  }
-  if (bool_result) {
-    if (!result.empty()) {
-      result += kPlatformCoreDelimiter;
-    }
-    result += kPlatformCoreArmv7;
-  }
-
-  ret = GetValueBool("tizen.org/feature/platform.core.cpu.arch.x86", &bool_result);
-  if (ret.IsError()) {
-    return ret;
-  }
-  if (bool_result) {
-    if (!result.empty()) {
-      result += kPlatformCoreDelimiter;
-    }
-    result += kPlatformCoreX86;
-  }
-
-  if (result.empty()) {
-    LoggerE("Platform error while retrieving platformCoreCpuArch: result is empty");
-    return PlatformResult(ErrorCode::UNKNOWN_ERR, "platformCoreCpuArch result is empty");
-  }
-  *return_value = result;
-  return PlatformResult(ErrorCode::NO_ERROR);
-}
-
-PlatformResult SystemInfoDeviceCapability::GetPlatfomCoreFpuArch(std::string* return_value) {
-  std::string result;
-  bool bool_result = false;
-  PlatformResult ret = GetValueBool("tizen.org/feature/platform.core.fpu.arch.sse2", &bool_result);
-  if (ret.IsError()) {
-    return ret;
-  }
-  if (bool_result) {
-    result = kPlatformCoreSse2;
-  }
-
-  ret = GetValueBool("tizen.org/feature/platform.core.fpu.arch.sse3", &bool_result);
-  if (ret.IsError()) {
-    return ret;
-  }
-  if (bool_result) {
-    if (!result.empty()) {
-      result += kPlatformCoreDelimiter;
-    }
-    result += kPlatformCoreSse3;
-  }
-
-  ret = GetValueBool("tizen.org/feature/platform.core.fpu.arch.ssse3", &bool_result);
-  if (ret.IsError()) {
-    return ret;
-  }
-  if (bool_result) {
-    if (!result.empty()) {
-      result += kPlatformCoreDelimiter;
-    }
-    result += kPlatformCoreSsse3;
-  }
-
-  ret = GetValueBool("tizen.org/feature/platform.core.fpu.arch.vfpv2", &bool_result);
-  if (ret.IsError()) {
-    return ret;
-  }
-  if (bool_result) {
-    if (!result.empty()) {
-      result += kPlatformCoreDelimiter;
-    }
-    result += kPlatformCoreVfpv2;
-  }
-
-  ret = GetValueBool("tizen.org/feature/platform.core.fpu.arch.vfpv3", &bool_result);
-  if (ret.IsError()) {
-    return ret;
-  }
-  if (bool_result) {
-    if (!result.empty()) {
-      result += kPlatformCoreDelimiter;
-    }
-    result += kPlatformCoreVfpv3;
-  }
-  if (result.empty()) {
-    LoggerE("Platform error while retrieving platformCoreFpuArch: result is empty");
-    return PlatformResult(ErrorCode::UNKNOWN_ERR, "platformCoreFpuArch result is empty");
-  }
-  *return_value = result;
-  return PlatformResult(ErrorCode::NO_ERROR);
-}
-
-PlatformResult SystemInfoDeviceCapability::GetProfile(std::string* return_value) {
-  std::string profile = "";
-  PlatformResult ret = GetValueString("tizen.org/feature/profile", &profile);
-  if (ret.IsError()) {
-    return ret;
-  }
-
-  *return_value = kProfileFull;
-  if ( kPlatformFull == profile ) {
-    *return_value = kProfileFull;
-  } else if ( kPlatformMobile == profile ) {
-    *return_value = kProfileMobile;
-  } else if ( kPlatformWearable == profile ) {
-    *return_value = kProfileWearable;
-  }
-  return PlatformResult(ErrorCode::NO_ERROR);
-}
-
-bool SystemInfoDeviceCapability::IsBluetoothAlwaysOn() {
-#ifdef PROFILE_MOBILE_FULL
-  return false;
-#elif PROFILE_MOBILE
-  return false;
-#elif PROFILE_WEARABLE
-  return false;
-#elif PROFILE_TV
-  return true;
-#else
-  return false;
-#endif
-}
-
-bool SystemInfoDeviceCapability::IsScreen()
-{
-  return true;
-}
-
-
-PlatformResult SystemInfoDeviceCapability::GetPlatformCoreCpuFrequency(int* return_value)
-{
-  LoggerD("Entered");
-
-  std::string freq;
-  std::string file_name;
-
-#ifdef TIZEN_IS_EMULATOR
-  file_name = "/proc/cpuinfo";
-#else
-  file_name = "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq";
-#endif
-
-  std::ifstream cpuinfo_freq(file_name);
-  if (!cpuinfo_freq.is_open()) {
-    LoggerE("Failed to get cpu frequency");
-    return PlatformResult(ErrorCode::UNKNOWN_ERR, "Unable to open file");
-  }
-
-#ifdef TIZEN_IS_EMULATOR
-  //get frequency value from cpuinfo file
-  //example entry for frequency looks like below
-  //cpu MHz   : 3392.046
-  std::size_t found;
-  do {
-    getline(cpuinfo_freq, freq);
-    found = freq.find("cpu MHz");
-  } while (std::string::npos == found && !cpuinfo_freq.eof());
-
-  found = freq.find(":");
-  if (std::string::npos != found) {
-    *return_value = std::stoi(freq.substr(found + 2));
-  }
-#else
-  getline(cpuinfo_freq, freq);
-  *return_value = std::stoi(freq) / 1000; // unit: MHz
-#endif
-
-  cpuinfo_freq.close();
-  LoggerD("cpu frequency : %d", *return_value);
-
-  return PlatformResult(ErrorCode::NO_ERROR);
-}
-
-PlatformResult SystemInfoDeviceCapability::IsNativeOspCompatible(bool* result)
-{
-  LoggerD("Enter");
-#ifdef PROFILE_WEARABLE
-  *result = false;
-  return PlatformResult(ErrorCode::NO_ERROR);
-#else
-  return GetValueBool(kTizenFeaturePlatformNativeOspCompatible, result);
-#endif
-}
-
-PlatformResult SystemInfoDeviceCapability::GetNativeAPIVersion(std::string* return_value)
-{
-  LoggerD("Enter");
-#ifdef PROFILE_WEARABLE
-  *return_value = "";
-  return PlatformResult(ErrorCode::NO_ERROR);
-#else
-  return GetValueString(kTizenFeaturePlatformNativeApiVersion, return_value);
-#endif
-}
-
-PlatformResult SystemInfoDeviceCapability::GetPlatformVersionName(std::string* result)
-{
-  LoggerD("Enter");
-
-  //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);
-}
-
 } // namespace systeminfo
 } // namespace webapi
index df5af85..19060b8 100644 (file)
@@ -21,6 +21,7 @@
 #include <functional>
 #include "common/picojson.h"
 #include "common/platform_result.h"
+#include "systeminfo/systeminfo_device_capability.h"
 
 namespace extension {
 namespace systeminfo {
@@ -110,26 +111,6 @@ class SysteminfoUtils {
 
 typedef unsigned char byte;
 
-class SystemInfoDeviceCapability {
- public:
-  static common::PlatformResult GetCapability(const std::string& key, picojson::value& result);
-  static common::PlatformResult GetValueBool(const char *key, bool* value);
-  static common::PlatformResult GetValueInt(const char *key, int* value);
-  static common::PlatformResult GetValueString(const char *key, std::string* str_value);
-
-  static common::PlatformResult IsInputKeyboardLayout(bool* result);
-  static common::PlatformResult GetOpenglesTextureFormat(std::string* result);
-  static common::PlatformResult GetPlatfomCoreCpuArch(std::string* return_value);
-  static common::PlatformResult GetPlatfomCoreFpuArch(std::string* return_value);
-  static common::PlatformResult GetProfile(std::string* return_value);
-  static common::PlatformResult GetPlatformCoreCpuFrequency(int* return_value);
-  static common::PlatformResult IsNativeOspCompatible(bool* result);
-  static common::PlatformResult GetNativeAPIVersion(std::string* return_value);
-  static common::PlatformResult GetPlatformVersionName(std::string* result);
-  static bool IsBluetoothAlwaysOn();
-  static bool IsScreen();
-};
-
 } // namespace systeminfo
 } // namespace webapi
 
index 5659bfa..4564c4a 100644 (file)
         'systeminfo_instance.h',
         'systeminfo-utils.cpp',
         'systeminfo-utils.h',
+        'systeminfo_manager.cc',
+        'systeminfo_manager.h',
+        'systeminfo_device_capability.cc',
+        'systeminfo_device_capability.h',
       ],
       'includes': [
         '../common/pkg-config.gypi',
diff --git a/src/systeminfo/systeminfo_device_capability.cc b/src/systeminfo/systeminfo_device_capability.cc
new file mode 100644 (file)
index 0000000..ab722d6
--- /dev/null
@@ -0,0 +1,612 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+#include "systeminfo_device_capability.h"
+
+#include <fstream>
+#include <system_info.h>
+
+#include "common/logger.h"
+
+// TODO:: hardcoded value, only for IsBluetoothAlwaysOn
+#define PROFILE_MOBILE 1
+
+namespace extension {
+namespace systeminfo {
+
+using common::PlatformResult;
+using common::ErrorCode;
+
+namespace {
+// device profile
+const char* kPlatformFull = "mobile-full";
+const char* kPlatformMobile = "mobile-web";
+const char* kPlatformWearable = "wearable";
+
+const char* kProfileFull = "MOBILE_FULL";
+const char* kProfileMobile = "MOBILE_WEB";
+const char* kProfileWearable = "WEARABLE";
+//opengles
+const char* kOpenglesTextureDelimiter = "/";
+const char* kOpenglesTextureUtc = "utc";
+const char* kOpenglesTexturePtc = "ptc";
+const char* kOpenglesTextureEtc = "etc";
+const char* kOpenglesTexture3dc = "3dc";
+const char* kOpenglesTextureAtc = "atc";
+const char* kOpenglesTexturePvrtc = "pvrtc";
+//core cpu arch
+const char* kPlatformCoreDelimiter = " | ";
+const char* kPlatformCoreArmv6 = "armv6";
+const char* kPlatformCoreArmv7 = "armv7";
+const char* kPlatformCoreX86 = "x86";
+//core fpu arch
+const char* kPlatformCoreSse2 = "sse2";
+const char* kPlatformCoreSse3 = "sse3";
+const char* kPlatformCoreSsse3 = "ssse3";
+const char* kPlatformCoreVfpv2 = "vfpv2";
+const char* kPlatformCoreVfpv3 = "vfpv3";
+
+/*API feature*/
+/*Network feature*/
+const char* kTizenFeatureBluetoothAlwaysOn = "http://tizen.org/capability/network.bluetooth.always_on"; //TODO mobile/wearable: false, tv: true
+const char* kTizenFeatureOpenglesTextureFormat = "http://tizen.org/feature/opengles.texture_format";
+const char* kTizenFeatureCoreApiVersion = "http://tizen.org/feature/platform.core.api.version";
+const char* kTizenFeaturePlatfromCoreCpuArch = "http://tizen.org/feature/platform.core.cpu.arch";
+const char* kTizenFeaturePlatfromCoreFpuArch = "http://tizen.org/feature/platform.core.fpu.arch";
+/*profile feature*/
+const char* kTizenFeatureProfile = "http://tizen.org/feature/profile";
+/*Screen feature*/
+const char* kTizenFeatureScreen = "http://tizen.org/feature/screen";
+/*Sensor feature*/
+const char* kTizenFeatureCpuFrequency = "http://tizen.org/feature/platform.core.cpu.frequency";
+/*platform*/
+const char* kTizenFeaturePlatformNativeApiVersion = "tizen.org/feature/platform.native.api.version";
+const char* kTizenFeaturePlatformNativeOspCompatible = "tizen.org/feature/platform.native.osp_compatible";
+const char* kTizenFeaturePlatformVersionName = "http://tizen.org/feature/platform.version.name";
+} //namespace
+
+PlatformResult SystemInfoDeviceCapability::GetValueBool(const char *key, bool* value) {
+  bool platform_result = false;
+  int ret = system_info_get_platform_bool(key, &platform_result);
+  if (SYSTEM_INFO_ERROR_NONE != ret) {
+    ret = system_info_get_custom_bool(key, &platform_result);
+    if (SYSTEM_INFO_ERROR_NONE != ret) {
+      std::string log_msg = "Platform error while getting bool value: ";
+      log_msg += std::string(key) + " " + std::to_string(ret);
+      LoggerE("%s", log_msg.c_str());
+      return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg);
+    }
+  }
+
+  *value = platform_result;
+  LoggerD("value[%s]: %s", key, *value ? "true" : "false");
+  return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult SystemInfoDeviceCapability::GetValueInt(const char *key, int* value) {
+  int platform_result = 0;
+  int ret = system_info_get_platform_int(key, &platform_result);
+  if (SYSTEM_INFO_ERROR_NONE != ret) {
+    ret = system_info_get_custom_int(key, &platform_result);
+    if (SYSTEM_INFO_ERROR_NONE != ret) {
+      std::string log_msg = "Platform error while getting int value: ";
+      log_msg += std::string(key) + " " + std::to_string(ret);
+      LoggerE("%s", log_msg.c_str());
+      return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg);
+    }
+  }
+
+  *value = platform_result;
+  LoggerD("value[%s]: %d", key, *value);
+  return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult SystemInfoDeviceCapability::GetValueString(const char *key, std::string* str_value) {
+  char* value = nullptr;
+
+  int ret = system_info_get_platform_string(key, &value);
+  if (SYSTEM_INFO_ERROR_NONE != ret) {
+    ret = system_info_get_custom_string(key, &value);
+    if (SYSTEM_INFO_ERROR_NONE != ret) {
+      std::string log_msg = "Platform error while getting string value: ";
+      log_msg += std::string(key) + " " + std::to_string(ret);
+      LoggerE("%s", log_msg.c_str());
+      return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg);
+    }
+  }
+
+  if (value != nullptr) {
+    *str_value = value;
+    free(value);
+    value = nullptr;
+  }
+
+  LoggerD("value[%s]: %s", key, str_value->c_str());
+  return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+static PlatformResult CheckStringCapability(const std::string& key, std::string* value, bool* fetched) {
+  LoggerD("Entered CheckStringCapability");
+  *fetched = false;
+  if (kTizenFeatureOpenglesTextureFormat == key) {
+    PlatformResult ret = SystemInfoDeviceCapability::GetOpenglesTextureFormat(value);
+    if (ret.IsError()) {
+      return ret;
+    }
+  } else if (kTizenFeatureCoreApiVersion == key) {
+    *value = "2.3";
+  } 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 PlatformResult(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) {
+  LoggerD("Entered CheckBoolCapability");
+  *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 PlatformResult(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;
+    }
+  }
+  return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+static PlatformResult CheckIntCapability(const std::string& key, std::string* value,
+                                         bool* fetched) {
+  LoggerD("Entered CheckIntCapability");
+  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 PlatformResult(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);
+}
+
+PlatformResult SystemInfoDeviceCapability::GetCapability(const std::string& key,
+                                                          picojson::value* result) {
+  LoggerD("Entered");
+  picojson::object& result_obj = result->get<picojson::object>();
+
+  std::string value = "";
+  std::string type = "";
+  bool bool_value = false ;
+  bool is_fetched = false;
+
+  PlatformResult ret = CheckBoolCapability(key, &bool_value, &is_fetched);
+  if (ret.IsError()) {
+    return ret;
+  }
+  if (is_fetched) {
+    type = "bool";
+  } else {
+    ret = CheckIntCapability(key, &value, &is_fetched);
+    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";
+      }
+    }
+  }
+
+  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 {
+    LoggerD("Value for given key was not found");
+    return PlatformResult(ErrorCode::NOT_SUPPORTED_ERR, "Value for given key was not found");
+  }
+  result_obj.insert(std::make_pair("type", picojson::value(type)));
+
+  return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult SystemInfoDeviceCapability::IsInputKeyboardLayout(bool* result) {
+  std::string input_keyboard_layout = "";
+  PlatformResult ret = GetValueString("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);
+  if (ret.IsError()) {
+    return ret;
+  }
+
+  // according to SystemInfo-DeviceCapabilities-dependency-table
+  // inputKeyboard   inputKeyboardLayout
+  //  O               O                   Possible
+  //  O               X                   Possible
+  //  X               X                   Possible
+  //  X               O                   Impossible
+
+  *result = input_keyboard ? !(input_keyboard_layout.empty()) : false;
+  return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult SystemInfoDeviceCapability::GetOpenglesTextureFormat(std::string* result) {
+  bool bool_result = false;
+  PlatformResult ret = GetValueBool("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";
+    LoggerE("%s", log_msg.c_str());
+    return PlatformResult(ErrorCode::NOT_SUPPORTED_ERR, log_msg);
+  }
+  std::string texture_format = "";
+
+  ret = GetValueBool("tizen.org/feature/opengles.texture_format.utc", &bool_result);
+  if (ret.IsError()) {
+    return ret;
+  }
+  if (bool_result) {
+    texture_format += kOpenglesTextureUtc;
+  }
+
+  ret = GetValueBool("tizen.org/feature/opengles.texture_format.ptc", &bool_result);
+  if (ret.IsError()) {
+    return ret;
+  }
+  if (bool_result) {
+    if (!texture_format.empty()) {
+      texture_format += kOpenglesTextureDelimiter;
+    }
+    texture_format += kOpenglesTexturePtc;
+  }
+
+  ret = GetValueBool("tizen.org/feature/opengles.texture_format.etc", &bool_result);
+  if (ret.IsError()) {
+    return ret;
+  }
+  if (bool_result) {
+    if (!texture_format.empty()) {
+      texture_format += kOpenglesTextureDelimiter;
+    }
+    texture_format += kOpenglesTextureEtc;
+  }
+
+  ret = GetValueBool("tizen.org/feature/opengles.texture_format.3dc", &bool_result);
+  if (ret.IsError()) {
+    return ret;
+  }
+  if (bool_result) {
+    if (!texture_format.empty()) {
+      texture_format += kOpenglesTextureDelimiter;
+    }
+    texture_format += kOpenglesTexture3dc;
+  }
+
+  ret = GetValueBool("tizen.org/feature/opengles.texture_format.atc", &bool_result);
+  if (ret.IsError()) {
+    return ret;
+  }
+  if (bool_result) {
+    if (!texture_format.empty()) {
+      texture_format += kOpenglesTextureDelimiter;
+    }
+    texture_format += kOpenglesTextureAtc;
+  }
+
+  ret = GetValueBool("tizen.org/feature/opengles.texture_format.pvrtc", &bool_result);
+  if (ret.IsError()) {
+    return ret;
+  }
+  if (bool_result) {
+    if (!texture_format.empty()) {
+      texture_format += kOpenglesTextureDelimiter;
+    }
+    texture_format += kOpenglesTexturePvrtc;
+  }
+
+  if (texture_format.empty()) {
+    // this exception is converted to "Undefined" value in JS layer
+    std::string log_msg = "Platform error while getting OpenGL-ES texture format";
+    LoggerE("%s", log_msg.c_str());
+    return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg);
+  }
+  *result = texture_format;
+  return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult SystemInfoDeviceCapability::GetPlatfomCoreCpuArch(std::string* return_value) {
+  std::string result;
+  bool bool_result = false;
+  PlatformResult ret = GetValueBool("tizen.org/feature/platform.core.cpu.arch.armv6", &bool_result);
+  if (ret.IsError()) {
+    return ret;
+  }
+  if (bool_result) {
+    result = kPlatformCoreArmv6;
+  }
+
+  ret = GetValueBool("tizen.org/feature/platform.core.cpu.arch.armv7", &bool_result);
+  if (ret.IsError()) {
+    return ret;
+  }
+  if (bool_result) {
+    if (!result.empty()) {
+      result += kPlatformCoreDelimiter;
+    }
+    result += kPlatformCoreArmv7;
+  }
+
+  ret = GetValueBool("tizen.org/feature/platform.core.cpu.arch.x86", &bool_result);
+  if (ret.IsError()) {
+    return ret;
+  }
+  if (bool_result) {
+    if (!result.empty()) {
+      result += kPlatformCoreDelimiter;
+    }
+    result += kPlatformCoreX86;
+  }
+
+  if (result.empty()) {
+    LoggerE("Platform error while retrieving platformCoreCpuArch: result is empty");
+    return PlatformResult(ErrorCode::UNKNOWN_ERR, "platformCoreCpuArch result is empty");
+  }
+  *return_value = result;
+  return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult SystemInfoDeviceCapability::GetPlatfomCoreFpuArch(std::string* return_value) {
+  std::string result;
+  bool bool_result = false;
+  PlatformResult ret = GetValueBool("tizen.org/feature/platform.core.fpu.arch.sse2", &bool_result);
+  if (ret.IsError()) {
+    return ret;
+  }
+  if (bool_result) {
+    result = kPlatformCoreSse2;
+  }
+
+  ret = GetValueBool("tizen.org/feature/platform.core.fpu.arch.sse3", &bool_result);
+  if (ret.IsError()) {
+    return ret;
+  }
+  if (bool_result) {
+    if (!result.empty()) {
+      result += kPlatformCoreDelimiter;
+    }
+    result += kPlatformCoreSse3;
+  }
+
+  ret = GetValueBool("tizen.org/feature/platform.core.fpu.arch.ssse3", &bool_result);
+  if (ret.IsError()) {
+    return ret;
+  }
+  if (bool_result) {
+    if (!result.empty()) {
+      result += kPlatformCoreDelimiter;
+    }
+    result += kPlatformCoreSsse3;
+  }
+
+  ret = GetValueBool("tizen.org/feature/platform.core.fpu.arch.vfpv2", &bool_result);
+  if (ret.IsError()) {
+    return ret;
+  }
+  if (bool_result) {
+    if (!result.empty()) {
+      result += kPlatformCoreDelimiter;
+    }
+    result += kPlatformCoreVfpv2;
+  }
+
+  ret = GetValueBool("tizen.org/feature/platform.core.fpu.arch.vfpv3", &bool_result);
+  if (ret.IsError()) {
+    return ret;
+  }
+  if (bool_result) {
+    if (!result.empty()) {
+      result += kPlatformCoreDelimiter;
+    }
+    result += kPlatformCoreVfpv3;
+  }
+  if (result.empty()) {
+    LoggerE("Platform error while retrieving platformCoreFpuArch: result is empty");
+    return PlatformResult(ErrorCode::UNKNOWN_ERR, "platformCoreFpuArch result is empty");
+  }
+  *return_value = result;
+  return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult SystemInfoDeviceCapability::GetProfile(std::string* return_value) {
+  std::string profile = "";
+  PlatformResult ret = GetValueString("tizen.org/feature/profile", &profile);
+  if (ret.IsError()) {
+    return ret;
+  }
+
+  *return_value = kProfileFull;
+  if ( kPlatformFull == profile ) {
+    *return_value = kProfileFull;
+  } else if ( kPlatformMobile == profile ) {
+    *return_value = kProfileMobile;
+  } else if ( kPlatformWearable == profile ) {
+    *return_value = kProfileWearable;
+  }
+  return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+bool SystemInfoDeviceCapability::IsBluetoothAlwaysOn() {
+#ifdef PROFILE_MOBILE_FULL
+  return false;
+#elif PROFILE_MOBILE
+  return false;
+#elif PROFILE_WEARABLE
+  return false;
+#elif PROFILE_TV
+  return true;
+#else
+  return false;
+#endif
+}
+
+bool SystemInfoDeviceCapability::IsScreen() {
+  return true;
+}
+
+PlatformResult SystemInfoDeviceCapability::GetPlatformCoreCpuFrequency(int* return_value) {
+  LoggerD("Entered");
+
+  std::string freq;
+  std::string file_name;
+
+#ifdef TIZEN_IS_EMULATOR
+  file_name = "/proc/cpuinfo";
+#else
+  file_name = "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq";
+#endif
+
+  std::ifstream cpuinfo_freq(file_name);
+  if (!cpuinfo_freq.is_open()) {
+    LoggerE("Failed to get cpu frequency");
+    return PlatformResult(ErrorCode::UNKNOWN_ERR, "Unable to open file");
+  }
+
+#ifdef TIZEN_IS_EMULATOR
+  //get frequency value from cpuinfo file
+  //example entry for frequency looks like below
+  //cpu MHz   : 3392.046
+  std::size_t found;
+  do {
+    getline(cpuinfo_freq, freq);
+    found = freq.find("cpu MHz");
+  } while (std::string::npos == found && !cpuinfo_freq.eof());
+
+  found = freq.find(":");
+  if (std::string::npos != found) {
+    *return_value = std::stoi(freq.substr(found + 2));
+  }
+#else
+  getline(cpuinfo_freq, freq);
+  *return_value = std::stoi(freq) / 1000; // unit: MHz
+#endif
+
+  cpuinfo_freq.close();
+  LoggerD("cpu frequency : %d", *return_value);
+
+  return PlatformResult(ErrorCode::NO_ERROR);
+}
+
+PlatformResult SystemInfoDeviceCapability::IsNativeOspCompatible(bool* result) {
+  LoggerD("Enter");
+#ifdef PROFILE_WEARABLE
+  *result = false;
+  return PlatformResult(ErrorCode::NO_ERROR);
+#else
+  return GetValueBool(kTizenFeaturePlatformNativeOspCompatible, result);
+#endif
+}
+
+PlatformResult SystemInfoDeviceCapability::GetNativeAPIVersion(std::string* return_value) {
+  LoggerD("Enter");
+#ifdef PROFILE_WEARABLE
+  *return_value = "";
+  return PlatformResult(ErrorCode::NO_ERROR);
+#else
+  return GetValueString(kTizenFeaturePlatformNativeApiVersion, return_value);
+#endif
+}
+
+PlatformResult SystemInfoDeviceCapability::GetPlatformVersionName(std::string* result) {
+  LoggerD("Enter");
+
+  //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);
+}
+
+} // namespace systeminfo
+} // namespace webapi
diff --git a/src/systeminfo/systeminfo_device_capability.h b/src/systeminfo/systeminfo_device_capability.h
new file mode 100644 (file)
index 0000000..8285e61
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+#ifndef WEBAPI_PLUGINS_SYSTEMINFO_SYSTEMINFO_DEVICE_CAPABILITY_H__
+#define WEBAPI_PLUGINS_SYSTEMINFO_SYSTEMINFO_DEVICE_CAPABILITY_H__
+
+#include <string>
+#include "common/picojson.h"
+#include "common/platform_result.h"
+
+namespace extension {
+namespace systeminfo {
+
+class SystemInfoDeviceCapability {
+ public:
+  static common::PlatformResult GetCapability(const std::string& key, picojson::value* result);
+  static common::PlatformResult GetValueBool(const char *key, bool* value);
+  static common::PlatformResult GetValueInt(const char *key, int* value);
+  static common::PlatformResult GetValueString(const char *key, std::string* str_value);
+
+  static common::PlatformResult IsInputKeyboardLayout(bool* result);
+  static common::PlatformResult GetOpenglesTextureFormat(std::string* result);
+  static common::PlatformResult GetPlatfomCoreCpuArch(std::string* return_value);
+  static common::PlatformResult GetPlatfomCoreFpuArch(std::string* return_value);
+  static common::PlatformResult GetProfile(std::string* return_value);
+  static common::PlatformResult GetPlatformCoreCpuFrequency(int* return_value);
+  static common::PlatformResult IsNativeOspCompatible(bool* result);
+  static common::PlatformResult GetNativeAPIVersion(std::string* return_value);
+  static common::PlatformResult GetPlatformVersionName(std::string* result);
+  static bool IsBluetoothAlwaysOn();
+  static bool IsScreen();
+};
+
+} // namespace systeminfo
+} // namespace webapi
+
+#endif // WEBAPI_PLUGINS_SYSTEMINFO_SYSTEMINFO_DEVICE_CAPABILITY_H__
index 2f7f68b..858f1e7 100644 (file)
@@ -26,6 +26,7 @@
 #include "common/task-queue.h"
 
 #include "systeminfo-utils.h"
+#include "systeminfo_device_capability.h"
 
 namespace extension {
 namespace systeminfo {
@@ -116,7 +117,7 @@ const std::string kPropertyIdCameraFlash= "CAMERA_FLASH";
   result_obj.insert(std::make_pair(str_name, picojson::value(str_value)));
 }
 
-SysteminfoInstance::SysteminfoInstance() {
+SysteminfoInstance::SysteminfoInstance() : manager_(*this) {
   LoggerD("Enter");
   using std::placeholders::_1;
   using std::placeholders::_2;
@@ -162,103 +163,12 @@ SysteminfoInstance::~SysteminfoInstance() {
 
 void SysteminfoInstance::GetCapabilities(const picojson::value& args, picojson::object& out) {
   LoggerD("Enter");
-  picojson::value result = picojson::value(picojson::object());
-  picojson::object& result_obj = result.get<picojson::object>();
-
-  bool bool_value = false;
-  int int_value = 0;
-  std::string str_value = "";
-  PlatformResult ret(ErrorCode::NO_ERROR);
-  DEFAULT_REPORT_BOOL_CAPABILITY("bluetooth", "tizen.org/feature/network.bluetooth")
-  DEFAULT_REPORT_BOOL_CAPABILITY("nfc", "tizen.org/feature/network.nfc")
-  DEFAULT_REPORT_BOOL_CAPABILITY("nfcReservedPush", "tizen.org/feature/network.nfc.reserved_push")
-  DEFAULT_REPORT_INT_CAPABILITY("multiTouchCount", "tizen.org/feature/multi_point_touch.point_count")
-  DEFAULT_REPORT_BOOL_CAPABILITY("inputKeyboard", "tizen.org/feature/input.keyboard")
-  REPORT_BOOL_CAPABILITY("inputKeyboardLayout", SystemInfoDeviceCapability::IsInputKeyboardLayout)
-  DEFAULT_REPORT_BOOL_CAPABILITY("wifi", "tizen.org/feature/network.wifi")
-  DEFAULT_REPORT_BOOL_CAPABILITY("wifiDirect", "tizen.org/feature/network.wifi.direct")
-  DEFAULT_REPORT_STRING_CAPABILITY("platformName", "tizen.org/system/platform.name")
-  DEFAULT_REPORT_STRING_CAPABILITY("platformVersion", "tizen.org/feature/platform.version")
-  DEFAULT_REPORT_STRING_CAPABILITY("webApiVersion", "tizen.org/feature/platform.web.api.version")
-  DEFAULT_REPORT_BOOL_CAPABILITY("fmRadio", "tizen.org/feature/fmradio")
-  DEFAULT_REPORT_BOOL_CAPABILITY("opengles", "tizen.org/feature/opengles")
-  DEFAULT_REPORT_BOOL_CAPABILITY("openglesVersion1_1", "tizen.org/feature/opengles.version.1_1")
-  DEFAULT_REPORT_BOOL_CAPABILITY("openglesVersion2_0", "tizen.org/feature/opengles.version.2_0")
-  REPORT_STRING_CAPABILITY("openglestextureFormat",
-                           SystemInfoDeviceCapability::GetOpenglesTextureFormat)
-  DEFAULT_REPORT_BOOL_CAPABILITY("speechRecognition", "tizen.org/feature/speech.recognition")
-  DEFAULT_REPORT_BOOL_CAPABILITY("speechSynthesis", "tizen.org/feature/speech.synthesis")
-  DEFAULT_REPORT_BOOL_CAPABILITY("accelerometer", "tizen.org/feature/sensor.accelerometer")
-  DEFAULT_REPORT_BOOL_CAPABILITY("accelerometerWakeup", "tizen.org/feature/sensor.accelerometer.wakeup")
-  DEFAULT_REPORT_BOOL_CAPABILITY("barometer", "tizen.org/feature/sensor.barometer")
-  DEFAULT_REPORT_BOOL_CAPABILITY("barometerWakeup", "tizen.org/feature/sensor.barometer.wakeup")
-  DEFAULT_REPORT_BOOL_CAPABILITY("gyroscope", "tizen.org/feature/sensor.gyroscope")
-  DEFAULT_REPORT_BOOL_CAPABILITY("gyroscopeWakeup", "tizen.org/feature/sensor.gyroscope.wakeup")
-  DEFAULT_REPORT_BOOL_CAPABILITY("camera", "tizen.org/feature/camera")
-  DEFAULT_REPORT_BOOL_CAPABILITY("cameraFront", "tizen.org/feature/camera.front")
-  DEFAULT_REPORT_BOOL_CAPABILITY("cameraFrontFlash", "tizen.org/feature/camera.front.flash")
-  DEFAULT_REPORT_BOOL_CAPABILITY("cameraBack", "tizen.org/feature/camera.back")
-  DEFAULT_REPORT_BOOL_CAPABILITY("cameraBackFlash", "tizen.org/feature/camera.back.flash")
-  DEFAULT_REPORT_BOOL_CAPABILITY("location", "tizen.org/feature/location")
-  DEFAULT_REPORT_BOOL_CAPABILITY("locationGps", "tizen.org/feature/location.gps")
-  DEFAULT_REPORT_BOOL_CAPABILITY("locationWps", "tizen.org/feature/location.wps")
-  DEFAULT_REPORT_BOOL_CAPABILITY("microphone", "tizen.org/feature/microphone")
-  DEFAULT_REPORT_BOOL_CAPABILITY("usbHost", "tizen.org/feature/usb.host")
-  DEFAULT_REPORT_BOOL_CAPABILITY("usbAccessory", "tizen.org/feature/usb.accessory")
-  DEFAULT_REPORT_BOOL_CAPABILITY("screenOutputRca", "tizen.org/feature/screen.output.rca")
-  DEFAULT_REPORT_BOOL_CAPABILITY("screenOutputHdmi", "tizen.org/feature/screen.output.hdmi")
-  DEFAULT_REPORT_BOOL_CAPABILITY("graphicsAcceleration", "tizen.org/feature/graphics.acceleration")
-  DEFAULT_REPORT_BOOL_CAPABILITY("push", "tizen.org/feature/network.push")
-  DEFAULT_REPORT_BOOL_CAPABILITY("telephony", "tizen.org/feature/network.telephony")
-  DEFAULT_REPORT_BOOL_CAPABILITY("telephonyMms", "tizen.org/feature/network.telephony.mms")
-  DEFAULT_REPORT_BOOL_CAPABILITY("telephonySms", "tizen.org/feature/network.telephony.sms")
-  REPORT_STRING_CAPABILITY("platformCoreCpuArch",
-                             SystemInfoDeviceCapability::GetPlatfomCoreCpuArch)
-  REPORT_STRING_CAPABILITY("platformCoreFpuArch",
-                             SystemInfoDeviceCapability::GetPlatfomCoreFpuArch)
-  DEFAULT_REPORT_BOOL_CAPABILITY("sipVoip", "tizen.org/feature/sip.voip")
-  DEFAULT_REPORT_BOOL_CAPABILITY("magnetometer", "tizen.org/feature/sensor.magnetometer")
-  DEFAULT_REPORT_BOOL_CAPABILITY("magnetometerWakeup", "tizen.org/feature/sensor.magnetometer.wakeup")
-  DEFAULT_REPORT_BOOL_CAPABILITY("photometer", "tizen.org/feature/sensor.photometer")
-  DEFAULT_REPORT_BOOL_CAPABILITY("photometerWakeup", "tizen.org/feature/sensor.photometer.wakeup")
-  DEFAULT_REPORT_BOOL_CAPABILITY("proximity", "tizen.org/feature/sensor.proximity")
-  DEFAULT_REPORT_BOOL_CAPABILITY("proximityWakeup", "tizen.org/feature/sensor.proximity.wakeup")
-  DEFAULT_REPORT_BOOL_CAPABILITY("tiltmeter", "tizen.org/feature/sensor.tiltmeter")
-  DEFAULT_REPORT_BOOL_CAPABILITY("tiltmeterWakeup", "tizen.org/feature/sensor.tiltmeter.wakeup")
-  DEFAULT_REPORT_BOOL_CAPABILITY("dataEncryption", "tizen.org/feature/database.encryption")
-  DEFAULT_REPORT_BOOL_CAPABILITY("autoRotation", "tizen.org/feature/screen.auto_rotation")
-  DEFAULT_REPORT_BOOL_CAPABILITY("visionImageRecognition", "tizen.org/feature/vision.image_recognition")
-  DEFAULT_REPORT_BOOL_CAPABILITY("visionQrcodeGeneration", "tizen.org/feature/vision.qrcode_generation")
-  DEFAULT_REPORT_BOOL_CAPABILITY("visionQrcodeRecognition", "tizen.org/feature/vision.qrcode_recognition")
-  DEFAULT_REPORT_BOOL_CAPABILITY("visionFaceRecognition", "tizen.org/feature/vision.face_recognition")
-  DEFAULT_REPORT_BOOL_CAPABILITY("secureElement", "tizen.org/feature/network.secure_element")
-  REPORT_STRING_CAPABILITY("profile", SystemInfoDeviceCapability::GetProfile)
-  DEFAULT_REPORT_STRING_CAPABILITY("nativeApiVersion", "tizen.org/feature/platform.native.api.version")
-  DEFAULT_REPORT_STRING_CAPABILITY("duid", "tizen.org/system/tizenid")
-  DEFAULT_REPORT_BOOL_CAPABILITY("screenSizeNormal", "tizen.org/feature/screen.size.normal")
-  DEFAULT_REPORT_BOOL_CAPABILITY("screenSize480_800", "tizen.org/feature/screen.size.normal.480.800")
-  DEFAULT_REPORT_BOOL_CAPABILITY("screenSize720_1280", "tizen.org/feature/screen.size.normal.720.1280")
-  DEFAULT_REPORT_BOOL_CAPABILITY("shellAppWidget", "tizen.org/feature/shell.appwidget")
-  DEFAULT_REPORT_BOOL_CAPABILITY("nativeOspCompatible", "tizen.org/feature/platform.native.osp_compatible")
-
-  ReportSuccess(result, out);
-  LoggerD("Success");
+  manager_.GetCapabilities(args, &out);
 }
 
 void SysteminfoInstance::GetCapability(const picojson::value& args, picojson::object& out) {
   LoggerD("Enter");
-  CHECK_EXIST(args, "key", out)
-  const std::string& key = args.get("key").get<std::string>();
-  LoggerD("Getting capability with key: %s ", key.c_str());
-
-  picojson::value result = picojson::value(picojson::object());
-  PlatformResult ret = SystemInfoDeviceCapability::GetCapability(key, result);
-  if (ret.IsSuccess()) {
-    ReportSuccess(result, out);
-    LoggerD("Success");
-  } else {
-    ReportError(ret, &out);
-  }
+  manager_.GetCapability(args, &out);
 }
 
 void SysteminfoInstance::GetPropertyValue(const picojson::value& args, picojson::object& out) {
index 19dff82..1a29194 100644 (file)
@@ -18,6 +18,7 @@
 #define SYSTEMINFO_INSTANCE_H_
 
 #include "common/extension.h"
+#include "systeminfo/systeminfo_manager.h"
 
 namespace extension {
 namespace systeminfo {
@@ -41,6 +42,8 @@ class SysteminfoInstance
   void GetTotalMemory(const picojson::value& args, picojson::object& out);
   void GetAvailableMemory(const picojson::value& args, picojson::object& out);
   void GetCount(const picojson::value& args, picojson::object& out);
+
+  SysteminfoManager manager_;
 };
 
 } // namespace systeminfo
diff --git a/src/systeminfo/systeminfo_manager.cc b/src/systeminfo/systeminfo_manager.cc
new file mode 100644 (file)
index 0000000..1c9c5ed
--- /dev/null
@@ -0,0 +1,463 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+#include "systeminfo/systeminfo_manager.h"
+
+#include "systeminfo/systeminfo_instance.h"
+#include "systeminfo/systeminfo_device_capability.h"
+#include "common/logger.h"
+#include "common/converter.h"
+
+using common::PlatformResult;
+using common::ErrorCode;
+using common::TypeMismatchException;
+using common::tools::ReportError;
+using common::tools::ReportSuccess;
+
+namespace extension {
+namespace systeminfo {
+
+namespace {
+#define CHECK_EXIST(args, name, out) \
+  if (!args.contains(name)) {\
+    ReportError(TypeMismatchException(name" is required argument"), *out);\
+      return;\
+    }
+
+#define DEFAULT_REPORT_BOOL_CAPABILITY(str_name, feature_name) \
+  ret = SystemInfoDeviceCapability::GetValueBool(feature_name, &bool_value); \
+  if (ret.IsError()) { \
+    ReportError(ret, out); \
+    return; \
+  } \
+  result_obj.insert(std::make_pair(str_name, picojson::value(bool_value)));
+
+#define REPORT_BOOL_CAPABILITY(str_name, method) \
+  ret = method(&bool_value); \
+  if (ret.IsError()) { \
+    ReportError(ret, out); \
+    return; \
+  } \
+  result_obj.insert(std::make_pair(str_name, picojson::value(bool_value)));
+
+#define DEFAULT_REPORT_INT_CAPABILITY(str_name, feature_name) \
+  ret = SystemInfoDeviceCapability::GetValueInt(feature_name, &int_value); \
+  if (ret.IsError()) { \
+    ReportError(ret, out); \
+    return; \
+  } \
+  result_obj.insert(std::make_pair(str_name, picojson::value(std::to_string(int_value))));
+
+#define DEFAULT_REPORT_STRING_CAPABILITY(str_name, feature_name) \
+  ret = SystemInfoDeviceCapability::GetValueString(feature_name, &str_value); \
+  if (ret.IsError()) { \
+    ReportError(ret, out); \
+    return; \
+  } \
+  result_obj.insert(std::make_pair(str_name, picojson::value(str_value)));
+
+#define REPORT_STRING_CAPABILITY(str_name, method) \
+  ret = method(&str_value); \
+  if (ret.IsError()) { \
+    ReportError(ret, out); \
+    return; \
+  } \
+  result_obj.insert(std::make_pair(str_name, picojson::value(str_value)));
+
+} //namespace
+
+SysteminfoManager::SysteminfoManager(SysteminfoInstance& instance)
+    : instance_(instance){
+}
+
+SysteminfoManager::~SysteminfoManager() {
+  LoggerD("Enter");
+}
+
+void SysteminfoManager::GetCapabilities(const picojson::value& args, picojson::object* out) {
+  LoggerD("Enter");
+  picojson::value result = picojson::value(picojson::object());
+  picojson::object& result_obj = result.get<picojson::object>();
+
+  bool bool_value = false;
+  int int_value = 0;
+  std::string str_value = "";
+  PlatformResult ret(ErrorCode::NO_ERROR);
+  DEFAULT_REPORT_BOOL_CAPABILITY("bluetooth", "tizen.org/feature/network.bluetooth")
+  DEFAULT_REPORT_BOOL_CAPABILITY("nfc", "tizen.org/feature/network.nfc")
+  DEFAULT_REPORT_BOOL_CAPABILITY("nfcReservedPush", "tizen.org/feature/network.nfc.reserved_push")
+  DEFAULT_REPORT_INT_CAPABILITY("multiTouchCount", "tizen.org/feature/multi_point_touch.point_count")
+  DEFAULT_REPORT_BOOL_CAPABILITY("inputKeyboard", "tizen.org/feature/input.keyboard")
+  REPORT_BOOL_CAPABILITY("inputKeyboardLayout", SystemInfoDeviceCapability::IsInputKeyboardLayout)
+  DEFAULT_REPORT_BOOL_CAPABILITY("wifi", "tizen.org/feature/network.wifi")
+  DEFAULT_REPORT_BOOL_CAPABILITY("wifiDirect", "tizen.org/feature/network.wifi.direct")
+  DEFAULT_REPORT_STRING_CAPABILITY("platformName", "tizen.org/system/platform.name")
+  DEFAULT_REPORT_STRING_CAPABILITY("platformVersion", "tizen.org/feature/platform.version")
+  DEFAULT_REPORT_STRING_CAPABILITY("webApiVersion", "tizen.org/feature/platform.web.api.version")
+  DEFAULT_REPORT_BOOL_CAPABILITY("fmRadio", "tizen.org/feature/fmradio")
+  DEFAULT_REPORT_BOOL_CAPABILITY("opengles", "tizen.org/feature/opengles")
+  DEFAULT_REPORT_BOOL_CAPABILITY("openglesVersion1_1", "tizen.org/feature/opengles.version.1_1")
+  DEFAULT_REPORT_BOOL_CAPABILITY("openglesVersion2_0", "tizen.org/feature/opengles.version.2_0")
+  REPORT_STRING_CAPABILITY("openglestextureFormat",
+                           SystemInfoDeviceCapability::GetOpenglesTextureFormat)
+  DEFAULT_REPORT_BOOL_CAPABILITY("speechRecognition", "tizen.org/feature/speech.recognition")
+  DEFAULT_REPORT_BOOL_CAPABILITY("speechSynthesis", "tizen.org/feature/speech.synthesis")
+  DEFAULT_REPORT_BOOL_CAPABILITY("accelerometer", "tizen.org/feature/sensor.accelerometer")
+  DEFAULT_REPORT_BOOL_CAPABILITY("accelerometerWakeup", "tizen.org/feature/sensor.accelerometer.wakeup")
+  DEFAULT_REPORT_BOOL_CAPABILITY("barometer", "tizen.org/feature/sensor.barometer")
+  DEFAULT_REPORT_BOOL_CAPABILITY("barometerWakeup", "tizen.org/feature/sensor.barometer.wakeup")
+  DEFAULT_REPORT_BOOL_CAPABILITY("gyroscope", "tizen.org/feature/sensor.gyroscope")
+  DEFAULT_REPORT_BOOL_CAPABILITY("gyroscopeWakeup", "tizen.org/feature/sensor.gyroscope.wakeup")
+  DEFAULT_REPORT_BOOL_CAPABILITY("camera", "tizen.org/feature/camera")
+  DEFAULT_REPORT_BOOL_CAPABILITY("cameraFront", "tizen.org/feature/camera.front")
+  DEFAULT_REPORT_BOOL_CAPABILITY("cameraFrontFlash", "tizen.org/feature/camera.front.flash")
+  DEFAULT_REPORT_BOOL_CAPABILITY("cameraBack", "tizen.org/feature/camera.back")
+  DEFAULT_REPORT_BOOL_CAPABILITY("cameraBackFlash", "tizen.org/feature/camera.back.flash")
+  DEFAULT_REPORT_BOOL_CAPABILITY("location", "tizen.org/feature/location")
+  DEFAULT_REPORT_BOOL_CAPABILITY("locationGps", "tizen.org/feature/location.gps")
+  DEFAULT_REPORT_BOOL_CAPABILITY("locationWps", "tizen.org/feature/location.wps")
+  DEFAULT_REPORT_BOOL_CAPABILITY("microphone", "tizen.org/feature/microphone")
+  DEFAULT_REPORT_BOOL_CAPABILITY("usbHost", "tizen.org/feature/usb.host")
+  DEFAULT_REPORT_BOOL_CAPABILITY("usbAccessory", "tizen.org/feature/usb.accessory")
+  DEFAULT_REPORT_BOOL_CAPABILITY("screenOutputRca", "tizen.org/feature/screen.output.rca")
+  DEFAULT_REPORT_BOOL_CAPABILITY("screenOutputHdmi", "tizen.org/feature/screen.output.hdmi")
+  DEFAULT_REPORT_BOOL_CAPABILITY("graphicsAcceleration", "tizen.org/feature/graphics.acceleration")
+  DEFAULT_REPORT_BOOL_CAPABILITY("push", "tizen.org/feature/network.push")
+  DEFAULT_REPORT_BOOL_CAPABILITY("telephony", "tizen.org/feature/network.telephony")
+  DEFAULT_REPORT_BOOL_CAPABILITY("telephonyMms", "tizen.org/feature/network.telephony.mms")
+  DEFAULT_REPORT_BOOL_CAPABILITY("telephonySms", "tizen.org/feature/network.telephony.sms")
+  REPORT_STRING_CAPABILITY("platformCoreCpuArch",
+                             SystemInfoDeviceCapability::GetPlatfomCoreCpuArch)
+  REPORT_STRING_CAPABILITY("platformCoreFpuArch",
+                             SystemInfoDeviceCapability::GetPlatfomCoreFpuArch)
+  DEFAULT_REPORT_BOOL_CAPABILITY("sipVoip", "tizen.org/feature/sip.voip")
+  DEFAULT_REPORT_BOOL_CAPABILITY("magnetometer", "tizen.org/feature/sensor.magnetometer")
+  DEFAULT_REPORT_BOOL_CAPABILITY("magnetometerWakeup", "tizen.org/feature/sensor.magnetometer.wakeup")
+  DEFAULT_REPORT_BOOL_CAPABILITY("photometer", "tizen.org/feature/sensor.photometer")
+  DEFAULT_REPORT_BOOL_CAPABILITY("photometerWakeup", "tizen.org/feature/sensor.photometer.wakeup")
+  DEFAULT_REPORT_BOOL_CAPABILITY("proximity", "tizen.org/feature/sensor.proximity")
+  DEFAULT_REPORT_BOOL_CAPABILITY("proximityWakeup", "tizen.org/feature/sensor.proximity.wakeup")
+  DEFAULT_REPORT_BOOL_CAPABILITY("tiltmeter", "tizen.org/feature/sensor.tiltmeter")
+  DEFAULT_REPORT_BOOL_CAPABILITY("tiltmeterWakeup", "tizen.org/feature/sensor.tiltmeter.wakeup")
+  DEFAULT_REPORT_BOOL_CAPABILITY("dataEncryption", "tizen.org/feature/database.encryption")
+  DEFAULT_REPORT_BOOL_CAPABILITY("autoRotation", "tizen.org/feature/screen.auto_rotation")
+  DEFAULT_REPORT_BOOL_CAPABILITY("visionImageRecognition", "tizen.org/feature/vision.image_recognition")
+  DEFAULT_REPORT_BOOL_CAPABILITY("visionQrcodeGeneration", "tizen.org/feature/vision.qrcode_generation")
+  DEFAULT_REPORT_BOOL_CAPABILITY("visionQrcodeRecognition", "tizen.org/feature/vision.qrcode_recognition")
+  DEFAULT_REPORT_BOOL_CAPABILITY("visionFaceRecognition", "tizen.org/feature/vision.face_recognition")
+  DEFAULT_REPORT_BOOL_CAPABILITY("secureElement", "tizen.org/feature/network.secure_element")
+  REPORT_STRING_CAPABILITY("profile", SystemInfoDeviceCapability::GetProfile)
+  DEFAULT_REPORT_STRING_CAPABILITY("nativeApiVersion", "tizen.org/feature/platform.native.api.version")
+  DEFAULT_REPORT_STRING_CAPABILITY("duid", "tizen.org/system/tizenid")
+  DEFAULT_REPORT_BOOL_CAPABILITY("screenSizeNormal", "tizen.org/feature/screen.size.normal")
+  DEFAULT_REPORT_BOOL_CAPABILITY("screenSize480_800", "tizen.org/feature/screen.size.normal.480.800")
+  DEFAULT_REPORT_BOOL_CAPABILITY("screenSize720_1280", "tizen.org/feature/screen.size.normal.720.1280")
+  DEFAULT_REPORT_BOOL_CAPABILITY("shellAppWidget", "tizen.org/feature/shell.appwidget")
+  DEFAULT_REPORT_BOOL_CAPABILITY("nativeOspCompatible", "tizen.org/feature/platform.native.osp_compatible")
+
+  ReportSuccess(result, *out);
+  LoggerD("Success");
+}
+
+void SysteminfoManager::GetCapability(const picojson::value& args, picojson::object* out) {
+  LoggerD("Enter");
+  CHECK_EXIST(args, "key", out)
+  const std::string& key = args.get("key").get<std::string>();
+  LoggerD("Getting capability with key: %s ", key.c_str());
+
+  picojson::value result = picojson::value(picojson::object());
+  PlatformResult ret = SystemInfoDeviceCapability::GetCapability(key, &result);
+  if (ret.IsSuccess()) {
+    ReportSuccess(result, *out);
+    LoggerD("Success");
+  } else {
+    ReportError(ret, out);
+  }
+}
+
+void SysteminfoManager::GetPropertyValue(const picojson::value& args, picojson::object* out) {
+  LoggerD("Enter");
+  CHECK_EXIST(args, "callbackId", out)
+  CHECK_EXIST(args, "property", out)
+  const double callback_id = args.get("callbackId").get<double>();
+  const std::string& prop_id = args.get("property").get<std::string>();
+  LoggerD("Getting property with id: %s ", prop_id.c_str());
+
+//  auto get = [this, prop_id, callback_id](const std::shared_ptr<picojson::value>& response) -> void {
+//    LoggerD("Getting");
+//    picojson::value result = picojson::value(picojson::object());
+//    PlatformResult ret = SysteminfoUtils::GetPropertyValue(prop_id, false, result);
+//    if (ret.IsError()) {
+//      ReportError(ret,&(response->get<picojson::object>()));
+//      return;
+//    }
+//    ReportSuccess(result, response->get<picojson::object>());
+//  };
+//
+//  auto get_response = [this, callback_id](const std::shared_ptr<picojson::value>& response) -> void {
+//    LoggerD("Getting response");
+//    picojson::object& obj = response->get<picojson::object>();
+//    obj.insert(std::make_pair("callbackId", picojson::value{static_cast<double>(callback_id)}));
+//    LoggerD("message: %s", response->serialize().c_str());
+//    PostMessage(response->serialize().c_str());
+//  };
+//
+//  TaskQueue::GetInstance().Queue<picojson::value>
+//  (get, get_response, std::shared_ptr<picojson::value>(new picojson::value(picojson::object())));
+}
+
+void SysteminfoManager::GetPropertyValueArray(const picojson::value& args, picojson::object* out) {
+  LoggerD("Enter");
+  CHECK_EXIST(args, "callbackId", out)
+  CHECK_EXIST(args, "property", out)
+  const double callback_id = args.get("callbackId").get<double>();
+  const std::string& prop_id = args.get("property").get<std::string>();
+  LoggerD("Getting property arrray with id: %s ", prop_id.c_str());
+
+//  auto get = [this, prop_id, callback_id](const std::shared_ptr<picojson::value>& response) -> void {
+//    LoggerD("Getting");
+//    picojson::value result = picojson::value(picojson::object());
+//    PlatformResult ret = SysteminfoUtils::GetPropertyValue(prop_id, true, result);
+//    if (ret.IsError()) {
+//      LoggerE("Failed: GetPropertyValue()");
+//      ReportError(ret,&(response->get<picojson::object>()));
+//      return;
+//    }
+//    ReportSuccess(result, response->get<picojson::object>());
+//  };
+//
+//  auto get_response = [this, callback_id](const std::shared_ptr<picojson::value>& response) -> void {
+//    LoggerD("Getting response");
+//    picojson::object& obj = response->get<picojson::object>();
+//    obj.insert(std::make_pair("callbackId", picojson::value(callback_id)));
+//    PostMessage(response->serialize().c_str());
+//  };
+//
+//  TaskQueue::GetInstance().Queue<picojson::value>
+//  (get, get_response, std::shared_ptr<picojson::value>(new picojson::value(picojson::object())));
+}
+
+void SysteminfoManager::AddPropertyValueChangeListener(const picojson::value& args, picojson::object* out) {
+  LoggerD("Enter");
+  // Check type of property for which listener should be registered
+  CHECK_EXIST(args, "property", out)
+  const std::string& property_name = args.get("property").get<std::string>();
+
+  LoggerD("Adding listener for property with id: %s ", property_name.c_str());
+//  PlatformResult ret(ErrorCode::NO_ERROR);
+//  if (property_name == kPropertyIdBattery) {
+//    ret = SysteminfoUtils::RegisterBatteryListener(OnBatteryChangedCallback, *this);
+//  } else if (property_name == kPropertyIdCpu) {
+//    ret = SysteminfoUtils::RegisterCpuListener(OnCpuChangedCallback, *this);
+//  } else if (property_name == kPropertyIdStorage) {
+//    ret = SysteminfoUtils::RegisterStorageListener(OnStorageChangedCallback, *this);
+//  } else if (property_name == kPropertyIdDisplay) {
+//    ret = SysteminfoUtils::RegisterDisplayListener(OnDisplayChangedCallback, *this);
+//  } else if (property_name == kPropertyIdDeviceOrientation) {
+//    ret = SysteminfoUtils::RegisterDeviceOrientationListener(OnDeviceOrientationChangedCallback, *this);
+//  } else if (property_name == kPropertyIdBuild) {
+//    LoggerW("BUILD property's value is a fixed value");
+//    //should be accepted, but no registration is needed
+//    //ret = PlatformResult(ErrorCode::NOT_SUPPORTED_ERR, "BUILD property's value is a fixed value");
+//  } else if (property_name == kPropertyIdLocale) {
+//    ret = SysteminfoUtils::RegisterLocaleListener(OnLocaleChangedCallback, *this);
+//  } else if (property_name == kPropertyIdNetwork) {
+//    ret = SysteminfoUtils::RegisterNetworkListener(OnNetworkChangedCallback, *this);
+//  } else if (property_name == kPropertyIdWifiNetwork) {
+//    ret = SysteminfoUtils::RegisterWifiNetworkListener(OnWifiNetworkChangedCallback, *this);
+//  } else if (property_name == kPropertyIdEthernetNetwork) {
+//    ret = SysteminfoUtils::RegisterEthernetNetworkListener(OnEthernetNetworkChangedCallback, *this);
+//  } else if (property_name == kPropertyIdCellularNetwork) {
+//    ret = SysteminfoUtils::RegisterCellularNetworkListener(OnCellularNetworkChangedCallback, *this);
+//  } else if (property_name == kPropertyIdSim) {
+//    //SIM listeners are not supported by core API, so we just pass over
+//    LoggerW("SIM listener is not supported by Core API - ignoring");
+//  } else if (property_name == kPropertyIdPeripheral) {
+//    ret = SysteminfoUtils::RegisterPeripheralListener(OnPeripheralChangedCallback, *this);
+//  } else if (property_name == kPropertyIdMemory) {
+//    ret = SysteminfoUtils::RegisterMemoryListener(OnMemoryChangedCallback, *this);
+//  } else if (property_name == kPropertyIdCameraFlash) {
+//    ret = SysteminfoUtils::RegisterCameraFlashListener(OnBrigthnessChangedCallback, *this);
+//  } else {
+//    LoggerE("Not supported property");
+//    ret = PlatformResult(ErrorCode::INVALID_VALUES_ERR, "Not supported property");
+//  }
+//  if (ret.IsSuccess()) {
+//    ReportSuccess(out);
+//    LoggerD("Success");
+//    return;
+//  }
+//  LoggerD("Error");
+//  ReportError(ret, &out);
+}
+
+void SysteminfoManager::GetTotalMemory(const picojson::value& args, picojson::object* out) {
+  LoggerD("Enter");
+  picojson::value result = picojson::value(picojson::object());
+  picojson::object& result_obj = result.get<picojson::object>();
+
+  long long return_value = 0;
+//  PlatformResult ret = SysteminfoUtils::GetTotalMemory(return_value);
+//  if (ret.IsError()) {
+//    LoggerD("Error");
+//    ReportError(ret, &out);
+//    return;
+//  }
+//  result_obj.insert(std::make_pair("totalMemory",
+//                                   picojson::value(static_cast<double>(return_value))));
+//
+//  ReportSuccess(result, out);
+//  LoggerD("Success");
+}
+
+void SysteminfoManager::GetAvailableMemory(const picojson::value& args, picojson::object* out) {
+  LoggerD("Enter");
+  picojson::value result = picojson::value(picojson::object());
+  picojson::object& result_obj = result.get<picojson::object>();
+
+  long long return_value = 0;
+//  PlatformResult ret = SysteminfoUtils::GetAvailableMemory(return_value);
+//  if (ret.IsError()) {
+//    LoggerD("Error");
+//    ReportError(ret, &out);
+//    return;
+//  }
+//  result_obj.insert(std::make_pair("availableMemory",
+//                                   picojson::value(static_cast<double>(return_value))));
+//
+//  ReportSuccess(result, out);
+//  LoggerD("Success");
+}
+
+void SysteminfoManager::GetCount(const picojson::value& args, picojson::object* out) {
+
+  LoggerD("Enter");
+  CHECK_EXIST(args, "property", out)
+  const std::string& property = args.get("property").get<std::string>();
+  LoggerD("Getting count of property with id: %s ", property.c_str());
+
+  picojson::value result = picojson::value(picojson::object());
+  picojson::object& result_obj = result.get<picojson::object>();
+  unsigned long count = 0;
+//  PlatformResult ret = SysteminfoUtils::GetCount(property, count);
+//  if (ret.IsError()) {
+//    LoggerE("Failed: GetCount()");
+//    ReportError(ret, &out);
+//    return;
+//  }
+//  result_obj.insert(std::make_pair("count", picojson::value(static_cast<double>(count))));
+//
+//  ReportSuccess(result, out);
+//  LoggerD("Success");
+}
+
+void SysteminfoManager::RemovePropertyValueChangeListener(const picojson::value& args, picojson::object* out) {
+  LoggerD("Enter");
+
+  // Check type of property for which listener should be removed
+  CHECK_EXIST(args, "property", out)
+  const std::string& property_name = args.get("property").get<std::string>();
+  LoggerD("Removing listener for property with id: %s ", property_name.c_str());
+  PlatformResult ret(ErrorCode::NO_ERROR);
+//  if (property_name == kPropertyIdBattery) {
+//    ret = SysteminfoUtils::UnregisterBatteryListener();
+//  } else if (property_name == kPropertyIdCpu) {
+//    ret = SysteminfoUtils::UnregisterCpuListener();
+//  } else if (property_name == kPropertyIdStorage) {
+//    ret = SysteminfoUtils::UnregisterStorageListener();
+//  } else if (property_name == kPropertyIdDisplay) {
+//    ret = SysteminfoUtils::UnregisterDisplayListener();
+//  } else if (property_name == kPropertyIdDeviceOrientation) {
+//    ret = SysteminfoUtils::UnregisterDeviceOrientationListener();
+//  } else if (property_name == kPropertyIdBuild) {
+//    LoggerW("BUILD property's value is a fixed value");
+//    //should be accepted, but no unregistration is needed
+//    //ret = PlatformResult(ErrorCode::NOT_SUPPORTED_ERR, "BUILD property's value is a fixed value");
+//  } else if (property_name == kPropertyIdLocale) {
+//    ret = SysteminfoUtils::UnregisterLocaleListener();
+//  } else if (property_name == kPropertyIdNetwork) {
+//    ret = SysteminfoUtils::UnregisterNetworkListener();
+//  } else if (property_name == kPropertyIdWifiNetwork) {
+//    ret = SysteminfoUtils::UnregisterWifiNetworkListener();
+//  } else if (property_name == kPropertyIdEthernetNetwork) {
+//    ret = SysteminfoUtils::UnregisterEthernetNetworkListener();
+//  } else if (property_name == kPropertyIdCellularNetwork) {
+//    ret = SysteminfoUtils::UnregisterCellularNetworkListener();
+//  } else if (property_name == kPropertyIdSim) {
+//    //SIM listeners are not supported by core API, so we just pass over
+//    LoggerW("SIM listener is not supported by Core API - ignoring");
+//  } else if (property_name == kPropertyIdPeripheral) {
+//    ret = SysteminfoUtils::UnregisterPeripheralListener();
+//  } else if (property_name == kPropertyIdMemory) {
+//    ret = SysteminfoUtils::UnregisterMemoryListener();
+//  } else if (property_name == kPropertyIdCameraFlash) {
+//    ret = SysteminfoUtils::UnregisterCameraFlashListener();
+//  } else {
+//    LoggerE("Not supported property");
+//    ret = PlatformResult(ErrorCode::INVALID_VALUES_ERR, "Not supported property");
+//  }
+//  if (ret.IsSuccess()) {
+//    ReportSuccess(out);
+//    LoggerD("Success");
+//    return;
+//  }
+//  LoggerD("Error");
+//  ReportError(ret, &out);
+}
+
+void SysteminfoManager::SetBrightness(const picojson::value& args, picojson::object* out) {
+  LoggerD("entered");
+
+  CHECK_EXIST(args, "brightness", out)
+
+  const double brightness = args.get("brightness").get<double>();
+//  int result = device_flash_set_brightness(brightness);
+//  if (result != DEVICE_ERROR_NONE) {
+//    LoggerE("Error occured");
+//    ReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Error occured"), &out);
+//    return;
+//  }
+//  ReportSuccess(out);
+}
+
+void SysteminfoManager::GetBrightness(const picojson::value& args, picojson::object* out) {
+  LoggerD("entered");
+
+  int brightness = 0;
+//  int result = device_flash_get_brightness(&brightness);
+//  if (result != DEVICE_ERROR_NONE) {
+//    LoggerE("Error occured");
+//    ReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Error occured"), &out);
+//    return;
+//  }
+//  ReportSuccess(picojson::value(std::to_string(brightness)), out);
+}
+
+void SysteminfoManager::GetMaxBrightness(const picojson::value& args, picojson::object* out) {
+  LoggerD("entered");
+
+  int brightness = 0;
+//  int result = device_flash_get_max_brightness(&brightness);
+//  if (result != DEVICE_ERROR_NONE) {
+//    LoggerE("Error occured");
+//    ReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Not supported property"), &out);
+//    return;
+//  }
+//  ReportSuccess(picojson::value(std::to_string(brightness)), out);
+}
+
+}  // namespace systeminfo
+}  // namespace extension
diff --git a/src/systeminfo/systeminfo_manager.h b/src/systeminfo/systeminfo_manager.h
new file mode 100644 (file)
index 0000000..ad9e6c2
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+#ifndef WEBAPI_PLUGINS_SYSTEMINFO_SYSTEMINFO_MANAGER_H__
+#define WEBAPI_PLUGINS_SYSTEMINFO_SYSTEMINFO_MANAGER_H__
+
+#include "common/picojson.h"
+#include "common/platform_result.h"
+
+namespace extension {
+namespace systeminfo {
+
+class SysteminfoInstance;
+
+class SysteminfoManager {
+ public:
+  SysteminfoManager(SysteminfoInstance& instance);
+  ~SysteminfoManager();
+
+  void GetCapabilities(const picojson::value& args, picojson::object* out);
+  void GetCapability(const picojson::value& args, picojson::object* out);
+  void GetPropertyValue(const picojson::value& args, picojson::object* out);
+  void GetPropertyValueArray(const picojson::value& args, picojson::object* out);
+  void AddPropertyValueChangeListener(const picojson::value& args, picojson::object* out);
+  void RemovePropertyValueChangeListener(const picojson::value& args, picojson::object* out);
+  void GetMaxBrightness(const picojson::value& args, picojson::object* out);
+  void GetBrightness(const picojson::value& args, picojson::object* out);
+  void SetBrightness(const picojson::value& args, picojson::object* out);
+  void GetTotalMemory(const picojson::value& args, picojson::object* out);
+  void GetAvailableMemory(const picojson::value& args, picojson::object* out);
+  void GetCount(const picojson::value& args, picojson::object* out);
+
+ private:
+  SysteminfoInstance& instance_;
+
+};
+} // namespace systeminfo
+} // namespace webapi
+
+#endif // WEBAPI_PLUGINS_SYSTEMINFO_SYSTEMINFO_MANAGER_H__