Add display feature for headless profile
[platform/core/api/device.git] / src / callback.c
index f4d7d45..b3cf676 100644 (file)
 #include <errno.h>
 #include <vconf.h>
 #include <gio/gio.h>
+#include <libsyscommon/dbus-system.h>
+#include <libsyscommon/list.h>
 
 #include "callback.h"
 #include "battery.h"
 #include "display.h"
+#include "display-internal.h"
 #include "common.h"
-#include "dbus.h"
-#include "list.h"
 
 #define SIGNAL_FLASH_STATE  "ChangeFlashState"
 
@@ -36,7 +37,7 @@ struct device_cb_info {
        void *data;
 };
 
-static dd_list *device_cb_list[DEVICE_CALLBACK_MAX];
+static GList *device_cb_list[DEVICE_CALLBACK_MAX];
 static int flash_sigid;
 
 //LCOV_EXCL_START Not called Callback
@@ -44,13 +45,13 @@ static void battery_capacity_cb(keynode_t *key, void *data)
 {
        static device_callback_e type = DEVICE_CALLBACK_BATTERY_CAPACITY;
        struct device_cb_info *cb_info;
-       dd_list *elem, *elem_next;
+       GList *elem, *elem_next;
        int val;
 
        val = vconf_keynode_get_int(key);
 
        /* invoke the each callback with value */
-       DD_LIST_FOREACH_SAFE(device_cb_list[type], elem, elem_next, cb_info)
+       SYS_G_LIST_FOREACH_SAFE(device_cb_list[type], elem, elem_next, cb_info)
                cb_info->cb(type, (void*)val, cb_info->data);
 }
 //LCOV_EXCL_STOP
@@ -60,13 +61,13 @@ static void battery_charging_cb(keynode_t *key, void *data)
 {
        static device_callback_e type = DEVICE_CALLBACK_BATTERY_CHARGING;
        struct device_cb_info *cb_info;
-       dd_list *elem, *elem_next;
+       GList *elem, *elem_next;
        int val;
 
        val = vconf_keynode_get_int(key);
 
        /* invoke the each callback with value */
-       DD_LIST_FOREACH_SAFE(device_cb_list[type], elem, elem_next, cb_info)
+       SYS_G_LIST_FOREACH_SAFE(device_cb_list[type], elem, elem_next, cb_info)
                cb_info->cb(type, (void*)val, cb_info->data);
 }
 //LCOV_EXCL_STOP
@@ -76,7 +77,7 @@ static void battery_level_cb(keynode_t *key, void *data)
 {
        static device_callback_e type = DEVICE_CALLBACK_BATTERY_LEVEL;
        struct device_cb_info *cb_info;
-       dd_list *elem, *elem_next;
+       GList *elem, *elem_next;
        int val, status;
 
        val = vconf_keynode_get_int(key);
@@ -95,7 +96,7 @@ static void battery_level_cb(keynode_t *key, void *data)
                status = -1;
 
        /* invoke the each callback with value */
-       DD_LIST_FOREACH_SAFE(device_cb_list[type], elem, elem_next, cb_info)
+       SYS_G_LIST_FOREACH_SAFE(device_cb_list[type], elem, elem_next, cb_info)
                cb_info->cb(type, (void*)status, cb_info->data);
 }
 //LCOV_EXCL_STOP
@@ -105,7 +106,7 @@ static void display_changed_cb(keynode_t *key, void *data)
 {
        static device_callback_e type = DEVICE_CALLBACK_DISPLAY_STATE;
        struct device_cb_info *cb_info;
-       dd_list *elem, *elem_next;
+       GList *elem, *elem_next;
        display_state_e state;
        int val;
 
@@ -123,7 +124,7 @@ static void display_changed_cb(keynode_t *key, void *data)
        }
 
        /* invoke the each callback with value */
-       DD_LIST_FOREACH_SAFE(device_cb_list[type], elem, elem_next, cb_info)
+       SYS_G_LIST_FOREACH_SAFE(device_cb_list[type], elem, elem_next, cb_info)
                cb_info->cb(type, (void*)state, cb_info->data);
 }
 //LCOV_EXCL_STOP
