From b9529768db5176b449a1a961d934c31b5c2a2f57 Mon Sep 17 00:00:00 2001 From: Yunmi Ha Date: Tue, 5 Jan 2021 17:53:49 +0900 Subject: [PATCH] Use libsyscommon for list and ini-parser Change-Id: I1d0f41b21ecac551962dca3bec702a4d9cf59441 Signed-off-by: Yunmi Ha --- src/callback.c | 40 +++++++++---------- src/common.c | 122 --------------------------------------------------------- src/common.h | 10 ----- src/haptic.c | 32 +++++++-------- src/list.h | 83 --------------------------------------- src/power.c | 1 + 6 files changed, 37 insertions(+), 251 deletions(-) delete mode 100644 src/list.h diff --git a/src/callback.c b/src/callback.c index 5e2dd59..f973d06 100644 --- a/src/callback.c +++ b/src/callback.c @@ -22,12 +22,12 @@ #include #include #include +#include #include "callback.h" #include "battery.h" #include "display.h" #include "common.h" -#include "list.h" #define SIGNAL_FLASH_STATE "ChangeFlashState" @@ -36,7 +36,7 @@ struct device_cb_info { void *data; }; -static dd_list *device_cb_list[DEVICE_CALLBACK_MAX]; +static list *device_cb_list[DEVICE_CALLBACK_MAX]; static int flash_sigid; //LCOV_EXCL_START Not called Callback @@ -44,13 +44,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; + list *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) + 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 +60,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; + list *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) + 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 +76,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; + list *elem, *elem_next; int val, status; val = vconf_keynode_get_int(key); @@ -95,7 +95,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) + 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 +105,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; + list *elem, *elem_next; display_state_e state; int val; @@ -123,7 +123,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) + 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 +139,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; + list *elem, *elem_next; int val; if (strncmp(signal, SIGNAL_FLASH_STATE, @@ -153,7 +153,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) + LIST_FOREACH_SAFE(device_cb_list[type], elem, elem_next, cb_info) cb_info->cb(type, (void*)val, cb_info->data); } //LCOV_EXCL_STOP @@ -289,7 +289,7 @@ 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; + list *elem, *elem_next; int ret, n; if (!is_display_supported() && type == DEVICE_CALLBACK_DISPLAY_STATE) @@ -302,7 +302,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 = LIST_LENGTH(device_cb_list[type]); if (n == 0) { ret = register_request(type); if (ret < 0) @@ -310,7 +310,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) { + LIST_FOREACH_SAFE(device_cb_list[type], elem, elem_next, cb_info) { if (cb_info->cb == cb) return DEVICE_ERROR_ALREADY_IN_PROGRESS; } @@ -323,7 +323,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); + LIST_APPEND(device_cb_list[type], cb_info); return DEVICE_ERROR_NONE; } @@ -331,7 +331,7 @@ 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; + list *elem, *elem_next; int ret, n; if (!is_display_supported() && type == DEVICE_CALLBACK_DISPLAY_STATE) @@ -344,7 +344,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) { + LIST_FOREACH_SAFE(device_cb_list[type], elem, elem_next, cb_info) { if (cb_info->cb == cb) break; } @@ -353,11 +353,11 @@ 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); + 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 = LIST_LENGTH(device_cb_list[type]); if (n == 0) { ret = release_request(type); if (ret < 0) diff --git a/src/common.c b/src/common.c index 893c7b9..a35a612 100644 --- a/src/common.c +++ b/src/common.c @@ -22,133 +22,11 @@ #include "common.h" #include -#define MAX_LINE 128 -#define MAX_SECTION 64 -#define WHITESPACE " \t" -#define NEWLINE "\n\r" -#define COMMENT '#' - #define MODEL_NAME "http://tizen.org/system/model_name" #define MODEL_EMULATOR "Emulator" #define DISPLAY_FEATURE "http://tizen.org/feature/display" #define DISPLAY_STATE_FEATURE "http://tizen.org/feature/display.state" -static inline char *trim_str(char *s) -{ - char *t; - /* left trim */ - s += strspn(s, WHITESPACE); - - /* right trim */ - for (t = strchr(s, 0); t > s; t--) - if (!strchr(WHITESPACE, t[-1])) - break; - *t = 0; - return s; -} - -int config_parse(const char *file_name, int cb(struct parse_result *result, - void *user_data), void *user_data) -{ - FILE *f = NULL; - struct parse_result result; - /* use stack for parsing */ - char line[MAX_LINE]; - char section[MAX_SECTION]; - char *start, *end, *name, *value; - int lineno = 0, ret = 0; - - if (!file_name || !cb) { -//LCOV_EXCL_START System Error - ret = -EINVAL; - goto error; -//LCOV_EXCL_STOP - } - - /* open conf file */ - f = fopen(file_name, "r"); - if (!f) { -//LCOV_EXCL_START System Error - if (errno == ENOENT) { - _I("There is no power config file"); - return 0; -//LCOV_EXCL_STOP - } - -//LCOV_EXCL_START System Error - _E("Failed to open file %s", file_name); - ret = -EIO; - goto error; -//LCOV_EXCL_STOP - } - - /* parsing line by line */ - while (fgets(line, MAX_LINE, f) != NULL) { - lineno++; - - start = line; - start[strcspn(start, NEWLINE)] = '\0'; - start = trim_str(start); - - if (*start == COMMENT) { - continue; - } else if (*start == '[') { - /* parse section */ - end = strchr(start, ']'); - if (!end || *end != ']') { -//LCOV_EXCL_START System Error - ret = -EBADMSG; - goto error; -//LCOV_EXCL_STOP - } - - *end = '\0'; - strncpy(section, start + 1, sizeof(section)); - section[MAX_SECTION-1] = '\0'; - } else if (*start) { - /* parse name & value */ - end = strchr(start, '='); - if (!end || *end != '=') { -//LCOV_EXCL_START System Error - ret = -EBADMSG; - goto error; -//LCOV_EXCL_STOP - } - *end = '\0'; - name = trim_str(start); - value = trim_str(end + 1); - end = strchr(value, COMMENT); - if (end && *end == COMMENT) { - *end = '\0'; - value = trim_str(value); - } - - result.section = section; - result.name = name; - result.value = value; - /* callback with parse result */ - ret = cb(&result, user_data); - if (ret < 0) { -//LCOV_EXCL_START System Error - ret = -EBADMSG; - goto error; -//LCOV_EXCL_STOP - } - } - } - _D("Success to load %s", file_name); - fclose(f); - return 0; - -//LCOV_EXCL_START System Error -error: - if (f) - fclose(f); - _E("Failed to read %s:%d!", file_name, lineno); -//LCOV_EXCL_STOP - return ret; -} - tizen_profile_t _get_tizen_profile() { static tizen_profile_t profile = TIZEN_PROFILE_UNKNOWN; diff --git a/src/common.h b/src/common.h index 273ed79..ad87d86 100644 --- a/src/common.h +++ b/src/common.h @@ -56,16 +56,6 @@ static inline int errno_to_device_error(int err) } } -struct parse_result { - char *section; - char *name; - char *value; -}; - -int config_parse(const char *file_name, - int cb(struct parse_result *result, void *data), - void *user_data); - typedef enum { TIZEN_PROFILE_UNKNOWN = 0, TIZEN_PROFILE_MOBILE = 0x1, diff --git a/src/haptic.c b/src/haptic.c index 19d7383..d4e75f9 100644 --- a/src/haptic.c +++ b/src/haptic.c @@ -22,10 +22,10 @@ #include #include #include +#include #include "haptic.h" #include "common.h" -#include "list.h" #define SIGNAL_VIBRATOR_INITIATED "InitiateVibrator" @@ -54,7 +54,7 @@ struct haptic_handle { }; static guint haptic_id = 0; -static dd_list *handle_list; +static list *handle_list; static int is_haptic_supported(void) { @@ -107,11 +107,11 @@ int device_haptic_get_count(int *device_number) //LCOV_EXCL_START Not called Callback static void restart_callback(void) { - dd_list *elem, *elem_next; + list *elem, *elem_next; struct haptic_handle *temp; int ret; - DD_LIST_FOREACH_SAFE(handle_list, elem, elem_next, temp) { + LIST_FOREACH_SAFE(handle_list, elem, elem_next, temp) { ret = dbus_handle_method_sync_var(VIBRATOR_BUS_NAME, VIBRATOR_PATH_HAPTIC, VIBRATOR_INTERFACE_HAPTIC, METHOD_OPEN_DEVICE, g_variant_new("(i)", temp->index)); @@ -154,7 +154,7 @@ static void haptic_signal_callback(GDBusConnection *conn, int device_haptic_open(int device_index, haptic_device_h *device_handle) { - dd_list *elem, *elem_next; + list *elem, *elem_next; struct haptic_handle *handle; struct haptic_handle *temp; int ret, max; @@ -181,7 +181,7 @@ int device_haptic_open(int device_index, haptic_device_h *device_handle) if (ret < 0) return errno_to_device_error(ret); //LCOV_EXCL_LINE System Error - DD_LIST_FOREACH_SAFE(handle_list, elem, elem_next, temp) { + LIST_FOREACH_SAFE(handle_list, elem, elem_next, temp) { if (temp->handle == ret) { found = true; temp->index = device_index; @@ -200,10 +200,10 @@ int device_haptic_open(int device_index, haptic_device_h *device_handle) handle->handle = ret; handle->index = device_index; - DD_LIST_APPEND(handle_list, handle); + LIST_APPEND(handle_list, handle); *device_handle = (haptic_device_h)handle; } - if (DD_LIST_LENGTH(handle_list) == 1) { + if (LIST_LENGTH(handle_list) == 1) { haptic_id = subscribe_dbus_signal(NULL, VIBRATOR_PATH_HAPTIC, VIBRATOR_INTERFACE_HAPTIC, @@ -220,7 +220,7 @@ int device_haptic_open(int device_index, haptic_device_h *device_handle) int device_haptic_close(haptic_device_h device_handle) { - dd_list *elem, *elem_next; + list *elem, *elem_next; struct haptic_handle *handle = (struct haptic_handle *)device_handle; struct haptic_handle *temp; int ret; @@ -233,7 +233,7 @@ int device_haptic_close(haptic_device_h device_handle) if (!ret) return DEVICE_ERROR_NOT_SUPPORTED; - DD_LIST_FOREACH_SAFE(handle_list, elem, elem_next, temp) { + LIST_FOREACH_SAFE(handle_list, elem, elem_next, temp) { if (temp->handle != handle->handle) continue; found = true; @@ -242,7 +242,7 @@ int device_haptic_close(haptic_device_h device_handle) if (!found) return DEVICE_ERROR_OPERATION_FAILED; - DD_LIST_REMOVE(handle_list, handle); + LIST_REMOVE(handle_list, handle); /* request to deviced to open haptic device */ ret = dbus_handle_method_sync_var(VIBRATOR_BUS_NAME, @@ -254,7 +254,7 @@ int device_haptic_close(haptic_device_h device_handle) if (ret < 0) return errno_to_device_error(ret); //LCOV_EXCL_LINE System Error - if (DD_LIST_LENGTH(handle_list) == 0) + if (LIST_LENGTH(handle_list) == 0) unsubscribe_dbus_signal(NULL, haptic_id); return DEVICE_ERROR_NONE; @@ -262,7 +262,7 @@ int device_haptic_close(haptic_device_h device_handle) int device_haptic_vibrate(haptic_device_h device_handle, int duration, int feedback, haptic_effect_h *effect_handle) { - dd_list *elem, *elem_next; + list *elem, *elem_next; struct haptic_handle *handle = (struct haptic_handle *)device_handle; struct haptic_handle *temp; int ret, priority; @@ -283,7 +283,7 @@ int device_haptic_vibrate(haptic_device_h device_handle, int duration, int feedb priority = HAPTIC_PRIORITY_MIN; - DD_LIST_FOREACH_SAFE(handle_list, elem, elem_next, temp) { + LIST_FOREACH_SAFE(handle_list, elem, elem_next, temp) { if (temp != handle) continue; found = true; @@ -308,7 +308,7 @@ int device_haptic_vibrate(haptic_device_h device_handle, int duration, int feedb int device_haptic_stop(haptic_device_h device_handle, haptic_effect_h effect_handle) { - dd_list *elem, *elem_next; + list *elem, *elem_next; struct haptic_handle *handle = (struct haptic_handle *)device_handle; struct haptic_handle *temp; int ret; @@ -321,7 +321,7 @@ int device_haptic_stop(haptic_device_h device_handle, haptic_effect_h effect_han if (!ret) return DEVICE_ERROR_NOT_SUPPORTED; - DD_LIST_FOREACH_SAFE(handle_list, elem, elem_next, temp) { + LIST_FOREACH_SAFE(handle_list, elem, elem_next, temp) { if (temp != handle) continue; found = true; diff --git a/src/list.h b/src/list.h deleted file mode 100644 index 712ca70..0000000 --- a/src/list.h +++ /dev/null @@ -1,83 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __LIST_H__ -#define __LIST_H__ - -#include - -#define EINA_LIST_APPEND(a, b) \ - a = eina_list_append(a, b) - -#define EINA_LIST_REMOVE(a, b) \ - a = eina_list_remove(a, b) - -#define EINA_LIST_REMOVE_LIST(a, b) \ - a = eina_list_remove_list(a, b) - -#define EINA_LIST_FREE_LIST(a) \ - a = eina_list_free(a) - -#define EINA_LIST_PROMOTE_LIST(a, b) \ - a = eina_list_promote_list(a, b) - -#ifdef EINA_LIST -#include -typedef Eina_List dd_list; -#define DD_LIST_PREPEND(a, b) \ - a = eina_list_prepend(a, b) -#define DD_LIST_APPEND(a, b) \ - a = eina_list_append(a, b) -#define DD_LIST_REMOVE(a, b) \ - a = eina_list_remove(a, b) -#define DD_LIST_LENGTH(a) \ - eina_list_count(a) -#define DD_LIST_NTH(a, b) \ - eina_list_nth(a, b) -#define DD_LIST_FREE_LIST(a) \ - a = eina_list_free(a) -#define DD_LIST_FOREACH(head, elem, node) \ - EINA_LIST_FOREACH(head, elem, node) -#define DD_LIST_FOREACH_SAFE(head, elem, elem_next, node) \ - EINA_LIST_FOREACH_SAFE(head, elem, elem_next, node) - -#else -#include -typedef GList dd_list; -#define DD_LIST_PREPEND(a, b) \ - a = g_list_prepend(a, (gpointer)b) -#define DD_LIST_APPEND(a, b) \ - a = g_list_append(a, (gpointer)b) -#define DD_LIST_REMOVE(a, b) \ - a = g_list_remove(a, (gpointer)b) -#define DD_LIST_LENGTH(a) \ - g_list_length(a) -#define DD_LIST_NTH(a, b) \ - g_list_nth_data(a, b) -#define DD_LIST_FREE_LIST(a) \ - g_list_free(a) -#define DD_LIST_FOREACH(head, elem, node) \ - for (elem = head, node = NULL; elem && ((node = elem->data) != NULL); elem = elem->next, node = NULL) -#define DD_LIST_FOREACH_SAFE(head, elem, elem_next, node) \ - for (elem = head, elem_next = g_list_next(elem), node = NULL; \ - elem && ((node = elem->data) != NULL); \ - elem = elem_next, elem_next = g_list_next(elem), node = NULL) - -#endif - -#endif diff --git a/src/power.c b/src/power.c index 2d62928..325a313 100644 --- a/src/power.c +++ b/src/power.c @@ -24,6 +24,7 @@ #include #include #include +#include #include "power.h" #include "power-internal.h" -- 2.7.4