From 7d99a94e7c5de7d5a6534b89835fc2925a794aaa Mon Sep 17 00:00:00 2001 From: Wojciech Kosowicz Date: Wed, 25 Mar 2015 11:31:58 +0100 Subject: [PATCH] [SystemInfo] Added callback for camera flash change Unable to test it out as the callback does not come back from the platform. [Verification] Tct without changes Change-Id: I76155c46d7f966a49a11c454a8bcf1c3a3c2cae0 Signed-off-by: Wojciech Kosowicz --- src/systeminfo/systeminfo-utils.cpp | 67 ++++++++++++++++++++++++++- src/systeminfo/systeminfo-utils.h | 3 ++ src/systeminfo/systeminfo_api.js | 19 ++++++-- src/systeminfo/systeminfo_instance.cc | 23 +++++++++ 4 files changed, 108 insertions(+), 4 deletions(-) diff --git a/src/systeminfo/systeminfo-utils.cpp b/src/systeminfo/systeminfo-utils.cpp index 86384fd0..c14550c1 100644 --- a/src/systeminfo/systeminfo-utils.cpp +++ b/src/systeminfo/systeminfo-utils.cpp @@ -32,6 +32,8 @@ #include #include #include +#include +#include #include #include "common/logger.h" @@ -93,6 +95,7 @@ static void OnNetworkValueChangedCb(const char* ipv4_address, static void OnCellularNetworkValueChangedCb(keynode_t *node, void *event_ptr); static void OnPeripheralChangedCb(keynode_t* node, void* event_ptr); static void OnMemoryChangedCb(keynode_t* node, void* event_ptr); +static void OnBrightnessChangedCb(device_callback_e type, void *value, void *user_data); static void SimCphsValueCallback(TapiHandle *handle, int result, void *data, void *user_data); static void SimMsisdnValueCallback(TapiHandle *handle, int result, void *data, void *user_data); @@ -492,6 +495,9 @@ class SystemInfoListeners { PlatformResult RegisterMemoryListener(const SysteminfoUtilsCallback& callback, SysteminfoInstance& instance); PlatformResult UnregisterMemoryListener(); + PlatformResult RegisterCameraFlashListener(const SysteminfoUtilsCallback& callback, + SysteminfoInstance& instance); + PlatformResult UnregisterCameraFlashListener(); void SetCpuInfoLoad(double load); void SetAvailableCapacityInternal(unsigned long long capacity); @@ -512,6 +518,7 @@ class SystemInfoListeners { void OnCellularNetworkValueCallback(keynode_t *node, void *event_ptr); void OnPeripheralChangedCallback(keynode_t* node, void* event_ptr); void OnMemoryChangedCallback(keynode_t* node, void* event_ptr); + void OnBrightnessChangedCallback(device_callback_e type, void* value, void* user_data); TapiHandle* GetTapiHandle(); TapiHandle** GetTapiHandles(); @@ -548,6 +555,7 @@ class SystemInfoListeners { SysteminfoUtilsCallback m_cellular_network_listener; SysteminfoUtilsCallback m_peripheral_listener; SysteminfoUtilsCallback m_memory_listener; + SysteminfoUtilsCallback m_camera_flash_listener; TapiHandle *m_tapi_handles[TAPI_HANDLE_MAX+1]; //for ip change callback @@ -577,7 +585,8 @@ SystemInfoListeners::SystemInfoListeners(): m_peripheral_listener(nullptr), m_memory_listener(nullptr), m_connection_handle(nullptr), - m_sensor_handle(-1) + m_sensor_handle(-1), + m_camera_flash_listener(nullptr) { LoggerD("Entered"); } @@ -1034,6 +1043,35 @@ PlatformResult SystemInfoListeners::UnregisterMemoryListener() return PlatformResult(ErrorCode::NO_ERROR); } +PlatformResult SystemInfoListeners::RegisterCameraFlashListener(const SysteminfoUtilsCallback& callback, + SysteminfoInstance& instance) +{ + if (nullptr == m_camera_flash_listener) { + if (DEVICE_ERROR_NONE != device_add_callback(DEVICE_CALLBACK_FLASH_BRIGHTNESS, + OnBrightnessChangedCb, static_cast(&instance))) { + return PlatformResult(ErrorCode::UNKNOWN_ERR); + } + m_camera_flash_listener = callback; + } + return PlatformResult(ErrorCode::NO_ERROR); +} + +PlatformResult SystemInfoListeners::UnregisterCameraFlashListener() +{ + if (nullptr != m_camera_flash_listener) { + PlatformResult ret = PlatformResult(ErrorCode::NO_ERROR); + int value = 0; + if (DEVICE_ERROR_NONE != device_remove_callback(DEVICE_CALLBACK_FLASH_BRIGHTNESS, + OnBrightnessChangedCb)) { + return PlatformResult(ErrorCode::UNKNOWN_ERR); + } + LoggerD("Removed callback for camera_flash"); + m_camera_flash_listener = nullptr; + } + return PlatformResult(ErrorCode::NO_ERROR); +} + + void SystemInfoListeners::SetCpuInfoLoad(double load) { m_cpu_load = load; @@ -1187,6 +1225,14 @@ void SystemInfoListeners::OnMemoryChangedCallback(keynode_t* /*node*/, void* eve } } +void SystemInfoListeners::OnBrightnessChangedCallback(device_callback_e type, void* value, void* user_data) +{ + if (nullptr != m_camera_flash_listener) { + SysteminfoInstance* instance = static_cast(user_data); + m_camera_flash_listener(*instance); + } +} + void SystemInfoListeners::InitTapiHandles() { LoggerD("Entered"); @@ -1380,6 +1426,14 @@ void OnMemoryChangedCb(keynode_t* node, void* event_ptr) system_info_listeners.OnMemoryChangedCallback(node, event_ptr); } +void OnBrightnessChangedCb(device_callback_e type, void* value, void* user_data) +{ + LoggerD(""); + if (type == DEVICE_CALLBACK_FLASH_BRIGHTNESS) { + system_info_listeners.OnBrightnessChangedCallback(type, value, user_data); + } +} + /////////////////////////// SysteminfoUtils //////////////////////////////// PlatformResult SystemInfoDeviceCapability::GetValueBool(const char *key, bool* value) { @@ -2566,6 +2620,17 @@ PlatformResult SysteminfoUtils::UnregisterMemoryListener() return system_info_listeners.UnregisterMemoryListener(); } +PlatformResult SysteminfoUtils::RegisterCameraFlashListener(const SysteminfoUtilsCallback& callback, + SysteminfoInstance& instance) +{ + return system_info_listeners.RegisterCameraFlashListener(callback, instance); +} + +PlatformResult SysteminfoUtils::UnregisterCameraFlashListener() +{ + return system_info_listeners.UnregisterCameraFlashListener(); +} + static PlatformResult CheckStringCapability(const std::string& key, std::string* value, bool* fetched) { diff --git a/src/systeminfo/systeminfo-utils.h b/src/systeminfo/systeminfo-utils.h index a36651a4..eff8b24b 100644 --- a/src/systeminfo/systeminfo-utils.h +++ b/src/systeminfo/systeminfo-utils.h @@ -78,6 +78,9 @@ class SysteminfoUtils { static common::PlatformResult RegisterMemoryListener(const SysteminfoUtilsCallback& callback, SysteminfoInstance& instance); static common::PlatformResult UnregisterMemoryListener(); + static common::PlatformResult RegisterCameraFlashListener(const SysteminfoUtilsCallback& callback, + SysteminfoInstance& instance); + static common::PlatformResult UnregisterCameraFlashListener(); private: static common::PlatformResult ReportProperty(const std::string& property, int index, diff --git a/src/systeminfo/systeminfo_api.js b/src/systeminfo/systeminfo_api.js index 1e1c339b..60903a09 100644 --- a/src/systeminfo/systeminfo_api.js +++ b/src/systeminfo/systeminfo_api.js @@ -654,7 +654,7 @@ function SystemInfoCameraFlash(data) { var getBrightness = function() { var result = native_.callSync('SystemInfo_getBrightness', {}); if (native_.isSuccess(result)) { - return Converter_.toLong(native_.getResultObject(result)); + return Converter_.toLong(native_.getResultObject(result)) / this.levels; } return null; }; @@ -678,6 +678,7 @@ SystemInfoCameraFlash.prototype.setBrightness = function(brightness) { var args = validator_.validateArgs(arguments, [ {name: 'brightness', type: types_.LONG} ]); + args.brightness = args.brightness * this.levels; var result = native_.callSync('SystemInfo_setBrightness', args); if (native_.isFailure(result)) { @@ -801,6 +802,7 @@ var _cellularNetworkStr = SystemInfoPropertyId.CELLULAR_NETWORK; var _simStr = SystemInfoPropertyId.SIM; var _peripheralStr = SystemInfoPropertyId.PERIPHERAL; var _memoryStr = SystemInfoPropertyId.MEMORY; +var _cameraFlashStr = SystemInfoPropertyId.CAMERA_FLASH; var _nextId = 0; @@ -1003,8 +1005,19 @@ function _systeminfoMemoryListenerCallback(eventObj) { } } -function _systeminfoCameraFlashListenerCallback(eventObject) { - //TODO fill this up +function _systeminfoCameraFlashListenerCallback(eventObj) { + var property = _cameraFlashStr; + var callbacks = _propertyContainer[property].callbacks; + + for (var watchId in callbacks) { + if (callbacks.hasOwnProperty(watchId)) { + var listener = callbacks[watchId]; + var propObj = !listener.isArrayType ? + _createProperty(property, eventObj.result.array[0]) : + _createPropertyArray(property, eventObj.result); + callbacks[watchId].callback(propObj); + } + } } var _propertyContainer = { diff --git a/src/systeminfo/systeminfo_instance.cc b/src/systeminfo/systeminfo_instance.cc index 2b6c6d81..9f06033d 100644 --- a/src/systeminfo/systeminfo_instance.cc +++ b/src/systeminfo/systeminfo_instance.cc @@ -33,6 +33,7 @@ static void OnWifiNetworkChangedCallback(SysteminfoInstance& instance); static void OnCellularNetworkChangedCallback(SysteminfoInstance& instance); static void OnPeripheralChangedCallback(SysteminfoInstance& instance); static void OnMemoryChangedCallback(SysteminfoInstance& instance); +static void OnBrigthnessChangedCallback(SysteminfoInstance& instance); namespace { const std::string kPropertyIdString = "propertyId"; @@ -52,6 +53,7 @@ const std::string kPropertyIdCellularNetwork = "CELLULAR_NETWORK"; const std::string kPropertyIdSim = "SIM"; const std::string kPropertyIdPeripheral = "PERIPHERAL"; const std::string kPropertyIdMemory= "MEMORY"; +const std::string kPropertyIdCameraFlash= "CAMERA_FLASH"; const std::string kPrivilegeLED = "http://tizen.org/privilege/led"; @@ -103,6 +105,7 @@ const std::string kPrivilegeLED = "http://tizen.org/privilege/led"; } SysteminfoInstance::SysteminfoInstance() { + using std::placeholders::_1; using std::placeholders::_2; @@ -329,6 +332,8 @@ void SysteminfoInstance::AddPropertyValueChangeListener(const picojson::value& a 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"); @@ -437,6 +442,8 @@ void SysteminfoInstance::RemovePropertyValueChangeListener(const picojson::value 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"); @@ -682,5 +689,21 @@ void OnMemoryChangedCallback(SysteminfoInstance& instance) } } +void OnBrigthnessChangedCallback(SysteminfoInstance &instance) +{ + LoggerD(""); + const std::shared_ptr& response = + std::shared_ptr(new picojson::value(picojson::object())); + response->get()[kPropertyIdString] = picojson::value(kPropertyIdCameraFlash); + response->get()[kListenerIdString] = picojson::value(kListenerConstValue); + + picojson::value result = picojson::value(picojson::object()); + PlatformResult ret = SysteminfoUtils::GetPropertyValue(kPropertyIdCameraFlash, true, result); + if (ret.IsSuccess()) { + ReportSuccess(result,response->get()); + instance.PostMessage(response->serialize().c_str()); + } +} + } // namespace systeminfo } // namespace extension -- 2.34.1