@@ -139,7 +140,7 @@ static void flash_state_cb(GDBusConnection *conn,
 {
        static int type = DEVICE_CALLBACK_FLASH_BRIGHTNESS;
        struct device_cb_info *cb_info;
-       dd_list *elem, *elem_next;
+       GList *elem, *elem_next;
        int val;
 
        if (strncmp(signal, SIGNAL_FLASH_STATE,
@@ -153,7 +154,7 @@ static void flash_state_cb(GDBusConnection *conn,
        _D("%s - %d", signal, val);
 
        /* invoke the each callback with value */
-       DD_LIST_FOREACH_SAFE(device_cb_list[type], elem, elem_next, cb_info)
+       SYS_G_LIST_FOREACH_SAFE(device_cb_list[type], elem, elem_next, cb_info)
                cb_info->cb(type, (void*)val, cb_info->data);
 }
 //LCOV_EXCL_STOP
@@ -175,9 +176,11 @@ static int register_signal(const char *bus_name,
 
        conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
        if (!conn) {
-               _E("fail to get dbus connection : %s", err->message); //LCOV_EXCL_LINE
-               g_clear_error(&err); //LCOV_EXCL_LINE System Error
+//LCOV_EXCL_START System Error
+               _E("fail to get dbus connection : %s", err->message);
+               g_clear_error(&err);
                return -EPERM;
+//LCOV_EXCL_STOP
        }
 
        /* subscribe signal */
@@ -192,8 +195,10 @@ static int register_signal(const char *bus_name,
                        NULL,
                        NULL);
        if (id == 0) {
-               _E("fail to connect %s signal", signal); //LCOV_EXCL_LINE
+//LCOV_EXCL_START System Error
+               _E("fail to connect %s signal", signal);
                return -EPERM;
+//LCOV_EXCL_STOP
        }
 
        if (sig_id)
@@ -212,9 +217,11 @@ static int unregister_signal(int *sig_id)
 
        conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
        if (!conn) {
-               _E("fail to get dbus connection : %s", err->message); //LCOV_EXCL_LINE
-               g_clear_error(&err); //LCOV_EXCL_LINE System Error
+//LCOV_EXCL_START System Error
+               _E("fail to get dbus connection : %s", err->message);
+               g_clear_error(&err);
                return -EPERM;
+//LCOV_EXCL_STOP
        }
 
        /* unsubscribe signal */
@@ -283,10 +290,10 @@ static int release_request(device_callback_e type)
 int device_add_callback(device_callback_e type, device_changed_cb cb, void *data)
 {
        struct device_cb_info *cb_info;
-       dd_list *elem, *elem_next;
+       GList *elem, *elem_next;
        int ret, n;
 
-       if (!is_display_supported() && type == DEVICE_CALLBACK_DISPLAY_STATE)
+       if (!is_feature_display_supported() && type == DEVICE_CALLBACK_DISPLAY_STATE)
                return DEVICE_ERROR_NOT_SUPPORTED;
 
        if (type < 0 || type >= DEVICE_CALLBACK_MAX)
@@ -296,7 +303,7 @@ int device_add_callback(device_callback_e type, device_changed_cb cb, void *data
                return DEVICE_ERROR_INVALID_PARAMETER;
 
        /* check if it is the first request */
-       n = DD_LIST_LENGTH(device_cb_list[type]);
+       n = SYS_G_LIST_LENGTH(device_cb_list[type]);
        if (n == 0) {
                ret = register_request(type);
                if (ret < 0)
@@ -304,7 +311,7 @@ int device_add_callback(device_callback_e type, device_changed_cb cb, void *data
        }
 
        /* check for the same request */
-       DD_LIST_FOREACH_SAFE(device_cb_list[type], elem, elem_next, cb_info) {
+       SYS_G_LIST_FOREACH_SAFE(device_cb_list[type], elem, elem_next, cb_info) {
                if (cb_info->cb == cb)
                        return DEVICE_ERROR_ALREADY_IN_PROGRESS;
        }
@@ -317,7 +324,7 @@ int device_add_callback(device_callback_e type, device_changed_cb cb, void *data
        cb_info->cb = cb;
        cb_info->data = data;
 
-       DD_LIST_APPEND(device_cb_list[type], cb_info);
+       SYS_G_LIST_APPEND(device_cb_list[type], cb_info);
 
        return DEVICE_ERROR_NONE;
 }
@@ -325,10 +332,10 @@ int device_add_callback(device_callback_e type, device_changed_cb cb, void *data
 int device_remove_callback(device_callback_e type, device_changed_cb cb)
 {
        struct device_cb_info *cb_info;
-       dd_list *elem, *elem_next;
+       GList *elem, *elem_next;
        int ret, n;
 
-       if (!is_display_supported() && type == DEVICE_CALLBACK_DISPLAY_STATE)
+       if (!is_feature_display_supported() && type == DEVICE_CALLBACK_DISPLAY_STATE)
                return DEVICE_ERROR_NOT_SUPPORTED;
 
        if (type < 0 || type >= DEVICE_CALLBACK_MAX)
@@ -338,7 +345,7 @@ int device_remove_callback(device_callback_e type, device_changed_cb cb)
                return DEVICE_ERROR_INVALID_PARAMETER;
 
        /* search for the same element with callback */
-       DD_LIST_FOREACH_SAFE(device_cb_list[type], elem, elem_next, cb_info) {
+       SYS_G_LIST_FOREACH_SAFE(device_cb_list[type], elem, elem_next, cb_info) {
                if (cb_info->cb == cb)
                        break;
        }
@@ -347,15 +354,15 @@ int device_remove_callback(device_callback_e type, device_changed_cb cb)
                return DEVICE_ERROR_INVALID_PARAMETER;
 
        /* remove device callback from list (local) */
-       DD_LIST_REMOVE(device_cb_list[type], cb_info);
+       SYS_G_LIST_REMOVE(device_cb_list[type], cb_info);
        free(cb_info);
 
        /* check if this callback is last element */
-       n = DD_LIST_LENGTH(device_cb_list[type]);
+       n = SYS_G_LIST_LENGTH(device_cb_list[type]);
        if (n == 0) {
                ret = release_request(type);
                if (ret < 0)
-                       return DEVICE_ERROR_OPERATION_FAILED;
+                       return DEVICE_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE System Error
        }
 
        return DEVICE_ERROR_NONE;