#include <ITapiModem.h>
#include <ITapiSim.h>
#include <device.h>
+#include <device/callback.h>
+#include <device/device-error.h>
#include <sensor_internal.h>
#include "common/logger.h"
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);
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);
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();
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
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");
}
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<void*>(&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;
}
}
+void SystemInfoListeners::OnBrightnessChangedCallback(device_callback_e type, void* value, void* user_data)
+{
+ if (nullptr != m_camera_flash_listener) {
+ SysteminfoInstance* instance = static_cast<SysteminfoInstance*>(user_data);
+ m_camera_flash_listener(*instance);
+ }
+}
+
void SystemInfoListeners::InitTapiHandles()
{
LoggerD("Entered");
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) {
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)
{
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;
};
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)) {
var _simStr = SystemInfoPropertyId.SIM;
var _peripheralStr = SystemInfoPropertyId.PERIPHERAL;
var _memoryStr = SystemInfoPropertyId.MEMORY;
+var _cameraFlashStr = SystemInfoPropertyId.CAMERA_FLASH;
var _nextId = 0;
}
}
-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 = {
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";
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";
}
SysteminfoInstance::SysteminfoInstance() {
+
using std::placeholders::_1;
using std::placeholders::_2;
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");
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");
}
}
+void OnBrigthnessChangedCallback(SysteminfoInstance &instance)
+{
+ LoggerD("");
+ const std::shared_ptr<picojson::value>& response =
+ std::shared_ptr<picojson::value>(new picojson::value(picojson::object()));
+ response->get<picojson::object>()[kPropertyIdString] = picojson::value(kPropertyIdCameraFlash);
+ response->get<picojson::object>()[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<picojson::object>());
+ instance.PostMessage(response->serialize().c_str());
+ }
+}
+
} // namespace systeminfo
} // namespace extension