From: Piotr Kosko Date: Thu, 27 Aug 2015 06:22:32 +0000 (+0200) Subject: [Systeminfo] Changed implementation of getPropertyValue method X-Git-Tag: submit/tizen/20151026.073646^2^2~130^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d6004548756b88287611e534f84af82142c1504b;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [Systeminfo] Changed implementation of getPropertyValue method [Feature] Implementation of getPropertyValue was changed to use new class: SysteminfoPropertiesManager. Module was reorganized. [Verification] Code compiles without errors. Change-Id: I962411adf614f33734c88ed4a9caf47767aa247f Signed-off-by: Piotr Kosko --- diff --git a/src/systeminfo/systeminfo.gyp b/src/systeminfo/systeminfo.gyp index 4564c4a7..a4ffa45d 100644 --- a/src/systeminfo/systeminfo.gyp +++ b/src/systeminfo/systeminfo.gyp @@ -21,6 +21,8 @@ 'systeminfo_manager.h', 'systeminfo_device_capability.cc', 'systeminfo_device_capability.h', + 'systeminfo_properties_manager.cc', + 'systeminfo_properties_manager.h', ], 'includes': [ '../common/pkg-config.gypi', diff --git a/src/systeminfo/systeminfo_instance.cc b/src/systeminfo/systeminfo_instance.cc index 858f1e77..b5a7a62a 100644 --- a/src/systeminfo/systeminfo_instance.cc +++ b/src/systeminfo/systeminfo_instance.cc @@ -117,7 +117,7 @@ const std::string kPropertyIdCameraFlash= "CAMERA_FLASH"; result_obj.insert(std::make_pair(str_name, picojson::value(str_value))); } -SysteminfoInstance::SysteminfoInstance() : manager_(*this) { +SysteminfoInstance::SysteminfoInstance() : manager_(this) { LoggerD("Enter"); using std::placeholders::_1; using std::placeholders::_2; @@ -173,33 +173,7 @@ void SysteminfoInstance::GetCapability(const picojson::value& args, picojson::ob void SysteminfoInstance::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(); - const std::string& prop_id = args.get("property").get(); - LoggerD("Getting property with id: %s ", prop_id.c_str()); - - auto get = [this, prop_id, callback_id](const std::shared_ptr& 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())); - return; - } - ReportSuccess(result, response->get()); - }; - - auto get_response = [this, callback_id](const std::shared_ptr& response) -> void { - LoggerD("Getting response"); - picojson::object& obj = response->get(); - obj.insert(std::make_pair("callbackId", picojson::value{static_cast(callback_id)})); - LoggerD("message: %s", response->serialize().c_str()); - Instance::PostMessage(this, response->serialize().c_str()); - }; - - TaskQueue::GetInstance().Queue - (get, get_response, std::shared_ptr(new picojson::value(picojson::object()))); + manager_.GetPropertyValue(args, &out); } void SysteminfoInstance::GetPropertyValueArray(const picojson::value& args, picojson::object& out) { diff --git a/src/systeminfo/systeminfo_manager.cc b/src/systeminfo/systeminfo_manager.cc index 1c9c5ed6..020fa125 100644 --- a/src/systeminfo/systeminfo_manager.cc +++ b/src/systeminfo/systeminfo_manager.cc @@ -16,16 +16,22 @@ #include "systeminfo/systeminfo_manager.h" +#include +#include + #include "systeminfo/systeminfo_instance.h" #include "systeminfo/systeminfo_device_capability.h" #include "common/logger.h" #include "common/converter.h" +#include "common/task-queue.h" using common::PlatformResult; using common::ErrorCode; using common::TypeMismatchException; using common::tools::ReportError; using common::tools::ReportSuccess; +using common::Instance; +using common::TaskQueue; namespace extension { namespace systeminfo { @@ -79,7 +85,7 @@ namespace { } //namespace -SysteminfoManager::SysteminfoManager(SysteminfoInstance& instance) +SysteminfoManager::SysteminfoManager(SysteminfoInstance* instance) : instance_(instance){ } @@ -196,27 +202,27 @@ void SysteminfoManager::GetPropertyValue(const picojson::value& args, picojson:: const std::string& prop_id = args.get("property").get(); LoggerD("Getting property with id: %s ", prop_id.c_str()); -// auto get = [this, prop_id, callback_id](const std::shared_ptr& 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())); -// return; -// } -// ReportSuccess(result, response->get()); -// }; -// -// auto get_response = [this, callback_id](const std::shared_ptr& response) -> void { -// LoggerD("Getting response"); -// picojson::object& obj = response->get(); -// obj.insert(std::make_pair("callbackId", picojson::value{static_cast(callback_id)})); -// LoggerD("message: %s", response->serialize().c_str()); -// PostMessage(response->serialize().c_str()); -// }; -// -// TaskQueue::GetInstance().Queue -// (get, get_response, std::shared_ptr(new picojson::value(picojson::object()))); + auto get = [this, prop_id, callback_id](const std::shared_ptr& response) -> void { + LoggerD("Getting"); + picojson::value result = picojson::value(picojson::object()); + PlatformResult ret = prop_manager_.GetPropertyValue(prop_id, false, &result); + if (ret.IsError()) { + ReportError(ret,&(response->get())); + return; + } + ReportSuccess(result, response->get()); + }; + + auto get_response = [this, callback_id](const std::shared_ptr& response) -> void { + LoggerD("Getting response"); + picojson::object& obj = response->get(); + obj.insert(std::make_pair("callbackId", picojson::value{static_cast(callback_id)})); + LoggerD("message: %s", response->serialize().c_str()); + Instance::PostMessage(instance_, response->serialize().c_str()); + }; + + TaskQueue::GetInstance().Queue + (get, get_response, std::shared_ptr(new picojson::value(picojson::object()))); } void SysteminfoManager::GetPropertyValueArray(const picojson::value& args, picojson::object* out) { diff --git a/src/systeminfo/systeminfo_manager.h b/src/systeminfo/systeminfo_manager.h index ad9e6c20..a7b721b3 100644 --- a/src/systeminfo/systeminfo_manager.h +++ b/src/systeminfo/systeminfo_manager.h @@ -19,6 +19,7 @@ #include "common/picojson.h" #include "common/platform_result.h" +#include "systeminfo/systeminfo_properties_manager.h" namespace extension { namespace systeminfo { @@ -27,7 +28,7 @@ class SysteminfoInstance; class SysteminfoManager { public: - SysteminfoManager(SysteminfoInstance& instance); + SysteminfoManager(SysteminfoInstance* instance); ~SysteminfoManager(); void GetCapabilities(const picojson::value& args, picojson::object* out); @@ -44,7 +45,8 @@ class SysteminfoManager { void GetCount(const picojson::value& args, picojson::object* out); private: - SysteminfoInstance& instance_; + SysteminfoInstance* instance_; + SystemInfoPropertiesManager prop_manager_; }; } // namespace systeminfo diff --git a/src/systeminfo/systeminfo_properties_manager.cc b/src/systeminfo/systeminfo_properties_manager.cc new file mode 100644 index 00000000..05979407 --- /dev/null +++ b/src/systeminfo/systeminfo_properties_manager.cc @@ -0,0 +1,1169 @@ +/* + * 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_properties_manager.h" + +#include +#include + +namespace extension { +namespace systeminfo { + +using common::PlatformResult; +using common::ErrorCode; + +namespace { +const std::string kPropertyIdCpu = "CPU"; +//Battery +const double kRemainingBatteryChargeMax = 100.0; +const int kVconfErrorNone = 0; +//Display +const double kDisplayBrightnessDivideValue = 100; +//Device Orientation +const std::string kOrientationPortraitPrimary = "PORTRAIT_PRIMARY"; +const std::string kOrientationPortraitSecondary = "PORTRAIT_SECONDARY"; +const std::string kOrientationLandscapePrimary = "LANDSCAPE_PRIMARY"; +const std::string kOrientationLandscapeSecondary = "LANDSCAPE_SECONDARY"; +//Peripheral +const std::string kVideoOutputString = "isVideoOutputOn"; +//Storage +const char* kStorageInternalPath = "/opt/usr/media"; +const char* kStorageSdcardPath = "/opt/storage/sdcard"; +const std::string kPropertyIdStorage = "STORAGE"; +const std::string kTypeUnknown = "UNKNOWN"; +const std::string kTypeInternal = "INTERNAL"; +const std::string kTypeUsbHost = "USB_HOST"; +const std::string kTypeMmc = "MMC"; +const double kPropertyWatcherTime = 1; +//Network +enum NetworkType { + kNone, + kType2G, + kType2_5G, + kType3G, + kType4G, + kWifi, + kEthernet, + kUnknown +}; + +const char* kNetworkTypeNone = "NONE"; +const char* kNetworkType2G = "2G"; +const char* kNetworkType2_5G = "2.5G"; +const char* kNetworkType3G = "3G"; +const char* kNetworkType4G = "4G"; +const char* kNetworkTypeWifi = "WIFI"; +const char* kNetworkTypeEthernet = "ETHERNET"; +const char* kNetworkTypeUnknown = "UNKNOWN"; +//Wifi Network +const std::string kWifiStatusOn = "ON"; +const std::string kWifiStatusOff = "OFF"; +const int kWifiSignalStrengthDivideValue = 100; +//Cellular Network +const unsigned short kMccDivider = 100; +const char* kConnectionOff = "OFF"; +const char* kConnectionOn = "ON"; +//Sim +const char* kSimStatusAbsent = "ABSENT"; +const char* kSimStatusInitializing = "INITIALIZING"; +const char* kSimStatusReady = "READY"; +const char* kSimStatusPinRequired = "PIN_REQUIRED"; +const char* kSimStatusPukRequired = "PUK_REQUIRED"; +const char* kSimStatusSimLocked = "SIM_LOCKED"; +const char* kSimStatusNetworkLocked = "NETWORK_LOCKED"; +const char* kSimStatusUnknown = "UNKNOWN"; +} + +SystemInfoPropertiesManager::SystemInfoPropertiesManager() { + LoggerD("Entered"); +} + +SystemInfoPropertiesManager::~SystemInfoPropertiesManager() { + LoggerD("Entered"); +} + +PlatformResult SystemInfoPropertiesManager::GetPropertyValue(const std::string& property, bool is_array_type, + picojson::value* res) { + LoggerD("Entered getPropertyValue"); + + if (!is_array_type) { + picojson::object& res_obj = res->get(); + return ReportProperty(property, 0, &res_obj); + } else { + picojson::object& array_result_obj = res->get(); + picojson::array& array = array_result_obj.insert( + std::make_pair("array", picojson::value(picojson::array()))). + first->second.get(); + + unsigned long property_count = 0; + PlatformResult ret(ErrorCode::NO_ERROR); +// PlatformResult ret = SysteminfoUtils::GetCount(property, property_count); +// if (ret.IsError()){ +// return ret; +// } + + LoggerD("property name: %s", property.c_str()); +// LoggerD("available property count: %d", property_count); +// for (size_t i = 0; i < property_count; i++) { + size_t i = 0; + picojson::value result = picojson::value(picojson::object()); + picojson::object& result_obj = result.get(); + + ret = ReportProperty(property, i, &result_obj); + if (ret.IsError()){ + return ret; + } + array.push_back(result); +// } +// if (property_count == 0) { +// return PlatformResult(ErrorCode::NOT_SUPPORTED_ERR, "Property with given id is not supported"); +// } + } + + return PlatformResult(ErrorCode::NO_ERROR); +} + +PlatformResult SystemInfoPropertiesManager::ReportProperty(const std::string& property, int index, + picojson::object* res_obj) { + LoggerD("Entered"); + if ("BATTERY" == property){ + return ReportBattery(res_obj); + } else if ("CPU" == property) { +// return ReportCpu(res_obj); + } else if ("STORAGE" == property) { +// return ReportStorage(res_obj); + } else if ("DISPLAY" == property) { +// return ReportDisplay(res_obj); + } else if ("DEVICE_ORIENTATION" == property) { +// return ReportDeviceOrientation(res_obj); + } else if ("BUILD" == property) { +// return ReportBuild(res_obj); + } else if ("LOCALE" == property) { +// return ReportLocale(res_obj); + } else if ("NETWORK" == property) { +// return ReportNetwork(res_obj); + } else if ("WIFI_NETWORK" == property) { +// return ReportWifiNetwork(res_obj); + } else if ("ETHERNET_NETWORK" == property) { +// return ReportEthernetNetwork(res_obj); + } else if ("CELLULAR_NETWORK" == property) { +// return ReportCellularNetwork(res_obj, index); + } else if ("SIM" == property) { +// return ReportSim(res_obj, index); + } else if ("PERIPHERAL" == property) { +// return ReportPeripheral(res_obj); + } else if ("MEMORY" == property) { +// return ReportMemory(res_obj); + } else if ("CAMERA_FLASH" == property) { +// return ReportCameraFlash(res_obj); + } + LoggerD("Property with given id is not supported"); + return PlatformResult(ErrorCode::NOT_SUPPORTED_ERR, "Property with given id is not supported"); +} + +PlatformResult SystemInfoPropertiesManager::ReportBattery(picojson::object* out) { + int value = 0; + int ret = vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CAPACITY, &value); + if (kVconfErrorNone != ret) { + std::string log_msg = "Platform error while getting battery detail: "; + LoggerE("%s%d", log_msg.c_str(), ret); + return PlatformResult(ErrorCode::UNKNOWN_ERR, (log_msg + std::to_string(ret))); + } + + out->insert(std::make_pair("level", picojson::value(static_cast(value)/kRemainingBatteryChargeMax))); + value = 0; + ret = vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, &value); + if (kVconfErrorNone != ret) { + std::string log_msg = "Platform error while getting battery charging: "; + LoggerE("%s%d",log_msg.c_str(), ret); + return PlatformResult(ErrorCode::UNKNOWN_ERR, (log_msg + std::to_string(ret))); + } + out->insert(std::make_pair("isCharging", picojson::value(0 != value))); + return PlatformResult(ErrorCode::NO_ERROR); +} +//TODO maybe make two functions later onGSourceFunc +//PlatformResult SystemInfoPropertiesManager::ReportCpu(picojson::object* out) { +// LoggerD("Entered"); +// static CpuInfo cpu_info; +// FILE *fp = nullptr; +// fp = fopen("/proc/stat", "r"); +// if (nullptr == fp) { +// std::string error_msg("Can not open /proc/stat for reading"); +// LoggerE( "%s", error_msg.c_str() ); +// return PlatformResult(ErrorCode::UNKNOWN_ERR, error_msg); +// } +// +// long long usr = 0; +// long long system = 0; +// long long nice = 0; +// long long idle = 0; +// double load = 0; +// +// int read_ret = fscanf( fp, "%*s %lld %lld %lld %lld", &usr, &system, &nice, &idle); +// fclose(fp); +// +// if (4 == read_ret) { +// long long total = usr + nice + system + idle - cpu_info.usr - cpu_info.nice - +// cpu_info.system - cpu_info.idle; +// long long diff_idle = idle - cpu_info.idle; +// if (( total > 0LL ) && ( diff_idle > 0LL )) { +// load = static_cast< double >( diff_idle ) * 100LL / total; +// cpu_info.usr = usr; +// cpu_info.system = system; +// cpu_info.nice = nice; +// cpu_info.idle = idle; +// cpu_info.load = load; +// } else { +// LoggerW("Cannot calculate cpu load, previous value returned"); +// load = cpu_info.load; +// } +// } else { +// std::string error_msg( "Could not read /proc/stat" ); +// LoggerE( "%s", error_msg.c_str() ); +// return PlatformResult(ErrorCode::UNKNOWN_ERR, error_msg); +// } +// +// system_info_listeners.SetCpuInfoLoad(cpu_info.load); +// +// load = 100 - load; +// LoggerD("Cpu load : %f", load ); +// out.insert(std::make_pair("load", picojson::value(load / 100.0))); +// return PlatformResult(ErrorCode::NO_ERROR); +//} +// +//PlatformResult SystemInfoPropertiesManager::ReportDisplay(picojson::object* out) { +// int screenWidth = 0; +// int screenHeight = 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_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_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"); +// } +// +// //FETCH DOTS PER INCH +// int dots_per_inch=0; +// if (SYSTEM_INFO_ERROR_NONE == system_info_get_platform_int( +// "tizen.org/feature/screen.dpi", &dots_per_inch)) { +// dotsPerInchWidth = dots_per_inch; +// dotsPerInchHeight = dots_per_inch; +// } else { +// LoggerE("Cannot get 'tizen.org/feature/screen.dpi' value"); +// return PlatformResult(ErrorCode::UNKNOWN_ERR, +// "Cannot get 'tizen.org/feature/screen.dpi' value"); +// } +// +// //FETCH PHYSICAL WIDTH +// if (dotsPerInchWidth != 0 && screenWidth != 0) { +// 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(), +// screenWidth, dotsPerInchWidth); +// } +// +// //FETCH PHYSICAL HEIGHT +// if (dotsPerInchHeight != 0 && screenHeight != 0) { +// 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(), +// screenHeight, dotsPerInchHeight); +// } +// +// //FETCH BRIGHTNESS +// int brightness; +// if (kVconfErrorNone == vconf_get_int(VCONFKEY_SETAPPL_LCD_BRIGHTNESS, &brightness)) { +// scaledBrightness = static_cast(brightness)/kDisplayBrightnessDivideValue; +// } else { +// LoggerE("Cannot get brightness value of display"); +// return PlatformResult(ErrorCode::UNKNOWN_ERR, "Cannot get brightness value of display"); +// } +// +// out.insert(std::make_pair("resolutionWidth", picojson::value(std::to_string(screenWidth)))); +// out.insert(std::make_pair("resolutionHeight", picojson::value(std::to_string(screenHeight)))); +// out.insert(std::make_pair("dotsPerInchWidth", picojson::value(std::to_string(dotsPerInchWidth)))); +// out.insert(std::make_pair("dotsPerInchHeight", picojson::value(std::to_string(dotsPerInchHeight)))); +// out.insert(std::make_pair("physicalWidth", picojson::value(std::to_string(physicalWidth)))); +// out.insert(std::make_pair("physicalHeight", picojson::value(std::to_string(physicalHeight)))); +// out.insert(std::make_pair("brightness", picojson::value(scaledBrightness))); +// return PlatformResult(ErrorCode::NO_ERROR); +//} +// +//static PlatformResult FetchIsAutoRotation(bool* result) +//{ +// LoggerD("Entered"); +// int is_auto_rotation = 0; +// +// if ( 0 == vconf_get_bool( +// VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, &is_auto_rotation)) { +// if (is_auto_rotation) { +// *result = true; +// } else { +// *result = false; +// } +// return PlatformResult(ErrorCode::NO_ERROR); +// } +// else { +// LoggerE("VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL check failed"); +// return PlatformResult(ErrorCode::UNKNOWN_ERR, +// "VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL check failed"); +// } +//} +// +//static PlatformResult FetchStatus(std::string* result) +//{ +// LoggerD("Entered"); +// int rotation = 0; +// std::string status = kOrientationPortraitPrimary; +// +// sensor_data_t data; +// bool ret = sensord_get_data(system_info_listeners.GetSensorHandle(), +// AUTO_ROTATION_BASE_DATA_SET, &data); +// if (ret) { +// LoggerD("size of the data value array:%d", data.value_count); +// if (data.value_count > 0 ) { +// rotation = data.values[0]; +// LoggerD("rotation is: %d", rotation); +// } else { +// LoggerE("Failed to get data : the size of array is 0. Default rotation would be returned."); +// } +// } else { +// LoggerE("Failed to get data(sensord_get_data). Default rotation would be returned."); +// } +// +// +// switch (rotation) { +// case AUTO_ROTATION_DEGREE_UNKNOWN: +// case AUTO_ROTATION_DEGREE_0: +// LoggerD("AUTO_ROTATION_DEGREE_0"); +// status = kOrientationPortraitPrimary; +// break; +// case AUTO_ROTATION_DEGREE_90: +// LoggerD("AUTO_ROTATION_DEGREE_90"); +// status = kOrientationLandscapePrimary; +// break; +// case AUTO_ROTATION_DEGREE_180: +// LoggerD("AUTO_ROTATION_DEGREE_180"); +// status = kOrientationPortraitSecondary; +// break; +// case AUTO_ROTATION_DEGREE_270: +// LoggerD("AUTO_ROTATION_DEGREE_270"); +// status = kOrientationLandscapeSecondary; +// break; +// default: +// LoggerE("Received unexpected data: %u", rotation); +// return PlatformResult(ErrorCode::UNKNOWN_ERR, "Received unexpected data"); +// } +// *result = status; +// return PlatformResult(ErrorCode::NO_ERROR); +//} + +//PlatformResult SystemInfoPropertiesManager::ReportDeviceOrientation(picojson::object* out) { +// bool is_auto_rotation = false; +// std::string status = ""; +// +// PlatformResult ret = FetchIsAutoRotation(&is_auto_rotation); +// if (ret.IsError()) return ret; +// +// ret = FetchStatus(&status); +// if (ret.IsError()) return ret; +// +// out.insert(std::make_pair("isAutoRotation", picojson::value(is_auto_rotation))); +// out.insert(std::make_pair("status", picojson::value(status))); +// return PlatformResult(ErrorCode::NO_ERROR); +//} +// +//PlatformResult SystemInfoPropertiesManager::ReportBuild(picojson::object* out) { +// std::string model = ""; +// PlatformResult ret = SystemInfoDeviceCapability::GetValueString( +// "tizen.org/system/model_name", &model); +// if (ret.IsError()) { +// return ret; +// } +// std::string manufacturer = ""; +// ret = SystemInfoDeviceCapability::GetValueString( +// "tizen.org/system/manufacturer", &manufacturer); +// if (ret.IsError()) { +// return ret; +// } +// std::string buildVersion = ""; +// ret = SystemInfoDeviceCapability::GetValueString( +// "tizen.org/system/build.string", &buildVersion); +// if (ret.IsError()) { +// return ret; +// } +// +// out.insert(std::make_pair("model", picojson::value(model))); +// out.insert(std::make_pair("manufacturer", picojson::value(manufacturer))); +// out.insert(std::make_pair("buildVersion", picojson::value(buildVersion))); +// return PlatformResult(ErrorCode::NO_ERROR); +//} +// +//PlatformResult SystemInfoPropertiesManager::ReportLocale(picojson::object* out) { +// std::string str_language = ""; +// PlatformResult ret = GetRuntimeInfoString(SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, str_language); +// if (ret.IsError()) { +// return ret; +// } +// +// std::string str_country = ""; +// ret = GetRuntimeInfoString(SYSTEM_SETTINGS_KEY_LOCALE_COUNTRY, str_country); +// if (ret.IsError()) { +// return ret; +// } +// +// out.insert(std::make_pair("language", picojson::value(str_language))); +// out.insert(std::make_pair("country", picojson::value(str_country))); +// return PlatformResult(ErrorCode::NO_ERROR); +//} +// +//static PlatformResult GetNetworkTypeString(NetworkType type, std::string& type_string) +//{ +// switch (type) { +// case kNone: +// type_string = kNetworkTypeNone; +// break; +// case kType2G: +// type_string = kNetworkType2G; +// break; +// case kType2_5G: +// type_string = kNetworkType2_5G; +// break; +// case kType3G: +// type_string = kNetworkType3G; +// break; +// case kType4G: +// type_string = kNetworkType4G; +// break; +// case kWifi: +// type_string = kNetworkTypeWifi; +// break; +// case kEthernet: +// type_string = kNetworkTypeEthernet; +// break; +// case kUnknown: +// type_string = kNetworkTypeUnknown; +// break; +// default: +// LoggerE("Incorrect type: %d", type); +// return PlatformResult(ErrorCode::TYPE_MISMATCH_ERR, "Incorrect type"); +// } +// return PlatformResult(ErrorCode::NO_ERROR); +//} +// +//PlatformResult SystemInfoPropertiesManager::ReportNetwork(picojson::object* out) { +// connection_h connection_handle = nullptr; +// connection_type_e connection_type = CONNECTION_TYPE_DISCONNECTED; +// int networkType = 0; +// NetworkType type = kNone; +// +// //connection must be created in every call, in other case error occurs +// int error = connection_create(&connection_handle); +// if (CONNECTION_ERROR_NONE != error) { +// std::string log_msg = "Cannot create connection: " + std::to_string(error); +// LoggerE("%s", log_msg.c_str()); +// return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg); +// } +// std::unique_ptr::type, int(*)(connection_h)> +// connection_handle_ptr(connection_handle, &connection_destroy); +// // automatically release the memory +// +// error = connection_get_type(connection_handle, &connection_type); +// if (CONNECTION_ERROR_NONE != error) { +// std::string log_msg = "Cannot get connection type: " + std::to_string(error); +// LoggerE("%s", log_msg.c_str()); +// return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg); +// } +// +// switch (connection_type) { +// case CONNECTION_TYPE_DISCONNECTED : +// type = kNone; +// break; +// case CONNECTION_TYPE_WIFI : +// type = kWifi; +// break; +// case CONNECTION_TYPE_CELLULAR : +// if (vconf_get_int(VCONFKEY_TELEPHONY_SVCTYPE, &networkType) == 0) { +// if (networkType < VCONFKEY_TELEPHONY_SVCTYPE_2G) { +// type = kNone; +// } else if (networkType == VCONFKEY_TELEPHONY_SVCTYPE_2G) { +// type = kType2G; +// } else if (networkType == VCONFKEY_TELEPHONY_SVCTYPE_2G +// || networkType == VCONFKEY_TELEPHONY_SVCTYPE_2_5G_EDGE) { +// type = kType2_5G; +// } else if (networkType == VCONFKEY_TELEPHONY_SVCTYPE_3G +// || networkType == VCONFKEY_TELEPHONY_SVCTYPE_HSDPA) { +// type = kType3G; +// } else if (networkType == VCONFKEY_TELEPHONY_SVCTYPE_LTE) { +// type = kType4G; +// } else { +// type = kNone; +// } +// } +// break; +// case CONNECTION_TYPE_ETHERNET : +// type = kEthernet; +// break; +// default: +// LoggerE("Incorrect type: %d", connection_type); +// return PlatformResult(ErrorCode::UNKNOWN_ERR, "Incorrect type"); +// } +// std::string type_str = ""; +// PlatformResult ret = GetNetworkTypeString(type, type_str); +// if(ret.IsError()) { +// return ret; +// } +// out.insert(std::make_pair("networkType", picojson::value(type_str))); +// return PlatformResult(ErrorCode::NO_ERROR); +//} +// +//static PlatformResult GetIps(wifi_ap_h wifi_ap_handle, std::string* ip_addr_str, +// std::string* ipv6_addr_str){ +// //getting ipv4 address +// char* ip_addr = nullptr; +// int error = wifi_ap_get_ip_address(wifi_ap_handle, +// WIFI_ADDRESS_FAMILY_IPV4, +// &ip_addr); +// if (WIFI_ERROR_NONE != error) { +// LoggerE("Failed to get ip address: %d", error); +// return PlatformResult(ErrorCode::UNKNOWN_ERR, "Cannot get ip address"); +// } +// *ip_addr_str = ip_addr; +// free(ip_addr); +// +// //getting ipv6 address +// ip_addr = nullptr; +// error = wifi_ap_get_ip_address(wifi_ap_handle, +// WIFI_ADDRESS_FAMILY_IPV6, +// &ip_addr); +// if (WIFI_ERROR_NONE != error) { +// LoggerE("Failed to get ipv6 address: %d", error); +// return PlatformResult(ErrorCode::UNKNOWN_ERR, "Cannot get ipv6 address"); +// } +// *ipv6_addr_str = ip_addr; +// free(ip_addr); +// return PlatformResult(ErrorCode::NO_ERROR); +//} +// +//PlatformResult SystemInfoPropertiesManager::ReportWifiNetwork(picojson::object* out) { +// LoggerD("Entered"); +// +// bool result_status = false; +// std::string result_ssid; +// std::string result_ip_address; +// std::string result_ipv6_address; +// std::string result_mac_address; +// double result_signal_strength = 0; +// +// // wifi_initialize() must be called in each thread +// int error = wifi_initialize(); +// if (WIFI_ERROR_NONE != error) { +// std::string log_msg = "Initialize failed: " + parseWifiNetworkError(error); +// LoggerE("%s", log_msg.c_str()); +// return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg); +// } else { +// LoggerD("WIFI initializatino succeed"); +// } +// SCOPE_EXIT { +// wifi_deinitialize(); +// }; +// +// wifi_ap_h wifi_ap_handle = nullptr; +// error = wifi_get_connected_ap(&wifi_ap_handle); +// if (WIFI_ERROR_NONE != error) { +// LoggerD("Error while wifi_get_connnected_ap: %s", parseWifiNetworkError(error).c_str()); +// // in case of no connection, ignore error and leave status as false +// if (WIFI_ERROR_NO_CONNECTION != error) { +// std::string log_msg = "Cannot get connected access point handle: " + parseWifiNetworkError(error); +// LoggerE("%s", log_msg.c_str()); +// return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg); +// } +// } else { +// //if getting connected AP succeed, set status on true +// result_status = true; +// } +// +// if (result_status) { +// std::unique_ptr::type, int(*)(wifi_ap_h)> +// wifi_ap_handle_ptr(wifi_ap_handle, &wifi_ap_destroy); +// // automatically release the memory +// +// //gathering mac address +// char* mac = nullptr; +// error = wifi_get_mac_address(&mac); +// if (WIFI_ERROR_NONE == error && nullptr != mac) { +// SLoggerD("MAC address fetched: %s", mac); +// result_mac_address = mac; +// free(mac); +// } else { +// std::string log_msg = "Failed to get mac address: " + parseWifiNetworkError(error); +// LoggerE("%s", log_msg.c_str()); +// return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg); +// } +// +// //refreshing access point information +// error = wifi_ap_refresh(wifi_ap_handle); +// if (WIFI_ERROR_NONE != error) { +// std::string log_msg = "Failed to refresh access point information: " + parseWifiNetworkError(error); +// LoggerE("%s", log_msg.c_str()); +// return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg); +// } +// +// //gathering ssid +// char* essid = nullptr; +// error = wifi_ap_get_essid(wifi_ap_handle, &essid); +// if (WIFI_ERROR_NONE == error) { +// result_ssid = essid; +// free(essid); +// } else { +// std::string log_msg = "Failed to get network ssid: " + parseWifiNetworkError(error); +// LoggerE("%s", log_msg.c_str()); +// return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg); +// } +// +// //gathering ips +// PlatformResult ret = GetIps(wifi_ap_handle, &result_ip_address, &result_ipv6_address); +// if (ret.IsError()) { +// return ret; +// } +// +// //gathering strength +// wifi_rssi_level_e rssi_level = system_info_listeners.GetWifiLevel(); +// // this mean that level was not initialized or wifi not connected +// if (WIFI_RSSI_LEVEL_0 == rssi_level) { +// // so try to gather rssi level with dedicated function +// int rssi = 0; +// error = wifi_ap_get_rssi(wifi_ap_handle, &rssi); +// if (WIFI_ERROR_NONE == error) { +// result_signal_strength = ((double) abs(rssi))/kWifiSignalStrengthDivideValue; +// } else { +// std::string log_msg = "Failed to get signal strength: " + parseWifiNetworkError(error); +// LoggerE("%s", log_msg.c_str()); +// return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg); +// } +// } else { +// result_signal_strength = ((double) rssi_level)/WIFI_RSSI_LEVEL_4; +// } +// } +// //building result object +// out.insert(std::make_pair("status", picojson::value(result_status ? kWifiStatusOn : kWifiStatusOff))); +// out.insert(std::make_pair("ssid", picojson::value(result_ssid))); +// out.insert(std::make_pair("ipAddress", picojson::value(result_ip_address))); +// out.insert(std::make_pair("ipv6Address", picojson::value(result_ipv6_address))); +// out.insert(std::make_pair("macAddress", picojson::value(result_mac_address))); +// out.insert(std::make_pair("signalStrength", picojson::value(std::to_string(result_signal_strength)))); +// +// return PlatformResult(ErrorCode::NO_ERROR); +//} +// +//PlatformResult SystemInfoPropertiesManager::ReportEthernetNetwork(picojson::object* out) { +// LoggerD("Entered"); +// +// std::string result_cable; +// std::string result_status; +// std::string result_ip_address; +// std::string result_ipv6_address; +// std::string result_mac_address; +// +// connection_h connection_handle = nullptr; +// connection_ethernet_state_e connection_state = CONNECTION_ETHERNET_STATE_DEACTIVATED; +// connection_type_e connection_type = CONNECTION_TYPE_DISCONNECTED; +// connection_profile_h profile_handle = nullptr; +// +// // connection must be created in every call, in other case error occurs +// int error = connection_create(&connection_handle); +// if (CONNECTION_ERROR_NONE != error) { +// std::string log_msg = "Cannot create connection: " + std::to_string(error); +// LoggerE("%s", log_msg.c_str()); +// return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg); +// } +// std::unique_ptr::type, int (*)(connection_h)> connection_handle_ptr( +// connection_handle, &connection_destroy); // automatically release the memory +// +// error = connection_get_ethernet_state(connection_handle, &connection_state); +// if (CONNECTION_ERROR_NONE != error) { +// if (CONNECTION_ERROR_NOT_SUPPORTED == error) { +// std::string log_msg = "Cannot get ethernet connection state: Not supported"; +// LoggerE("%s", log_msg.c_str()); +// return PlatformResult(ErrorCode::NOT_SUPPORTED_ERR, log_msg); +// } +// std::string log_msg = "Cannot get ethernet connection state: " + std::to_string(error); +// LoggerE("%s", log_msg.c_str()); +// return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg); +// } +// +// switch (connection_state) { +// case CONNECTION_ETHERNET_STATE_DEACTIVATED: +// result_status = "DEACTIVATED"; +// break; +// +// case CONNECTION_ETHERNET_STATE_DISCONNECTED: +// result_status = "DISCONNECTED"; +// break; +// +// case CONNECTION_ETHERNET_STATE_CONNECTED: +// result_status = "CONNECTED"; +// break; +// +// default: +// result_status = "UNKNOWN"; +// break; +// } +// +// connection_ethernet_cable_state_e cable_state = CONNECTION_ETHERNET_CABLE_DETACHED; +// error = connection_get_ethernet_cable_state(connection_handle, &cable_state); +// if (CONNECTION_ERROR_NONE != error) { +// std::string log_msg = "Cannot get ethernet cable state: " + std::to_string(error); +// LoggerE("%s", log_msg.c_str()); +// return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg); +// } +// +// switch (cable_state) { +// case CONNECTION_ETHERNET_CABLE_DETACHED: +// result_cable = "DETACHED"; +// break; +// +// case CONNECTION_ETHERNET_CABLE_ATTACHED: +// result_cable = "ATTACHED"; +// break; +// +// default: +// result_cable = "UNKNOWN"; +// break; +// } +// +// char* mac = nullptr; +// error = connection_get_mac_address(connection_handle, CONNECTION_TYPE_ETHERNET, &mac); +// if (CONNECTION_ERROR_NONE == error && nullptr != mac) { +// SLoggerD("MAC address fetched: %s", mac); +// result_mac_address = mac; +// free(mac); +// } else { +// std::string log_msg = "Failed to get mac address: " + std::to_string(error); +// LoggerE("%s", log_msg.c_str()); +// return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg); +// } +// +// error = connection_get_type(connection_handle, &connection_type); +// if (CONNECTION_ERROR_NONE != error) { +// std::string log_msg = "Cannot get connection type: " + std::to_string(error); +// LoggerE("%s", log_msg.c_str()); +// return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg); +// } +// +// if (CONNECTION_TYPE_ETHERNET == connection_type) { +// //gathering profile +// error = connection_get_current_profile(connection_handle, &profile_handle); +// if (CONNECTION_ERROR_NONE != error) { +// std::string log_msg = "Cannot get connection profile: " + std::to_string(error); +// LoggerE("%s", log_msg.c_str()); +// return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg); +// } +// std::unique_ptr::type, +// int (*)(connection_profile_h)> profile_handle_ptr( +// profile_handle, &connection_profile_destroy); // automatically release the memory +// +// //gathering ips +// PlatformResult ret = GetIps(profile_handle, &result_ip_address, &result_ipv6_address); +// if (ret.IsError()) { +// return ret; +// } +// } else { +// LoggerD("Connection type = %d. ETHERNET is disabled", connection_type); +// } +// +// out.insert(std::make_pair("cable", picojson::value(result_cable))); +// out.insert(std::make_pair("status", picojson::value(result_status))); +// out.insert(std::make_pair("ipAddress", picojson::value(result_ip_address))); +// out.insert(std::make_pair("ipv6Address", picojson::value(result_ipv6_address))); +// out.insert(std::make_pair("macAddress", picojson::value(result_mac_address))); +// +// return PlatformResult(ErrorCode::NO_ERROR); +//} +// +//static PlatformResult FetchBasicSimProperties(TapiHandle *tapi_handle, +// unsigned short *result_mcc, +// unsigned short *result_mnc, +// unsigned short *result_cell_id, +// unsigned short *result_lac, +// bool *result_is_roaming, +// bool *result_is_flight_mode) +//{ +// LoggerD("Entered"); +// int result_value = 0; +// int tapi_res = TAPI_API_SUCCESS; +// tapi_res = tel_get_property_int(tapi_handle, TAPI_PROP_NETWORK_PLMN, &result_value); +// if (TAPI_API_SUCCESS != tapi_res) { +// std::string error_msg = "Cannot get mcc value, error: " + std::to_string(tapi_res); +// LoggerE("%s", error_msg.c_str()); +// return PlatformResult(ErrorCode::UNKNOWN_ERR, error_msg); +// } +// *result_mcc = static_cast(result_value) / kMccDivider; +// *result_mnc = static_cast(result_value) % kMccDivider; +// +// tapi_res = tel_get_property_int(tapi_handle, TAPI_PROP_NETWORK_CELLID, &result_value); +// if (TAPI_API_SUCCESS != tapi_res) { +// std::string error_msg = "Cannot get cell_id value, error: " + std::to_string(tapi_res); +// LoggerE("%s", error_msg.c_str()); +// return PlatformResult(ErrorCode::UNKNOWN_ERR, error_msg); +// } +// *result_cell_id = static_cast(result_value); +// +// tapi_res = tel_get_property_int(tapi_handle, TAPI_PROP_NETWORK_LAC, &result_value); +// if (TAPI_API_SUCCESS != tapi_res) { +// std::string error_msg = "Cannot get lac value, error: " + std::to_string(tapi_res); +// LoggerE("%s", error_msg.c_str()); +// return PlatformResult(ErrorCode::UNKNOWN_ERR, error_msg); +// } +// *result_lac = static_cast(result_value); +// +// tapi_res = tel_get_property_int(tapi_handle, TAPI_PROP_NETWORK_ROAMING_STATUS, &result_value); +// if (TAPI_API_SUCCESS != tapi_res) { +// std::string error_msg = "Cannot get is_roaming value, error: " + std::to_string(tapi_res); +// LoggerE("%s", error_msg.c_str()); +// return PlatformResult(ErrorCode::UNKNOWN_ERR, error_msg); +// } +// *result_is_roaming = (0 != result_value) ? true : false; +// +// if (0 != vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &result_value)) { +// LoggerE("Cannot get is_flight_mode value"); +// return PlatformResult(ErrorCode::UNKNOWN_ERR, "Cannot get is_flight_mode value"); +// } +// *result_is_flight_mode = (0 != result_value) ? true : false; +// return PlatformResult(ErrorCode::NO_ERROR); +//} +// +//static PlatformResult FetchConnection(TapiHandle *tapi_handle, std::string* result_status, +// std::string* result_apn, std::string* result_ip_address, +// std::string* result_ipv6_address, std::string* result_imei) +//{ +// LoggerD("Entered"); +// connection_type_e connection_type = CONNECTION_TYPE_DISCONNECTED; +// connection_profile_h profile_handle = nullptr; +// connection_h connection_handle = nullptr; +// +// //connection must be created in every call, in other case error occurs +// int error = connection_create(&connection_handle); +// if (CONNECTION_ERROR_NONE != error) { +// std::string log_msg = "Cannot create connection: " + std::to_string(error); +// LoggerE("%s", log_msg.c_str()); +// return PlatformResult(ErrorCode::UNKNOWN_ERR, log_msg); +// } +// std::unique_ptr::type, int(*)(connection_h)> +// connection_handle_ptr(connection_handle, &connection_destroy); +// // automatically release the memory +// +// error = connection_get_type(connection_handle, &connection_type); +// if (CONNECTION_ERROR_NONE != error) { +// LoggerE("Failed to get connection type: %d", error); +// return PlatformResult(ErrorCode::UNKNOWN_ERR, "Cannot get connection type"); +// } +// +// char* apn = nullptr; +// if (CONNECTION_TYPE_CELLULAR == connection_type) { +// *result_status = kConnectionOn; +// +// error = connection_get_current_profile(connection_handle, +// &profile_handle); +// std::unique_ptr +// ::type, int(*)(connection_profile_h)> +// profile_handle_ptr(profile_handle, &connection_profile_destroy); +// // automatically release the memory +// if (CONNECTION_ERROR_NONE != error) { +// LoggerE("Failed to get profile: %d", error); +// return PlatformResult(ErrorCode::UNKNOWN_ERR, "Cannot get profile"); +// } +// +// error = connection_profile_get_cellular_apn(profile_handle, &apn); +// if (CONNECTION_ERROR_NONE != error) { +// LoggerE("Failed to get apn name: %d", error); +// return PlatformResult(ErrorCode::UNKNOWN_ERR, "Cannot get apn name"); +// } +// *result_apn = apn; +// free(apn); +// +// PlatformResult ret = GetIps(profile_handle, result_ip_address, result_ipv6_address); +// if (ret.IsError()) { +// return ret; +// } +// } else { +// *result_status = kConnectionOff; +// +// //According to previous implementation in case of error +// //don't throw exception here +// error = connection_get_default_cellular_service_profile( +// connection_handle, +// CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET, +// &profile_handle); +// std::unique_ptr +// ::type, int(*)(connection_profile_h)> +// profile_handle_ptr(profile_handle, &connection_profile_destroy); +// // automatically release the memory +// if (CONNECTION_ERROR_NONE == error) { +// error = connection_profile_get_cellular_apn(profile_handle, &apn); +// if (CONNECTION_ERROR_NONE == error) { +// *result_apn = apn; +// free(apn); +// } else { +// LoggerE("Failed to get default apn name: %d. Failing silently", +// error); +// } +// } else { +// LoggerE("Failed to get default profile: %d. Failing silently", +// error); +// } +// } +// +// char* imei = nullptr; +// imei = tel_get_misc_me_imei_sync(tapi_handle); +// if (nullptr != imei) { +// *result_imei = imei; +// free(imei); +// } else { +// LoggerE("Failed to get imei, nullptr pointer. Setting empty value."); +// *result_imei = ""; +// } +// return PlatformResult(ErrorCode::NO_ERROR); +//} +// +//PlatformResult SystemInfoPropertiesManager::ReportCellularNetwork(picojson::object* out, unsigned long count) { +// PlatformResult ret = CheckTelephonySupport(); +// if (ret.IsError()) { +// return ret; +// } +// std::string result_status; +// std::string result_apn; +// std::string result_ip_address; +// std::string result_ipv6_address; +// unsigned short result_mcc; +// unsigned short result_mnc; +// unsigned short result_cell_id; +// unsigned short result_lac; +// bool result_is_roaming; +// bool result_is_flight_mode; +// std::string result_imei; +// +// //gathering vconf-based values +// ret = FetchBasicSimProperties(system_info_listeners.GetTapiHandles()[count], &result_mcc, +// &result_mnc, &result_cell_id, &result_lac, +// &result_is_roaming, &result_is_flight_mode); +// if (ret.IsError()) { +// return ret; +// } +// //gathering connection informations +// ret = FetchConnection(system_info_listeners.GetTapiHandles()[count], +// &result_status, &result_apn, &result_ip_address, &result_ipv6_address, &result_imei); +// if (ret.IsError()) { +// return ret; +// } +// +// out.insert(std::make_pair("status", picojson::value(result_status))); +// out.insert(std::make_pair("apn", picojson::value(result_apn))); +// out.insert(std::make_pair("ipAddress", picojson::value(result_ip_address))); +// out.insert(std::make_pair("ipv6Address", picojson::value(result_ipv6_address))); +// out.insert(std::make_pair("mcc", picojson::value(std::to_string(result_mcc)))); +// out.insert(std::make_pair("mnc", picojson::value(std::to_string(result_mnc)))); +// out.insert(std::make_pair("cellId", picojson::value(std::to_string(result_cell_id)))); +// out.insert(std::make_pair("lac", picojson::value(std::to_string(result_lac)))); +// out.insert(std::make_pair("isRoaming", picojson::value(result_is_roaming))); +// out.insert(std::make_pair("isFligthMode", picojson::value(result_is_flight_mode))); +// out.insert(std::make_pair("imei", picojson::value(result_imei))); +// return PlatformResult(ErrorCode::NO_ERROR); +//} +// +//void SimCphsValueCallback(TapiHandle */*handle*/, int result, void *data, void */*user_data*/) +//{ +// LoggerD("Entered"); +// TelSimAccessResult_t access_rt = static_cast(result); +// TelSimCphsNetName_t *cphs_info = static_cast(data); +// +// std::string result_operator; +// if (TAPI_SIM_ACCESS_SUCCESS == access_rt) { +// std::stringstream s; +// s << cphs_info->full_name; +// if (s.str().empty()) { +// s << cphs_info->short_name; +// } +// result_operator = s.str(); +// } else { +// LoggerW("Failed to retrieve cphs_info: %d", access_rt); +// } +// sim_mgr.set_operator_name(result_operator); +// sim_mgr.TryReturn(); +//} +// +//void SimMsisdnValueCallback(TapiHandle */*handle*/, int result, void *data, void */*user_data*/) +//{ +// LoggerD("Entered"); +// TelSimAccessResult_t access_rt = static_cast(result); +// TelSimMsisdnList_t *msisdn_info = static_cast(data); +// +// std::string result_msisdn; +// if (TAPI_SIM_ACCESS_SUCCESS == access_rt) { +// if (msisdn_info->count > 0) { +// if (strlen(msisdn_info->list[0].num) > 0) { +// result_msisdn = msisdn_info->list[0].num; +// } else { +// LoggerW("MSISDN number empty"); +// } +// } else { +// LoggerW("msisdn_info list empty"); +// } +// } else { +// LoggerW("Failed to retrieve msisdn_: %d", access_rt); +// } +// +// sim_mgr.set_msisdn(result_msisdn); +// sim_mgr.TryReturn(); +//} +// +//void SimSpnValueCallback(TapiHandle */*handle*/, int result, void *data, void */*user_data*/) +//{ +// LoggerD("Entered"); +// TelSimAccessResult_t access_rt = static_cast(result); +// TelSimSpn_t *spn_info = static_cast(data); +// +// std::string result_spn; +// if (TAPI_SIM_ACCESS_SUCCESS == access_rt) { +// result_spn = (char *)spn_info->spn; +// } else { +// LoggerW("Failed to retrieve spn_: %d", access_rt); +// } +// +// sim_mgr.set_spn(result_spn); +// sim_mgr.TryReturn(); +//} +// +//PlatformResult SystemInfoPropertiesManager::ReportSim(picojson::object* out, unsigned long count) { +// PlatformResult ret = CheckTelephonySupport(); +// if (ret.IsError()) { +// return ret; +// } +// return sim_mgr.GatherSimInformation( +// system_info_listeners.GetTapiHandles()[count], &out); +//} +// +//PlatformResult SystemInfoPropertiesManager::ReportPeripheral(picojson::object* out) { +// +///* int wireless_display_status = 0; +// PlatformResult ret = GetVconfInt(VCONFKEY_MIRACAST_WFD_SOURCE_STATUS, wireless_display_status); +// if (ret.IsSuccess()) { +// if (VCONFKEY_MIRACAST_WFD_SOURCE_ON == wireless_display_status) { +// out.insert(std::make_pair(kVideoOutputString, picojson::value(true))); +// return PlatformResult(ErrorCode::NO_ERROR); +// } +// }*/ +// int hdmi_status = 0; +// PlatformResult ret = GetVconfInt(VCONFKEY_SYSMAN_HDMI, hdmi_status); +// if (ret.IsSuccess()) { +// if (VCONFKEY_SYSMAN_HDMI_CONNECTED == hdmi_status) { +// out.insert(std::make_pair(kVideoOutputString, picojson::value(true))); +// return PlatformResult(ErrorCode::NO_ERROR); +// } +// } +// +// out.insert(std::make_pair(kVideoOutputString, picojson::value(false))); +// return PlatformResult(ErrorCode::NO_ERROR); +//} +// +//PlatformResult SystemInfoPropertiesManager::ReportMemory(picojson::object* out) { +// std::string state = MEMORY_STATE_NORMAL; +// int status = 0; +// PlatformResult ret = GetVconfInt(VCONFKEY_SYSMAN_LOW_MEMORY, status); +// if (ret.IsSuccess()) { +// switch (status) { +// case VCONFKEY_SYSMAN_LOW_MEMORY_SOFT_WARNING: +// case VCONFKEY_SYSMAN_LOW_MEMORY_HARD_WARNING: +// state = MEMORY_STATE_WARNING; +// break; +// case VCONFKEY_SYSMAN_LOW_MEMORY_NORMAL: +// default: +// state = MEMORY_STATE_NORMAL; +// } +// } +// +// out.insert(std::make_pair("state", picojson::value(state))); +// return PlatformResult(ErrorCode::NO_ERROR); +//} +// +//static void CreateStorageInfo(const std::string& type, struct statfs& fs, picojson::object* out) { +// out->insert(std::make_pair("type", picojson::value(type))); +// out->insert(std::make_pair("capacity", picojson::value(std::to_string( +// static_cast(fs.f_bsize) * +// static_cast(fs.f_blocks))))); +// out->insert(std::make_pair("availableCapacity", picojson::value(std::to_string( +// static_cast(fs.f_bsize) * +// static_cast(fs.f_bavail))))); +// bool isRemovable = (type == kTypeInternal) ? false : true; +// out->insert(std::make_pair("isRemovable", picojson::value(isRemovable))); +//} +// +//PlatformResult SystemInfoPropertiesManager::ReportStorage(picojson::object* out) { +// int sdcardState = 0; +// struct statfs fs; +// +// picojson::value result = picojson::value(picojson::array()); +// +// picojson::array& array = result.get(); +// array.push_back(picojson::value(picojson::object())); +// picojson::object& internal_obj = array.back().get(); +// +// if (statfs(kStorageInternalPath, &fs) < 0) { +// LoggerE("There are no storage units detected"); +// return PlatformResult(ErrorCode::UNKNOWN_ERR, "There are no storage units detected"); +// } +// CreateStorageInfo(kTypeInternal, fs, &internal_obj); +// system_info_listeners.SetAvailableCapacityInternal(fs.f_bavail); +// +// if (0 == vconf_get_int(VCONFKEY_SYSMAN_MMC_STATUS, &sdcardState)) { +// if (VCONFKEY_SYSMAN_MMC_MOUNTED == sdcardState){ +// if (statfs(kStorageSdcardPath, &fs) < 0) { +// LoggerE("MMC mounted, but not accessible"); +// return PlatformResult(ErrorCode::UNKNOWN_ERR, "MMC mounted, but not accessible"); +// } +// array.push_back(picojson::value(picojson::object())); +// picojson::object& external_obj = array.back().get(); +// CreateStorageInfo(kTypeMmc, fs, &external_obj); +// system_info_listeners.SetAvailableCapacityMmc(fs.f_bavail); +// } +// } +// +// out.insert(std::make_pair("storages", picojson::value(result))); +// return PlatformResult(ErrorCode::NO_ERROR); +//} +//PlatformResult SystemInfoPropertiesManager::ReportCameraFlash(picojson::object* out) { +// PlatformResult ret = CheckCameraFlashSupport(); +// if (ret.IsError()) { +// return ret; +// } +// return PlatformResult(ErrorCode::NO_ERROR); +//} + + +} // namespace systeminfo +} // namespace webapi diff --git a/src/systeminfo/systeminfo_properties_manager.h b/src/systeminfo/systeminfo_properties_manager.h new file mode 100644 index 00000000..ccd5808b --- /dev/null +++ b/src/systeminfo/systeminfo_properties_manager.h @@ -0,0 +1,57 @@ +/* + * 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_PROPERTIES_MANAGER_H__ +#define WEBAPI_PLUGINS_SYSTEMINFO_SYSTEMINFO_PROPERTIES_MANAGER_H__ + +#include +#include "common/picojson.h" +#include "common/platform_result.h" + +namespace extension { +namespace systeminfo { + +class SystemInfoPropertiesManager { + public: + SystemInfoPropertiesManager(); + ~SystemInfoPropertiesManager(); + + common::PlatformResult GetPropertyValue( + const std::string& prop, bool is_array_type, picojson::value* res); + + private: + common::PlatformResult ReportProperty(const std::string& property, int index, + picojson::object* res_obj); + common::PlatformResult ReportBattery(picojson::object* out); + common::PlatformResult ReportCpu(picojson::object* out); + common::PlatformResult ReportDisplay(picojson::object* out); + common::PlatformResult ReportDeviceOrientation(picojson::object* out); + common::PlatformResult ReportBuild(picojson::object* out); + common::PlatformResult ReportLocale(picojson::object* out); + common::PlatformResult ReportNetwork(picojson::object* out); + common::PlatformResult ReportWifiNetwork(picojson::object* out); + common::PlatformResult ReportEthernetNetwork(picojson::object* out); + common::PlatformResult ReportCellularNetwork(picojson::object* out, unsigned long count); + common::PlatformResult ReportSim(picojson::object* out, unsigned long count); + common::PlatformResult ReportPeripheral(picojson::object* out); + common::PlatformResult ReportCameraFlash(picojson::object* out); + common::PlatformResult ReportStorage(picojson::object* out); +}; + +} // namespace systeminfo +} // namespace webapi + +#endif // WEBAPI_PLUGINS_SYSTEMINFO_SYSTEMINFO_PROPERTIES_MANAGER_H__