capi-system-device: Add flash brightness callback function 55/39755/2
authorJiyoung Yun <jy910.yun@samsung.com>
Fri, 22 May 2015 04:09:01 +0000 (13:09 +0900)
committerJiyoung Yun <jy910.yun@samsung.com>
Fri, 22 May 2015 04:24:35 +0000 (13:24 +0900)
enum: DEVICE_CALLBACK_FLASH_BRIGHTNESS
value: Changed brightness

Flash led can't control camera flash when camera API preempted flash.
In this case, led api will return DEVICE_ERROR_RESOURCE_BUSY error.

Change-Id: Iecfd19e05de83a2de56fff126034d19349f57c9f
Signed-off-by: Jiyoung Yun <jy910.yun@samsung.com>
CMakeLists.txt
capi-system-device.pc.in
include/callback.h
packaging/capi-system-device.spec
src/callback.c

index 974e587..d6c80d6 100755 (executable)
@@ -10,11 +10,8 @@ SET(PREFIX ${CMAKE_INSTALL_PREFIX})
 SET(INC_DIR include)
 INCLUDE_DIRECTORIES(${INC_DIR})
 
-SET(dependents "dlog vconf dbus-1 dbus-glib-1 capi-base-common capi-system-info")
-SET(pc_dependents "capi-base-common")
-
 INCLUDE(FindPkgConfig)
-pkg_check_modules(${fw_name} REQUIRED ${dependents})
+pkg_check_modules(${fw_name} REQUIRED dlog vconf dbus-1 dbus-glib-1 capi-base-common capi-system-info gio-2.0)
 FOREACH(flag ${${fw_name}_CFLAGS})
     SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
 ENDFOREACH(flag)
index ef89a5e..30f2af2 100644 (file)
@@ -9,6 +9,6 @@ includedir=/usr/include
 Name: @PC_NAME@
 Description: @PACKAGE_DESCRIPTION@
 Version: @VERSION@
-Requires: @PC_REQUIRED@
+Requires: capi-base-common
 Libs: -L${libdir} @PC_LDFLAGS@
 Cflags: -I${includedir} -I/usr/include/system
index 45f6cf7..1a7ee5d 100755 (executable)
@@ -41,6 +41,7 @@ typedef enum
     DEVICE_CALLBACK_BATTERY_LEVEL,       /**< Called when a battery level is changed */
     DEVICE_CALLBACK_BATTERY_CHARGING,    /**< Called when battery charging state is changed */
     DEVICE_CALLBACK_DISPLAY_STATE,       /**< Called when a display state is changed */
+    DEVICE_CALLBACK_FLASH_BRIGHTNESS,    /**< Called when a flash brightness is changed (Since Tizen 2.4) */
     DEVICE_CALLBACK_MAX
 } device_callback_e;
 
@@ -52,10 +53,13 @@ typedef enum
  *          DEVICE_CALLBACK_BATTERY_CAPACITY        int \n
  *          DEVICE_CALLBACK_BATTERY_LEVEL           int \n
  *          DEVICE_CALLBACK_BATTERY_CHARGING        bool \n
- *          DEVICE_CALLBACK_DISPLAY_STATE           int
+ *          DEVICE_CALLBACK_DISPLAY_STATE           int \n
+ *          DEVICE_CALLBACK_FLASH_BRIGHTNESS        int
  *
  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
  *
