From 64bec949084f2bff0dce333052eda84d0244ee3f Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Wed, 14 Mar 2018 08:10:43 +0000 Subject: [PATCH 01/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 02/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 03/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 04/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 From a6909abda82d4ed64903606a8fe20608e65e0921 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Fri, 16 Mar 2018 15:10:57 +0900 Subject: [PATCH 05/16] Remove unused socket and function socket: deviced.socket function: deviced_call_predef_action Change-Id: Ie09f1e8f913f95f95fb64146392ff9929447d2cf Signed-off-by: lokilee73 --- CMakeLists.txt | 1 - packaging/deviced.spec | 3 - src/deviced/dd-deviced.h | 13 ----- src/libdeviced/deviced-noti.c | 130 ------------------------------------------ src/shared/deviced-priv.h | 11 ---- systemd/deviced.socket | 10 ---- 6 files changed, 168 deletions(-) mode change 100644 => 100755 src/libdeviced/deviced-noti.c mode change 100644 => 100755 src/shared/deviced-priv.h delete mode 100644 systemd/deviced.socket diff --git a/CMakeLists.txt b/CMakeLists.txt index be3ac66..8d5cb32 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -261,7 +261,6 @@ INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc DESTINATION ${LIB_I 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) diff --git a/packaging/deviced.spec b/packaging/deviced.spec index baa8ccb..b5a3b0b 100755 --- a/packaging/deviced.spec +++ b/packaging/deviced.spec @@ -161,7 +161,6 @@ rm -rf %{buildroot} %make_install %install_service multi-user.target.wants deviced.service -%install_service sockets.target.wants deviced.socket # usb_module condition is removed because it is always on %if %{?sdb_prestart} == on %install_service basic.target.wants sdb-prestart.service @@ -208,9 +207,7 @@ mv %{_libdir}/display-tv.so %{_libdir}/deviced/display.so %license LICENSE.Apache-2.0 %{_bindir}/deviced %{_unitdir}/multi-user.target.wants/deviced.service -%{_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 diff --git a/src/deviced/dd-deviced.h b/src/deviced/dd-deviced.h index e9d3f98..b15a530 100755 --- a/src/deviced/dd-deviced.h +++ b/src/deviced/dd-deviced.h @@ -107,19 +107,6 @@ int deviced_get_apppath(pid_t pid, char *app_path, size_t app_path_size); int deviced_set_timezone(char *tzpath_str); /** - * @fn int deviced_call_predef_action(const char *type, int num, ...) - * @brief This API calls predefined systemd action. - * Internally it send message through SYSTEM_NOTI_SOCKET_PATH (/tmp/sn) UNIX socket to systemd. - * @param[in] type systemd action type name - * @param[in] num input parameters count. num cannot exceed SYSTEM_NOTI_MAXARG (16). - * @param[in] ... action input parameters. List of the parameters depends on action type. - * @return 0 on success, -1 if failed. - * If the action type is not set (is blank) or num > SYSTEM_NOTI_MAXARG it will return -1 - * and errno will be set as EINVAL. - */ -int deviced_call_predef_action(const char *type, int num, ...); - -/** * @fn int deviced_change_flightmode(int mode) * @brief This API call notifies about flight mode. * @return 0 or positive value on success and negative value if failed. diff --git a/src/libdeviced/deviced-noti.c b/src/libdeviced/deviced-noti.c old mode 100644 new mode 100755 index 77a8424..c4957cb --- a/src/libdeviced/deviced-noti.c +++ b/src/libdeviced/deviced-noti.c @@ -54,136 +54,6 @@ #define ALARM_INTERFACE_NAME ALARM_BUS_NAME #define ALARM_SET_TIME_METHOD "alarm_set_time" -enum deviced_noti_cmd { - ADD_deviced_ACTION, - CALL_deviced_ACTION -}; - -#define SYSTEM_NOTI_SOCKET_PATH "/tmp/sn" -#define RETRY_READ_COUNT 10 - -static inline int send_int(int fd, int val) -{ - return write(fd, &val, sizeof(int)); -} - -static inline int send_str(int fd, char *str) -{ - int len; - int ret; - if (str == NULL) { - len = 0; - ret = write(fd, &len, sizeof(int)); - } else { - len = strlen(str); - if (len > SYSTEM_NOTI_MAXSTR) - len = SYSTEM_NOTI_MAXSTR; - ret = write(fd, &len, sizeof(int)); - if (ret < 0) - _E("Failed to write (%d)", errno); - ret = write(fd, str, len); - if (ret < 0) - _E("Failed to write (%d)", errno); - } - return ret; -} - -static int noti_send(struct sysnoti *msg) -{ - int client_len; - int client_sockfd; - int result; - int r; - int retry_count = 0; - struct sockaddr_un clientaddr; - int i; - - client_sockfd = socket(AF_UNIX, SOCK_STREAM, 0); - if (client_sockfd == -1) { - _E("socket create failed"); - return -1; - } - bzero(&clientaddr, sizeof(clientaddr)); - clientaddr.sun_family = AF_UNIX; - strncpy(clientaddr.sun_path, SYSTEM_NOTI_SOCKET_PATH, sizeof(clientaddr.sun_path) - 1); - client_len = sizeof(clientaddr); - - if (connect(client_sockfd, (struct sockaddr *)&clientaddr, client_len) < - 0) { - _E("connect failed"); - close(client_sockfd); - return -1; - } - - send_int(client_sockfd, msg->pid); - send_int(client_sockfd, msg->cmd); - send_str(client_sockfd, msg->type); - send_str(client_sockfd, msg->path); - send_int(client_sockfd, msg->argc); - for (i = 0; i < msg->argc; i++) - send_str(client_sockfd, msg->argv[i]); - - while (retry_count < RETRY_READ_COUNT) { - r = read(client_sockfd, &result, sizeof(int)); - if (r < 0) { - if (errno == EINTR) { - _E("Re-read for error(EINTR)"); - retry_count++; - continue; - } - _E("Read fail for str length"); - result = -1; - break; - - } - break; - } - if (retry_count == RETRY_READ_COUNT) - _E("Read retry failed"); - - close(client_sockfd); - return result; -} - -API int deviced_call_predef_action(const char *type, int num, ...) -{ - struct sysnoti *msg; - int ret; - va_list argptr; - int i; - char *args = NULL; - - if (type == NULL || num > SYSTEM_NOTI_MAXARG) { - errno = EINVAL; - return -1; - } - - msg = malloc(sizeof(struct sysnoti)); - - if (msg == NULL) { - /* Do something for not enought memory error */ - return -1; - } - - msg->pid = getpid(); - msg->cmd = CALL_deviced_ACTION; - msg->type = (char *)type; - msg->path = NULL; - - msg->argc = num; - va_start(argptr, num); - for (i = 0; i < num; i++) { - args = va_arg(argptr, char *); - msg->argv[i] = args; - } - va_end(argptr); - - ret = noti_send(msg); - free(msg); - - return ret; -} - static int dbus_proc_handler(char* type, char *buf) { GVariant *msg; diff --git a/src/shared/deviced-priv.h b/src/shared/deviced-priv.h old mode 100644 new mode 100755 index 0adb00f..8cb6cf9 --- a/src/shared/deviced-priv.h +++ b/src/shared/deviced-priv.h @@ -26,19 +26,8 @@ extern "C" { #endif -#define SYSTEM_NOTI_MAXARG 16 -#define SYSTEM_NOTI_MAXSTR 255 #define BUFF_MAX 255 -struct sysnoti { - int pid; - int cmd; - char *type; - char *path; - int argc; - char *argv[SYSTEM_NOTI_MAXARG]; -}; - int util_launch_app_cmd(const char *cmdline); #ifdef __cplusplus diff --git a/systemd/deviced.socket b/systemd/deviced.socket deleted file mode 100644 index aa36429..0000000 --- a/systemd/deviced.socket +++ /dev/null @@ -1,10 +0,0 @@ -[Unit] -Description=System server socket - -[Socket] -ListenStream=/tmp/sn -SocketMode=0777 -PassCredentials=yes -SmackLabelIPIn=* -SmackLabelIPOut=@ -Accept=false -- 2.7.4 From 30ca3f2efd1154db78d5a13f9555ea51110f98f2 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Fri, 16 Mar 2018 17:30:49 +0900 Subject: [PATCH 06/16] Change a string from ShutDownAction to ShutdownAction Change-Id: I60d63a373c54b4d803580495d4e5011655dfec26 Signed-off-by: lokilee73 --- src/thermal/thermal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) mode change 100644 => 100755 src/thermal/thermal.c diff --git a/src/thermal/thermal.c b/src/thermal/thermal.c old mode 100644 new mode 100755 index a29b965..d1b99e2 --- a/src/thermal/thermal.c +++ b/src/thermal/thermal.c @@ -39,7 +39,7 @@ static int noti; #define RELEASE_ACTION "ReleaseAction" #define WARNING_ACTION "WarningAction" #define LIMIT_ACTION "LimitAction" -#define SHUTDOWN_ACTION "ShutDownAction" +#define SHUTDOWN_ACTION "ShutdownAction" /* Dbus Interfaces (THERMAL_PATH, THERMAL_INTERFACE, and THERMAL_METHOD_TEMP_CHANGED) and Action Type Strings (RELEASE_ACTION, WARNING_ACTION, etc.) -- 2.7.4 From 77d6ca00bbfc62b3398531eabfa492fc815b0743 Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Mon, 19 Mar 2018 16:45:59 +0900 Subject: [PATCH 07/16] Add umount_partition_by_kill() For better filesystem reliability, this api is used to umount writable partitions (/opt/usr, /opt, and etc.) by killing processes with open files 1) lazy-umount partitions MNT_DETACH (since Linux 2.4.11) Perform a lazy unmount: make the mount point unavailable for new accesses, and actually perform the unmount when the mount point ceases to be busy. 2) kill processes (SIGTERM and SIGKILL) Restarted processes cannot open files from the detached partition. So, the number of processes that have opened files on the partition is solely reduced. 3) check # of remaining processes and repeat 2)~3) a fixed number of times. Change-Id: I5d93de15b58e31715ec058f2ce154a03808da6e3 Signed-off-by: Hyotaek Shim --- src/core/common.c | 114 +++++++++++++++++++++++++++++++--------------- src/core/common.h | 6 +-- src/power/power-handler.c | 19 ++++---- 3 files changed, 90 insertions(+), 49 deletions(-) diff --git a/src/core/common.c b/src/core/common.c index 6e5a192..1adb267 100644 --- a/src/core/common.c +++ b/src/core/common.c @@ -16,7 +16,7 @@ * limitations under the License. */ - +#define _GNU_SOURCE #include #include #include @@ -343,7 +343,7 @@ int sys_set_str(char *fname, char *val) return r; } -int terminate_process(const char *partition, bool force) +static int terminate_processes_on_partition(const char *partition, bool force) { const char *argv[7] = {"/usr/bin/fuser", "-m", "-k", "-s", NULL, NULL, NULL}; int argc; @@ -352,8 +352,10 @@ int terminate_process(const char *partition, bool force) argv[4] = "-SIGKILL"; else argv[4] = "-SIGTERM"; + argv[5] = partition; argc = sizeof(argv) / sizeof(argv[0]); + return run_child(argc, argv); } @@ -383,44 +385,82 @@ int mount_check(const char *path) return ret; } -int umount_partition(const char *path, const bool force) +static int get_num_processes_on_partition(const char *part_path) { - int retry = 0, ret = -1; - struct timespec time = {0,}; - - sync(); - while (ret && retry < 2) { - switch (retry++) { - case 0: - /* Second, kill app with SIGTERM */ - _I("Kill app with SIGTERM"); - terminate_process(path, false); - time.tv_nsec = 500 * NANO_SECOND_MULTIPLIER; - nanosleep(&time, NULL); - ret = umount2(path, 0); - break; - case 1: - /* Last time, kill app with SIGKILL */ - _I("Kill app with SIGKILL"); - terminate_process(path, true); - time.tv_nsec = 200 * NANO_SECOND_MULTIPLIER; - nanosleep(&time, NULL); - ret = umount2(path, 0); - break; - } - _I("ret %d retry %d", ret, retry); + FILE *fp; + char *cmd = NULL; + char *line = NULL; + size_t len = 0; + int num_processes = 0; + + asprintf(&cmd, "fuser -m %s | grep -o '[0-9]*'", part_path); + printf("cmd=%s\n", cmd); + fp = popen(cmd, "r"); + free(cmd); + if (fp == NULL) + return -1; + + while (getline(&line, &len, fp) != -1) { + num_processes++; } - if (ret) { - if (force) - ret = umount2(path, MNT_DETACH); - else - ret = umount2(path, 0); + + free(line); + pclose(fp); + + return num_processes; +} + +void umount_partition_by_kill(const char *path, const int max_retry) +{ + FILE *fp; + char *part_path = NULL; + size_t len = 0; + int ret = 0, retry = 0; + int remain; + char *cmd = NULL; + + /* if the path is not a mountpoint, do not perform umounting and killing */ + if (!mount_check(path)) + return; + + ret = asprintf(&cmd, "mount | grep \" on %s \" | awk '{print $1}'", path); + if (ret == -1) + return; + + fp = popen(cmd, "r"); + free(cmd); + if (!fp) + return; + + ret = getline(&part_path, &len, fp); + if (ret == -1 || !part_path) { + pclose(fp); + return; + } else if (ret > 0 && *(part_path + ret - 1) == '\n') { + *(part_path + ret -1) = '\0'; } - if (ret) - _I("Failed to unmount %s", path); - else - _I("%s unmounted successfully", path); - return ret; + + umount2(path, MNT_DETACH); + + do { + sync(); + + /* Kill processes with SIGTERM */ + terminate_processes_on_partition(part_path, false); + usleep((useconds_t)MSEC_TO_USEC(500)); + + /* Kill processes with SIGKILL */ + terminate_processes_on_partition(part_path, true); + usleep((useconds_t)MSEC_TO_USEC(200)); + + remain = get_num_processes_on_partition(part_path); + + retry++; + + } while (remain > 0 && retry < max_retry); + + pclose(fp); + return; } void print_time(const char *prefix) diff --git a/src/core/common.h b/src/core/common.h index 372f73e..cf86002 100644 --- a/src/core/common.h +++ b/src/core/common.h @@ -102,10 +102,8 @@ #define USEC_TO_MSEC(x) ((double)x/1000) #endif -#define DATA_VALUE_INT(x) (*(int *)(x)) -#define DATA_VALUE_BOOL(x) (*(bool *)(x)) - -#define NANO_SECOND_MULTIPLIER 1000000 /* 1ms = 1,000,000 nsec */ +#define DATA_VALUE_INT(x) (*(int *)(x)) +#define DATA_VALUE_BOOL(x) (*(bool *)(x)) #ifndef safe_free #define safe_free(x) safe_free_memory((void**)&(x)) diff --git a/src/power/power-handler.c b/src/power/power-handler.c index 02b350a..e7e0181 100755 --- a/src/power/power-handler.c +++ b/src/power/power-handler.c @@ -57,17 +57,19 @@ #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 POWEROFF_WAIT_RESOURCED (0.5*1000) /* 0.5 seconds */ +#define POWEROFF_WAIT_MAX 10 /* 10 seconds */ -#define SIGNAL_POWEROFF_STATE "ChangeState" +#define SIGNAL_POWEROFF_STATE "ChangeState" -#define UMOUNT_RW_PATH "/opt/usr" +#define UMOUNT_RW_PATH_USER "/opt/usr" +#define UMOUNT_RW_PATH_SYSTEM "/opt" +#define MAX_UMOUNT_KILL_RETRY 4 -#define POWER_FLAG_POWEROFF "/run/"POWER_POWEROFF -#define POWER_FLAG_REBOOT "/run/"POWER_REBOOT +#define POWER_FLAG_POWEROFF "/run/"POWER_POWEROFF +#define POWER_FLAG_REBOOT "/run/"POWER_REBOOT -#define POWER_CONF_FILE "/etc/deviced/power.conf" +#define POWER_CONF_FILE "/etc/deviced/power.conf" struct power_flag { enum poweroff_type type; @@ -193,7 +195,8 @@ static void stop_systemd_service(void) /* umount usr data partition */ static void unmount_rw_partition(void) { - umount_partition(UMOUNT_RW_PATH, true); + umount_partition_by_kill(UMOUNT_RW_PATH_USER, MAX_UMOUNT_KILL_RETRY); + umount_partition_by_kill(UMOUNT_RW_PATH_SYSTEM, MAX_UMOUNT_KILL_RETRY); } static void powerdown(void) -- 2.7.4 From e86573b28f9bd38ec4e001d5cf70e094199b13db Mon Sep 17 00:00:00 2001 From: "sanghyeok.oh" Date: Wed, 21 Mar 2018 22:23:49 +0900 Subject: [PATCH 08/16] prevent: fix prevent issue Change-Id: Iadce5347e6dba92599ff42cabb57b082b46ad1d2 Signed-off-by: sanghyeok.oh --- plugins/display/state-tv.c | 2 +- src/display/display-dbus.c | 4 +++- src/display/input.c | 4 +--- src/libdeviced/usbhost.c | 2 +- src/power/power-handler.c | 5 +++++ src/usb/usb-state.c | 7 +++++-- src/usbhost/usb-host.c | 3 +++ 7 files changed, 19 insertions(+), 8 deletions(-) diff --git a/plugins/display/state-tv.c b/plugins/display/state-tv.c index cdcff8a..8c0d7f3 100644 --- a/plugins/display/state-tv.c +++ b/plugins/display/state-tv.c @@ -156,7 +156,7 @@ static int lcdon_action(int timeout) pm_cur_state != S_SLEEP) set_setting_pmstate(pm_cur_state); - if (pm_old_state != S_LCDOFF || + if (pm_old_state != S_LCDOFF && pm_old_state != S_SLEEP) { _I("pm_old_state (%s). Skip lcd on", states[pm_old_state].name); return 0; diff --git a/src/display/display-dbus.c b/src/display/display-dbus.c index 18c26d0..f733931 100644 --- a/src/display/display-dbus.c +++ b/src/display/display-dbus.c @@ -860,7 +860,7 @@ GVariant *dbus_locktimeout_expired(GDBusConnection *conn, pid_t pid; char pid_str[16]; char comm[NAME_MAX]; - struct pmlock_expired_s *ex; + struct pmlock_expired_s *ex = NULL; GVariant *gvar = NULL; CHECK_POWEROFF(); @@ -915,6 +915,8 @@ GVariant *dbus_locktimeout_expired(GDBusConnection *conn, out: gvar = g_variant_new("(si)", req_id, ret); g_free(req_id); + if (ex) + free(ex); return gvar; } diff --git a/src/display/input.c b/src/display/input.c index 6ef5c78..95714ac 100644 --- a/src/display/input.c +++ b/src/display/input.c @@ -90,9 +90,7 @@ static inline void process_event(struct libinput_event *ev) input.type = EV_REL; fd = libinput_get_fd(li); - _D("time %d.%d type %d code %d value %d fd %d", - input.time.tv_sec, input.time.tv_usec, input.type, - input.code, input.value, fd); + _D("type %d fd %d", input.type, fd); if (CHECK_OPS(keyfilter_ops, check) && keyfilter_ops->check(&input, fd) != 0) diff --git a/src/libdeviced/usbhost.c b/src/libdeviced/usbhost.c index f3d107f..2f9ece5 100644 --- a/src/libdeviced/usbhost.c +++ b/src/libdeviced/usbhost.c @@ -133,7 +133,7 @@ static void device_signal_handler(GDBusConnection *conn, &device.product, &device.serial); - strncpy(device.devpath, syspath, PATH_MAX); + strncpy(device.devpath, syspath, PATH_MAX - 1); DD_LIST_FOREACH(handlers, element, handler) { if (strcmp(handler->name, SIGNAL_NAME_USB_DEVICE_CHANGED)) diff --git a/src/power/power-handler.c b/src/power/power-handler.c index e7e0181..2e7d7b9 100755 --- a/src/power/power-handler.c +++ b/src/power/power-handler.c @@ -383,6 +383,11 @@ int check_power_flag(void) if (fd >= 0) { len = read(fd, buf, sizeof(buf) - 1); close(fd); + if (len < 0) { + len = errno; + _E("read() failed (%d)", len); + return 0; + } while (len > 0 && buf[len - 1] == '\n') len--; buf[len] = '\0'; diff --git a/src/usb/usb-state.c b/src/usb/usb-state.c index 043340c..f87da53 100644 --- a/src/usb/usb-state.c +++ b/src/usb/usb-state.c @@ -191,8 +191,11 @@ void usb_state_update_state(usb_connection_state_e state, unsigned int mode) if (mode == USB_FUNCTION_NONE) { if (noti_id >= 0) { - remove_notification("MediaDeviceNotiOff", noti_id); - noti_id = -1; + int ret = remove_notification("MediaDeviceNotiOff", noti_id); + if (ret < 0) + _E("Failed to remove event_noti : %d", ret); + else + noti_id = -1; } } else if (mode & USB_FUNCTION_MTP) { if (noti_id < 0) diff --git a/src/usbhost/usb-host.c b/src/usbhost/usb-host.c index 06d08c2..5c6f08f 100644 --- a/src/usbhost/usb-host.c +++ b/src/usbhost/usb-host.c @@ -650,6 +650,7 @@ static int read_policy(void) entry->creds.sec_label = calloc(ENTRY_LINE_SIZE, 1); if (!entry->creds.sec_label) { _E("No memory: %m"); + free(entry); goto out; } @@ -675,6 +676,8 @@ static int read_policy(void) if (entry->value < 0) { _E("Invalid policy value: %s", value_str); ret = -EINVAL; + free(entry->creds.sec_label); + free(entry); goto out; } -- 2.7.4 From 887a81e0ca389f0c743c513baf66a3abde187f09 Mon Sep 17 00:00:00 2001 From: lokilee73 Date: Thu, 22 Mar 2018 16:32:02 +0900 Subject: [PATCH 09/16] Remove OOMADJ item in auto test OOMADJ function was moved to resourced. So, it should be removed in deviced. Change-Id: I89b05e064c70f58b5e8680b8fea55fc48786f4a2 Signed-off-by: lokilee73 --- src/auto-test/proc.c | 52 ----------------------------------------------- src/core/common.c | 8 ++++++-- src/power/power-handler.c | 1 + 3 files changed, 7 insertions(+), 54 deletions(-) mode change 100644 => 100755 src/auto-test/proc.c mode change 100644 => 100755 src/core/common.c diff --git a/src/auto-test/proc.c b/src/auto-test/proc.c old mode 100644 new mode 100755 index f4b9b5b..532c4a1 --- a/src/auto-test/proc.c +++ b/src/auto-test/proc.c @@ -17,56 +17,9 @@ */ #include "test.h" -#define METHOD_PROC_OOMADJ_SET "oomadj_set" - #define METHOD_SYSNOTI_GETREVISION "GetRevision" -static bool set_proc_method(const char *method, GVariant *param) -{ - GVariant *msg; - int val; - bool ret = FALSE; - - msg = dbus_handle_method_sync_with_reply_var(DEVICED_BUS_NAME, - DEVICED_PATH_PROCESS, - DEVICED_INTERFACE_PROCESS, - method, - param); - if (!msg) { - _E("fail (%s): no reply", method); - return ret; - } - - if (!dh_get_param_from_var(msg, "(i)", &val)) - _E("fail (%s): no message", method); - else { - if ((val == -ENOTSUP) || (val == -ENOSYS)) { - _I("Not supported feature! (%s): %d", method, val); - ret = TRUE; - } else if (val < 0) { - _E("fail (%s): returned fail (%d)", method, val); - } else { - _I("success (%s): %d", method, val); - ret = TRUE; - } - } - - g_variant_unref(msg); - return ret; -} - -static bool set_proc_oomadj(char *type, int argc, int pid, int score_adj) -{ - char str_pid[10]; - char str_score_adj[10]; - - snprintf(str_pid, sizeof(str_pid) - 1, "%d", pid); - snprintf(str_score_adj, sizeof(str_score_adj) - 1, "%d", score_adj); - - return set_proc_method(METHOD_PROC_OOMADJ_SET, g_variant_new("(siss)", type, argc, str_pid, str_score_adj)); -} - static bool get_sysnoti_revision() { GVariant *msg; @@ -105,9 +58,6 @@ void proc_test_all(int *success, int *fail) int s = 0; int f = 0; - (set_proc_oomadj("oomadj_set", 2, getpid(), 300)) ? s++ : f++; - (set_proc_oomadj("oomadj_set", 2, getpid(), 100)) ? s++ : f++; - (get_sysnoti_revision()) ? s++ : f++; if (NULL != success) *success = s; @@ -140,8 +90,6 @@ static int proc_unit(int argc, char **argv) _I("start test"); proc_test_all(&success, &fail); _I("Total: %d, Success: %d, Fail: %d", success+fail, success, fail); - } else if (0 == strcmp(argv[3], METHOD_PROC_OOMADJ_SET)) { - set_proc_oomadj(argv[4], atoi(argv[5]), atoi(argv[6]), atoi(argv[7])); } else if (0 == strcmp(argv[3], METHOD_SYSNOTI_GETREVISION)) { get_sysnoti_revision(); } else { diff --git a/src/core/common.c b/src/core/common.c old mode 100644 new mode 100755 index 1adb267..04ec6ac --- a/src/core/common.c +++ b/src/core/common.c @@ -392,8 +392,12 @@ static int get_num_processes_on_partition(const char *part_path) char *line = NULL; size_t len = 0; int num_processes = 0; + int ret = 0; + + ret = asprintf(&cmd, "fuser -m %s | grep -o '[0-9]*'", part_path); + if (ret < 0) + return -1; - asprintf(&cmd, "fuser -m %s | grep -o '[0-9]*'", part_path); printf("cmd=%s\n", cmd); fp = popen(cmd, "r"); free(cmd); @@ -424,7 +428,7 @@ void umount_partition_by_kill(const char *path, const int max_retry) return; ret = asprintf(&cmd, "mount | grep \" on %s \" | awk '{print $1}'", path); - if (ret == -1) + if (ret < 0) return; fp = popen(cmd, "r"); diff --git a/src/power/power-handler.c b/src/power/power-handler.c index 2e7d7b9..8365070 100755 --- a/src/power/power-handler.c +++ b/src/power/power-handler.c @@ -86,6 +86,7 @@ static struct power_option poweroff_opt; static bool during_poweroff; static dd_list *poweroff_handles; +extern void umount_partition_by_kill(const char *path, const int max_retry); static int get_poweroff_type_enum(char *type, enum poweroff_type *val) { size_t len; -- 2.7.4 From 03399522d3b434f410c701d5ccbe19ce22e5f355 Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Thu, 22 Mar 2018 16:49:50 +0900 Subject: [PATCH 10/16] Removed BuildRequires: pkgconfig(argos_watchdog) Change-Id: I5eb0781aaa8a09039d37f6c8264315a891b050d0 Signed-off-by: Hyotaek Shim --- CMakeLists.txt | 1 - packaging/deviced.spec | 1 - src/core/main.c | 10 +--------- systemd/deviced.service | 1 + 4 files changed, 2 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8d5cb32..9d15cb9 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -170,7 +170,6 @@ SET(PKG_MODULES hwcommon mount capi-system-info - argos_watchdog libsystemd ) diff --git a/packaging/deviced.spec b/packaging/deviced.spec index b5a3b0b..3d66f2f 100755 --- a/packaging/deviced.spec +++ b/packaging/deviced.spec @@ -28,7 +28,6 @@ BuildRequires: pkgconfig(eventsystem) BuildRequires: pkgconfig(libtzplatform-config) BuildRequires: pkgconfig(hwcommon) BuildRequires: pkgconfig(capi-system-info) -BuildRequires: pkgconfig(argos_watchdog) BuildRequires: pkgconfig(libsystemd) BuildRequires: pkgconfig(libinput) BuildRequires: pkgconfig(capi-system-sensor) diff --git a/src/core/main.c b/src/core/main.c index 55b7011..a664c32 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -20,7 +20,6 @@ #include #include #include -#include #include #include @@ -63,9 +62,7 @@ static void sig_usr1(int signo) void watchdog_notify(void) { - int ret = aw_notify(); - if (ret < 0) - _E("aw_notify failed(%d)", ret); + sd_notify(0, "WATCHDOG=1"); } static void deviced_dbus_name_acquired(GDBusConnection *connection, const gchar *name, gpointer user_data) @@ -107,11 +104,6 @@ static int deviced_main(int argc, char **argv) signal(SIGUSR1, sig_usr1); timer = g_timeout_add_seconds_full(G_PRIORITY_HIGH, WATCHDOG_TIMEOUT, watchdog_cb, NULL, NULL); - if (timer) { - ret = aw_register(WATCHDOG_TIMEOUT * 2); - if (ret < 0) - _E("aw_register failed"); - } /* g_main_loop */ g_main_loop_run(mainloop); diff --git a/systemd/deviced.service b/systemd/deviced.service index f3b48b9..9396821 100644 --- a/systemd/deviced.service +++ b/systemd/deviced.service @@ -9,6 +9,7 @@ Restart=always RestartSec=0 KillSignal=SIGUSR1 NotifyAccess=main +WatchdogSec=30s [Install] WantedBy=multi-user.target -- 2.7.4 From 19f28633e69ec61b9bd32d904b89f0b5a6f48aee Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Thu, 22 Mar 2018 16:56:33 +0900 Subject: [PATCH 11/16] To prevent Watchdog Kill during the dbus sync call Change-Id: I91b9b66ff089b638fa649ba695bd4806639cb84d Signed-off-by: Hyotaek Shim --- src/display/dpms-wayland-none.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/display/dpms-wayland-none.c b/src/display/dpms-wayland-none.c index eecf7a6..8af4ac8 100644 --- a/src/display/dpms-wayland-none.c +++ b/src/display/dpms-wayland-none.c @@ -87,6 +87,8 @@ int dpms_get_power(enum dpms_state *state) if (!state) return -EINVAL; + watchdog_notify(); + ret = dbus_handle_method_sync(ENLIGHTENMENT_BUS_NAME, ENLIGHTENMENT_OBJECT_PATH, ENLIGHTENMENT_INTERFACE_NAME, -- 2.7.4 From ec0c448eb40bdd81953a6541e7c6c0106b81699d Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Wed, 21 Mar 2018 18:51:58 +0900 Subject: [PATCH 12/16] libgdbus: Move common gdbus interfaces to libsystem package Change-Id: I3afd64a2f7603e5e63c0db1b0c46bc661f6f8b0a Signed-off-by: pr.jung --- CMakeLists.txt | 1 + packaging/deviced.spec | 1 + src/apps/apps.c | 1 - src/apps/apps.h | 4 +- src/auto-test/CMakeLists.txt | 1 - src/auto-test/test.h | 2 +- src/battery/battery-time.c | 2 +- src/battery/lowbat-handler.c | 2 +- src/control/control.c | 2 +- src/core/devices.c | 2 +- src/core/edbus-handler.c | 1 - src/core/edbus-handler.h | 1 - src/core/event-handler.c | 2 +- src/core/main.c | 2 +- src/core/udev.c | 2 +- src/cpu/pmqos-plugin.c | 2 +- src/cpu/pmqos.c | 2 +- src/devicectl/devicectl.c | 2 +- src/display/ambient-mode.c | 2 +- src/display/core.c | 2 +- src/display/display-dbus.c | 6 +- src/display/dpms-wayland-none.c | 2 +- src/display/key-filter.c | 2 +- src/display/poll.h | 2 +- src/extcon/cradle.c | 2 +- src/extcon/extcon.c | 2 +- src/extcon/hdmi.c | 2 +- src/ir/ir.c | 2 +- src/led/noti.c | 2 +- src/led/rgb.c | 2 +- src/led/torch.c | 2 +- src/led/touch-key.c | 2 +- src/libdeviced/CMakeLists.txt | 2 +- src/libdeviced/dbus.c | 1046 --------------- src/libdeviced/deviced-noti.c | 2 +- src/libdeviced/display.c | 2 +- src/libdeviced/haptic.c | 4 +- src/libdeviced/led.c | 2 +- src/libdeviced/mmc.c | 26 +- src/libdeviced/usbhost.c | 2 +- src/power/boot.c | 2 +- src/power/low-power.c | 3 +- src/power/power-handler.c | 2 +- src/proc/cpu-info.c | 2 +- src/shared/CMakeLists.txt | 1 - src/shared/dbus.c | 2684 ------------------------------------- src/shared/dbus.h | 462 ------- src/shared/deviced-systemd.c | 2 +- src/time/time-handler.c | 2 +- src/tzip/tzip.c | 2 +- src/usb-host-test/usb-host-test.c | 2 +- src/usb/usb-dbus.c | 3 +- src/usbhost/usb-host.c | 3 +- 53 files changed, 61 insertions(+), 4259 deletions(-) delete mode 100644 src/libdeviced/dbus.c delete mode 100644 src/shared/dbus.c delete mode 100644 src/shared/dbus.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 9d15cb9..f1a67f3 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -171,6 +171,7 @@ SET(PKG_MODULES mount capi-system-info libsystemd + libgdbus ) IF(DISPLAY_MODULE STREQUAL on) diff --git a/packaging/deviced.spec b/packaging/deviced.spec index 3d66f2f..8c68f05 100755 --- a/packaging/deviced.spec +++ b/packaging/deviced.spec @@ -35,6 +35,7 @@ BuildRequires: pkgconfig(fuse) BuildRequires: pkgconfig(minizip) BuildRequires: pkgconfig(libkmod) BuildRequires: pkgconfig(libusbgx) +BuildRequires: pkgconfig(libgdbus) Requires: %{name}-tools = %{version}-%{release} %{?systemd_requires} diff --git a/src/apps/apps.c b/src/apps/apps.c index 14342f9..b49b291 100644 --- a/src/apps/apps.c +++ b/src/apps/apps.c @@ -20,7 +20,6 @@ #include "core/log.h" #include "core/common.h" #include "apps.h" -#include "shared/dbus.h" #define POPUP_METHOD "PopupLaunch" #define BUFF_MAX 255 diff --git a/src/apps/apps.h b/src/apps/apps.h index edbc3b8..24d9214 100644 --- a/src/apps/apps.h +++ b/src/apps/apps.h @@ -19,8 +19,8 @@ #ifndef __APPS_H__ #define __APPS_H__ - -#include "shared/dbus.h" +#include +#include #include "core/common.h" #include "display/poll.h" diff --git a/src/auto-test/CMakeLists.txt b/src/auto-test/CMakeLists.txt index f7db8ea..185958c 100644 --- a/src/auto-test/CMakeLists.txt +++ b/src/auto-test/CMakeLists.txt @@ -13,7 +13,6 @@ SET(SRCS result.c ../core/config-parser.c config.c - ../shared/dbus.c battery.c display.c led.c diff --git a/src/auto-test/test.h b/src/auto-test/test.h index a5bb1d6..d755d3a 100644 --- a/src/auto-test/test.h +++ b/src/auto-test/test.h @@ -23,11 +23,11 @@ #include #include #include +#include #include "core/list.h" #include "core/common.h" #include "core/udev.h" -#include "shared/dbus.h" #ifdef ENABLE_TEST_DLOG #define ENABLE_DLOG diff --git a/src/battery/battery-time.c b/src/battery/battery-time.c index 092c99d..989ad37 100644 --- a/src/battery/battery-time.c +++ b/src/battery/battery-time.c @@ -23,12 +23,12 @@ #include #include #include +#include #include "core/common.h" #include "core/devices.h" #include "core/log.h" #include "core/udev.h" -#include "shared/dbus.h" #include "display/setting.h" #include "power-supply.h" diff --git a/src/battery/lowbat-handler.c b/src/battery/lowbat-handler.c index 6163e9d..be1ab4c 100755 --- a/src/battery/lowbat-handler.c +++ b/src/battery/lowbat-handler.c @@ -25,6 +25,7 @@ #include #include #include +#include #include "lowbat-handler.h" #include "battery.h" @@ -39,7 +40,6 @@ #include "device-node.h" #include "display/setting.h" #include "display/poll.h" -#include "shared/dbus.h" #include "power/power-handler.h" #include "apps/apps.h" #include "power-supply.h" diff --git a/src/control/control.c b/src/control/control.c index cb60336..7ce5662 100644 --- a/src/control/control.c +++ b/src/control/control.c @@ -22,11 +22,11 @@ #include #include #include +#include #include "core/log.h" #include "core/common.h" #include "core/devices.h" -#include "shared/dbus.h" #include "extcon/extcon.h" #define CONTROL_HANDLER_NAME "control" diff --git a/src/core/devices.c b/src/core/devices.c index e91c7ff..9578c2f 100644 --- a/src/core/devices.c +++ b/src/core/devices.c @@ -18,12 +18,12 @@ #include +#include #include "log.h" #include "list.h" #include "common.h" #include "devices.h" -#include "shared/dbus.h" static const struct device_ops default_ops = { .name = "default-ops", diff --git a/src/core/edbus-handler.c b/src/core/edbus-handler.c index bc0241a..ddc5944 100644 --- a/src/core/edbus-handler.c +++ b/src/core/edbus-handler.c @@ -20,7 +20,6 @@ #include #include "core/log.h" -#include "core/edbus-handler.h" #include "core/common.h" #include "core/device-idler.h" #include "core/device-notifier.h" diff --git a/src/core/edbus-handler.h b/src/core/edbus-handler.h index e6ccd0c..9dfa21b 100644 --- a/src/core/edbus-handler.h +++ b/src/core/edbus-handler.h @@ -23,7 +23,6 @@ #include #include #include -#include "shared/dbus.h" struct edbus_method { const char *member; diff --git a/src/core/event-handler.c b/src/core/event-handler.c index 6608710..f8bb1ec 100644 --- a/src/core/event-handler.c +++ b/src/core/event-handler.c @@ -19,11 +19,11 @@ #include #include +#include #include "common.h" #include "devices.h" #include "device-notifier.h" -#include "shared/dbus.h" #include "log.h" static device_notifier_state_e state = DEVICE_NOTIFIER_STATE_STOP; diff --git a/src/core/main.c b/src/core/main.c index a664c32..5b5acf2 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -22,12 +22,12 @@ #include #include #include +#include #include "display/core.h" #include "log.h" #include "common.h" #include "devices.h" -#include "shared/dbus.h" #include "power/boot.h" #include "power/power-handler.h" #include "device-notifier.h" diff --git a/src/core/udev.c b/src/core/udev.c index fae5fdb..07ac8e1 100644 --- a/src/core/udev.c +++ b/src/core/udev.c @@ -20,13 +20,13 @@ #include #include #include +#include #include "log.h" #include "device-notifier.h" #include "devices.h" #include "udev.h" #include "list.h" -#include "shared/dbus.h" #define KERNEL "kernel" #define UDEV "udev" diff --git a/src/cpu/pmqos-plugin.c b/src/cpu/pmqos-plugin.c index dda17b3..775fa79 100644 --- a/src/cpu/pmqos-plugin.c +++ b/src/cpu/pmqos-plugin.c @@ -22,9 +22,9 @@ #include #include #include +#include #include "core/log.h" -#include "shared/dbus.h" #include "core/config-parser.h" #include "pmqos.h" diff --git a/src/cpu/pmqos.c b/src/cpu/pmqos.c index b63ece6..66f12df 100644 --- a/src/cpu/pmqos.c +++ b/src/cpu/pmqos.c @@ -24,9 +24,9 @@ #include #include #include +#include #include "core/log.h" -#include "shared/dbus.h" #include "core/devices.h" #include "core/common.h" #include "core/list.h" diff --git a/src/devicectl/devicectl.c b/src/devicectl/devicectl.c index 637645a..50b251a 100644 --- a/src/devicectl/devicectl.c +++ b/src/devicectl/devicectl.c @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include #include "usb.h" diff --git a/src/display/ambient-mode.c b/src/display/ambient-mode.c index 776130d..a275500 100644 --- a/src/display/ambient-mode.c +++ b/src/display/ambient-mode.c @@ -19,11 +19,11 @@ #include #include +#include #include "util.h" #include "core.h" #include "display-ops.h" -#include "shared/dbus.h" #include "core/device-notifier.h" #include "core/devices.h" diff --git a/src/display/core.c b/src/display/core.c index adf8aa4..44f550e 100755 --- a/src/display/core.c +++ b/src/display/core.c @@ -38,6 +38,7 @@ #include #include #include +#include #include "ambient-mode.h" #include "util.h" @@ -50,7 +51,6 @@ #include "core/udev.h" #include "core/list.h" #include "core/common.h" -#include "shared/dbus.h" #include "shared/plugin.h" #include "core/config-parser.h" #include "core/launch.h" diff --git a/src/display/display-dbus.c b/src/display/display-dbus.c index f733931..3e374cf 100644 --- a/src/display/display-dbus.c +++ b/src/display/display-dbus.c @@ -28,6 +28,7 @@ #include #include #include +#include #include "ambient-mode.h" #include "core/log.h" @@ -40,7 +41,6 @@ #include "dd-display.h" #include "display-actor.h" #include "display-ops.h" -#include "shared/dbus.h" #define SIGNAL_HOMESCREEN "HomeScreen" @@ -596,7 +596,7 @@ GVariant *dbus_setautobrightnessmin(GDBusConnection *conn, goto error; } if (display_info.reset_autobrightness_min) { - id = dbus_handle_watch_name(sender, display_info.reset_autobrightness_min, NULL, NULL); + id = dbus_handle_watch_name(sender, display_info.reset_autobrightness_min, NULL, NULL, NULL); if (id <= 0) { _E("failed to watch name %s, id %d", sender, id); //todo: set return value @@ -624,7 +624,7 @@ GVariant *dbus_setlcdtimeout(GDBusConnection *conn, if (ret) { _W("fail to set lcd timeout %d by %d", ret, pid); } else { - id = dbus_handle_watch_name(sender, reset_lcd_timeout, NULL, NULL); + id = dbus_handle_watch_name(sender, reset_lcd_timeout, NULL, NULL, NULL); if (id <= 0) { _E("failed to watch name %s, id %d", sender, id); //todo: set return value diff --git a/src/display/dpms-wayland-none.c b/src/display/dpms-wayland-none.c index 8af4ac8..3766df5 100644 --- a/src/display/dpms-wayland-none.c +++ b/src/display/dpms-wayland-none.c @@ -17,8 +17,8 @@ */ #include +#include -#include "shared/dbus.h" #include "device-interface.h" #include "util.h" #include "core.h" diff --git a/src/display/key-filter.c b/src/display/key-filter.c index 4128a3f..98904b6 100644 --- a/src/display/key-filter.c +++ b/src/display/key-filter.c @@ -24,6 +24,7 @@ #include #include #include +#include #include "ambient-mode.h" #include "util.h" @@ -34,7 +35,6 @@ #include "core/common.h" #include "core/devices.h" #include "core/device-notifier.h" -#include "shared/dbus.h" #include "power/power-handler.h" #include "led/touch-key.h" diff --git a/src/display/poll.h b/src/display/poll.h index 8a830a9..a3e12a8 100644 --- a/src/display/poll.h +++ b/src/display/poll.h @@ -27,7 +27,7 @@ #define __PM_POLL_H__ -#include "shared/dbus.h" +#include /** * @addtogroup POWER_MANAGER * @{ diff --git a/src/extcon/cradle.c b/src/extcon/cradle.c index e1007ae..26780e1 100644 --- a/src/extcon/cradle.c +++ b/src/extcon/cradle.c @@ -19,10 +19,10 @@ #include #include +#include #include "core/log.h" #include "core/device-notifier.h" -#include "shared/dbus.h" #include "core/udev.h" #include "display/core.h" #include "extcon/extcon.h" diff --git a/src/extcon/extcon.c b/src/extcon/extcon.c index d89de01..a54f1d2 100644 --- a/src/extcon/extcon.c +++ b/src/extcon/extcon.c @@ -19,6 +19,7 @@ #include #include +#include #include "core/log.h" #include "core/list.h" @@ -26,7 +27,6 @@ #include "core/devices.h" #include "core/config-parser.h" #include "core/device-notifier.h" -#include "shared/dbus.h" #include "core/udev.h" #include "extcon.h" diff --git a/src/extcon/hdmi.c b/src/extcon/hdmi.c index 9b42fa2..6f80bfc 100644 --- a/src/extcon/hdmi.c +++ b/src/extcon/hdmi.c @@ -18,9 +18,9 @@ #include +#include #include "core/log.h" #include "core/device-notifier.h" -#include "shared/dbus.h" #include "display/core.h" #include "extcon.h" diff --git a/src/ir/ir.c b/src/ir/ir.c index 3b43fd3..4b60777 100644 --- a/src/ir/ir.c +++ b/src/ir/ir.c @@ -19,7 +19,7 @@ #include #include #include -#include "shared/dbus.h" +#include #include "core/devices.h" #include "core/common.h" #include "core/log.h" diff --git a/src/led/noti.c b/src/led/noti.c index ae4ed87..ffc4002 100644 --- a/src/led/noti.c +++ b/src/led/noti.c @@ -19,9 +19,9 @@ #include #include +#include #include "core/log.h" -#include "shared/dbus.h" #define METHOD_TORCH_NOTI_ON "LedTorchNotiOn" #define METHOD_TORCH_NOTI_OFF "LedTorchNotiOff" diff --git a/src/led/rgb.c b/src/led/rgb.c index 4732265..921aab2 100644 --- a/src/led/rgb.c +++ b/src/led/rgb.c @@ -25,11 +25,11 @@ #include #include +#include #include "core/log.h" #include "core/list.h" #include "core/common.h" -#include "shared/dbus.h" #include "core/devices.h" #include "core/device-notifier.h" diff --git a/src/led/torch.c b/src/led/torch.c index 1982cdc..719d673 100644 --- a/src/led/torch.c +++ b/src/led/torch.c @@ -23,9 +23,9 @@ #include #include #include +#include #include "core/log.h" -#include "shared/dbus.h" #include "core/devices.h" #include "torch.h" diff --git a/src/led/touch-key.c b/src/led/touch-key.c index d27d791..c38eb9b 100644 --- a/src/led/touch-key.c +++ b/src/led/touch-key.c @@ -20,9 +20,9 @@ #include #include #include +#include #include "core/log.h" -#include "shared/dbus.h" #include "core/devices.h" #include "core/device-notifier.h" #include "display/core.h" diff --git a/src/libdeviced/CMakeLists.txt b/src/libdeviced/CMakeLists.txt index aaa73e3..5d8ee53 100755 --- a/src/libdeviced/CMakeLists.txt +++ b/src/libdeviced/CMakeLists.txt @@ -3,7 +3,6 @@ PROJECT(libdeviced C) SET(LIBDEVICED_SRCS display.c - dbus.c haptic.c led.c mmc.c @@ -20,6 +19,7 @@ pkg_check_modules(libpkgs REQUIRED dlog glib-2.0 gio-2.0 + libgdbus gio-unix-2.0) FOREACH(flag ${libpkgs_CFLAGS}) diff --git a/src/libdeviced/dbus.c b/src/libdeviced/dbus.c deleted file mode 100644 index 8d68141..0000000 --- a/src/libdeviced/dbus.c +++ /dev/null @@ -1,1046 +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 "common.h" -#include "log.h" -#include "dbus.h" - -/* -1 is a default timeout value, it's converted to 25*1000 internally. */ -#define DBUS_REPLY_TIMEOUT (-1) - -/* basic information */ -typedef struct { - GDBusConnection *conn; - GBusType bus_type; - gboolean priv; - GList *list_names; /* dbus_name */ - GList *list_object; /* dbus_object_handle_s */ - pthread_mutex_t mutex; -} dbus_handle_s; - -/* path + interfaces */ -typedef struct { - dbus_handle_s *dh; /* dbus handle */ - const char *path; /* object path */ - GList *list_ifaces; /* dbus_interface_s */ -} dbus_object_handle_s; -#define get_dh_from_oh(oh) ((dbus_object_handle_s*)oh)->dh - -/* global shared bus : system, session */ -static dbus_handle_s g_dh[2]; - -static dbus_handle_s *_dbus_handle_get_connection(GBusType bus_type); - -static GBusType g_default_bus_type = G_BUS_TYPE_SYSTEM; -pthread_mutex_t g_mutex = PTHREAD_MUTEX_INITIALIZER; - -GBusType dbus_handle_get_default_bus_type(void) -{ - GBusType type; - - pthread_mutex_lock(&g_mutex); - type = g_default_bus_type; - pthread_mutex_unlock(&g_mutex); - - return type; -} - -dbus_handle_s * _dbus_handle_get_default_connection(void) -{ - return _dbus_handle_get_connection(dbus_handle_get_default_bus_type()); -} - -#define dbus_handle_lock(handle) do {\ - assert(handle);\ - pthread_mutex_lock(&((handle)->mutex));\ -} while (0); - -#define dbus_handle_unlock(handle) do {\ - assert(handle);\ - pthread_mutex_unlock(&(handle)->mutex);\ -} while (0); - -#define dcl_dbus_handle() dbus_handle_s *dh = (dbus_handle_s *)handle; -#define dcl_dbus_handle_null_check() dbus_handle_s *dh = (dbus_handle_s *)handle;\ - if (!dh) {\ - _E("dbus handle is null\n");\ - return 0;\ - } - -static GDBusConnection * _get_bus(GBusType bus_type) -{ - GDBusConnection *conn = NULL; - GError *err = NULL; - - if (bus_type != G_BUS_TYPE_SYSTEM && bus_type != G_BUS_TYPE_SESSION) { - _E("Wrong bus_type %d", bus_type); - return NULL; - } - - conn = g_bus_get_sync(bus_type, NULL, &err); - if (!conn || err) { - _E("failed to get bus:type:%d, %s\n", bus_type, err->message); - g_error_free(err); - return NULL; - } - - return conn; -} - -static GDBusConnection * _get_bus_private(GBusType bus_type) -{ - GError *err = NULL; - GDBusConnection *conn = NULL; - const char * address; - - if (bus_type != G_BUS_TYPE_SYSTEM && bus_type != G_BUS_TYPE_SESSION) { - _E("Wrong bus_type %d", bus_type); - return NULL; - } - - address = g_dbus_address_get_for_bus_sync(bus_type, NULL, &err); - if (!address || err) { - _E("failed to get bus address\n"); - g_error_free(err); - return NULL; - } - - conn = g_dbus_connection_new_for_address_sync(address, - (GDBusConnectionFlags) (G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT | - G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION), - NULL, /* GDBusAuthObserver */ - NULL, - &err); - if (!conn || err) { - _E("failed to get private bus\n"); - g_error_free(err); - return NULL; - } - - return conn; -} - -/* ref cout is 1 */ -static dbus_handle_s *_dbus_handle_get_connection(GBusType bus_type) -{ - int ibus = bus_type - 1; - dbus_handle_s *dh = NULL; - - if (bus_type != G_BUS_TYPE_SYSTEM && bus_type != G_BUS_TYPE_SESSION) { - _E("Unknown bus type %d", bus_type); - return NULL; - } - dh = &g_dh[ibus]; - - dbus_handle_lock(dh); - - if (!dh->conn) { - dh->conn = _get_bus(bus_type); - dh->priv = FALSE; - dh->bus_type = bus_type; - if (!dh->conn) - dh = NULL; - } - - dbus_handle_unlock(dh); - - return dh; -} - -/* ref cout is 1 */ -static dbus_handle_s *_dbus_handle_get_connection_private(GBusType bus_type) -{ - dbus_handle_s * dh; - - if (bus_type != G_BUS_TYPE_SYSTEM && bus_type != G_BUS_TYPE_SESSION) { - _E("Unknown bus type %d", bus_type); - return NULL; - } - - dh = (dbus_handle_s *)calloc(1, sizeof(dbus_handle_s)); - if (!dh) { - _E("failed to allocate memory for dbus handle"); - return NULL; - } - - dbus_handle_lock(dh); - - if (!dh->conn) { - dh->conn = _get_bus_private(bus_type); - dh->bus_type = bus_type; - if (!dh->conn) - goto err; - } - - dbus_handle_unlock(dh); - - return dh; -err: - if (dh) { - dbus_handle_unlock(dh); - free(dh); - } - return NULL; -} - - -static void _free_func_signal(gpointer data) -{ - _D("free signal subscribe"); -} - -guint subscribe_dbus_signal(dbus_handle_h handle, const char *path, - const char *iface, const char *name, - GDBusSignalCallback cb, void *data, - destroy_notified free_func) -{ - dcl_dbus_handle(); - - if (!dh) { - dh = _dbus_handle_get_default_connection(); - if (!dh) { - _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); - return 0; - } - } - - if (!dh->conn) { - _E("connection is null. check bus status"); - return 0; - } - return g_dbus_connection_signal_subscribe(dh->conn, NULL, iface, name, path, NULL, G_DBUS_SIGNAL_FLAGS_NONE, cb, data, _free_func_signal); -} - -void unsubscribe_dbus_signal(dbus_handle_h handle, guint id) -{ - dcl_dbus_handle(); - if (!dh) { - dh = _dbus_handle_get_default_connection(); - if (!dh) { - _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); - return ; - } - } - - if (!dh->conn) { - _E("connection is null. check bus status"); - return ; - } - - g_dbus_connection_signal_unsubscribe(dh->conn, id); -} - -int _check_type_string_is_container(const char *signature) -{ - if (!signature) - return FALSE; - - switch (signature[0]) { - case 'a': - case 'm': - case 'r': - case '(': - case '{': - case 'v': - return TRUE; - default: - return FALSE; - } - - return TRUE; -} - -GVariant *dbus_handle_make_simple_array(const char *sig, int *param) -{ - GVariantBuilder *builder = NULL; - GVariant *var = NULL; - char format[256]; - int i = 0; - - builder = g_variant_builder_new(G_VARIANT_TYPE(sig)); - if (!builder) { - _E("failed to g_variant_builder_new"); - return NULL; - } - - while (param[i]) - g_variant_builder_add(builder, "i", param[i++]); - - snprintf(format, sizeof(format) - 1, "(%s)", sig); - var = g_variant_new(format, builder); - g_variant_builder_unref(builder); - return var; -} - -/* todo: looks like garbage... */ -static GVariant* _append_variant(const char *signature, const char *param[]) -{ - char *ch; - int i; - int pi; - int int_type; - gboolean bool_type; - unsigned long long int64_type; - GVariant *ret; - int len; - char container[255];// The maximum length of a signature is 255. - const char *sig = signature; - GVariantBuilder *builder = NULL; - - if (!signature || !param) - return 0; - - /* workaround for user fault "(i) != i" but we treat this as same signature */ - /* G_VARIANT_TYPE("si") return NULL */ - /* todo: actually user have to use correct signature */ - if (!_check_type_string_is_container(signature)) { - snprintf(container, sizeof(container) - 1, "(%s)", signature); - sig = container; - } - if (!g_variant_type_is_container(G_VARIANT_TYPE(sig))) { - _E("signature (%s) is not container type", signature); - } - - builder = g_variant_builder_new(G_VARIANT_TYPE(sig)); - len = strlen(sig); - pi = 0; - for (ch = (char *)sig, i = 0; i < len; ++i, ++ch) { - switch (*ch) { - case '(': - case ')': - continue; - case 'b': - bool_type = (atoi(param[pi++]) == 0 ? FALSE : TRUE); - g_variant_builder_add(builder, "b", bool_type); - break; - case 'i': - int_type = atoi(param[pi++]); - g_variant_builder_add(builder, "i", int_type); - break; - case 'u': - int_type = strtoul(param[pi++], NULL, 10); - g_variant_builder_add(builder, "u", int_type); - break; - case 't': - int64_type = atoll(param[pi++]); - g_variant_builder_add(builder, "t", int64_type); - break; - case 's': - g_variant_builder_add(builder, "s", param[pi++]); - break; - case 'a': - ++ch; - switch (*ch) { - case 'y': - g_variant_builder_add(builder, "^ay", param[pi++]); - ++i; - break; - default: - break; - } - break; - default: - break; - } - } - ret = g_variant_builder_end(builder); - g_variant_builder_clear(builder); - g_variant_builder_unref(builder); - - return ret; -} - -GVariant *dbus_handle_method_sync_with_reply(const char *dest, const char *path, - const char *iface, const char *method, - const char *signature, const char *param[]) -{ - GError *err = NULL; - GVariant * var = NULL; - GVariant * ret = NULL; - dbus_handle_s *dh = NULL; - - if (!dest || !path || !iface || !method) { - _E("wrong parameters dest(%s) path(%s) iface(%s) method(%s)", dest, path, iface, method); - return NULL; - } - - dh = _dbus_handle_get_default_connection(); - if (!dh) { - _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); - return NULL; - } - - if (signature && param) - var = _append_variant(signature, param); - - ret = g_dbus_connection_call_sync(dh->conn, - dest, path, iface, method, - var, NULL, G_DBUS_CALL_FLAGS_NONE, DBUS_REPLY_TIMEOUT, NULL, &err); - if (!ret || err) { - if (err) { - _E("failed to g_dbus_connection_call_sync:%s", err->message); - g_error_free(err); - } else { - _E("failed to g_dbus_connection_call_sync"); - g_variant_unref(var); - } - return NULL; - } - - return ret; -} - -GVariant *dbus_handle_method_sync_with_reply_var(const char *dest, - const char *path, - const char *iface, - const char *method, - GVariant *var) -{ - GError *err = NULL; - GVariant * ret = NULL; - dbus_handle_s *dh = NULL; - - if (!dest || !path || !iface || !method) { - _E("wrong parameters dest(%s) path(%s) iface(%s) method(%s)", dest, path, iface, method); - if (var) - g_variant_unref(var); - return NULL; - } - - dh = _dbus_handle_get_default_connection(); - if (!dh) { - _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); - if (var) - g_variant_unref(var); - return NULL; - } - - ret = g_dbus_connection_call_sync(dh->conn, - dest, path, iface, method, - var, NULL, G_DBUS_CALL_FLAGS_NONE, DBUS_REPLY_TIMEOUT, NULL, &err); - if (!ret || err) { - if (err) { - _E("failed to g_dbus_connection_call_sync:%s", err->message); - g_error_free(err); - } else { - _E("failed to g_dbus_connection_call_sync"); - } - return NULL; - } - - return ret; -} - -GVariant *dbus_handle_method_with_unix_fd_list_sync_with_reply(const char *dest, - const char *path, - const char *iface, - const char *method, - const char *signature, - const char *param[], - int *in_fdlist, - int in_size, - int **out_fdlist, - int *out_size) -{ - GError *err = NULL; - GVariant * var = NULL; - GVariant * ret = NULL; - dbus_handle_s *dh = NULL; - GDBusProxy *proxy = NULL; - GUnixFDList *g_infdlist = NULL; - GUnixFDList *g_outfdlist = NULL; - - if (!dest || !path || !iface || !method) { - _E("wrong parameters dest(%s) path(%s) iface(%s) method(%s)", dest, path, iface, method); - return NULL; - } - if (in_fdlist && in_size == 0) { - _E("wrong in_fdlist is not null but in_size is 0"); - return NULL; - } - - dh = _dbus_handle_get_default_connection(); - if (!dh) { - _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); - return NULL; - } - - if (signature && param) - var = _append_variant(signature, param); - - proxy = g_dbus_proxy_new_sync(dh->conn, G_DBUS_PROXY_FLAGS_NONE, NULL, dest, path, iface, NULL, &err); - if (!proxy) { - if (err) { - _E("failed to proxy_new_sync(%s)\n", err->message); - g_error_free(err); - } else { - _E("failed to proxy_new_sync\n"); - if (var) - g_variant_unref(var); - } - } - - /* append fd */ - if (in_fdlist) { - g_infdlist = g_unix_fd_list_new_from_array(in_fdlist, in_size); - if (!g_infdlist) { - _E("failed to g_unix_fd_list_new_from_array\n"); - goto out; - } - //g_infdlist = g_unix_fd_list_new(); - //if (g_unix_fd_list_append(g_infdlist, in_fdlist[0], &err) < 0) { - } - - ret = g_dbus_proxy_call_with_unix_fd_list_sync(proxy, method, var, G_DBUS_CALL_FLAGS_NONE, -1, - g_infdlist, &g_outfdlist, NULL, &err); - if (!ret || err) { - if (err) { - _E("failed to g_dbus_proxy_call_with_unix_fd_list_sync:%s", err->message); - g_error_free(err); - } else { - _E("failed to g_dbus_proxy_call_with_unix_fd_list_sync:"); - if (var) - g_variant_unref(var); - if (g_infdlist) - g_object_unref(g_infdlist); - } - goto out; - } - - /* fds to out array */ - if (g_outfdlist) { - *out_size = g_unix_fd_list_get_length(g_outfdlist); - if (*out_size == 0) - goto out; - - *out_fdlist = g_unix_fd_list_steal_fds(g_outfdlist, NULL); - } - -out: - if (g_outfdlist) - g_object_unref(g_outfdlist); - if (proxy) - g_object_unref(proxy); - - return ret; -} - -GVariant *dbus_handle_method_with_unix_fd_list_sync_with_reply_var(const char *dest, - const char *path, - const char *iface, - const char *method, - GVariant *param, - int *in_fdlist, - int in_size, - int **out_fdlist, - int *out_size) -{ - GError *err = NULL; - GVariant * ret = NULL; - dbus_handle_s *dh = NULL; - GDBusProxy *proxy = NULL; - GUnixFDList *g_infdlist = NULL; - GUnixFDList *g_outfdlist = NULL; - - if (!dest || !path || !iface || !method) { - _E("wrong parameters dest(%s) path(%s) iface(%s) method(%s)", dest, path, iface, method); - return NULL; - } - if (in_fdlist && in_size == 0) { - _E("wrong in_fdlist is not null but in_size is 0"); - return NULL; - } - - dh = _dbus_handle_get_default_connection(); - if (!dh) { - _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); - return NULL; - } - - proxy = g_dbus_proxy_new_sync(dh->conn, G_DBUS_PROXY_FLAGS_NONE, NULL, dest, path, iface, NULL, &err); - if (!proxy) { - if (err) { - _E("failed to proxy_new_sync(%s)\n", err->message); - g_error_free(err); - } else { - _E("failed to proxy_new_sync\n"); - if (param) - g_variant_unref(param); - } - goto out; - } - - /* append fd */ - if (in_fdlist) { - g_infdlist = g_unix_fd_list_new_from_array(in_fdlist, in_size); - if (!g_infdlist) { - _E("failed to g_unix_fd_list_new_from_array\n"); - goto out; - } - //g_infdlist = g_unix_fd_list_new(); - //if (g_unix_fd_list_append(g_infdlist, in_fdlist[0], &err) < 0) { - } - - /* send message */ - ret = g_dbus_proxy_call_with_unix_fd_list_sync(proxy, method, param, G_DBUS_CALL_FLAGS_NONE, -1, - g_infdlist, &g_outfdlist, NULL, &err); - if (!ret || err) { - if (err) { - _E("failed to g_dbus_proxy_call_with_unix_fd_list_sync:%s", err->message); - g_error_free(err); - } else { - _E("failed to g_dbus_proxy_call_with_unix_fd_list_sync:"); - if (param) - g_variant_unref(param); - if (g_infdlist) - g_object_unref(g_infdlist); - } - goto out; - } - - /* copy fds to out array */ - if (g_outfdlist) { - *out_size = g_unix_fd_list_get_length(g_outfdlist); - if (*out_size == 0) - goto out; - *out_fdlist = g_unix_fd_list_steal_fds(g_outfdlist, NULL); - } -out: - if (g_outfdlist) - g_object_unref(g_outfdlist); - if (proxy) - g_object_unref(proxy); - return ret; -} - -int dbus_handle_method_sync(const char *dest, - const char *path, - const char *iface, - const char *method, - const char *signature, - const char *param[]) -{ - int result; - gboolean result_bool; - GVariant *reply = NULL; - - if (!dest || !path || !iface || !method) { - _E("wrong parameters dest(%s) path(%s) iface(%s) method(%s)", dest, path, iface, method); - return -1; - } - - reply = dbus_handle_method_sync_with_reply(dest, path, iface, method, signature, param); - if (!reply) - return -ECOMM; - - if (g_strcmp0("(i)", g_variant_get_type_string(reply)) == 0) { - g_variant_get(reply, "(i)", &result); - } else if (g_strcmp0("(b)", g_variant_get_type_string(reply)) == 0) { - g_variant_get(reply, "(b)", &result_bool); - result = (int)result_bool; - } else { - result = -ENOMSG; - } - - g_variant_unref(reply); - - return result; -} - -int dbus_handle_method_sync_var(const char *dest, - const char *path, - const char *iface, - const char *method, - GVariant *param) -{ - int result; - gboolean result_bool; - GVariant *reply = NULL; - - if (!dest || !path || !iface || !method) { - _E("wrong parameters dest(%s) path(%s) iface(%s) method(%s)", dest, path, iface, method); - return -1; - } - - reply = dbus_handle_method_sync_with_reply_var(dest, path, iface, method, param); - if (!reply) - return -ECOMM; - - if (g_strcmp0("(i)", g_variant_get_type_string(reply)) == 0) { - g_variant_get(reply, "(i)", &result); - } else if (g_strcmp0("(b)", g_variant_get_type_string(reply)) == 0) { - g_variant_get(reply, "(b)", &result_bool); - result = (int)result_bool; - } else { - result = -ENOMSG; - } - - g_variant_unref(reply); - - return result; -} - -int dbus_handle_method_sync_timeout(const char *dest, - const char *path, - const char *iface, - const char *method, - const char *signature, - const char *param[], - int timeout) -{ - dbus_handle_s *dh = NULL; - GError *err = NULL; - GVariant * var = NULL; - GVariant * reply = NULL; - int result = 0; - - if (!dest || !path || !iface || !method) { - _E("wrong parameters dest(%s) path(%s) iface(%s) method(%s)", dest, path, iface, method); - return -1; - } - - dh = _dbus_handle_get_default_connection(); - if (!dh) { - _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); - return -EPERM; - } - - if (signature && param) - var = _append_variant(signature, param); - - reply = g_dbus_connection_call_sync(dh->conn, - dest, path, iface, method, - var, NULL, G_DBUS_CALL_FLAGS_NONE, timeout, NULL, &err); - if (!reply || err) { - _E("failed to g_dbus_connection_call_sync:%s", err->message); - g_error_free(err); - return -1; - } - - if (g_strcmp0("(i)", g_variant_get_type_string(reply)) == 0) - g_variant_get(reply, "(i)", &result); - else - result = -ENOMSG; - - g_variant_unref(reply); - - return result; -} - -int dbus_handle_method_sync_pairs(const char *dest, - const char *path, - const char *iface, - const char *method, - int num, - va_list args) -{ - GError *err = NULL; - GVariant * reply = NULL; - char *key, *value; - int ret = 0; - GVariant *var; - GVariantBuilder *builder; - dbus_handle_s *dh = NULL; - - if (!dest || !path || !iface || !method) { - _E("wrong parameters dest(%s) path(%s) iface(%s) method(%s)", dest, path, iface, method); - return -1; - } - - dh = _dbus_handle_get_default_connection(); - if (!dh) { - _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); - return -1; - } - - builder = g_variant_builder_new(G_VARIANT_TYPE("a{ss}")); - - for (int i = 0 ; i < num ; i = i + 2) { - key = va_arg(args, char *); - value = va_arg(args, char *); - _I("key(%s), value(%s)", key, value); - g_variant_builder_add(builder, "{ss}", key, value); - } - - var = g_variant_new("(a{ss})", builder); - g_variant_builder_unref(builder); - - reply = g_dbus_connection_call_sync(dh->conn, - dest, path, iface, method, - var, NULL, G_DBUS_CALL_FLAGS_NONE, DBUS_REPLY_TIMEOUT, NULL, &err); - if (!reply || err) { - _E("failed to g_dbus_connection_call_sync"); - return -1; - } - - if (g_strcmp0("(i)", g_variant_get_type_string(reply)) == 0) - g_variant_get(reply, "(i)", &ret); - else - ret = -ENOMSG; - - g_variant_unref(reply); - - return ret; -} - -int dbus_handle_method_async_pairs(const char *dest, - const char *path, - const char *iface, - const char *method, - int num, - va_list args) -{ - char *key, *value; - GVariant *var; - GVariantBuilder *builder; - dbus_handle_s *dh = NULL; - - if (!dest || !path || !iface || !method) { - _E("wrong parameters dest(%s) path(%s) iface(%s) method(%s)", dest, path, iface, method); - return -1; - } - - dh = _dbus_handle_get_default_connection(); - if (!dh) { - _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); - return -1; - } - - // dict - builder = g_variant_builder_new(G_VARIANT_TYPE("a{ss}")); - - for (int i = 0 ; i < num ; i = i + 2) { - key = va_arg(args, char *); - value = va_arg(args, char *); - _I("key(%s), value(%s)", key, value); - g_variant_builder_add(builder, "{ss}", key, value); - } - - var = g_variant_new("(a{ss})", builder); - g_variant_builder_unref(builder); - - g_dbus_connection_call(dh->conn, dest, path, iface, method, - var, NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, - NULL, - NULL); - - return 0; -} - -int dbus_handle_method_async(const char *dest, - const char *path, - const char *iface, - const char *method, - const char *signature, - const char *param[]) -{ - GVariant * var = NULL; - dbus_handle_s *dh = NULL; - - if (!dest || !path || !iface || !method) { - _E("wrong parameters dest(%s) path(%s) iface(%s) method(%s)", dest, path, iface, method); - return -1; - } - - dh = _dbus_handle_get_default_connection(); - if (!dh) { - _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); - return -1; - } - - if (signature && param) - var = _append_variant(signature, param); - - g_dbus_connection_call(dh->conn, dest, path, iface, method, - var, NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, - NULL, - NULL); - - return 0; -} - -int dbus_handle_method_async_var(const char *dest, - const char *path, - const char *iface, - const char *method, - GVariant *param) -{ - dbus_handle_s *dh = NULL; - - if (!dest || !path || !iface || !method) { - _E("wrong parameters dest(%s) path(%s) iface(%s) method(%s)", dest, path, iface, method); - return -1; - } - - dh = _dbus_handle_get_default_connection(); - if (!dh) { - _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); - return -1; - } - - g_dbus_connection_call(dh->conn, dest, path, iface, method, - param, NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, - NULL, - NULL); - - return 0; -} - -/* callback should free gvariant */ -static void _cb_pending(GDBusConnection *conn, - GAsyncResult *res, - gpointer user_data) -{ - GVariant *reply = NULL; - GError *err = NULL; - pending_call_data *data = (pending_call_data *)user_data; - - reply = g_dbus_connection_call_finish(conn, res, &err); - if (!reply || err) { - if (err) { - _E("no message : [%s]", err->message); - g_error_free(err); - } else { - _E("no message"); - } - - if (data && data->func) - data->func(NULL, data->data, err); - goto out; - } - - if (data && data->func) - data->func(reply, data->data, err); -out: - if (data) - free(data); -} - -int dbus_handle_method_async_with_reply(const char *dest, - const char *path, - const char *iface, - const char *method, - const char *signature, - const char *param[], - dbus_pending_cb cb, - int timeout_msec, - void *data) -{ - dbus_handle_s *dh = NULL; - pending_call_data *pdata = NULL; - GVariant * var = NULL; - int ret = 0; - - if (!dest || !path || !iface || !method) { - _E("wrong parameters dest(%s) path(%s) iface(%s) method(%s)", dest, path, iface, method); - return -1; - } - - if (timeout_msec < -1) { - _E("wrong timeout %d", timeout_msec); - return -1; - } - - dh = _dbus_handle_get_default_connection(); - if (!dh) { - _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); - return -EPERM; - } - - if (signature && param) - var = _append_variant(signature, param); - - if (cb) { - pdata = (pending_call_data*)malloc(sizeof(pending_call_data)); - if (!pdata) { - ret = -ENOMEM; - goto err; - } - - pdata->func = cb; - pdata->data = data; - } - g_dbus_connection_call(dh->conn, dest, path, iface, method, - var, NULL, G_DBUS_CALL_FLAGS_NONE, timeout_msec, NULL, - (GAsyncReadyCallback)_cb_pending, - pdata); - - return ret; -err: - if (var) - g_variant_unref(var); - return ret; -} - -int dbus_handle_method_async_with_reply_var(const char *dest, - const char *path, - const char *iface, - const char *method, - GVariant *param, - dbus_pending_cb cb, - int timeout_msec, - void *data) -{ - dbus_handle_s *dh = NULL; - pending_call_data *pdata = NULL; - int ret = 0; - - if (!dest || !path || !iface || !method) { - _E("wrong parameters dest(%s) path(%s) iface(%s) method(%s)", dest, path, iface, method); - return -1; - } - - if (timeout_msec < -1) { - _E("wrong timeout %d", timeout_msec); - return -1; - } - - dh = _dbus_handle_get_default_connection(); - if (!dh) { - _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); - return -EPERM; - } - - if (cb) { - pdata = (pending_call_data*)malloc(sizeof(pending_call_data)); - if (!pdata) { - ret = -ENOMEM; - goto err; - } - - pdata->func = cb; - pdata->data = data; - } - g_dbus_connection_call(dh->conn, dest, path, iface, method, - param, NULL, G_DBUS_CALL_FLAGS_NONE, timeout_msec, NULL, - (GAsyncReadyCallback)_cb_pending, - pdata); - - return ret; -err: - if (param) - g_variant_unref(param); - return ret; -} diff --git a/src/libdeviced/deviced-noti.c b/src/libdeviced/deviced-noti.c index c4957cb..c217cab 100755 --- a/src/libdeviced/deviced-noti.c +++ b/src/libdeviced/deviced-noti.c @@ -27,11 +27,11 @@ #include #include #include +#include #include "dd-deviced.h" #include "deviced-priv.h" #include "log.h" -#include "dbus.h" #define PREDEF_PWROFF_POPUP "pwroff-popup" #define PREDEF_ENTERSLEEP "entersleep" diff --git a/src/libdeviced/display.c b/src/libdeviced/display.c index 8cecfa4..5df5e3f 100644 --- a/src/libdeviced/display.c +++ b/src/libdeviced/display.c @@ -19,9 +19,9 @@ #include #include +#include #include "log.h" -#include "dbus.h" #include "common.h" #include "dd-display.h" diff --git a/src/libdeviced/haptic.c b/src/libdeviced/haptic.c index dcd8569..c788c4a 100644 --- a/src/libdeviced/haptic.c +++ b/src/libdeviced/haptic.c @@ -26,9 +26,9 @@ #include #include #include +#include #include "log.h" -#include "dbus.h" #include "dd-haptic.h" #include "common.h" @@ -60,4 +60,4 @@ API int haptic_stop_all_effects(haptic_device_h device_handle) { _E("Not Supported, Please use capi-system-device apis"); return HAPTIC_ERROR_OPERATION_FAILED; -} \ No newline at end of file +} diff --git a/src/libdeviced/led.c b/src/libdeviced/led.c index 2d0d0dd..e7da673 100644 --- a/src/libdeviced/led.c +++ b/src/libdeviced/led.c @@ -20,9 +20,9 @@ #include #include #include +#include #include "log.h" -#include "dbus.h" #include "common.h" #define METHOD_GET_BRIGHTNESS "GetBrightness" diff --git a/src/libdeviced/mmc.c b/src/libdeviced/mmc.c index 52cecbb..f1c6484 100644 --- a/src/libdeviced/mmc.c +++ b/src/libdeviced/mmc.c @@ -22,9 +22,9 @@ #include #include #include +#include #include "log.h" -#include "dbus.h" #include "common.h" #include "dd-mmc.h" @@ -71,9 +71,9 @@ static int get_mmc_primary_id() int ret; int id; - reply = dbus_handle_method_sync_with_reply_var(STORAGE_BUS_NAME, - DEVICED_PATH_BLOCK_MANAGER, - DEVICED_INTERFACE_BLOCK_MANAGER, + reply = dbus_handle_method_sync_with_reply_var(STORAGED_BUS_NAME, + STORAGED_PATH_BLOCK_MANAGER, + STORAGED_INTERFACE_BLOCK_MANAGER, "GetDeviceList", g_variant_new("(s)", "mmc")); if (!reply) { @@ -175,9 +175,9 @@ API int deviced_request_mount_mmc(struct mmc_contents *mmc_data) if (id < 0) return id; - ret = dbus_handle_method_async_with_reply_var(STORAGE_BUS_NAME, - DEVICED_PATH_BLOCK_MANAGER, - DEVICED_INTERFACE_BLOCK_MANAGER, + ret = dbus_handle_method_async_with_reply_var(STORAGED_BUS_NAME, + STORAGED_PATH_BLOCK_MANAGER, + STORAGED_INTERFACE_BLOCK_MANAGER, "Mount", g_variant_new("(is)", id, ""), mount_cb, @@ -236,9 +236,9 @@ API int deviced_request_unmount_mmc(struct mmc_contents *mmc_data, int option) if (id < 0) return id; - ret = dbus_handle_method_async_with_reply_var(STORAGE_BUS_NAME, - DEVICED_PATH_BLOCK_MANAGER, - DEVICED_INTERFACE_BLOCK_MANAGER, + ret = dbus_handle_method_async_with_reply_var(STORAGED_BUS_NAME, + STORAGED_PATH_BLOCK_MANAGER, + STORAGED_INTERFACE_BLOCK_MANAGER, "Unmount", g_variant_new("(ii)", id, option), unmount_cb, @@ -302,9 +302,9 @@ API int deviced_format_mmc(struct mmc_contents *mmc_data, int option) if (id < 0) return id; - ret = dbus_handle_method_async_with_reply_var(STORAGE_BUS_NAME, - DEVICED_PATH_BLOCK_MANAGER, - DEVICED_INTERFACE_BLOCK_MANAGER, + ret = dbus_handle_method_async_with_reply_var(STORAGED_BUS_NAME, + STORAGED_PATH_BLOCK_MANAGER, + STORAGED_INTERFACE_BLOCK_MANAGER, "Format", g_variant_new("(ii)", id, option), format_cb, diff --git a/src/libdeviced/usbhost.c b/src/libdeviced/usbhost.c index 2f9ece5..c36aa46 100644 --- a/src/libdeviced/usbhost.c +++ b/src/libdeviced/usbhost.c @@ -19,10 +19,10 @@ #include #include +#include #include "log.h" #include "common.h" -#include "dbus.h" #include "dd-usbhost.h" #include "core/list.h" diff --git a/src/power/boot.c b/src/power/boot.c index 1b6be5d..e6e95b5 100644 --- a/src/power/boot.c +++ b/src/power/boot.c @@ -20,12 +20,12 @@ #include #include #include +#include #include "core/log.h" #include "core/device-notifier.h" #include "core/common.h" #include "display/poll.h" -#include "shared/dbus.h" #include "shared/deviced-systemd.h" #define SIGNAL_BOOTING_DONE "BootingDone" diff --git a/src/power/low-power.c b/src/power/low-power.c index efe8344..ab1719a 100644 --- a/src/power/low-power.c +++ b/src/power/low-power.c @@ -22,14 +22,13 @@ #include #include #include +#include #include "core/log.h" #include "core/device-notifier.h" #include "core/device-idler.h" #include "core/common.h" #include "core/devices.h" -#include "shared/dbus.h" -#include "shared/dbus.h" #ifndef VCONFKEY_SYSMAN_LOW_POWER_MODE #define VCONFKEY_SYSMAN_LOW_POWER_MODE "db/sysman/low_power_mode" diff --git a/src/power/power-handler.c b/src/power/power-handler.c index 8365070..5fd733f 100755 --- a/src/power/power-handler.c +++ b/src/power/power-handler.c @@ -36,6 +36,7 @@ #include #include #include +#include #include "dd-deviced.h" #include "core/log.h" @@ -48,7 +49,6 @@ #include "core/launch.h" #include "display/poll.h" #include "display/setting.h" -#include "shared/dbus.h" #include "display/core.h" #include "power-handler.h" #include "apps/apps.h" diff --git a/src/proc/cpu-info.c b/src/proc/cpu-info.c index 216dee6..352b191 100644 --- a/src/proc/cpu-info.c +++ b/src/proc/cpu-info.c @@ -18,10 +18,10 @@ #include +#include #include "core/log.h" #include "core/devices.h" -#include "shared/dbus.h" #include "core/common.h" #define METHOD_GET_REVISION "GetRevision" diff --git a/src/shared/CMakeLists.txt b/src/shared/CMakeLists.txt index c274d9c..2ad9dc1 100644 --- a/src/shared/CMakeLists.txt +++ b/src/shared/CMakeLists.txt @@ -1,7 +1,6 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) SET(SHARED_SRCS - dbus.c deviced-systemd.c plugin.c ) diff --git a/src/shared/dbus.c b/src/shared/dbus.c deleted file mode 100644 index 276b074..0000000 --- a/src/shared/dbus.c +++ /dev/null @@ -1,2684 +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 "common.h" -#include "log.h" -#include "dbus.h" - -/* 10 seconds */ -#define DBUS_REPLY_TIMEOUT (10000) - -int check_systemd_active(void) -{ - int ret = FALSE; - GVariant *msg = NULL; - GVariant *var = NULL; - char *state; - - _I("%s %s", "org.freedesktop.systemd1.Unit", "ActiveState"); - - msg = dbus_handle_method_sync_with_reply_var("org.freedesktop.systemd1", - "/org/freedesktop/systemd1/unit/default_2etarget", - "org.freedesktop.DBus.Properties", - "Get", - g_variant_new("(ss)", "org.freedesktop.systemd1.Unit", "ActiveState")); - if (!msg) - return -EBADMSG; - - if (!dh_get_param_from_var(msg, "(v)", &var)) { - _E("reply is not variant type"); - ret = -EBADMSG; - goto out; - } - if (!dh_get_param_from_var(var, "(s)", &state)) { - _E("variant doesn't have string (%s)", g_variant_get_type_string(var)); - ret = -EBADMSG; - goto out; - } - - if (strncmp(state, "active", 6) == 0) - ret = TRUE; - - g_free(state); -out: - if (var) - g_variant_unref(var); - if (msg) - g_variant_unref(msg); - - return ret; -} - -static GBusType g_default_bus_type = G_BUS_TYPE_SYSTEM; -pthread_mutex_t g_mutex = PTHREAD_MUTEX_INITIALIZER; - -void dbus_handle_set_default_bus_type(GBusType bus_type) -{ - if (bus_type != G_BUS_TYPE_SYSTEM && bus_type != G_BUS_TYPE_SESSION) - return ; - - pthread_mutex_lock(&g_mutex); - g_default_bus_type = bus_type; - pthread_mutex_unlock(&g_mutex); -} - -GBusType dbus_handle_get_default_bus_type(void) -{ - GBusType type; - - pthread_mutex_lock(&g_mutex); - type = g_default_bus_type; - pthread_mutex_unlock(&g_mutex); - - return type; -} - -typedef struct { - const char *bus_name; - guint id; -} dbus_name; - -/* basic information */ -typedef struct { - GDBusConnection *conn; - GBusType bus_type; - gboolean priv; - GList *list_names; /* dbus_name */ - GList *list_object; /* dbus_object_handle_s */ - pthread_mutex_t mutex; -} dbus_handle_s; - -/* path + interfaces */ -typedef struct { - dbus_handle_s *dh; /* dbus handle */ - const char *path; /* object path */ - GList *list_ifaces; /* dbus_interface_s */ -} dbus_object_handle_s; - -typedef struct { - dbus_object_handle_s *oh; /* object handle */ - const char *name; /* interface name */ - GList *list_methods; /* const dbus_method_s */ - guint reg_id; - int modified; -} dbus_interface_s; - -#define get_dh_from_oh(oh) ((dbus_object_handle_s*)oh)->dh - -/* global shared bus : system, session */ -static dbus_handle_s g_dh[2]; - -static dbus_handle_s *_dbus_handle_get_connection(GBusType bus_type); - -dbus_handle_s * _dbus_handle_get_default_connection(void) -{ - return _dbus_handle_get_connection(dbus_handle_get_default_bus_type()); -} - -#define dbus_handle_lock(handle) do {\ - assert(handle);\ - pthread_mutex_lock(&((handle)->mutex));\ -} while (0); - -#define dbus_handle_unlock(handle) do {\ - assert(handle);\ - pthread_mutex_unlock(&(handle)->mutex);\ -} while (0); - -#define dcl_dbus_handle() dbus_handle_s *dh = (dbus_handle_s *)handle; -#define dcl_dbus_handle_null_check() dbus_handle_s *dh = (dbus_handle_s *)handle;\ - if (!dh) {\ - _E("dbus handle is null\n");\ - return 0;\ - } - -dbus_object_handle_s * _dbus_handle_lookup_object(GList *list_obj, const char *obj_path); -dbus_interface_s * _dbus_handle_lookup_interface(GList *list_iface, const char *iface_name); -dbus_method_s * _dbus_handle_lookup_method(GList *list_methods, const char *method_name); -static GVariant* _append_variant(const char *signature, const char *param[]); - -dbus_interface_s *_iface_u_to_s(const dbus_interface_u *iface_u) -{ - dbus_interface_s *iface = NULL; - - if (!iface_u || !iface_u->methods) { - _E("param is null"); - return NULL; - } - - iface = (dbus_interface_s *)calloc(1, sizeof(dbus_interface_s)); - if (!iface) { - _E("failed to calloc"); - return NULL; - } - - iface->name = iface_u->name; - iface->modified = TRUE; - - for (int i = 0 ; i < iface_u->nr_methods; ++i) { - //_D("attached %s:%p", iface_u->methods[i].member, iface_u->methods[i].func); - iface->list_methods = g_list_prepend(iface->list_methods, (void*)(iface_u->methods + i)); - } - - return iface; -} - -static GDBusConnection * _get_bus(GBusType bus_type) -{ - GDBusConnection *conn = NULL; - GError *err = NULL; - - if (bus_type != G_BUS_TYPE_SYSTEM && bus_type != G_BUS_TYPE_SESSION) { - _E("Wrong bus_type %d", bus_type); - return NULL; - } - - conn = g_bus_get_sync(bus_type, NULL, &err); - if (!conn || err) { - _E("failed to get bus:type:%d, %s\n", bus_type, err->message); - g_error_free(err); - return NULL; - } - - return conn; -} - -static GDBusConnection * _get_bus_private(GBusType bus_type) -{ - GError *err = NULL; - GDBusConnection *conn = NULL; - const char * address; - - if (bus_type != G_BUS_TYPE_SYSTEM && bus_type != G_BUS_TYPE_SESSION) { - _E("Wrong bus_type %d", bus_type); - return NULL; - } - - address = g_dbus_address_get_for_bus_sync(bus_type, NULL, &err); - if (!address || err) { - _E("failed to get bus address\n"); - g_error_free(err); - return NULL; - } - - conn = g_dbus_connection_new_for_address_sync(address, - (GDBusConnectionFlags) (G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT | - G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION), - NULL, /* GDBusAuthObserver */ - NULL, - &err); - if (!conn || err) { - _E("failed to get private bus\n"); - g_error_free(err); - return NULL; - } - - return conn; -} - -/* ref cout is 1 */ -static dbus_handle_s *_dbus_handle_get_connection(GBusType bus_type) -{ - int ibus = bus_type - 1; - dbus_handle_s *dh = NULL; - - if (bus_type != G_BUS_TYPE_SYSTEM && bus_type != G_BUS_TYPE_SESSION) { - _E("Unknown bus type %d", bus_type); - return NULL; - } - dh = &g_dh[ibus]; - - dbus_handle_lock(dh); - - if (!dh->conn) { - dh->conn = _get_bus(bus_type); - dh->priv = FALSE; - dh->bus_type = bus_type; - if (!dh->conn) - dh = NULL; - } - - dbus_handle_unlock(dh); - - return dh; -} - -/* ref cout is 1 */ -static dbus_handle_s *_dbus_handle_get_connection_private(GBusType bus_type) -{ - dbus_handle_s * dh; - - if (bus_type != G_BUS_TYPE_SYSTEM && bus_type != G_BUS_TYPE_SESSION) { - _E("Unknown bus type %d", bus_type); - return NULL; - } - - dh = (dbus_handle_s *)calloc(1, sizeof(dbus_handle_s)); - if (!dh) { - _E("failed to allocate memory for dbus handle"); - return NULL; - } - - dbus_handle_lock(dh); - - if (!dh->conn) { - dh->conn = _get_bus_private(bus_type); - dh->bus_type = bus_type; - if (!dh->conn) - goto err; - } - - dbus_handle_unlock(dh); - - return dh; -err: - if (dh) { - dbus_handle_unlock(dh); - free(dh); - } - return NULL; -} - -dbus_handle_h dbus_handle_get_connection(GBusType bus_type, gboolean priv) -{ - dbus_handle_s *dh = NULL; - - if (bus_type != G_BUS_TYPE_SYSTEM && bus_type != G_BUS_TYPE_SESSION) { - _E("Wrong bus_type %d\n", bus_type); - return dh; - } - - /* private */ - if (priv) - dh = _dbus_handle_get_connection_private(bus_type); - /* shared */ - else - dh = _dbus_handle_get_connection(bus_type); - - return dh; -} - -static void _dbus_handle_add_bus_name(dbus_handle_s *handle, const char *name, guint id) -{ - dbus_name *dn = NULL; - int locked = 0; - - if (!handle || !name || !id) - return ; - - dn = (dbus_name*)calloc(1, sizeof(dbus_name)); - if (!dn) { - _E("failed to calloc"); - assert(0); - } - dn->bus_name = name; - dn->id = id; - - // todo : delete lock ? - locked = pthread_mutex_trylock(&handle->mutex); - if (locked != 0 && locked != EBUSY) { - _E("failed to lock %d\n", locked); - assert(0); - } - - handle->list_names = g_list_prepend(handle->list_names, dn); - - // todo : delete lock ? - if (locked != EBUSY) - dbus_handle_unlock(handle); -} - -static gint _compare_dbus_name(gconstpointer a, gconstpointer b) -{ - const char *bus_name = ((dbus_name *)a)->bus_name; - if (!bus_name || !b) - return -1; - return strcmp(bus_name, (const char *)b); -} - -dbus_name * _dbus_handle_lookup_dbus_name(GList *list_name, const char *bus_name) -{ - if (!list_name || !bus_name) - return NULL; - - GList *item = g_list_find_custom(list_name, bus_name, _compare_dbus_name); - if (!item) - return NULL; - - return (dbus_name *)item->data; -} - -#define dh_to_ds(x) ((dbus_handle_s*)x) - -/* remove dbus_name from dbus handle */ -static void _dbus_handle_remove_bus_name(dbus_handle_s *handle, const char *bus_name) -{ - dcl_dbus_handle(); - dbus_name *dn = NULL; - - if (!bus_name) { - _E("wrong bus_name %s", bus_name); - return ; - } - if (!dh) { - dh = _dbus_handle_get_default_connection(); - if (!dh) { - _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); - return ; - } - } - - dbus_handle_lock(dh); - dn = _dbus_handle_lookup_dbus_name(dh->list_names, bus_name); - if (!dn) { - _E("failed to find dbus name %s", bus_name); - goto out; - } - dh->list_names = g_list_remove(dh->list_names, dn); - free(dn); -out: - dbus_handle_unlock(dh); -} - -extern void booting_done(void); - -/* default handler */ -static void _name_acquired(GDBusConnection *connection, const gchar *name, gpointer user_data) -{ - dbus_handle_s *dh = (dbus_handle_s *)user_data; - - _D("name %s", name); - - if (!dh) { - _E("%s:%d:dbus handle is null\n", __func__, __LINE__); - return ; - } - - // todo: add bus name? - //dh->bus_name = name; -} - -/* default handler */ -static void _name_lost(GDBusConnection *connection, const gchar *name, gpointer user_data) -{ - _E("%s:%d:%s\n", __func__, __LINE__, name); - dbus_handle_s *dh = (dbus_handle_s *)user_data; - if (!dh) { - _E("%s:%d:dbus handle is null\n", __func__, __LINE__); - return ; - } - _dbus_handle_remove_bus_name(dh, name); -} - -int dbus_handle_request_bus_name(dbus_handle_h handle, - const char *bus_name, - GBusNameAcquiredCallback acquired_handler, - GBusNameLostCallback lost_handler) -{ - dcl_dbus_handle(); - int id = -1; - GList *item = NULL; - - if (!bus_name) { - _E("bus_name is NULL"); - return -1; - } - - /* get shared connection */ - if (!dh) { - dh = _dbus_handle_get_default_connection(); - if (!dh) { - _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); - return -1; - } - } - - dbus_handle_lock(dh); - if (!dh->conn) { - _E("failed to register name: connection is null\n"); - goto out; - } - - /* todo : search name on connection */ - item = g_list_find_custom(dh->list_names, bus_name, _compare_dbus_name); - if (item) { - id = ((dbus_name*)(item->data))->id; - _E("name already exist:%u", id); - goto out; - } - - id = g_bus_own_name_on_connection(dh->conn, - bus_name, - G_BUS_NAME_OWNER_FLAGS_NONE, - acquired_handler ? acquired_handler : _name_acquired, - lost_handler ? lost_handler : _name_lost, - dh, - NULL); - if (!id) { - _E("failed to own name:%s\n", bus_name); - goto out; - } - - _dbus_handle_add_bus_name(dh, bus_name, id); - -out: - dbus_handle_unlock(dh); - return id; -} - -/* !! _name_lost handler callback is disabled by g_bus_unown_name : ubuntu */ -int dbus_handle_release_bus_name(dbus_handle_h handle, const char *bus_name) -{ - dcl_dbus_handle(); - dbus_name *dn = NULL; - - if (!bus_name) { - _E("Wrong bus name"); - return -1; - } - - if (!dh) { - dh = _dbus_handle_get_default_connection(); - if (!dh) { - _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); - return -1; - } - } - - dn = _dbus_handle_lookup_dbus_name(dh->list_names, bus_name); - if (!dn) { - _E("failed to find bus_name %s on dbus handle", bus_name); - return -1; - } - - _E("unown name %d", dn->id); - /* _name_lost handler is disabled by g_bus_unown_name : ubuntu */ - g_bus_unown_name(dn->id); - - dbus_handle_lock(dh); - dh->list_names = g_list_remove(dh->list_names, dn); - free(dn); - dbus_handle_unlock(dh); - - return 0; -} - -int dbus_handle_free_connection(dbus_handle_h handle) -{ - dcl_dbus_handle(); - dbus_handle_s *pdh = NULL; - GError *err = NULL; - GList *item = NULL; - - if (!dh) { - dh = _dbus_handle_get_default_connection(); - if (!dh) { - _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); - return -1; - } - } - - if (!dh->conn) { - _E("connection is NULL"); - return 0; - } - - pdh = dh; - - /* disable dbus handler */ - dbus_handle_lock(dh); - if (!pdh->conn) { - _E("conn is null"); - free(pdh); - return 0; - } - - /* flush everything */ - if (!g_dbus_connection_flush_sync(pdh->conn, NULL, &err)) { - _E("failed to flush %s\n", err->message); - g_error_free(err); - err = NULL; - } - - _D("list_names %u", g_list_length(pdh->list_names)); - - /* unown every well-knwon name */ - if (pdh->list_names) { - dbus_name *dn = NULL; - for (item = g_list_first(pdh->list_names); item != NULL; item = g_list_next(item)) { - dn = (dbus_name *)item->data; - if (!dn) - continue; - - /* _name_lost handler is disabled by g_bus_unown_name : ubuntu */ - _D("unown name id : %u", dn->id); - g_bus_unown_name(dn->id); - free(dn); - } - g_list_free(pdh->list_names); - pdh->list_names = NULL; - } - - _D("list_object %u", g_list_length(pdh->list_object)); - - /* unregister every object */ - if (pdh->list_object) { - dbus_object_handle_s * oh = NULL; - //g_list_foreach(pdh->list_object, [] (gpointer data, gpointer user_data) {}, NULL); - for (item = g_list_first(pdh->list_object); item != NULL; item = g_list_next(item)) { - oh = (dbus_object_handle_s *)item->data; - if (!oh || !oh->list_ifaces) - continue; - - _D("delete object path %s", oh->path); - - /* unregister every interface, method handles */ - for (GList *iface = g_list_first(oh->list_ifaces); iface != NULL; iface = g_list_next(iface)) { - dbus_interface_s *ih = (dbus_interface_s *)iface->data; - if (!ih) - continue; - - _D("delete object iface %s", ih->name); - - if (ih->reg_id) - g_dbus_connection_unregister_object(pdh->conn, ih->reg_id); - } - } - } - - /* close connection */ - if (pdh->priv) { - _E("close private connection\n"); - - if (!g_dbus_connection_close_sync(pdh->conn, NULL, &err)) { - _E("Error closing connection %s\n", err->message); - g_error_free(err); - err = NULL; - } - } - - /* _free_func_object callback free the data */ - //assert(g_list_length(pdh->list_names) == 0); - //assert(g_list_length(pdh->list_object) == 0); - - g_object_unref(pdh->conn); - - dbus_handle_unlock(dh); - - if (dh->priv) - free(dh); - - return 0; - - // todo: signal ? -} - -#define buf_cal_free_space(size, nwrite) ((size - nwrite - 1) > 0 ? (size - nwrite - 1) : 0) -#define buf_block_size 8192 - -#define buf_check_space_realloc(buf, nwrite, buf_len) do {\ - if ((nwrite >= buf_len - 1024)) {\ - if (buf_len >= buf_block_size * 10) {\ - _E("buf is too big to allocate. %d", buf_len);\ - } else {\ - _E("buf_check_space_realloc");\ - char *tmp = NULL;\ - buf_len += buf_block_size;\ - tmp = (char *)realloc(buf, buf_len);\ - if (!tmp) {\ - _E("failed to realloc");\ - } else\ - buf = tmp;\ - } \ - } \ -} while (0); - -/* cal index of end of brace */ -static int _check_brace(const char * expr) -{ - int len = 0; - char qu[128]; - int qucnt = 0; - - if (!expr) - return -1; - - len = strlen(expr); - - if (expr[0] != '(' && expr[0] != '{') - return -1; - - for (int i = 0 ; i < len; ++i) { - - if (expr[i] == '(' || expr[i] == '{') { - qu[qucnt++] = expr[i]; - if (qucnt >= sizeof(qu)) { - _E("queue is too large. %s", expr); - return -1; - } - continue; - } - - if (expr[i] == ')' || expr[i] == '}') { - char ch; - - if (qucnt > 0) - ch = qu[qucnt-1]; - else - return -1; - - if (expr[i] == ')') { - if (ch == '(') { - --qucnt; - } else - return -1; - } else if (expr[i] == '}') { - if (ch == '{') { - --qucnt; - } else - return -1; - } else - return -1; - - if (qucnt == 0) { - return i + 1; - } - } - } - - return -1; -} - -/* -in : interface_s -out : xml format -*/ -static int _get_xml_from_interfaces(char **xml, const dbus_interface_s *interfaces) -{ - int nwrite = 0; - int len_args; - char *buf = NULL; - const dbus_method_s *pmethod; - int buf_len = buf_block_size; - - if (!interfaces) { - _E("interfaces is null"); - return -1; - } - - // todo : check dbus naming rule for interface name. ? - if (!interfaces->name) { - _E("wrong interface name"); - return -1; - } - if (!interfaces->list_methods) { - _E("no methods"); - return -1; - } - - buf = (char *)malloc(buf_len); - if (!buf) { - _E("buf is null. not enough memory\n"); - return -1; - } - - nwrite += snprintf(buf + nwrite, buf_cal_free_space(buf_len, nwrite), """\n""\t""""\n", interfaces->name); - - /* members */ - for (GList *item = g_list_first(interfaces->list_methods); item != NULL; item = g_list_next(item)) { - pmethod = (const dbus_method_s *)item->data; - if (!pmethod) - continue; - - /* check free space of buf */ - buf_check_space_realloc(buf, nwrite, buf_len); - - if (pmethod->signature_in == NULL && pmethod->signature_out == NULL) { - nwrite += snprintf(buf + nwrite, buf_cal_free_space(buf_len, nwrite), "\t\t""""\n", pmethod->member); - continue; - } - - /* */ - nwrite += snprintf(buf + nwrite, buf_cal_free_space(buf_len, nwrite), "\t\t""""\n", pmethod->member); - - /* in args */ - len_args = pmethod->signature_in ? strlen(pmethod->signature_in) : 0; - for (int m = 0; m < len_args; ++m) { - // todo - // array a(), as, ay ? - if (pmethod->signature_in[m] == 'a') { - int ei; //end index - ei = _check_brace(pmethod->signature_in + m + 1); - if (ei > 0) { - char tmp[128] = {0,}; - strncpy(tmp, pmethod->signature_in + m, ei + 1); - nwrite += snprintf(buf + nwrite, buf_cal_free_space(buf_len, nwrite), "\t\t\t""""\n", tmp, m); - m += ei; - continue; - } else { - nwrite += snprintf(buf + nwrite, buf_cal_free_space(buf_len, nwrite), "\t\t\t""""\n", pmethod->signature_in[m], pmethod->signature_in[m+1], m); - m += 1; - continue; - } - } - nwrite += snprintf(buf + nwrite, buf_cal_free_space(buf_len, nwrite), "\t\t\t""""\n", pmethod->signature_in[m], m); - } - - /* out args */ - len_args = pmethod->signature_out ? strlen(pmethod->signature_out) : 0; - for (int m = 0; m < len_args; ++m) { - // array - // todo: container type - if (pmethod->signature_out[m] == 'a') { - int ei; //end index - ei = _check_brace(pmethod->signature_out + m + 1); - if (ei > 0) { - char tmp[128] = {0,}; - strncpy(tmp, pmethod->signature_out + m, ei + 1); - nwrite += snprintf(buf + nwrite, buf_cal_free_space(buf_len, nwrite), "\t\t\t""""\n", tmp, m); - m += ei; - continue; - } else { - nwrite += snprintf(buf + nwrite, buf_cal_free_space(buf_len, nwrite), "\t\t\t""""\n", pmethod->signature_out[m], pmethod->signature_out[m+1], m); - m += 1; - continue; - } - } - nwrite += snprintf(buf + nwrite, buf_cal_free_space(buf_len, nwrite), "\t\t\t""""\n", pmethod->signature_out[m], m); - } - - /* */ - nwrite += snprintf(buf + nwrite, buf_cal_free_space(buf_len, nwrite), "\t\t""""\n"); - } - - nwrite += snprintf(buf + nwrite, buf_cal_free_space(buf_len, nwrite), "\t""""\n"""""); - - *xml = buf; - - /* todo: delete log */ -#if 0 - if (nwrite <= 512) - _E("%s", buf); - else - _E("%s", buf + nwrite - 512); -#endif - return 0; -} - -static gint _compare_dbus_object(gconstpointer a, gconstpointer b) -{ - dbus_object_handle_s * pa = (dbus_object_handle_s *)a; - if (!pa->path || !((const char*)b)) - return -1; - return strcmp(pa->path, (const char*)b); -} - -static gint _compare_dbus_interface(gconstpointer a, gconstpointer b) -{ - dbus_interface_s * pa = (dbus_interface_s *)a; - if (!pa->name || !((const char*)b)) - return -1; - return strcmp(pa->name, (const char*)b); -} - -static gint _compare_dbus_interface_by_id(gconstpointer a, gconstpointer b) -{ - dbus_interface_s * pa = (dbus_interface_s *)a; - if (!pa->reg_id || !((guint*)b)) - return -1; - return !(pa->reg_id == *((guint*)b)); -} - -static gint _compare_dbus_method(gconstpointer a, gconstpointer b) -{ - dbus_method_s *pa = (dbus_method_s*)a; - if (!pa->member || !((const char*)b)) - return -1; - return strcmp(pa->member, (const char*)b); -} - -dbus_object_handle_s * _dbus_handle_lookup_object(GList *list_obj, const char *obj_path) -{ - if (!list_obj || !obj_path) - return NULL; - - GList *item = g_list_find_custom(list_obj, obj_path, _compare_dbus_object); - if (!item) - return NULL; - - return (dbus_object_handle_s *)item->data; -} - -dbus_interface_s * _dbus_handle_lookup_interface(GList *list_iface, const char *iface_name) -{ - if (!list_iface || !iface_name) - return NULL; - - GList *item = g_list_find_custom(list_iface, iface_name, _compare_dbus_interface); - if (!item) - return NULL; - - return (dbus_interface_s *)item->data; -} - -dbus_interface_s * _dbus_handle_lookup_interface_by_id(GList *list_iface, guint id) -{ - if (!list_iface || !id) - return NULL; - - GList *item = g_list_find_custom(list_iface, &id, _compare_dbus_interface_by_id); - if (!item) - return NULL; - - return (dbus_interface_s *)item->data; -} - -dbus_method_s * _dbus_handle_lookup_method(GList *list_methods, const char *method_name) -{ - if (!list_methods || !method_name) - return NULL; - - GList *item = g_list_find_custom(list_methods, method_name, _compare_dbus_method); - if (!item) - return NULL; - - return (dbus_method_s *)item->data; -} - -static void _free_func_object(gpointer data) -{ - dbus_interface_s *ih = (dbus_interface_s *)data; - dbus_object_handle_s *oh = NULL; - - if (!ih) { - _E("interface handle is null"); - assert(0); // something wrong - return ; - } - - _E("unregister interface %s", ih->name); - - /* just free list, not data(static dbus_method_s) */ - g_list_free(ih->list_methods); - - oh = ih->oh; - if (!oh) { - _E("object handle is null"); - assert(0); // something wrong - return ; - } - - /* remove ih from list_ifaces */ - oh->list_ifaces = g_list_remove(oh->list_ifaces, ih); - - /* interface_s is copy of interface_u */ - free(ih); - - /* remove oh from list_object */ - if (!oh->list_ifaces) { - oh->dh->list_object = g_list_remove(oh->dh->list_object, oh); - free(oh); - } -} - -static int _dbus_handle_attach_object(dbus_handle_s *dh, const char *obj_path, dbus_interface_s *iface) -{ - dbus_object_handle_s *oh = NULL; - - if (!dh || !obj_path || !iface) { - _E("failed to attache object. wrong parameter"); - return -1; - } - - /* find object handle */ - if (dh->list_object) - oh = _dbus_handle_lookup_object(dh->list_object, obj_path); - - if (!oh) { - oh = (dbus_object_handle_s*)calloc(1, sizeof(dbus_object_handle_s)); - if (!oh) { - _E("failed to calloc"); - return -1; - } - oh->dh = dh; - oh->path = obj_path; - - /* attach object */ - dh->list_object = g_list_prepend(dh->list_object, oh); - } - - iface->oh = oh; - /* attach interface */ - oh->list_ifaces = g_list_prepend(oh->list_ifaces, iface); - - return 0; -} - -/* -_method_call_handler - -libgio verify path and interface of incoming message. ---> just check method name. - -# parameters - member of invocation struct -every parameters of this function are member of GDBusMethodInvocation *invocation. -There are no reason to using g_dbus_method_invocation_get_* apis to get inforamtion from message. -just use params - sender, path, iface, name and param. - - -# user defined handler # - -1. synchronous handling - 1) with return value - handler() { - return g_variant_new("(i)", ret); - } - - 2) without return value - handler() { - return dbus_handle_new_g_variant_tuple(); // g_variant_new_tuple(NULL, 0) - } - -2. asynchronous handling - handler MUST call 'g_dbus_method_invocation_return_value' itself. otherwise, LEAK !! - - handler() { - return NULL; - } - - # if handler return NULL, assume asynchronous handling. do nothing. - - thread() { - do something; - - 1) with return value - g_dbus_method_invocation_return_value(invocation, g_variant_new("(i)", ret)); - - 2) without return value - g_dbus_method_invocation_return_value(invocation, NULL); - } - - -*/ -static void _method_call_handler(GDBusConnection *conn, - const gchar *sender, - const gchar *path, - const gchar *iface, - const gchar *name, - GVariant *param, - GDBusMethodInvocation *invocation, - gpointer user_data) -{ - dbus_interface_s *iface_s = (dbus_interface_s *)user_data; - const dbus_method_s *methods; - GVariant *result = NULL; - - /* todo: ghash ? */ - methods = _dbus_handle_lookup_method(iface_s->list_methods, name); - if (methods) { - result = methods->func(conn, sender, path, iface, name, param, invocation, get_dh_from_oh(iface_s->oh)); - - /* async, maybe they will reply...maybe.. */ - if (!result) { - return ; - } - } else { - _E("no methods"); - } - - g_dbus_method_invocation_return_value(invocation, result); -} - -static GDBusInterfaceVTable path_vtable = {_method_call_handler}; - - -/* -before register object, attach object into dbus handle -_dbus_handle_attach_object() -*/ -static int _dbus_handle_register_dbus_object(dbus_handle_h handle, const char *obj_path, dbus_interface_s *iface) -{ - dcl_dbus_handle(); - int ret = 0; - char *buf = NULL; - GError *err = NULL; - GDBusNodeInfo * nodeinfo = NULL; - GDBusInterfaceInfo *ifaceinfo = NULL; - - if (!obj_path || !iface) { - _E("wrong parameter\n"); - return -1; - } - if (!dh) { - dh = _dbus_handle_get_default_connection(); - if (!dh) { - _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); - return -1; - } - } - if (!dh->conn) { - _E("connection is null\n"); - return -1; - } - - ret = _get_xml_from_interfaces(&buf, iface); - if (ret < 0) { - _E("failed to make xml format"); - goto err; - } - - /* todo: delete this */ -#if 0 - if (strlen(buf) <= 512) { - _E("%s", buf); - } else { - _E("%s", buf + strlen(buf) - 512); - } -#endif - - nodeinfo = g_dbus_node_info_new_for_xml(buf, &err); - if (!nodeinfo || err) { - _E("failed to make introspection data:err:%s:xml:%s\n", err->message, buf); - ret = -1; - goto err; - } - - ifaceinfo = g_dbus_node_info_lookup_interface(nodeinfo, iface->name); - if (!ifaceinfo) { - _E("failed to g_dbus_node_info_lookup_interface"); - ret = -1; - goto err; - } - - /* - path own single interface - if interface is already registered, then failed. - g_dbus_connection_register_object ref(ifaceinfo) now, unref if object is unregistered - */ - ret = g_dbus_connection_register_object(dh->conn, - obj_path, - ifaceinfo/*ref 2*/, - &path_vtable, - (void*)iface, - _free_func_object, - &err); - if (err) { - _E("failed to register object:err:%s:\n", err->message); - ret = -1; - goto err; - } - - iface->reg_id = ret; - iface->modified = FALSE; - -err: - /* todo: detach object */ - //_dbus_handle_detach_object(dh, obj_path, iface); - /* attach interface before register object */ - /*ret = _dbus_handle_detach_object(dh, obj_path, iface); - if (ret < 0) { - _E("failed to attach object"); - goto err; - }*/ - - if (nodeinfo) - g_dbus_node_info_unref(nodeinfo); - if (buf) - free(buf); - if (err) - g_error_free(err); - - return ret; -} - -/* -register same interface at once - -if interface is constructed by multiple methods, -also it is not possible to make methods struct at once, - -use dbus_handle_add_dbus_object(), dbus_handle_register_dbus_object_all(). - -return reg_id -*/ -int dbus_handle_register_dbus_object(dbus_handle_h handle, const char *obj_path, const dbus_interface_u *iface_u) -{ - dcl_dbus_handle(); - int ret = 0; - dbus_interface_s *iface = NULL; - - if (!obj_path || !iface_u) { - _E("wrong parameter\n"); - return -1; - } - if (!dh) { - dh = _dbus_handle_get_default_connection(); - if (!dh) { - _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); - return -1; - } - } - if (!dh->conn) { - _E("connection is null\n"); - return -1; - } - - /* check registered interface */ - if (dh->list_object) { - dbus_object_handle_s *oh = _dbus_handle_lookup_object(dh->list_object, obj_path); - if (oh) { - dbus_interface_s *ih = _dbus_handle_lookup_interface(oh->list_ifaces, iface_u->name); - if (ih) { - _E("path %s, interface %s already registered", obj_path, iface_u->name); - return -1; - } - } - } - - iface = _iface_u_to_s(iface_u); - if (!iface) { - _E("failed to _iface_u_to_s"); - return -1; - } - - /* attach interface before register object */ - ret = _dbus_handle_attach_object(dh, obj_path, iface); - if (ret < 0) { - _E("failed to attach object"); - goto err; - } - - ret = _dbus_handle_register_dbus_object(dh, obj_path, iface); - if (ret <= 0) { - _E("failed to register dbus object%d", ret); - goto err; - } -err: - return ret; -} - -int dbus_handle_unregister_dbus_object(dbus_handle_h handle, const char *obj_path) -{ - dcl_dbus_handle(); - dbus_object_handle_s *oh = NULL; - int ret = 0; - - if (!obj_path) { - return -1; - } - if (!dh) { - dh = _dbus_handle_get_default_connection(); - if (!dh) { - _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); - return -1; - } - } - if (!dh->list_object) { - _E("list_object is empty"); - return 0; - } - - oh = _dbus_handle_lookup_object(dh->list_object, obj_path); - if (!oh) { - _E("no object with name %s", obj_path); - return -1; - } - - /* unregister every interface of object*/ - for (GList *item = g_list_first(oh->list_ifaces); item != NULL; item = g_list_next(item)) { - dbus_interface_s *ih = item->data; - if (!ih) { - _E("this is error"); - assert(0); - } - - /* remove ih from list_ifaces */ - if (!ih->reg_id) { - item = g_list_previous(item); - - /* remove and free link */ - oh->list_ifaces = g_list_remove(oh->list_ifaces, ih); - - /* free list_methods */ - g_list_free(ih->list_methods); - - /* free data */ - free(ih); - continue; - } - - /* unregister object by id */ - ret = g_dbus_connection_unregister_object(dh->conn, ih->reg_id); - if (!ret) - _E("failed to unregister object %s, interface %s, regid %d", oh->path, ih->name, ih->reg_id); - } - - return 0; -} - -/* -add object temporarily. -dbus_handle_register_dbus_object_all register every objects on connection. - -return registered method count -*/ -int dbus_handle_add_dbus_object(dbus_handle_h handle, const char *obj_path, const dbus_interface_u *iface_u) -{ - dcl_dbus_handle(); - dbus_object_handle_s *oh = NULL; - dbus_interface_s *ih = NULL; - int cnt; - - if (!obj_path || !iface_u) { - _E("wrong parameter path %s, iface_u %p\n", obj_path, iface_u); - return -1; - } - if (iface_u && (!iface_u->name || !iface_u->methods)) { - _E("wrong parameter path %s, iface_u %p\n", obj_path, iface_u); - return -1; - } - - cnt = iface_u->nr_methods; - - if (!dh) { - dh = _dbus_handle_get_default_connection(); - if (!dh) { - _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); - return -1; - } - } - - if (!dh->conn) { - _E("failed to register method. connection is null\n"); - return -1; - } - - /* if there are no object list, just add */ - if (!dh->list_object) { - if (_dbus_handle_attach_object(dh, obj_path, _iface_u_to_s(iface_u))) { - _E("failed to attach object"); - return -1; - } - goto out; - } - - oh = _dbus_handle_lookup_object(dh->list_object, obj_path); - /* if there are no matched object, just add */ - if (!oh) { - if (_dbus_handle_attach_object(dh, obj_path, _iface_u_to_s(iface_u))) { - _E("failed to attach object"); - return -1; - } - goto out; - } - - /* this is an error, interface must have one or more item ? */ - if (!oh->list_ifaces) { - _E("error. list_ifaces is null\n"); - assert(0); - goto out; - } - - ih = _dbus_handle_lookup_interface(oh->list_ifaces, iface_u->name); - /* if there are no matched interface, just add */ - if (!ih) { - if (_dbus_handle_attach_object(dh, obj_path, _iface_u_to_s(iface_u))) { - _E("failed to attach object"); - return -1; - } - goto out; - } - - /* todo: - 1. unregister interface - 2. update interface and methods - 3. register interface - */ - if (ih->reg_id) { - _E("interface already registered, ignore new interface"); - return -1; - } - - /* attach new methods */ - cnt = 0; - for (int i = 0; i < iface_u->nr_methods; ++i) { - GList *item = g_list_find_custom(g_list_first(ih->list_methods), iface_u->methods[i].member, _compare_dbus_method); - if (!item) { - //_D("attached %s", iface_u->methods[i].member); - ih->list_methods = g_list_prepend(ih->list_methods, (void*)(iface_u->methods + i)); - ++cnt; - } - } - - if (cnt) - ih->modified = TRUE; - -out: - /*todo: delete debugging log */ - //if (dh && dh->list_object) - // _D("obj list len %d", g_list_length(dh->list_object)); - //if (oh && oh->list_ifaces) - // _D("iface list len %d", g_list_length(oh->list_ifaces)); - //if (ih && ih->list_methods) - // _D("method list len %d", g_list_length(ih->list_methods)); - - return cnt; -} - -int dbus_handle_register_dbus_object_all(dbus_handle_h handle) -{ - dcl_dbus_handle(); - dbus_object_handle_s *oh = NULL; - dbus_interface_s *ih = NULL; - int ret = 0; - - if (!dh) { - dh = _dbus_handle_get_default_connection(); - if (!dh) { - _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); - return -1; - } - } - if (!dh->conn) { - _E("connection is null\n"); - return -1; - } - - if (!dh->list_object) { - _E("obj list is empty"); - return -1; - } - - /*if (dh && dh->list_object) - _D("obj list len %d", g_list_length(dh->list_object));*/ - - for (GList *item = g_list_first(dh->list_object); item != NULL; item = g_list_next(item)) { - oh = (dbus_object_handle_s *)item->data; - - if (!oh) { - _E("something wrong"); - assert(0); - } - if (!oh->list_ifaces) { - _E("path %s: list_ifaces are null", oh->path); - goto err; - } - - //_D("iface list len %d", g_list_length(oh->list_ifaces)); - - for (GList *li = g_list_first(oh->list_ifaces); li != NULL; li = g_list_next(li)) { - ih = (dbus_interface_s *)li->data; - - /* if there are no modification, goto next */ - if (!ih->modified) - continue; - - /* todo: if already registered interface, unregister first */ - - /*_E("interface %s:", ih->name); - if (ih && ih->list_methods) - _D("method list len %d", g_list_length(ih->list_methods));*/ - - ret = _dbus_handle_register_dbus_object(dh, oh->path, ih); - if (ret <= 0) - _E("failed to register dbus object%d", ret); - - } - } - return 0; -err: - - // todo: delete all updates - - return -1; -} - -static void _free_func_signal(gpointer data) -{ - //_D("free signal subscribe"); -} - -guint subscribe_dbus_signal(dbus_handle_h handle, const char *path, - const char *iface, const char *name, - GDBusSignalCallback cb, void *data, - destroy_notified free_func) -{ - dcl_dbus_handle(); - - if (!dh) { - dh = _dbus_handle_get_default_connection(); - if (!dh) { - _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); - return 0; - } - } - - if (!dh->conn) { - _E("connection is null. check bus status"); - return 0; - } - return g_dbus_connection_signal_subscribe(dh->conn, NULL, iface, name, path, NULL, G_DBUS_SIGNAL_FLAGS_NONE, cb, data, _free_func_signal); -} - -void unsubscribe_dbus_signal(dbus_handle_h handle, guint id) -{ - dcl_dbus_handle(); - if (!dh) { - dh = _dbus_handle_get_default_connection(); - if (!dh) { - _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); - return ; - } - } - - if (!dh->conn) { - _E("connection is null. check bus status"); - return ; - } - - g_dbus_connection_signal_unsubscribe(dh->conn, id); -} - -int _check_type_string_is_container(const char *signature) -{ - if (!signature) - return FALSE; - - switch (signature[0]) { - case 'a': - case 'm': - case 'r': - case '(': - case '{': - case 'v': - return TRUE; - default: - return FALSE; - } - - return TRUE; -} - -GVariant *dbus_handle_make_simple_array(const char *sig, int *param) -{ - GVariantBuilder *builder = NULL; - GVariant *var = NULL; - char format[256]; - int i = 0; - - builder = g_variant_builder_new(G_VARIANT_TYPE(sig)); - if (!builder) { - _E("failed to g_variant_builder_new"); - return NULL; - } - - while (param[i]) - g_variant_builder_add(builder, "i", param[i++]); - - snprintf(format, sizeof(format) - 1, "(%s)", sig); - var = g_variant_new(format, builder); - g_variant_builder_unref(builder); - return var; -} - -/* todo: looks like garbage... */ -static GVariant* _append_variant(const char *signature, const char *param[]) -{ - char *ch; - int i; - int pi; - int int_type; - gboolean bool_type; - unsigned long long int64_type; - GVariant *ret; - int len; - char container[255];// The maximum length of a signature is 255. - const char *sig = signature; - GVariantBuilder *builder = NULL; - - if (!signature || !param) - return 0; - - /* workaround for user fault "(i) != i" but we treat this as same signature */ - /* G_VARIANT_TYPE("si") return NULL */ - /* todo: actually user have to use correct signature */ - if (!_check_type_string_is_container(signature)) { - snprintf(container, sizeof(container) - 1, "(%s)", signature); - sig = container; - } - if (!g_variant_type_is_container(G_VARIANT_TYPE(sig))) { - _E("signature (%s) is not container type", signature); - } - - builder = g_variant_builder_new(G_VARIANT_TYPE(sig)); - len = strlen(sig); - pi = 0; - for (ch = (char *)sig, i = 0; i < len; ++i, ++ch) { - switch (*ch) { - case '(': - case ')': - continue; - case 'b': - bool_type = (atoi(param[pi++]) == 0 ? FALSE : TRUE); - g_variant_builder_add(builder, "b", bool_type); - break; - case 'i': - int_type = atoi(param[pi++]); - g_variant_builder_add(builder, "i", int_type); - break; - case 'u': - int_type = strtoul(param[pi++], NULL, 10); - g_variant_builder_add(builder, "u", int_type); - break; - case 't': - int64_type = atoll(param[pi++]); - g_variant_builder_add(builder, "t", int64_type); - break; - case 's': - g_variant_builder_add(builder, "s", param[pi++]); - break; - case 'a': - ++ch; - switch (*ch) { - case 'y': - g_variant_builder_add(builder, "^ay", param[pi++]); - ++i; - break; - default: - break; - } - break; - default: - break; - } - } - ret = g_variant_builder_end(builder); - g_variant_builder_clear(builder); - g_variant_builder_unref(builder); - - return ret; -} - -int dbus_handle_broadcast_dbus_signal(const char *path, - const char *iface, - const char *name, - const char *signature, - const char *param[]) -{ - dbus_handle_s *dh = NULL; - GError *err = NULL; - gboolean ret = 0; - GVariant *var = NULL; - - dh = _dbus_handle_get_default_connection(); - if (!dh) { - _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); - return -1; - } - - if (signature && param) - var = _append_variant(signature, param); - ret = g_dbus_connection_emit_signal(dh->conn, NULL, path, iface, name, var, &err); - if (err) { - _E("%d %s\n", ret, err ? err->message : NULL); - g_error_free(err); - } - - return ret; -} - -int dbus_handle_broadcast_dbus_signal_var(const char *path, - const char *iface, - const char *name, - GVariant *param) -{ - dbus_handle_s *dh = NULL; - GError *err = NULL; - gboolean ret = 0; - - dh = _dbus_handle_get_default_connection(); - if (!dh) { - _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); - return -1; - } - - ret = g_dbus_connection_emit_signal(dh->conn, NULL, path, iface, name, param, &err); - if (err) { - _E("%d %s\n", ret, err ? err->message : NULL); - g_error_free(err); - } - - return ret; -} - -GVariant *dbus_handle_method_sync_with_reply(const char *dest, - const char *path, - const char *iface, - const char *method, - const char *signature, - const char *param[]) -{ - GError *err = NULL; - GVariant * var = NULL; - GVariant * ret = NULL; - dbus_handle_s *dh = NULL; - - if (!dest || !path || !iface || !method) { - _E("wrong parameters dest(%s) path(%s) iface(%s) method(%s)", dest, path, iface, method); - return NULL; - } - - dh = _dbus_handle_get_default_connection(); - if (!dh) { - _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); - return NULL; - } - - if (signature && param) - var = _append_variant(signature, param); - - ret = g_dbus_connection_call_sync(dh->conn, - dest, path, iface, method, - var, NULL, G_DBUS_CALL_FLAGS_NONE, DBUS_REPLY_TIMEOUT, NULL, &err); - if (!ret || err) { - if (err) { - _E("failed to g_dbus_connection_call_sync:%s", err->message); - g_error_free(err); - } else { - _E("failed to g_dbus_connection_call_sync"); - g_variant_unref(var); - } - return NULL; - } - - return ret; -} - -GVariant *dbus_handle_method_sync_with_reply_var(const char *dest, - const char *path, - const char *iface, - const char *method, - GVariant *var) -{ - GError *err = NULL; - GVariant * ret = NULL; - dbus_handle_s *dh = NULL; - - if (!dest || !path || !iface || !method) { - _E("wrong parameters dest(%s) path(%s) iface(%s) method(%s)", dest, path, iface, method); - if (var) - g_variant_unref(var); - return NULL; - } - - dh = _dbus_handle_get_default_connection(); - if (!dh) { - _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); - if (var) - g_variant_unref(var); - return NULL; - } - - ret = g_dbus_connection_call_sync(dh->conn, - dest, path, iface, method, - var, NULL, G_DBUS_CALL_FLAGS_NONE, DBUS_REPLY_TIMEOUT, NULL, &err); - if (!ret || err) { - if (err) { - _E("failed to g_dbus_connection_call_sync:%s", err->message); - g_error_free(err); - } else { - _E("failed to g_dbus_connection_call_sync"); - } - return NULL; - } - - return ret; -} - -gint* dbus_handle_get_unix_fd_list(GDBusMethodInvocation *invocation, int *size) -{ - GUnixFDList *fd_list = NULL; - int length = 0; - - fd_list = g_dbus_message_get_unix_fd_list(g_dbus_method_invocation_get_message(invocation)); - - if (!fd_list) { - _E("failed to g_unix_fd_list_get_length: fd_list is null"); - return NULL; - } - - length = g_unix_fd_list_get_length(fd_list); - if (length == 0) { - _E("failed to g_unix_fd_list_get_length: list size is 0"); - return NULL; - } - if (size) - *size = length; - - return g_unix_fd_list_steal_fds(fd_list, NULL); -} - -GVariant *dbus_handle_method_with_unix_fd_list_sync_with_reply(const char *dest, - const char *path, - const char *iface, - const char *method, - const char *signature, - const char *param[], - int *in_fdlist, - int in_size, - int **out_fdlist, - int *out_size) -{ - GError *err = NULL; - GVariant * var = NULL; - GVariant * ret = NULL; - dbus_handle_s *dh = NULL; - GDBusProxy *proxy = NULL; - GUnixFDList *g_infdlist = NULL; - GUnixFDList *g_outfdlist = NULL; - - if (!dest || !path || !iface || !method) { - _E("wrong parameters dest(%s) path(%s) iface(%s) method(%s)", dest, path, iface, method); - return NULL; - } - if (in_fdlist && in_size == 0) { - _E("wrong in_fdlist is not null but in_size is 0"); - return NULL; - } - - dh = _dbus_handle_get_default_connection(); - if (!dh) { - _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); - return NULL; - } - - if (signature && param) - var = _append_variant(signature, param); - - proxy = g_dbus_proxy_new_sync(dh->conn, G_DBUS_PROXY_FLAGS_NONE, NULL, dest, path, iface, NULL, &err); - if (!proxy) { - if (err) { - _E("failed to proxy_new_sync(%s)\n", err->message); - g_error_free(err); - } else { - _E("failed to proxy_new_sync\n"); - if (var) - g_variant_unref(var); - } - } - - /* append fd */ - if (in_fdlist) { - g_infdlist = g_unix_fd_list_new_from_array(in_fdlist, in_size); - if (!g_infdlist) { - _E("failed to g_unix_fd_list_new_from_array\n"); - goto out; - } - //g_infdlist = g_unix_fd_list_new(); - //if (g_unix_fd_list_append(g_infdlist, in_fdlist[0], &err) < 0) { - } - - ret = g_dbus_proxy_call_with_unix_fd_list_sync(proxy, method, var, G_DBUS_CALL_FLAGS_NONE, -1, - g_infdlist, &g_outfdlist, NULL, &err); - if (!ret || err) { - if (err) { - _E("failed to g_dbus_proxy_call_with_unix_fd_list_sync:%s", err->message); - g_error_free(err); - } else { - _E("failed to g_dbus_proxy_call_with_unix_fd_list_sync:"); - if (var) - g_variant_unref(var); - if (g_infdlist) - g_object_unref(g_infdlist); - } - goto out; - } - - /* fds to out array */ - if (g_outfdlist) { - *out_size = g_unix_fd_list_get_length(g_outfdlist); - if (*out_size == 0) - goto out; - - *out_fdlist = g_unix_fd_list_steal_fds(g_outfdlist, NULL); - } - -out: - if (g_outfdlist) - g_object_unref(g_outfdlist); - if (proxy) - g_object_unref(proxy); - - return ret; -} - -GVariant *dbus_handle_method_with_unix_fd_list_sync_with_reply_var(const char *dest, - const char *path, - const char *iface, - const char *method, - GVariant *param, - int *in_fdlist, - int in_size, - int **out_fdlist, - int *out_size) -{ - GError *err = NULL; - GVariant * ret = NULL; - dbus_handle_s *dh = NULL; - GDBusProxy *proxy = NULL; - GUnixFDList *g_infdlist = NULL; - GUnixFDList *g_outfdlist = NULL; - - if (!dest || !path || !iface || !method) { - _E("wrong parameters dest(%s) path(%s) iface(%s) method(%s)", dest, path, iface, method); - return NULL; - } - if (in_fdlist && in_size == 0) { - _E("wrong in_fdlist is not null but in_size is 0"); - return NULL; - } - - dh = _dbus_handle_get_default_connection(); - if (!dh) { - _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); - return NULL; - } - - proxy = g_dbus_proxy_new_sync(dh->conn, G_DBUS_PROXY_FLAGS_NONE, NULL, dest, path, iface, NULL, &err); - if (!proxy) { - if (err) { - _E("failed to proxy_new_sync(%s)\n", err->message); - g_error_free(err); - } else { - _E("failed to proxy_new_sync\n"); - if (param) - g_variant_unref(param); - } - goto out; - } - - /* append fd */ - if (in_fdlist) { - g_infdlist = g_unix_fd_list_new_from_array(in_fdlist, in_size); - if (!g_infdlist) { - _E("failed to g_unix_fd_list_new_from_array\n"); - goto out; - } - //g_infdlist = g_unix_fd_list_new(); - //if (g_unix_fd_list_append(g_infdlist, in_fdlist[0], &err) < 0) { - } - - /* send message */ - ret = g_dbus_proxy_call_with_unix_fd_list_sync(proxy, method, param, G_DBUS_CALL_FLAGS_NONE, -1, - g_infdlist, &g_outfdlist, NULL, &err); - if (!ret || err) { - if (err) { - _E("failed to g_dbus_proxy_call_with_unix_fd_list_sync:%s", err->message); - g_error_free(err); - } else { - _E("failed to g_dbus_proxy_call_with_unix_fd_list_sync:"); - if (param) - g_variant_unref(param); - if (g_infdlist) - g_object_unref(g_infdlist); - } - goto out; - } - - /* copy fds to out array */ - if (g_outfdlist) { - *out_size = g_unix_fd_list_get_length(g_outfdlist); - if (*out_size == 0) - goto out; - *out_fdlist = g_unix_fd_list_steal_fds(g_outfdlist, NULL); - } -out: - if (g_outfdlist) - g_object_unref(g_outfdlist); - if (proxy) - g_object_unref(proxy); - return ret; -} - -int dbus_handle_method_sync(const char *dest, - const char *path, - const char *iface, - const char *method, - const char *signature, - const char *param[]) -{ - int result; - gboolean result_bool; - GVariant *reply = NULL; - - if (!dest || !path || !iface || !method) { - _E("wrong parameters dest(%s) path(%s) iface(%s) method(%s)", dest, path, iface, method); - return -1; - } - - reply = dbus_handle_method_sync_with_reply(dest, path, iface, method, signature, param); - if (!reply) - return -ECOMM; - - if (g_strcmp0("(i)", g_variant_get_type_string(reply)) == 0) { - g_variant_get(reply, "(i)", &result); - } else if (g_strcmp0("(b)", g_variant_get_type_string(reply)) == 0) { - g_variant_get(reply, "(b)", &result_bool); - result = (int)result_bool; - } else { - result = -ENOMSG; - } - - g_variant_unref(reply); - - return result; -} - -int dbus_handle_method_sync_var(const char *dest, - const char *path, - const char *iface, - const char *method, - GVariant *param) -{ - int result; - gboolean result_bool; - GVariant *reply = NULL; - - if (!dest || !path || !iface || !method) { - _E("wrong parameters dest(%s) path(%s) iface(%s) method(%s)", dest, path, iface, method); - return -1; - } - - reply = dbus_handle_method_sync_with_reply_var(dest, path, iface, method, param); - if (!reply) - return -ECOMM; - - if (g_strcmp0("(i)", g_variant_get_type_string(reply)) == 0) { - g_variant_get(reply, "(i)", &result); - } else if (g_strcmp0("(b)", g_variant_get_type_string(reply)) == 0) { - g_variant_get(reply, "(b)", &result_bool); - result = (int)result_bool; - } else { - result = -ENOMSG; - } - - g_variant_unref(reply); - - return result; -} - -int dbus_handle_method_sync_timeout(const char *dest, - const char *path, - const char *iface, - const char *method, - const char *signature, - const char *param[], - int timeout) -{ - dbus_handle_s *dh = NULL; - GError *err = NULL; - GVariant * var = NULL; - GVariant * reply = NULL; - int result = 0; - - if (!dest || !path || !iface || !method) { - _E("wrong parameters dest(%s) path(%s) iface(%s) method(%s)", dest, path, iface, method); - return -1; - } - - dh = _dbus_handle_get_default_connection(); - if (!dh) { - _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); - return -EPERM; - } - - if (signature && param) - var = _append_variant(signature, param); - - reply = g_dbus_connection_call_sync(dh->conn, - dest, path, iface, method, - var, NULL, G_DBUS_CALL_FLAGS_NONE, timeout, NULL, &err); - if (!reply || err) { - _E("failed to g_dbus_connection_call_sync:%s", err->message); - g_error_free(err); - return -1; - } - - if (g_strcmp0("(i)", g_variant_get_type_string(reply)) == 0) - g_variant_get(reply, "(i)", &result); - else - result = -ENOMSG; - - g_variant_unref(reply); - - return result; -} - -int dbus_handle_method_sync_pairs(const char *dest, - const char *path, - const char *iface, - const char *method, - int num, - va_list args) -{ - GError *err = NULL; - GVariant * reply = NULL; - char *key, *value; - int ret = 0; - GVariant *var; - GVariantBuilder *builder; - dbus_handle_s *dh = NULL; - - if (!dest || !path || !iface || !method) { - _E("wrong parameters dest(%s) path(%s) iface(%s) method(%s)", dest, path, iface, method); - return -1; - } - - dh = _dbus_handle_get_default_connection(); - if (!dh) { - _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); - return -1; - } - - builder = g_variant_builder_new(G_VARIANT_TYPE("a{ss}")); - - for (int i = 0 ; i < num ; i = i + 2) { - key = va_arg(args, char *); - value = va_arg(args, char *); - _I("key(%s), value(%s)", key, value); - g_variant_builder_add(builder, "{ss}", key, value); - } - - var = g_variant_new("(a{ss})", builder); - g_variant_builder_unref(builder); - - reply = g_dbus_connection_call_sync(dh->conn, - dest, path, iface, method, - var, NULL, G_DBUS_CALL_FLAGS_NONE, DBUS_REPLY_TIMEOUT, NULL, &err); - if (!reply || err) { - _E("failed to g_dbus_connection_call_sync"); - return -1; - } - - if (g_strcmp0("(i)", g_variant_get_type_string(reply)) == 0) - g_variant_get(reply, "(i)", &ret); - else - ret = -ENOMSG; - - g_variant_unref(reply); - - return ret; -} - -int dbus_handle_method_async_pairs(const char *dest, - const char *path, - const char *iface, - const char *method, - int num, - va_list args) -{ - char *key, *value; - GVariant *var; - GVariantBuilder *builder; - dbus_handle_s *dh = NULL; - - if (!dest || !path || !iface || !method) { - _E("wrong parameters dest(%s) path(%s) iface(%s) method(%s)", dest, path, iface, method); - return -1; - } - - dh = _dbus_handle_get_default_connection(); - if (!dh) { - _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); - return -1; - } - - // dict - builder = g_variant_builder_new(G_VARIANT_TYPE("a{ss}")); - - for (int i = 0 ; i < num ; i = i + 2) { - key = va_arg(args, char *); - value = va_arg(args, char *); - _I("key(%s), value(%s)", key, value); - g_variant_builder_add(builder, "{ss}", key, value); - } - - var = g_variant_new("(a{ss})", builder); - g_variant_builder_unref(builder); - - g_dbus_connection_call(dh->conn, dest, path, iface, method, - var, NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, - NULL, - NULL); - - return 0; -} - -int dbus_handle_method_async(const char *dest, - const char *path, - const char *iface, - const char *method, - const char *signature, - const char *param[]) -{ - GVariant * var = NULL; - dbus_handle_s *dh = NULL; - - if (!dest || !path || !iface || !method) { - _E("wrong parameters dest(%s) path(%s) iface(%s) method(%s)", dest, path, iface, method); - return -1; - } - - dh = _dbus_handle_get_default_connection(); - if (!dh) { - _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); - return -1; - } - - if (signature && param) - var = _append_variant(signature, param); - - g_dbus_connection_call(dh->conn, dest, path, iface, method, - var, NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, - NULL, - NULL); - - return 0; -} - -int dbus_handle_method_async_var(const char *dest, - const char *path, - const char *iface, - const char *method, - GVariant *param) -{ - dbus_handle_s *dh = NULL; - - if (!dest || !path || !iface || !method) { - _E("wrong parameters dest(%s) path(%s) iface(%s) method(%s)", dest, path, iface, method); - return -1; - } - - dh = _dbus_handle_get_default_connection(); - if (!dh) { - _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); - return -1; - } - - g_dbus_connection_call(dh->conn, dest, path, iface, method, - param, NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, - NULL, - NULL); - - return 0; -} - -/* callback should free gvariant */ -static void _cb_pending(GDBusConnection *conn, - GAsyncResult *res, - gpointer user_data) -{ - GVariant *reply = NULL; - GError *err = NULL; - pending_call_data *data = (pending_call_data *)user_data; - - reply = g_dbus_connection_call_finish(conn, res, &err); - if (!reply || err) { - if (err) { - _E("no message : [%s]", err->message); - g_error_free(err); - } else { - _E("no message"); - } - - if (data && data->func) - data->func(NULL, data->data, err); - goto out; - } - - if (data && data->func) - data->func(reply, data->data, err); -out: - if (data) - free(data); -} - -int dbus_handle_method_async_with_reply(const char *dest, - const char *path, - const char *iface, - const char *method, - const char *signature, - const char *param[], - dbus_pending_cb cb, - int timeout_msec, - void *data) -{ - dbus_handle_s *dh = NULL; - pending_call_data *pdata = NULL; - GVariant * var = NULL; - int ret = 0; - - if (!dest || !path || !iface || !method) { - _E("wrong parameters dest(%s) path(%s) iface(%s) method(%s)", dest, path, iface, method); - return -1; - } - - if (timeout_msec < -1) { - _E("wrong timeout %d", timeout_msec); - return -1; - } - - dh = _dbus_handle_get_default_connection(); - if (!dh) { - _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); - return -EPERM; - } - - if (signature && param) - var = _append_variant(signature, param); - - if (cb) { - pdata = (pending_call_data*)malloc(sizeof(pending_call_data)); - if (!pdata) { - ret = -ENOMEM; - goto err; - } - - pdata->func = cb; - pdata->data = data; - } - g_dbus_connection_call(dh->conn, dest, path, iface, method, - var, NULL, G_DBUS_CALL_FLAGS_NONE, timeout_msec, NULL, - (GAsyncReadyCallback)_cb_pending, - pdata); - - return ret; -err: - if (var) - g_variant_unref(var); - return ret; -} - -int dbus_handle_method_async_with_reply_var(const char *dest, - const char *path, - const char *iface, - const char *method, - GVariant *param, - dbus_pending_cb cb, - int timeout_msec, - void *data) -{ - dbus_handle_s *dh = NULL; - pending_call_data *pdata = NULL; - int ret = 0; - - if (!dest || !path || !iface || !method) { - _E("wrong parameters dest(%s) path(%s) iface(%s) method(%s)", dest, path, iface, method); - return -1; - } - - if (timeout_msec < -1) { - _E("wrong timeout %d", timeout_msec); - return -1; - } - - dh = _dbus_handle_get_default_connection(); - if (!dh) { - _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); - return -EPERM; - } - - if (cb) { - pdata = (pending_call_data*)malloc(sizeof(pending_call_data)); - if (!pdata) { - ret = -ENOMEM; - goto err; - } - - pdata->func = cb; - pdata->data = data; - } - g_dbus_connection_call(dh->conn, dest, path, iface, method, - param, NULL, G_DBUS_CALL_FLAGS_NONE, timeout_msec, NULL, - (GAsyncReadyCallback)_cb_pending, - pdata); - - return ret; -err: - if (param) - g_variant_unref(param); - return ret; -} - -int dbus_connection_get_sender_pid(GDBusConnection *conn, const char * sender) -{ - GError *err = NULL; - GVariant *vret = NULL; - pid_t pid = 0; - - if (!conn) { - _E("connection is null"); - return -1; - } - if (!sender) { - _E("sender is null"); - return -1; - } - - vret = g_dbus_connection_call_sync(conn, - "org.freedesktop.DBus", "/", "org.freedesktop.DBus", "GetConnectionUnixProcessID", - g_variant_new("(s)", sender), - NULL, - G_DBUS_CALL_FLAGS_NONE, - DBUS_REPLY_TIMEOUT, - NULL, - &err); - if (!vret || err) { - _E("failed to g_dbus_connection_call_sync:%s", err->message); - g_error_free(err); - return -1; - } - - g_variant_get(vret, "(u)", &pid); - g_variant_unref(vret); - - return pid; -} - -int dbus_handle_get_sender_pid(dbus_handle_h handle, const char * sender) -{ - dcl_dbus_handle(); - - if (!dh) { - dh = _dbus_handle_get_default_connection(); - if (!dh) { - _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); - return -1; - } - } - if (!dh->conn) { - _E("wrong dbus handle. connection is null"); - assert(0); - return -1; - } - - return dbus_connection_get_sender_pid(dh->conn, sender); -} - -int dbus_handle_get_sender_credentials(dbus_handle_h handle, const char *name, GDBusCredentials *creds) -{ - dcl_dbus_handle(); - GVariant *vret = NULL; - GError *err = NULL; - GVariantIter *iter = NULL; - char * item; - GVariant *sub; - - if (!dh) { - dh = _dbus_handle_get_default_connection(); - if (!dh) { - _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); - return -1; - } - } - vret = g_dbus_connection_call_sync(dh->conn, - DBUS_BUS_NAME, - DBUS_OBJECT_PATH, - DBUS_INTERFACE_NAME, - "GetConnectionCredentials", - g_variant_new("(s)", name), - NULL, - G_DBUS_CALL_FLAGS_NONE, - DBUS_REPLY_TIMEOUT, - NULL, - &err); - if (!vret || err) { - _E("failed to g_dbus_connection_call_sync:%s", err->message); - return -1; - } - - g_variant_get(vret, "(a{sv})", &iter); - - while (g_variant_iter_loop(iter, "{sv}", &item, &sub)) { - if (!g_strcmp0(item, "UnixUserID")) { - g_variant_get(sub, "u", &creds->uid); - //_D("UnixUserID %u", creds->uid); - } else if (!g_strcmp0(item, "ProcessID")) { - g_variant_get(sub, "u", &creds->pid); - //_D("ProcessID %u", creds->pid); - } else if (!g_strcmp0(item, "LinuxSecurityLabel")) { - g_variant_get(sub, "^ay", &creds->sec_label); - //_D("%s", creds->sec_label); - } - } - - if (iter) - g_variant_iter_free(iter); - if (vret) - g_variant_unref(vret); - - return 0; -} - -void _destroy_notify_watch_name(gpointer data) -{ - if (data) - free(data); -} - -int dbus_handle_watch_name(const char *name, - GBusNameAppearedCallback name_appeared_handler, - GBusNameVanishedCallback name_vanished_handler, - void *user_data) -{ - guint id = 0; - - if (!name) { - _E("wrong name name %s", name); - return -1; - } - if (!name_appeared_handler && !name_vanished_handler) { - _E("both function pointers are null"); - return -1; - } - - id = g_bus_watch_name(dbus_handle_get_default_bus_type(), - name, - G_BUS_NAME_WATCHER_FLAGS_NONE, - name_appeared_handler, - name_vanished_handler, - user_data, - _destroy_notify_watch_name); - if (!id) { - _E("failed to g_bus_watch_name"); - return -1; - } - - return id; -} - -void dbus_handle_unwatch_name(guint id) -{ - if (id == 0) { - _E("wrong id %d", id); - return; - } - g_bus_unwatch_name(id); -} - -int _get_cmdline_name(pid_t pid, char *cmdline, size_t cmdline_size) -{ - int fd, ret; - char buf[PATH_MAX + 1]; - char *filename; - - snprintf(buf, sizeof(buf), "/proc/%d/cmdline", pid); - fd = open(buf, O_RDONLY); - if (fd < 0) { - errno = ESRCH; - return -1; - } - - ret = read(fd, buf, PATH_MAX); - close(fd); - if (ret < 0) - return -1; - - buf[PATH_MAX] = '\0'; - - filename = strrchr(buf, '/'); - if (filename == NULL) - filename = buf; - else - filename = filename + 1; - - if (cmdline_size < strlen(filename) + 1) { - errno = EOVERFLOW; - return -1; - } - - strncpy(cmdline, filename, cmdline_size - 1); - cmdline[cmdline_size - 1] = '\0'; - return 0; -} - -// g_strfreev(strv) -char **dbus_handle_get_owner_list(dbus_handle_h handle, const char *bus_name) -{ - dcl_dbus_handle(); - GError *err = NULL; - GVariant *vret = NULL; - GVariantIter *iter = NULL; - gchar **strv = NULL; - gchar *str = NULL; - int i = 0; - - if (!bus_name) { - _E("wrong parameter bus_name(%s)", bus_name); - return NULL; - } - - if (!dh) { - dh = _dbus_handle_get_default_connection(); - if (!dh) { - _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); - return NULL; - } - } - - vret = g_dbus_connection_call_sync(dh->conn, - "org.freedesktop.DBus", - "/", - "org.freedesktop.DBus", - "ListQueuedOwners", - g_variant_new("(s)", bus_name), - NULL, - G_DBUS_CALL_FLAGS_NONE, - DBUS_REPLY_TIMEOUT, - NULL, - &err); - if (!vret || err) { - _E("failed to g_dbus_connection_call_sync:%s", err->message); - g_error_free(err); - return NULL; - } - - g_variant_get(vret, "(as)", &iter); - strv = g_new(gchar *, g_variant_iter_n_children(iter) + 1); - - i = 0; - while (g_variant_iter_loop(iter, "s", &str)) - strv[i++] = g_strdup(str); - strv[i] = NULL; - - g_variant_iter_free(iter); - g_variant_unref(vret); - - return strv; -} - -void dbush_handle_check_owner_name(dbus_handle_h handle, const char *owner_name) -{ - dcl_dbus_handle(); - char exe_name[PATH_MAX]; - int pid; - char **strv = NULL; - int i; - - if (!dh) { - dh = _dbus_handle_get_default_connection(); - if (!dh) { - _E("failed to get default connection, bustype:%d", (int)dbus_handle_get_default_bus_type()); - return ; - } - } - - strv = dbus_handle_get_owner_list(dh, owner_name); - if (!strv) { - _E("failed to get owner list of %s", owner_name); - return ; - } - - for (i = 0; strv[i] != NULL; ++i) { - pid = dbus_handle_get_sender_pid(dh, strv[i]); - if (_get_cmdline_name(pid, exe_name, PATH_MAX) != 0) - break; - _I("%s(%d)", exe_name, pid); - } - - g_strfreev(strv); -} - -dbus_handle_h dbus_handle_init(GBusType type, - const char* bus_name, - GBusNameAcquiredCallback acquired_handler, - GBusNameLostCallback lost_handler) -{ - dbus_handle_h handle = NULL; - int i, ret = 0; - - if (!bus_name) { - _E("Wrong bus name, %s", bus_name); - return NULL; - } - - // todo: do we need retry ? - booting time - for (i = 0 ; i < 3; ++i) { - handle = dbus_handle_get_connection(type, FALSE); - if (handle) - break; - usleep(5000); - } - ret = dbus_handle_request_bus_name(handle, bus_name, acquired_handler, lost_handler); - if (ret <= 0) - goto out; - - dbush_handle_check_owner_name(NULL, bus_name); - - return handle; - -out: - return NULL; -} diff --git a/src/shared/dbus.h b/src/shared/dbus.h deleted file mode 100644 index b887d33..0000000 --- a/src/shared/dbus.h +++ /dev/null @@ -1,462 +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 __DBUS_H__ -#define __DBUS_H__ - -#include -#include -#include -#include -#include - -/* - * Template - * -#define XXX_BUS_NAME "org.tizen.system.XXX" -#define XXX_OBJECT_PATH "/Org/Tizen/System/XXX" -#define XXX_INTERFACE_NAME XXX_BUS_NAME -#define XXX_PATH_YYY XXX_OBJECT_PATH"/YYY" -#define XXX_INTERFACE_YYY XXX_INTERFACE_NAME".YYY" -#define XXX_SIGNAL_ZZZ "ZZZ" -#define XXX_METHOD_ZZZ "ZZZ" - */ - -/* - * DBus daemon - */ -#define DBUS_BUS_NAME "org.freedesktop.DBus" -#define DBUS_OBJECT_PATH "/org/freedesktop/DBus" -#define DBUS_INTERFACE_NAME DBUS_BUS_NAME - -/* - * Device daemon - */ -#define DEVICED_BUS_NAME "org.tizen.system.deviced" -#define DEVICED_OBJECT_PATH "/Org/Tizen/System/DeviceD" -#define DEVICED_INTERFACE_NAME DEVICED_BUS_NAME -/* Core service: get/set device status operations about device */ -#define DEVICED_PATH_CORE DEVICED_OBJECT_PATH"/Core" -#define DEVICED_INTERFACE_CORE DEVICED_INTERFACE_NAME".core" -/* Display service: start/stop display(pm), get/set brightness operations about display */ -#define DEVICED_PATH_DISPLAY DEVICED_OBJECT_PATH"/Display" -#define DEVICED_INTERFACE_DISPLAY DEVICED_INTERFACE_NAME".display" -/* Pass service: start/stop pass operations about pass */ -#define DEVICED_PATH_PASS DEVICED_OBJECT_PATH"/Pass" -#define DEVICED_INTERFACE_PASS DEVICED_INTERFACE_NAME".pass" -/* Power service: set resetkey disable operations about power */ -#define DEVICED_PATH_POWER DEVICED_OBJECT_PATH"/Power" -#define DEVICED_INTERFACE_POWER DEVICED_INTERFACE_NAME".power" -/* Low Power service: start/stop low power mode */ -#define DEVICED_PATH_LOWPOWER DEVICED_OBJECT_PATH"/LowPower" -#define DEVICED_INTERFACE_LOWPOWER DEVICED_INTERFACE_NAME".lowpower" -/* Reboot service: request reboot operation */ -#define DEVICED_PATH_REBOOT DEVICED_OBJECT_PATH"/Reboot" -#define DEVICED_INTERFACE_REBOOT DEVICED_INTERFACE_NAME".reboot" -/* Storage service: get storage size operatioins about storage */ -#define DEVICED_PATH_STORAGE DEVICED_OBJECT_PATH"/Storage" -#define DEVICED_INTERFACE_STORAGE DEVICED_INTERFACE_NAME".storage" -/* ODE service: request ode popup result operatioins about storage */ -#define DEVICED_PATH_SDE DEVICED_OBJECT_PATH"/Sde" -#define DEVICED_INTERFACE_SDE DEVICED_INTERFACE_NAME".sde" -#define DEVICED_PATH_ODE DEVICED_OBJECT_PATH"/Ode" -#define DEVICED_INTERFACE_ODE DEVICED_INTERFACE_NAME".ode" -/* Lowmem service: get critical low status operations about Lowmem */ -#define DEVICED_PATH_LOWMEM DEVICED_OBJECT_PATH"/Lowmem" -#define DEVICED_INTERFACE_LOWMEM DEVICED_INTERFACE_NAME".lowmem" -/* Poweroff service: get power off status operations about Poweroff */ -#define DEVICED_PATH_POWEROFF DEVICED_OBJECT_PATH"/PowerOff" -#define DEVICED_INTERFACE_POWEROFF DEVICED_INTERFACE_NAME".PowerOff" -/* Led service: play/stop led operations about led */ -#define DEVICED_PATH_LED DEVICED_OBJECT_PATH"/Led" -#define DEVICED_INTERFACE_LED DEVICED_INTERFACE_NAME".Led" -/* Block service: manage block device */ -#define STORAGE_BUS_NAME "org.tizen.system.storage" -#define STORAGE_OBJECT_PATH "/Org/Tizen/System/Storage" -#define STORAGE_INTERFACE_NAME STORAGE_BUS_NAME -#define DEVICED_PATH_BLOCK STORAGE_OBJECT_PATH"/Block" -#define DEVICED_PATH_BLOCK_MANAGER DEVICED_PATH_BLOCK"/Manager" -#define DEVICED_INTERFACE_BLOCK_MANAGER STORAGE_INTERFACE_NAME".BlockManager" -/* MMC service: mount/unmount/format mmc operations about mmc */ -#define DEVICED_PATH_MMC DEVICED_OBJECT_PATH"/Mmc" -#define DEVICED_INTERFACE_MMC DEVICED_INTERFACE_NAME".Mmc" -/* Process service: operations about process */ -#define DEVICED_PATH_PROCESS DEVICED_OBJECT_PATH"/Process" -#define DEVICED_INTERFACE_PROCESS DEVICED_INTERFACE_NAME".Process" -/* Key service: operations about key */ -#define DEVICED_PATH_KEY DEVICED_OBJECT_PATH"/Key" -#define DEVICED_INTERFACE_KEY DEVICED_INTERFACE_NAME".Key" -/* USB client service: change usb connection mode */ -#define DEVICED_PATH_USB DEVICED_OBJECT_PATH"/Usb" -#define DEVICED_INTERFACE_USB DEVICED_INTERFACE_NAME".Usb" -/* USB start/stop service: operations about usb start/stop */ -#define DEVICED_PATH_USB_CONTROL DEVICED_OBJECT_PATH"/UsbControl" -#define DEVICED_INTERFACE_USB_CONTROL DEVICED_INTERFACE_NAME".UsbControl" -/* USB host service: operations about usb start/stop */ -#define DEVICED_PATH_USBHOST DEVICED_OBJECT_PATH"/Usbhost" -#define DEVICED_INTERFACE_USBHOST DEVICED_INTERFACE_NAME".Usbhost" -/* Sysnoti service */ -#define DEVICED_PATH_SYSNOTI DEVICED_OBJECT_PATH"/SysNoti" -#define DEVICED_INTERFACE_SYSNOTI DEVICED_INTERFACE_NAME".SysNoti" -/* ExtCon service */ -#define DEVICED_PATH_EXTCON DEVICED_OBJECT_PATH"/ExtCon" -#define DEVICED_INTERFACE_EXTCON DEVICED_INTERFACE_NAME".ExtCon" -/* Battery service */ -#define DEVICED_PATH_BATTERY DEVICED_OBJECT_PATH"/Battery" -#define DEVICED_INTERFACE_BATTERY DEVICED_INTERFACE_NAME".Battery" -/* Time service */ -#define DEVICED_PATH_TIME DEVICED_OBJECT_PATH"/Time" -#define DEVICED_INTERFACE_TIME DEVICED_INTERFACE_NAME".Time" -/* IR service */ -#define DEVICED_PATH_IR DEVICED_OBJECT_PATH"/Ir" -#define DEVICED_INTERFACE_IR DEVICED_INTERFACE_NAME".ir" -/* USB_HOST_TEST service */ -#define DEVICED_PATH_USB_HOST_TEST DEVICED_OBJECT_PATH"/UsbHostTest" -#define DEVICED_INTERFACE_USB_HOST_TEST DEVICED_INTERFACE_NAME".UsbHostTest" - -/* HDMICEC service: status check about gpio */ -#define DEVICED_PATH_HDMICEC DEVICED_OBJECT_PATH"/HdmiCec" -#define DEVICED_INTERFACE_HDMICEC DEVICED_INTERFACE_NAME".HdmiCec" - -/* Tzip service: Archive file system */ -#define DEVICED_PATH_TZIP DEVICED_OBJECT_PATH"/Tzip" -#define DEVICED_INTERFACE_TZIP DEVICED_INTERFACE_NAME".Tzip" - -/* - * Vibrator daemon - */ -#define VIBRATOR_BUS_NAME "org.tizen.system.vibrator" -#define VIBRATOR_OBJECT_PATH "/Org/Tizen/System/Vibrator" -#define VIBRATOR_INTERFACE_NAME VIBRATOR_BUS_NAME -/* Core service: get/set device status operations about device */ -#define VIBRATOR_PATH_CORE VIBRATOR_OBJECT_PATH"/Core" -#define VIBRATOR_INTERFACE_CORE VIBRATOR_INTERFACE_NAME".core" - -#define VIBRATOR_PATH_HAPTIC VIBRATOR_OBJECT_PATH"/Haptic" -#define VIBRATOR_INTERFACE_HAPTIC VIBRATOR_INTERFACE_NAME".haptic" - -/* - * Resource daemon - */ -#define RESOURCED_BUS_NAME "org.tizen.resourced" -#define RESOURCED_OBJECT_PATH "/Org/Tizen/ResourceD" -#define RESOURCED_INTERFACE_NAME RESOURCED_BUS_NAME - -#define RESOURCED_PATH_PROCESS RESOURCED_OBJECT_PATH"/Process" -#define RESOURCED_INTERFACE_PROCESS RESOURCED_INTERFACE_NAME".process" -#define RESOURCED_METHOD_ACTIVE "Active" - -#define RESOURCED_PATH_FREEZER RESOURCED_OBJECT_PATH"/Freezer" -#define RESOURCED_INTERFACE_FREEZER RESOURCED_INTERFACE_NAME".freezer" - -#define RESOURCED_PATH_SLUGGISH RESOURCED_OBJECT_PATH"/Sluggish" -#define RESOURCED_INTERFACE_SLUGGISH RESOURCED_INTERFACE_NAME".sluggish" -#define RESOURCED_SIGNAL_SLUGGISH "SluggishDetected" - -#define RESOURCED_PATH_LOGGING RESOURCED_OBJECT_PATH"/Logging" -#define RESOURCED_INTERFACE_LOGGING RESOURCED_INTERFACE_NAME".logging" -/* - * Popup launcher - */ -#define POPUP_BUS_NAME "org.tizen.system.popup" -#define POPUP_OBJECT_PATH "/Org/Tizen/System/Popup" -#define POPUP_INTERFACE_NAME POPUP_BUS_NAME -/* LED */ -#define POPUP_PATH_LED POPUP_OBJECT_PATH"/Led" -#define POPUP_INTERFACE_LED POPUP_INTERFACE_NAME".Led" -/* Notification */ -#define POPUP_PATH_NOTI POPUP_OBJECT_PATH"/Noti" -#define POPUP_INTERFACE_NOTI POPUP_INTERFACE_NAME".Noti" -/* Power key longpress */ -#define POPUP_PATH_POWERKEY POPUP_OBJECT_PATH"/Powerkey" -#define POPUP_INTERFACE_POWERKEY POPUP_INTERFACE_NAME".Powerkey" -/* Low battery */ -#define POPUP_PATH_LOWBAT POPUP_OBJECT_PATH"/Lowbat" -#define POPUP_INTERFACE_LOWBAT POPUP_INTERFACE_NAME".Lowbat" -/* Low memory */ -#define POPUP_PATH_LOWMEM POPUP_OBJECT_PATH"/Lowmem" -#define POPUP_INTERFACE_LOWMEM POPUP_INTERFACE_NAME".Lowmem" -/* MMC */ -#define POPUP_PATH_MMC POPUP_OBJECT_PATH"/Mmc" -#define POPUP_INTERFACE_MMC POPUP_INTERFACE_NAME".Mmc" -/* USB */ -#define POPUP_PATH_USB POPUP_OBJECT_PATH"/Usb" -#define POPUP_INTERFACE_USB POPUP_INTERFACE_NAME".Usb" -/* USB otg */ -#define POPUP_PATH_USBOTG POPUP_OBJECT_PATH"/Usbotg" -#define POPUP_INTERFACE_USBOTG POPUP_INTERFACE_NAME".Usbotg" -/* USB host */ -#define POPUP_PATH_USBHOST POPUP_OBJECT_PATH"/Usbhost" -#define POPUP_INTERFACE_USBHOST POPUP_INTERFACE_NAME".Usbhost" -/* System */ -#define POPUP_PATH_SYSTEM POPUP_OBJECT_PATH"/System" -#define POPUP_INTERFACE_SYSTEM POPUP_INTERFACE_NAME".System" -/* Overheat */ -#define POPUP_PATH_OVERHEAT POPUP_OBJECT_PATH"/Overheat" -#define POPUP_INTERFACE_OVERHEAT POPUP_INTERFACE_NAME".Overheat" -/* Crash */ -#define POPUP_PATH_CRASH POPUP_OBJECT_PATH"/Crash" -#define POPUP_INTERFACE_CRASH POPUP_INTERFACE_NAME".Crash" -/* Servant */ -#define POPUP_PATH_SERVANT POPUP_OBJECT_PATH"/Servant" -#define POPUP_IFACE_SERVANT POPUP_INTERFACE_NAME".Servant" - -#define POPUP_PATH_APP POPUP_OBJECT_PATH"/Apps" -#define POPUP_IFACE_APP POPUP_BUS_NAME".Apps" - -#define POPUP_METHOD_LAUNCH "PopupLaunch" -#define POPUP_METHOD_TERMINATE "AppTerminateByPid" -#define POPUP_KEY_CONTENT "_SYSPOPUP_CONTENT_" - -/* - * Crash daemon - */ -#define CRASHD_BUS_NAME "org.tizen.system.crashd" -#define CRASHD_OBJECT_PATH "/Org/Tizen/System/CrashD" -#define CRASHD_INTERFACE_NAME CRASHD_BUS_NAME - -#define CRASHD_PATH_CRASH CRASHD_OBJECT_PATH"/Crash" -#define CRASHD_INTERFACE_CRASH CRASHD_INTERFACE_NAME".Crash" - -/* - * Device Manager Policy Popup - */ -#define DEVICEMANAGER_BUS_NAME "org.tizen.DevicePolicyManager" -#define DEVICEMANAGER_OBJECT_PATH "/org/tizen/DevicePolicyManager" -#define DEVICEMANAGER_INTERFACE_NAME DEVICEMANAGER_BUS_NAME - -#define DEVICEMANAGER_PATH_POPUP DEVICEMANAGER_OBJECT_PATH"/Syspopup" -#define DEVICEMANAGER_INTERFACE_POPUP DEVICEMANAGER_INTERFACE_NAME".Syspopup" - - -/***************************************************************/ -/* Experimental for Specific device - contact to deviced owner */ -/***************************************************************/ - -/* Hall service: get hall status operations about hall */ -#define DEVICED_PATH_HALL DEVICED_OBJECT_PATH"/Hall" -#define DEVICED_INTERFACE_HALL DEVICED_INTERFACE_NAME".hall" -/* Cpu service: operations about cpu */ -#define DEVICED_PATH_CPU DEVICED_OBJECT_PATH"/Cpu" -#define DEVICED_INTERFACE_CPU DEVICED_INTERFACE_NAME".Cpu" -/* PmQos service: operations about pmqos */ -#define DEVICED_PATH_PMQOS DEVICED_OBJECT_PATH"/PmQos" -#define DEVICED_INTERFACE_PMQOS DEVICED_INTERFACE_NAME".PmQos" -/* Apps service */ -#define DEVICED_PATH_APPS DEVICED_OBJECT_PATH"/Apps" -#define DEVICED_INTERFACE_APPS DEVICED_INTERFACE_NAME".Apps" -/* GPIO service: status check about gpio */ -#define DEVICED_PATH_GPIO DEVICED_OBJECT_PATH"/Gpio" -#define DEVICED_INTERFACE_GPIO DEVICED_INTERFACE_NAME".Gpio" -/* Board service */ -#define DEVICED_PATH_BOARD DEVICED_OBJECT_PATH"/Board" -#define DEVICED_INTERFACE_BOARD DEVICED_INTERFACE_NAME".Board" -/* Csa service */ -#define DEVICED_PATH_CSA DEVICED_OBJECT_PATH"/Csa" -#define DEVICED_INTERFACE_CSA DEVICED_INTERFACE_NAME".Csa" -/* dump service */ -#define DUMP_SERVICE_BUS_NAME "org.tizen.system.dumpservice" -#define DUMP_SERVICE_OBJECT_PATH "/Org/Tizen/System/DumpService" -#define DUMP_SERVICE_INTERFACE_NAME DUMP_SERVICE_BUS_NAME -/* Coord daemon */ -#define COORD_BUS_NAME "org.tizen.system.coord" -#define COORD_OBJECT_PATH "/Org/Tizen/System/Coord" -#define COORD_INTERFACE_NAME COORD_BUS_NAME -#define COORD_PATH_AUTOBRIGHTNESS COORD_OBJECT_PATH"/Autobrightness" -#define COORD_INTERFACE_AUTOBRIGHTNESS COORD_INTERFACE_NAME".autobrightness" - -/* LED */ -#define POPUP_PATH_LED POPUP_OBJECT_PATH"/Led" -#define POPUP_INTERFACE_LED POPUP_INTERFACE_NAME".Led" -/* ODE */ -#define POPUP_PATH_ODE POPUP_OBJECT_PATH"/Ode" -#define POPUP_INTERFACE_ODE POPUP_INTERFACE_NAME".Ode" -/* Battery */ -#define POPUP_PATH_BATTERY POPUP_OBJECT_PATH"/Battery" -#define POPUP_INTERFACE_BATTERY POPUP_INTERFACE_NAME".Battery" -#define POPUP_METHOD_SCREENOFF_TTS "ScreenOffTts" -/* Overheat Timer*/ -#define POPUP_OVERHEAT_PATH POPUP_OBJECT_PATH"/Overheat" -#define POPUP_OVERHEAT_INTERFACE POPUP_INTERFACE_NAME".Overheat" - -/***********************************************/ -/* End of the Experimental for Specific device */ -/***********************************************/ - - - -typedef struct { - const unsigned char *data; - int size; -} dbus_byte; - -GVariant *dbus_handle_method_sync_with_reply(const char *dest, const char *path, - const char *interface, const char *method, - const char *sig, const char *param[]); - -GVariant *dbus_handle_method_sync_with_reply_var(const char *dest, const char *path, const char *iface, const char *method, GVariant *var); - -/* fd */ -gint* dbus_handle_get_unix_fd_list(GDBusMethodInvocation *invocation, int *size); - -GVariant *dbus_handle_method_with_unix_fd_list_sync_with_reply(const char *dest, const char *path, - const char *iface, const char *method, - const char *signature, const char *param[], - int *in_fdlist, int in_size, - int **out_fdlist, int *out_size); -GVariant *dbus_handle_method_with_unix_fd_list_sync_with_reply_var(const char *dest, const char *path, - const char *iface, const char *method, - GVariant *param, - int *in_fdlist, int in_size, - int **out_fdlist, int *out_size); - -int dbus_handle_method_sync(const char *dest, const char *path, - const char *interface, const char *method, - const char *sig, const char *param[]); - -int dbus_handle_method_sync_var(const char *dest, const char *path, const char *iface, const char *method, GVariant *param); - -int dbus_handle_method_sync_timeout(const char *dest, const char *path, - const char *interface, const char *method, - const char *sig, const char *param[], int timeout); - -int dbus_handle_method_sync_pairs(const char *dest, const char *path, - const char *interface, const char *method, - int num, va_list args); -int dbus_handle_method_async_pairs(const char *dest, const char *path, - const char *interface, const char *method, - int num, va_list args); -int dbus_handle_method_async(const char *dest, const char *path, - const char *interface, const char *method, - const char *sig, const char *param[]); - -int dbus_handle_method_async_var(const char *dest, const char *path, const char *iface, const char *method, GVariant *param); - -typedef void (*dbus_pending_cb)(GVariant *var, void *user_data, GError *err); - -int dbus_handle_method_async_with_reply(const char *dest, - const char *path, - const char *iface, - const char *method, - const char *signature, - const char *param[], - dbus_pending_cb cb, - int timeout_msec, - void *data); - - -int dbus_handle_method_async_with_reply_var(const char *dest, - const char *path, - const char *iface, - const char *method, - GVariant *param, - dbus_pending_cb cb, - int timeout_msec, - void *data); - -int check_systemd_active(void); - -/** - * @brief Dbus handler which is used to register and call methods - - * @since_tizen 4.0 - */ -typedef void *dbus_handle_h; - -/** - * @brief Dbus method handler which is used to unregister dbus methods - * @since_tizen 4.0 - */ -typedef void *dbus_object_handle_h; - -/** - * @brief Structure which contains the dbus method name and callback function. - * @since_tizen 4.0 - */ -typedef struct { - const char *member; - const char *signature_in; - const char *signature_out; - GVariant *(*func)(GDBusConnection *conn, - const gchar *sender, const gchar *path, const gchar *iface, const gchar *name, - GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data); -} dbus_method_s; - -/** - * @brief Structure which contains the dbus interface information and its methods.i - * @since_tizen 4.0 - */ -typedef struct { - dbus_object_handle_h oh; - const char *name; - const dbus_method_s *methods; - int nr_methods; -} dbus_interface_u; - -#define dh_get_param_from_var(gvar, signature, ...) ((g_strcmp0(signature, g_variant_get_type_string(gvar)) == 0) ? g_variant_get(gvar, signature, __VA_ARGS__), TRUE : FALSE) - -#define dbus_handle_new_g_variant_tuple() g_variant_new_tuple(NULL, 0) - -/** - * @brief Callback function which is called when the user data needs to be released. - * @since_tizen 4.0 - */ -typedef void (*destroy_notified)(void *data); - -typedef struct { - dbus_pending_cb func; - void *data; -} pending_call_data; - -int dbus_handle_request_bus_name(dbus_handle_h handle, const char *bus_name, GBusNameAcquiredCallback acquired_handler, GBusNameLostCallback lost_handler); - -dbus_handle_h dbus_handle_get_connection(GBusType bus_type, gboolean priv); - -int dbus_handle_register_dbus_object(dbus_handle_h handle, const char *obj_path, const dbus_interface_u *iface); -int dbus_handle_unregister_dbus_object(dbus_handle_h handle, const char *obj_path); - -int dbus_handle_add_dbus_object(dbus_handle_h handle, const char *obj_path, const dbus_interface_u *iface_u); -int dbus_handle_register_dbus_object_all(dbus_handle_h handle); - -guint subscribe_dbus_signal(dbus_handle_h handle, const char *path, const char *iface, const char *name, GDBusSignalCallback cb, void *data, destroy_notified free_func); -void unsubscribe_dbus_signal(dbus_handle_h handle, guint id); - -GVariant *dbus_handle_make_simple_array(const char *sig, int *param); - -int dbus_handle_broadcast_dbus_signal(const char *path, const char *iface, const char *name, const char *signature, const char *param[]); -int dbus_handle_broadcast_dbus_signal_var(const char *path, const char *iface, const char *name, GVariant *param); - -typedef struct -{ - guint pid; - guint uid; - gchar *unique_name; - gchar *sec_label; -} GDBusCredentials; - -int dbus_connection_get_sender_pid(GDBusConnection *conn, const char * sender); -int dbus_handle_get_sender_pid(dbus_handle_h handle, const char * sender); -int dbus_handle_get_sender_credentials(dbus_handle_h handle, const char *name, GDBusCredentials *creds); -int dbus_handle_watch_name(const char *name, GBusNameAppearedCallback name_appeared_handler, GBusNameVanishedCallback name_vanished_handler, void *user_data); -void dbus_handle_unwatch_name(guint id); -dbus_handle_h dbus_handle_init(GBusType type, const char* bus_name, GBusNameAcquiredCallback acquired_handler, GBusNameLostCallback lost_handler); -char** dbus_handle_get_owner_list(dbus_handle_h handle, const char *bus_name); -void dbush_handle_check_owner_name(dbus_handle_h handle, const char *owner_name); - -#endif diff --git a/src/shared/deviced-systemd.c b/src/shared/deviced-systemd.c index 8d317dd..d4a85b1 100644 --- a/src/shared/deviced-systemd.c +++ b/src/shared/deviced-systemd.c @@ -24,9 +24,9 @@ #include #include #include +#include #include "common.h" -#include "dbus.h" #include "deviced-systemd.h" #include "core/log.h" diff --git a/src/time/time-handler.c b/src/time/time-handler.c index 9278118..e078439 100644 --- a/src/time/time-handler.c +++ b/src/time/time-handler.c @@ -30,12 +30,12 @@ #include #include #include +#include #include "core/log.h" #include "core/devices.h" #include "display/poll.h" #include "display/core.h" -#include "shared/dbus.h" #include "core/common.h" #include "core/device-notifier.h" diff --git a/src/tzip/tzip.c b/src/tzip/tzip.c index 9541e03..6af7bd4 100644 --- a/src/tzip/tzip.c +++ b/src/tzip/tzip.c @@ -34,10 +34,10 @@ #include #include #include +#include #include "core/log.h" #include "core/devices.h" -#include "shared/dbus.h" #include "core/list.h" #include "core/device-notifier.h" #include "core/common.h" diff --git a/src/usb-host-test/usb-host-test.c b/src/usb-host-test/usb-host-test.c index 40a6753..d3b201d 100644 --- a/src/usb-host-test/usb-host-test.c +++ b/src/usb-host-test/usb-host-test.c @@ -22,13 +22,13 @@ #include #include #include +#include #include "core/log.h" #include "core/config-parser.h" #include "core/device-idler.h" #include "core/device-notifier.h" #include "core/devices.h" -#include "shared/dbus.h" #include "core/list.h" #include "shared/deviced-systemd.h" diff --git a/src/usb/usb-dbus.c b/src/usb/usb-dbus.c index f3a64fe..2b4f38f 100755 --- a/src/usb/usb-dbus.c +++ b/src/usb/usb-dbus.c @@ -21,12 +21,11 @@ #include #include #include +#include #include "core/log.h" #include "core/common.h" #include "core/devices.h" -#include "shared/dbus.h" -#include "shared/dbus.h" #include "usb.h" /* Legacy signals */ diff --git a/src/usbhost/usb-host.c b/src/usbhost/usb-host.c index 5c6f08f..24876f2 100644 --- a/src/usbhost/usb-host.c +++ b/src/usbhost/usb-host.c @@ -22,17 +22,16 @@ #include #include #include +#include #include "core/log.h" #include "core/devices.h" -#include "shared/dbus.h" #include "core/device-notifier.h" #include "core/udev.h" #include "core/list.h" #include "core/device-idler.h" #include "apps/apps.h" #include "extcon/extcon.h" -#include "shared/dbus.h" #define USB_INTERFACE_CLASS "bInterfaceClass" #define USB_INTERFACE_SUBCLASS "bInterfaceSubClass" -- 2.7.4 From 203eef71e435a58e57289852809521a43753ef4d Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Thu, 22 Mar 2018 18:25:57 +0900 Subject: [PATCH 13/16] common: Remove build warning Change-Id: I9c4bd8067cf3547e6becdff244bb9291fde2144d Signed-off-by: pr.jung --- src/core/main.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/core/main.c b/src/core/main.c index 5b5acf2..2c06b1b 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -87,7 +87,6 @@ static gboolean watchdog_cb(void *data) static int deviced_main(int argc, char **argv) { int ret; - guint timer; mainloop = g_main_loop_new(NULL, FALSE); @@ -103,7 +102,7 @@ static int deviced_main(int argc, char **argv) signal(SIGTERM, sig_quit); signal(SIGUSR1, sig_usr1); - timer = g_timeout_add_seconds_full(G_PRIORITY_HIGH, WATCHDOG_TIMEOUT, watchdog_cb, NULL, NULL); + g_timeout_add_seconds_full(G_PRIORITY_HIGH, WATCHDOG_TIMEOUT, watchdog_cb, NULL, NULL); /* g_main_loop */ g_main_loop_run(mainloop); -- 2.7.4 From a8dc36abc06f99bd67b0f38bd31cbf3e38353060 Mon Sep 17 00:00:00 2001 From: "pr.jung" Date: Fri, 23 Mar 2018 15:39:55 +0900 Subject: [PATCH 14/16] libgdbus: Remove dbus_handle_method_sync_with_reply usage - Change dbus_handle_method_sync_with_reply to dbus_handle_method_sync_with_reply_var Change-Id: Ifab9ea4cff00f643964f09187d77117ecbcbe563 Signed-off-by: pr.jung --- src/auto-test/battery.c | 12 ++++++------ src/auto-test/display.c | 16 ++++++++-------- src/auto-test/extcon.c | 4 ++-- src/auto-test/led.c | 4 ++-- src/auto-test/proc.c | 4 ++-- src/devicectl/devicectl.c | 16 ++++++++-------- src/libdeviced/led.c | 8 ++++---- 7 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/auto-test/battery.c b/src/auto-test/battery.c index 389553f..bb1d7be 100644 --- a/src/auto-test/battery.c +++ b/src/auto-test/battery.c @@ -126,10 +126,10 @@ static bool get_battery_method(const char *method, int *value) int val; bool ret = FALSE; - msg = dbus_handle_method_sync_with_reply(DEVICED_BUS_NAME, + msg = dbus_handle_method_sync_with_reply_var(DEVICED_BUS_NAME, DEVICED_PATH_BATTERY, DEVICED_INTERFACE_BATTERY, - method, NULL, NULL); + method, NULL); if (!msg) { _E("fail (%s): no reply", method); return ret; @@ -154,10 +154,10 @@ static bool get_battery_method_vconf(const char *method) int val; bool ret = FALSE; - msg = dbus_handle_method_sync_with_reply(DEVICED_BUS_NAME, + msg = dbus_handle_method_sync_with_reply_var(DEVICED_BUS_NAME, DEVICED_PATH_BATTERY, DEVICED_INTERFACE_BATTERY, - method, NULL, NULL); + method, NULL); if (!msg) { _E("fail (%s): no reply", method); return ret; @@ -287,10 +287,10 @@ static bool get_battery_info() bool ret = FALSE; char *argv[3]; - msg = dbus_handle_method_sync_with_reply(DEVICED_BUS_NAME, + msg = dbus_handle_method_sync_with_reply_var(DEVICED_BUS_NAME, DEVICED_PATH_BATTERY, DEVICED_INTERFACE_BATTERY, - METHOD_BATTERY_GETINFO, NULL, NULL); + METHOD_BATTERY_GETINFO, NULL); if (!msg) { _E("fail: no reply"); return ret; diff --git a/src/auto-test/display.c b/src/auto-test/display.c index 13e7f05..c7d30eb 100644 --- a/src/auto-test/display.c +++ b/src/auto-test/display.c @@ -58,10 +58,10 @@ static bool get_display_method(const char *method, int *value) int val; bool ret = FALSE; - msg = dbus_handle_method_sync_with_reply(DEVICED_BUS_NAME, + msg = dbus_handle_method_sync_with_reply_var(DEVICED_BUS_NAME, DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, - method, NULL, NULL); + method, NULL); if (!msg) { _E("fail (%s): no reply", method); return ret; @@ -112,14 +112,14 @@ static bool set_display_method(const char *method, GVariant *param) return ret; } -static bool set_display_method_noreply(const char *method, char *sig, const char *param[]) +static bool set_display_method_noreply(const char *method, GVariant *var) { GVariant *msg; - msg = dbus_handle_method_sync_with_reply(DEVICED_BUS_NAME, + msg = dbus_handle_method_sync_with_reply_var(DEVICED_BUS_NAME, DEVICED_PATH_DISPLAY, DEVICED_INTERFACE_DISPLAY, - method, sig, param); + method, var); if (!msg) { _E("fail (%s): no reply", method); return FALSE; @@ -332,7 +332,7 @@ static bool set_display_savelog() if (!stat(PM_STATE_LOG_FILE, &buf)) remove(PM_STATE_LOG_FILE); - if (!set_display_method_noreply(METHOD_DISPLAY_SAVELOG, NULL, NULL)) + if (!set_display_method_noreply(METHOD_DISPLAY_SAVELOG, NULL)) return ret; sleep(3); @@ -410,12 +410,12 @@ static bool set_display_actorcontrol(char *command, int actor, int caps) static bool set_display_start() { - return set_display_method_noreply(METHOD_DISPLAY_START, NULL, NULL); + return set_display_method_noreply(METHOD_DISPLAY_START, NULL); } static bool set_display_stop() { - return set_display_method_noreply(METHOD_DISPLAY_STOP, NULL, NULL); + return set_display_method_noreply(METHOD_DISPLAY_STOP, NULL); } void display_test_all(int *success, int *fail) diff --git a/src/auto-test/extcon.c b/src/auto-test/extcon.c index a2ef544..ed2c187 100644 --- a/src/auto-test/extcon.c +++ b/src/auto-test/extcon.c @@ -64,10 +64,10 @@ static bool get_sysnoti_method(const char *method) int val; bool ret = FALSE; - msg = dbus_handle_method_sync_with_reply(DEVICED_BUS_NAME, + msg = dbus_handle_method_sync_with_reply_var(DEVICED_BUS_NAME, DEVICED_PATH_SYSNOTI, DEVICED_INTERFACE_SYSNOTI, - method, NULL, NULL); + method, NULL); if (!msg) { _E("fail (%s): no reply", method); return ret; diff --git a/src/auto-test/led.c b/src/auto-test/led.c index e47aa5e..79cfae3 100644 --- a/src/auto-test/led.c +++ b/src/auto-test/led.c @@ -38,10 +38,10 @@ static bool get_led_method(const char *method) int val; bool ret = FALSE; - msg = dbus_handle_method_sync_with_reply(DEVICED_BUS_NAME, + msg = dbus_handle_method_sync_with_reply_var(DEVICED_BUS_NAME, DEVICED_PATH_LED, DEVICED_INTERFACE_LED, - method, NULL, NULL); + method, NULL); if (!msg) { _E("fail (%s): no reply", method); return ret; diff --git a/src/auto-test/proc.c b/src/auto-test/proc.c index 532c4a1..44bb8dc 100755 --- a/src/auto-test/proc.c +++ b/src/auto-test/proc.c @@ -26,10 +26,10 @@ static bool get_sysnoti_revision() int val; bool ret = FALSE; - msg = dbus_handle_method_sync_with_reply(DEVICED_BUS_NAME, + msg = dbus_handle_method_sync_with_reply_var(DEVICED_BUS_NAME, DEVICED_PATH_SYSNOTI, DEVICED_INTERFACE_SYSNOTI, - METHOD_SYSNOTI_GETREVISION, NULL, NULL); + METHOD_SYSNOTI_GETREVISION, NULL); if (!msg) { _E("fail : no reply"); return ret; diff --git a/src/devicectl/devicectl.c b/src/devicectl/devicectl.c index 50b251a..52455f2 100644 --- a/src/devicectl/devicectl.c +++ b/src/devicectl/devicectl.c @@ -70,11 +70,11 @@ static int start_device(char **args) printf("start %s device!\n", args[1]); - msg = dbus_handle_method_sync_with_reply(DEVICED_BUS_NAME, + msg = dbus_handle_method_sync_with_reply_var(DEVICED_BUS_NAME, devices[arg_id].path, devices[arg_id].iface, "start", - NULL, NULL); + NULL); if (!msg) return -EBADMSG; @@ -92,11 +92,11 @@ static int stop_device(char **args) printf("stop %s device!\n", args[1]); - msg = dbus_handle_method_sync_with_reply(DEVICED_BUS_NAME, + msg = dbus_handle_method_sync_with_reply_var(DEVICED_BUS_NAME, devices[arg_id].path, devices[arg_id].iface, "stop", - NULL, NULL); + NULL); if (!msg) return -EBADMSG; @@ -179,11 +179,11 @@ static int save_dbus_name(char **args) printf("save dbus name!\n"); - msg = dbus_handle_method_sync_with_reply(DBUS_BUS_NAME, + msg = dbus_handle_method_sync_with_reply_var(DBUS_BUS_NAME, DBUS_OBJECT_PATH, DBUS_INTERFACE_NAME, "ListNames", - NULL, NULL); + NULL); if (!msg) { printf("failed to get list names"); return -EBADMSG; @@ -218,11 +218,11 @@ static int device_list(char **args) printf("print %s to dlog!\n", args[1]); - msg = dbus_handle_method_sync_with_reply(DEVICED_BUS_NAME, + msg = dbus_handle_method_sync_with_reply_var(DEVICED_BUS_NAME, devices[arg_id].path, devices[arg_id].iface, "DeviceList", - NULL, NULL); + NULL); if (!msg) return -EBADMSG; diff --git a/src/libdeviced/led.c b/src/libdeviced/led.c index e7da673..bf152b4 100644 --- a/src/libdeviced/led.c +++ b/src/libdeviced/led.c @@ -35,11 +35,11 @@ API int led_get_brightness(void) GVariant *msg = NULL; int ret_val = 0; - msg = dbus_handle_method_sync_with_reply(DEVICED_BUS_NAME, + msg = dbus_handle_method_sync_with_reply_var(DEVICED_BUS_NAME, DEVICED_PATH_LED, DEVICED_INTERFACE_LED, METHOD_GET_BRIGHTNESS, - NULL, NULL); + NULL); if (!msg) return -EBADMSG; @@ -58,11 +58,11 @@ API int led_get_max_brightness(void) GVariant *msg = NULL; int ret_val; - msg = dbus_handle_method_sync_with_reply(DEVICED_BUS_NAME, + msg = dbus_handle_method_sync_with_reply_var(DEVICED_BUS_NAME, DEVICED_PATH_LED, DEVICED_INTERFACE_LED, METHOD_GET_MAX_BRIGHTNESS, - NULL, NULL); + NULL); if (!msg) return -EBADMSG; -- 2.7.4 From 2a97e96e8156f83323f0e69703ab17c63f6f4124 Mon Sep 17 00:00:00 2001 From: "sanghyeok.oh" Date: Mon, 26 Mar 2018 18:16:25 +0900 Subject: [PATCH 15/16] dbus-policy: add rule default deny own Change-Id: I1cc4b02d3d20c2e12c4675352f51384c04ec71fa Signed-off-by: sanghyeok.oh --- conf/org.tizen.system.deviced.conf | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/conf/org.tizen.system.deviced.conf b/conf/org.tizen.system.deviced.conf index 656af38..81c31c6 100644 --- a/conf/org.tizen.system.deviced.conf +++ b/conf/org.tizen.system.deviced.conf @@ -2,8 +2,8 @@ "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd"> + - @@ -18,6 +18,7 @@ + -- 2.7.4 From 9daacb9a9e82ecb41f7d3c71d19ee732f927ed36 Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Mon, 19 Mar 2018 17:48:21 +0900 Subject: [PATCH 16/16] Fix build error that occurred with a new version of cmake(3.9.4) Change-Id: Ifc95d7062cf63674032fdf6e2684fc0a4437ef2f Signed-off-by: Hyotaek Shim --- CMakeLists.txt | 1 + src/auto-test/CMakeLists.txt | 4 +--- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f1a67f3..7ef248b 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -218,6 +218,7 @@ ENDIF() ADD_DEFINITIONS("-DDEBUG") ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS}) +SET(deviced_LDFLAGS ${pkgs_LDFLAGS}) TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} "-lrt -ldl -lm" shared) INSTALL(TARGETS ${PROJECT_NAME} DESTINATION bin) diff --git a/src/auto-test/CMakeLists.txt b/src/auto-test/CMakeLists.txt index 185958c..aef9346 100644 --- a/src/auto-test/CMakeLists.txt +++ b/src/auto-test/CMakeLists.txt @@ -23,8 +23,6 @@ SET(SRCS time.c ) -INCLUDE(FindPkgConfig) - FOREACH(flag ${pkgs_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") ENDFOREACH(flag) @@ -37,7 +35,7 @@ ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"") ADD_DEFINITIONS("-DENABLE_TEST_DLOG") ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS}) -TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} shared) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${deviced_LDFLAGS} shared) INSTALL(TARGETS ${PROJECT_NAME} DESTINATION bin) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/auto-test.conf DESTINATION /etc/deviced) -- 2.7.4