From 79d3c28b1bab7a183d3cf9326a2c66ef3a243bf6 Mon Sep 17 00:00:00 2001 From: Segwon Date: Thu, 16 Nov 2017 14:03:25 +0900 Subject: [PATCH] interface: do not close request to daemon by gdbus. - daemon will be detect gdbus disconnection by g_bus_watch_name() Signed-off-by: Segwon Change-Id: Id9882a8b576b9110eb21aa66a94b3fa7e9c4b14c --- include/gdbus/peripheral_gdbus_gpio.h | 2 +- include/gdbus/peripheral_gdbus_i2c.h | 2 +- include/gdbus/peripheral_gdbus_pwm.h | 2 +- include/gdbus/peripheral_gdbus_spi.h | 2 +- include/gdbus/peripheral_gdbus_uart.h | 2 +- src/gdbus/peripheral_gdbus_gpio.c | 41 ++++++++++------------------------- src/gdbus/peripheral_gdbus_i2c.c | 41 ++++++++++------------------------- src/gdbus/peripheral_gdbus_pwm.c | 41 ++++++++++------------------------- src/gdbus/peripheral_gdbus_spi.c | 41 ++++++++++------------------------- src/gdbus/peripheral_gdbus_uart.c | 41 ++++++++++------------------------- src/gdbus/peripheral_io.xml | 20 ----------------- src/peripheral_gpio.c | 2 +- src/peripheral_i2c.c | 2 +- src/peripheral_pwm.c | 2 +- src/peripheral_spi.c | 2 +- src/peripheral_uart.c | 2 +- 16 files changed, 70 insertions(+), 175 deletions(-) diff --git a/include/gdbus/peripheral_gdbus_gpio.h b/include/gdbus/peripheral_gdbus_gpio.h index c63aeba..1ffe214 100644 --- a/include/gdbus/peripheral_gdbus_gpio.h +++ b/include/gdbus/peripheral_gdbus_gpio.h @@ -20,6 +20,6 @@ #include "peripheral_gdbus_common.h" int peripheral_gdbus_gpio_open(peripheral_gpio_h gpio); -int peripheral_gdbus_gpio_close(peripheral_gpio_h gpio); +int peripheral_gdbus_gpio_close(); #endif /* __PERIPHERAL_GDBUS_GPIO_H__ */ diff --git a/include/gdbus/peripheral_gdbus_i2c.h b/include/gdbus/peripheral_gdbus_i2c.h index e1b1722..9d9f9a5 100644 --- a/include/gdbus/peripheral_gdbus_i2c.h +++ b/include/gdbus/peripheral_gdbus_i2c.h @@ -20,6 +20,6 @@ #include "peripheral_gdbus_common.h" int peripheral_gdbus_i2c_open(peripheral_i2c_h i2c, int bus, int address); -int peripheral_gdbus_i2c_close(peripheral_i2c_h i2c); +int peripheral_gdbus_i2c_close(); #endif /* __PERIPHERAL_GDBUS_I2C_H__ */ diff --git a/include/gdbus/peripheral_gdbus_pwm.h b/include/gdbus/peripheral_gdbus_pwm.h index 70a4b02..c0764c6 100644 --- a/include/gdbus/peripheral_gdbus_pwm.h +++ b/include/gdbus/peripheral_gdbus_pwm.h @@ -20,6 +20,6 @@ #include "peripheral_gdbus_common.h" int peripheral_gdbus_pwm_open(peripheral_pwm_h pwm, int chip, int pin); -int peripheral_gdbus_pwm_close(peripheral_pwm_h pwm); +int peripheral_gdbus_pwm_close(); #endif /* __PERIPHERAL_GDBUS_PWM_H__ */ diff --git a/include/gdbus/peripheral_gdbus_spi.h b/include/gdbus/peripheral_gdbus_spi.h index 94b2242..6f4aaa3 100644 --- a/include/gdbus/peripheral_gdbus_spi.h +++ b/include/gdbus/peripheral_gdbus_spi.h @@ -20,6 +20,6 @@ #include "peripheral_gdbus_common.h" int peripheral_gdbus_spi_open(peripheral_spi_h spi, int bus, int cs); -int peripheral_gdbus_spi_close(peripheral_spi_h spi); +int peripheral_gdbus_spi_close(); #endif /* __PERIPHERAL_GDBUS_SPI_H_ */ diff --git a/include/gdbus/peripheral_gdbus_uart.h b/include/gdbus/peripheral_gdbus_uart.h index bf7af68..048eed5 100644 --- a/include/gdbus/peripheral_gdbus_uart.h +++ b/include/gdbus/peripheral_gdbus_uart.h @@ -20,6 +20,6 @@ #include "peripheral_gdbus_common.h" int peripheral_gdbus_uart_open(peripheral_uart_h uart, int port); -int peripheral_gdbus_uart_close(peripheral_uart_h uart); +int peripheral_gdbus_uart_close(); #endif /* __PERIPHERAL_GDBUS_UART_H_ */ diff --git a/src/gdbus/peripheral_gdbus_gpio.c b/src/gdbus/peripheral_gdbus_gpio.c index c8a6d8c..c935a4c 100644 --- a/src/gdbus/peripheral_gdbus_gpio.c +++ b/src/gdbus/peripheral_gdbus_gpio.c @@ -49,13 +49,18 @@ static int __gpio_proxy_init() return PERIPHERAL_ERROR_NONE; } -static void __gpio_proxy_deinit() +static int __gpio_proxy_deinit() { - if (gpio_proxy != NULL) { - g_object_unref(gpio_proxy); - if (!G_IS_OBJECT(gpio_proxy)) - gpio_proxy = NULL; + if (gpio_proxy == NULL) { + _E("Gpio proxy is NULL"); + return PERIPHERAL_ERROR_UNKNOWN; } + + g_object_unref(gpio_proxy); + if (!G_IS_OBJECT(gpio_proxy)) + gpio_proxy = NULL; + + return PERIPHERAL_ERROR_NONE; } int peripheral_gdbus_gpio_open(peripheral_gpio_h gpio) @@ -112,30 +117,8 @@ int peripheral_gdbus_gpio_open(peripheral_gpio_h gpio) return ret; } -int peripheral_gdbus_gpio_close(peripheral_gpio_h gpio) +int peripheral_gdbus_gpio_close() { - int ret; - GError *error = NULL; - - if (gpio_proxy == NULL) { - _E("Can't try to gpio close because gpio proxy is NULL."); - return PERIPHERAL_ERROR_UNKNOWN; - } - - if (peripheral_io_gdbus_gpio_call_close_sync( - gpio_proxy, - gpio->handle, - &ret, - NULL, - &error) == FALSE) { - _E("Failed to request daemon to gpio close : %s", error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - // TODO : If the return value is not PERIPHERAL_ERROR_NONE, the daemon returns status before close request. - if (ret == PERIPHERAL_ERROR_NONE) - __gpio_proxy_deinit(); - + int ret = __gpio_proxy_deinit(); return ret; } \ No newline at end of file diff --git a/src/gdbus/peripheral_gdbus_i2c.c b/src/gdbus/peripheral_gdbus_i2c.c index 29ba888..cc5f300 100644 --- a/src/gdbus/peripheral_gdbus_i2c.c +++ b/src/gdbus/peripheral_gdbus_i2c.c @@ -47,13 +47,18 @@ static int __i2c_proxy_init() return PERIPHERAL_ERROR_NONE; } -static void __i2c_proxy_deinit() +static int __i2c_proxy_deinit() { - if (i2c_proxy) { - g_object_unref(i2c_proxy); - if (!G_IS_OBJECT(i2c_proxy)) - i2c_proxy = NULL; + if (i2c_proxy == NULL) { + _E("I2c proxy is NULL"); + return PERIPHERAL_ERROR_UNKNOWN; } + + g_object_unref(i2c_proxy); + if (!G_IS_OBJECT(i2c_proxy)) + i2c_proxy = NULL; + + return PERIPHERAL_ERROR_NONE; } int peripheral_gdbus_i2c_open(peripheral_i2c_h i2c, int bus, int address) @@ -96,30 +101,8 @@ int peripheral_gdbus_i2c_open(peripheral_i2c_h i2c, int bus, int address) return ret; } -int peripheral_gdbus_i2c_close(peripheral_i2c_h i2c) +int peripheral_gdbus_i2c_close() { - int ret; - GError *error = NULL; - - if (i2c_proxy == NULL) { - _E("Can't try to i2c close because i2c proxy is NULL."); - return PERIPHERAL_ERROR_UNKNOWN; - } - - if (peripheral_io_gdbus_i2c_call_close_sync( - i2c_proxy, - i2c->handle, - &ret, - NULL, - &error) == FALSE) { - _E("Failed to request daemon to i2c close : %s", error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - // TODO : If the return value is not PERIPHERAL_ERROR_NONE, the daemon returns status before close request. - if (ret == PERIPHERAL_ERROR_NONE) - __i2c_proxy_deinit(); - + int ret = __i2c_proxy_deinit(); return ret; } diff --git a/src/gdbus/peripheral_gdbus_pwm.c b/src/gdbus/peripheral_gdbus_pwm.c index 48ff164..4c1d916 100644 --- a/src/gdbus/peripheral_gdbus_pwm.c +++ b/src/gdbus/peripheral_gdbus_pwm.c @@ -50,13 +50,18 @@ static int __pwm_proxy_init() return PERIPHERAL_ERROR_NONE; } -static void __pwm_proxy_deinit() +static int __pwm_proxy_deinit() { - if (pwm_proxy) { - g_object_unref(pwm_proxy); - if (!G_IS_OBJECT(pwm_proxy)) - pwm_proxy = NULL; + if (pwm_proxy == NULL) { + _E("Pwm proxy is NULL"); + return PERIPHERAL_ERROR_UNKNOWN; } + + g_object_unref(pwm_proxy); + if (!G_IS_OBJECT(pwm_proxy)) + pwm_proxy = NULL; + + return PERIPHERAL_ERROR_NONE; } int peripheral_gdbus_pwm_open(peripheral_pwm_h pwm, int chip, int pin) @@ -121,30 +126,8 @@ int peripheral_gdbus_pwm_open(peripheral_pwm_h pwm, int chip, int pin) return ret; } -int peripheral_gdbus_pwm_close(peripheral_pwm_h pwm) +int peripheral_gdbus_pwm_close() { - int ret; - GError *error = NULL; - - if (pwm_proxy == NULL) { - _E("Can't try to pwm close because pwm proxy is NULL."); - return PERIPHERAL_ERROR_UNKNOWN; - } - - if (peripheral_io_gdbus_pwm_call_close_sync( - pwm_proxy, - pwm->handle, - &ret, - NULL, - &error) == FALSE) { - _E("Failed to request daemon to pwm close : %s", error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - // TODO : If the return value is not PERIPHERAL_ERROR_NONE, the daemon returns status before close request. - if (ret == PERIPHERAL_ERROR_NONE) - __pwm_proxy_deinit(); - + int ret = __pwm_proxy_deinit(); return ret; } diff --git a/src/gdbus/peripheral_gdbus_spi.c b/src/gdbus/peripheral_gdbus_spi.c index fce5a41..b0653e4 100644 --- a/src/gdbus/peripheral_gdbus_spi.c +++ b/src/gdbus/peripheral_gdbus_spi.c @@ -47,13 +47,18 @@ static int __spi_proxy_init() return PERIPHERAL_ERROR_NONE; } -static void __spi_proxy_deinit() +static int __spi_proxy_deinit() { - if (spi_proxy) { - g_object_unref(spi_proxy); - if (!G_IS_OBJECT(spi_proxy)) - spi_proxy = NULL; + if (spi_proxy == NULL) { + _E("Spi proxy is NULL"); + return PERIPHERAL_ERROR_UNKNOWN; } + + g_object_unref(spi_proxy); + if (!G_IS_OBJECT(spi_proxy)) + spi_proxy = NULL; + + return PERIPHERAL_ERROR_NONE; } int peripheral_gdbus_spi_open(peripheral_spi_h spi, int bus, int cs) @@ -97,30 +102,8 @@ int peripheral_gdbus_spi_open(peripheral_spi_h spi, int bus, int cs) return ret; } -int peripheral_gdbus_spi_close(peripheral_spi_h spi) +int peripheral_gdbus_spi_close() { - int ret; - GError *error = NULL; - - if (spi_proxy == NULL) { - _E("Can't try to spi close because spi proxy is NULL."); - return PERIPHERAL_ERROR_UNKNOWN; - } - - if (peripheral_io_gdbus_spi_call_close_sync( - spi_proxy, - spi->handle, - &ret, - NULL, - &error) == FALSE) { - _E("Failed to request daemon to spi close : %s", error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - // TODO : If the return value is not PERIPHERAL_ERROR_NONE, the daemon returns status before close request. - if (ret == PERIPHERAL_ERROR_NONE) - __spi_proxy_deinit(); - + int ret = __spi_proxy_deinit(); return ret; } diff --git a/src/gdbus/peripheral_gdbus_uart.c b/src/gdbus/peripheral_gdbus_uart.c index 852e244..a15e566 100644 --- a/src/gdbus/peripheral_gdbus_uart.c +++ b/src/gdbus/peripheral_gdbus_uart.c @@ -47,13 +47,18 @@ static int __uart_proxy_init() return PERIPHERAL_ERROR_NONE; } -static void __uart_proxy_deinit() +static int __uart_proxy_deinit() { - if (uart_proxy) { - g_object_unref(uart_proxy); - if (!G_IS_OBJECT(uart_proxy)) - uart_proxy = NULL; + if (uart_proxy == NULL) { + _E("Uart proxy is NULL"); + return PERIPHERAL_ERROR_UNKNOWN; } + + g_object_unref(uart_proxy); + if (!G_IS_OBJECT(uart_proxy)) + uart_proxy = NULL; + + return PERIPHERAL_ERROR_NONE; } int peripheral_gdbus_uart_open(peripheral_uart_h uart, int port) @@ -96,30 +101,8 @@ int peripheral_gdbus_uart_open(peripheral_uart_h uart, int port) return ret; } -int peripheral_gdbus_uart_close(peripheral_uart_h uart) +int peripheral_gdbus_uart_close() { - int ret; - GError *error = NULL; - - if (uart_proxy == NULL) { - _E("Can't try to uart close because uart proxy is NULL."); - return PERIPHERAL_ERROR_UNKNOWN; - } - - if (peripheral_io_gdbus_uart_call_close_sync( - uart_proxy, - uart->handle, - &ret, - NULL, - &error) == FALSE) { - _E("Failed to request daemon to uart close : %s", error->message); - g_error_free(error); - return PERIPHERAL_ERROR_UNKNOWN; - } - - // TODO : If the return value is not PERIPHERAL_ERROR_NONE, the daemon returns status before close request. - if (ret == PERIPHERAL_ERROR_NONE) - __uart_proxy_deinit(); - + int ret = __uart_proxy_deinit(); return ret; } diff --git a/src/gdbus/peripheral_io.xml b/src/gdbus/peripheral_io.xml index 00c49e7..6b987a3 100644 --- a/src/gdbus/peripheral_io.xml +++ b/src/gdbus/peripheral_io.xml @@ -7,10 +7,6 @@ - - - - @@ -20,10 +16,6 @@ - - - - @@ -33,10 +25,6 @@ - - - - @@ -45,10 +33,6 @@ - - - - @@ -58,9 +42,5 @@ - - - - diff --git a/src/peripheral_gpio.c b/src/peripheral_gpio.c index 040d862..1333122 100644 --- a/src/peripheral_gpio.c +++ b/src/peripheral_gpio.c @@ -90,7 +90,7 @@ int peripheral_gpio_close(peripheral_gpio_h gpio) RETVM_IF(gpio == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "gpio handle is NULL"); /* call gpio_close */ - ret = peripheral_gdbus_gpio_close(gpio); + ret = peripheral_gdbus_gpio_close(); if (ret != PERIPHERAL_ERROR_NONE) _E("Failed to close the gpio pin, ret : %d", ret); diff --git a/src/peripheral_i2c.c b/src/peripheral_i2c.c index e89e401..44d6052 100644 --- a/src/peripheral_i2c.c +++ b/src/peripheral_i2c.c @@ -90,7 +90,7 @@ int peripheral_i2c_close(peripheral_i2c_h i2c) RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "I2C feature is not supported"); RETVM_IF(i2c == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "i2c handle is NULL"); - ret = peripheral_gdbus_i2c_close(i2c); + ret = peripheral_gdbus_i2c_close(); if (ret != PERIPHERAL_ERROR_NONE) _E("Failed to close i2c communcation, ret : %d", ret); diff --git a/src/peripheral_pwm.c b/src/peripheral_pwm.c index fb1ed14..12e6fc2 100644 --- a/src/peripheral_pwm.c +++ b/src/peripheral_pwm.c @@ -82,7 +82,7 @@ int peripheral_pwm_close(peripheral_pwm_h pwm) RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "PWM feature is not supported"); RETVM_IF(pwm == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "pwm handle is NULL"); - if ((ret = peripheral_gdbus_pwm_close(pwm)) < 0) + if ((ret = peripheral_gdbus_pwm_close()) < 0) _E("Failed to close PWM chip, continuing anyway, ret : %d", ret); free(pwm); diff --git a/src/peripheral_spi.c b/src/peripheral_spi.c index 13c2b05..9b25a2e 100644 --- a/src/peripheral_spi.c +++ b/src/peripheral_spi.c @@ -81,7 +81,7 @@ int peripheral_spi_close(peripheral_spi_h spi) RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "SPI feature is not supported"); RETVM_IF(spi == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "spi handle is NULL"); - ret = peripheral_gdbus_spi_close(spi); + ret = peripheral_gdbus_spi_close(); if (ret < PERIPHERAL_ERROR_NONE) _E("Failed to close SPI device, continuing anyway, ret : %d", ret); diff --git a/src/peripheral_uart.c b/src/peripheral_uart.c index d7d3577..b18ccff 100644 --- a/src/peripheral_uart.c +++ b/src/peripheral_uart.c @@ -86,7 +86,7 @@ int peripheral_uart_close(peripheral_uart_h uart) RETVM_IF(__is_feature_supported() == false, PERIPHERAL_ERROR_NOT_SUPPORTED, "UART feature is not supported"); RETVM_IF(uart == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "uart handle is NULL"); - ret = peripheral_gdbus_uart_close(uart); + ret = peripheral_gdbus_uart_close(); if (ret < PERIPHERAL_ERROR_NONE) _E("Failed to close uart communication, continuing anyway, ret : %d", ret); -- 2.7.4