+ * @remarks DEVICE_CALLBACK_FLASH_BRIGHTNESS callback invoked when user set flash brightness by using device_flash_set_brightness(). It does not work by camera flash operation. To register DEVICE_CALLBACK_FLASH_BRIGHTNESS callback, you need to declare the LED privilege (%http://tizen.org/privilege/led).
+ *
  * @param[out] type          The device type to monitor
  * @param[out] value         The changed value \n
  * @param[out] user_data     The user data passed from the callback registration function
index 52e176e..55dc255 100644 (file)
@@ -13,6 +13,7 @@ BuildRequires:  pkgconfig(dlog)
 BuildRequires:  pkgconfig(vconf)
 BuildRequires:  pkgconfig(dbus-1)
 BuildRequires:  pkgconfig(dbus-glib-1)
+BuildRequires:  pkgconfig(gio-2.0)
 
 %description
 A Device library in TIZEN C API package.
index 39dd5ef..b9867da 100644 (file)
@@ -20,6 +20,7 @@
 #include <string.h>
 #include <errno.h>
 #include <vconf.h>
+#include <gio/gio.h>
 
 #include "callback.h"
 #include "battery.h"
 #include "dbus.h"
 #include "list.h"
 
+#define SIGNAL_FLASH_STATE  "ChangeFlashState"
+
 struct device_cb_info {
        device_changed_cb cb;
        void *data;
 };
 
 static dd_list *device_cb_list[DEVICE_CALLBACK_MAX];
+static int flash_sigid;
 
 static void battery_capacity_cb(keynode_t *key, void *data)
 {
@@ -116,6 +120,100 @@ static void display_changed_cb(keynode_t *key, void *data)
                cb_info->cb(type, (void*)state, cb_info->data);
 }
 
+static void flash_state_cb(GDBusConnection *conn,
+               const gchar *sender,
+               const gchar *object,
+               const gchar *interface,
+               const gchar *signal,
+               GVariant *parameters,
+               gpointer user_data)
+{
+       static int type = DEVICE_CALLBACK_FLASH_BRIGHTNESS;
+       struct device_cb_info *cb_info;
+       dd_list *elem;
+       int val;
+
+       if (strncmp(signal, SIGNAL_FLASH_STATE,
+                               sizeof(SIGNAL_FLASH_STATE)) != 0) {
+               _E("wrong parameter : signal(%s)", signal);
+               return;
+       }
+
+       /* get camera value */
+       g_variant_get(parameters, "(i)", &val);
+       _D("%s - %d", signal, val);
+
+       /* invoke the each callback with value */
+       DD_LIST_FOREACH(device_cb_list[type], elem, cb_info)
+               cb_info->cb(type, (void*)val, cb_info->data);
+}
+
+static int register_signal(const char *bus_name,
+               const char *object_path,
+               const char *interface_name,
+               const char *signal,
+               GDBusSignalCallback callback,
+               int *sig_id)
+{
+       GError *err = NULL;
+       GDBusConnection *conn;
+       int id;
+
+#if !GLIB_CHECK_VERSION(2,35,0)
+       g_type_init();
+#endif
+
+       conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
+       if (!conn) {
+               _E("fail to get dbus connection : %s", err->message);
+               g_clear_error(&err);
+               return -EPERM;
+       }
+
+       /* subscribe signal */
+       id = g_dbus_connection_signal_subscribe(conn,
+                       bus_name,
+                       interface_name,
+                       signal,         /* null to match on all signals */
+                       object_path,
+                       NULL,           /* null to match on all kinds of arguments */
+                       G_DBUS_SIGNAL_FLAGS_NONE,
+                       callback,
+                       NULL,
+                       NULL);
+       if (id == 0) {
+               _E("fail to connect %s signal", signal);
+               return -EPERM;
+       }
+
+       if (sig_id)
+               *sig_id = id;
+
+       return 0;
+}
+
+static int unregister_signal(int *sig_id)
+{
+       GError *err = NULL;
+       GDBusConnection *conn;
+
+       if (!sig_id)
+               return -EINVAL;
+
+       conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
+       if (!conn) {
+               _E("fail to get dbus connection : %s", err->message);
+               g_clear_error(&err);
+               return -EPERM;
+       }
+
+       /* unsubscribe signal */
+       g_dbus_connection_signal_unsubscribe(conn, *sig_id);
+       *sig_id = 0;
+
+       return 0;
+}
+
 static int register_request(device_callback_e type)
 {
        switch (type) {
@@ -131,6 +229,14 @@ static int register_request(device_callback_e type)
        case DEVICE_CALLBACK_DISPLAY_STATE:
                return vconf_notify_key_changed(VCONFKEY_PM_STATE,
                                display_changed_cb, NULL);
+       case DEVICE_CALLBACK_FLASH_BRIGHTNESS:
+               /* sig_id begins with 1. */
+               if (flash_sigid)
+                       return -EEXIST;
+               return register_signal(DEVICED_BUS_NAME,
+                               DEVICED_PATH_LED,
+                               DEVICED_INTERFACE_LED,
+                               SIGNAL_FLASH_STATE, flash_state_cb, &flash_sigid);
        default:
                break;
        }
@@ -153,6 +259,10 @@ static int release_request(device_callback_e type)
        case DEVICE_CALLBACK_DISPLAY_STATE:
                return vconf_ignore_key_changed(VCONFKEY_PM_STATE,
                                display_changed_cb);
+       case DEVICE_CALLBACK_FLASH_BRIGHTNESS:
+               if (!flash_sigid)
+                       return -ENOENT;
+               return unregister_signal(&flash_sigid);
        default:
                break;
        }