From: yangruiintel Date: Wed, 28 Aug 2013 06:09:54 +0000 (+0800) Subject: [SystemInfo] Implement peripheral property support X-Git-Tag: accepted/tizen/generic/20140324.124941~170^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=68d6f19d1e1c4cea90a6a8f66563a9bea1c9d3b3;p=platform%2Fframework%2Fweb%2Ftizen-extensions-crosswalk.git [SystemInfo] Implement peripheral property support --- diff --git a/system_info/system_info_peripheral.h b/system_info/system_info_peripheral.h index d53331d..08f26a0 100644 --- a/system_info/system_info_peripheral.h +++ b/system_info/system_info_peripheral.h @@ -5,6 +5,11 @@ #ifndef SYSTEM_INFO_SYSTEM_INFO_PERIPHERAL_H_ #define SYSTEM_INFO_SYSTEM_INFO_PERIPHERAL_H_ +#if defined(TIZEN_MOBILE) +#include +#include +#endif + #include "common/extension_adapter.h" #include "common/picojson.h" #include "common/utils.h" @@ -24,9 +29,26 @@ class SysInfoPeripheral { private: explicit SysInfoPeripheral(ContextAPI* api) { api_ = api; + PlatformInitialize(); } + void PlatformInitialize(); + +#if defined(TIZEN_MOBILE) + void SetWFD(int wfd); + void SetHDMI(int hdmi); + + void UpdateIsVideoOutputOn(); + void SendData(picojson::value& data); + + static void OnWFDChanged(keynode_t* node, void* user_data); + static void OnHDMIChanged(keynode_t* node, void* user_data); +#endif + ContextAPI* api_; + bool is_video_output_; + int wfd_; + int hdmi_; DISALLOW_COPY_AND_ASSIGN(SysInfoPeripheral); }; diff --git a/system_info/system_info_peripheral_desktop.cc b/system_info/system_info_peripheral_desktop.cc index 8fabbfc..8c6b486 100644 --- a/system_info/system_info_peripheral_desktop.cc +++ b/system_info/system_info_peripheral_desktop.cc @@ -11,3 +11,5 @@ void SysInfoPeripheral::Get(picojson::value& error, system_info::SetPicoJsonObjectValue(error, "message", picojson::value("Peripheral is not supported on desktop.")); } + +void SysInfoPeripheral::PlatformInitialize() { } diff --git a/system_info/system_info_peripheral_mobile.cc b/system_info/system_info_peripheral_mobile.cc index 8644f3a..02acdbd 100644 --- a/system_info/system_info_peripheral_mobile.cc +++ b/system_info/system_info_peripheral_mobile.cc @@ -8,7 +8,77 @@ void SysInfoPeripheral::Get(picojson::value& error, picojson::value& data) { - // FIXME(halton): Add actual implementation - system_info::SetPicoJsonObjectValue(error, "message", - picojson::value("NOT IMPLEMENTED.")); + if (vconf_get_int(VCONFKEY_MIRACAST_WFD_SOURCE_STATUS, &wfd_) != 0) { + system_info::SetPicoJsonObjectValue(error, "message", + picojson::value("Get wireless display Status failed.")); + return; + } + + if (vconf_get_int(VCONFKEY_SYSMAN_HDMI, &hdmi_) != 0) { + system_info::SetPicoJsonObjectValue(error, "message", + picojson::value("Get HDMI status failed.")); + return; + } + + SendData(data); + system_info::SetPicoJsonObjectValue(error, "message", picojson::value("")); +} + +void SysInfoPeripheral::SendData(picojson::value& data) { + is_video_output_ = (wfd_ == VCONFKEY_MIRACAST_WFD_SOURCE_ON) || + (hdmi_ == VCONFKEY_SYSMAN_HDMI_CONNECTED); + system_info::SetPicoJsonObjectValue(data, "isVideoOutputOn", + picojson::value(is_video_output_)); +} + +void SysInfoPeripheral::UpdateIsVideoOutputOn() { + picojson::value output = picojson::value(picojson::object()); + picojson::value data = picojson::value(picojson::object()); + + bool old_is_video_output = is_video_output_; + SendData(data); + if (old_is_video_output == is_video_output_) + return; + + system_info::SetPicoJsonObjectValue(output, "cmd", + picojson::value("SystemInfoPropertyValueChanged")); + system_info::SetPicoJsonObjectValue(output, "prop", + picojson::value("PERIPHERAL")); + system_info::SetPicoJsonObjectValue(output, "data", data); + + std::string result = output.serialize(); + api_->PostMessage(result.c_str()); +} + +void SysInfoPeripheral::SetWFD(int wfd) { + wfd_ = wfd; + UpdateIsVideoOutputOn(); +} + +void SysInfoPeripheral::SetHDMI(int hdmi) { + hdmi_ = hdmi; + UpdateIsVideoOutputOn(); +} + +void SysInfoPeripheral::OnWFDChanged(keynode_t* node, void* user_data) { + int wfd = vconf_keynode_get_int(node); + SysInfoPeripheral* peripheral = + static_cast(user_data); + + peripheral->SetWFD(wfd); +} + +void SysInfoPeripheral::OnHDMIChanged(keynode_t* node, void* user_data) { + int hdmi = vconf_keynode_get_int(node); + SysInfoPeripheral* peripheral = + static_cast(user_data); + + peripheral->SetHDMI(hdmi); +} + +void SysInfoPeripheral::PlatformInitialize() { + vconf_notify_key_changed(VCONFKEY_MIRACAST_WFD_SOURCE_STATUS, + (vconf_callback_fn)OnWFDChanged, this); + vconf_notify_key_changed(VCONFKEY_SYSMAN_HDMI, + (vconf_callback_fn)OnHDMIChanged, this); }