From 82eee939801af8ae1b55f11ea572c03d537bd369 Mon Sep 17 00:00:00 2001 From: "sanghyeok.oh" Date: Wed, 7 Mar 2018 15:39:58 +0900 Subject: [PATCH 01/16] usb-host-test: fix signal subscription error Change-Id: I57492796405cd95d7f429ad90719af8fe6c08368 Signed-off-by: sanghyeok.oh --- src/usb-host-test/usb-host-test.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/usb-host-test/usb-host-test.c b/src/usb-host-test/usb-host-test.c index fb375b4..40a6753 100644 --- a/src/usb-host-test/usb-host-test.c +++ b/src/usb-host-test/usb-host-test.c @@ -242,7 +242,10 @@ static void service_started_handler(GDBusConnection *conn, char *unit; int ret; - g_variant_get(param, "(isss)", &id, NULL, &unit, NULL); + if (!dh_get_param_from_var(param, "(uoss)", &id, NULL, &unit, NULL)) { + _E("failed to get params grom gvariant. expected:%s, type:%s", "uoss", g_variant_get_type(param)); + return ; + } if (strcmp(unit, SYSTEMD_UNIT_NAME) == 0) { ret = enable_gadget(); @@ -280,7 +283,10 @@ static void service_stopped_handler(GDBusConnection *conn, usbg_state *s; usbg_gadget *g; - g_variant_get(param, "(isss)", &id, NULL, &unit, NULL); + if (!dh_get_param_from_var(param, "(uoss)", &id, NULL, &unit, NULL)) { + _E("failed to get params grom gvariant. expected:%s, type:%s", "uoss", g_variant_get_type(param)); + return ; + } if (strcmp(unit, SYSTEMD_SERVICE_NAME) == 0) { ret = umount(FFS_PATH); -- 2.7.4 From ab5dff777e0348d46272a478f21dc55f0c9eee70 Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Wed, 7 Mar 2018 15:21:11 +0900 Subject: [PATCH 02/16] libdeviced: Fix a bug - GetDeviceList return format string is (a(issssssisibii)) Change-Id: I3ab44b28c8f1cd1056bb36a57a35412e0d0af845 Signed-off-by: pr.jung --- src/libdeviced/mmc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libdeviced/mmc.c b/src/libdeviced/mmc.c index 858279e..1593884 100644 --- a/src/libdeviced/mmc.c +++ b/src/libdeviced/mmc.c @@ -109,7 +109,7 @@ static int get_mmc_primary_id() // if (type == STORAGE_MMC && primary && devnode) // break; //} - if (!dh_get_param_from_var(reply, "a(issssssisibii)", &iter)) { + if (!dh_get_param_from_var(reply, "(a(issssssisibii))", &iter)) { _E("Failed to get mmc storage list, wrong signature:%s", g_variant_get_type_string(reply)); return -EPERM; } -- 2.7.4 From 932451c3313518a0033aa9169ee9df54ecee56b9 Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Wed, 7 Mar 2018 22:17:14 +0900 Subject: [PATCH 03/16] Revert "Remove deviced_conf_set_mempolicy_bypid and deviced_conf_set_mempolicy." This reverts commit f0696d6bf5a3ed911b7e5790d8ab8e986178f752. Change-Id: I44caea81bf818f170f76cb733cc200d663fd623b Signed-off-by: Hyotaek Shim --- src/deviced/dd-deviced.h | 26 +++++++++++ src/libdeviced/CMakeLists.txt | 1 + src/libdeviced/deviced-conf.c | 104 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 131 insertions(+) mode change 100755 => 100644 src/deviced/dd-deviced.h mode change 100755 => 100644 src/libdeviced/CMakeLists.txt create mode 100644 src/libdeviced/deviced-conf.c diff --git a/src/deviced/dd-deviced.h b/src/deviced/dd-deviced.h old mode 100755 new mode 100644 index e9d3f98..7bb3a63 --- a/src/deviced/dd-deviced.h +++ b/src/deviced/dd-deviced.h @@ -95,6 +95,32 @@ int deviced_get_apppath(pid_t pid, char *app_path, size_t app_path_size); /* sysconf */ /** + * @fn int deviced_conf_set_mempolicy(enum mem_policy mempol) + * @brief This API is used to set the policy of the current process when the phone has low available memory. + * @param[in] mempol oom adjust value which you want to set + * @return 0 on success, -1 if failed. + * @see deviced_conf_set_mempolicy_bypid() + * @retval -1 operation error + * @retval -EBADMSG - dbus error (in case of any error on the bus) + * @retval -EINVAL no mandatory parameters + * @retval -ESRCH incorrect sender process id + */ +int deviced_conf_set_mempolicy(enum mem_policy mempol); + +/** + * @fn int deviced_conf_set_mempolicy_bypid(pid_t pid, enum mem_policy mempol) + * @brief This API is used to set the policy of the given process when the phone has low available memory. + * @param[in] pid process id which you want to set + * @param[in] mempol oom adjust value which you want to set + * @return 0 on success, -1 if failed. + * @retval -1 operation error + * @retval -EBADMSG - dbus error (in case of any error on the bus) + * @retval -EINVAL no mandatory parameters + * @retval -ESRCH incorrect sender process id + */ +int deviced_conf_set_mempolicy_bypid(pid_t pid, enum mem_policy mempol); + +/** * @fn int deviced_set_timezone(char *tzpath_str) * @brief This API sets system timezone. * @param[in] tzpath_str path to timezone definition file diff --git a/src/libdeviced/CMakeLists.txt b/src/libdeviced/CMakeLists.txt old mode 100755 new mode 100644 index 55a60c5..8bc9e5c --- a/src/libdeviced/CMakeLists.txt +++ b/src/libdeviced/CMakeLists.txt @@ -9,6 +9,7 @@ SET(LIBDEVICED_SRCS mmc.c storage.c usbhost.c + deviced-conf.c deviced-noti.c deviced-util.c ) diff --git a/src/libdeviced/deviced-conf.c b/src/libdeviced/deviced-conf.c new file mode 100644 index 0000000..d6e8bc5 --- /dev/null +++ b/src/libdeviced/deviced-conf.c @@ -0,0 +1,104 @@ +/* + * 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 +#include +#include +#include + +#include "log.h" +#include "deviced-priv.h" +#include "dd-deviced.h" +#include "dbus.h" +#include "score-defines.h" + +#define PERMANENT_DIR "/tmp/permanent" +#define VIP_DIR "/tmp/vip" + +#define OOMADJ_SET "oomadj_set" +#define PROCESS_GROUP_SET "process_group_set" +#define PROCESS_VIP "process_vip" +#define PROCESS_PERMANENT "process_permanent" + +enum mp_entry_type { + MP_VIP, + MP_PERMANENT, + MP_NONE +}; + +int util_oomadj_set(int pid, int oomadj_val) +{ + GVariant *msg; + char buf1[SYSTEM_NOTI_MAXARG]; + char buf2[SYSTEM_NOTI_MAXARG]; + int val; + + snprintf(buf1, sizeof(buf1), "%d", pid); + snprintf(buf2, sizeof(buf2), "%d", oomadj_val); + + msg = dbus_handle_method_sync_with_reply_var(DEVICED_BUS_NAME, + DEVICED_PATH_PROCESS, + DEVICED_INTERFACE_PROCESS, + OOMADJ_SET, + g_variant_new("(siss)", OOMADJ_SET, 2, buf1, buf2)); + if (!msg) + return -EBADMSG; + + if (!dh_get_param_from_var(msg, "(i)", &val)) { + _E("fail (signature:%s): no message", g_variant_get_type_string(msg)); + val = -EBADMSG; + goto out; + } + + _D("%s-%s : %d", DEVICED_INTERFACE_PROCESS, OOMADJ_SET, val); + +out: + g_variant_unref(msg); + return val; +} + +API int deviced_conf_set_mempolicy_bypid(int pid, enum mem_policy mempol) +{ + if (pid < 1) + return -1; + + int oomadj_val = 0; + + switch (mempol) { + case OOM_LIKELY: + oomadj_val = OOMADJ_BACKGRD_UNLOCKED; + break; + case OOM_IGNORE: + oomadj_val = OOMADJ_SU; + break; + default: + return -1; + } + + return util_oomadj_set(pid, oomadj_val); +} + +API int deviced_conf_set_mempolicy(enum mem_policy mempol) +{ + return deviced_conf_set_mempolicy_bypid(getpid(), mempol); +} -- 2.7.4 From f1344fc12ecc8e9412c0c3d6718c00dbf860b161 Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Thu, 8 Mar 2018 11:42:57 +0900 Subject: [PATCH 04/16] Revert "Revert "Remove deviced_conf_set_mempolicy_bypid and deviced_conf_set_mempolicy."" This reverts commit 932451c3313518a0033aa9169ee9df54ecee56b9. Change-Id: Ibc79de3bccdf864037914486d0f11f59f5693a19 Signed-off-by: Hyotaek Shim --- src/deviced/dd-deviced.h | 26 ----------- src/libdeviced/CMakeLists.txt | 1 - src/libdeviced/deviced-conf.c | 104 ------------------------------------------ 3 files changed, 131 deletions(-) mode change 100644 => 100755 src/deviced/dd-deviced.h mode change 100644 => 100755 src/libdeviced/CMakeLists.txt delete mode 100644 src/libdeviced/deviced-conf.c diff --git a/src/deviced/dd-deviced.h b/src/deviced/dd-deviced.h old mode 100644 new mode 100755 index 7bb3a63..e9d3f98 --- a/src/deviced/dd-deviced.h +++ b/src/deviced/dd-deviced.h @@ -95,32 +95,6 @@ int deviced_get_apppath(pid_t pid, char *app_path, size_t app_path_size); /* sysconf */ /** - * @fn int deviced_conf_set_mempolicy(enum mem_policy mempol) - * @brief This API is used to set the policy of the current process when the phone has low available memory. - * @param[in] mempol oom adjust value which you want to set - * @return 0 on success, -1 if failed. - * @see deviced_conf_set_mempolicy_bypid() - * @retval -1 operation error - * @retval -EBADMSG - dbus error (in case of any error on the bus) - * @retval -EINVAL no mandatory parameters - * @retval -ESRCH incorrect sender process id - */ -int deviced_conf_set_mempolicy(enum mem_policy mempol); - -/** - * @fn int deviced_conf_set_mempolicy_bypid(pid_t pid, enum mem_policy mempol) - * @brief This API is used to set the policy of the given process when the phone has low available memory. - * @param[in] pid process id which you want to set - * @param[in] mempol oom adjust value which you want to set - * @return 0 on success, -1 if failed. - * @retval -1 operation error - * @retval -EBADMSG - dbus error (in case of any error on the bus) - * @retval -EINVAL no mandatory parameters - * @retval -ESRCH incorrect sender process id - */ -int deviced_conf_set_mempolicy_bypid(pid_t pid, enum mem_policy mempol); - -/** * @fn int deviced_set_timezone(char *tzpath_str) * @brief This API sets system timezone. * @param[in] tzpath_str path to timezone definition file diff --git a/src/libdeviced/CMakeLists.txt b/src/libdeviced/CMakeLists.txt old mode 100644 new mode 100755 index 8bc9e5c..55a60c5 --- a/src/libdeviced/CMakeLists.txt +++ b/src/libdeviced/CMakeLists.txt @@ -9,7 +9,6 @@ SET(LIBDEVICED_SRCS mmc.c storage.c usbhost.c - deviced-conf.c deviced-noti.c deviced-util.c ) diff --git a/src/libdeviced/deviced-conf.c b/src/libdeviced/deviced-conf.c deleted file mode 100644 index d6e8bc5..0000000 --- a/src/libdeviced/deviced-conf.c +++ /dev/null @@ -1,104 +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 -#include -#include -#include - -#include "log.h" -#include "deviced-priv.h" -#include "dd-deviced.h" -#include "dbus.h" -#include "score-defines.h" - -#define PERMANENT_DIR "/tmp/permanent" -#define VIP_DIR "/tmp/vip" - -#define OOMADJ_SET "oomadj_set" -#define PROCESS_GROUP_SET "process_group_set" -#define PROCESS_VIP "process_vip" -#define PROCESS_PERMANENT "process_permanent" - -enum mp_entry_type { - MP_VIP, - MP_PERMANENT, - MP_NONE -}; - -int util_oomadj_set(int pid, int oomadj_val) -{ - GVariant *msg; - char buf1[SYSTEM_NOTI_MAXARG]; - char buf2[SYSTEM_NOTI_MAXARG]; - int val; - - snprintf(buf1, sizeof(buf1), "%d", pid); - snprintf(buf2, sizeof(buf2), "%d", oomadj_val); - - msg = dbus_handle_method_sync_with_reply_var(DEVICED_BUS_NAME, - DEVICED_PATH_PROCESS, - DEVICED_INTERFACE_PROCESS, - OOMADJ_SET, - g_variant_new("(siss)", OOMADJ_SET, 2, buf1, buf2)); - if (!msg) - return -EBADMSG; - - if (!dh_get_param_from_var(msg, "(i)", &val)) { - _E("fail (signature:%s): no message", g_variant_get_type_string(msg)); - val = -EBADMSG; - goto out; - } - - _D("%s-%s : %d", DEVICED_INTERFACE_PROCESS, OOMADJ_SET, val); - -out: - g_variant_unref(msg); - return val; -} - -API int deviced_conf_set_mempolicy_bypid(int pid, enum mem_policy mempol) -{ - if (pid < 1) - return -1; - - int oomadj_val = 0; - - switch (mempol) { - case OOM_LIKELY: - oomadj_val = OOMADJ_BACKGRD_UNLOCKED; - break; - case OOM_IGNORE: - oomadj_val = OOMADJ_SU; - break; - default: - return -1; - } - - return util_oomadj_set(pid, oomadj_val); -} - -API int deviced_conf_set_mempolicy(enum mem_policy mempol) -{ - return deviced_conf_set_mempolicy_bypid(getpid(), mempol); -} -- 2.7.4 From 84d761d16014bf1f8381e1e646ba1daf6fad49d1 Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Thu, 8 Mar 2018 11:33:57 +0900 Subject: [PATCH 05/16] libdeviced-storage: Remove unsused logics and deprecated storage internal apis Change-Id: I20f5ec0d70f9426fa4764fa952bd905aaf9dc15d Signed-off-by: pr.jung --- CMakeLists.txt | 1 - packaging/deviced.spec | 1 - src/deviced/dd-storage.h | 77 ------------------------------- src/libdeviced/CMakeLists.txt | 2 - src/libdeviced/mmc.c | 1 - src/libdeviced/storage.c | 104 ------------------------------------------ 6 files changed, 186 deletions(-) delete mode 100644 src/deviced/dd-storage.h delete mode 100644 src/libdeviced/storage.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 007070e..6e2cc32 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -178,7 +178,6 @@ SET(PKG_MODULES capi-system-info argos_watchdog libsystemd - storage ) IF(DISPLAY_MODULE STREQUAL on) diff --git a/packaging/deviced.spec b/packaging/deviced.spec index 498d7df..05e0038 100644 --- a/packaging/deviced.spec +++ b/packaging/deviced.spec @@ -37,7 +37,6 @@ BuildRequires: pkgconfig(minizip) BuildRequires: pkgconfig(libkmod) BuildRequires: pkgconfig(libusbgx) BuildRequires: pkgconfig(tapi) -BuildRequires: pkgconfig(storage) Requires: %{name}-tools = %{version}-%{release} %{?systemd_requires} diff --git a/src/deviced/dd-storage.h b/src/deviced/dd-storage.h deleted file mode 100644 index 9181e91..0000000 --- a/src/deviced/dd-storage.h +++ /dev/null @@ -1,77 +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_STORAGE_H__ -#define __DD_STORAGE_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @file dd-storage.h - * @defgroup CAPI_SYSTEM_DEVICED_STORAGE_MODULE Storage - * @ingroup CAPI_SYSTEM_DEVICED - * @brief This file provides the API for control of storage - * @section CAPI_SYSTEM_DEVICED_STORAGE_MODULE_HEADER Required Header - * \#include - */ - -/** - * @addtogroup CAPI_SYSTEM_DEVICED_STORAGE_MODULE - * @{ - */ - -/** - * @par Description - * Storage path type - */ -enum storage_path_type { - STORAGE_DEFAULT = 0, - STORAGE_INTERNAL, - STORAGE_EXTERNAL, - STORAGE_MAX, -}; - -/** - * @par Description: - * This API is used go get storage path.\n - * @param[in] type storage path type - * @param[in] path pointer to a buffer where the path is stored - * @param[in] size size of buffer - * @return 0 on success, -1 if failed - * @see storage_path_type - * @par Example - * @code - * ... - * if ( storage_get_path(STORAGE_INTERNAL, path, 50) < 0 ) - * printf("Get storage path failed\n"); - * ... - * @endcode - */ -int storage_get_path(int type, char *path, int size); - -/** - * @} // end of CAPI_SYSTEM_DEVICED_STORAGE_MODULE - */ - -#ifdef __cplusplus -} -#endif -#endif diff --git a/src/libdeviced/CMakeLists.txt b/src/libdeviced/CMakeLists.txt index 55a60c5..aaa73e3 100755 --- a/src/libdeviced/CMakeLists.txt +++ b/src/libdeviced/CMakeLists.txt @@ -7,7 +7,6 @@ SET(LIBDEVICED_SRCS haptic.c led.c mmc.c - storage.c usbhost.c deviced-noti.c deviced-util.c @@ -19,7 +18,6 @@ INCLUDE(FindPkgConfig) pkg_check_modules(libpkgs REQUIRED vconf dlog - storage glib-2.0 gio-2.0 gio-unix-2.0) diff --git a/src/libdeviced/mmc.c b/src/libdeviced/mmc.c index 1593884..52cecbb 100644 --- a/src/libdeviced/mmc.c +++ b/src/libdeviced/mmc.c @@ -21,7 +21,6 @@ #include #include #include -#include #include #include "log.h" diff --git a/src/libdeviced/storage.c b/src/libdeviced/storage.c deleted file mode 100644 index 23fbe8d..0000000 --- a/src/libdeviced/storage.c +++ /dev/null @@ -1,104 +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 -#include - -#include "log.h" -#include "common.h" -#include "dd-deviced.h" -#include "dd-storage.h" - -struct storage_info { - storage_type_e type; - char *path; - size_t len; -}; - -static bool storage_get_info(int storage_id, storage_type_e type, - storage_state_e state, const char *path, void *user_data) -{ - struct storage_info *info; - - if (storage_id < 0 || !path || !user_data) - return true; - - info = (struct storage_info *)user_data; - if (type != info->type) - return true; - - if (state != STORAGE_STATE_MOUNTED && - state != STORAGE_STATE_MOUNTED_READ_ONLY) - return true; - - snprintf(info->path, info->len, "%s", path); - return false; -} - -API int storage_get_path(int type, char *path, int size) -{ - static char int_path[256] = { 0, }; - static char ext_path[256] = { 0, }; - int ret; - struct storage_info info; - - if (!path || size <= 0) - return -1; - - switch (type) { - case STORAGE_DEFAULT: - case STORAGE_INTERNAL: - if (strlen(int_path) > 0) { - snprintf(path, size, "%s", int_path); - return 0; - } - info.path = int_path; - info.len = sizeof(int_path); - info.type = type; - break; - case STORAGE_EXTERNAL: - if (strlen(ext_path) > 0) { - snprintf(path, size, "%s", ext_path); - return 0; - } - info.path = ext_path; - info.len = sizeof(ext_path); - info.type = type; - break; - default: - _E("Invalid type (%d)", type); - return -1; - } - - ret = storage_foreach_device_supported(storage_get_info, &info); - if (ret != STORAGE_ERROR_NONE) { - _E("Failed to get storage information (%d)", ret); - return -1; - } - - if (strlen(info.path) == 0) - return -1; - - snprintf(path, size, "%s", info.path); - return 0; -} -- 2.7.4 From 060ebe900fd9eab6a563422b1b90dfde38c3f8b3 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Thu, 8 Mar 2018 16:43:11 +0900 Subject: [PATCH 06/16] Remove unused OOM functions Change-Id: Ia9eb3346109a97a89ba8dd99caa389fcb8204ed8 Signed-off-by: lokilee73 --- CMakeLists.txt | 1 - src/proc/proc-handler.c | 212 ------------------------------------------------ 2 files changed, 213 deletions(-) delete mode 100644 src/proc/proc-handler.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 6e2cc32..b1d2aa8 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -77,7 +77,6 @@ SET(SRCS src/core/sig-handler.c src/core/udev.c src/proc/cpu-info.c - src/proc/proc-handler.c src/time/time-handler.c ) diff --git a/src/proc/proc-handler.c b/src/proc/proc-handler.c deleted file mode 100644 index 64d903d..0000000 --- a/src/proc/proc-handler.c +++ /dev/null @@ -1,212 +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 -//#include -//#include -#include -#include -//#include - -#include "core/log.h" -#include "core/common.h" -#include "core/devices.h" -#include "core/device-notifier.h" -#include "shared/dbus.h" -#include "shared/score-defines.h" - -#define OOMADJ_SET "oomadj_set" -#define OOM_PMQOS_TIME 2000 /* ms */ -#define SIGNAL_PROC_STATUS "ProcStatus" - -enum proc_status_type { - PROC_STATUS_LAUNCH, - PROC_STATUS_RESUME, - PROC_STATUS_TERMINATE, - PROC_STATUS_FOREGROUND, - PROC_STATUS_BACKGROUND, -}; - -static void memcg_move_group(int pid, int oom_score_adj) -{ - char buf[100]; - FILE *f; - int size; - char exe_name[PATH_MAX]; - - if (get_cmdline_name(pid, exe_name, PATH_MAX) != 0) { - _E("fail to get process name(%d)", pid); - return; - } - - _SD("memcg_move_group : %s, pid = %d", exe_name, pid); - if (oom_score_adj >= OOMADJ_BACKGRD_LOCKED) - snprintf(buf, sizeof(buf), "/sys/fs/cgroup/memory/background/cgroup.procs"); - else if (oom_score_adj >= OOMADJ_FOREGRD_LOCKED && oom_score_adj < OOMADJ_BACKGRD_LOCKED) - snprintf(buf, sizeof(buf), "/sys/fs/cgroup/memory/foreground/cgroup.procs"); - else - return; - - f = fopen(buf, "w"); - if (f == NULL) - return; - size = snprintf(buf, sizeof(buf), "%d", pid); - if (fwrite(buf, size, 1, f) != 1) - _E("fwrite cgroup tasks : %d", pid); - fclose(f); -} - -int set_oom_score_adj_action(int argc, char **argv) -{ - FILE *fp; - int pid = -1; - int new_oom_score_adj = 0; - - if (argc < 2) - return -1; - pid = atoi(argv[0]); - new_oom_score_adj = atoi(argv[1]); - if (pid < 0 || new_oom_score_adj <= -20) - return -1; - - _I("OOMADJ_SET : pid %d, new_oom_score_adj %d", pid, new_oom_score_adj); - - fp = open_proc_oom_score_adj_file(pid, "w"); - if (fp == NULL) - return -1; - if (new_oom_score_adj < OOMADJ_SU) - new_oom_score_adj = OOMADJ_SU; - fprintf(fp, "%d", new_oom_score_adj); - fclose(fp); - - memcg_move_group(pid, new_oom_score_adj); - return 0; -} - -GVariant *dbus_oom_handler(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) -{ - pid_t pid; - int ret; - int argc; - char *type_str; - char *argv[2]; - - g_variant_get(param, "(siss)", &type_str, &argc, &argv[0], &argv[1]); - - if (argc < 0) { - _E("message is invalid!"); - ret = -EINVAL; - goto out; - } - - pid = dbus_connection_get_sender_pid(conn, sender); - if (kill(pid, 0) == -1) { - _E("%d process does not exist, dbus ignored!", pid); - ret = -ESRCH; - goto out; - } - - if (strncmp(type_str, OOMADJ_SET, strlen(OOMADJ_SET)) == 0) - ret = set_oom_score_adj_action(argc, (char **)&argv); - else - ret = -EINVAL; - -out: - g_free(type_str); - g_free(argv[0]); - g_free(argv[1]); - return g_variant_new("(i)", ret); -} - -static void proc_signal_handler(GDBusConnection *conn, - const gchar *sender, - const gchar *path, - const gchar *iface, - const gchar *name, - GVariant *param, - gpointer data) -{ - int type; - pid_t pid; - - g_variant_get(param, "(ii)", &type, &pid); - - if (type == PROC_STATUS_BACKGROUND) - device_notify(DEVICE_NOTIFIER_PROCESS_BACKGROUND, &pid); - if (type == PROC_STATUS_FOREGROUND) - device_notify(DEVICE_NOTIFIER_PROCESS_FOREGROUND, &pid); -} - -static const dbus_method_s dbus_methods[] = { - { OOMADJ_SET, "siss", "i", dbus_oom_handler }, - /* Add methods here */ -}; - -static const dbus_interface_u dbus_interface = { - .oh = NULL, - .name = DEVICED_INTERFACE_PROCESS, - .methods = dbus_methods, - .nr_methods = ARRAY_SIZE(dbus_methods), -}; - - -static void proc_change_lowmemory(keynode_t *key, void *data) -{ - int state = 0; - - if (vconf_get_int(VCONFKEY_SYSMAN_LOW_MEMORY, &state)) - return; - - if (state == VCONFKEY_SYSMAN_LOW_MEMORY_HARD_WARNING) - device_notify(DEVICE_NOTIFIER_PMQOS_OOM, (void *)OOM_PMQOS_TIME); -} - -static void process_init(void *data) -{ - int ret; - - ret = subscribe_dbus_signal(NULL, - RESOURCED_PATH_PROCESS, - RESOURCED_INTERFACE_PROCESS, - SIGNAL_PROC_STATUS, - proc_signal_handler, - NULL, NULL); - if (ret <= 0) - _E("fail to init dbus method(%d)", ret); - - ret = dbus_handle_add_dbus_object(NULL, DEVICED_PATH_PROCESS, &dbus_interface); - if (ret < 0) - _E("fail to init dbus method(%d)", ret); - - vconf_notify_key_changed(VCONFKEY_SYSMAN_LOW_MEMORY, - proc_change_lowmemory, NULL); -} - -static const struct device_ops process_device_ops = { - .name = "process", - .init = process_init, -}; - -DEVICE_OPS_REGISTER(&process_device_ops) -- 2.7.4 From 7def3edc4807e5913fdc4f6a70530eff27aeb66a Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Mon, 12 Mar 2018 16:13:14 +0900 Subject: [PATCH 07/16] Remove telephony dependency Change-Id: I2a5dcb56c82e8c4b10196e2624057a8e94d2735c Signed-off-by: lokilee73 Signed-off-by: Hyotaek Shim Signed-off-by: lokilee73 Signed-off-by: Hyotaek Shim --- CMakeLists.txt | 8 -- packaging/deviced.spec | 2 - src/power/power-handler.c | 335 ++++++++++++++++++++++++++++++++-------------- src/power/power-handler.h | 10 +- src/telephony/telephony.c | 132 ------------------ 5 files changed, 244 insertions(+), 243 deletions(-) mode change 100644 => 100755 packaging/deviced.spec mode change 100644 => 100755 src/power/power-handler.c mode change 100644 => 100755 src/power/power-handler.h delete mode 100644 src/telephony/telephony.c diff --git a/CMakeLists.txt b/CMakeLists.txt index b1d2aa8..50475c8 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -152,11 +152,6 @@ IF(TIZEN_FEATURE_USBHOST_TEST STREQUAL on) DESTINATION /etc/deviced/usb-host-test/) ENDIF() -IF(TIZEN_FEATURE_TELEPHONY_MODULE STREQUAL on) - ADD_SOURCE(src/telephony TELEPHONY_SRCS) - SET(SRCS ${SRCS} ${TELEPHONY_SRCS}) -ENDIF() - INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src/deviced) @@ -188,9 +183,6 @@ ENDIF() IF(TIZEN_FEATURE_USBHOST_TEST STREQUAL on) SET(PKG_MODULES ${PKG_MODULES} libkmod libusbgx) ENDIF() -IF(TIZEN_FEATURE_TELEPHONY_MODULE STREQUAL on) - SET(PKG_MODULES ${PKG_MODULES} tapi) -ENDIF() INCLUDE(FindPkgConfig) pkg_check_modules(pkgs REQUIRED ${PKG_MODULES}) diff --git a/packaging/deviced.spec b/packaging/deviced.spec old mode 100644 new mode 100755 index 05e0038..7e0f6be --- a/packaging/deviced.spec +++ b/packaging/deviced.spec @@ -36,7 +36,6 @@ BuildRequires: pkgconfig(fuse) BuildRequires: pkgconfig(minizip) BuildRequires: pkgconfig(libkmod) BuildRequires: pkgconfig(libusbgx) -BuildRequires: pkgconfig(tapi) Requires: %{name}-tools = %{version}-%{release} %{?systemd_requires} @@ -147,7 +146,6 @@ Plugin libraries for TV profile -DUSBHOST_MODULE=on \ -DTHERMAL_MODULE=on \ -DTIZEN_FEATURE_CPU_MODULE=on \ - -DTIZEN_FEATURE_TELEPHONY_MODULE=on \ -DTIZEN_FEATURE_USBHOST_TEST=on \ -DTIZEN_FEATURE_BATTERY_OVER_TEMPERATURE=on \ #eol diff --git a/src/power/power-handler.c b/src/power/power-handler.c old mode 100644 new mode 100755 index 826e077..02b350a --- a/src/power/power-handler.c +++ b/src/power/power-handler.c @@ -58,6 +58,7 @@ #define POWEROFF_DURATION 2 #define MAX_RETRY 2 #define POWEROFF_WAIT_RESOURCED (0.5*1000) /* 0.5 seconds */ +#define POWEROFF_WAIT_MAX 10 /* 10 seconds */ #define SIGNAL_POWEROFF_STATE "ChangeState" @@ -79,6 +80,9 @@ struct power_flag { static struct timeval tv_start_poweroff; static dd_list *poweroff_options; +static struct power_option poweroff_opt; +static bool during_poweroff; +static dd_list *poweroff_handles; static int get_poweroff_type_enum(char *type, enum poweroff_type *val) { @@ -108,14 +112,14 @@ static int get_poweroff_type_enum(char *type, enum poweroff_type *val) return -EINVAL; } -static int find_poweroff_option(char *type, char *option, struct power_option **opt) +static int find_poweroff_option(char *type, char *option) { int ret; dd_list *l; struct power_option *elem; enum poweroff_type type_e; - if (!type || !opt) + if (!type) return -EINVAL; ret = get_poweroff_type_enum(type, &type_e); @@ -136,51 +140,23 @@ static int find_poweroff_option(char *type, char *option, struct power_option ** if (elem->option != NULL) continue; } - if (elem->option) { - free(elem->option); - elem->option = (option ? strdup(option) : NULL); + poweroff_opt.type = elem->type; + if (poweroff_opt.name) { + free(poweroff_opt.name); + poweroff_opt.name = NULL; + } + poweroff_opt.name = (elem->name ? strdup(elem->name) : NULL); + if (poweroff_opt.option) { + free(poweroff_opt.option); + poweroff_opt.option = NULL; } - *opt = elem; + poweroff_opt.option = (option ? strdup(option) : NULL); return 0; } return -ENOENT; } -static int telephony_off(struct power_option *opt) -{ - const struct device_ops *tele; - - tele = find_device("telephony"); - if (check_default(tele)) - return -ENODEV; - - return device_execute(tele, opt); -} - -static int app_privileged(pid_t pid) -{ - char attr[64]; - int ret; - size_t len; - - ret = get_privilege(pid, attr, sizeof(attr)); - if (ret < 0) { - _E("Failed to get privilege of PID(%d)", pid); - return 0; - } - - len = strlen(attr); - - if (!strncmp("System::Privileged", attr, len + 1)) - return 1; - - if (strstr(attr, "User::Pkg::") == attr) - return 1; - - return 0; -} - static int stop_systemd_journald(void) { int ret; @@ -196,7 +172,9 @@ static int stop_systemd_journald(void) _E("failed to stop 'systemd-journald.service'"); return ret; } - + _I("done %s with %s option", + poweroff_opt.name ? poweroff_opt.name : "NULL", + poweroff_opt.option ? poweroff_opt.option : "NULL"); return 0; } @@ -280,28 +258,24 @@ static void restart(char *option) } } -void powerdown_ap(struct power_option *opt) +void powerdown_ap(void) { - static int off; - - if (off) - return; - off = 1; - - _I("POWER DOWN: %s option(%s)", opt->name, opt->option); + _I("%s option(%s)", + poweroff_opt.name ? poweroff_opt.name : "NULL", + poweroff_opt.option ? poweroff_opt.option : "NULL"); powerdown(); - if (opt->type == POWER_OFF_DIRECT) { + if (poweroff_opt.type == POWER_OFF_DIRECT) { poweroff(); return; } - if (opt->type == POWER_OFF_RESTART) { - restart(opt->option); + if (poweroff_opt.type == POWER_OFF_RESTART) { + restart(poweroff_opt.option); return ; } - _E("Invalid type (%d)", opt->name); + _E("poweroff invalid type (%d)", poweroff_opt.type); } static void system_shutdown_send_system_event(void) @@ -341,23 +315,12 @@ static void disable_display(void) display_device_ops->exit(NULL); } -static int poweroff_procedure(struct power_option *opt) +static int poweroff_procedure(void) { - int ret; - - if (!opt) - return -EINVAL; - disable_display(); - sync(); - watchdog_notify(); - ret = telephony_off(opt); - if (ret < 0) { - powerdown_ap(opt); - return 0; - } - return ret; + powerdown_ap(); + return 0; } static int booting_done(void *data) @@ -478,74 +441,160 @@ static void poweroff_fixed_flow(enum poweroff_type type) device_notify(DEVICE_NOTIFIER_POWEROFF, &off); } -static void poweroff_idler_cb(void *data) +static void poweroff_remove_handle(pid_t pid) +{ + struct poweroff_handle *handle; + dd_list *elem; + + DD_LIST_FOREACH(poweroff_handles, elem, handle) { + if (handle->pid == pid) + break; + } + + assert(handle); + + _D("Remove handle pid(%d) timeout(%d) timeout_id(%d)", handle->pid, handle->timeout, handle->timeout_id); + DD_LIST_REMOVE(poweroff_handles, handle); + + if (handle->timeout_id) { + g_source_remove(handle->timeout_id); + handle->timeout = 0; + handle->timeout_id = 0; + } + + free(handle); +} + +static gboolean poweroff_timeout_cb(void *data) { - struct power_option *opt = data; int ret; + pid_t pid; - if (!opt) { - _E("power off option is NULL"); - return; + pid = (pid_t)((intptr_t)data); + poweroff_remove_handle(pid); + + if (DD_LIST_LENGTH(poweroff_handles)) { + _D("Timer is left"); + return G_SOURCE_REMOVE; + } + _D("No timer left"); + + if (!poweroff_opt.name) { + _E("There is no option"); + goto out; } watchdog_notify(); - if (opt->type == POWER_OFF_POPUP) { - vconf_set_int(VCONFKEY_SYSMAN_POWER_OFF_STATUS, opt->type); - pwroff_popup(); + if (poweroff_opt.type != POWER_OFF_DIRECT && + poweroff_opt.type != POWER_OFF_RESTART) { + _E("Invalid type (%d)", poweroff_opt.type); goto out; } - if (opt->type != POWER_OFF_DIRECT && - opt->type != POWER_OFF_RESTART) { - _E("Invalid type (%d)", opt->type); - return; - } + during_poweroff = true; - make_power_flag(opt->type, opt->option); + make_power_flag(poweroff_opt.type, poweroff_opt.option); pm_lock_internal(INTERNAL_LOCK_POWEROFF, LCD_OFF, STAY_CUR_STATE, 0); - poweroff_fixed_flow(opt->type); + poweroff_fixed_flow(poweroff_opt.type); /* TODO for notify. will be removed asap. */ - vconf_set_int(VCONFKEY_SYSMAN_POWER_OFF_STATUS, opt->type); + vconf_set_int(VCONFKEY_SYSMAN_POWER_OFF_STATUS, poweroff_opt.type); - ret = poweroff_procedure(opt); + ret = poweroff_procedure(); if (ret < 0) - _E("Failed to %s (%d)", opt->name, ret); + _E("Failed to %s (%d)", poweroff_opt.name, ret); out: if (update_pm_setting) - update_pm_setting(SETTING_POWEROFF, opt->type); + update_pm_setting(SETTING_POWEROFF, poweroff_opt.type); + during_poweroff = false; + return G_SOURCE_REMOVE; +} + +void poweroff_start_timers() +{ + struct poweroff_handle *handle = NULL; + dd_list *l; + bool timer_exist = false; + int pid_alive = 0; + + DD_LIST_FOREACH(poweroff_handles, l, handle) { + pid_alive = kill(handle->pid, 0); + if (pid_alive == -1) { + _D("Pid(%d) is dead", handle->pid); + handle->timeout = 0; + } + + _D("Run timer, pid(%d) timeout(%d) timeout_id(%d)", handle->pid, handle->timeout, handle->timeout_id); + handle->timeout_id = g_timeout_add_seconds(handle->timeout, + poweroff_timeout_cb, + (void *)((intptr_t)(handle->pid))); + + timer_exist = true; + } + + if (timer_exist) { + return; + } else { + _D("handle is NULL"); + handle = (struct poweroff_handle *)malloc(sizeof(struct poweroff_handle)); + if (handle == NULL) { + _E("Not enough memory."); + return; + } + + handle->pid = getpid(); + handle->timeout = 0; + handle->timeout_id = g_timeout_add_seconds(handle->timeout, + poweroff_timeout_cb, + (void *)((intptr_t)(handle->pid))); + + if (!handle->timeout_id) { + _E("timer_add failed"); + free(handle); + return; + } + + DD_LIST_APPEND(poweroff_handles, handle); + } + + _D("Last Timer : timer_id(%d) pid(%d) timeout(%d)", handle->timeout_id, handle->pid, handle->timeout); + return; } static int power_execute_pid(char *type, char *option, pid_t pid) { int ret; - struct power_option *opt; + + if (during_poweroff) { + _E("during poweroff"); + return -EINVAL; + } if (!type) return -EINVAL; - ret = find_poweroff_option(type, option, &opt); + ret = find_poweroff_option(type, option); if (ret < 0) { _E("Failed to find supported %s option %s (%d)", type, (option ? option : "NULL"), ret); return ret; } - if (opt->type == POWER_OFF_RESTART) { - if (!app_privileged(pid)) { - _E("PID(%d) does not have the permission for reboot", pid); - return -EPERM; + if (strncmp(PWROFF_POPUP, poweroff_opt.name, PWROFF_POPUP_LEN) == 0) { + _D("request popup"); + if (poweroff_opt.type == POWER_OFF_POPUP) { + vconf_set_int(VCONFKEY_SYSMAN_POWER_OFF_STATUS, poweroff_opt.type); + pwroff_popup(); } + return 0; } - ret = add_idle_request(poweroff_idler_cb, opt); - if (ret < 0) { - _E("fail to add poweroff idle request : %d", ret); - return ret; - } + poweroff_opt.pid = pid; + poweroff_send_broadcast(poweroff_opt.type); + poweroff_start_timers(); return 0; } @@ -632,11 +681,101 @@ GVariant *request_reboot(GDBusConnection *conn, return g_variant_new("(i)", ret); } +static GVariant *add_poweroff_time(GDBusConnection *conn, + const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, + GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) +{ + struct poweroff_handle *handle; + int ret; + pid_t pid; + dd_list *l; + + pid = dbus_connection_get_sender_pid(conn, sender); + _D("add_poweroff_timer(%d)", pid); + if (pid == -1) { + _E("Failed to get sender's pid."); + ret = -1; + goto add_out; + } + + DD_LIST_FOREACH(poweroff_handles, l, handle) { + if (handle->pid == pid) + break; + } + + if (handle) + poweroff_remove_handle(pid); + + _D("Make a new handle"); + handle = (struct poweroff_handle *)malloc(sizeof(struct poweroff_handle)); + if (handle == NULL) { + _E("Not enough memory."); + ret = -1; + goto add_out; + } + + handle->pid = pid; + handle->timeout_id = 0; + handle->timeout = POWEROFF_WAIT_MAX; + + DD_LIST_APPEND(poweroff_handles, handle); + _D("Add a new poweroff timer(%d %d %d)", handle->pid, handle->timeout, handle->timeout_id); + + ret = 0; + +add_out: + return g_variant_new("(i)", ret); +} + +static GVariant *remove_poweroff_time(GDBusConnection *conn, + const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, + GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data) +{ + struct poweroff_handle *handle; + dd_list *l; + int ret = 0; + pid_t pid; + + pid = dbus_connection_get_sender_pid(conn, sender); + _D("remove_poweroff_timer(%d)", pid); + if (pid == -1) { + _E("Failed to get sender's pid."); + ret = -1; + goto remove_out; + } + + DD_LIST_FOREACH(poweroff_handles, l, handle) { + if (handle->pid == pid) { + break; + } + } + + if (handle) { + assert(handle); + + if (handle && handle->timeout_id) { + g_source_remove(handle->timeout_id); + handle->timeout = 0; + handle->timeout_id = g_timeout_add_seconds(handle->timeout, + poweroff_timeout_cb, + (void *)((intptr_t)(handle->pid))); + } + } else { + _E("Invalid pid(%d)", pid); + ret = -1; + } + +remove_out: + return g_variant_new("(i)", ret); +} + static const dbus_method_s dbus_methods[] = { { POWER_REBOOT, "si", "i", dbus_power_handler }, { "RebootWithOption", "ss", "i", dbus_power_option_handler }, /* Public API device_power_reboot() calls this dbus method. */ { "Reboot", "s", "i", request_reboot }, + { "AddPoweroffWait", NULL, "i", add_poweroff_time }, + { "RemovePoweroffWait", NULL, "i", remove_poweroff_time }, /* Add methods here */ }; @@ -650,7 +789,6 @@ static const dbus_interface_u dbus_interface = { static int add_poweroff_option(enum poweroff_type type, char *option) { struct power_option *opt; - static int index = 0; char *name; if (type == POWER_OFF_POPUP) @@ -673,7 +811,6 @@ static int add_poweroff_option(enum poweroff_type type, char *option) opt->type = type; opt->name = strdup(name); opt->option = (option ? strdup(option) : NULL); - opt->index = index++; DD_LIST_APPEND(poweroff_options, opt); diff --git a/src/power/power-handler.h b/src/power/power-handler.h old mode 100644 new mode 100755 index e9f32c4..2f11f1f --- a/src/power/power-handler.h +++ b/src/power/power-handler.h @@ -36,13 +36,19 @@ enum poweroff_type { }; struct power_option { + pid_t pid; enum poweroff_type type; char *name; char *option; - int index; }; -void powerdown_ap(struct power_option *opt); +struct poweroff_handle { + pid_t pid; + int timeout; + guint timeout_id; +}; + +void powerdown_ap(void); int check_power_flag(void); #endif /* __POWER_HANDLE_H__ */ diff --git a/src/telephony/telephony.c b/src/telephony/telephony.c deleted file mode 100644 index 18f1855..0000000 --- a/src/telephony/telephony.c +++ /dev/null @@ -1,132 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2012 - 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 "core/log.h" -#include "core/common.h" -#include "core/devices.h" -#include "core/device-notifier.h" -#include "shared/dbus.h" -#include "power/power-handler.h" - -#define TELEPHONY_NOTI_TIMEOUT 10000 /* milliseconds */ - -static TapiHandle *tapi_handle; -static struct power_option *opt; - -static void telephony_off(void) -{ - static int already = 0; - - if (already) - return; - - already = 1; - - powerdown_ap(opt); -} - -static void telephony_noti_cb(TapiHandle *handle, const char *noti_id, void *data, void *user_data) -{ - int ret; - - _I("Modem Power Off"); - - if (handle) { - ret = tel_deregister_noti_event(handle, TAPI_NOTI_MODEM_POWER); - if (ret != TAPI_API_SUCCESS) - _E("Failed to unregister tapi noti event (%d)", ret); - - ret = tel_deinit(tapi_handle); - if (ret != TAPI_API_SUCCESS) - _E("Failed to deinit tapi handle (%d)", ret); - } - - telephony_off(); -} - -static void telephony_resp_cb(TapiHandle *handle, int result, void *data, void *user_data) -{ - _D("poweroff command request : %d", result); -} - -static gboolean telephony_request_timeout(gpointer data) -{ - _E("No response from Telephony"); - telephony_off(); - return G_SOURCE_REMOVE; -} - -static int telephony_poweroff(void *data) -{ - int ret; - guint id; - - if (!data) - return -EINVAL; - - opt = data; - - if (!tapi_handle) { - tapi_handle = tel_init(NULL); - if (!tapi_handle) { - _E("Failed to init telephony"); - return -ENOMEM; - } - } - - ret = tel_register_noti_event(tapi_handle, - TAPI_NOTI_MODEM_POWER, telephony_noti_cb, NULL); - if (ret != TAPI_API_SUCCESS) { - _E("Failed to register tapi noti event (%d)", ret); - return (ret < 0 ? ret : -ret); - } - - ret = tel_process_power_command(tapi_handle, - TAPI_PHONE_POWER_OFF, telephony_resp_cb, NULL); - if (ret != TAPI_API_SUCCESS) { - _E("Failed to notify tapi power command response(%d)", ret); - return (ret < 0 ? ret : -ret); - } - - id = g_timeout_add(TELEPHONY_NOTI_TIMEOUT, telephony_request_timeout, NULL); - if (id == 0) { - _E("Failed to add timer for force poweroff"); - return -ENOMEM; - } - - return 0; -} - -static int telephony_execute(void *data) -{ - return telephony_poweroff(data); -} - -static const struct device_ops tel_device_ops = { - .name = "telephony", - .execute = telephony_execute, -}; - -DEVICE_OPS_REGISTER(&tel_device_ops) -- 2.7.4 From 48763fe1d4173f68803e941acf8c605a66ccbfe4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Pawe=C5=82=20Szewczyk?= Date: Tue, 27 Feb 2018 17:16:29 +0100 Subject: [PATCH 08/16] usb: Remove usb-operation MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Starting and stopping usb operation is specific to the implementation. This responsibility is moved to USB HAL. Change-Id: I1c9135f40ea203ff529c3699b442e947a6cf50a9 Signed-off-by: Paweł Szewczyk --- CMakeLists.txt | 2 - conf/usb-operation.conf | 14 ------ packaging/deviced.spec | 1 - src/usb/usb-operation.c | 114 ------------------------------------------------ src/usb/usb.c | 8 ---- src/usb/usb.h | 3 -- 6 files changed, 142 deletions(-) delete mode 100644 conf/usb-operation.conf delete mode 100644 src/usb/usb-operation.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 50475c8..97448e1 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -242,8 +242,6 @@ ENDIF() # USB connection IF(USB_MODULE STREQUAL on) - INSTALL_CONF(conf usb-operation) - # USB (Manual setting) INSTALL(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/scripts/direct_set_debug.sh DESTINATION bin) IF(${SDB_PRESTART} STREQUAL on) diff --git a/conf/usb-operation.conf b/conf/usb-operation.conf deleted file mode 100644 index da6c71c..0000000 --- a/conf/usb-operation.conf +++ /dev/null @@ -1,14 +0,0 @@ -[sdb] -StartService=sdbd.service -StopService=sdbd.service - -[mtp] -StartService=mtp-responder.service -StopService=mtp-responder.service - -[rndis] -Start=/sbin/ifconfig usb0 192.168.129.3 up -Start=/sbin/route add -net 192.168.129.0 netmask 255.255.255.0 dev usb0 -StartService=sshd.service -StopService=sshd.service -Stop=/sbin/ifconfig usb0 down diff --git a/packaging/deviced.spec b/packaging/deviced.spec index 7e0f6be..ecf21d6 100755 --- a/packaging/deviced.spec +++ b/packaging/deviced.spec @@ -220,7 +220,6 @@ mv %{_libdir}/display-tv.so %{_libdir}/deviced/display.so %config %{_sysconfdir}/deviced/power.conf %config %{_sysconfdir}/deviced/battery.conf %config %{_sysconfdir}/deviced/display.conf -%config %{_sysconfdir}/deviced/usb-operation.conf # usbhost_test %{_sysconfdir}/deviced/usb-host-test/test_gadget.gs %{_bindir}/usb-host-ffs-test-daemon diff --git a/src/usb/usb-operation.c b/src/usb/usb-operation.c deleted file mode 100644 index 1bc8efc..0000000 --- a/src/usb/usb-operation.c +++ /dev/null @@ -1,114 +0,0 @@ -/* - * deviced - * - * Copyright (c) 2015 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 "core/log.h" -#include "core/common.h" -#include "core/config-parser.h" -#include "core/launch.h" -#include "shared/deviced-systemd.h" -#include "usb.h" - -#define USB_OPERATION "/etc/deviced/usb-operation.conf" - -#define KEY_START_STR "Start" -#define KEY_STOP_STR "Stop" - -#define BUF_MAX 128 - -typedef enum { - OPERATION_STOP, - OPERATION_START, -} operation_e; - -struct oper_data { - char mode_str[BUF_MAX]; - operation_e type; -}; - -static int load_operation_config(struct parse_result *result, void *user_data) -{ - struct oper_data *data = user_data; - int ret; - operation_e type; - - if (!data || !result) - return -EINVAL; - - if (!strstr(data->mode_str, result->section)) - return 0; - - if (!strncmp(result->name, KEY_START_STR, strlen(KEY_START_STR))) - type = OPERATION_START; - else if (!strncmp(result->name, KEY_STOP_STR, strlen(KEY_STOP_STR))) - type = OPERATION_STOP; - else { - _E("Invalid name (%s)", result->name); - return -EINVAL; - } - - if (type != data->type) - return 0; - - if (strstr(result->name, "Service")) { - if (type == OPERATION_START) - ret = deviced_systemd_start_unit(result->value); - if (type == OPERATION_STOP) - ret = deviced_systemd_stop_unit(result->value); - } else - ret = launch_app_cmd(result->value); - - _I("Execute(%s %s: %d)", result->name, result->value, ret); - - return 0; -} - -static int usb_execute_operation(unsigned int mode, operation_e type) -{ - int ret; - struct oper_data data; - - usb_state_get_mode_str(mode, data.mode_str, sizeof(data.mode_str)); - - data.type = type; - - ret = config_parse(USB_OPERATION, - load_operation_config, &data); - if (ret < 0) - _E("Failed to load usb operation (%d)", ret); - - return ret; -} - -int usb_operation_start(unsigned int mode) -{ - if (is_emulator()) - return 0; - return usb_execute_operation(mode, OPERATION_START); -} - -int usb_operation_stop(unsigned int mode) -{ - if (is_emulator()) - return 0; - return usb_execute_operation(mode, OPERATION_STOP); -} diff --git a/src/usb/usb.c b/src/usb/usb.c index be8a02a..4caef6b 100644 --- a/src/usb/usb.c +++ b/src/usb/usb.c @@ -290,8 +290,6 @@ int usb_change_mode(unsigned mode) unsigned int curr = usb_state_get_current_mode(); if (curr != USB_FUNCTION_NONE) { - usb_operation_stop(curr); - ret = usb_disable(); if (ret < 0) { _E("Failed to disable current usb mode"); @@ -314,8 +312,6 @@ int usb_change_mode(unsigned mode) _E("Failed to enable usb mode (%d)"); return ret; } - - usb_operation_start(mode); } return 0; @@ -334,15 +330,11 @@ static int usb_connected(void) return ret; } - usb_operation_start(mode); - return 0; } static int usb_disconnected(void) { - usb_operation_stop(usb_state_get_current_mode()); - usb_state_update_state(USB_DISCONNECTED, USB_FUNCTION_NONE); return usb_disable(); diff --git a/src/usb/usb.h b/src/usb/usb.h index ae26162..0e6165b 100644 --- a/src/usb/usb.h +++ b/src/usb/usb.h @@ -67,9 +67,6 @@ void usb_state_set_selected_mode(unsigned int mode); unsigned int usb_state_get_current_mode(void); usb_connection_state_e usb_state_get_connection(void); -int usb_operation_start(unsigned int mode); -int usb_operation_stop(unsigned int mode); - /* dbus methods/signals (usb-dbus.c) */ enum { DISABLED, -- 2.7.4 From 566638a6ec33cedef0c4f7d02c57f83f6fc549c1 Mon Sep 17 00:00:00 2001 From: INSUN PYO Date: Thu, 8 Mar 2018 14:51:59 +0900 Subject: [PATCH 09/16] usb: support configfs usb hal Signed-off-by: INSUN PYO Change-Id: Ic810941b85fa985d68117dcc979b3ce75dedc0a1 --- src/usb/usb.c | 144 +++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 86 insertions(+), 58 deletions(-) diff --git a/src/usb/usb.c b/src/usb/usb.c index 4caef6b..28c2777 100644 --- a/src/usb/usb.c +++ b/src/usb/usb.c @@ -38,81 +38,109 @@ static struct usb_client *usb_client; struct extcon_ops extcon_usb_ops; -static int usb_probe(void) +static struct usb_gadget_translator *gadget_translator_probe(void) { struct hw_info *info; struct hw_common *common; - int ret; + struct usb_gadget_translator *gadget; - /* We need both HALs up and running for operating in USB client mode */ + if (hw_get_info(USB_GADGET_DEVICE_ID, (const struct hw_info **)&info)) { + _E("No usb gadget translator"); + return NULL; + } - if (!gadget_translator) { - ret = hw_get_info(USB_GADGET_DEVICE_ID, - (const struct hw_info **)&info); - if (ret) - goto no_gadget_hal; + if (!info->open) { + _E("Failed to open usb gadget translator; open(NULL)"); + return NULL; + } - if (!info->open) { - _E("Failed to open gadget translator; open(NULL)"); - /* TODO. Shouldn't we free somehow info structure? */ - return -ENODEV; - } + if (info->open(info, NULL, &common) < 0) { + _E("Failed to open usb gadget translator"); + return NULL; + } - ret = info->open(info, NULL, &common); - if (ret < 0) { - _E("Failed to open usb gadget translator (%d)", ret); - return ret; - } + gadget = container_of(common, struct usb_gadget_translator, common); + if (!gadget->id_to_gadget || !gadget->cleanup_gadget) { + _E("Invalid usb gadget translator"); - gadget_translator = container_of(common, - struct usb_gadget_translator, - common); - if (!gadget_translator->id_to_gadget || - !gadget_translator->cleanup_gadget) { - _E("Invalid gadget translator HAL"); - goto invalid_translator_hal; - } + if (gadget->common.info) + gadget->common.info->close(&gadget->common); + + return NULL; } - if (!usb_client) { - ret = hw_get_info(USB_CLIENT_HARDWARE_DEVICE_ID, - (const struct hw_info **)&info); - if (ret) - goto no_client_hal; - - if (!info->open) { - _E("Failed to open usb client hw; open(NULL)"); - /* TODO. Shouldn't we free somehow info structure? */ - return -ENODEV; - } + return gadget; +} - ret = info->open(info, NULL, &common); - if (ret < 0) { - _E("Failed to open usb client hw (%d)", ret); - return ret; - } +static struct usb_client *usb_client_probe(const char *id) +{ + struct hw_info *info; + struct hw_common *common; + struct usb_client *client; - usb_client = container_of(common, struct usb_client, common); + _I("Loading usb client: %s", id); - if (!usb_client->reconfigure_gadget || !usb_client->enable || - !usb_client->disable) - goto invalid_config_hal; + if (hw_get_info(id, (const struct hw_info **)&info)) { + _I("No usb_client: %s", id); + return NULL; } - return 0; + if (!info->open) { + _E("Failed to open usb client open(NULL): %s", id); + return NULL; + } -invalid_config_hal: - if (usb_client->common.info->close) - usb_client->common.info->close(&usb_client->common); + if (info->open(info, NULL, &common) < 0) { + _E("Failed to open usb client: %s", id); + return NULL; + } -no_client_hal: -invalid_translator_hal: - if (gadget_translator->common.info) - gadget_translator->common.info->close(&gadget_translator->common); - gadget_translator = NULL; -no_gadget_hal: - /* TODO. Maybe some default action here? */ - return -ENOENT; + client = container_of(common, struct usb_client, common); + if (!client->reconfigure_gadget || !client->enable || !client->disable) { + _E("Invalid usb client: %s", id); + + if (client->common.info->close) + client->common.info->close(&client->common); + + return NULL; + } + + _I("Success lodging usb client: %s", id); + return client; +} + +static int usb_probe(void) +{ + /* Both the gadget and client should be valid. */ + if (gadget_translator || usb_client) { + if (gadget_translator && usb_client) + return 0; + return -EINVAL; + } + + /* gadget_translator */ + gadget_translator = gadget_translator_probe(); + if (!gadget_translator) + return -ENODEV; + + /* usb_client */ + usb_client = usb_client_probe(USB_CLIENT_HARDWARE_DEVICE_ID); + + if (!usb_client) + usb_client = usb_client_probe(USB_SLP_CLIENT_HARDWARE_DEVICE_ID); + + if (!usb_client) + usb_client = usb_client_probe(USB_CFS_CLIENT_HARDWARE_DEVICE_ID); + + if (!usb_client) { + if (gadget_translator->common.info) + gadget_translator->common.info->close(&gadget_translator->common); + gadget_translator = NULL; + + return -ENODEV; + } + + return 0; } static void usb_release() -- 2.7.4 From 1235e37c3341fed1f73053832e8af6afdb469cbb Mon Sep 17 00:00:00 2001 From: "sanghyeok.oh" Date: Wed, 7 Mar 2018 18:54:58 +0900 Subject: [PATCH 10/16] dbus: modify dbus policy correctly Change-Id: Id903a35e006f82be38b0b65fad818c9ac59d3364 Signed-off-by: sanghyeok.oh --- conf/org.tizen.system.deviced.conf | 57 +++++++++++++++++++++++++++++++------- 1 file changed, 47 insertions(+), 10 deletions(-) diff --git a/conf/org.tizen.system.deviced.conf b/conf/org.tizen.system.deviced.conf index 81086b6..fa226d9 100644 --- a/conf/org.tizen.system.deviced.conf +++ b/conf/org.tizen.system.deviced.conf @@ -1,22 +1,59 @@ + + + + + + + + + + + + + + + + + - + + + - - - - + + + + + + + + + + + + + + + + + + + + -- 2.7.4 From 2e9c1f68c7c90da3d759ed342fedcc36d197f422 Mon Sep 17 00:00:00 2001 From: INSUN PYO Date: Wed, 14 Mar 2018 09:51:41 +0900 Subject: [PATCH 11/16] usb: remove unused usb_client item Signed-off-by: INSUN PYO Change-Id: I54463731572ac6015629a3e114de5f9cde2eba0e --- src/usb/usb.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/usb/usb.c b/src/usb/usb.c index 28c2777..db380f5 100644 --- a/src/usb/usb.c +++ b/src/usb/usb.c @@ -127,9 +127,6 @@ static int usb_probe(void) usb_client = usb_client_probe(USB_CLIENT_HARDWARE_DEVICE_ID); if (!usb_client) - usb_client = usb_client_probe(USB_SLP_CLIENT_HARDWARE_DEVICE_ID); - - if (!usb_client) usb_client = usb_client_probe(USB_CFS_CLIENT_HARDWARE_DEVICE_ID); if (!usb_client) { -- 2.7.4 From 8761726f5d3c6ff4835c59c505eba6ebb25d3708 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Wed, 14 Mar 2018 11:09:51 +0900 Subject: [PATCH 12/16] display: reset system timeout when specific process requested same state Change-Id: I1db14da69eaf0d68a568675dda16a7a1eb138e56 Signed-off-by: lokilee73 --- src/display/core.c | 5 ----- 1 file changed, 5 deletions(-) mode change 100644 => 100755 src/display/core.c diff --git a/src/display/core.c b/src/display/core.c old mode 100644 new mode 100755 index a334462..adf8aa4 --- a/src/display/core.c +++ b/src/display/core.c @@ -895,11 +895,6 @@ static int default_proc_change_state(unsigned int cond, pid_t pid) enum state_t next; next = GET_COND_STATE(cond); - if (pm_cur_state == next) { - _I("current state (%d) == next state (%d)", pm_cur_state, next); - return 0; - } - _I("Change State to %s (%d)", states[next].name, pid); switch (next) { -- 2.7.4 From 64bec949084f2bff0dce333052eda84d0244ee3f Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Wed, 14 Mar 2018 08:10:43 +0000 Subject: [PATCH 13/16] Revert "usb: Remove usb-operation" This reverts commit 48763fe1d4173f68803e941acf8c605a66ccbfe4. Change-Id: I6e20e9f2fce3e1b79a63c6a292840b24a7ab0d68 --- CMakeLists.txt | 2 + conf/usb-operation.conf | 14 ++++++ packaging/deviced.spec | 1 + src/usb/usb-operation.c | 114 ++++++++++++++++++++++++++++++++++++++++++++++++ src/usb/usb.c | 8 ++++ src/usb/usb.h | 3 ++ 6 files changed, 142 insertions(+) create mode 100644 conf/usb-operation.conf create mode 100644 src/usb/usb-operation.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 97448e1..50475c8 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -242,6 +242,8 @@ ENDIF() # USB connection IF(USB_MODULE STREQUAL on) + INSTALL_CONF(conf usb-operation) + # USB (Manual setting) INSTALL(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/scripts/direct_set_debug.sh DESTINATION bin) IF(${SDB_PRESTART} STREQUAL on) diff --git a/conf/usb-operation.conf b/conf/usb-operation.conf new file mode 100644 index 0000000..da6c71c --- /dev/null +++ b/conf/usb-operation.conf @@ -0,0 +1,14 @@ +[sdb] +StartService=sdbd.service +StopService=sdbd.service + +[mtp] +StartService=mtp-responder.service +StopService=mtp-responder.service + +[rndis] +Start=/sbin/ifconfig usb0 192.168.129.3 up +Start=/sbin/route add -net 192.168.129.0 netmask 255.255.255.0 dev usb0 +StartService=sshd.service +StopService=sshd.service +Stop=/sbin/ifconfig usb0 down diff --git a/packaging/deviced.spec b/packaging/deviced.spec index ecf21d6..7e0f6be 100755 --- a/packaging/deviced.spec +++ b/packaging/deviced.spec @@ -220,6 +220,7 @@ mv %{_libdir}/display-tv.so %{_libdir}/deviced/display.so %config %{_sysconfdir}/deviced/power.conf %config %{_sysconfdir}/deviced/battery.conf %config %{_sysconfdir}/deviced/display.conf +%config %{_sysconfdir}/deviced/usb-operation.conf # usbhost_test %{_sysconfdir}/deviced/usb-host-test/test_gadget.gs %{_bindir}/usb-host-ffs-test-daemon diff --git a/src/usb/usb-operation.c b/src/usb/usb-operation.c new file mode 100644 index 0000000..1bc8efc --- /dev/null +++ b/src/usb/usb-operation.c @@ -0,0 +1,114 @@ +/* + * deviced + * + * Copyright (c) 2015 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 "core/log.h" +#include "core/common.h" +#include "core/config-parser.h" +#include "core/launch.h" +#include "shared/deviced-systemd.h" +#include "usb.h" + +#define USB_OPERATION "/etc/deviced/usb-operation.conf" + +#define KEY_START_STR "Start" +#define KEY_STOP_STR "Stop" + +#define BUF_MAX 128 + +typedef enum { + OPERATION_STOP, + OPERATION_START, +} operation_e; + +struct oper_data { + char mode_str[BUF_MAX]; + operation_e type; +}; + +static int load_operation_config(struct parse_result *result, void *user_data) +{ + struct oper_data *data = user_data; + int ret; + operation_e type; + + if (!data || !result) + return -EINVAL; + + if (!strstr(data->mode_str, result->section)) + return 0; + + if (!strncmp(result->name, KEY_START_STR, strlen(KEY_START_STR))) + type = OPERATION_START; + else if (!strncmp(result->name, KEY_STOP_STR, strlen(KEY_STOP_STR))) + type = OPERATION_STOP; + else { + _E("Invalid name (%s)", result->name); + return -EINVAL; + } + + if (type != data->type) + return 0; + + if (strstr(result->name, "Service")) { + if (type == OPERATION_START) + ret = deviced_systemd_start_unit(result->value); + if (type == OPERATION_STOP) + ret = deviced_systemd_stop_unit(result->value); + } else + ret = launch_app_cmd(result->value); + + _I("Execute(%s %s: %d)", result->name, result->value, ret); + + return 0; +} + +static int usb_execute_operation(unsigned int mode, operation_e type) +{ + int ret; + struct oper_data data; + + usb_state_get_mode_str(mode, data.mode_str, sizeof(data.mode_str)); + + data.type = type; + + ret = config_parse(USB_OPERATION, + load_operation_config, &data); + if (ret < 0) + _E("Failed to load usb operation (%d)", ret); + + return ret; +} + +int usb_operation_start(unsigned int mode) +{ + if (is_emulator()) + return 0; + return usb_execute_operation(mode, OPERATION_START); +} + +int usb_operation_stop(unsigned int mode) +{ + if (is_emulator()) + return 0; + return usb_execute_operation(mode, OPERATION_STOP); +} diff --git a/src/usb/usb.c b/src/usb/usb.c index db380f5..66ac8b1 100644 --- a/src/usb/usb.c +++ b/src/usb/usb.c @@ -315,6 +315,8 @@ int usb_change_mode(unsigned mode) unsigned int curr = usb_state_get_current_mode(); if (curr != USB_FUNCTION_NONE) { + usb_operation_stop(curr); + ret = usb_disable(); if (ret < 0) { _E("Failed to disable current usb mode"); @@ -337,6 +339,8 @@ int usb_change_mode(unsigned mode) _E("Failed to enable usb mode (%d)"); return ret; } + + usb_operation_start(mode); } return 0; @@ -355,11 +359,15 @@ static int usb_connected(void) return ret; } + usb_operation_start(mode); + return 0; } static int usb_disconnected(void) { + usb_operation_stop(usb_state_get_current_mode()); + usb_state_update_state(USB_DISCONNECTED, USB_FUNCTION_NONE); return usb_disable(); diff --git a/src/usb/usb.h b/src/usb/usb.h index 0e6165b..ae26162 100644 --- a/src/usb/usb.h +++ b/src/usb/usb.h @@ -67,6 +67,9 @@ void usb_state_set_selected_mode(unsigned int mode); unsigned int usb_state_get_current_mode(void); usb_connection_state_e usb_state_get_connection(void); +int usb_operation_start(unsigned int mode); +int usb_operation_stop(unsigned int mode); + /* dbus methods/signals (usb-dbus.c) */ enum { DISABLED, -- 2.7.4 From d949817d9969999bfa1c3cbc503216eb4107b074 Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Thu, 15 Mar 2018 08:52:54 +0900 Subject: [PATCH 14/16] Enable systemd-based dbus activiation for deviced.service Change-Id: Ia9d1c38bc5d8baad1e0660fb5dcb3fa5e0721691 Signed-off-by: Hyotaek Shim --- CMakeLists.txt | 14 ++++++-------- packaging/deviced.spec | 1 + systemd/org.tizen.system.deviced.service | 5 +++++ 3 files changed, 12 insertions(+), 8 deletions(-) create mode 100644 systemd/org.tizen.system.deviced.service diff --git a/CMakeLists.txt b/CMakeLists.txt index 50475c8..be3ac66 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -255,17 +255,15 @@ IF(TIZEN_FEATURE_CPU_MODULE STREQUAL on) INSTALL_CONF(conf cpu) ENDIF() -INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/conf/org.tizen.system.deviced.conf DESTINATION /etc/dbus-1/system.d) - CONFIGURE_FILE(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY) INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) -INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/systemd/ DESTINATION lib/systemd/system - FILES_MATCHING - PATTERN "*.service" - PATTERN "*.socket" - PATTERN "sdb-prestart.service" EXCLUDE - PATTERN "usb-host*" EXCLUDE) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/conf/org.tizen.system.deviced.conf DESTINATION /etc/dbus-1/system.d) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/systemd/org.tizen.system.deviced.service DESTINATION /usr/share/dbus-1/system-services) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/systemd/deviced.service DESTINATION /usr/lib/systemd/system) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/systemd/deviced.socket DESTINATION /usr/lib/systemd/system) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/systemd/usb-host-ffs-test-daemon.service DESTINATION /usr/lib/systemd/system) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/systemd/usb-host-test.socket DESTINATION /usr/lib/systemd/system) IF(TIZEN_FEATURE_USBHOST_TEST STREQUAL on) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/systemd/usb-host-ffs-test-daemon.service diff --git a/packaging/deviced.spec b/packaging/deviced.spec index 7e0f6be..baa8ccb 100755 --- a/packaging/deviced.spec +++ b/packaging/deviced.spec @@ -211,6 +211,7 @@ mv %{_libdir}/display-tv.so %{_libdir}/deviced/display.so %{_unitdir}/sockets.target.wants/deviced.socket %{_unitdir}/deviced.service %{_unitdir}/deviced.socket +%{_datadir}/dbus-1/system-services/org.tizen.system.deviced.service %if %{?sdb_prestart} == on %{_unitdir}/sdb-prestart.service %{_unitdir}/basic.target.wants/sdb-prestart.service diff --git a/systemd/org.tizen.system.deviced.service b/systemd/org.tizen.system.deviced.service new file mode 100644 index 0000000..3a592cc --- /dev/null +++ b/systemd/org.tizen.system.deviced.service @@ -0,0 +1,5 @@ +[D-BUS Service] +Name=org.tizen.system.deviced +Exec=/bin/false +User=root +SystemdService=deviced.service -- 2.7.4 From 7d37ade950ab6006584dec46e1a4ac3c706ddada Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Wed, 7 Mar 2018 19:45:21 +0900 Subject: [PATCH 15/16] libdeviced-haptic: Remove unused codes - Remove unused logics and deprecated haptic internal apis Change-Id: I2b992dbd193f9429b90fa56ef30e1afff9ffa648 Signed-off-by: pr.jung --- src/deviced/dd-haptic.h | 423 ------------------------ src/deviced/haptic-module.h | 91 ------ src/deviced/haptic-plugin-intf.h | 42 --- src/libdeviced/haptic.c | 672 +-------------------------------------- 4 files changed, 10 insertions(+), 1218 deletions(-) delete mode 100644 src/deviced/haptic-module.h delete mode 100644 src/deviced/haptic-plugin-intf.h diff --git a/src/deviced/dd-haptic.h b/src/deviced/dd-haptic.h index 1f2f9fa..8b50a44 100644 --- a/src/deviced/dd-haptic.h +++ b/src/deviced/dd-haptic.h @@ -195,257 +195,6 @@ int haptic_close(haptic_device_h device_handle); int haptic_vibrate_monotone(haptic_device_h device_handle, int duration, haptic_effect_h *effect_handle); /** - * @brief Vibrates during the specified time with a constant intensity. - * @details - * This function can be used to start monotonous vibration for specified time. - * - * @remark - * If you don't use th api regarding effect_handle, you can pass in a NULL value to last parameter. - * - * @param[in] device_handle The device handle from haptic_open() - * @param[in] duration The play duration in milliseconds - * @param[in] feedback The amount of the intensity variation - * @param[in] priority The priority from HAPTIC_PRIORITY_MIN to HAPTIC_PRIORITY_HIGH - * @param[out] effect_handle Pointer to the variable that will receive a handle to the playing effect - * - * @return 0 on success, otherwise a negative error value. - * @retval #HAPTIC_ERROR_NONE Successful - * @retval #HAPTIC_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #HAPTIC_ERROR_NOT_INITIALIZED Not initialized - * @retval #HAPTIC_ERROR_OPERATION_FAILED Operation failed - * @retval #HAPTIC_ERROR_NOT_SUPPORTED_DEVICE Not supported device - * - * @see haptic_vibrate_monotone() - * @see haptic_vibrate_file_with_detail() - * @see haptic_vibrate_buffer_with_detail() - * @see haptic_get_count() - */ -int haptic_vibrate_monotone_with_detail(haptic_device_h device_handle, - int duration, - haptic_feedback_e feedback, - haptic_priority_e priority, - haptic_effect_h *effect_handle); - -/** - * @brief Vibrates a predefined rhythmic haptic-vibration pattern file. - * @details - * This function can be used to play a haptic-vibration pattern file. - * - * @remark - * If you don't use th api regarding effect_handle, you can pass in a NULL value to last parameter.\n - * And default value of feedback and priority is used.\n - * feedback level is reserved for auto chaning to save variable in the settings.\n - * priority level uses HAPTIC_PRIORITY_MIN. - * - * @param[in] device_handle The device handle from haptic_open() - * @param[in] file_path Vibration pattern file with path - * @param[out] effect_handle Pointer to the variable that will receive a handle to the playing effect - * - * @return 0 on success, otherwise a negative error value. - * @retval #HAPTIC_ERROR_NONE Successful - * @retval #HAPTIC_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #HAPTIC_ERROR_NOT_INITIALIZED Not initialized - * @retval #HAPTIC_ERROR_OPERATION_FAILED Operation failed - * @retval #HAPTIC_ERROR_NOT_SUPPORTED_DEVICE Not supported device - * - * @see haptic_vibrate_file_with_detail() - * @see haptic_vibrate_monotone() - * @see haptic_vibrate_buffer() - * @see haptic_get_count() - */ -int haptic_vibrate_file(haptic_device_h device_handle, const char *file_path, haptic_effect_h *effect_handle); - -/** - * @brief Vibrates a predefined rhythmic haptic-vibration pattern file. - * @details - * This function can be used to play a haptic-vibration pattern file. - * - * @remark - * If you don't use th api regarding effect_handle, you can pass in a NULL value to last parameter. - * - * @param[in] device_handle The device handle from haptic_open() - * @param[in] file_path Vibration pattern file with path - * @param[in] iteration The number of times to repeat the effect - * @param[in] feedback The amount of the intensity variation - * @param[in] priority The priority from HAPTIC_PRIORITY_MIN to HAPTIC_PRIORITY_HIGH - * @param[out] effect_handle Pointer to the variable that will receive a handle to the playing effect - * - * @return 0 on success, otherwise a negative error value. - * @retval #HAPTIC_ERROR_NONE Successful - * @retval #HAPTIC_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #HAPTIC_ERROR_NOT_INITIALIZED Not initialized - * @retval #HAPTIC_ERROR_OPERATION_FAILED Operation failed - * @retval #HAPTIC_ERROR_NOT_SUPPORTED_DEVICE Not supported device - * - * @see haptic_vibrate_file() - * @see haptic_vibrate_monotone_with_detail() - * @see haptic_vibrate_buffer_with_detail() - * @see haptic_get_count() - */ -int haptic_vibrate_file_with_detail(haptic_device_h device_handle, - const char *file_path, - haptic_iteration_e iteration, - haptic_feedback_e feedback, - haptic_priority_e priority, - haptic_effect_h *effect_handle); - -/** - * @brief Vibrates a predefined rhythmic haptic-vibration pattern buffer. - * @details - * This function can be used to play a haptic-vibration pattern buffer. - * - * @remark - * If you don't use th api regarding effect_handle, you can pass in a NULL value to last parameter.\n - * And default value of feedback and priority is used.\n - * feedback level is reserved for auto chaning to save variable in the settings.\n - * priority level uses HAPTIC_PRIORITY_MIN. - * - * @param[in] device_handle The device handle from haptic_open() - * @param[in] vibe_buffer Pointer to the vibration pattern - * @param[out] effect_handle Pointer to the variable that will receive a handle to the playing effect - * - * @return 0 on success, otherwise a negative error value. - * @retval #HAPTIC_ERROR_NONE Successful - * @retval #HAPTIC_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #HAPTIC_ERROR_NOT_INITIALIZED Not initialized - * @retval #HAPTIC_ERROR_OPERATION_FAILED Operation failed - * @retval #HAPTIC_ERROR_NOT_SUPPORTED_DEVICE Not supported device - * - * @see haptic_vibrate_buffer_with_detail() - * @see haptic_vibrate_monotone() - * @see haptic_vibrate_file() - * @see haptic_get_count() - */ -int haptic_vibrate_buffer(haptic_device_h device_handle, const unsigned char *vibe_buffer, haptic_effect_h *effect_handle); - -/** - * @brief Vibrates a predefined rhythmic haptic-vibration pattern buffer. - * @details - * This function can be used to play a haptic-vibration pattern buffer. - * - * @remark - * If you don't use th api regarding effect_handle, you can pass in a NULL value to last parameter. - * - * @param[in] device_handle The device handle from haptic_open() - * @param[in] vibe_buffer Pointer to the vibration pattern - * @param[in] iteration The number of times to repeat the effect - * @param[in] feedback The amount of the intensity variation - * @param[in] priority The priority from HAPTIC_PRIORITY_MIN to HAPTIC_PRIORITY_HIGH - * @param[out] effect_handle Pointer to the variable that will receive a handle to the playing effect - * - * @return 0 on success, otherwise a negative error value. - * @retval #HAPTIC_ERROR_NONE Successful - * @retval #HAPTIC_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #HAPTIC_ERROR_NOT_INITIALIZED Not initialized - * @retval #HAPTIC_ERROR_OPERATION_FAILED Operation failed - * @retval #HAPTIC_ERROR_NOT_SUPPORTED_DEVICE Not supported device - * - * @see haptic_vibrate_buffer() - * @see haptic_vibrate_monotone_with_detail() - * @see haptic_vibrate_file_with_detail() - * @see haptic_get_count() - */ -int haptic_vibrate_buffer_with_detail(haptic_device_h device_handle, - const unsigned char *vibe_buffer, - haptic_iteration_e iteration, - haptic_feedback_e feedback, - haptic_priority_e priority, - haptic_effect_h *effect_handle); - -/** - * @brief Vibrates a predefined rhythmic haptic-vibration pattern buffer. - * @details - * This function can be used to play a haptic-vibration pattern buffer. - * - * @remark - * If you don't use th api regarding effect_handle, you can pass in a NULL value to last parameter.\n - * And default value of feedback and priority is used.\n - * feedback level is reserved for auto chaning to save variable in the settings.\n - * priority level uses HAPTIC_PRIORITY_MIN. - * - * @param[in] device_handle The device handle from haptic_open() - * @param[in] vibe_buffer Pointer to the vibration pattern - * @param[in] size Size to the vibration pattern - * @param[out] effect_handle Pointer to the variable that will receive a handle to the playing effect - * - * @return 0 on success, otherwise a negative error value. - * @retval #HAPTIC_ERROR_NONE Successful - * @retval #HAPTIC_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #HAPTIC_ERROR_NOT_INITIALIZED Not initialized - * @retval #HAPTIC_ERROR_OPERATION_FAILED Operation failed - * @retval #HAPTIC_ERROR_NOT_SUPPORTED_DEVICE Not supported device - * - * @see haptic_vibrate_buffer_with_detail() - * @see haptic_vibrate_monotone() - * @see haptic_vibrate_file() - * @see haptic_get_count() - */ -int haptic_vibrate_buffers(haptic_device_h device_handle, - const unsigned char *vibe_buffer, - int size, - haptic_effect_h *effect_handle); - -/** - * @brief Vibrates a predefined rhythmic haptic-vibration pattern buffer. - * @details - * This function can be used to play a haptic-vibration pattern buffer. - * - * @remark - * If you don't use th api regarding effect_handle, you can pass in a NULL value to last parameter. - * - * @param[in] device_handle The device handle from haptic_open() - * @param[in] vibe_buffer Pointer to the vibration pattern - * @param[in] size Size to the vibration pattern - * @param[in] iteration The number of times to repeat the effect - * @param[in] feedback The amount of the intensity variation - * @param[in] priority The priority from HAPTIC_PRIORITY_MIN to HAPTIC_PRIORITY_HIGH - * @param[out] effect_handle Pointer to the variable that will receive a handle to the playing effect - * - * @return 0 on success, otherwise a negative error value. - * @retval #HAPTIC_ERROR_NONE Successful - * @retval #HAPTIC_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #HAPTIC_ERROR_NOT_INITIALIZED Not initialized - * @retval #HAPTIC_ERROR_OPERATION_FAILED Operation failed - * @retval #HAPTIC_ERROR_NOT_SUPPORTED_DEVICE Not supported device - * - * @see haptic_vibrate_buffer() - * @see haptic_vibrate_monotone_with_detail() - * @see haptic_vibrate_file_with_detail() - * @see haptic_get_count() - */ -int haptic_vibrate_buffers_with_detail(haptic_device_h device_handle, - const unsigned char *vibe_buffer, - int size, - haptic_iteration_e iteration, - haptic_feedback_e feedback, - haptic_priority_e priority, - haptic_effect_h *effect_handle); - -/** - * @brief Stops the current vibration effect which is being played. - * @details This function can be used to stop each effect started by haptic_vibrate_xxx(). - * - * @remark - * - * @param[in] device_handle The device handle from haptic_open() - * @param[in] effect_handle The effect handle from haptic_vibrate_xxx() - * - * @return 0 on success, otherwise a negative error value. - * @retval #HAPTIC_ERROR_NONE Successful - * @retval #HAPTIC_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #HAPTIC_ERROR_NOT_INITIALIZED Not initialized - * @retval #HAPTIC_ERROR_OPERATION_FAILED Operation failed - * @retval #HAPTIC_ERROR_NOT_SUPPORTED_DEVICE Not supported device - * - * @see haptic_vibrate_buffer() - * @see haptic_vibrate_monotone() - * @see haptic_vibrate_file() - * @see haptic_get_count() - * @see haptic_stop_all_effects() - */ -int haptic_stop_effect(haptic_device_h device_handle, haptic_effect_h effect_handle); - -/** * @brief Stops all vibration effects which are being played. * @details This function can be used to stop all effects started by haptic_vibrate_xxx(). * @@ -467,178 +216,6 @@ int haptic_stop_effect(haptic_device_h device_handle, haptic_effect_h effect_han * @see haptic_stop_effect() */ int haptic_stop_all_effects(haptic_device_h device_handle); - -/** - * @brief Gets the status of the effect. - * @details This function can be used to get the status of the effect wheter the effect are playing or not. - * - * @remark - * - * @param[in] device_handle The device handle from haptic_open() - * @param[in] effect_handle The effect handle from haptic_vibrate_xxx() - * @param[out] state The pointer to variable that will receive the status of the effect. - * - * @return 0 on success, otherwise a negative error value. - * @retval #HAPTIC_ERROR_NONE Successful - * @retval #HAPTIC_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #HAPTIC_ERROR_NOT_INITIALIZED Not initialized - * @retval #HAPTIC_ERROR_OPERATION_FAILED Operation failed - * @retval #HAPTIC_ERROR_NOT_SUPPORTED_DEVICE Not supported device - * - * @see haptic_vibrate_buffer() - * @see haptic_vibrate_monotone() - * @see haptic_vibrate_file() - * @see haptic_get_count() - * @see haptic_stop_effect() - * @see haptic_stop_all_effects() - */ -int haptic_get_effect_state(haptic_device_h device_handle, haptic_effect_h effect_handle, haptic_state_e *state); - -/** - * @par Description: - * effect element for haptic. - */ -typedef struct { - int haptic_duration; /**< Start time of the effect element in millisecond */ - int haptic_level; /**< Duration of the effect element in millisecond */ -} haptic_effect_element_s; - -/** - * @brief Creates an effect buffer. - * @details This function can be used to create an effect buffer using effeclt_element variable. - * - * @remark - * - * @param[out] vibe_buffer Pointer to the vibration pattern - * @param[in] max_bufsize The size of the buffer pointed to by vibe_buffer - * @param[in] elem_arr Pointer to an haptic_effect_element_s structure - * @param[in] max_elemcnt The size fo the buffer pointed to by elem_arr - * - * @return 0 on success, otherwise a negative error value. - * @retval #HAPTIC_ERROR_NONE Successful - * @retval #HAPTIC_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #HAPTIC_ERROR_NOT_INITIALIZED Not initialized - * @retval #HAPTIC_ERROR_OPERATION_FAILED Operation failed - * @retval #HAPTIC_ERROR_NOT_SUPPORTED_DEVICE Not supported device - * - * @see haptic_save_effect() - */ -int haptic_create_effect(unsigned char *vibe_buffer, - int max_bufsize, - haptic_effect_element_s *elem_arr, - int max_elemcnt); - -/** - * @brief Save an effect buffer to the file. - * @details This function can be used to save an effect buffer to the file using third parameter. - * - * @remark - * - * @param[in] vibe_buffer Pointer to the vibration pattern - * @param[in] max_bufsize The size of the buffer pointed to by vibe_buffer - * @param[in] file_path The pointer to the character buffer containing the path to save - * - * @return 0 on success, otherwise a negative error value. - * @retval #HAPTIC_ERROR_NONE Successful - * @retval #HAPTIC_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #HAPTIC_ERROR_NOT_INITIALIZED Not initialized - * @retval #HAPTIC_ERROR_FILE_EXISTS File exists - * @retval #HAPTIC_ERROR_OPERATION_FAILED Operation failed - * @retval #HAPTIC_ERROR_NOT_SUPPORTED_DEVICE Not supported device - * - * @see haptic_create_effect() - */ -int haptic_save_effect(const unsigned char *vibe_buffer, - int max_bufsize, - const char *file_path); - -/** - * @brief Gets a duration time value from file. - * @details This function can be used to get a duration time value from the file using second parameter. - * - * @remark - * - * @param[in] device_handle The device handle from haptic_open() - * @param[in] file_path The pointer to the character buffer containing the path to save - * @param[out] duration The pointer to the duration time value - * - * @return 0 on success, otherwise a negative error value. - * @retval #HAPTIC_ERROR_NONE Successful - * @retval #HAPTIC_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #HAPTIC_ERROR_NOT_INITIALIZED Not initialized - * @retval #HAPTIC_ERROR_OPERATION_FAILED Operation failed - * @retval #HAPTIC_ERROR_NOT_SUPPORTED_DEVICE Not supported device - * - * @see haptic_get_buffer_duration() - */ -int haptic_get_file_duration(haptic_device_h device_handle, const char *file_path, int *duration); - -/** - * @brief Gets a duration time value from buffer. - * @details This function can be used to get a duration time value from the buffer using second parameter. - * - * @remark - * - * @param[in] device_handle The device handle from haptic_open() - * @param[in] vibe_buffer Pointer to the vibration pattern buffer - * @param[out] duration The pointer to the duration time value - * - * @return 0 on success, otherwise a negative error value. - * @retval #HAPTIC_ERROR_NONE Successful - * @retval #HAPTIC_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #HAPTIC_ERROR_NOT_INITIALIZED Not initialized - * @retval #HAPTIC_ERROR_OPERATION_FAILED Operation failed - * @retval #HAPTIC_ERROR_NOT_SUPPORTED_DEVICE Not supported device - * - * @see haptic_get_file_duration() - */ -int haptic_get_buffer_duration(haptic_device_h device_handle, const unsigned char *vibe_buffer, int *duration); - -/** - * @brief Gets a duration time value from buffer. - * @details This function can be used to get a duration time value from the buffer using second parameter. - * - * @remark - * - * @param[in] device_handle The device handle from haptic_open() - * @param[in] vibe_buffer Pointer to the vibration pattern buffer - * @param[in] size Size to the vibration pattern buffer - * @param[out] buffer_duration The pointer to the duration time value - * - * @return 0 on success, otherwise a negative error value. - * @retval #HAPTIC_ERROR_NONE Successful - * @retval #HAPTIC_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #HAPTIC_ERROR_NOT_INITIALIZED Not initialized - * @retval #HAPTIC_ERROR_OPERATION_FAILED Operation failed - * @retval #HAPTIC_ERROR_NOT_SUPPORTED_DEVICE Not supported device - * - * @see haptic_get_file_duration() - */ -int haptic_get_buffers_duration(haptic_device_h device_handle, const unsigned char *vibe_buffer, int size, int *buffer_duration); - -/** - * @brief Save an effect buffer to the led file. - * @details This function can be used to save an effect buffer to the led file which name is third parameter. - * - * @remark - * Third parameter should be compatible with ledplayer file. - * - * @param[in] vibe_buffer Pointer to the vibration pattern - * @param[in] max_bufsize The size of the buffer pointed to by vibe_buffer - * @param[in] file_path The pointer to the character buffer containing the path to save - * - * @return 0 on success, otherwise a negative error value. - * @retval #HAPTIC_ERROR_NONE Successful - * @retval #HAPTIC_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #HAPTIC_ERROR_NOT_INITIALIZED Not initialized - * @retval #HAPTIC_ERROR_FILE_EXISTS File exists - * @retval #HAPTIC_ERROR_OPERATION_FAILED Operation failed - * @retval #HAPTIC_ERROR_NOT_SUPPORTED_DEVICE Not supported device - * - * @see haptic_save_effect() - */ -int haptic_save_led(const unsigned char *vibe_buffer, int max_bufsize, const char *file_path); - /** * @} end of CAPI_SYSTEM_DEVICED_HAPTIC_MODULE */ diff --git a/src/deviced/haptic-module.h b/src/deviced/haptic-module.h deleted file mode 100644 index 449fdd2..0000000 --- a/src/deviced/haptic-module.h +++ /dev/null @@ -1,91 +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 __HAPTIC_MODULE_H__ -#define __HAPTIC_MODULE_H__ - -/** - * @brief Enumerations of device id for the Haptic Module API. - * @details We support two motors now. - */ -typedef enum { - HAPTIC_MODULE_DEVICE_0 = 0x0, /**< 1st motor */ - HAPTIC_MODULE_DEVICE_1 = 0x1, /**< 2nd motor */ - HAPTIC_MODULE_DEVICE_ALL = 0x4, /**< both of them */ -} haptic_module_device; - -/** - * @brief Enumerations of priority level for the Haptic Module API. - */ -typedef enum { - HAPTIC_MODULE_PRIORITY_MIN = 0, /**< Minimum effect priority for developers (default) */ - HAPTIC_MODULE_PRIORITY_MIDDLE, /**< Maximum effect priority for developers */ - HAPTIC_MODULE_PRIORITY_HIGH, /**< Maximum effect priority for OEMs */ -} haptic_module_priority; - -/** - * @brief Enumerations of feedback level for the Haptic Module API. - * @details Haptic level means vibration power (intensity). - */ -typedef enum { - HAPTIC_MODULE_FEEDBACK_MIN = 0, - HAPTIC_MODULE_FEEDBACK_MAX = 100, -} haptic_module_feedback; - -/** - * @brief Enumerations of unlimited duration for the Haptic Module API. - */ -typedef enum { - HAPTIC_MODULE_DURATION_UNLIMITED = 0x7FFFFFFF, -} haptic_module_duration; - -/** - * @brief Enumerations of iteration count for the Haptic Module API. - */ -typedef enum { - HAPTIC_MODULE_ITERATION_ONCE = 1, - HAPTIC_MODULE_ITERATION_INFINITE = 256, -} haptic_module_iteration; - -/** - * @brief Enumerations of effect or device state for the Haptic Module API. - */ -typedef enum { - HAPTIC_MODULE_STATE_STOP = 0, - HAPTIC_MODULE_STATE_PLAYING, -} haptic_module_state; - -/* Error and Return value codes */ -#define HAPTIC_MODULE_ERROR_NONE 0 -#define HAPTIC_MODULE_NOT_INITIALIZED -1 -#define HAPTIC_MODULE_ALREADY_INITIALIZED -2 -#define HAPTIC_MODULE_INVALID_ARGUMENT -3 -#define HAPTIC_MODULE_OPERATION_FAILED -4 -#define HAPTIC_MODULE_NOT_SUPPORTED -5 - -/** - * @par Description: - * effect element for haptic module. - */ -typedef struct { - int haptic_duration; /**< Start time of the effect element in millisecond */ - int haptic_level; /**< Duration of the effect element in millisecond */ -} haptic_module_effect_element; - -#endif /* __HAPTIC_MODULE_H__ */ diff --git a/src/deviced/haptic-plugin-intf.h b/src/deviced/haptic-plugin-intf.h deleted file mode 100644 index 6fe854d..0000000 --- a/src/deviced/haptic-plugin-intf.h +++ /dev/null @@ -1,42 +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 __HAPTIC_PLUGIN_INTF_H__ -#define __HAPTIC_PLUGIN_INTF_H__ - -#include "haptic-module.h" - -struct haptic_plugin_ops { - int (*get_device_count) (int*); - int (*open_device) (int, int*); - int (*close_device) (int); - int (*vibrate_monotone) (int, int, int, int, int*); - int (*vibrate_buffer) (int, const unsigned char*, int, int, int, int*); - int (*vibrate_effect) (int, const char*, int, int); - int (*is_supported) (const char*); - int (*stop_device) (int); - int (*get_device_state) (int, int*); - int (*create_effect) (unsigned char*, int, haptic_module_effect_element*, int); - int (*get_buffer_duration) (int, const unsigned char*, int*); - int (*convert_binary) (const unsigned char*, int, const char*); -}; - -const struct haptic_plugin_ops *get_haptic_plugin_interface(); - -#endif /* __HAPTIC_PLUGIN_INTF_H__ */ diff --git a/src/libdeviced/haptic.c b/src/libdeviced/haptic.c index 05daa2d..dcd8569 100644 --- a/src/libdeviced/haptic.c +++ b/src/libdeviced/haptic.c @@ -29,687 +29,35 @@ #include "log.h" #include "dbus.h" -#include "haptic-plugin-intf.h" #include "dd-haptic.h" #include "common.h" -#define METHOD_OPEN_DEVICE "OpenDevice" -#define METHOD_CLOSE_DEVICE "CloseDevice" -#define METHOD_STOP_DEVICE "StopDevice" -#define METHOD_VIBRATE_MONOTONE "VibrateMonotone" -#define METHOD_VIBRATE_BUFFER "VibrateBuffer" -#define METHOD_GET_COUNT "GetCount" -#define METHOD_GET_STATE "GetState" -#define METHOD_GET_DURATION "GetDuration" -#define METHOD_CREATE_EFFECT "CreateEffect" -#define METHOD_SAVE_BINARY "SaveBinary" - -#define TEMP_BUFFER_SIZE (64*1024) - -/* START of Static Function Section */ -static unsigned char *convert_file_to_buffer(const char *file_name, int *size) -{ - FILE *pf; - long file_size; - unsigned char *pdata = NULL; - - if (!file_name) - return NULL; - - /* Get File Stream Pointer */ - pf = fopen(file_name, "rb"); - if (!pf) { - _E("fopen failed : %d", errno); - return NULL; - } - - if (fseek(pf, 0, SEEK_END)) - goto error; - - file_size = ftell(pf); - if (fseek(pf, 0, SEEK_SET)) - goto error; - - if (file_size < 0) - goto error; - - pdata = (unsigned char *)malloc(file_size); - if (!pdata) - goto error; - - if (fread(pdata, 1, file_size, pf) != file_size) - goto err_free; - - fclose(pf); - *size = file_size; - return pdata; - -err_free: - free(pdata); - -error: - fclose(pf); - - _E("failed to convert file to buffer (%d)", errno); - return NULL; -} - -static int save_data(const unsigned char *data, int size, const char *file_path) -{ - FILE *file; - int fd; - - file = fopen(file_path, "wb+"); - if (file == NULL) { - _E("To open file is failed : %d", errno); - return -1; - } - - if (fwrite(data, 1, size, file) != size) { - _E("To write file is failed : %d", errno); - fclose(file); - return -1; - } - - fd = fileno(file); - if (fd < 0) { - _E("To get file descriptor is failed : %d", errno); - fclose(file); - return -1; - } - - if (fsync(fd) < 0) { - _E("To be synchronized with the disk is failed : %d", errno); - fclose(file); - return -1; - } - - fclose(file); - return 0; -} - -static haptic_feedback_e convert_setting_to_module_level(void) -{ - int setting_fb_level; - - if (vconf_get_int(VCONFKEY_SETAPPL_TOUCH_FEEDBACK_VIBRATION_LEVEL_INT, &setting_fb_level) < 0) - setting_fb_level = SETTING_VIB_FEEDBACK_LEVEL3; - - if (setting_fb_level < HAPTIC_FEEDBACK_0 || setting_fb_level > HAPTIC_FEEDBACK_5) - return -1; - - switch (setting_fb_level) { - case SETTING_VIB_FEEDBACK_LEVEL0: - return HAPTIC_FEEDBACK_0; - case SETTING_VIB_FEEDBACK_LEVEL1: - return HAPTIC_FEEDBACK_1; - case SETTING_VIB_FEEDBACK_LEVEL2: - return HAPTIC_FEEDBACK_2; - case SETTING_VIB_FEEDBACK_LEVEL3: - return HAPTIC_FEEDBACK_3; - case SETTING_VIB_FEEDBACK_LEVEL4: - return HAPTIC_FEEDBACK_4; - case SETTING_VIB_FEEDBACK_LEVEL5: - return HAPTIC_FEEDBACK_5; - default: - break; - } - return -1; -} -/* END of Static Function Section */ - API int haptic_get_count(int *device_number) { - int ret; - - /* check if pointer is valid */ - if (device_number == NULL) { - _E("Invalid parameter : device_number(NULL)"); - return HAPTIC_ERROR_INVALID_PARAMETER; - } - - /* request to deviced to get haptic count */ - ret = dbus_handle_method_sync(VIBRATOR_BUS_NAME, - VIBRATOR_PATH_HAPTIC, - VIBRATOR_INTERFACE_HAPTIC, - METHOD_GET_COUNT, - NULL, - NULL); - if (ret < 0) - return HAPTIC_ERROR_OPERATION_FAILED; - - *device_number = ret; - return HAPTIC_ERROR_NONE; + _E("Not Supported, Please use capi-system-device apis"); + return HAPTIC_ERROR_OPERATION_FAILED; } API int haptic_open(haptic_device_e device_index, haptic_device_h *device_handle) { - int ret; - - /* check if index is valid */ - if (!(device_index == HAPTIC_DEVICE_0 || device_index == HAPTIC_DEVICE_1 || - device_index == HAPTIC_DEVICE_ALL)) { - _E("Invalid parameter : device_index(%d)", device_index); - return HAPTIC_ERROR_INVALID_PARAMETER; - } - - /* check if pointer is valid */ - if (device_handle == NULL) { - _E("Invalid parameter : device_handle(NULL)"); - return HAPTIC_ERROR_INVALID_PARAMETER; - } - - /* request to deviced to open haptic device */ - ret = dbus_handle_method_sync_var(VIBRATOR_BUS_NAME, - VIBRATOR_PATH_HAPTIC, - VIBRATOR_INTERFACE_HAPTIC, - METHOD_OPEN_DEVICE, - g_variant_new("(i)", device_index)); - if (ret < 0) - return HAPTIC_ERROR_OPERATION_FAILED; - - *device_handle = (haptic_device_h)ret; - return HAPTIC_ERROR_NONE; + _E("Not Supported, Please use capi-system-device apis"); + return HAPTIC_ERROR_OPERATION_FAILED; } API int haptic_close(haptic_device_h device_handle) { - int ret; - - /* check if handle is valid */ - if (!device_handle) { - _E("Invalid parameter : device_handle"); - return HAPTIC_ERROR_INVALID_PARAMETER; - } - - /* request to deviced to open haptic device */ - ret = dbus_handle_method_sync_var(VIBRATOR_BUS_NAME, - VIBRATOR_PATH_HAPTIC, - VIBRATOR_INTERFACE_HAPTIC, - METHOD_CLOSE_DEVICE, - g_variant_new("(u)", device_handle)); - if (ret < 0) - return HAPTIC_ERROR_OPERATION_FAILED; - - return HAPTIC_ERROR_NONE; + _E("Not Supported, Please use capi-system-device apis"); + return HAPTIC_ERROR_OPERATION_FAILED; } API int haptic_vibrate_monotone(haptic_device_h device_handle, int duration, haptic_effect_h *effect_handle) { - return haptic_vibrate_monotone_with_detail(device_handle, - duration, - HAPTIC_FEEDBACK_AUTO, - HAPTIC_PRIORITY_MIN, - effect_handle); -} - -API int haptic_vibrate_monotone_with_detail(haptic_device_h device_handle, - int duration, - haptic_feedback_e feedback, - haptic_priority_e priority, - haptic_effect_h *effect_handle) -{ - int ret; - - /* check if handle is valid */ - if (!device_handle) { - _E("Invalid parameter : device_handle"); - return HAPTIC_ERROR_INVALID_PARAMETER; - } - - /* check if passed arguments are valid */ - if (duration < 0 && duration != HAPTIC_DURATION_UNLIMITED) { - _E("Invalid parameter : duration(%d)", duration); - return HAPTIC_ERROR_INVALID_PARAMETER; - } - - if (feedback < HAPTIC_FEEDBACK_0 || feedback > HAPTIC_FEEDBACK_AUTO) { - _E("Invalid parameter : feedback(%d)", feedback); - return HAPTIC_ERROR_INVALID_PARAMETER; - } - - if (priority < HAPTIC_PRIORITY_MIN || priority > HAPTIC_PRIORITY_HIGH) { - _E("Invalid parameter : priority(%d)", priority); - return HAPTIC_ERROR_INVALID_PARAMETER; - } - - /* in case of FEEDBACK_AUTO, should be converted */ - if (feedback == HAPTIC_FEEDBACK_AUTO) - feedback = convert_setting_to_module_level(); - - /* request to deviced to open haptic device */ - ret = dbus_handle_method_sync_var(VIBRATOR_BUS_NAME, - VIBRATOR_PATH_HAPTIC, - VIBRATOR_INTERFACE_HAPTIC, - METHOD_VIBRATE_MONOTONE, - g_variant_new("(uiii)", device_handle, duration, feedback, priority)); - if (ret < 0) - return HAPTIC_ERROR_OPERATION_FAILED; - - if (effect_handle != NULL) - *effect_handle = (haptic_effect_h)ret; - - return HAPTIC_ERROR_NONE; -} - -API int haptic_vibrate_file(haptic_device_h device_handle, const char *file_path, haptic_effect_h *effect_handle) -{ - unsigned char *vibe_buffer; - int size, ret; - - vibe_buffer = convert_file_to_buffer(file_path, &size); - if (!vibe_buffer) { - _E("Convert file to buffer error"); - return HAPTIC_ERROR_OPERATION_FAILED; - } - - ret = haptic_vibrate_buffers_with_detail(device_handle, - (const unsigned char *)vibe_buffer, - size, - HAPTIC_ITERATION_ONCE, - HAPTIC_FEEDBACK_AUTO, - HAPTIC_PRIORITY_MIN, - effect_handle); - free(vibe_buffer); - return ret; -} - -API int haptic_vibrate_file_with_detail(haptic_device_h device_handle, - const char *file_path, - haptic_iteration_e iteration, - haptic_feedback_e feedback, - haptic_priority_e priority, - haptic_effect_h *effect_handle) -{ - unsigned char *vibe_buffer; - int size, ret; - - vibe_buffer = convert_file_to_buffer(file_path, &size); - if (!vibe_buffer) { - _E("Convert file to buffer error"); - return HAPTIC_ERROR_OPERATION_FAILED; - } - - ret = haptic_vibrate_buffers_with_detail(device_handle, - (const unsigned char *)vibe_buffer, - size, - iteration, - feedback, - priority, - effect_handle); - free(vibe_buffer); - return ret; -} - -API int haptic_vibrate_buffer(haptic_device_h device_handle, const unsigned char *vibe_buffer, haptic_effect_h *effect_handle) -{ - return haptic_vibrate_buffers_with_detail(device_handle, - vibe_buffer, - TEMP_BUFFER_SIZE, - HAPTIC_ITERATION_ONCE, - HAPTIC_FEEDBACK_AUTO, - HAPTIC_PRIORITY_MIN, - effect_handle); -} - -API int haptic_vibrate_buffer_with_detail(haptic_device_h device_handle, - const unsigned char *vibe_buffer, - haptic_iteration_e iteration, - haptic_feedback_e feedback, - haptic_priority_e priority, - haptic_effect_h *effect_handle) -{ - return haptic_vibrate_buffers_with_detail(device_handle, - vibe_buffer, - TEMP_BUFFER_SIZE, - iteration, - feedback, - priority, - effect_handle); -} - -API int haptic_vibrate_buffers(haptic_device_h device_handle, - const unsigned char *vibe_buffer, - int size, - haptic_effect_h *effect_handle) -{ - return haptic_vibrate_buffers_with_detail(device_handle, - vibe_buffer, - size, - HAPTIC_ITERATION_ONCE, - HAPTIC_FEEDBACK_AUTO, - HAPTIC_PRIORITY_MIN, - effect_handle); -} - -API int haptic_vibrate_buffers_with_detail(haptic_device_h device_handle, - const unsigned char *vibe_buffer, - int size, - haptic_iteration_e iteration, - haptic_feedback_e feedback, - haptic_priority_e priority, - haptic_effect_h *effect_handle) -{ - GVariant *pvar = NULL; - int ret; - - /* check if handle is valid */ - if (!device_handle) { - _E("Invalid parameter : device_handle"); - return HAPTIC_ERROR_INVALID_PARAMETER; - } - - /* check if passed arguments are valid */ - if (vibe_buffer == NULL) { - _E("Invalid parameter : vibe_buffer(NULL)"); - return HAPTIC_ERROR_INVALID_PARAMETER; - } - - if (iteration < HAPTIC_ITERATION_ONCE || iteration > HAPTIC_ITERATION_INFINITE) { - _E("Invalid parameter : iteration(%d)", iteration); - return HAPTIC_ERROR_INVALID_PARAMETER; - } - - if (feedback < HAPTIC_FEEDBACK_0 || feedback > HAPTIC_FEEDBACK_AUTO) { - _E("Invalid parameter : feedback(%d)", feedback); - return HAPTIC_ERROR_INVALID_PARAMETER; - } - - if (priority < HAPTIC_PRIORITY_MIN || priority > HAPTIC_PRIORITY_HIGH) { - _E("Invalid parameter : priority(%d)", priority); - return HAPTIC_ERROR_INVALID_PARAMETER; - } - - /* in case of FEEDBACK_AUTO, should be converted */ - if (feedback == HAPTIC_FEEDBACK_AUTO) - feedback = convert_setting_to_module_level(); - - - /* request to deviced to open haptic device */ - pvar = g_variant_new_fixed_array(G_VARIANT_TYPE_BYTE, vibe_buffer, size, sizeof(char)); - ret = dbus_handle_method_sync_var(VIBRATOR_BUS_NAME, - VIBRATOR_PATH_HAPTIC, - VIBRATOR_INTERFACE_HAPTIC, - METHOD_VIBRATE_BUFFER, - g_variant_new("(u@ayiii)", device_handle, pvar, iteration, feedback, priority)); - if (ret < 0) - return HAPTIC_ERROR_OPERATION_FAILED; - - if (effect_handle != NULL) - *effect_handle = (haptic_effect_h)ret; - - return HAPTIC_ERROR_NONE; -} - -API int haptic_stop_effect(haptic_device_h device_handle, haptic_effect_h effect_handle) -{ - return haptic_stop_all_effects(device_handle); + _E("Not Supported, Please use capi-system-device apis"); + return HAPTIC_ERROR_OPERATION_FAILED; } API int haptic_stop_all_effects(haptic_device_h device_handle) { - int ret; - - /* check if handle is valid */ - if (!device_handle) { - _E("Invalid parameter : device_handle"); - return HAPTIC_ERROR_INVALID_PARAMETER; - } - - /* request to deviced to open haptic device */ - ret = dbus_handle_method_sync_var(VIBRATOR_BUS_NAME, - VIBRATOR_PATH_HAPTIC, - VIBRATOR_INTERFACE_HAPTIC, - METHOD_STOP_DEVICE, - g_variant_new("(u)", device_handle)); - if (ret < 0) - return HAPTIC_ERROR_OPERATION_FAILED; - - return HAPTIC_ERROR_NONE; -} - -API int haptic_get_effect_state(haptic_device_h device_handle, haptic_effect_h effect_handle, haptic_state_e *effect_state) -{ - int ret; - - /* check if handle is valid */ - if (!device_handle) { - _E("Invalid parameter : device_handle"); - return HAPTIC_ERROR_INVALID_PARAMETER; - } - - /* check if pointer is valid */ - if (effect_state == NULL) { - _E("Invalid parameter : effect_state(NULL)"); - return HAPTIC_ERROR_INVALID_PARAMETER; - } - - /* request to deviced to open haptic device */ - ret = dbus_handle_method_sync_var(VIBRATOR_BUS_NAME, - VIBRATOR_PATH_HAPTIC, - VIBRATOR_INTERFACE_HAPTIC, - METHOD_GET_STATE, - g_variant_new("(i)", HAPTIC_DEVICE_0)); - if (ret < 0) - return HAPTIC_ERROR_OPERATION_FAILED; - - *effect_state = (haptic_state_e)ret; - return HAPTIC_ERROR_NONE; -} - -API int haptic_create_effect(unsigned char *vibe_buffer, - int max_bufsize, - haptic_effect_element_s *elem_arr, - int max_elemcnt) -{ - GVariant *msg; - GVariant *pvar = NULL; - const char *data = NULL; - int i, temp, ret_val; - gsize size; - - /* check if passed arguments are valid */ - if (vibe_buffer == NULL) { - _E("Invalid parameter : vibe_buffer(NULL)"); - return HAPTIC_ERROR_INVALID_PARAMETER; - } - - if (max_bufsize <= 0) { - _E("Invalid parameter : max_bufsize(%d)", max_bufsize); - return HAPTIC_ERROR_INVALID_PARAMETER; - } - - if (elem_arr == NULL) { - _E("Invalid parameter : elem_arr(NULL)"); - return HAPTIC_ERROR_INVALID_PARAMETER; - } - - if (max_elemcnt <= 0) { - _E("Invalid parameter : max_elemcnt(%d)", max_elemcnt); - return HAPTIC_ERROR_INVALID_PARAMETER; - } - - /* convert to proper feedback level in case of auto */ - for (i = 0; i < max_elemcnt; i++) { - if (elem_arr[i].haptic_level == HAPTIC_FEEDBACK_AUTO) { - vconf_get_int(VCONFKEY_SETAPPL_TOUCH_FEEDBACK_VIBRATION_LEVEL_INT, &temp); - elem_arr[i].haptic_level = temp*20; - } - } - - pvar = g_variant_new_fixed_array(G_VARIANT_TYPE_BYTE, elem_arr, sizeof(haptic_effect_element_s) * max_elemcnt, sizeof(char)); - msg = dbus_handle_method_sync_with_reply_var(VIBRATOR_BUS_NAME, - VIBRATOR_PATH_HAPTIC, - VIBRATOR_INTERFACE_HAPTIC, - METHOD_CREATE_EFFECT, - g_variant_new("(i@ayi)", max_bufsize, pvar, max_elemcnt)); - if (!msg) - return HAPTIC_ERROR_OPERATION_FAILED; - - if (!dh_get_param_from_var(msg, "(@ayi)", &pvar, &ret_val)) { - _E("no message [%s]", g_variant_get_type_string(msg)); - goto err; - } - if (ret_val < 0) { - _E("%s-%s failed : %d", VIBRATOR_INTERFACE_HAPTIC, METHOD_CREATE_EFFECT, ret_val); - goto err; - } - - data = g_variant_get_fixed_array(pvar, &size, sizeof(char)); - g_variant_unref(pvar); - - if (max_bufsize < size) { - _E("max_bufsize(%d) is smaller than effect buffer size(%d)", max_bufsize, size); - goto err; - } - - memcpy(vibe_buffer, data, max_bufsize); - g_variant_unref(msg); - return HAPTIC_ERROR_NONE; -err: - g_variant_unref(msg); + _E("Not Supported, Please use capi-system-device apis"); return HAPTIC_ERROR_OPERATION_FAILED; -} - -API int haptic_save_effect(const unsigned char *vibe_buffer, - int max_bufsize, - const char *file_path) -{ - struct stat buf; - int ret; - - /* check if passed arguments are valid */ - if (vibe_buffer == NULL) { - _E("Invalid parameter : vibe_buffer(NULL)"); - return HAPTIC_ERROR_INVALID_PARAMETER; - } - - if (max_bufsize <= 0) { - _E("Invalid parameter : max_bufsize(%d)", max_bufsize); - return HAPTIC_ERROR_INVALID_PARAMETER; - } - - if (file_path == NULL) { - _E("Invalid parameter : file_path(NULL)"); - return HAPTIC_ERROR_INVALID_PARAMETER; - } - - /* check if the file already exists */ - if (!stat(file_path, &buf)) { - _E("Already exist : file_path(%s)", file_path); - return HAPTIC_ERROR_FILE_EXISTS; - } - - _D("file path : %s", file_path); - ret = save_data(vibe_buffer, max_bufsize, file_path); - if (ret < 0) { - _E("fail to save data"); - return HAPTIC_MODULE_OPERATION_FAILED; - } - - return HAPTIC_ERROR_NONE; -} - -API int haptic_get_file_duration(haptic_device_h device_handle, const char *file_path, int *file_duration) -{ - unsigned char *vibe_buffer; - int size, ret; - - vibe_buffer = convert_file_to_buffer(file_path, &size); - if (!vibe_buffer) { - _E("Convert file to buffer error"); - return HAPTIC_ERROR_OPERATION_FAILED; - } - - ret = haptic_get_buffers_duration(device_handle, - (const unsigned char *)vibe_buffer, - size, - file_duration); - free(vibe_buffer); - return ret; -} - -API int haptic_get_buffer_duration(haptic_device_h device_handle, const unsigned char *vibe_buffer, int *buffer_duration) -{ - return haptic_get_buffers_duration(device_handle, - vibe_buffer, - TEMP_BUFFER_SIZE, - buffer_duration); -} - -API int haptic_get_buffers_duration(haptic_device_h device_handle, const unsigned char *vibe_buffer, int size, int *buffer_duration) -{ - GVariant *pvar = NULL; - int ret; - - /* check if handle is valid */ - if (!device_handle) { - _E("Invalid parameter : device_handle"); - return HAPTIC_ERROR_INVALID_PARAMETER; - } - - if (vibe_buffer == NULL) { - _E("Invalid parameter : vibe_buffer(NULL)"); - return HAPTIC_ERROR_INVALID_PARAMETER; - } - - /* check if pointer is valid */ - if (buffer_duration == NULL) { - _E("Invalid parameter : buffer_duration(NULL)"); - return HAPTIC_ERROR_INVALID_PARAMETER; - } - - /* request to deviced to open haptic device */ - pvar = g_variant_new_fixed_array(G_VARIANT_TYPE_BYTE, vibe_buffer, size, sizeof(char)); - ret = dbus_handle_method_sync_var(VIBRATOR_BUS_NAME, - VIBRATOR_PATH_HAPTIC, - VIBRATOR_INTERFACE_HAPTIC, - METHOD_GET_DURATION, - g_variant_new("(u@ay)", device_handle, pvar)); - if (ret < 0) - return HAPTIC_ERROR_OPERATION_FAILED; - - *buffer_duration = ret; - return HAPTIC_ERROR_NONE; -} - -API int haptic_save_led(const unsigned char *vibe_buffer, int max_bufsize, const char *file_path) -{ - GVariant *pvar = NULL; - struct stat buf; - int ret; - - /* check if passed arguments are valid */ - if (vibe_buffer == NULL) { - _E("Invalid parameter : vibe_buffer(NULL)"); - return HAPTIC_ERROR_INVALID_PARAMETER; - } - - if (max_bufsize <= 0) { - _E("Invalid parameter : max_bufsize(%d)", max_bufsize); - return HAPTIC_ERROR_INVALID_PARAMETER; - } - - if (file_path == NULL) { - _E("Invalid parameter : file_path(NULL)"); - return HAPTIC_ERROR_INVALID_PARAMETER; - } - - /* check if the file already exists */ - if (!stat(file_path, &buf)) { - _E("Already exist : file_path(%s)", file_path); - return HAPTIC_ERROR_FILE_EXISTS; - } - - /* request to deviced to open haptic device */ - pvar = g_variant_new_fixed_array(G_VARIANT_TYPE_BYTE, vibe_buffer, max_bufsize, sizeof(char)); - ret = dbus_handle_method_sync_var(VIBRATOR_BUS_NAME, - VIBRATOR_PATH_HAPTIC, - VIBRATOR_INTERFACE_HAPTIC, - METHOD_SAVE_BINARY, - g_variant_new("(@ays)", pvar, file_path)); - if (ret < 0) - return HAPTIC_ERROR_OPERATION_FAILED; - - return HAPTIC_ERROR_NONE; -} +} \ No newline at end of file -- 2.7.4 From f1155e012ed08734b102413efe523556a16c1bc5 Mon Sep 17 00:00:00 2001 From: "sanghyeok.oh" Date: Thu, 15 Mar 2018 14:44:14 +0900 Subject: [PATCH 16/16] dbus: remove ineffective rule Change-Id: I17c4d1961cc6ca4eaa25947ef9e4bc7f7f2087a1 Signed-off-by: sanghyeok.oh --- conf/org.tizen.system.deviced.conf | 1 - 1 file changed, 1 deletion(-) diff --git a/conf/org.tizen.system.deviced.conf b/conf/org.tizen.system.deviced.conf index fa226d9..656af38 100644 --- a/conf/org.tizen.system.deviced.conf +++ b/conf/org.tizen.system.deviced.conf @@ -4,7 +4,6 @@ - -- 2.7.4