From 34e6a2eb2ecedeeeeeaa61b0d302288128259f07 Mon Sep 17 00:00:00 2001 From: taeyoung Date: Mon, 25 Jul 2016 17:27:10 +0900 Subject: [PATCH 01/16] block: remove unused variables Change-Id: Icbe575f938a7ddcc2c84e34a2c7325c398d2655d Signed-off-by: taeyoung --- src/block/block.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/block/block.c b/src/block/block.c index 6aecd83..d6cee71 100644 --- a/src/block/block.c +++ b/src/block/block.c @@ -2226,7 +2226,6 @@ static int add_device_to_iter(struct block_data *data, DBusMessageIter *piter) static int add_device_to_struct_iter(struct block_data *data, DBusMessageIter *iter) { DBusMessageIter piter; - char *str_null = ""; if (!data || !iter) return -EINVAL; @@ -2547,7 +2546,6 @@ static DBusMessage *request_get_mmc_primary(E_DBus_Object *obj, DBusMessage *msg struct block_device *bdev; struct block_data *data, nodata = {0,}; dd_list *elem; - int ret; bool found; if (!obj || !msg) -- 2.7.4 From 2c541ac99eb76adcc1ba1626dcc7250dbf5b0f24 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Bollo?= Date: Mon, 22 Jun 2015 15:32:42 +0200 Subject: [PATCH 02/16] Removes hidden dependency MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The depedency to the project platform/adaptation/system-plugin that provides tizen-system-env.service is missing. This removes the hidden dependency. This is a hack. Please either explicit the dependency in spec file or keep that removal. Change-Id: Id480a018a036ecbc3a76b15d2424e94c23cc4546 Signed-off-by: José Bollo Signed-off-by: taeyoung --- systemd/deviced.service | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/systemd/deviced.service b/systemd/deviced.service index 2c1c155..3cf62e0 100644 --- a/systemd/deviced.service +++ b/systemd/deviced.service @@ -1,10 +1,9 @@ [Unit] Description=System device daemon After=deviced-pre.service -Requires=deviced-pre.service tizen-system-env.service +Requires=deviced-pre.service [Service] -EnvironmentFile=-/run/tizen-system-env EnvironmentFile=/run/deviced/deviced_env SmackProcessLabel=System::Privileged ExecStart=/usr/bin/deviced -- 2.7.4 From 123af3bfea654058c9e967e931deebea0d40ff5b Mon Sep 17 00:00:00 2001 From: taeyoung Date: Wed, 27 Jul 2016 17:24:48 +0900 Subject: [PATCH 03/16] libdeviced: remove unused apis Change-Id: I4c3e34e0bc2d530c52c68fa2ce37518b09eff3af Signed-off-by: taeyoung --- src/deviced/dd-battery.h | 147 -------------------------------- src/deviced/dd-display.h | 175 -------------------------------------- src/libdeviced/CMakeLists.txt | 2 - src/libdeviced/battery.c | 58 ------------- src/libdeviced/control.c | 134 ----------------------------- src/libdeviced/display.c | 192 ------------------------------------------ 6 files changed, 708 deletions(-) delete mode 100644 src/deviced/dd-battery.h delete mode 100644 src/libdeviced/battery.c delete mode 100644 src/libdeviced/control.c diff --git a/src/deviced/dd-battery.h b/src/deviced/dd-battery.h deleted file mode 100644 index 72beda3..0000000 --- a/src/deviced/dd-battery.h +++ /dev/null @@ -1,147 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. - * - * 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 __DD_BATTERY_H__ -#define __DD_BATTERY_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @file dd-battery.h - * @defgroup CAPI_SYSTEM_DEVICED_BATTERY_MODULE Battery - * @ingroup CAPI_SYSTEM_DEVICED - * @brief This file provides the API for control of battery - * @section CAPI_SYSTEM_DEVICED_BATTERY_MODULE_HEADER Required Header - * \#include - */ - -/** - * @addtogroup CAPI_SYSTEM_DEVICED_BATTERY_MODULE - * @{ - */ - -/** - * @par Description - * Battery Health status - */ -enum { - BAT_UNKNOWN = 0, - BAT_GOOD, - BAT_OVERHEAT, - BAT_DEAD, - BAT_OVERVOLTAGE, - BAT_UNSPECIFIED, - BAT_COLD, - BAT_HEALTH_MAX, -}; - -/** - * @par Description: - * This API is used to get the remaining battery percentage.\n - * It gets the Battery percentage by calling device_get_property() function.\n - * It returns integer value(0~100) that indicates remaining batterty percentage on success.\n - * Or a negative value(-1) is returned on failure. - * @return On success, integer value(0~100) is returned. - * Or a negative value(-1) is returned on failure. - * @see battery_is_full(), battery_get_percent_raw() - * @par Example - * @code - * ... - * int battery; - * battery = battery_get_percent(); - * if( battery < 0 ) - * printf("Fail to get the remaining battery percentage.\n"); - * else - * printf("remaining battery percentage : %d\n", battery); - * ... - * @endcode - */ -int battery_get_percent(void); - -/** - * @par Description: - * This API is used to get the remaining battery percentage expressed 1/10000.\n - * It gets the Battery percentage by calling device_get_property() function.\n - * It returns integer value(0~10000) that indicates remaining batterty percentage on success.\n - * Or a negative value(-1) is returned on failure. - * @return On success, integer value(0~10000) is returned. - * Or a negative value(-1) is returned on failure. - * @see battery_is_full(), battery_get_percent() - * @par Example - * @code - * ... - * int battery; - * battery = battery_get_percent_raw(); - * if( battery < 0 ) - * printf("Fail to get the remaining battery percentage.\n"); - * else - * printf("remaining battery percentage expressed 1/10000 : %d\n", battery); - * ... - * @endcode - */ -int battery_get_percent_raw(void); - -/** - * @par Description: - * This API is used to get the fully charged status of battery.\n - * It gets the fully charged status of Battery by calling device_get_property() function.\n - * If the status of battery is full, it returns 1.\n - * Or a negative value(-1) is returned, if the status of battery is not full. - * @return 1 with battery full, or 0 on not full-charged, -1 if failed - * @see battery_get_percent() - * @par Example - * @code - * ... - * if( battery_is_full() > 0 ) - * printf("battery fully chared\n"); - * ... - * @endcode - */ -int battery_is_full(void); - -/** - * @par Description: - * This API is used to get the battery health status.\n - * It gets the battery health status by calling device_get_property() function.\n - * It returns integer value(0~7) that indicate battery health status on success.\n - * Or a negative value(-1) is returned, if the status of battery is not full. - * @return integer value, -1 if failed\n - * (0 BATTERY_UNKNOWN, 1 GOOD, 2 OVERHEAT, 3 DEAD, 4 OVERVOLTAGE, 5 UNSPECIFIED, 6 COLD, 7 BAT_HEALTH_MAX) - * @par Example - * @code - * ... - * int bat_health; - * bat_health = battery_get_health(); - * if( bat_health != BAT_GOOD ) - * printf("battery health is not good\n"); - * ... - * @endcode - */ -int battery_get_health(void); - -/** - * @} // end of CAPI_SYSTEM_DEVICED_BATTERY_MODULE - */ - -#ifdef __cplusplus -} -#endif -#endif diff --git a/src/deviced/dd-display.h b/src/deviced/dd-display.h index ad36ec8..f7a7101 100644 --- a/src/deviced/dd-display.h +++ b/src/deviced/dd-display.h @@ -67,22 +67,6 @@ extern "C" { #define PM_KEEP_TIMER 0x2 /**< keep timer for unlock */ /** - * @brief This API is used to get number of displays on the phone.\n - * @details It returns enum value which is the current number on success.\n - * Or a negative value(-1) is returned on failure. - * @return 0 on success, -1 if failed - * @par Example - * @code - * ... - * ret = display_get_count(); - * if( ret < 0 ) - * printf("Fail to get number of displays\n"); - * ... - * @endcode - */ -int display_get_count(void); - -/** * @brief This API is used to get the max brightness of the display.\n * @details It gets the current brightness of the display * by calling device_get_property() function.\n @@ -104,48 +88,6 @@ int display_get_count(void); int display_get_max_brightness(void); /** - * @brief This API is used to get the min brightness of the display.\n - * @details It gets the current brightness of the display - * by calling device_get_property() function.\n - * It returns integer value which is the min brightness on success.\n - * Or a negative value(-1) is returned on failure - * @return min brightness value on success, negative if failed - * @par Example - * @code - * ... - * int min_brt; - * min_brt = display_get_min_brightness(); - * if( min_brt < 0 ) - * printf("Fail to get the min brightness of the display.\n"); - * else - * printf("Min brightness of the display is %d\n", min_brt); - * ... - * @endcode - */ -int display_get_min_brightness(void); - -/** - * @brief This API is used to get the current brightness of the display.\n - * @details It gets the current brightness of the display - * by calling device_get_property() function.\n - * It returns integer value which is the current brightness on success.\n - * Or a negative value(-1) is returned on failure. - * @return current brightness value on success, negative if failed - * @par Example - * @code - * ... - * int cur_brt; - * cur_brt = display_get_brightness(); - * if( cur_brt < 0 ) - * printf("Fail to get the current brightness of the display.\n"); - * else - * printf("Current brightness of the display is %d\n", cur_brt); - * ... - * @endcode - */ -int display_get_brightness(void); - -/** * @brief This API is used to set the current brightness of the display * and system brightness value in settings.\n * @details It sets the current brightness of the display @@ -170,107 +112,6 @@ int display_get_brightness(void); */ int display_set_brightness_with_setting(int val); -/** - * @brief This API is used to set the current brightness of the display.\n - * @details It sets the current brightness of the display - * by calling device_set_property() function.\n - * MUST use this API very carefully. \n - * you MUST set original brightness by display_release_brightness(), - * after you finish your job using this API. - * @param[in] val brightness value that you want to set - * @return 0 on success, negative if failed - * @see display_get_brightness(), display_release_brightness() - * @par Example - * @code - * ... - * if( display_set_brightness(6) < 0 ) - * printf("Fail to set the current brightness of the display\n"); - * else - * printf("The current brightness of the display is set 6\n"); - * ... - * @endcode - */ -int display_set_brightness(int val); - -/** - * @brief This API is used to release brightness control.\n - * @details It sets the current brightness of the display - * by calling device_set_property() function.\n - * MUST call this API after you finished the job - * which need to change the brightness. - * @return 0 on success, negative if failed - * @see display_set_brightness() - * @par Example - * @code - * ... - * org_val = display_get_brightness(); - * display_set_brightness(1); - * ... - * ret = display_release_brightness(); - * if( ret < 0 ) - * printf("Fail to release brightness control\n"); - * ... - * @endcode - */ -int display_release_brightness(void); - -/** - * @brief This API is used to get the current state for acl.\n - * @details It gets the current state for acl - * by calling device_get_property() function.\n - * @return current status for acl(1 on, 0 off) on success, negative if failed - * @see display_set_acl_status() - * @par Example - * @code - * ... - * int acl_stat; - * acl_stat = display_get_acl_status(); - * if( acl_stat < 0 ) - * printf("Fail to get the current status for acl.\n"); - * else - * printf("Current status for acl is %d\n", cur_brt); - * ... - * @endcode - */ -int display_get_acl_status(void); - -/** - * @brief This API is used to set the current status for acl.\n - * @details It sets the current status for acl - * by calling device_set_property() function.\n - * @param[in] val status for acl(1 on, 0 off) that you want to set - * @return 0 on success, negative if failed - * @see display_get_acl_status() - * @par Example - * @code - * ... - * if( display_set_acl_status(0) < 0 ) - * printf("Fail to set the current status for acl\n"); - * else - * printf("The current status for acl is set 6\n"); - * ... - * @endcode - */ -int display_set_acl_status(int val); - -/** - * @brief This API is used to set frame rate of display.\n - * @param[in] val frame rate - * @return 0 on success, negative if failed - * @par Example - * @code - * ... - * if( display_set_frame_rate() < 0 ) - * printf("Fail to set display frame rate\n"); - * ... - * @endcode - * @todo describe range of val - */ -int display_set_frame_rate(int val) DEPRECATED; - -/** - * @brief refresh app - setting, video, camera - */ enum refresh_app { REFRESH_SETTING, REFRESH_VIDEO, @@ -279,22 +120,6 @@ enum refresh_app { }; /** - * @brief This API is used to set refresh rate of display.\n - * @param[in] app caller application type - * @param[in] val refresh rate - * @return 0 on success, negative if failed - * @par Example - * @code - * ... - * if( display_set_refresh_rate(REFRESH_SETTING, 60) < 0 ) - * printf("Fail to set display refresh rate\n"); - * ... - * @endcode - * @todo describe range of val - */ -int display_set_refresh_rate(enum refresh_app app, int val); - -/** * @brief This API is used to lock a particular display state * as the current display-state.\n * @details The parameter state specifies the display state which diff --git a/src/libdeviced/CMakeLists.txt b/src/libdeviced/CMakeLists.txt index 6b03c58..8ca1402 100755 --- a/src/libdeviced/CMakeLists.txt +++ b/src/libdeviced/CMakeLists.txt @@ -2,8 +2,6 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) PROJECT(libdeviced C) SET(LIBDEVICED_SRCS - battery.c - control.c display.c dbus.c haptic.c diff --git a/src/libdeviced/battery.c b/src/libdeviced/battery.c deleted file mode 100644 index 8606ac6..0000000 --- a/src/libdeviced/battery.c +++ /dev/null @@ -1,58 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. - * - * 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. - */ - - -#include -#include - -#include "log.h" -#include "dbus.h" -#include "common.h" - -#define METHOD_GET_PERCENT "GetPercent" -#define METHOD_GET_PERCENT_RAW "GetPercentRaw" -#define METHOD_IS_FULL "IsFull" -#define METHOD_GET_HEALTH "GetHealth" - -API int battery_get_percent(void) -{ - return dbus_method_sync(DEVICED_BUS_NAME, - DEVICED_PATH_BATTERY, DEVICED_INTERFACE_BATTERY, - METHOD_GET_PERCENT, NULL, NULL); -} - -API int battery_get_percent_raw(void) -{ - return dbus_method_sync(DEVICED_BUS_NAME, - DEVICED_PATH_BATTERY, DEVICED_INTERFACE_BATTERY, - METHOD_GET_PERCENT_RAW, NULL, NULL); -} - -API int battery_is_full(void) -{ - return dbus_method_sync(DEVICED_BUS_NAME, - DEVICED_PATH_BATTERY, DEVICED_INTERFACE_BATTERY, - METHOD_IS_FULL, NULL, NULL); -} - -API int battery_get_health(void) -{ - return dbus_method_sync(DEVICED_BUS_NAME, - DEVICED_PATH_BATTERY, DEVICED_INTERFACE_BATTERY, - METHOD_GET_HEALTH, NULL, NULL); -} diff --git a/src/libdeviced/control.c b/src/libdeviced/control.c deleted file mode 100644 index cc94947..0000000 --- a/src/libdeviced/control.c +++ /dev/null @@ -1,134 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. - * - * 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. - */ - - -#include -#include -#include -#include - -#include "log.h" -#include "dbus.h" -#include "common.h" -#include "dd-control.h" - -#define CONTROL_HANDLER_NAME "control" -#define CONTROL_GETTER_NAME "getcontrol" - -static int deviced_control_common(int device, bool enable) -{ - DBusError err; - DBusMessage *msg; - char *pa[5]; - int ret, val; - char buf_pid[6]; - char buf_dev[3]; - char buf_enable[2]; - - snprintf(buf_pid, sizeof(buf_pid), "%d", getpid()); - snprintf(buf_dev, sizeof(buf_dev), "%d", device); - snprintf(buf_enable, sizeof(buf_enable), "%d", enable); - - pa[0] = CONTROL_HANDLER_NAME; - pa[1] = "3"; - pa[2] = buf_pid; - pa[3] = buf_dev; - pa[4] = buf_enable; - - msg = dbus_method_sync_with_reply(DEVICED_BUS_NAME, - DEVICED_PATH_SYSNOTI, DEVICED_INTERFACE_SYSNOTI, - pa[0], "sisss", pa); - if (!msg) - return -EBADMSG; - - dbus_error_init(&err); - - ret = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &val, DBUS_TYPE_INVALID); - if (!ret) { - _E("no message : [%s:%s]", err.name, err.message); - val = -EBADMSG; - } - - dbus_message_unref(msg); - dbus_error_free(&err); - - _D("%s-%s : %d", DEVICED_INTERFACE_SYSNOTI, pa[0], val); - return val; -} - -static int deviced_get_control(int device, void *data) -{ - DBusError err; - DBusMessage *msg; - char *pa[4]; - int ret, val; - char buf_pid[6]; - char buf_dev[3]; - - snprintf(buf_pid, sizeof(buf_pid), "%d", getpid()); - snprintf(buf_dev, sizeof(buf_dev), "%d", device); - - pa[0] = CONTROL_GETTER_NAME; - pa[1] = "2"; - pa[2] = buf_pid; - pa[3] = buf_dev; - - msg = dbus_method_sync_with_reply(DEVICED_BUS_NAME, - DEVICED_PATH_SYSNOTI, DEVICED_INTERFACE_SYSNOTI, - pa[0], "siss", pa); - if (!msg) - return -EBADMSG; - - dbus_error_init(&err); - - ret = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &val, DBUS_TYPE_INVALID); - if (!ret) { - _E("no message : [%s:%s]", err.name, err.message); - val = -EBADMSG; - } - - dbus_message_unref(msg); - dbus_error_free(&err); - - _D("%s-%s : %d", DEVICED_INTERFACE_SYSNOTI, pa[0], val); - return val; -} - - -/* - * example of control api - * API int deviced_display_control(bool enable) - * { - * return deviced_control_common(DEVICE_CONTROL_DISPLAY, enable); - * } - */ - -API int deviced_mmc_control(bool enable) -{ - return deviced_control_common(DEVICE_CONTROL_MMC, enable); -} - -API int deviced_usb_control(bool enable) -{ - return deviced_control_common(DEVICE_CONTROL_USBCLIENT, enable); -} - -API int deviced_get_usb_control(void) -{ - return deviced_get_control(DEVICE_CONTROL_USBCLIENT, NULL); -} diff --git a/src/libdeviced/display.c b/src/libdeviced/display.c index d60cfe4..f9174b2 100644 --- a/src/libdeviced/display.c +++ b/src/libdeviced/display.c @@ -59,31 +59,6 @@ #define STR_RESET_TIMER "resettimer" #define STR_KEEP_TIMER "keeptimer" -API int display_get_count(void) -{ - DBusError err; - DBusMessage *msg; - int ret, ret_val; - - msg = dbus_method_sync_with_reply(DEVICED_BUS_NAME, - DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, - METHOD_GET_DISPLAY_COUNT, NULL, NULL); - if (!msg) - return -EBADMSG; - - dbus_error_init(&err); - - ret = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &ret_val, DBUS_TYPE_INVALID); - if (!ret) { - _E("no message : [%s:%s]", err.name, err.message); - dbus_error_free(&err); - ret_val = -EBADMSG; - } - - dbus_message_unref(msg); - return ret_val; -} - API int display_get_max_brightness(void) { int ret; @@ -98,36 +73,6 @@ API int display_get_max_brightness(void) return ret; } -API int display_get_min_brightness(void) -{ - return DISPLAY_MIN_BRIGHTNESS; -} - -API int display_get_brightness(void) -{ - DBusError err; - DBusMessage *msg; - int ret, ret_val; - - msg = dbus_method_sync_with_reply(DEVICED_BUS_NAME, - DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, - METHOD_GET_BRIGHTNESS, NULL, NULL); - if (!msg) - return -EBADMSG; - - dbus_error_init(&err); - - ret = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &ret_val, DBUS_TYPE_INVALID); - if (!ret) { - _E("no message : [%s:%s]", err.name, err.message); - dbus_error_free(&err); - ret_val = -EBADMSG; - } - - dbus_message_unref(msg); - return ret_val; -} - API int display_set_brightness_with_setting(int val) { char str_val[32]; @@ -149,137 +94,6 @@ API int display_set_brightness_with_setting(int val) return ret; } -API int display_set_brightness(int val) -{ - DBusError err; - DBusMessage *msg; - char str_val[32]; - char *arr[1]; - int ret, ret_val; - - snprintf(str_val, sizeof(str_val), "%d", val); - arr[0] = str_val; - - msg = dbus_method_sync_with_reply(DEVICED_BUS_NAME, - DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, - METHOD_HOLD_BRIGHTNESS, "i", arr); - if (!msg) - return -EBADMSG; - - dbus_error_init(&err); - - ret = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &ret_val, DBUS_TYPE_INVALID); - if (!ret) { - _E("no message : [%s:%s]", err.name, err.message); - dbus_error_free(&err); - ret_val = -EBADMSG; - } - - dbus_message_unref(msg); - return ret_val; -} - -API int display_release_brightness(void) -{ - DBusError err; - DBusMessage *msg; - int ret, ret_val; - - msg = dbus_method_sync_with_reply(DEVICED_BUS_NAME, - DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, - METHOD_RELEASE_BRIGHTNESS, NULL, NULL); - if (!msg) - return -EBADMSG; - - dbus_error_init(&err); - - ret = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &ret_val, DBUS_TYPE_INVALID); - if (!ret) { - _E("no message : [%s:%s]", err.name, err.message); - dbus_error_free(&err); - ret_val = -EBADMSG; - } - - dbus_message_unref(msg); - return ret_val; -} - -API int display_get_acl_status(void) -{ - DBusError err; - DBusMessage *msg; - int ret, ret_val; - - msg = dbus_method_sync_with_reply(DEVICED_BUS_NAME, - DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, - METHOD_GET_ACL_STATUS, NULL, NULL); - if (!msg) - return -EBADMSG; - - dbus_error_init(&err); - - ret = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &ret_val, DBUS_TYPE_INVALID); - if (!ret) { - _E("no message : [%s:%s]", err.name, err.message); - dbus_error_free(&err); - ret_val = -EBADMSG; - } - - dbus_message_unref(msg); - return ret_val; -} - -API int display_set_acl_status(int val) -{ - DBusError err; - DBusMessage *msg; - char str_val[32]; - char *arr[1]; - int ret, ret_val; - - snprintf(str_val, sizeof(str_val), "%d", val); - arr[0] = str_val; - - msg = dbus_method_sync_with_reply(DEVICED_BUS_NAME, - DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, - METHOD_SET_ACL_STATUS, "i", arr); - if (!msg) - return -EBADMSG; - - dbus_error_init(&err); - - ret = dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &ret_val, DBUS_TYPE_INVALID); - if (!ret) { - _E("no message : [%s:%s]", err.name, err.message); - dbus_error_free(&err); - ret_val = -EBADMSG; - } - - dbus_message_unref(msg); - return ret_val; -} - -API int display_set_refresh_rate(enum refresh_app app, int val) -{ - char str_app[32]; - char str_val[32]; - char *arr[2]; - - snprintf(str_app, sizeof(str_app), "%d", app); - arr[0] = str_app; - snprintf(str_val, sizeof(str_val), "%d", val); - arr[1] = str_val; - - return dbus_method_sync(DEVICED_BUS_NAME, - DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, - METHOD_SET_REFRESH_RATE, "ii", arr); -} - -API int display_set_frame_rate(int val) -{ - return display_set_refresh_rate(REFRESH_SETTING, val); -} - static inline char *get_lcd_str(unsigned int val) { switch (val) { @@ -445,9 +259,3 @@ API int display_unlock_state(unsigned int s_bits, unsigned int flag) return ret; } - -API void display_set_timeout(unsigned int normal, unsigned int dim, unsigned int lock) -{ - return; -} - -- 2.7.4 From 2d451eeaf595ed4ee38925b43b8acc036f639c17 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Pawe=C5=82=20Szewczyk?= Date: Wed, 10 Feb 2016 13:32:13 +0100 Subject: [PATCH 04/16] usbhost: Add API for handling device attach/detach MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Change-Id: Ie333f7b403721f7b0611c57d172a930d1b1fc456 Signed-off-by: Paweł Szewczyk --- src/deviced/dd-usbhost.h | 77 ++++++++++++++++++++ src/libdeviced/usbhost.c | 185 ++++++++++++++++++++++++++++++++++------------- src/usbhost/usb-host.c | 12 +-- 3 files changed, 216 insertions(+), 58 deletions(-) diff --git a/src/deviced/dd-usbhost.h b/src/deviced/dd-usbhost.h index eff38b0..9bae8ae 100644 --- a/src/deviced/dd-usbhost.h +++ b/src/deviced/dd-usbhost.h @@ -36,6 +36,24 @@ extern "C" { * @{ */ +#include +struct usbhost_device { + char devpath[PATH_MAX]; /* unique info. */ + int baseclass; + int subclass; + int protocol; + int vendorid; + int productid; + char *manufacturer; + char *product; + char *serial; +}; + +enum usbhost_state { + USB_HOST_REMOVED, + USB_HOST_ADDED, +}; + /** * @par Description: * This API is used to initialize usbhost signal \n @@ -100,6 +118,37 @@ int register_usb_storage_change_handler( /** * @par Description: + * This API is used to register usbhost signal \n + * @param[in] device_changed callback function which is called when the device is connected/disconnected + * @param[in] data parameter of the callback function + * @return 0 on success, negative if failed + * @par Example + * @code + * ... + * if (init_usbhost_signal() < 0) + * printf("Failed to initialize usbhost signal\n"); + * + * if (register_usb_device_change_handler(device_cb, data) < 0) { + * printf("Failed to register device handler\n"); + * deinit_usbhost_signal(); + * return; + * } + * + * // Do something + * + * if (unregister_usb_device_changed_handler() < 0) + * printf("Failed to unregister device changed signal\n"); + * + * deinit_usbhost_signal(); + * ... + * @endcode + */ +int register_usb_device_change_handler( + void (*device_changed)(struct usbhost_device *device, int state, void *data), + void *data); + +/** + * @par Description: * This API is used to unregister usbhost signal \n * @return 0 on success, negative if failed * @par Example @@ -127,6 +176,34 @@ int unregister_usb_storage_change_handler(void); /** * @par Description: + * This API is used to unregister usb connect/disconnect signal handler\n + * @return 0 on success, negative if failed + * @par Example + * @code + * ... + * if (init_usbhost_signal() < 0) + * printf("Failed to initialize usbhost signal\n"); + * + * if (register_usb_device_change_handler(device_cb, data) < 0) { + * printf("Failed to register device signal\n"); + * deinit_usbhost_signal(); + * return; + * } + * + * // Do something + * + * if (unregister_usb_device_change_handler() < 0) + * printf("Failed to unregister storage signal\n"); + * + * deinit_usbhost_signal(); + * ... + * @endcode + */ +int unregister_usb_device_change_handler( + void (*device_changed)(struct usbhost_device *device, int state, void *data)); + +/** + * @par Description: * This API is used to request usb storage information \n * @return 0 on success, negative if failed * @par Example diff --git a/src/libdeviced/usbhost.c b/src/libdeviced/usbhost.c index 747be17..fae5d8a 100644 --- a/src/libdeviced/usbhost.c +++ b/src/libdeviced/usbhost.c @@ -24,6 +24,8 @@ #include "log.h" #include "common.h" #include "dbus.h" +#include "dd-usbhost.h" +#include "core/list.h" #define ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0])) @@ -33,27 +35,32 @@ #define METHOD_REQUEST_STORAGE_UNMOUNT "StorageUnmount" #define METHOD_REQUEST_STORAGE_FORMAT "StorageFormat" #define SIGNAL_NAME_USB_STORAGE_CHANGED "usb_storage_changed" +#define SIGNAL_NAME_USB_DEVICE_CHANGED "ChangedDevice" #define RETRY_MAX 5 +union action { + void (*storage)(char *type, char *path, int mount, void *param); + void (*device)(struct usbhost_device *device, int state, void *data); +}; + struct signal_handler { - char *name; + const char *name; E_DBus_Signal_Handler *handler; - void (*action)(char *type, char *path, int mount, void *param); + union action action; void *data; }; -static struct signal_handler handlers[] = { - { SIGNAL_NAME_USB_STORAGE_CHANGED , NULL, NULL, NULL }, -}; +static dd_list *handlers; static E_DBus_Connection *conn = NULL; static int register_edbus_signal_handler(const char *path, const char *interface, const char *name, E_DBus_Signal_Cb cb, - void (*action)(char *type, char *path, int mount, void *param), + union action action, void *data) { - int i, ret; + int ret; + struct signal_handler *handler = NULL; if (!conn) { _E("Use init_usbhost_signal() first to use this function"); @@ -61,45 +68,39 @@ static int register_edbus_signal_handler(const char *path, const char *interface goto out; } - for (i = 0 ; i < ARRAY_SIZE(handlers) ; i++) { - if (strncmp(handlers[i].name, name, strlen(name))) - continue; - break; - } - if (i >= ARRAY_SIZE(handlers)) { - _E("Failed to find \"storage_changed\" signal"); - ret = -1; - goto out; - } - - if (handlers[i].handler) { - _E("The handler is already registered"); - ret = -1; + handler = calloc(1, sizeof(*handler)); + if (!handler) { + _E("No memory"); goto out; } - - handlers[i].handler = e_dbus_signal_handler_add(conn, NULL, path, + handler->name = name; + handler->handler = e_dbus_signal_handler_add(conn, NULL, path, interface, name, cb, NULL); - if (!(handlers[i].handler)) { + if (!(handler->handler)) { _E("fail to add edbus handler"); ret = -1; goto out; } - handlers[i].action = action; - handlers[i].data = data; + + handler->action = action; + handler->data = data; + + DD_LIST_APPEND(handlers, handler); return 0; out: + free(handler); return ret; } static void storage_signal_handler(void *data, DBusMessage *msg) { - int i; char *type, *path; int mount; DBusError err; + dd_list *elem; + struct signal_handler *handler; if (dbus_message_is_signal(msg, DEVICED_INTERFACE_USBHOST, SIGNAL_NAME_USB_STORAGE_CHANGED) == 0) { _E("The signal is not for storage changed"); @@ -117,18 +118,55 @@ static void storage_signal_handler(void *data, DBusMessage *msg) return; } - for (i = 0 ; i < ARRAY_SIZE(handlers) ; i++) { - if (strcmp(handlers[i].name, SIGNAL_NAME_USB_STORAGE_CHANGED)) + DD_LIST_FOREACH(handlers, elem, handler) { + if (strcmp(handler->name, SIGNAL_NAME_USB_STORAGE_CHANGED)) continue; - break; + + if (handler->action.storage) + handler->action.storage(type, path, mount, handler->data); } - if (i >= ARRAY_SIZE(handlers)) { - _E("Failed to find \"storage_changed\" signal"); +} + +static void device_signal_handler(void *data, DBusMessage *msg) +{ + char *path; + struct usbhost_device device; + int state; + DBusError err; + struct signal_handler *handler; + dd_list *element; + + if (dbus_message_is_signal(msg, DEVICED_INTERFACE_USBHOST, SIGNAL_NAME_USB_DEVICE_CHANGED) == 0) { + _E("The signal is not ChangedDevice"); return; } - if (handlers[i].action) - handlers[i].action(type, path, mount, handlers[i].data); + dbus_error_init(&err); + if (dbus_message_get_args(msg, &err, + DBUS_TYPE_INT32, &state, + DBUS_TYPE_STRING, &path, + DBUS_TYPE_INT32, &device.baseclass, + DBUS_TYPE_INT32, &device.subclass, + DBUS_TYPE_INT32, &device.protocol, + DBUS_TYPE_INT32, &device.vendorid, + DBUS_TYPE_INT32, &device.productid, + DBUS_TYPE_STRING, &device.manufacturer, + DBUS_TYPE_STRING, &device.product, + DBUS_TYPE_STRING, &device.serial, + DBUS_TYPE_INVALID) == 0) { + _E("Failed to get device info"); + return; + } + + strncpy(device.devpath, path, PATH_MAX); + + DD_LIST_FOREACH(handlers, element, handler) { + if (strcmp(handler->name, SIGNAL_NAME_USB_DEVICE_CHANGED)) + continue; + + if (handler->action.device) + handler->action.device(&device, state, handler->data); + } } API int init_usbhost_signal(void) @@ -158,18 +196,20 @@ API int init_usbhost_signal(void) API void deinit_usbhost_signal(void) { - int i; + dd_list *n, *next; + struct signal_handler *handler; if (!conn) return; - for (i = 0 ; i < ARRAY_SIZE(handlers) ; i++) { - if (handlers[i].handler) { - e_dbus_signal_handler_del(conn, handlers[i].handler); - handlers[i].handler = NULL; + DD_LIST_FOREACH_SAFE(handlers, n, next, handler) { + DD_LIST_REMOVE(handlers, handler); + if (handler->handler) { + e_dbus_signal_handler_del(conn, handler->handler); + handler->handler = NULL; } - handlers[i].action = NULL; - handlers[i].data = NULL; + + free(handler); } e_dbus_connection_close(conn); @@ -185,36 +225,77 @@ API int request_usb_storage_info(void) } API int register_usb_storage_change_handler( - void (*storage_changed)(char *type, char *path, int mount, void *), + void (*storage_changed)(char *type, char *path, int mount, void *param), void *data) { + union action action; if (!storage_changed) return -EINVAL; + action.storage = storage_changed; return register_edbus_signal_handler(DEVICED_PATH_USBHOST, DEVICED_INTERFACE_USBHOST, SIGNAL_NAME_USB_STORAGE_CHANGED, storage_signal_handler, - storage_changed, + action, + data); +} + +API int register_usb_device_change_handler( + void (*device_changed)(struct usbhost_device *device, int state, void *data), + void *data) +{ + union action action; + if (!device_changed) + return -EINVAL; + + action.device = device_changed; + return register_edbus_signal_handler(DEVICED_PATH_USBHOST, + DEVICED_INTERFACE_USBHOST, + SIGNAL_NAME_USB_DEVICE_CHANGED, + device_signal_handler, + action, data); } API int unregister_usb_storage_change_handler(void) { - int i; + dd_list *n, *next; + struct signal_handler *handler; - for (i = 0 ; i < ARRAY_SIZE(handlers) ; i++) { - if (strcmp(handlers[i].name, SIGNAL_NAME_USB_STORAGE_CHANGED)) + DD_LIST_FOREACH_SAFE(handlers, n, next, handler) { + if (strcmp(handler->name, SIGNAL_NAME_USB_STORAGE_CHANGED)) continue; - if (handlers[i].handler == NULL) + if (handler->handler == NULL) continue; - e_dbus_signal_handler_del(conn, handlers[i].handler); - handlers[i].handler = NULL; - handlers[i].action = NULL; - handlers[i].data = NULL; - return 0; + e_dbus_signal_handler_del(conn, handler->handler); + DD_LIST_REMOVE(handlers, handler); + free(handler); } + + return 0; +} + +API int unregister_usb_device_change_handler( + void (*device_changed)(struct usbhost_device *device, int state, void *data)) +{ + dd_list *n, *next; + struct signal_handler *handler; + + DD_LIST_FOREACH_SAFE(handlers, n, next, handler) { + if (strcmp(handler->name, SIGNAL_NAME_USB_DEVICE_CHANGED)) + continue; + if (handler->handler == NULL) + continue; + if (handler->action.device != device_changed) + continue; + + e_dbus_signal_handler_del(conn, handler->handler); + DD_LIST_REMOVE(handlers, handler); + free(handler); + } + return -1; } diff --git a/src/usbhost/usb-host.c b/src/usbhost/usb-host.c index 99c1068..e4a48b8 100644 --- a/src/usbhost/usb-host.c +++ b/src/usbhost/usb-host.c @@ -29,6 +29,7 @@ #include "core/device-notifier.h" #include "core/udev.h" #include "core/list.h" +#include "core/device-idler.h" #define USB_INTERFACE_CLASS "bInterfaceClass" #define USB_INTERFACE_SUBCLASS "bInterfaceSubClass" @@ -45,7 +46,7 @@ #define ROOTPATH tzplatform_getenv(TZ_SYS_VAR) #define POLICY_FILENAME "usbhost-policy" -const char *POLICY_FILEPATH; +char *POLICY_FILEPATH; /** * Below usb host class is defined by www.usb.org. @@ -582,7 +583,6 @@ static int read_policy(void) FILE *fp; struct policy_entry *entry; char *line = NULL, value_str[256]; - char *p; int ret = -1; int count = 0; size_t len; @@ -608,7 +608,7 @@ static int read_policy(void) goto out; } - ret = sscanf(line, "%d %s %04x %02x %02x %02x %04x %04x %04x %s\n", + ret = sscanf(line, "%d %s %04hx %02hhx %02hhx %02hhx %04hx %04hx %04hx %s\n", &entry->creds.uid, entry->creds.sec_label, &entry->device.bcdUSB, @@ -831,7 +831,7 @@ static int creds_read_label(DBusMessageIter *iter, char **dest) static int get_caller_credentials(DBusMessage *msg, struct user_credentials *cred) { - char *cid; + const char *cid; char *key; char *arr[1]; DBusMessage *reply; @@ -846,7 +846,7 @@ static int get_caller_credentials(DBusMessage *msg, struct user_credentials *cre return -1; } - arr[0] = cid; + arr[0] = (char *)cid; reply = dbus_method_sync_with_reply(DBUS_BUS_NAME, DBUS_OBJECT_PATH, DBUS_INTERFACE_NAME, @@ -929,7 +929,7 @@ static DBusMessage *open_device(E_DBus_Object *obj, DBusMessage *msg) DBusError err; dbus_bool_t dbus_ret; int ret = 0, fd = -1; - const char *path; + char *path; struct user_credentials cred; dbus_error_init(&err); -- 2.7.4 From e930414678bc1092fd4b6b686ec73d815fc693a9 Mon Sep 17 00:00:00 2001 From: taeyoung Date: Wed, 3 Aug 2016 15:52:24 +0900 Subject: [PATCH 05/16] devicectl: add power off/reboot comand - Power off command $ devicectl power off - Reboot command $ devicectl power reboot Change-Id: I32abdd6c7cbb01ecd7b111ee5e8b25e6b3d33a2b Signed-off-by: taeyoung --- src/devicectl/devicectl.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/devicectl/devicectl.c b/src/devicectl/devicectl.c index 8d015b0..8734466 100644 --- a/src/devicectl/devicectl.c +++ b/src/devicectl/devicectl.c @@ -39,6 +39,7 @@ enum device_type { DEVICE_PASS, DEVICE_USB, DEVICE_EXTCON, + DEVICE_POWER, DEVICE_MAX, DEVICE_ALL, }; @@ -56,6 +57,7 @@ static const struct device { { DEVICE_PASS, "pass", DEVICED_PATH_PASS, DEVICED_INTERFACE_PASS }, { DEVICE_USB, "usb", DEVICED_PATH_USB, DEVICED_INTERFACE_USB }, { DEVICE_EXTCON, "extcon", DEVICED_PATH_EXTCON, DEVICED_INTERFACE_EXTCON }, + { DEVICE_POWER, "power", DEVICED_PATH_POWER, DEVICED_INTERFACE_POWER }, }; static int start_device(char **args) @@ -287,6 +289,39 @@ static int disable_device(char **args) return 0; } +static int power_operation(char **args, char *type) +{ + DBusMessage *msg; + char *arr[2]; + + if (!args[1] || !type) + return -EINVAL; + + printf("Power %s device!\n", args[2]); + + arr[0] = type; + arr[1] = "0"; + + msg = dbus_method_sync_with_reply(DEVICED_BUS_NAME, + devices[arg_id].path, devices[arg_id].iface, + "reboot", "si", arr); + if (!msg) + return -EBADMSG; + + dbus_message_unref(msg); + + return 0; +} +static int power_off(char *args) +{ + return power_operation(args, "poweroff"); +} + +static int power_reboot(char *args) +{ + return power_operation(args, "reboot"); +} + static const struct action { const enum device_type id; const char *action; @@ -305,6 +340,8 @@ static const struct action { { DEVICE_CORE, "devicelist", 3, device_list, "" }, { DEVICE_EXTCON, "enable", 4, enable_device, "[USB|HEADPHONE|HDMI|DOCK]" }, { DEVICE_EXTCON, "disable", 4, disable_device, "[USB|HEADPHONE|HDMI|DOCK]" }, + { DEVICE_POWER, "off", 3, power_off, "" }, + { DEVICE_POWER, "reboot", 3, power_reboot, "" }, }; static inline void usage() -- 2.7.4 From 657fa84fcf1213c6f9025bda2db478d73ec81126 Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Thu, 21 Jul 2016 16:52:50 +0900 Subject: [PATCH 06/16] block: Modify block module 1. Merge Block interface to BlockManager - Before, deviced creates new object for every device node, sends signal and receives dbus methods requests using Block interface. It cause some timing issues. - Now, block module will not creates new object for each node, and only have BlockManager interface. 2. Check queue has unmount operation before mount - If operation queue has unmount operation, then deviced doesn't need to mount device. So, deviced dequeue operations before unmount operation. 3. Check operation is already done - If operation is already done, deviced doesn't need to do it again. 4. Use specific number of thread - Maximum number of thread is 5. - If new block_device which use same devnode is inserted, same thread which used before dealt with the new block_device. - Each thread processes operation in the order of block_device is added to block_dev_list. - After operation queue is empty from one block_device, thread processes operation for next block_device. 5. Add thread mutex and thread wait condition - Add thread mutex for operation queue and op_len - Remove block_device mutex (which was for operation queue) - Wait when all operation queue of thread is empty (op_len == 0) - Wakeup when first operation is added (op_len is changed to 1) 6. Make block_dev_list for each thread - Use thread mutex for each block_dev_list of thread - Dbus method calls should not get information about physically removed block device 7. Same device is dealt with the same thread - All partitions from same device is dealt with the same thread 8. Remove BLOCK_DEV_DEQUEUE pipe command Change-Id: Ia4064de11afafdcbeb9811cf4884978f22f27b25 Signed-off-by: pr.jung --- src/block/block.c | 1058 +++++++++++++++++++++++++------------------------- src/libdeviced/mmc.c | 105 ++--- src/shared/dbus.h | 2 - 3 files changed, 563 insertions(+), 602 deletions(-) diff --git a/src/block/block.c b/src/block/block.c index d6cee71..43a9e40 100644 --- a/src/block/block.c +++ b/src/block/block.c @@ -57,6 +57,7 @@ #define MMC_LINK_PATH "*/sdcard/*" #define SCSI_PATH "*/sd[a-z]*" #define SCSI_PARTITION_PATH "sd[a-z][0-9]" +#define SCSI_PARTITION_LENGTH 9 #define FILESYSTEM "filesystem" @@ -65,13 +66,11 @@ #define UNMOUNT_RETRY 5 #define TIMEOUT_MAKE_OBJECT 500 /* milliseconds */ -#define BLOCK_OBJECT_ADDED "ObjectAdded" -#define BLOCK_OBJECT_REMOVED "ObjectRemoved" +#define BLOCK_DEVICE_ADDED "DeviceAdded" +#define BLOCK_DEVICE_REMOVED "DeviceRemoved" #define BLOCK_DEVICE_BLOCKED "DeviceBlocked" #define BLOCK_DEVICE_CHANGED "DeviceChanged" #define BLOCK_DEVICE_CHANGED_2 "DeviceChanged2" -#define BLOCK_DEVICE_ADDED "DeviceAdded" -#define BLOCK_DEVICE_REMOVED "DeviceRemoved" #define BLOCK_TYPE_MMC "mmc" #define BLOCK_TYPE_SCSI "scsi" @@ -87,13 +86,15 @@ /* For 2.4 Backward Compatibility */ #define EXT_PRIMARY_SD_FIXID 1 +/* Maximum number of thread */ +#define THREAD_MAX 5 + enum block_dev_operation { BLOCK_DEV_MOUNT, BLOCK_DEV_UNMOUNT, BLOCK_DEV_FORMAT, BLOCK_DEV_INSERT, BLOCK_DEV_REMOVE, - BLOCK_DEV_DEQUEUE, }; struct operation_queue { @@ -104,11 +105,10 @@ struct operation_queue { }; struct block_device { - E_DBus_Object *object; - pthread_mutex_t mutex; struct block_data *data; dd_list *op_queue; - bool th_alive; + int thread_id; /* Current thread ID */ + bool removed; /* True when device is physically removed but operation is not precessed yet */ }; struct format_data { @@ -127,23 +127,32 @@ static struct block_conf { bool multimount; } block_conf[BLOCK_MMC_DEV + 1]; +static struct manage_thread { + dd_list *th_node_list; /* List of devnode which thread dealt with. Only main thread access */ + dd_list *block_dev_list; /* Use thread mutex */ + pthread_t th; + pthread_mutex_t mutex; + pthread_cond_t cond; + int num_dev; /* Number of devices which thread holds. Only main thread access */ + int op_len; /* Number of operation of thread. Use thread mutex */ + int thread_id; /* Never changed */ + bool start_th; +} th_manager[THREAD_MAX]; + static dd_list *fs_head; -static dd_list *block_dev_list; -static dd_list *block_rm_list; static dd_list *block_ops_list; static bool smack; static int pfds[2]; static Ecore_Fd_Handler *phandler; -static E_DBus_Interface *iface; static bool block_control = false; static bool block_boot = false; -static pthread_mutex_t glob_mutex = PTHREAD_MUTEX_INITIALIZER; - static int add_operation(struct block_device *bdev, enum block_dev_operation operation, DBusMessage *msg, void *data); static void remove_operation(struct block_device *bdev); +static void check_removed(struct block_device *bdev, dd_list **queue, struct operation_queue **op); +static bool check_unmount(struct block_device *bdev, dd_list **queue, struct operation_queue **op); static void uevent_block_handler(struct udev_device *dev); static struct uevent_handler uh = { @@ -224,22 +233,30 @@ static void broadcast_block_info(enum block_dev_operation op, } } +// Called by MainThread - Insert static int block_get_new_id(void) { static int id = BLOCK_ID_MIN; struct block_device *bdev; dd_list *elem; bool found; - int i; + int i, j; for (i = 0 ; i < INT_MAX ; i++) { found = false; - DD_LIST_FOREACH(block_dev_list, elem, bdev) { - if (bdev->data->id == id) { - found = true; - break; + for (j = 0; j < THREAD_MAX; j++) { + pthread_mutex_lock(&(th_manager[j].mutex)); + DD_LIST_FOREACH(th_manager[j].block_dev_list, elem, bdev) { + if (bdev->data->id == id) { + found = true; + break; + } } + pthread_mutex_unlock(&(th_manager[j].mutex)); + if (found) + break; } + if (!found) return id++; @@ -255,7 +272,6 @@ static void signal_device_blocked(struct block_device *bdev) struct block_data *data; char *arr[2]; char *str_null = ""; - const char *object_path; if (!bdev || !bdev->data) return; @@ -266,14 +282,8 @@ static void signal_device_blocked(struct block_device *bdev) arr[0] = (data->fs_uuid_enc ? data->fs_uuid_enc : str_null); arr[1] = (data->mount_point ? data->mount_point : str_null); - object_path = e_dbus_object_path_get(bdev->object); - if (!object_path) { - _E("there is no object_path"); - return; - } - - broadcast_block_edbus_signal(object_path, - DEVICED_INTERFACE_BLOCK, + broadcast_block_edbus_signal(DEVICED_PATH_BLOCK_MANAGER, + DEVICED_INTERFACE_BLOCK_MANAGER, BLOCK_DEVICE_BLOCKED, "ss", arr); } @@ -290,7 +300,6 @@ static void signal_device_changed(struct block_device *bdev, char str_flags[32]; char str_id[32]; char *str_null = ""; - const char *object_path; int flags; if (!bdev || !bdev->data) @@ -313,7 +322,7 @@ static void signal_device_changed(struct block_device *bdev, break; } - /* Broadcast outside with Block iface */ + /* Broadcast outside with BlockManager iface */ snprintf(str_block_type, sizeof(str_block_type), "%d", data->block_type); arr[0] = str_block_type; @@ -338,29 +347,23 @@ static void signal_device_changed(struct block_device *bdev, snprintf(str_id, sizeof(str_id), "%d", data->id); arr[12] = str_id; - object_path = e_dbus_object_path_get(bdev->object); - if (!object_path) { - _E("there is no object_path"); - return; - } - if (op == BLOCK_DEV_INSERT) - broadcast_block_edbus_signal(object_path, - DEVICED_INTERFACE_BLOCK, + broadcast_block_edbus_signal(DEVICED_PATH_BLOCK_MANAGER, + DEVICED_INTERFACE_BLOCK_MANAGER, BLOCK_DEVICE_ADDED, "issssssisibii", arr); else if (op == BLOCK_DEV_REMOVE) - broadcast_block_edbus_signal(object_path, - DEVICED_INTERFACE_BLOCK, + broadcast_block_edbus_signal(DEVICED_PATH_BLOCK_MANAGER, + DEVICED_INTERFACE_BLOCK_MANAGER, BLOCK_DEVICE_REMOVED, "issssssisibii", arr); else { - broadcast_block_edbus_signal(object_path, - DEVICED_INTERFACE_BLOCK, + broadcast_block_edbus_signal(DEVICED_PATH_BLOCK_MANAGER, + DEVICED_INTERFACE_BLOCK_MANAGER, BLOCK_DEVICE_CHANGED, "issssssisibii", arr); - broadcast_block_edbus_signal(object_path, - DEVICED_INTERFACE_BLOCK, + broadcast_block_edbus_signal(DEVICED_PATH_BLOCK_MANAGER, + DEVICED_INTERFACE_BLOCK_MANAGER, BLOCK_DEVICE_CHANGED_2, "issssssisibi", arr); } @@ -601,89 +604,6 @@ static int update_block_data(struct block_data *data, return 0; } -static E_DBus_Object *make_block_object(const char *devnode, - struct block_data *data) -{ - E_DBus_Object *object; - char object_path[PATH_MAX]; - const char *name; - char *arr[1]; - dd_list *l; - struct block_device *bdev; - size_t len; - bool found; - struct timespec time = {0,}; - - if (!devnode) - return NULL; - - /* check if devnode has the /dev/ prefix */ - if (strncmp(devnode, DEV_PREFIX, strlen(DEV_PREFIX))) - return NULL; - - name = devnode + strlen(DEV_PREFIX); - snprintf(object_path, sizeof(object_path), - "%s/%s", DEVICED_PATH_BLOCK_DEVICES, name); - - len = strlen(devnode) + 1; - time.tv_nsec = TIMEOUT_MAKE_OBJECT * NANO_SECOND_MULTIPLIER; /* 500ms */ - do { - found = false; - pthread_mutex_lock(&glob_mutex); - DD_LIST_FOREACH(block_rm_list, l, bdev) { - if (strncmp(bdev->data->devnode, devnode, len)) - continue; - found = true; - break; - } - pthread_mutex_unlock(&glob_mutex); - - if (found) - nanosleep(&time , NULL); - } while (found); - - /* register block object */ - object = register_block_edbus_object(object_path, data); - if (!object) { - _E("Failed to register dbus object"); - goto error; - } - - /* attach interface to object */ - e_dbus_object_interface_attach(object, iface); - - /* Broadcast outside with BlockManager iface */ - arr[0] = object_path; - broadcast_block_edbus_signal(DEVICED_PATH_BLOCK_MANAGER, - DEVICED_INTERFACE_BLOCK_MANAGER, - BLOCK_OBJECT_ADDED, - "s", arr); - - return object; -error: - unregister_edbus_object(object); - return NULL; -} - -static void free_block_object(E_DBus_Object *object) -{ - char *arr[1]; - - if (!object) - return; - - /* Broadcast outside with BlockManager iface */ - arr[0] = (char *)e_dbus_object_path_get(object); - broadcast_block_edbus_signal(DEVICED_PATH_BLOCK_MANAGER, - DEVICED_INTERFACE_BLOCK_MANAGER, - BLOCK_OBJECT_REMOVED, - "s", arr); - - /* detach interface from object */ - e_dbus_object_interface_detach(object, iface); - unregister_edbus_object(object); -} - static struct block_device *make_block_device(struct block_data *data) { struct block_device *bdev; @@ -695,45 +615,86 @@ static struct block_device *make_block_device(struct block_data *data) if (!bdev) return NULL; - pthread_mutex_init(&bdev->mutex, NULL); bdev->data = data; - bdev->th_alive = false; + bdev->thread_id = -1; + bdev->removed = false; return bdev; } +// Called by MainThread - Remove DevNode static void free_block_device(struct block_device *bdev) { dd_list *l, *next; struct operation_queue *op; + int thread_id; if (!bdev) return; - pthread_mutex_lock(&bdev->mutex); + thread_id = bdev->thread_id; + if (thread_id < 0 || thread_id >= THREAD_MAX) + return; + + pthread_mutex_lock(&(th_manager[thread_id].mutex)); + + th_manager[thread_id].num_dev--; + DD_LIST_REMOVE(th_manager[thread_id].block_dev_list, bdev); free_block_data(bdev->data); - free_block_object(bdev->object); DD_LIST_FOREACH_SAFE(bdev->op_queue, l, next, op) { + if (!op->done) + th_manager[thread_id].op_len--; DD_LIST_REMOVE(bdev->op_queue, op); free(op); } - pthread_mutex_unlock(&bdev->mutex); + pthread_mutex_unlock(&(th_manager[thread_id].mutex)); free(bdev); } +// Called By MainThread - Remove Device static struct block_device *find_block_device(const char *devnode) { struct block_device *bdev; dd_list *elem; int len; + int i; len = strlen(devnode) + 1; - DD_LIST_FOREACH(block_dev_list, elem, bdev) { - if (bdev->data && - !strncmp(bdev->data->devnode, devnode, len)) - return bdev; + for (i = 0; i < THREAD_MAX; i++) { + pthread_mutex_lock(&(th_manager[i].mutex)); + DD_LIST_FOREACH(th_manager[i].block_dev_list, elem, bdev) { + if (bdev->data && + !strncmp(bdev->data->devnode, devnode, len)) { + pthread_mutex_unlock(&(th_manager[i].mutex)); + return bdev; + } + } + pthread_mutex_unlock(&(th_manager[i].mutex)); + } + + return NULL; +} + +// Called By MainThread - Mount,Unmount,Format,GetInfo +static struct block_device *find_block_device_by_id(int id) +{ + struct block_device *bdev; + dd_list *elem; + int i; + + for (i = 0; i < THREAD_MAX; i++) { + pthread_mutex_lock(&(th_manager[i].mutex)); + DD_LIST_FOREACH(th_manager[i].block_dev_list, elem, bdev) { + if (!bdev->data) + continue; + if (bdev->data->id == id) { + pthread_mutex_unlock(&(th_manager[i].mutex)); + return bdev; + } + } + pthread_mutex_unlock(&(th_manager[i].mutex)); } return NULL; @@ -763,9 +724,6 @@ static char *get_operation_char(enum block_dev_operation op, case BLOCK_DEV_REMOVE: str = "REMOVE"; break; - case BLOCK_DEV_DEQUEUE: - str = "DEQUEUE"; - break; default: _E("invalid operation (%d)", op); break; @@ -786,12 +744,8 @@ static int pipe_trigger(enum block_dev_operation op, get_operation_char(pdata.op, name, sizeof(name)), pdata.bdev, pdata.result); - pthread_mutex_lock(&glob_mutex); - n = write(pfds[1], &pdata, sizeof(struct pipe_data)); - pthread_mutex_unlock(&glob_mutex); - return (n != sizeof(struct pipe_data)) ? -EPERM : 0; } @@ -800,6 +754,7 @@ static Eina_Bool pipe_cb(void *data, Ecore_Fd_Handler *fdh) struct pipe_data pdata = {0,}; int fd; int n; + int thread_id; char name[16]; if (ecore_main_fd_handler_active_get(fdh, ECORE_FD_ERROR)) { @@ -823,11 +778,6 @@ static Eina_Bool pipe_cb(void *data, Ecore_Fd_Handler *fdh) get_operation_char(pdata.op, name, sizeof(name)), pdata.bdev, pdata.result); - if (pdata.op == BLOCK_DEV_DEQUEUE) { - remove_operation(pdata.bdev); - goto out; - } - /* Broadcast to mmc and usb storage module */ broadcast_block_info(pdata.op, pdata.bdev->data, pdata.result); @@ -835,10 +785,10 @@ static Eina_Bool pipe_cb(void *data, Ecore_Fd_Handler *fdh) signal_device_changed(pdata.bdev, pdata.op); if (pdata.op == BLOCK_DEV_REMOVE) { - pthread_mutex_lock(&glob_mutex); - DD_LIST_REMOVE(block_rm_list, pdata.bdev); + thread_id = pdata.bdev->thread_id; + if (thread_id < 0 || thread_id >= THREAD_MAX) + return ECORE_CALLBACK_RENEW; free_block_device(pdata.bdev); - pthread_mutex_unlock(&glob_mutex); } out: @@ -1329,35 +1279,22 @@ static void release_format_data(struct format_data *data) } } -static int block_insert_device(struct block_device *bdev, void *bdata) -{ - struct block_data *data = bdata; - - if (!bdev || !data) - return -EINVAL; - - /* create block object */ - bdev->object = make_block_object(data->devnode, data); - if (!bdev->object) { - _E("Failed to make block object"); - return -EIO; - } - - if (pipe_trigger(BLOCK_DEV_INSERT, bdev, 0) < 0) - _E("fail to trigger pipe"); - - return 0; -} - +// Called by BlockThread - Real Mount Op static int block_mount_device(struct block_device *bdev, void *data) { dd_list *l; int ret; + int thread_id; if (!bdev) return -EINVAL; - l = DD_LIST_FIND(block_dev_list, bdev); + thread_id = bdev->thread_id; + if (thread_id < 0 || thread_id >= THREAD_MAX) + return -EINVAL; + pthread_mutex_lock(&(th_manager[thread_id].mutex)); + l = DD_LIST_FIND(th_manager[thread_id].block_dev_list, bdev); + pthread_mutex_unlock(&(th_manager[thread_id].mutex)); if (!l) { _E("(%d) does not exist in the device list", bdev->data->devnode); return -ENOENT; @@ -1371,10 +1308,12 @@ static int block_mount_device(struct block_device *bdev, void *data) return ret; } +// Called by BlockThread - Real Format Op static int block_format_device(struct block_device *bdev, void *data) { dd_list *l; int ret; + int thread_id; struct format_data *fdata = (struct format_data *)data; if (!bdev || !fdata) { @@ -1382,7 +1321,12 @@ static int block_format_device(struct block_device *bdev, void *data) goto out; } - l = DD_LIST_FIND(block_dev_list, bdev); + thread_id = bdev->thread_id; + if (thread_id < 0 || thread_id >= THREAD_MAX) + return -EINVAL; + pthread_mutex_lock(&(th_manager[thread_id].mutex)); + l = DD_LIST_FIND(th_manager[thread_id].block_dev_list, bdev); + pthread_mutex_unlock(&(th_manager[thread_id].mutex)); if (!l) { _E("(%d) does not exist in the device list", bdev->data->devnode); ret = -ENOENT; @@ -1399,6 +1343,7 @@ out: return ret; } +// Called by BlockThread - Real Unmount Op static int block_unmount_device(struct block_device *bdev, void *data) { int ret; @@ -1416,17 +1361,23 @@ static int block_unmount_device(struct block_device *bdev, void *data) return 0; } +/* Called by BlockThread - Remove Operation + Direct Call at BlockThread + Previously this function was called by MainThread. However, it will increase complexity. + Need thread lock before to call remove_operation +*/ static void remove_operation(struct block_device *bdev) { struct operation_queue *op; dd_list *l, *next; char name[16]; + int thread_id; assert(bdev); - /* LOCK - * during removing queue and checking the queue length */ - pthread_mutex_lock(&bdev->mutex); + thread_id = bdev->thread_id; + if (thread_id < 0 || thread_id >= THREAD_MAX) + return; DD_LIST_FOREACH_SAFE(bdev->op_queue, l, next, op) { if (op->done) { @@ -1438,9 +1389,6 @@ static void remove_operation(struct block_device *bdev) free(op); } } - - pthread_mutex_unlock(&bdev->mutex); - /* UNLOCK */ } static void block_send_dbus_reply(DBusMessage *msg, int result) @@ -1469,88 +1417,136 @@ static void block_send_dbus_reply(DBusMessage *msg, int result) _E("Failed to send reply"); } -static bool check_removed(struct block_device *bdev, dd_list **queue, struct operation_queue **op) +// Called by BlockThread +static void check_removed(struct block_device *bdev, dd_list **queue, struct operation_queue **op) { struct operation_queue *temp; dd_list *l; - bool removed = false; + int thread_id; if (!bdev) - return removed; + return; if (!queue) - return removed; + return; if (!op) - return removed; + return; + + thread_id = bdev->thread_id; + if (thread_id < 0 || thread_id >= THREAD_MAX) + return; + + pthread_mutex_lock(&(th_manager[thread_id].mutex)); - pthread_mutex_lock(&bdev->mutex); DD_LIST_FOREACH(*queue, l, temp) { if (temp->op == BLOCK_DEV_REMOVE) { - removed = true; - _D("Operation queue has remove operation"); + *op = temp; break; } + temp->done = true; + th_manager[thread_id].op_len--; + block_send_dbus_reply((*op)->msg, 0); } - pthread_mutex_unlock(&bdev->mutex); - if (!removed) - return removed; + remove_operation(bdev); + pthread_mutex_unlock(&(th_manager[thread_id].mutex)); +} + +// Called by BlockThread +static bool check_unmount(struct block_device *bdev, dd_list **queue, struct operation_queue **op) +{ + struct operation_queue *temp; + dd_list *l; + int thread_id; + bool unmounted = false; + + if (!bdev) + return false; + + if (!queue) + return false; - pthread_mutex_lock(&bdev->mutex); + if (!op) + return false; + thread_id = bdev->thread_id; + if (thread_id < 0 || thread_id >= THREAD_MAX) + return false; + + pthread_mutex_lock(&(th_manager[thread_id].mutex)); DD_LIST_FOREACH(*queue, l, temp) { - if (temp->op == BLOCK_DEV_REMOVE) { + if (temp->op == BLOCK_DEV_UNMOUNT) { + unmounted = true; + _D("Operation queue has unmount operation"); + break; + } + } + pthread_mutex_unlock(&(th_manager[thread_id].mutex)); + + if (!unmounted) + return unmounted; + + pthread_mutex_lock(&(th_manager[thread_id].mutex)); + + DD_LIST_FOREACH(*queue, l, temp) { + if (temp->op == BLOCK_DEV_UNMOUNT) { *op = temp; break; } temp->done = true; + th_manager[thread_id].op_len--; block_send_dbus_reply((*op)->msg, 0); - - if (pipe_trigger(BLOCK_DEV_DEQUEUE, bdev, 0) < 0) - _E("fail to trigger pipe"); } - pthread_mutex_unlock(&bdev->mutex); + remove_operation(bdev); + pthread_mutex_unlock(&(th_manager[thread_id].mutex)); - return removed; + return unmounted; } -static void trigger_operation(struct block_device *bdev) +// Called by BlockThread +static void trigger_operation(struct block_device *bdev, dd_list *queue, struct operation_queue *op) { - struct operation_queue *op; - dd_list *queue; int ret = 0; - bool continue_th; + int thread_id; char devnode[PATH_MAX]; char name[16]; enum block_dev_operation operation; - bool removed = false; + bool unmounted = false; assert(bdev); - if (!bdev->op_queue) + if (!queue) return; - queue = bdev->op_queue; + thread_id = bdev->thread_id; + if (thread_id < 0 || thread_id >= THREAD_MAX) + return; snprintf(devnode, sizeof(devnode), "%s", bdev->data->devnode); do { - op = DD_LIST_NTH(queue, 0); - if (!op) { - _D("Operation queue is empty"); - break; - } + if (!op) + return; + if (op->done) + return; operation = op->op; - _D("Trigger operation (%s, %s)", + _D("Thread id %d Trigger operation (%s, %s)", thread_id, get_operation_char(operation, name, sizeof(name)), devnode); - if (operation == BLOCK_DEV_INSERT) { - removed = check_removed(bdev, &queue, &op); - if (removed) { + unmounted = false; + if (operation == BLOCK_DEV_INSERT && bdev->removed) { + check_removed(bdev, &queue, &op); + operation = op->op; + _D("Trigger operation again (%s, %s)", + get_operation_char(operation, name, sizeof(name)), devnode); + } + if (operation == BLOCK_DEV_MOUNT) { + unmounted = check_unmount(bdev, &queue, &op); + if (unmounted) { operation = op->op; _D("Trigger operation again (%s, %s)", get_operation_char(operation, name, sizeof(name)), devnode); @@ -1559,8 +1555,6 @@ static void trigger_operation(struct block_device *bdev) switch (operation) { case BLOCK_DEV_INSERT: - ret = block_insert_device(bdev, op->data); - _D("Insert (%s) result:(%d)", devnode, ret); break; case BLOCK_DEV_MOUNT: ret = block_mount_device(bdev, op->data); @@ -1585,57 +1579,148 @@ static void trigger_operation(struct block_device *bdev) /* LOCK * during checking the queue length */ - pthread_mutex_lock(&bdev->mutex); + pthread_mutex_lock(&(th_manager[thread_id].mutex)); op->done = true; + th_manager[thread_id].op_len--; block_send_dbus_reply(op->msg, ret); + queue = bdev->op_queue; queue = DD_LIST_NEXT(queue); + op = DD_LIST_NTH(queue, 0); + remove_operation(bdev); - continue_th = true; - if (!queue || DD_LIST_LENGTH(queue) == 0 || - operation == BLOCK_DEV_REMOVE) { - bdev->th_alive = false; - continue_th = false; - } - - pthread_mutex_unlock(&bdev->mutex); + pthread_mutex_unlock(&(th_manager[thread_id].mutex)); /* UNLOCK */ - if (pipe_trigger(BLOCK_DEV_DEQUEUE, bdev, ret) < 0) - _E("fail to trigger pipe"); - if (operation == BLOCK_DEV_REMOVE) { - if (pipe_trigger(BLOCK_DEV_REMOVE, bdev, 0) < 0) + if (operation == BLOCK_DEV_INSERT || operation == BLOCK_DEV_REMOVE) { + if (pipe_trigger(operation, bdev, 0) < 0) _E("fail to trigger pipe"); } - _D("block (%s) thread (%s)", devnode, - (continue_th ? "Continue" : "Stop")); + } while(true); - } while (continue_th); - - _D("Stop block (%s) thread", devnode); } +// Called by BlockThread static void *block_th_start(void *arg) { - struct block_device *bdev = (struct block_device *)arg; - assert(bdev); + struct block_device *temp; + struct manage_thread *th = (struct manage_thread *)arg; + struct operation_queue *op; + dd_list *elem; + dd_list *queue; + int thread_id; + + assert(th); + + thread_id = th->thread_id; + if (thread_id < 0 || thread_id >= THREAD_MAX) { + _E("Thread Number: %d", th->thread_id); + return NULL; + } + + do { + pthread_mutex_lock(&(th_manager[thread_id].mutex)); + if (th_manager[thread_id].op_len == 0) { + _D("Operation queue of thread is empty"); + pthread_cond_wait(&(th_manager[thread_id].cond), &(th_manager[thread_id].mutex)); + _D("Wake up %d", thread_id); + } - trigger_operation(bdev); + DD_LIST_FOREACH(th_manager[thread_id].block_dev_list, elem, temp) { + queue = temp->op_queue; + do { + op = DD_LIST_NTH(queue, 0); + if (!op) { + _D("Operation queue for device %s is Empty", temp->data->devnode); + break; + } + if (op->done) { + queue = DD_LIST_NEXT(queue); + continue; + } + break; + } while(true); + if (op) + break; + } + pthread_mutex_unlock(&(th_manager[thread_id].mutex)); + + if (op && !op->done) + trigger_operation(temp, queue, op); + + } while (true); return NULL; } +// This function will be refactored later +// Especially, we don't need to keep th_node_list. +static int find_thread(char *devnode) +{ + dd_list *elem; + char str[PATH_MAX]; + char *th_node; + char *temp; + char dev_scsi; + int i, len, min, min_num; + int dev_mmc = -1, part = -1, num; + + len = 0; + if (!fnmatch("*/"MMC_PARTITION_PATH, devnode, 0)) { + sscanf(devnode, "/dev/mmcblk%dp%d", &dev_mmc, &part); + num = dev_mmc; + while (num > 0) { + num = num / 10; + len++; + } + len = len + 12; + snprintf(str, len, "/dev/mmcblk%d", dev_mmc); + th_node = strdup(str); + } else if (!fnmatch("*/"SCSI_PARTITION_PATH, devnode, 0)) { + sscanf(devnode, "/dev/sd%c%d", &dev_scsi, &part); + snprintf(str, SCSI_PARTITION_LENGTH, "/dev/sd%c", dev_scsi); + th_node = strdup(str); + } else + th_node = devnode; + + len = strlen(str) + 1; + min_num = 1000; + min = -1; + for (i = 0; i < THREAD_MAX; i++){ + DD_LIST_FOREACH(th_manager[i].th_node_list, elem, temp) { + if (!temp) + continue; + if (!strncmp(temp, th_node, len)) + return i; + } + if (th_manager[i].num_dev < min_num) { + min_num = th_manager[i].num_dev; + min = i; + } + } + + if (min >= 0 && min < THREAD_MAX) { + DD_LIST_APPEND(th_manager[min].th_node_list, th_node); + return min; + } + + _E("Finding thread is failed"); + DD_LIST_APPEND(th_manager[0].th_node_list, th_node); + return 0; +} + /* Only Main thread is permmited */ +// Called by MainThread static int add_operation(struct block_device *bdev, enum block_dev_operation operation, DBusMessage *msg, void *data) { struct operation_queue *op; - pthread_t th; int ret; + int thread_id; bool start_th; char name[16]; @@ -1660,31 +1745,36 @@ static int add_operation(struct block_device *bdev, msg = dbus_message_ref(msg); op->msg = msg; + thread_id = bdev->thread_id; + if (thread_id < 0 || thread_id >= THREAD_MAX) { + _E("Fail to find thread to add"); + return -EPERM; + } + /* LOCK * during adding queue and checking the queue length */ - pthread_mutex_lock(&bdev->mutex); + pthread_mutex_lock(&(th_manager[thread_id].mutex)); + start_th = th_manager[thread_id].start_th; DD_LIST_APPEND(bdev->op_queue, op); + th_manager[thread_id].op_len++; - start_th = false; - if (DD_LIST_LENGTH(bdev->op_queue) == 1 || - bdev->th_alive == false) { - bdev->th_alive = true; - start_th = true; - } + if (th_manager[thread_id].op_len == 1 && !start_th) + pthread_cond_signal(&(th_manager[thread_id].cond)); - pthread_mutex_unlock(&bdev->mutex); + pthread_mutex_unlock(&(th_manager[thread_id].mutex)); /* UNLOCK */ if (start_th) { _D("Start New thread for block device"); - ret = pthread_create(&th, NULL, block_th_start, bdev); + th_manager[thread_id].start_th = false; + ret = pthread_create(&(th_manager[thread_id].th), NULL, block_th_start, &th_manager[thread_id]); if (ret != 0) { _E("fail to create thread for %s", bdev->data->devnode); return -EPERM; } - pthread_detach(th); + pthread_detach(th_manager[thread_id].th); } return 0; @@ -1762,12 +1852,14 @@ out: return ret; } +// Called by MainThread static int add_block_device(struct udev_device *dev, const char *devnode) { struct block_data *data; struct block_device *bdev; bool partition; int ret; + int thread_id; partition = check_partition(dev); if (partition) { @@ -1795,7 +1887,17 @@ static int add_block_device(struct udev_device *dev, const char *devnode) return -EPERM; } - DD_LIST_APPEND(block_dev_list, bdev); + thread_id = find_thread(bdev->data->devnode); + if (thread_id < 0 || thread_id >= THREAD_MAX) { + _E("Fail to find thread to add"); + return -EPERM; + } + bdev->thread_id = thread_id; + + pthread_mutex_lock(&(th_manager[thread_id].mutex)); + th_manager[thread_id].num_dev++; + DD_LIST_APPEND(th_manager[thread_id].block_dev_list, bdev); + pthread_mutex_unlock(&(th_manager[thread_id].mutex)); ret = add_operation(bdev, BLOCK_DEV_INSERT, NULL, (void *)data); if (ret < 0) { @@ -1825,12 +1927,7 @@ static int remove_block_device(struct udev_device *dev, const char *devnode) BLOCK_FLAG_SET(bdev->data, UNMOUNT_UNSAFE); - DD_LIST_REMOVE(block_dev_list, bdev); - - pthread_mutex_lock(&glob_mutex); - DD_LIST_APPEND(block_rm_list, bdev); - pthread_mutex_unlock(&glob_mutex); - + bdev->removed = true; ret = add_operation(bdev, BLOCK_DEV_UNMOUNT, NULL, (void *)UNMOUNT_FORCE); if (ret < 0) { _E("Failed to add operation (unmount %s)", devnode); @@ -1918,58 +2015,76 @@ static int block_init_from_udev_enumerate(void) return 0; } +// Called by MainThread static void show_block_device_list(void) { struct block_device *bdev; struct block_data *data; dd_list *elem; + int i; - DD_LIST_FOREACH(block_dev_list, elem, bdev) { - data = bdev->data; - if (!data) - continue; - _D("%s:", data->devnode); - _D("\tSyspath: %s", data->syspath); - _D("\tBlock type: %s", - (data->block_type == BLOCK_MMC_DEV ? - BLOCK_TYPE_MMC : BLOCK_TYPE_SCSI)); - _D("\tFs type: %s", data->fs_type); - _D("\tFs usage: %s", data->fs_usage); - _D("\tFs version: %s", data->fs_version); - _D("\tFs uuid enc: %s", data->fs_uuid_enc); - _D("\tReadonly: %s", - (data->readonly ? "true" : "false")); - _D("\tMount point: %s", data->mount_point); - _D("\tMount state: %s", - (data->state == BLOCK_MOUNT ? - "mount" : "unmount")); - _D("\tPrimary: %s", - (data->primary ? "true" : "false")); - _D("\tID: %d", data->id); + for (i = 0; i < THREAD_MAX; i++) { + pthread_mutex_lock(&(th_manager[i].mutex)); + DD_LIST_FOREACH(th_manager[i].block_dev_list, elem, bdev) { + data = bdev->data; + if (!data) + continue; + if (bdev->removed) + continue; + _D("%s:", data->devnode); + _D("\tSyspath: %s", data->syspath); + _D("\tBlock type: %s", + (data->block_type == BLOCK_MMC_DEV ? + BLOCK_TYPE_MMC : BLOCK_TYPE_SCSI)); + _D("\tFs type: %s", data->fs_type); + _D("\tFs usage: %s", data->fs_usage); + _D("\tFs version: %s", data->fs_version); + _D("\tFs uuid enc: %s", data->fs_uuid_enc); + _D("\tReadonly: %s", + (data->readonly ? "true" : "false")); + _D("\tMount point: %s", data->mount_point); + _D("\tMount state: %s", + (data->state == BLOCK_MOUNT ? + "mount" : "unmount")); + _D("\tPrimary: %s", + (data->primary ? "true" : "false")); + _D("\tID: %d", data->id); + } + pthread_mutex_unlock(&(th_manager[i].mutex)); } } +// Called by MainThread static void remove_whole_block_device(void) { struct block_device *bdev; dd_list *elem; dd_list *next; int r; + int i; - DD_LIST_FOREACH_SAFE(block_dev_list, elem, next, bdev) { - DD_LIST_REMOVE(block_dev_list, bdev); - - pthread_mutex_lock(&glob_mutex); - DD_LIST_APPEND(block_rm_list, bdev); - pthread_mutex_unlock(&glob_mutex); - - r = add_operation(bdev, BLOCK_DEV_UNMOUNT, NULL, (void *)UNMOUNT_NORMAL); - if (r < 0) - _E("Failed to add operation (unmount %s)", bdev->data->devnode); - - r = add_operation(bdev, BLOCK_DEV_REMOVE, NULL, NULL); - if (r < 0) - _E("Failed to add operation (remove %s)", bdev->data->devnode); + for (i = 0; i < THREAD_MAX; i++) { + do { + pthread_mutex_lock(&(th_manager[i].mutex)); + DD_LIST_FOREACH_SAFE(th_manager[i].block_dev_list, elem, next, bdev) { + if (bdev->removed == false) { + break; + } + } + pthread_mutex_unlock(&(th_manager[i].mutex)); + + if (bdev && bdev->removed == false) { + bdev->removed = true; + r = add_operation(bdev, BLOCK_DEV_UNMOUNT, NULL, (void *)UNMOUNT_NORMAL); + if (r < 0) + _E("Failed to add operation (unmount %s)", bdev->data->devnode); + + r = add_operation(bdev, BLOCK_DEV_REMOVE, NULL, NULL); + if (r < 0) + _E("Failed to add operation (remove %s)", bdev->data->devnode); + } else + break; + } while(true); } } @@ -2025,32 +2140,26 @@ static void uevent_block_handler(struct udev_device *dev) remove_block_device(dev, devnode); } -static DBusMessage *handle_block_mount(E_DBus_Object *obj, +static DBusMessage *request_mount_block(E_DBus_Object *obj, DBusMessage *msg) { struct block_device *bdev; - struct block_data *data; char *mount_point; + int id; int ret = -EBADMSG; if (!obj || !msg) goto out; ret = dbus_message_get_args(msg, NULL, + DBUS_TYPE_INT32, &id, DBUS_TYPE_STRING, &mount_point, DBUS_TYPE_INVALID); if (!ret) goto out; - - data = e_dbus_object_data_get(obj); - if (!data) - goto out; - - _D("devnode : %s, mount_point : %s", data->devnode, mount_point); - - bdev = find_block_device(data->devnode); + bdev = find_block_device_by_id(id); if (!bdev) { - _E("Failed to find (%s) in the device list", data->devnode); + _E("Failed to find (%d) in the device list", id); ret = -ENOENT; goto out; } @@ -2066,7 +2175,7 @@ static DBusMessage *handle_block_mount(E_DBus_Object *obj, ret = add_operation(bdev, BLOCK_DEV_MOUNT, msg, NULL); if (ret < 0) { - _E("Failed to add operation (mount %s)", data->devnode); + _E("Failed to add operation (mount %s)", bdev->data->devnode); goto out; } @@ -2076,39 +2185,33 @@ out: return make_reply_message(msg, ret); } -static DBusMessage *handle_block_unmount(E_DBus_Object *obj, +static DBusMessage *request_unmount_block(E_DBus_Object *obj, DBusMessage *msg) { struct block_device *bdev; - struct block_data *data; long option; + int id; int ret = -EBADMSG; if (!obj || !msg) goto out; ret = dbus_message_get_args(msg, NULL, + DBUS_TYPE_INT32, &id, DBUS_TYPE_INT32, &option, DBUS_TYPE_INVALID); if (!ret) goto out; - - data = e_dbus_object_data_get(obj); - if (!data) - goto out; - - _D("devnode : %s, option : %d", data->devnode, option); - - bdev = find_block_device(data->devnode); + bdev = find_block_device_by_id(id); if (!bdev) { - _E("Failed to find (%s) in the device list", data->devnode); + _E("Failed to find (%d) in the device list", id); ret = -ENOENT; goto out; } ret = add_operation(bdev, BLOCK_DEV_UNMOUNT, msg, (void *)option); if (ret < 0) { - _E("Failed to add operation (unmount %s)", data->devnode); + _E("Failed to add operation (unmount %s)", bdev->data->devnode); goto out; } @@ -2118,12 +2221,12 @@ out: return make_reply_message(msg, ret); } -static DBusMessage *handle_block_format(E_DBus_Object *obj, +static DBusMessage *request_format_block(E_DBus_Object *obj, DBusMessage *msg) { struct block_device *bdev; - struct block_data *data; struct format_data *fdata; + int id; int option; int ret = -EBADMSG; int prev_state; @@ -2132,20 +2235,14 @@ static DBusMessage *handle_block_format(E_DBus_Object *obj, goto out; ret = dbus_message_get_args(msg, NULL, + DBUS_TYPE_INT32, &id, DBUS_TYPE_INT32, &option, DBUS_TYPE_INVALID); if (!ret) goto out; - - data = e_dbus_object_data_get(obj); - if (!data) - goto out; - - _D("devnode : %s, option : %d", data->devnode, option); - - bdev = find_block_device(data->devnode); + bdev = find_block_device_by_id(id); if (!bdev) { - _E("Failed to find (%s) in the device list", data->devnode); + _E("Failed to find (%d) in the device list", id); goto out; } @@ -2155,11 +2252,11 @@ static DBusMessage *handle_block_format(E_DBus_Object *obj, goto out; } - prev_state = data->state; + prev_state = bdev->data->state; if (prev_state == BLOCK_MOUNT) { ret = add_operation(bdev, BLOCK_DEV_UNMOUNT, NULL, (void *)UNMOUNT_FORCE); if (ret < 0) { - _E("Failed to add operation (unmount %s)", data->devnode); + _E("Failed to add operation (unmount %s)", bdev->data->devnode); release_format_data(fdata); goto out; } @@ -2167,14 +2264,14 @@ static DBusMessage *handle_block_format(E_DBus_Object *obj, ret = add_operation(bdev, BLOCK_DEV_FORMAT, msg, (void *)fdata); if (ret < 0) { - _E("Failed to add operation (format %s)", data->devnode); + _E("Failed to add operation (format %s)", bdev->data->devnode); release_format_data(fdata); } /* Maintain previous state of mount/unmount */ if (prev_state == BLOCK_MOUNT) { if (add_operation(bdev, BLOCK_DEV_MOUNT, NULL, NULL) < 0) { - _E("Failed to add operation (mount %s)", data->devnode); + _E("Failed to add operation (mount %s)", bdev->data->devnode); goto out; } } @@ -2275,12 +2372,14 @@ static int add_device_to_iter_2(struct block_data *data, DBusMessageIter *iter) return 0; } -static DBusMessage *get_device_info(E_DBus_Object *obj, +static DBusMessage *request_get_device_info(E_DBus_Object *obj, DBusMessage *msg) { DBusMessageIter iter; DBusMessage *reply; + struct block_device *bdev; struct block_data *data; + int ret, id; if (!obj || !msg) return NULL; @@ -2289,37 +2388,21 @@ static DBusMessage *get_device_info(E_DBus_Object *obj, if (!reply) goto out; - data = e_dbus_object_data_get(obj); - if (!data) + ret = dbus_message_get_args(msg, NULL, + DBUS_TYPE_INT32, &id, + DBUS_TYPE_INVALID); + if (!ret) goto out; - dbus_message_iter_init_append(reply, &iter); - add_device_to_struct_iter(data, &iter); - -out: - return reply; -} - -static DBusMessage *get_device_info_2(E_DBus_Object *obj, - DBusMessage *msg) -{ - DBusMessageIter iter; - DBusMessage *reply; - struct block_data *data; - - if (!obj || !msg) - return NULL; - - reply = dbus_message_new_method_return(msg); - if (!reply) + bdev = find_block_device_by_id(id); + if (!bdev) goto out; - - data = e_dbus_object_data_get(obj); + data = bdev->data; if (!data) goto out; dbus_message_iter_init_append(reply, &iter); - add_device_to_iter_2(data, &iter); + add_device_to_iter(data, &iter); out: return reply; @@ -2332,6 +2415,7 @@ static DBusMessage *request_show_device_list(E_DBus_Object *obj, return dbus_message_new_method_return(msg); } +// Called by MainThread static DBusMessage *request_get_device_list(E_DBus_Object *obj, DBusMessage *msg) { @@ -2344,6 +2428,7 @@ static DBusMessage *request_get_device_list(E_DBus_Object *obj, char *type = NULL; int ret = -EBADMSG; int block_type; + int i; reply = dbus_message_new_method_return(msg); @@ -2376,22 +2461,27 @@ static DBusMessage *request_get_device_list(E_DBus_Object *obj, dbus_message_iter_init_append(reply, &iter); dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "(issssssisibii)", &aiter); - DD_LIST_FOREACH(block_dev_list, elem, bdev) { - data = bdev->data; - if (!data) - continue; - - switch (block_type) { - case BLOCK_SCSI_DEV: - case BLOCK_MMC_DEV: - if (data->block_type != block_type) + for (i = 0; i < THREAD_MAX; i++) { + pthread_mutex_lock(&(th_manager[i].mutex)); + DD_LIST_FOREACH(th_manager[i].block_dev_list, elem, bdev) { + data = bdev->data; + if (!data) + continue; + if (bdev->removed) continue; - break; - default: - break; - } - add_device_to_struct_iter(data, &aiter); + switch (block_type) { + case BLOCK_SCSI_DEV: + case BLOCK_MMC_DEV: + if (data->block_type != block_type) + continue; + break; + default: + break; + } + add_device_to_struct_iter(data, &aiter); + } + pthread_mutex_unlock(&(th_manager[i].mutex)); } dbus_message_iter_close_container(&iter, &aiter); @@ -2399,6 +2489,7 @@ out: return reply; } +// Called by MainThread static DBusMessage *request_get_device_list_2(E_DBus_Object *obj, DBusMessage *msg) { @@ -2411,6 +2502,7 @@ static DBusMessage *request_get_device_list_2(E_DBus_Object *obj, char *type = NULL; int ret = -EBADMSG; int block_type; + int i; reply = dbus_message_new_method_return(msg); @@ -2443,97 +2535,30 @@ static DBusMessage *request_get_device_list_2(E_DBus_Object *obj, dbus_message_iter_init_append(reply, &iter); dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "(issssssisibi)", &aiter); - DD_LIST_FOREACH(block_dev_list, elem, bdev) { - data = bdev->data; - if (!data) - continue; - - switch (block_type) { - case BLOCK_SCSI_DEV: - case BLOCK_MMC_DEV: - if (data->block_type != block_type) + for (i = 0; i < THREAD_MAX; i++) { + pthread_mutex_lock(&(th_manager[i].mutex)); + DD_LIST_FOREACH(th_manager[i].block_dev_list, elem, bdev) { + data = bdev->data; + if (!data) + continue; + if (bdev->removed) continue; - break; - default: - break; - } - - add_device_to_iter_2(data, &aiter); - } - dbus_message_iter_close_container(&iter, &aiter); - -out: - return reply; -} - -static DBusMessage *request_device_info_by_id(E_DBus_Object *obj, - DBusMessage *msg) -{ - DBusMessageIter iter; - DBusMessage *reply; - struct block_device *bdev; - struct block_data *data; - dd_list *elem; - int ret; - int block_id; - bool found; - char *str_null = ""; - - if (!obj || !msg) - return NULL; - - reply = dbus_message_new_method_return(msg); - if (!reply) - goto out; - ret = dbus_message_get_args(msg, NULL, - DBUS_TYPE_INT32, &block_id, - DBUS_TYPE_INVALID); - if (!ret) - goto out; + switch (block_type) { + case BLOCK_SCSI_DEV: + case BLOCK_MMC_DEV: + if (data->block_type != block_type) + continue; + break; + default: + break; + } - found = false; - DD_LIST_FOREACH(block_dev_list, elem, bdev) { - data = bdev->data; - if (!data) - continue; - if (data->id != block_id) - continue; - found = true; - break; + add_device_to_iter_2(data, &aiter); + } + pthread_mutex_unlock(&(th_manager[i].mutex)); } - - if (!found) - goto out; - - dbus_message_iter_init_append(reply, &iter); - - dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, - &(data->block_type)); - dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, - data->devnode ? &(data->devnode) : &str_null); - dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, - data->syspath ? &(data->syspath) : &str_null); - dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, - data->fs_usage ? &(data->fs_usage) : &str_null); - dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, - data->fs_type ? &(data->fs_type) : &str_null); - dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, - data->fs_version ? &(data->fs_version) : &str_null); - dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, - data->fs_uuid_enc ? &(data->fs_uuid_enc) : &str_null); - dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, - &(data->readonly)); - dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, - data->mount_point ? &(data->mount_point) : &str_null); - dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, - &(data->state)); - dbus_message_iter_append_basic(&iter, DBUS_TYPE_BOOLEAN, - &(data->primary)); - dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, - &(data->flags)); - dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, - &(data->id)); + dbus_message_iter_close_container(&iter, &aiter); out: return reply; @@ -2547,6 +2572,7 @@ static DBusMessage *request_get_mmc_primary(E_DBus_Object *obj, DBusMessage *msg struct block_data *data, nodata = {0,}; dd_list *elem; bool found; + int i; if (!obj || !msg) return NULL; @@ -2556,16 +2582,24 @@ static DBusMessage *request_get_mmc_primary(E_DBus_Object *obj, DBusMessage *msg goto out; found = false; - DD_LIST_FOREACH(block_dev_list, elem, bdev) { - data = bdev->data; - if (!data) - continue; - if (data->block_type != BLOCK_MMC_DEV) - continue; - if (!data->primary) - continue; - found = true; - break; + for (i = 0; i < THREAD_MAX; i++) { + pthread_mutex_lock(&(th_manager[i].mutex)); + DD_LIST_FOREACH(th_manager[i].block_dev_list, elem, bdev) { + data = bdev->data; + if (!data) + continue; + if (bdev->removed) + continue; + if (data->block_type != BLOCK_MMC_DEV) + continue; + if (!data->primary) + continue; + found = true; + break; + } + pthread_mutex_unlock(&(th_manager[i].mutex)); + if (found) + break; } dbus_message_iter_init_append(reply, &iter); @@ -2581,76 +2615,16 @@ out: } static const struct edbus_method manager_methods[] = { - { "ShowDeviceList", NULL, NULL, request_show_device_list }, - { "GetDeviceList" , "s", "a(issssssisibii)" , request_get_device_list }, - { "GetDeviceList2", "s", "a(issssssisibi)", request_get_device_list_2 }, - { "GetDeviceInfoByID" , "i", "(issssssisibii)" , request_device_info_by_id }, + { "ShowDeviceList", NULL, NULL, request_show_device_list }, + { "GetDeviceList" , "s", "a(issssssisibii)", request_get_device_list }, + { "GetDeviceList2", "s", "a(issssssisibi)", request_get_device_list_2 }, + { "Mount", "is", "i", request_mount_block }, + { "Unmount", "ii", "i", request_unmount_block }, + { "Format", "ii", "i", request_format_block }, + { "GetDeviceInfo", "i", "(issssssisibii)", request_get_device_info }, { "GetMmcPrimary" , NULL, "(issssssisibii)" , request_get_mmc_primary }, }; -static const struct edbus_method device_methods[] = { - { "Mount", "s", "i", handle_block_mount }, - { "Unmount", "i", "i", handle_block_unmount }, - { "Format", "i", "i", handle_block_format }, - { "GetDeviceInfo" , NULL, "(issssssisibii)" , get_device_info }, - { "GetDeviceInfo2" , NULL, "(issssssisibi)", get_device_info_2 }, -}; - -static int init_block_object_iface(void) -{ - int i; - int r; - - iface = e_dbus_interface_new(DEVICED_INTERFACE_BLOCK); - if (!iface) { - _E("fail to new block interface"); - return -EPERM; - } - - for (i = 0; i < ARRAY_SIZE(device_methods); ++i) { - r = e_dbus_interface_method_add(iface, - device_methods[i].member, - device_methods[i].signature, - device_methods[i].reply_signature, - device_methods[i].func); - if (r < 0) - _E("fail to register %s method to iface", - device_methods[i].member); - } - - r = e_dbus_interface_signal_add(iface, - BLOCK_DEVICE_BLOCKED, "ss"); - if (r < 0) - _E("fail to register %s signal to iface", - BLOCK_DEVICE_BLOCKED); - - r = e_dbus_interface_signal_add(iface, - BLOCK_DEVICE_CHANGED, "issssssisibii"); - if (r < 0) - _E("fail to register %s signal to iface", - BLOCK_DEVICE_CHANGED); - - r = e_dbus_interface_signal_add(iface, - BLOCK_DEVICE_CHANGED_2, "issssssisibi"); - if (r < 0) - _E("fail to register %s signal to iface", - BLOCK_DEVICE_CHANGED_2); - - r = e_dbus_interface_signal_add(iface, - BLOCK_DEVICE_ADDED, "issssssisibii"); - if (r < 0) - _E("fail to register %s signal to iface", - BLOCK_DEVICE_ADDED); - - r = e_dbus_interface_signal_add(iface, - BLOCK_DEVICE_REMOVED, "issssssisibii"); - if (r < 0) - _E("fail to register %s signal to iface", - BLOCK_DEVICE_REMOVED); - - return 0; -} - static int load_config(struct parse_result *result, void *user_data) { int index; @@ -2704,6 +2678,7 @@ static int mount_root_path_tmpfs(void) static void block_init(void *data) { int ret; + int i; /* load config */ ret = config_parse(BLOCK_CONF_FILE, load_config, NULL); @@ -2721,11 +2696,6 @@ static void block_init(void *data) if (ret < 0) _E("fail to init edbus interface and method(%d)", ret); - /* init block devices interface */ - ret = init_block_object_iface(); - if (ret < 0) - _E("fail to init block object iface"); - /* init pipe */ ret = pipe_init(); if (ret < 0) @@ -2739,11 +2709,20 @@ static void block_init(void *data) /* register notifier */ register_notifier(DEVICE_NOTIFIER_POWEROFF, block_poweroff); register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done); + + for (i = 0; i < THREAD_MAX; i++) { + th_manager[i].num_dev = 0; + th_manager[i].op_len = 0; + th_manager[i].start_th = true; + th_manager[i].thread_id = i; + pthread_mutex_init(&(th_manager[i].mutex), NULL); + pthread_cond_init(&(th_manager[i].cond), NULL); + } } static void block_exit(void *data) { - int ret; + int ret, i; /* unregister notifier */ unregister_notifier(DEVICE_NOTIFIER_POWEROFF, block_poweroff); @@ -2760,6 +2739,11 @@ static void block_exit(void *data) /* remove remaining blocks */ remove_whole_block_device(); + for (i = 0; i < THREAD_MAX; i++) { + if (!th_manager[i].start_th) + pthread_cancel(th_manager[i].th); + } + block_control = false; } diff --git a/src/libdeviced/mmc.c b/src/libdeviced/mmc.c index 6a9a4c8..e890741 100644 --- a/src/libdeviced/mmc.c +++ b/src/libdeviced/mmc.c @@ -62,7 +62,7 @@ API int mmc_secure_unmount(const char *mount_point) DEVICED_INTERFACE_MMC, METHOD_REQUEST_SECURE_UNMOUNT, "s", arr); } -static int get_mmc_primary_devnode(char *path, size_t len) +static int get_mmc_primary_id() { DBusMessage *reply; DBusMessageIter iter; @@ -72,6 +72,7 @@ static int get_mmc_primary_devnode(char *path, size_t len) char *devnode = NULL; bool primary; int ret; + int id; param[0] = "mmc"; reply = dbus_method_sync_with_reply( @@ -104,47 +105,22 @@ static int get_mmc_primary_devnode(char *path, size_t len) dbus_message_iter_next(&piter); /* primary */ dbus_message_iter_get_basic(&piter, &primary); dbus_message_iter_next(&piter); /* flags */ - dbus_message_iter_next(&piter); /* storage id */ + dbus_message_iter_get_basic(&piter, &id); /* storage id */ dbus_message_iter_next(&aiter); if (type == STORAGE_MMC && primary && devnode) break; } - if (devnode) { - _I("MMC Primary devnode (%s)", devnode); - snprintf(path, len, "%s", devnode); - ret = 0; - } else + if (devnode) + ret = id; + else ret = -ENODEV; dbus_message_unref(reply); return ret; } -static int get_object_path_mmc(char *path, size_t len) -{ - int ret; - char devpath[BUF_MAX], *devnode; - - if (!path || len == 0) - return -EINVAL; - - ret = get_mmc_primary_devnode(devpath, sizeof(devpath)); - if (ret < 0) { - _E("Failed to get mmc devpath (%d)", ret); - return -ENODEV; - } - - devnode = strstr(devpath, "mmcblk"); - if (!devnode) - return -EINVAL; - - snprintf(path, len, "%s/%s", - DEVICED_PATH_BLOCK_DEVICES, devnode); - return 0; -} - static void mount_mmc_cb(void *data, DBusMessage *msg, DBusError *err) { struct mmc_contents *mmc_data = (struct mmc_contents*)data; @@ -179,14 +155,9 @@ API int deviced_request_mount_mmc(struct mmc_contents *mmc_data) void (*mount_cb)(void*, DBusMessage*, DBusError*) = NULL; void *data = NULL; int ret; - char path[BUF_MAX] = { 0, }; - char *param[1]; - - ret = get_object_path_mmc(path, sizeof(path)); - if (ret < 0) { - _E("Failed to get object path"); - return ret; - } + int id; + char buf_id[32]; + char *param[2]; if (mmc_data && mmc_data->mmc_cb) { _I("Mount callback exists"); @@ -194,9 +165,15 @@ API int deviced_request_mount_mmc(struct mmc_contents *mmc_data) data = mmc_data; } - param[0] = ""; - ret = dbus_method_async_with_reply(STORAGE_BUS_NAME, path, - DEVICED_INTERFACE_BLOCK, "Mount", "s", param, + id = get_mmc_primary_id(); + if (id < 0) + return id; + + snprintf(buf_id, sizeof(buf_id), "%d", id); + param[0] = buf_id; + param[1] = ""; + ret = dbus_method_async_with_reply(STORAGE_BUS_NAME, DEVICED_PATH_BLOCK_MANAGER, + DEVICED_INTERFACE_BLOCK_MANAGER, "Mount", "is", param, mount_cb, -1, data); _I("Mount Request %s", ret == 0 ? "Success" : "Failed"); @@ -238,29 +215,30 @@ API int deviced_request_unmount_mmc(struct mmc_contents *mmc_data, int option) void (*unmount_cb)(void*, DBusMessage*, DBusError*) = NULL; void *data = NULL; char buf_opt[32]; + char buf_id[32]; int ret; - char path[BUF_MAX] = { 0, }; - char *param[1]; + int id; + char *param[2]; if (option < 0 || option > 1) return -EINVAL; - ret = get_object_path_mmc(path, sizeof(path)); - if (ret < 0) { - _E("Failed to get object path"); - return ret; - } - if (mmc_data && mmc_data->mmc_cb) { _I("Mount callback exists"); unmount_cb = unmount_mmc_cb; data = mmc_data; } + id = get_mmc_primary_id(); + if (id < 0) + return id; + + snprintf(buf_id, sizeof(buf_id), "%d", id); + param[0] = buf_id; snprintf(buf_opt, sizeof(buf_opt), "%d", option); - param[0] = buf_opt; - ret = dbus_method_async_with_reply(STORAGE_BUS_NAME, path, - DEVICED_INTERFACE_BLOCK, "Unmount", "i", param, + param[1] = buf_opt; + ret = dbus_method_async_with_reply(STORAGE_BUS_NAME, DEVICED_PATH_BLOCK_MANAGER, + DEVICED_INTERFACE_BLOCK_MANAGER, "Unmount", "ii", param, unmount_cb, -1, data); _I("Unmount Request %s", ret == 0 ? "Success" : "Failed"); @@ -307,29 +285,30 @@ API int deviced_format_mmc(struct mmc_contents *mmc_data, int option) void (*format_cb)(void*, DBusMessage*, DBusError*) = NULL; void *data = NULL; char buf_opt[32]; + char buf_id[32]; int ret; - char path[BUF_MAX] = { 0, }; - char *param[1]; + int id; + char *param[2]; if (option < 0 || option > 1) return -EINVAL; - ret = get_object_path_mmc(path, sizeof(path)); - if (ret < 0) { - _E("Failed to get object path"); - return ret; - } - if (mmc_data && mmc_data->mmc_cb) { _I("Mount callback exists"); format_cb = format_mmc_cb; data = mmc_data; } + id = get_mmc_primary_id(); + if (id < 0) + return id; + + snprintf(buf_id, sizeof(buf_id), "%d", id); + param[0] = buf_id; snprintf(buf_opt, sizeof(buf_opt), "%d", option); - param[0] = buf_opt; - ret = dbus_method_async_with_reply(STORAGE_BUS_NAME, path, - DEVICED_INTERFACE_BLOCK, "Format", "i", param, + param[1] = buf_opt; + ret = dbus_method_async_with_reply(STORAGE_BUS_NAME, DEVICED_PATH_BLOCK_MANAGER, + DEVICED_INTERFACE_BLOCK_MANAGER, "Format", "ii", param, format_cb, FORMAT_TIMEOUT, data); _I("Format Request %s", ret == 0 ? "Success" : "Failed"); diff --git a/src/shared/dbus.h b/src/shared/dbus.h index b0b80d5..8eb84cb 100644 --- a/src/shared/dbus.h +++ b/src/shared/dbus.h @@ -83,9 +83,7 @@ #define STORAGE_OBJECT_PATH "/Org/Tizen/System/Storage" #define STORAGE_INTERFACE_NAME STORAGE_BUS_NAME #define DEVICED_PATH_BLOCK STORAGE_OBJECT_PATH"/Block" -#define DEVICED_PATH_BLOCK_DEVICES DEVICED_PATH_BLOCK"/Devices" #define DEVICED_PATH_BLOCK_MANAGER DEVICED_PATH_BLOCK"/Manager" -#define DEVICED_INTERFACE_BLOCK STORAGE_INTERFACE_NAME".Block" #define DEVICED_INTERFACE_BLOCK_MANAGER STORAGE_INTERFACE_NAME".BlockManager" /* MMC service: mount/unmount/format mmc operations about mmc */ #define DEVICED_PATH_MMC DEVICED_OBJECT_PATH"/Mmc" -- 2.7.4 From 9ae0a6d047bf48cae9e4ae18dd8d767953a86d54 Mon Sep 17 00:00:00 2001 From: taeyoung Date: Fri, 5 Aug 2016 16:34:49 +0900 Subject: [PATCH 07/16] devicectl: fix invalid parameter type Change-Id: I8979e3e6a55896ffb319e708ee26841e2733dcd3 Signed-off-by: taeyoung --- src/devicectl/devicectl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/devicectl/devicectl.c b/src/devicectl/devicectl.c index 8734466..d2d9c77 100644 --- a/src/devicectl/devicectl.c +++ b/src/devicectl/devicectl.c @@ -312,12 +312,12 @@ static int power_operation(char **args, char *type) return 0; } -static int power_off(char *args) +static int power_off(char **args) { return power_operation(args, "poweroff"); } -static int power_reboot(char *args) +static int power_reboot(char **args) { return power_operation(args, "reboot"); } -- 2.7.4 From bb17486efd929d01ac915335c3a5bb7b54422840 Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Thu, 11 Aug 2016 14:14:05 +0900 Subject: [PATCH 08/16] block: Remove build warning Change-Id: Ieb9b550178d92089e74d21486bfe5487bb63e908 Signed-off-by: pr.jung --- src/block/block.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/block/block.c b/src/block/block.c index 43a9e40..f040018 100644 --- a/src/block/block.c +++ b/src/block/block.c @@ -1609,9 +1609,9 @@ static void *block_th_start(void *arg) { struct block_device *temp; struct manage_thread *th = (struct manage_thread *)arg; - struct operation_queue *op; + struct operation_queue *op = NULL; dd_list *elem; - dd_list *queue; + dd_list *queue = NULL; int thread_id; assert(th); -- 2.7.4 From 3b7f23bd95829d1d3df61134b8516eb75878cbe0 Mon Sep 17 00:00:00 2001 From: taeyoung Date: Thu, 11 Aug 2016 15:57:04 +0900 Subject: [PATCH 09/16] common: change fuser path - The path of the fuser path is changed from /sbin/fuser to /usr/bin/fuser by upgrading psmisc package. Change-Id: Iea29bdad6a8438fe5802618adf0fd8a74d1bd11d Signed-off-by: taeyoung --- src/core/common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/common.c b/src/core/common.c index 4297b9f..209fea5 100644 --- a/src/core/common.c +++ b/src/core/common.c @@ -333,7 +333,7 @@ int sys_set_str(char *fname, char *val) int terminate_process(const char *partition, bool force) { - const char *argv[7] = {"/sbin/fuser", "-m", "-k", "-s", NULL, NULL, NULL}; + const char *argv[7] = {"/usr/bin/fuser", "-m", "-k", "-s", NULL, NULL, NULL}; int argc; if (force) -- 2.7.4 From c744fc5a603aaaaa7a29e1adfbdda59b155fd0cb Mon Sep 17 00:00:00 2001 From: taeyoung Date: Thu, 11 Aug 2016 16:10:44 +0900 Subject: [PATCH 10/16] power: unmount cgroup after closing other apps - Previously, cgroup is unmounted when poweroff popup is launched. This is a critical bug and it should be fixed. - Now, cgroup is unmounted just before turning off power. Change-Id: Iafe16348a77aee6875e47e19b87cf755b85e8200 Signed-off-by: taeyoung --- src/power/power-handler.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/power/power-handler.c b/src/power/power-handler.c index 79f2761..8ffc22b 100644 --- a/src/power/power-handler.c +++ b/src/power/power-handler.c @@ -269,8 +269,6 @@ static void poweroff_idler_cb(void *data) device_notify(DEVICE_NOTIFIER_POWEROFF, &val); } - poweroff_stop_systemd_service(); - /* TODO for notify. will be removed asap. */ vconf_set_int(VCONFKEY_SYSMAN_POWER_OFF_STATUS, val); @@ -404,6 +402,9 @@ static void powerdown(void) if (check_duration < 0) break; } + + poweroff_stop_systemd_service(); + #ifndef EMULATOR unmount_rw_partition(); #endif -- 2.7.4 From fdad0f548fed01a61e62afc172f65c85d7797bec Mon Sep 17 00:00:00 2001 From: taeyoung Date: Fri, 12 Aug 2016 08:51:53 +0900 Subject: [PATCH 11/16] common: apply Tizen coding rules - Space is required before ":" and "(" Change-Id: I8bf8b8b3d747a54cf69818db24ec0d244eefa68e Signed-off-by: taeyoung --- src/battery/power-supply.c | 2 +- src/block/block.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/battery/power-supply.c b/src/battery/power-supply.c index 6a936c2..1ad2c1d 100644 --- a/src/battery/power-supply.c +++ b/src/battery/power-supply.c @@ -718,7 +718,7 @@ static void battery_print_info(struct battery_info *info) } _I(" BatPresent(%s)", battery.present == PRESENT_NORMAL ? "Normal" : "Abnormal"); _I(" Temperature(%s)", battery.temp == TEMP_LOW ? "Low" : "High"); - _I(" OVP(%s)", battery.ovp == OVP_NORMAL ? "Normal": "Abnormal"); + _I(" OVP(%s)", battery.ovp == OVP_NORMAL ? "Normal" : "Abnormal"); } static void battery_changed(struct battery_info *info, void *data) diff --git a/src/block/block.c b/src/block/block.c index f040018..9733928 100644 --- a/src/block/block.c +++ b/src/block/block.c @@ -538,7 +538,7 @@ static struct block_data *make_block_data(const char *devnode, BLOCK_FLAG_CLEAR_ALL(data); /* for 2.4 backward compatibility */ - if(data->primary == true && data->block_type == BLOCK_MMC_DEV) + if (data->primary == true && data->block_type == BLOCK_MMC_DEV) data->id = EXT_PRIMARY_SD_FIXID; else data->id = block_get_new_id(); -- 2.7.4 From df8dabd4b7c4191160ee88fd5efd32f01d332853 Mon Sep 17 00:00:00 2001 From: taeyoung Date: Wed, 10 Aug 2016 16:15:07 +0900 Subject: [PATCH 12/16] usb: add dbus methods and signals of Tizen 2.4 - dbus methods and signals supported in Tizen 2.4 is added. Change-Id: Iea351d8038a8043d751cd10166b407d181c7678e Signed-off-by: taeyoung --- src/core/edbus-handler.c | 1 + src/usb/usb-dbus.c | 246 +++++++++++++++++++++++++++++++++++++++++++++++ src/usb/usb.c | 12 ++- src/usb/usb.h | 12 +++ 4 files changed, 270 insertions(+), 1 deletion(-) create mode 100644 src/usb/usb-dbus.c diff --git a/src/core/edbus-handler.c b/src/core/edbus-handler.c index ddede31..ab98869 100644 --- a/src/core/edbus-handler.c +++ b/src/core/edbus-handler.c @@ -54,6 +54,7 @@ static struct edbus_object { { DEVICED_PATH_PROCESS, DEVICED_INTERFACE_PROCESS, NULL, NULL }, { DEVICED_PATH_KEY , DEVICED_INTERFACE_KEY , NULL, NULL }, { DEVICED_PATH_SYSNOTI, DEVICED_INTERFACE_SYSNOTI, NULL, NULL }, + { DEVICED_PATH_USB , DEVICED_INTERFACE_USB , NULL, NULL }, /* Add new object & interface here*/ }; diff --git a/src/usb/usb-dbus.c b/src/usb/usb-dbus.c new file mode 100644 index 0000000..36628ea --- /dev/null +++ b/src/usb/usb-dbus.c @@ -0,0 +1,246 @@ +/* + * deviced + * + * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * + * 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. + */ + + +#include +#include +#include +#include + +#include "core/log.h" +#include "core/common.h" +#include "core/devices.h" +#include "core/edbus-handler.h" +#include "shared/dbus.h" +#include "usb.h" + +/* Legacy signals */ +#define SIGNAL_STATE_CHANGED "StateChanged" +#define SIGNAL_MODE_CHANGED "ModeChanged" +#define SIGNAL_CONFIG_ENABLED "ConfigEnabled" +#define CHANGE_USB_MODE "ChangeUsbMode" + +static int get_usb_current_mode(void) +{ + int val, ret; + + ret = vconf_get_int(VCONFKEY_USB_CUR_MODE, &val); + if (ret != 0) { + _E("Failed to get current mode (%d)", ret); + return ret; + } + + return val; +} + +static int get_usb_state(void) +{ + int ret, val; + int result = 0; + + ret = vconf_get_int(VCONFKEY_SYSMAN_USB_STATUS, &val); + if (ret != 0) { + _E("Failed to get usb_state (%d)", ret); + return ret; + } + + if (val == VCONFKEY_SYSMAN_USB_DISCONNECTED) + result = val; + else { + result = VCONFKEY_SYSMAN_USB_CONNECTED; + if (val == VCONFKEY_SYSMAN_USB_AVAILABLE) + result |= VCONFKEY_SYSMAN_USB_AVAILABLE; + } + + return result; +} + +/* dbus signals */ +void broadcast_usb_config_enabled(int state) +{ + int ret; + char *param[1]; + char buf[2]; + + snprintf(buf, sizeof(buf), "%d", state); + param[0] = buf; + + _I("USB config enabled (%d)", state); + + ret = broadcast_edbus_signal(DEVICED_PATH_USB, + DEVICED_INTERFACE_USB, SIGNAL_CONFIG_ENABLED, + "i", param); + if (ret < 0) + _E("Failed to send dbus signal"); +} + +void broadcast_usb_state_changed(void) +{ + int ret; + char *param[1]; + char text[16]; + unsigned int state; + static unsigned int prev_state = UINT_MAX; + + state = get_usb_state(); + if (state == prev_state) + return; + prev_state = state; + + _I("USB state changed (%u)", state); + + snprintf(text, sizeof(text), "%u", state); + param[0] = text; + + ret = broadcast_edbus_signal(DEVICED_PATH_USB, + DEVICED_INTERFACE_USB, SIGNAL_STATE_CHANGED, + "u", param); + if (ret < 0) + _E("Failed to send dbus signal"); +} + +void broadcast_usb_mode_changed(void) +{ + int ret; + char *param[1]; + char text[16]; + unsigned int mode; + static unsigned int prev_mode = UINT_MAX; + + mode = get_usb_current_mode(); + if (mode == prev_mode) + return; + prev_mode = mode; + + snprintf(text, sizeof(text), "%u", mode); + param[0] = text; + + _I("USB mode changed (%u)", mode); + + ret = broadcast_edbus_signal(DEVICED_PATH_USB, + DEVICED_INTERFACE_USB, SIGNAL_MODE_CHANGED, + "u", param); + if (ret < 0) + _E("Failed to send dbus signal"); +} + +static void change_usb_client_mode(void *data, DBusMessage *msg) +{ + DBusError err; + int req, debug; + int ret; + char *mode; + + if (dbus_message_is_signal(msg, DEVICED_INTERFACE_USB, CHANGE_USB_MODE) == 0) + return; + + dbus_error_init(&err); + + if (dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &req, DBUS_TYPE_INVALID) == 0) { + _E("FAIL: dbus_message_get_args"); + goto out; + } + + debug = 0; + switch (req) { + case SET_USB_DEFAULT: + case SET_USB_SDB: + case SET_USB_SDB_DIAG: + mode = USB_MODE_STR_DEFAULT; + debug = 1; + break; + case SET_USB_RNDIS: + case SET_USB_RNDIS_DIAG: + case SET_USB_RNDIS_SDB: + mode = USB_MODE_STR_TETHERING; + debug = 1; + break; + case 11: /* SET_USB_DIAG_RMNET */ + case 12: /* SET_USB_ACM_SDB_DM */ + default: + _E("(%d) is unknown usb mode", req); + goto out; + } + + if (vconf_set_bool(VCONFKEY_SETAPPL_USB_DEBUG_MODE_BOOL, debug) != 0) + _E("Failed to set usb debug toggle (%d)", debug); + + ret = usb_change_mode(mode); + if (ret < 0) + _E("Failed to change usb mode (%d)", ret); + +out: + dbus_error_free(&err); +} + +/* dbus methods */ +static DBusMessage *get_usb_client_state(E_DBus_Object *obj, DBusMessage *msg) +{ + DBusMessageIter iter; + DBusMessage *reply; + unsigned int state; + + state = get_usb_state(); + + reply = dbus_message_new_method_return(msg); + dbus_message_iter_init_append(reply, &iter); + dbus_message_iter_append_basic(&iter, DBUS_TYPE_UINT32, &state); + return reply; +} + +static DBusMessage *get_usb_client_mode(E_DBus_Object *obj, DBusMessage *msg) +{ + DBusMessageIter iter; + DBusMessage *reply; + unsigned int mode; + + mode = get_usb_current_mode(); + + reply = dbus_message_new_method_return(msg); + dbus_message_iter_init_append(reply, &iter); + dbus_message_iter_append_basic(&iter, DBUS_TYPE_UINT32, &mode); + return reply; +} + +static const struct edbus_method edbus_methods[] = { + { "GetState", NULL, "u", get_usb_client_state }, /* from Tizen 2.3 */ + { "GetMode", NULL, "u", get_usb_client_mode }, /* from Tizen 2.3 */ + /* Add methods here */ +}; + +int usb_dbus_init(void) +{ + int ret; + + ret = register_edbus_method(DEVICED_PATH_USB, + edbus_methods, ARRAY_SIZE(edbus_methods)); + if (ret < 0) { + _E("Failed to register dbus method (%d)", ret); + return ret; + } + + ret = register_edbus_signal_handler(DEVICED_PATH_USB, + DEVICED_INTERFACE_USB, "ChangeUsbMode", + change_usb_client_mode); + if (ret < 0) { + _E("Failed to registser dbus signal (%d)", ret); + return ret; + } + + return 0; +} diff --git a/src/usb/usb.c b/src/usb/usb.c index 7819b02..39002c7 100644 --- a/src/usb/usb.c +++ b/src/usb/usb.c @@ -254,7 +254,7 @@ static void usb_change_state(int val, usb_mode_e mode_e) break; case USB_MODE_DEFAULT: default: - mode = SET_USB_DEFAULT; + mode = SET_USB_SDB; legacy_mode = SETTING_USB_DEFAULT_MODE; if (noti_id < 0) noti_id = add_notification("MediaDeviceNotiOn"); @@ -270,12 +270,18 @@ static void usb_change_state(int val, usb_mode_e mode_e) if (old_status != val) { usb_state_send_system_event(val); vconf_set_int(VCONFKEY_SYSMAN_USB_STATUS, val); + broadcast_usb_state_changed(); old_status = val; } if (old_mode != mode) { vconf_set_int(VCONFKEY_USB_CUR_MODE, mode); vconf_set_int(VCONFKEY_SETAPPL_USB_MODE_INT, legacy_mode); + broadcast_usb_mode_changed(); + if (mode == SET_USB_NONE) + broadcast_usb_config_enabled(DISABLED); + else + broadcast_usb_config_enabled(ENABLED); old_mode = mode; } } @@ -371,6 +377,10 @@ static void usb_init(void *data) if (ret < 0) _E("Failed to initialize usb configuation"); + ret = usb_dbus_init(); + if (ret < 0) + _E("Failed to init dbus (%d)", ret); + add_usb_tethering_handler(); ret = usb_state_changed(extcon_usb_ops.status); diff --git a/src/usb/usb.h b/src/usb/usb.h index dd4b7d5..d991fcd 100644 --- a/src/usb/usb.h +++ b/src/usb/usb.h @@ -54,4 +54,16 @@ void remove_usb_config(const struct usb_config_ops *ops); int usb_change_mode(char *name); +/* dbus methods/signals (usb-dbus.c) */ +enum { + DISABLED, + ENABLED, +}; + +int usb_dbus_init(void); + +void broadcast_usb_config_enabled(int state); +void broadcast_usb_state_changed(void); +void broadcast_usb_mode_changed(void); + #endif /* __USB_CLIENT_H__ */ -- 2.7.4 From 7891a5b419e41392f08d3d586a767ee8659afd72 Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Wed, 6 Jul 2016 19:22:21 +0900 Subject: [PATCH 13/16] haptic: Seperate haptic operation for wearable-circle from haptic.c Change-Id: I3c81b10bbe1909abe1bcb74e8ad6ee8c78401177 Signed-off-by: pr.jung --- CMakeLists.txt | 5 - src/haptic/CMakeLists.txt | 16 +- src/haptic/circle.c | 546 ++++++++++++++++++++++++++++++++++++++++++++++ src/haptic/haptic.c | 92 -------- src/haptic/standard-mix.c | 16 -- src/haptic/standard.c | 15 -- 6 files changed, 559 insertions(+), 131 deletions(-) create mode 100644 src/haptic/circle.c diff --git a/CMakeLists.txt b/CMakeLists.txt index a3a3f46..5eec0be 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,11 +19,6 @@ ENDIF() ######################################################## # Deviced Macros ######################################################## -IF("${PROFILE}" STREQUAL "wearable") - IF("${ARCH}" STREQUAL "arm") - ADD_DEFINITIONS("-DWEARABLE_CIRCLE") - ENDIF() -ENDIF() MACRO(ADD_SOURCE DIR OUT) FILE(GLOB ALL_SRCS "${DIR}/*.c") diff --git a/src/haptic/CMakeLists.txt b/src/haptic/CMakeLists.txt index 69b0be9..e0eabe0 100755 --- a/src/haptic/CMakeLists.txt +++ b/src/haptic/CMakeLists.txt @@ -22,6 +22,12 @@ ENDIF() ######################################################## SET(VERSION 0.1.0) +IF("${PROFILE}" STREQUAL "wearable") + IF("${ARCH}" STREQUAL "arm") + SET(CIRCLE "on") + ENDIF() +ENDIF() + SET(SRCS main.c haptic.c @@ -37,10 +43,14 @@ SET(SRCS ${CMAKE_SOURCE_DIR}/src/core/log.c ${CMAKE_SOURCE_DIR}/src/shared/dbus.c ) -IF(STANDARD_MIX STREQUAL on) - SET(SRCS ${SRCS} standard-mix.c) +IF(CIRCLE STREQUAL on) + SET(SRCS ${SRCS} circle.c) ELSE() - SET(SRCS ${SRCS} standard.c) + IF(STANDARD_MIX STREQUAL on) + SET(SRCS ${SRCS} standard-mix.c) + ELSE() + SET(SRCS ${SRCS} standard.c) + ENDIF() ENDIF() INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/src) diff --git a/src/haptic/circle.c b/src/haptic/circle.c new file mode 100644 index 0000000..298a46e --- /dev/null +++ b/src/haptic/circle.c @@ -0,0 +1,546 @@ +/* + * deviced-vibrator + * + * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * + * 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. + */ + + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "core/log.h" +#include "core/list.h" +#include "core/config-parser.h" +#include "haptic.h" + +#define VIBRATION_CONF_PATH "/usr/share/feedback/vibration.conf" +#define CIRCLE_ON_PATH "/sys/class/sec/motor/motor_on" +#define CIRCLE_OFF_PATH "/sys/class/sec/motor/motor_off" + + +struct vibration_config { + char *pattern; + dd_list *data; +}; + +struct duration_data { + int duration; + int wait; +}; + +struct haptic_data { + dd_list *vibration_data; + unsigned int handle; + int level; + int priority; + bool stop; +}; + +static int fd_play = -1, fd_stop = -1; +static dd_list *handle_list; +static dd_list *vib_conf_list; +static Ecore_Timer *duration_timer; +static Ecore_Timer *stop_timer; +static int unique_number; +static bool state = false; + +static int stop_device(int device_handle); +static bool find_from_list(int handle) +{ + dd_list *elem; + + elem = DD_LIST_FIND(handle_list, (gpointer)(long)handle); + if (elem) + return true; + + return false; +} + +static Eina_Bool timer_cb(void *data) +{ + int device_handle = (int)(long)data; + _I("stop vibration by timer"); + + /* stop previous vibration */ + stop_device(device_handle); + + return ECORE_CALLBACK_CANCEL; +} + +static int get_device_count(int *count) +{ + /* suppose there is just one haptic device */ + if (count) + *count = 1; + + return 0; +} + +static int open_device(int device_index, int *device_handle) +{ + int n; + bool found = false; + dd_list *elem; + + if (!device_handle) + return -EINVAL; + + /* if it is the first element */ + n = DD_LIST_LENGTH(handle_list); + if (n == 0) { + _I("Open"); + if (fd_play < 0) { + fd_play = open(CIRCLE_ON_PATH, O_RDONLY); + if (fd_play < 0) { + _E("Failed to open %s : %d", CIRCLE_ON_PATH, errno); + return -errno; + } + } + if (fd_stop < 0) { + fd_stop = open(CIRCLE_OFF_PATH, O_RDONLY); + if (fd_stop < 0) { + _E("Failed to open %s : %d", CIRCLE_OFF_PATH, errno); + return -errno; + } + } + } + + if (unique_number == INT_MAX) + unique_number = 0; + + while (found != true) { + ++unique_number; + elem = DD_LIST_FIND(handle_list, (gpointer)(long)unique_number); + if (!elem) + found = true; + } + + /* add info to local list */ + DD_LIST_APPEND(handle_list, (gpointer)(long)unique_number); + + *device_handle = unique_number; + return 0; +} + +static int close_device(int device_handle) +{ + int r, n; + bool found; + + found = find_from_list(device_handle); + if (!found) + return -EINVAL; + + if (fd_stop < 0) { + fd_stop = open(CIRCLE_OFF_PATH, O_RDONLY); + if (fd_stop < 0) + return -ENODEV; + } + + /* stop vibration */ + r = stop_device(device_handle); + if (r < 0) + _I("already stopped or failed to stop effect : %d", r); + + /* unregister existing timer */ + if (r >= 0) { + _D("device handle %d is closed and timer deleted", device_handle); + if (stop_timer) { + ecore_timer_del(stop_timer); + stop_timer = NULL; + } + if (duration_timer) { + ecore_timer_del(duration_timer); + duration_timer = NULL; + } + } + + DD_LIST_REMOVE(handle_list, (gpointer)(long)device_handle); + + /* if it is the last element */ + n = DD_LIST_LENGTH(handle_list); + if (n == 0) { + _I("Close"); + if (fd_play > 0) { + close(fd_play); + fd_play = -1; + } + if (fd_stop > 0) { + close(fd_stop); + fd_stop = -1; + } + } + + return 0; +} + +static int vibrate_monotone(int device_handle, int duration, int feedback, int priority, int *effect_handle) +{ + int ret; + char buf[8]; + bool found; + + found = find_from_list(device_handle); + if (!found) + return -EINVAL; + + if (fd_play < 0) { + fd_play = open(CIRCLE_ON_PATH, O_RDONLY); + if (fd_play < 0) + return -ENODEV; + } + + /* Zero(0) is the infinitely vibration value */ + if (duration == HAPTIC_MODULE_DURATION_UNLIMITED) + duration = 0; + + if (stop_timer) + stop_device(device_handle); + + /* play vibration */ + ret = read(fd_play, buf, 8); + if (ret < 0) { + _E("failed to play"); + return -errno; + } + + /* register timer */ + if (duration) { + stop_timer = ecore_timer_add(duration/1000.f, timer_cb, (void *)(long)device_handle); + if (!stop_timer) + _E("Failed to add timer callback"); + } + + _D("device handle %d %dms", device_handle, duration); + + return 0; +} + +static Eina_Bool haptic_duration_play(void *data) +{ + dd_list *head, *n, *next; + struct haptic_data *h_data; + struct duration_data *node; + int ret = 0; + + if (!data) + goto out; + + if (duration_timer) { + ecore_timer_del(duration_timer); + duration_timer = NULL; + } + + h_data = (struct haptic_data *)data; + if (h_data->stop) { + h_data->stop = false; + free(h_data); + goto out; + } + + head = h_data->vibration_data; + DD_LIST_FOREACH_SAFE(head, n, next, node) { + _D("Play: %dms and Wait: %dms", node->duration, node->wait); + if (!node->duration) { + free(h_data); + break; + } + + if (node->wait && next) { + h_data->vibration_data = next; + duration_timer = ecore_timer_add((node->duration + node->wait)/1000.0f, haptic_duration_play, (void *)h_data); + } + + ret = vibrate_monotone(h_data->handle, node->duration, 0, 0, NULL); + if (!next) { + free(h_data); + goto out; + } + break; + } + if (ret != 0) { + _D("auto stop vibration"); + if (h_data) + h_data->stop = true; + } +out: + return ECORE_CALLBACK_CANCEL; +} + +static int vibrate_buffer(int device_handle, const unsigned char *vibe_buffer, int iteration, int feedback, int priority, int *effect_handle) +{ + _E("Not support feature"); + return -EACCES; +} + +static int vibrate_effect(int device_handle, const char *pattern, int feedback, int priority) +{ + dd_list *elem; + struct vibration_config *conf; + struct haptic_data *data; + size_t len; + + if (device_handle < 0) + return -EINVAL; + + len = strlen(pattern) + 1; + DD_LIST_FOREACH(vib_conf_list, elem, conf) { + if (!conf->pattern) + continue; + if (strncmp(conf->pattern, pattern, len)) + continue; + + data = (struct haptic_data *)malloc(sizeof(struct haptic_data)); + if (!data) { + _E("fail to alloc"); + return -ENOMEM; + } + data->vibration_data = conf->data; + data->handle = device_handle; + data->stop = false; + _D("Play %s", conf->pattern); + haptic_duration_play((void *)data); + break; + } + + return 0; +} + +static int is_supported(const char *pattern) +{ + dd_list *elem; + struct vibration_config *conf; + size_t len; + int ret; + + if (!pattern) + return -EINVAL; + + len = strlen(pattern) + 1; + ret = 0; + DD_LIST_FOREACH(vib_conf_list, elem, conf) { + if (!conf->pattern) + continue; + if (!strncmp(conf->pattern, pattern, len)) { + ret = true; + break; + } + } + + return ret; +} + +static int stop_device(int device_handle) +{ + int ret; + char buf[8]; + bool found; + + found = find_from_list(device_handle); + if (!found) + return -EINVAL; + + if (fd_stop < 0) { + fd_stop = open(CIRCLE_OFF_PATH, O_RDONLY); + if (fd_stop < 0) + return -ENODEV; + } + ret = read(fd_stop, buf, 8); + if (ret < 0) { + _E("failed to stop"); + return -errno; + } + if (stop_timer) { + ecore_timer_del(stop_timer); + stop_timer = NULL; + } + + return 0; +} + +static int get_device_state(int device_index, int *effect_state) +{ + if (!effect_state) + return -EINVAL; + + *effect_state = state; + return 0; +} + +static int create_effect(unsigned char *vibe_buffer, int max_bufsize, haptic_module_effect_element *elem_arr, int max_elemcnt) +{ + _E("Not support feature"); + return -EACCES; +} + +static int get_buffer_duration(int device_handle, const unsigned char *vibe_buffer, int *buffer_duration) +{ + _E("Not support feature"); + return -EACCES; +} + +static int convert_binary(const unsigned char *vibe_buffer, int max_bufsize, const char *file_path) +{ + _E("Not support feature"); + return -EACCES; +} +/* END: Haptic Module APIs */ + +static const struct haptic_plugin_ops default_plugin = { + .get_device_count = get_device_count, + .open_device = open_device, + .close_device = close_device, + .vibrate_monotone = vibrate_monotone, + .vibrate_buffer = vibrate_buffer, + .vibrate_effect = vibrate_effect, + .is_supported = is_supported, + .stop_device = stop_device, + .get_device_state = get_device_state, + .create_effect = create_effect, + .get_buffer_duration = get_buffer_duration, + .convert_binary = convert_binary, +}; + +static int vibration_load_config(struct parse_result *result, void *user_data) +{ + struct vibration_config *conf; + struct duration_data *data; + char *value; + char *check; + int len; + + if (!result) + return 0; + + if (!MATCH(result->section, "Vibration")) + return 0; + + + if (!result->name || !result->value) + return 0; + + conf = (struct vibration_config *)calloc(1, sizeof(struct vibration_config)); + if (!conf) { + _E("fail to alloc"); + return -ENOMEM; + } + + conf->pattern = strdup(result->name); + if (!conf->pattern) + _E("fail to copy %s pattern data", result->name); + + value = result->value; + + if (!value) + len = 0; + else + len = strlen(value); + + if (len == 0) { + data = (struct duration_data *)malloc(sizeof(struct duration_data)); + if (!data) { + _E("not enough memory"); + free(conf->pattern); + free(conf); + return -ENOMEM; + } + data->duration = 0; + data->wait = 0; + + DD_LIST_APPEND(conf->data, data); + DD_LIST_APPEND(vib_conf_list, conf); + return 0; + } + + do { + data = (struct duration_data *)malloc(sizeof(struct duration_data)); + if (!data) { + _E("not enough memory"); + free(conf->pattern); + free(conf); + return -ENOMEM; + } + data->duration = 0; + data->wait = 0; + + check = strchr(value, 'D'); + if (check) { + *check = '\0'; + data->duration = strtol(value, NULL, 10); + if (!value) + len = len - 1; + else + len = len - strlen(value) - 1; + value = check + 1; + } + check = strchr(value, 'W'); + if (check) { + *check = '\0'; + data->wait = strtol(value, NULL, 10); + if (!value) + len = len - 1; + else + len = len - strlen(value) - 1; + value = check + 1; + } + DD_LIST_APPEND(conf->data, data); + if (data->duration == 0 && data->wait == 0) + break; + } while (value && len > 0); + + DD_LIST_APPEND(vib_conf_list, conf); + + return 0; +} + +static bool is_valid(void) +{ + int ret; + + if ((access(CIRCLE_ON_PATH, R_OK) != 0) || + (access(CIRCLE_OFF_PATH, R_OK) != 0)) { + _E("Do not support wearable haptic device"); + state = false; + return false; + } + + ret = config_parse(VIBRATION_CONF_PATH, vibration_load_config, NULL); + if (ret < 0) + _E("failed to load configuration file(%s) : %d", VIBRATION_CONF_PATH, ret); + + state = true; + _I("Support wearable haptic device"); + return true; +} + +static const struct haptic_plugin_ops *load(void) +{ + return &default_plugin; +} + +static const struct haptic_ops std_ops = { + .type = HAPTIC_STANDARD, + .is_valid = is_valid, + .load = load, +}; + +HAPTIC_OPS_REGISTER(&std_ops) diff --git a/src/haptic/haptic.c b/src/haptic/haptic.c index b5ab3e7..f67a37d 100644 --- a/src/haptic/haptic.c +++ b/src/haptic/haptic.c @@ -33,23 +33,12 @@ #include "core/config-parser.h" #include "haptic.h" -#ifdef WEARABLE_CIRCLE -#include -#include -#include -#endif - #ifndef DATADIR #define DATADIR "/usr/share/deviced" #endif #define HAPTIC_CONF_PATH "/etc/deviced/haptic.conf" -#ifdef WEARABLE_CIRCLE -#define CIRCLE_ON_PATH "/sys/class/sec/motor/motor_on" -#define CIRCLE_OFF_PATH "/sys/class/sec/motor/motor_off" -#endif - /* hardkey vibration variable */ #define HARDKEY_VIB_ITERATION 1 #define HARDKEY_VIB_FEEDBACK 3 @@ -160,64 +149,6 @@ static int convert_magnitude_by_conf(int level) return DEFAULT_FEEDBACK_LEVEL * HAPTIC_FEEDBACK_STEP; } -#ifdef WEARABLE_CIRCLE -Ecore_Timer *timer; - -static int circle_stop(); -static Eina_Bool timer_cb(void *data) -{ - circle_stop(); - return ECORE_CALLBACK_CANCEL; -} - -static int circle_stop() -{ - int fd, ret; - char buf[8]; - - fd = open(CIRCLE_OFF_PATH, O_RDONLY); - if (fd < 0) - return -ENODEV; - ret = read(fd, buf, 8); - if (ret < 0) { - _E("Failed to stop"); - close(fd); - return -1; - } - close(fd); - if (timer) { - ecore_timer_del(timer); - timer = NULL; - } - return 0; -} - -static int circle_play(int duration) -{ - int fd, ret; - char buf[8]; - - if (timer) { - ecore_timer_del(timer); - timer = NULL; - } - - fd = open(CIRCLE_ON_PATH, O_RDONLY); - if (fd < 0) - return -ENODEV; - ret = read(fd, buf, 8); - if (ret < 0) { - _E("Failed to play"); - close(fd); - return -1; - } - close(fd); - ecore_timer_add(duration/1000.f, timer_cb, timer); - - return 0; -} -#endif - static DBusMessage *edbus_get_count(E_DBus_Object *obj, DBusMessage *msg) { DBusMessageIter iter; @@ -327,10 +258,6 @@ static DBusMessage *edbus_open_device(E_DBus_Object *obj, DBusMessage *msg) goto exit; } -#ifdef WEARABLE_CIRCLE - ret = 1; - goto exit; -#endif ret = h_ops->open_device(index, &handle); if (ret < 0) goto exit; @@ -390,10 +317,6 @@ static DBusMessage *edbus_close_device(E_DBus_Object *obj, DBusMessage *msg) goto exit; } -#ifdef WEARABLE_CIRCLE - goto exit; -#endif - ret = h_ops->close_device(handle); if (ret < 0) goto exit; @@ -444,11 +367,6 @@ static DBusMessage *edbus_vibrate_monotone(E_DBus_Object *obj, DBusMessage *msg) goto exit; } -#ifdef WEARABLE_CIRCLE - ret = circle_play(duration); - goto exit; -#endif - ret = h_ops->vibrate_monotone(handle, duration, level, priority, &e_handle); if (ret >= 0) ret = e_handle; @@ -531,11 +449,6 @@ static DBusMessage *edbus_vibrate_effect(E_DBus_Object *obj, DBusMessage *msg) goto exit; } -#ifdef WEARABLE_CIRCLE - ret = circle_play(100); - goto exit; -#endif - ret = h_ops->vibrate_effect(handle, pattern, level, priority); @@ -564,11 +477,6 @@ static DBusMessage *edbus_stop_device(E_DBus_Object *obj, DBusMessage *msg) goto exit; } -#ifdef WEARABLE_CIRCLE - ret = circle_stop(); - goto exit; -#endif - ret = h_ops->stop_device(handle); exit: diff --git a/src/haptic/standard-mix.c b/src/haptic/standard-mix.c index 539d386..d810955 100644 --- a/src/haptic/standard-mix.c +++ b/src/haptic/standard-mix.c @@ -55,11 +55,6 @@ #define VIBRATION_DURATION_CONF_PATH "/usr/share/feedback/vibration_duration.conf" #define VIBRATION_WAITING_CONF_PATH "/usr/share/feedback/vibration_waiting.conf" -#ifdef WEARABLE_CIRCLE -#define CIRCLE_ON_PATH "/sys/class/sec/motor/motor_on" -#define CIRCLE_OFF_PATH "/sys/class/sec/motor/motor_off" -#endif - struct ff_info_header { unsigned int magic; int iteration; @@ -1058,17 +1053,6 @@ static bool is_valid(void) { int ret; -#ifdef WEARABLE_CIRCLE - if ((access(CIRCLE_ON_PATH, R_OK) != 0) || - (access(CIRCLE_OFF_PATH, R_OK) != 0)) { - _E("Do not support wearable haptic device"); - return false; - } - - _I("Support wearable haptic device"); - return true; -#endif - ret = ff_find_device(); if (ret < 0) { _E("Do not support standard haptic device"); diff --git a/src/haptic/standard.c b/src/haptic/standard.c index 7be333a..3ae2a97 100644 --- a/src/haptic/standard.c +++ b/src/haptic/standard.c @@ -52,10 +52,6 @@ #define FF_INFO_MAGIC 0xDEADFEED #define VIBRATION_CONF_PATH "/usr/share/feedback/vibration.conf" -#ifdef WEARABLE_CIRCLE -#define CIRCLE_ON_PATH "/sys/class/sec/motor/motor_on" -#define CIRCLE_OFF_PATH "/sys/class/sec/motor/motor_off" -#endif struct ff_info_header { unsigned int magic; @@ -896,17 +892,6 @@ static bool is_valid(void) { int ret; -#ifdef WEARABLE_CIRCLE - if ((access(CIRCLE_ON_PATH, R_OK) != 0) || - (access(CIRCLE_OFF_PATH, R_OK) != 0)) { - _E("Do not support wearable haptic device"); - return false; - } - - _I("Support wearable haptic device"); - return true; -#endif - ret = ff_find_device(); if (ret < 0) { _E("Do not support standard haptic device"); -- 2.7.4 From 15a2d033a1d05e13e955797f4c6e5805f0df320b Mon Sep 17 00:00:00 2001 From: Kunhoon Baik Date: Sat, 13 Aug 2016 10:04:25 +0900 Subject: [PATCH 14/16] Refactoring Standard Vibrate Engine Circle and Forced Feedback Standard Engine use standard Core Engine. Thus, Standard Core Engine was seperated. Change-Id: I058f98b94a3a6c9ff9b4e2b9e2e95b99d91dbe71 --- src/haptic/CMakeLists.txt | 4 +- src/haptic/circle.c | 239 ++------------------------------------- src/haptic/standard-vibcore.c | 257 ++++++++++++++++++++++++++++++++++++++++++ src/haptic/standard-vibcore.h | 7 ++ src/haptic/standard.c | 238 ++------------------------------------ 5 files changed, 283 insertions(+), 462 deletions(-) create mode 100644 src/haptic/standard-vibcore.c create mode 100644 src/haptic/standard-vibcore.h diff --git a/src/haptic/CMakeLists.txt b/src/haptic/CMakeLists.txt index e0eabe0..537c938 100755 --- a/src/haptic/CMakeLists.txt +++ b/src/haptic/CMakeLists.txt @@ -44,12 +44,12 @@ SET(SRCS ${CMAKE_SOURCE_DIR}/src/shared/dbus.c ) IF(CIRCLE STREQUAL on) - SET(SRCS ${SRCS} circle.c) + SET(SRCS ${SRCS} circle.c standard-vibcore.c) ELSE() IF(STANDARD_MIX STREQUAL on) SET(SRCS ${SRCS} standard-mix.c) ELSE() - SET(SRCS ${SRCS} standard.c) + SET(SRCS ${SRCS} standard.c standard-vibcore.c) ENDIF() ENDIF() diff --git a/src/haptic/circle.c b/src/haptic/circle.c index 298a46e..b9b2aa0 100644 --- a/src/haptic/circle.c +++ b/src/haptic/circle.c @@ -29,36 +29,14 @@ #include "core/log.h" #include "core/list.h" -#include "core/config-parser.h" #include "haptic.h" +#include "standard-vibcore.h" -#define VIBRATION_CONF_PATH "/usr/share/feedback/vibration.conf" #define CIRCLE_ON_PATH "/sys/class/sec/motor/motor_on" #define CIRCLE_OFF_PATH "/sys/class/sec/motor/motor_off" - -struct vibration_config { - char *pattern; - dd_list *data; -}; - -struct duration_data { - int duration; - int wait; -}; - -struct haptic_data { - dd_list *vibration_data; - unsigned int handle; - int level; - int priority; - bool stop; -}; - static int fd_play = -1, fd_stop = -1; static dd_list *handle_list; -static dd_list *vib_conf_list; -static Ecore_Timer *duration_timer; static Ecore_Timer *stop_timer; static int unique_number; static bool state = false; @@ -168,12 +146,10 @@ static int close_device(int device_handle) ecore_timer_del(stop_timer); stop_timer = NULL; } - if (duration_timer) { - ecore_timer_del(duration_timer); - duration_timer = NULL; - } } + standard_vibrate_close(); + DD_LIST_REMOVE(handle_list, (gpointer)(long)device_handle); /* if it is the last element */ @@ -235,120 +211,12 @@ static int vibrate_monotone(int device_handle, int duration, int feedback, int p return 0; } -static Eina_Bool haptic_duration_play(void *data) -{ - dd_list *head, *n, *next; - struct haptic_data *h_data; - struct duration_data *node; - int ret = 0; - - if (!data) - goto out; - - if (duration_timer) { - ecore_timer_del(duration_timer); - duration_timer = NULL; - } - - h_data = (struct haptic_data *)data; - if (h_data->stop) { - h_data->stop = false; - free(h_data); - goto out; - } - - head = h_data->vibration_data; - DD_LIST_FOREACH_SAFE(head, n, next, node) { - _D("Play: %dms and Wait: %dms", node->duration, node->wait); - if (!node->duration) { - free(h_data); - break; - } - - if (node->wait && next) { - h_data->vibration_data = next; - duration_timer = ecore_timer_add((node->duration + node->wait)/1000.0f, haptic_duration_play, (void *)h_data); - } - - ret = vibrate_monotone(h_data->handle, node->duration, 0, 0, NULL); - if (!next) { - free(h_data); - goto out; - } - break; - } - if (ret != 0) { - _D("auto stop vibration"); - if (h_data) - h_data->stop = true; - } -out: - return ECORE_CALLBACK_CANCEL; -} - static int vibrate_buffer(int device_handle, const unsigned char *vibe_buffer, int iteration, int feedback, int priority, int *effect_handle) { _E("Not support feature"); return -EACCES; } -static int vibrate_effect(int device_handle, const char *pattern, int feedback, int priority) -{ - dd_list *elem; - struct vibration_config *conf; - struct haptic_data *data; - size_t len; - - if (device_handle < 0) - return -EINVAL; - - len = strlen(pattern) + 1; - DD_LIST_FOREACH(vib_conf_list, elem, conf) { - if (!conf->pattern) - continue; - if (strncmp(conf->pattern, pattern, len)) - continue; - - data = (struct haptic_data *)malloc(sizeof(struct haptic_data)); - if (!data) { - _E("fail to alloc"); - return -ENOMEM; - } - data->vibration_data = conf->data; - data->handle = device_handle; - data->stop = false; - _D("Play %s", conf->pattern); - haptic_duration_play((void *)data); - break; - } - - return 0; -} - -static int is_supported(const char *pattern) -{ - dd_list *elem; - struct vibration_config *conf; - size_t len; - int ret; - - if (!pattern) - return -EINVAL; - - len = strlen(pattern) + 1; - ret = 0; - DD_LIST_FOREACH(vib_conf_list, elem, conf) { - if (!conf->pattern) - continue; - if (!strncmp(conf->pattern, pattern, len)) { - ret = true; - break; - } - } - - return ret; -} - static int stop_device(int device_handle) { int ret; @@ -411,8 +279,8 @@ static const struct haptic_plugin_ops default_plugin = { .close_device = close_device, .vibrate_monotone = vibrate_monotone, .vibrate_buffer = vibrate_buffer, - .vibrate_effect = vibrate_effect, - .is_supported = is_supported, + .vibrate_effect = standard_vibrate_effect, + .is_supported = standard_is_supported, .stop_device = stop_device, .get_device_state = get_device_state, .create_effect = create_effect, @@ -420,98 +288,6 @@ static const struct haptic_plugin_ops default_plugin = { .convert_binary = convert_binary, }; -static int vibration_load_config(struct parse_result *result, void *user_data) -{ - struct vibration_config *conf; - struct duration_data *data; - char *value; - char *check; - int len; - - if (!result) - return 0; - - if (!MATCH(result->section, "Vibration")) - return 0; - - - if (!result->name || !result->value) - return 0; - - conf = (struct vibration_config *)calloc(1, sizeof(struct vibration_config)); - if (!conf) { - _E("fail to alloc"); - return -ENOMEM; - } - - conf->pattern = strdup(result->name); - if (!conf->pattern) - _E("fail to copy %s pattern data", result->name); - - value = result->value; - - if (!value) - len = 0; - else - len = strlen(value); - - if (len == 0) { - data = (struct duration_data *)malloc(sizeof(struct duration_data)); - if (!data) { - _E("not enough memory"); - free(conf->pattern); - free(conf); - return -ENOMEM; - } - data->duration = 0; - data->wait = 0; - - DD_LIST_APPEND(conf->data, data); - DD_LIST_APPEND(vib_conf_list, conf); - return 0; - } - - do { - data = (struct duration_data *)malloc(sizeof(struct duration_data)); - if (!data) { - _E("not enough memory"); - free(conf->pattern); - free(conf); - return -ENOMEM; - } - data->duration = 0; - data->wait = 0; - - check = strchr(value, 'D'); - if (check) { - *check = '\0'; - data->duration = strtol(value, NULL, 10); - if (!value) - len = len - 1; - else - len = len - strlen(value) - 1; - value = check + 1; - } - check = strchr(value, 'W'); - if (check) { - *check = '\0'; - data->wait = strtol(value, NULL, 10); - if (!value) - len = len - 1; - else - len = len - strlen(value) - 1; - value = check + 1; - } - DD_LIST_APPEND(conf->data, data); - if (data->duration == 0 && data->wait == 0) - break; - } while (value && len > 0); - - DD_LIST_APPEND(vib_conf_list, conf); - - return 0; -} - static bool is_valid(void) { int ret; @@ -523,9 +299,9 @@ static bool is_valid(void) return false; } - ret = config_parse(VIBRATION_CONF_PATH, vibration_load_config, NULL); + ret = standard_config_parse(); if (ret < 0) - _E("failed to load configuration file(%s) : %d", VIBRATION_CONF_PATH, ret); + _E("failed to load standard vibration configuration file : %d", ret); state = true; _I("Support wearable haptic device"); @@ -534,6 +310,7 @@ static bool is_valid(void) static const struct haptic_plugin_ops *load(void) { + standard_set_vib_function(&vibrate_monotone); return &default_plugin; } diff --git a/src/haptic/standard-vibcore.c b/src/haptic/standard-vibcore.c new file mode 100644 index 0000000..3cd85fe --- /dev/null +++ b/src/haptic/standard-vibcore.c @@ -0,0 +1,257 @@ +#include +#include +#include + +#include "core/log.h" +#include "core/list.h" +#include "core/config-parser.h" +#include "standard-vibcore.h" + +#define VIBRATION_CONF_PATH "/usr/share/feedback/vibration.conf" + +struct vibration_config { + char *pattern; + dd_list *data; +}; + +struct duration_data { + int duration; + int wait; +}; + +struct haptic_data { + dd_list *vibration_data; + unsigned int handle; + int level; + int priority; + bool stop; +}; + +static dd_list *vib_conf_list; +static Ecore_Timer *duration_timer; + +static t_vibrate_monotone real_vibrate_monotone; + +static int vibration_load_config(struct parse_result *result, void *user_data) +{ + struct vibration_config *conf; + struct duration_data *data; + char *value; + char *check; + int len; + + if (!result) + return 0; + + if (!MATCH(result->section, "Vibration")) + return 0; + + + if (!result->name || !result->value) + return 0; + + conf = (struct vibration_config *)calloc(1, sizeof(struct vibration_config)); + if (!conf) { + _E("fail to alloc"); + return -ENOMEM; + } + + conf->pattern = strdup(result->name); + if (!conf->pattern) + _E("fail to copy %s pattern data", result->name); + + value = result->value; + + if (!value) + len = 0; + else + len = strlen(value); + + if (len == 0) { + data = (struct duration_data *)malloc(sizeof(struct duration_data)); + if (!data) { + _E("not enough memory"); + free(conf->pattern); + free(conf); + return -ENOMEM; + } + data->duration = 0; + data->wait = 0; + + DD_LIST_APPEND(conf->data, data); + DD_LIST_APPEND(vib_conf_list, conf); + return 0; + } + + do { + data = (struct duration_data *)malloc(sizeof(struct duration_data)); + if (!data) { + _E("not enough memory"); + free(conf->pattern); + free(conf); + return -ENOMEM; + } + data->duration = 0; + data->wait = 0; + + check = strchr(value, 'D'); + if (check) { + *check = '\0'; + data->duration = strtol(value, NULL, 10); + if (!value) + len = len - 1; + else + len = len - strlen(value) - 1; + value = check + 1; + } + check = strchr(value, 'W'); + if (check) { + *check = '\0'; + data->wait = strtol(value, NULL, 10); + if (!value) + len = len - 1; + else + len = len - strlen(value) - 1; + value = check + 1; + } + DD_LIST_APPEND(conf->data, data); + if (data->duration == 0 && data->wait == 0) + break; + } while (value && len > 0); + + DD_LIST_APPEND(vib_conf_list, conf); + + return 0; +} + +int standard_config_parse() +{ + return config_parse(VIBRATION_CONF_PATH, vibration_load_config, NULL); +} + +int standard_is_supported(const char *pattern) +{ + dd_list *elem; + struct vibration_config *conf; + size_t len; + int ret; + + if (!pattern) + return -EINVAL; + + len = strlen(pattern) + 1; + ret = 0; + DD_LIST_FOREACH(vib_conf_list, elem, conf) { + if (!conf->pattern) + continue; + if (!strncmp(conf->pattern, pattern, len)) { + ret = true; + break; + } + } + + return ret; +} + +static Eina_Bool haptic_duration_play(void *data) +{ + dd_list *head, *n, *next; + struct haptic_data *h_data; + struct duration_data *node; + int ret = 0; + + if (!data) + goto out; + + if (duration_timer) { + ecore_timer_del(duration_timer); + duration_timer = NULL; + } + + h_data = (struct haptic_data *)data; + if (h_data->stop) { + h_data->stop = false; + free(h_data); + goto out; + } + + head = h_data->vibration_data; + DD_LIST_FOREACH_SAFE(head, n, next, node) { + _D("Play: %dms and Wait: %dms", node->duration, node->wait); + if (!node->duration) { + free(h_data); + break; + } + + if (node->wait && next) { + h_data->vibration_data = next; + duration_timer = ecore_timer_add((node->duration + node->wait)/1000.0f, haptic_duration_play, (void *)h_data); + } + + ret = real_vibrate_monotone(h_data->handle, node->duration, h_data->level, h_data->priority, NULL); + if (!next) { + free(h_data); + goto out; + } + break; + } + if (ret != 0) { + _D("auto stop vibration"); + if (h_data) + h_data->stop = true; + } +out: + return ECORE_CALLBACK_CANCEL; +} + +int standard_set_vib_function(t_vibrate_monotone func) +{ + real_vibrate_monotone = func; + return 0; +} + +int standard_vibrate_effect(int device_handle, const char *pattern, int feedback, int priority) +{ + dd_list *elem; + struct vibration_config *conf; + struct haptic_data *data; + size_t len; + + if (device_handle < 0) + return -EINVAL; + + len = strlen(pattern) + 1; + DD_LIST_FOREACH(vib_conf_list, elem, conf) { + if (!conf->pattern) + continue; + if (strncmp(conf->pattern, pattern, len)) + continue; + + data = (struct haptic_data *)malloc(sizeof(struct haptic_data)); + if (!data) { + _E("fail to alloc"); + return -ENOMEM; + } + data->vibration_data = conf->data; + data->handle = device_handle; + data->level = feedback; + data->priority = priority; + data->stop = false; + _D("Play %s", conf->pattern); + haptic_duration_play((void *)data); + break; + } + + return 0; +} + +int standard_vibrate_close() +{ + if (duration_timer) { + ecore_timer_del(duration_timer); + duration_timer = NULL; + } + + return 0; +} + diff --git a/src/haptic/standard-vibcore.h b/src/haptic/standard-vibcore.h new file mode 100644 index 0000000..ea54e14 --- /dev/null +++ b/src/haptic/standard-vibcore.h @@ -0,0 +1,7 @@ +typedef int (*t_vibrate_monotone)(int device_handle, int duration, int feedback, int priority, int *effect_handle); + +int standard_config_parse(); +int standard_is_supported(const char *pattern); +int standard_vibrate_effect(int device_handle, const char *pattern, int feedback, int priority); +int standard_set_vib_function(t_vibrate_monotone func); +int standard_vibrate_close(); diff --git a/src/haptic/standard.c b/src/haptic/standard.c index 3ae2a97..0558e63 100644 --- a/src/haptic/standard.c +++ b/src/haptic/standard.c @@ -32,8 +32,8 @@ #include "core/log.h" #include "core/list.h" -#include "core/config-parser.h" #include "haptic.h" +#include "standard-vibcore.h" #define MAX_MAGNITUDE 0xFFFF #define PERIODIC_MAX_MAGNITUDE 0x7FFF /* 0.5 * MAX_MAGNITUDE */ @@ -51,8 +51,6 @@ #define MAX_DATA 16 #define FF_INFO_MAGIC 0xDEADFEED -#define VIBRATION_CONF_PATH "/usr/share/feedback/vibration.conf" - struct ff_info_header { unsigned int magic; int iteration; @@ -78,29 +76,9 @@ struct ff_info { int currentindex; }; -struct vibration_config { - char *pattern; - dd_list *data; -}; - -struct duration_data { - int duration; - int wait; -}; - -struct haptic_data { - dd_list *vibration_data; - unsigned int handle; - int level; - int priority; - bool stop; -}; - static int ff_fd; static dd_list *ff_list; static dd_list *handle_list; -static dd_list *vib_conf_list; -static Ecore_Timer *duration_timer; static char ff_path[PATH_MAX]; static int unique_number; @@ -412,6 +390,8 @@ static int close_device(int device_handle) info->timer = NULL; } + standard_vibrate_close(); + DD_LIST_REMOVE(handle_list, (gpointer)(long)info->handle); safe_free(info->ffinfobuffer); @@ -585,57 +565,6 @@ static int vibrate_custom_buffer(int device_handle, const unsigned char *vibe_bu return 0; } -static Eina_Bool haptic_duration_play(void *data) -{ - dd_list *head, *n, *next; - struct haptic_data *h_data; - struct duration_data *node; - int ret = 0; - - if (!data) - goto out; - - if (duration_timer) { - ecore_timer_del(duration_timer); - duration_timer = NULL; - } - - h_data = (struct haptic_data *)data; - if (h_data->stop) { - h_data->stop = false; - free(h_data); - goto out; - } - - head = h_data->vibration_data; - DD_LIST_FOREACH_SAFE(head, n, next, node) { - _D("Play: %dms and Wait: %dms", node->duration, node->wait); - if (!node->duration) { - free(h_data); - break; - } - - if (node->wait && next) { - h_data->vibration_data = next; - duration_timer = ecore_timer_add((node->duration + node->wait)/1000.0f, haptic_duration_play, (void *)h_data); - } - - ret = vibrate_monotone(h_data->handle, node->duration, h_data->level, h_data->priority, NULL); - if (!next) { - free(h_data); - goto out; - } - break; - } - if (ret != 0) { - _D("auto stop vibration"); - if (h_data) - h_data->stop = true; - } -out: - return ECORE_CALLBACK_CANCEL; -} - static int vibrate_buffer(int device_handle, const unsigned char *vibe_buffer, int iteration, int feedback, int priority, int *effect_handle) { int magic = 0; @@ -653,65 +582,6 @@ static int vibrate_buffer(int device_handle, const unsigned char *vibe_buffer, i return vibrate_monotone(device_handle, 300, feedback, priority, effect_handle); } -static int vibrate_effect(int device_handle, const char *pattern, int feedback, int priority) -{ - dd_list *elem; - struct vibration_config *conf; - struct haptic_data *data; - size_t len; - - if (device_handle < 0) - return -EINVAL; - - len = strlen(pattern) + 1; - DD_LIST_FOREACH(vib_conf_list, elem, conf) { - if (!conf->pattern) - continue; - if (strncmp(conf->pattern, pattern, len)) - continue; - - data = (struct haptic_data *)malloc(sizeof(struct haptic_data)); - if (!data) { - _E("fail to alloc"); - return -ENOMEM; - } - data->vibration_data = conf->data; - data->handle = device_handle; - data->level = feedback; - data->priority = priority; - data->stop = false; - _D("Play %s", conf->pattern); - haptic_duration_play((void *)data); - break; - } - - return 0; -} - -static int is_supported(const char *pattern) -{ - dd_list *elem; - struct vibration_config *conf; - size_t len; - int ret; - - if (!pattern) - return -EINVAL; - - len = strlen(pattern) + 1; - ret = 0; - DD_LIST_FOREACH(vib_conf_list, elem, conf) { - if (!conf->pattern) - continue; - if (!strncmp(conf->pattern, pattern, len)) { - ret = true; - break; - } - } - - return ret; -} - static int stop_device(int device_handle) { struct ff_info *info; @@ -787,8 +657,8 @@ static const struct haptic_plugin_ops default_plugin = { .close_device = close_device, .vibrate_monotone = vibrate_monotone, .vibrate_buffer = vibrate_buffer, - .vibrate_effect = vibrate_effect, - .is_supported = is_supported, + .vibrate_effect = standard_vibrate_effect, + .is_supported = standard_is_supported, .stop_device = stop_device, .get_device_state = get_device_state, .create_effect = create_effect, @@ -796,98 +666,6 @@ static const struct haptic_plugin_ops default_plugin = { .convert_binary = convert_binary, }; -static int vibration_load_config(struct parse_result *result, void *user_data) -{ - struct vibration_config *conf; - struct duration_data *data; - char *value; - char *check; - int len; - - if (!result) - return 0; - - if (!MATCH(result->section, "Vibration")) - return 0; - - - if (!result->name || !result->value) - return 0; - - conf = (struct vibration_config *)calloc(1, sizeof(struct vibration_config)); - if (!conf) { - _E("fail to alloc"); - return -ENOMEM; - } - - conf->pattern = strdup(result->name); - if (!conf->pattern) - _E("fail to copy %s pattern data", result->name); - - value = result->value; - - if (!value) - len = 0; - else - len = strlen(value); - - if (len == 0) { - data = (struct duration_data *)malloc(sizeof(struct duration_data)); - if (!data) { - _E("not enough memory"); - free(conf->pattern); - free(conf); - return -ENOMEM; - } - data->duration = 0; - data->wait = 0; - - DD_LIST_APPEND(conf->data, data); - DD_LIST_APPEND(vib_conf_list, conf); - return 0; - } - - do { - data = (struct duration_data *)malloc(sizeof(struct duration_data)); - if (!data) { - _E("not enough memory"); - free(conf->pattern); - free(conf); - return -ENOMEM; - } - data->duration = 0; - data->wait = 0; - - check = strchr(value, 'D'); - if (check) { - *check = '\0'; - data->duration = strtol(value, NULL, 10); - if (!value) - len = len - 1; - else - len = len - strlen(value) - 1; - value = check + 1; - } - check = strchr(value, 'W'); - if (check) { - *check = '\0'; - data->wait = strtol(value, NULL, 10); - if (!value) - len = len - 1; - else - len = len - strlen(value) - 1; - value = check + 1; - } - DD_LIST_APPEND(conf->data, data); - if (data->duration == 0 && data->wait == 0) - break; - } while (value && len > 0); - - DD_LIST_APPEND(vib_conf_list, conf); - - return 0; -} - static bool is_valid(void) { int ret; @@ -897,9 +675,10 @@ static bool is_valid(void) _E("Do not support standard haptic device"); return false; } - ret = config_parse(VIBRATION_CONF_PATH, vibration_load_config, NULL); + + ret = standard_config_parse(); if (ret < 0) - _E("failed to load configuration file(%s) : %d", VIBRATION_CONF_PATH, ret); + _E("failed to load standard vibration configuration file : %d", ret); _I("Support standard haptic device"); return true; @@ -907,6 +686,7 @@ static bool is_valid(void) static const struct haptic_plugin_ops *load(void) { + standard_set_vib_function(&vibrate_monotone); return &default_plugin; } -- 2.7.4 From d43b6a35d1a11006ae7c24ecd4262bbba8e1863a Mon Sep 17 00:00:00 2001 From: taeyoung Date: Tue, 9 Aug 2016 17:10:38 +0900 Subject: [PATCH 15/16] systemd: add user and group information of the systemd service files - deviced-pre.service: User and group are system_fw since the file is used just for the deviced. - zbooting-done.service: user and group are system_share since the signal is used at several other modules. - sdb-prestart.service: user and group are root since it needs to change the information of sysfs. The service file is changed not to be installed with normal images because the file is just used for debugging purposes. Change-Id: I1abf3cdc455b6fff5108e62377370d1df7419cc8 Signed-off-by: taeyoung --- CMakeLists.txt | 4 ++++ packaging/deviced.spec | 14 ++++++++------ systemd/deviced-pre.service | 2 ++ systemd/zbooting-done.service | 2 ++ 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5eec0be..837d4c8 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -246,6 +246,9 @@ IF(${USB_MODULE} STREQUAL on) # USB (Manual setting) INSTALL(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/scripts/direct_set_debug.sh DESTINATION bin) + IF(${SDB_PRESTART} STREQUAL on) + INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/systemd/sdb-prestart.service DESTINATION lib/systemd/system) + ENDIF(${SDB_PRESTART} STREQUAL on) ENDIF() INSTALL(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/scripts/deviced-pre.sh DESTINATION bin) @@ -258,6 +261,7 @@ INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/systemd/ DESTINATION lib/systemd/s FILES_MATCHING PATTERN "*.service" PATTERN "*.socket" + PATTERN "sdb-prestart.service" EXCLUDE PATTERN "deviced-vibrator.service" EXCLUDE) ADD_SUBDIRECTORY(src/shared) diff --git a/packaging/deviced.spec b/packaging/deviced.spec index 3ccbfa5..34d2f97 100644 --- a/packaging/deviced.spec +++ b/packaging/deviced.spec @@ -182,6 +182,7 @@ Deviced library for device control (devel) -DIR_MODULE=%{ir_module} \ -DLED_MODULE=%{led_module} \ -DPOWER_MODULE=%{power_module} \ + -DSDB_PRESTART=%{sdb_prestart} \ -DTOUCHSCREEN_MODULE=%{touchscreen_module} \ -DTZIP_MODULE=%{tzip_module} \ -DUSB_MODULE=%{usb_module} \ @@ -205,9 +206,10 @@ rm -rf %{buildroot} %install_service multi-user.target.wants deviced-vibrator.service %endif -%if %{?sdb_prestart} == on +%if %{?usb_module} == on && %{?sdb_prestart} == on %install_service basic.target.wants sdb-prestart.service %endif + %if %{?usbhost_module} == on mkdir -p %{buildroot}%{_prefix}/lib/udev/rules.d install -m 644 udev/99-usbhost.rules %{buildroot}%{_prefix}/lib/udev/rules.d/99-usbhost.rules @@ -277,14 +279,14 @@ systemctl daemon-reload %if %{?usb_module} == on %config %{_sysconfdir}/deviced/usb-setting.conf %config %{_sysconfdir}/deviced/usb-operation.conf +%if %{?sdb_prestart} == on +%{_unitdir}/sdb-prestart.service +%{_unitdir}/basic.target.wants/sdb-prestart.service %endif -%if %{?usbhost_module} == on -%{_prefix}/lib/udev/rules.d/99-usbhost.rules %endif -%{_unitdir}/sdb-prestart.service -%if %{?sdb_prestart} == on -%{_unitdir}/basic.target.wants/sdb-prestart.service +%if %{?usbhost_module} == on +%{_prefix}/lib/udev/rules.d/99-usbhost.rules %endif %files tools diff --git a/systemd/deviced-pre.service b/systemd/deviced-pre.service index 5455512..2dbaabb 100644 --- a/systemd/deviced-pre.service +++ b/systemd/deviced-pre.service @@ -7,3 +7,5 @@ Before=deviced.service Type=oneshot SmackProcessLabel=System ExecStart=/usr/bin/deviced-pre.sh +User=system_fw +Group=system_fw diff --git a/systemd/zbooting-done.service b/systemd/zbooting-done.service index 2e6abe3..074cdeb 100644 --- a/systemd/zbooting-done.service +++ b/systemd/zbooting-done.service @@ -6,6 +6,8 @@ After=default.target Type=oneshot SmackProcessLabel=System ExecStart=/usr/bin/dbus-send --type=signal --system /Org/Tizen/System/DeviceD/Core org.tizen.system.deviced.core.BootingDone +User=system_share +Group=system_share [Install] WantedBy=graphical.target -- 2.7.4 From d9d69097f50489f1d4cf8417f8665e5703b76a5b Mon Sep 17 00:00:00 2001 From: taeyoung Date: Tue, 30 Aug 2016 11:05:40 +0900 Subject: [PATCH 16/16] systemd: remove deviced-pre.service - device-pre.service is not used anymore. Thus it needs to be removed Change-Id: I566ca70d8074357482a27de495c83363be1b6606 Signed-off-by: taeyoung --- CMakeLists.txt | 1 - packaging/deviced.spec | 2 -- scripts/deviced-pre.sh | 37 ------------------------------------- systemd/deviced-pre.service | 11 ----------- systemd/deviced.service | 3 --- 5 files changed, 54 deletions(-) delete mode 100755 scripts/deviced-pre.sh delete mode 100644 systemd/deviced-pre.service diff --git a/CMakeLists.txt b/CMakeLists.txt index 837d4c8..4c7b27b 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -251,7 +251,6 @@ IF(${USB_MODULE} STREQUAL on) ENDIF(${SDB_PRESTART} STREQUAL on) ENDIF() -INSTALL(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/scripts/deviced-pre.sh DESTINATION bin) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/scripts/deviced.conf DESTINATION /etc/dbus-1/system.d) CONFIGURE_FILE(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY) diff --git a/packaging/deviced.spec b/packaging/deviced.spec index 34d2f97..7b5715f 100644 --- a/packaging/deviced.spec +++ b/packaging/deviced.spec @@ -248,7 +248,6 @@ systemctl daemon-reload %manifest %{name}.manifest %license LICENSE %config %{_sysconfdir}/dbus-1/system.d/deviced.conf -%{_bindir}/deviced-pre.sh %{_bindir}/deviced %{_unitdir}/multi-user.target.wants/deviced.service %if %{?haptic_module} == on @@ -261,7 +260,6 @@ systemctl daemon-reload %{_unitdir}/graphical.target.wants/zbooting-done.service %{_unitdir}/deviced.service %{_unitdir}/deviced.socket -%{_unitdir}/deviced-pre.service %{_unitdir}/zbooting-done.service %if %{?battery_module} == on %config %{_sysconfdir}/deviced/battery.conf diff --git a/scripts/deviced-pre.sh b/scripts/deviced-pre.sh deleted file mode 100755 index 6cf9f42..0000000 --- a/scripts/deviced-pre.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/bin/sh - -PATH=/bin:/usr/bin:/sbin:/usr/sbin - -DEVICED_ENV_F=/run/deviced/deviced_env -[ -e $DEVICED_ENV_F ] && /bin/rm -f $DEVICED_ENV_F -[ -d ${DEVICED_ENV_F%/*} ] || /bin/mkdir -p ${DEVICED_ENV_F%/*} - -echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib" >> $DEVICED_ENV_F - -TOUCHSCREEN=400 -TOUCHKEY=200 - -for file in /sys/class/input/event*; do - if [ -e $file ]; then - dev_keytype=`/bin/cat ${file}/device/capabilities/key` - if [ "$dev_keytype" != 0 ]; then - var=${dev_keytype%%' '*} - if [ $var == $TOUCHSCREEN ]; then - DEV_TOUCHSCREEN=/sys/class/input/${file#/sys/class/input/}/device/enabled - echo ${var} ${file#/sys/class/input/} - fi - if [ $var == $TOUCHKEY ]; then - dev_ledtype=`/bin/cat ${file}/device/capabilities/led` - if [ "$dev_ledtype" != 0 ]; then - DEV_TOUCHKEY=/sys/class/input/${file#/sys/class/input/}/device/enabled - echo ${var} ${file#/sys/class/input/} - fi - fi - fi - fi -done - -echo "PM_TOUCHSCREEN=$DEV_TOUCHSCREEN" >> $DEVICED_ENV_F -echo "PM_TOUCHKEY=$DEV_TOUCHKEY" >> $DEVICED_ENV_F -echo "PM_SYS_DIMBRT=0" >> $DEVICED_ENV_F - diff --git a/systemd/deviced-pre.service b/systemd/deviced-pre.service deleted file mode 100644 index 2dbaabb..0000000 --- a/systemd/deviced-pre.service +++ /dev/null @@ -1,11 +0,0 @@ -[Unit] -Description=prepare device daemon -DefaultDependencies=no -Before=deviced.service - -[Service] -Type=oneshot -SmackProcessLabel=System -ExecStart=/usr/bin/deviced-pre.sh -User=system_fw -Group=system_fw diff --git a/systemd/deviced.service b/systemd/deviced.service index 3cf62e0..ec30d82 100644 --- a/systemd/deviced.service +++ b/systemd/deviced.service @@ -1,10 +1,7 @@ [Unit] Description=System device daemon -After=deviced-pre.service -Requires=deviced-pre.service [Service] -EnvironmentFile=/run/deviced/deviced_env SmackProcessLabel=System::Privileged ExecStart=/usr/bin/deviced Restart=always -- 2.7.4