From 2fbe04726be903fc76e2d4ff68ccf47200058be5 Mon Sep 17 00:00:00 2001 From: Segwon Date: Fri, 8 Dec 2017 14:57:20 +0900 Subject: [PATCH] gdbus: communicate via gdbus when close Change-Id: Ieae106a611e8409c50996b68c08fcdbd3506d70b Signed-off-by: Segwon --- 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 | 26 ++++++++++++++++++++------ src/gdbus/peripheral_gdbus_i2c.c | 26 ++++++++++++++++++++------ src/gdbus/peripheral_gdbus_pwm.c | 26 ++++++++++++++++++++------ src/gdbus/peripheral_gdbus_spi.c | 26 ++++++++++++++++++++------ src/gdbus/peripheral_gdbus_uart.c | 26 ++++++++++++++++++++------ 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, 130 insertions(+), 40 deletions(-) diff --git a/include/gdbus/peripheral_gdbus_gpio.h b/include/gdbus/peripheral_gdbus_gpio.h index edef2ea..7ccc4a3 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 pin); -int peripheral_gdbus_gpio_close(void); +int peripheral_gdbus_gpio_close(peripheral_gpio_h gpio); #endif /* __PERIPHERAL_GDBUS_GPIO_H__ */ diff --git a/include/gdbus/peripheral_gdbus_i2c.h b/include/gdbus/peripheral_gdbus_i2c.h index 099da4e..e1b1722 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(void); +int peripheral_gdbus_i2c_close(peripheral_i2c_h i2c); #endif /* __PERIPHERAL_GDBUS_I2C_H__ */ diff --git a/include/gdbus/peripheral_gdbus_pwm.h b/include/gdbus/peripheral_gdbus_pwm.h index e5c26c8..70a4b02 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(void); +int peripheral_gdbus_pwm_close(peripheral_pwm_h pwm); #endif /* __PERIPHERAL_GDBUS_PWM_H__ */ diff --git a/include/gdbus/peripheral_gdbus_spi.h b/include/gdbus/peripheral_gdbus_spi.h index a828c10..94b2242 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(void); +int peripheral_gdbus_spi_close(peripheral_spi_h spi); #endif /* __PERIPHERAL_GDBUS_SPI_H_ */ diff --git a/include/gdbus/peripheral_gdbus_uart.h b/include/gdbus/peripheral_gdbus_uart.h index fc58ee8..bf7af68 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(void); +int peripheral_gdbus_uart_close(peripheral_uart_h uart); #endif /* __PERIPHERAL_GDBUS_UART_H_ */ diff --git a/src/gdbus/peripheral_gdbus_gpio.c b/src/gdbus/peripheral_gdbus_gpio.c index 5400429..dcc9ff2 100644 --- a/src/gdbus/peripheral_gdbus_gpio.c +++ b/src/gdbus/peripheral_gdbus_gpio.c @@ -51,10 +51,7 @@ static int __gpio_proxy_init(void) static int __gpio_proxy_deinit(void) { - if (gpio_proxy == NULL) { - _E("Gpio proxy is NULL"); - return PERIPHERAL_ERROR_IO_ERROR; - } + RETVM_IF(gpio_proxy == NULL, PERIPHERAL_ERROR_IO_ERROR, "Gpio proxy is NULL"); g_object_unref(gpio_proxy); if (!G_IS_OBJECT(gpio_proxy)) @@ -117,8 +114,25 @@ int peripheral_gdbus_gpio_open(peripheral_gpio_h gpio, int pin) return ret; } -int peripheral_gdbus_gpio_close(void) +int peripheral_gdbus_gpio_close(peripheral_gpio_h gpio) { - int ret = __gpio_proxy_deinit(); + RETVM_IF(gpio_proxy == NULL, PERIPHERAL_ERROR_IO_ERROR, "Gpio proxy is NULL"); + + int ret; + GError *error = NULL; + + 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_IO_ERROR; + } + + __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 e85f21b..c2fb06f 100644 --- a/src/gdbus/peripheral_gdbus_i2c.c +++ b/src/gdbus/peripheral_gdbus_i2c.c @@ -49,10 +49,7 @@ static int __i2c_proxy_init(void) static int __i2c_proxy_deinit(void) { - if (i2c_proxy == NULL) { - _E("I2c proxy is NULL"); - return PERIPHERAL_ERROR_IO_ERROR; - } + RETVM_IF(i2c_proxy == NULL, PERIPHERAL_ERROR_IO_ERROR, "I2c proxy is NULL"); g_object_unref(i2c_proxy); if (!G_IS_OBJECT(i2c_proxy)) @@ -102,8 +99,25 @@ int peripheral_gdbus_i2c_open(peripheral_i2c_h i2c, int bus, int address) return ret; } -int peripheral_gdbus_i2c_close(void) +int peripheral_gdbus_i2c_close(peripheral_i2c_h i2c) { - int ret = __i2c_proxy_deinit(); + RETVM_IF(i2c_proxy == NULL, PERIPHERAL_ERROR_IO_ERROR, "I2c proxy is NULL"); + + int ret; + GError *error = NULL; + + 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_IO_ERROR; + } + + __i2c_proxy_deinit(); + return ret; } diff --git a/src/gdbus/peripheral_gdbus_pwm.c b/src/gdbus/peripheral_gdbus_pwm.c index 4b76866..71a7344 100644 --- a/src/gdbus/peripheral_gdbus_pwm.c +++ b/src/gdbus/peripheral_gdbus_pwm.c @@ -52,10 +52,7 @@ static int __pwm_proxy_init(void) static int __pwm_proxy_deinit(void) { - if (pwm_proxy == NULL) { - _E("Pwm proxy is NULL"); - return PERIPHERAL_ERROR_IO_ERROR; - } + RETVM_IF(pwm_proxy == NULL, PERIPHERAL_ERROR_IO_ERROR, "Pwm proxy is NULL"); g_object_unref(pwm_proxy); if (!G_IS_OBJECT(pwm_proxy)) @@ -126,8 +123,25 @@ int peripheral_gdbus_pwm_open(peripheral_pwm_h pwm, int chip, int pin) return ret; } -int peripheral_gdbus_pwm_close(void) +int peripheral_gdbus_pwm_close(peripheral_pwm_h pwm) { - int ret = __pwm_proxy_deinit(); + RETVM_IF(pwm_proxy == NULL, PERIPHERAL_ERROR_IO_ERROR, "Pwm proxy is NULL"); + + int ret; + GError *error = NULL; + + if (peripheral_io_gdbus_pwm_call_close_sync( + pwm_proxy, + pwm->handle, + &ret, + NULL, + &error) == FALSE) { + _E("Failed to request daemon to gpio pwm : %s", error->message); + g_error_free(error); + return PERIPHERAL_ERROR_IO_ERROR; + } + + __pwm_proxy_deinit(); + return ret; } diff --git a/src/gdbus/peripheral_gdbus_spi.c b/src/gdbus/peripheral_gdbus_spi.c index d518d85..2861d52 100644 --- a/src/gdbus/peripheral_gdbus_spi.c +++ b/src/gdbus/peripheral_gdbus_spi.c @@ -49,10 +49,7 @@ static int __spi_proxy_init(void) static int __spi_proxy_deinit(void) { - if (spi_proxy == NULL) { - _E("Spi proxy is NULL"); - return PERIPHERAL_ERROR_IO_ERROR; - } + RETVM_IF(spi_proxy == NULL, PERIPHERAL_ERROR_IO_ERROR, "Spi proxy is NULL"); g_object_unref(spi_proxy); if (!G_IS_OBJECT(spi_proxy)) @@ -102,8 +99,25 @@ int peripheral_gdbus_spi_open(peripheral_spi_h spi, int bus, int cs) return ret; } -int peripheral_gdbus_spi_close(void) +int peripheral_gdbus_spi_close(peripheral_spi_h spi) { - int ret = __spi_proxy_deinit(); + RETVM_IF(spi_proxy == NULL, PERIPHERAL_ERROR_IO_ERROR, "Spi proxy is NULL"); + + int ret; + GError *error = NULL; + + if (peripheral_io_gdbus_spi_call_close_sync( + spi_proxy, + spi->handle, + &ret, + NULL, + &error) == FALSE) { + _E("Failed to request daemon to gpio spi : %s", error->message); + g_error_free(error); + return PERIPHERAL_ERROR_IO_ERROR; + } + + __spi_proxy_deinit(); + return ret; } diff --git a/src/gdbus/peripheral_gdbus_uart.c b/src/gdbus/peripheral_gdbus_uart.c index 671f7da..3376dff 100644 --- a/src/gdbus/peripheral_gdbus_uart.c +++ b/src/gdbus/peripheral_gdbus_uart.c @@ -49,10 +49,7 @@ static int __uart_proxy_init(void) static int __uart_proxy_deinit(void) { - if (uart_proxy == NULL) { - _E("Uart proxy is NULL"); - return PERIPHERAL_ERROR_IO_ERROR; - } + RETVM_IF(uart_proxy == NULL, PERIPHERAL_ERROR_IO_ERROR, "Uart proxy is NULL"); g_object_unref(uart_proxy); if (!G_IS_OBJECT(uart_proxy)) @@ -101,8 +98,25 @@ int peripheral_gdbus_uart_open(peripheral_uart_h uart, int port) return ret; } -int peripheral_gdbus_uart_close(void) +int peripheral_gdbus_uart_close(peripheral_uart_h uart) { - int ret = __uart_proxy_deinit(); + RETVM_IF(uart_proxy == NULL, PERIPHERAL_ERROR_IO_ERROR, "Uart proxy is NULL"); + + int ret; + GError *error = NULL; + + if (peripheral_io_gdbus_uart_call_close_sync( + uart_proxy, + uart->handle, + &ret, + NULL, + &error) == FALSE) { + _E("Failed to request daemon to gpio uart : %s", error->message); + g_error_free(error); + return PERIPHERAL_ERROR_IO_ERROR; + } + + __uart_proxy_deinit(); + return ret; } diff --git a/src/gdbus/peripheral_io.xml b/src/gdbus/peripheral_io.xml index 6b987a3..00c49e7 100644 --- a/src/gdbus/peripheral_io.xml +++ b/src/gdbus/peripheral_io.xml @@ -7,6 +7,10 @@ + + + + @@ -16,6 +20,10 @@ + + + + @@ -25,6 +33,10 @@ + + + + @@ -33,6 +45,10 @@ + + + + @@ -42,5 +58,9 @@ + + + + diff --git a/src/peripheral_gpio.c b/src/peripheral_gpio.c index 229c831..4d0579b 100644 --- a/src/peripheral_gpio.c +++ b/src/peripheral_gpio.c @@ -88,7 +88,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(); + ret = peripheral_gdbus_gpio_close(gpio); if (ret != PERIPHERAL_ERROR_NONE) { _E("Failed to close the gpio pin, ret : %d", ret); return ret; diff --git a/src/peripheral_i2c.c b/src/peripheral_i2c.c index 3d9b908..c36d72f 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(); + ret = peripheral_gdbus_i2c_close(i2c); if (ret != PERIPHERAL_ERROR_NONE) { _E("Failed to close i2c communcation, ret : %d", ret); return ret; diff --git a/src/peripheral_pwm.c b/src/peripheral_pwm.c index 51ad72b..ee0e829 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"); - ret = peripheral_gdbus_pwm_close(); + ret = peripheral_gdbus_pwm_close(pwm); if (ret != PERIPHERAL_ERROR_NONE) { _E("Failed to close PWM chip, continuing anyway, ret : %d", ret); return ret; diff --git a/src/peripheral_spi.c b/src/peripheral_spi.c index 0014893..10faddb 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(); + ret = peripheral_gdbus_spi_close(spi); if (ret != PERIPHERAL_ERROR_NONE) { _E("Failed to close SPI device, continuing anyway, ret : %d", ret); return ret; diff --git a/src/peripheral_uart.c b/src/peripheral_uart.c index e66856c..2b48f85 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(); + ret = peripheral_gdbus_uart_close(uart); if (ret != PERIPHERAL_ERROR_NONE) { _E("Failed to close uart communication, continuing anyway, ret : %d", ret); return ret; -- 2.34.1