From e1691cdb40e8e3efc0363c299d3f77a4a595c963 Mon Sep 17 00:00:00 2001 From: Jiajia Qin Date: Thu, 5 Sep 2013 13:25:05 +0800 Subject: [PATCH] [SystemInfo] Support multiple frames. Fixed bug #113 #569 --- system_info/system_info_battery.h | 7 +- system_info/system_info_build.h | 6 +- system_info/system_info_cellular_network.h | 10 +-- system_info/system_info_context.cc | 110 +++++++++++++++------------ system_info/system_info_context.h | 24 +++--- system_info/system_info_cpu.h | 13 +--- system_info/system_info_device_orientation.h | 12 +-- system_info/system_info_display.h | 7 +- system_info/system_info_locale.h | 6 +- system_info/system_info_network.h | 7 +- system_info/system_info_peripheral.h | 10 +-- system_info/system_info_sim.h | 12 +-- system_info/system_info_storage.h | 6 +- system_info/system_info_wifi_network.h | 7 +- 14 files changed, 93 insertions(+), 144 deletions(-) diff --git a/system_info/system_info_battery.h b/system_info/system_info_battery.h index 69cfa6f..de9685e 100644 --- a/system_info/system_info_battery.h +++ b/system_info/system_info_battery.h @@ -20,18 +20,13 @@ class SysInfoBattery { public: - static SysInfoBattery& GetSysInfoBattery(ContextAPI* api) { - static SysInfoBattery instance(api); - return instance; - } + explicit SysInfoBattery(ContextAPI* api); ~SysInfoBattery(); void Get(picojson::value& error, picojson::value& data); void StartListening(); void StopListening(); private: - explicit SysInfoBattery(ContextAPI* api); - static gboolean OnUpdateTimeout(gpointer user_data); bool Update(picojson::value& error); void SetData(picojson::value& data); diff --git a/system_info/system_info_build.h b/system_info/system_info_build.h index 7649f5a..7e34337 100644 --- a/system_info/system_info_build.h +++ b/system_info/system_info_build.h @@ -15,10 +15,7 @@ class SysInfoBuild { public: - static SysInfoBuild& GetSysInfoBuild(ContextAPI* api) { - static SysInfoBuild instance(api); - return instance; - } + explicit SysInfoBuild(ContextAPI* api); ~SysInfoBuild(); void Get(picojson::value& error, picojson::value& data); inline void StartListening() { @@ -30,7 +27,6 @@ class SysInfoBuild { inline void StopListening() { stopping_ = true; } private: - explicit SysInfoBuild(ContextAPI* api); bool UpdateHardware(); bool UpdateOSBuild(); static gboolean OnUpdateTimeout(gpointer user_data); diff --git a/system_info/system_info_cellular_network.h b/system_info/system_info_cellular_network.h index 762bdea..01ec833 100644 --- a/system_info/system_info_cellular_network.h +++ b/system_info/system_info_cellular_network.h @@ -19,10 +19,8 @@ class SysInfoCellularNetwork { public: - static SysInfoCellularNetwork& GetSysInfoCellularNetwork( - ContextAPI* api) { - static SysInfoCellularNetwork instance(api); - return instance; + explicit SysInfoCellularNetwork(ContextAPI* api) { + api_ = api; } ~SysInfoCellularNetwork() { } void Get(picojson::value& error, picojson::value& data); @@ -30,10 +28,6 @@ class SysInfoCellularNetwork { void StopListening(); private: - explicit SysInfoCellularNetwork(ContextAPI* api) { - api_ = api; - } - #if defined(TIZEN_MOBILE) void SendUpdate(); void SetData(picojson::value& data); diff --git a/system_info/system_info_context.cc b/system_info/system_info_context.cc index 1156de3..6ced51e 100644 --- a/system_info/system_info_context.cc +++ b/system_info/system_info_context.cc @@ -20,23 +20,33 @@ CXWalkExtension* xwalk_extension_init(int32_t api_version) { SystemInfoContext::SystemInfoContext(ContextAPI* api) : api_(api), - battery_(SysInfoBattery::GetSysInfoBattery(api)), - build_(SysInfoBuild::GetSysInfoBuild(api)), - cellular_network_( - SysInfoCellularNetwork::GetSysInfoCellularNetwork(api)), - cpu_(SysInfoCpu::GetSysInfoCpu(api)), - device_orientation_( - SysInfoDeviceOrientation::GetSysInfoDeviceOrientation(api)), - display_(SysInfoDisplay::GetSysInfoDisplay(api)), - locale_(SysInfoLocale::GetSysInfoLocale(api)), - sim_(SysInfoSim::GetSysInfoSim(api)), - storage_(SysInfoStorage::GetSysInfoStorage(api)), - network_(SysInfoNetwork::GetSysInfoNetwork(api)), - peripheral_(SysInfoPeripheral::GetSysInfoPeripheral(api)), - wifi_network_(SysInfoWifiNetwork::GetSysInfoWifiNetwork(api)) { + battery_(new SysInfoBattery(api)), + build_(new SysInfoBuild(api)), + cellular_network_(new SysInfoCellularNetwork(api)), + cpu_(new SysInfoCpu(api)), + device_orientation_(new SysInfoDeviceOrientation(api)), + display_(new SysInfoDisplay(api)), + locale_(new SysInfoLocale(api)), + sim_(new SysInfoSim(api)), + storage_(new SysInfoStorage(api)), + network_(new SysInfoNetwork(api)), + peripheral_(new SysInfoPeripheral(api)), + wifi_network_(new SysInfoWifiNetwork(api)) { } SystemInfoContext::~SystemInfoContext() { + delete wifi_network_; + delete peripheral_; + delete network_; + delete storage_; + delete sim_; + delete locale_; + delete display_; + delete device_orientation_; + delete cpu_; + delete cellular_network_; + delete build_; + delete battery_; delete api_; } @@ -62,29 +72,29 @@ void SystemInfoContext::HandleGetPropertyValue(const picojson::value& input, std::string prop = input.get("prop").to_str(); if (prop == "BATTERY") { - battery_.Get(error, data); + battery_->Get(error, data); } else if (prop == "CPU") { - cpu_.Get(error, data); + cpu_->Get(error, data); } else if (prop == "STORAGE") { - storage_.Get(error, data); + storage_->Get(error, data); } else if (prop == "DISPLAY") { - display_.Get(error, data); + display_->Get(error, data); } else if (prop == "DEVICE_ORIENTATION") { - device_orientation_.Get(error, data); + device_orientation_->Get(error, data); } else if (prop == "BUILD") { - build_.Get(error, data); + build_->Get(error, data); } else if (prop == "LOCALE") { - locale_.Get(error, data); + locale_->Get(error, data); } else if (prop == "NETWORK") { - network_.Get(error, data); + network_->Get(error, data); } else if (prop == "WIFI_NETWORK") { - wifi_network_.Get(error, data); + wifi_network_->Get(error, data); } else if (prop == "CELLULAR_NETWORK") { - cellular_network_.Get(error, data); + cellular_network_->Get(error, data); } else if (prop == "SIM") { - sim_.Get(error, data); + sim_->Get(error, data); } else if (prop == "PERIPHERAL") { - peripheral_.Get(error, data); + peripheral_->Get(error, data); } else { system_info::SetPicoJsonObjectValue(error, "message", picojson::value("Not supported property " + prop)); @@ -104,29 +114,29 @@ void SystemInfoContext::HandleStartListening(const picojson::value& input) { std::string prop = input.get("prop").to_str(); if (prop == "BATTERY") { - battery_.StartListening(); + battery_->StartListening(); } else if (prop == "CPU") { - cpu_.StartListening(); + cpu_->StartListening(); } else if (prop == "STORAGE") { - storage_.StartListening(); + storage_->StartListening(); } else if (prop == "DISPLAY") { - display_.StartListening(); + display_->StartListening(); } else if (prop == "DEVICE_ORIENTATION") { - device_orientation_.StartListening(); + device_orientation_->StartListening(); } else if (prop == "BUILD") { - build_.StartListening(); + build_->StartListening(); } else if (prop == "LOCALE") { - locale_.StartListening(); + locale_->StartListening(); } else if (prop == "NETWORK") { - network_.StartListening(); + network_->StartListening(); } else if (prop == "WIFI_NETWORK") { - wifi_network_.StartListening(); + wifi_network_->StartListening(); } else if (prop == "CELLULAR_NETWORK") { - cellular_network_.StartListening(); + cellular_network_->StartListening(); } else if (prop == "SIM") { - sim_.StartListening(); + sim_->StartListening(); } else if (prop == "PERIPHERAL") { - peripheral_.StartListening(); + peripheral_->StartListening(); } } @@ -134,29 +144,29 @@ void SystemInfoContext::HandleStopListening(const picojson::value& input) { std::string prop = input.get("prop").to_str(); if (prop == "BATTERY") { - battery_.StopListening(); + battery_->StopListening(); } else if (prop == "CPU") { - cpu_.StopListening(); + cpu_->StopListening(); } else if (prop == "STORAGE") { - storage_.StopListening(); + storage_->StopListening(); } else if (prop == "DISPLAY") { - display_.StopListening(); + display_->StopListening(); } else if (prop == "DEVICE_ORIENTATION") { - device_orientation_.StopListening(); + device_orientation_->StopListening(); } else if (prop == "BUILD") { - build_.StopListening(); + build_->StopListening(); } else if (prop == "LOCALE") { - locale_.StopListening(); + locale_->StopListening(); } else if (prop == "NETWORK") { - network_.StopListening(); + network_->StopListening(); } else if (prop == "WIFI_NETWORK") { - wifi_network_.StopListening(); + wifi_network_->StopListening(); } else if (prop == "CELLULAR_NETWORK") { - cellular_network_.StopListening(); + cellular_network_->StopListening(); } else if (prop == "SIM") { - sim_.StopListening(); + sim_->StopListening(); } else if (prop == "PERIPHERAL") { - peripheral_.StopListening(); + peripheral_->StopListening(); } } diff --git a/system_info/system_info_context.h b/system_info/system_info_context.h index 039f8cc..68bf154 100644 --- a/system_info/system_info_context.h +++ b/system_info/system_info_context.h @@ -49,18 +49,18 @@ class SystemInfoContext { } ContextAPI* api_; - SysInfoBattery& battery_; - SysInfoBuild& build_; - SysInfoCellularNetwork& cellular_network_; - SysInfoCpu& cpu_; - SysInfoDeviceOrientation& device_orientation_; - SysInfoDisplay& display_; - SysInfoLocale& locale_; - SysInfoNetwork& network_; - SysInfoPeripheral& peripheral_; - SysInfoSim& sim_; - SysInfoStorage& storage_; - SysInfoWifiNetwork& wifi_network_; + SysInfoBattery* battery_; + SysInfoBuild* build_; + SysInfoCellularNetwork* cellular_network_; + SysInfoCpu* cpu_; + SysInfoDeviceOrientation* device_orientation_; + SysInfoDisplay* display_; + SysInfoLocale* locale_; + SysInfoNetwork* network_; + SysInfoPeripheral* peripheral_; + SysInfoSim* sim_; + SysInfoStorage* storage_; + SysInfoWifiNetwork* wifi_network_; }; #endif // SYSTEM_INFO_SYSTEM_INFO_CONTEXT_H_ diff --git a/system_info/system_info_cpu.h b/system_info/system_info_cpu.h index 7bbaa69..7be9238 100644 --- a/system_info/system_info_cpu.h +++ b/system_info/system_info_cpu.h @@ -14,9 +14,10 @@ class SysInfoCpu { public: - static SysInfoCpu& GetSysInfoCpu(ContextAPI* api) { - static SysInfoCpu instance(api); - return instance; + explicit SysInfoCpu(ContextAPI* api) + : load_(0.0), + stopping_(false) { + api_ = api; } ~SysInfoCpu() { } // Get support @@ -32,12 +33,6 @@ class SysInfoCpu { inline void StopListening() { stopping_ = true; } private: - explicit SysInfoCpu(ContextAPI* api) - : load_(0.0), - stopping_(false) { - api_ = api; - } - static gboolean OnUpdateTimeout(gpointer user_data); bool UpdateLoad(); diff --git a/system_info/system_info_device_orientation.h b/system_info/system_info_device_orientation.h index 9afec0a..1a34395 100644 --- a/system_info/system_info_device_orientation.h +++ b/system_info/system_info_device_orientation.h @@ -26,10 +26,9 @@ enum SystemInfoDeviceOrientationStatus { class SysInfoDeviceOrientation { public: - static SysInfoDeviceOrientation& GetSysInfoDeviceOrientation( - ContextAPI* api) { - static SysInfoDeviceOrientation instance(api); - return instance; + explicit SysInfoDeviceOrientation(ContextAPI* api) + :status_(UNKNOWN) { + api_ = api; } ~SysInfoDeviceOrientation() { } void Get(picojson::value& error, picojson::value& data); @@ -37,11 +36,6 @@ class SysInfoDeviceOrientation { void StopListening(); private: - explicit SysInfoDeviceOrientation(ContextAPI* api) - :status_(UNKNOWN) { - api_ = api; - } - #if defined(TIZEN_MOBILE) void SetStatus(); bool SetAutoRotation(); diff --git a/system_info/system_info_display.h b/system_info/system_info_display.h index 3a8f135..cb03920 100644 --- a/system_info/system_info_display.h +++ b/system_info/system_info_display.h @@ -14,10 +14,7 @@ class SysInfoDisplay { public: - static SysInfoDisplay& GetSysInfoDisplay(ContextAPI* api) { - static SysInfoDisplay d(api); - return d; - } + explicit SysInfoDisplay(ContextAPI* api); ~SysInfoDisplay() { } // Get support void Get(picojson::value& error, picojson::value& data); @@ -32,8 +29,6 @@ class SysInfoDisplay { void StopListening() { stopping_ = true; } private: - explicit SysInfoDisplay(ContextAPI* api); - static gboolean OnUpdateTimeout(gpointer user_data); bool UpdateSize(); bool UpdateBrightness(); diff --git a/system_info/system_info_locale.h b/system_info/system_info_locale.h index e88d8ae..115a39d 100644 --- a/system_info/system_info_locale.h +++ b/system_info/system_info_locale.h @@ -15,10 +15,7 @@ class SysInfoLocale { public: - static SysInfoLocale& GetSysInfoLocale(ContextAPI* api) { - static SysInfoLocale instance(api); - return instance; - } + explicit SysInfoLocale(ContextAPI* api); ~SysInfoLocale(); void Get(picojson::value& error, picojson::value& data); inline void StartListening() { @@ -30,7 +27,6 @@ class SysInfoLocale { inline void StopListening() { stopping_ = true; } private: - explicit SysInfoLocale(ContextAPI* api); bool UpdateLanguage(); bool UpdateCountry(); static gboolean OnUpdateTimeout(gpointer user_data); diff --git a/system_info/system_info_network.h b/system_info/system_info_network.h index 9366334..2ff6539 100644 --- a/system_info/system_info_network.h +++ b/system_info/system_info_network.h @@ -39,11 +39,7 @@ enum SystemInfoNetworkType { class SysInfoNetwork { public: - static SysInfoNetwork& GetSysInfoNetwork( - ContextAPI* api) { - static SysInfoNetwork instance(api); - return instance; - } + explicit SysInfoNetwork(ContextAPI* api); ~SysInfoNetwork(); void Get(picojson::value& error, picojson::value& data); inline void StartListening() { @@ -61,7 +57,6 @@ class SysInfoNetwork { } private: - explicit SysInfoNetwork(ContextAPI* api); void PlatformInitialize(); bool Update(picojson::value& error); diff --git a/system_info/system_info_peripheral.h b/system_info/system_info_peripheral.h index 48684e1..25e617d 100644 --- a/system_info/system_info_peripheral.h +++ b/system_info/system_info_peripheral.h @@ -16,10 +16,8 @@ class SysInfoPeripheral { public: - static SysInfoPeripheral& GetSysInfoPeripheral( - ContextAPI* api) { - static SysInfoPeripheral instance(api); - return instance; + explicit SysInfoPeripheral(ContextAPI* api) { + api_ = api; } ~SysInfoPeripheral() { } void Get(picojson::value& error, picojson::value& data); @@ -27,10 +25,6 @@ class SysInfoPeripheral { void StopListening(); private: - explicit SysInfoPeripheral(ContextAPI* api) { - api_ = api; - } - #if defined(TIZEN_MOBILE) void SetWFD(int wfd); void SetHDMI(int hdmi); diff --git a/system_info/system_info_sim.h b/system_info/system_info_sim.h index 2c65aaf..ea36d76 100644 --- a/system_info/system_info_sim.h +++ b/system_info/system_info_sim.h @@ -16,10 +16,9 @@ class SysInfoSim { public: - static SysInfoSim& GetSysInfoSim( - ContextAPI* api) { - static SysInfoSim instance(api); - return instance; + explicit SysInfoSim(ContextAPI* api) + : state_(SYSTEM_INFO_SIM_UNKNOWN) { + api_ = api; } ~SysInfoSim() { } void Get(picojson::value& error, picojson::value& data); @@ -43,11 +42,6 @@ class SysInfoSim { #endif private: - explicit SysInfoSim(ContextAPI* api) - : state_(SYSTEM_INFO_SIM_UNKNOWN) { - api_ = api; - } - #if defined(TIZEN_MOBILE) std::string ToSimStateString(SystemInfoSimState state); SystemInfoSimState Get_systeminfo_sim_state(sim_state_e state); diff --git a/system_info/system_info_storage.h b/system_info/system_info_storage.h index de9348e..ef90342 100644 --- a/system_info/system_info_storage.h +++ b/system_info/system_info_storage.h @@ -18,10 +18,7 @@ class SysInfoStorage { public: - static SysInfoStorage& GetSysInfoStorage(ContextAPI* api) { - static SysInfoStorage instance(api); - return instance; - } + explicit SysInfoStorage(ContextAPI* api); ~SysInfoStorage(); void Get(picojson::value& error, picojson::value& data); inline void StartListening() { @@ -34,7 +31,6 @@ class SysInfoStorage { inline void StopListening() { stopping_ = true; } private: - explicit SysInfoStorage(ContextAPI* api); bool Update(picojson::value& error); static gboolean OnUpdateTimeout(gpointer user_data); diff --git a/system_info/system_info_wifi_network.h b/system_info/system_info_wifi_network.h index 3a354ba..4bca6f5 100644 --- a/system_info/system_info_wifi_network.h +++ b/system_info/system_info_wifi_network.h @@ -29,11 +29,7 @@ class SysInfoWifiNetwork { public: - static SysInfoWifiNetwork& GetSysInfoWifiNetwork( - ContextAPI* api) { - static SysInfoWifiNetwork instance(api); - return instance; - } + explicit SysInfoWifiNetwork(ContextAPI* api); ~SysInfoWifiNetwork(); void Get(picojson::value& error, picojson::value& data); inline void StartListening() { @@ -51,7 +47,6 @@ class SysInfoWifiNetwork { } private: - explicit SysInfoWifiNetwork(ContextAPI* api); void PlatformInitialize(); bool Update(picojson::value& error); -- 2.7.4