gdbus: communicate via gdbus when close 40/163240/3
authorSegwon <segwon.han@samsung.com>
Fri, 8 Dec 2017 05:57:20 +0000 (14:57 +0900)
committerSegwon <segwon.han@samsung.com>
Fri, 8 Dec 2017 08:55:13 +0000 (17:55 +0900)
Change-Id: Ieae106a611e8409c50996b68c08fcdbd3506d70b
Signed-off-by: Segwon <segwon.han@samsung.com>
16 files changed:
include/gdbus/peripheral_gdbus_gpio.h
include/gdbus/peripheral_gdbus_i2c.h
include/gdbus/peripheral_gdbus_pwm.h
include/gdbus/peripheral_gdbus_spi.h
include/gdbus/peripheral_gdbus_uart.h
src/gdbus/peripheral_gdbus_gpio.c
src/gdbus/peripheral_gdbus_i2c.c
src/gdbus/peripheral_gdbus_pwm.c
src/gdbus/peripheral_gdbus_spi.c
src/gdbus/peripheral_gdbus_uart.c
src/gdbus/peripheral_io.xml
src/peripheral_gpio.c
src/peripheral_i2c.c
src/peripheral_pwm.c
src/peripheral_spi.c
src/peripheral_uart.c

index edef2ea1aa739860b0a00f536a3df6d8001a33db..7ccc4a3a94e2f7637f78cb10f712ba3a7c8abe20 100644 (file)
@@ -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__ */
index 099da4e05bed0a00fcd134895d4c287fdc75f23b..e1b17224fe40f3da108b4e72bee6e2253ba7bebb 100644 (file)
@@ -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__ */
index e5c26c81eb823d328d859377a7314a37fb9ec348..70a4b02727b9718f80c55d835f346f070c656392 100644 (file)
@@ -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__ */
index a828c10f6ce6b35aa0cb4a2bb0a361298cf33659..94b22425d07c97d6d707d530937e033109ee5e87 100644 (file)
@@ -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_ */
index fc58ee8fbdc0584860ac89216f77ce5bb1571004..bf7af68300b76248d1eea84dff522f98b7d669f3 100644 (file)
@@ -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_ */
index 54004296a890c01b52a91d31f7a14c7f1ae91efe..dcc9ff21912af54ac4c04b674fd2b1128dbb9b32 100644 (file)
@@ -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
index e85f21b16374d7340f1cc3082b33c470d807b561..c2fb06fa985b2ac92921a6314e8daf97fe1e0ef2 100644 (file)
@@ -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;
 }
index 4b768661a39ed8ee7e776fd567540c2d31af478a..71a73446534308db64cdcc1fb957bb1c1e086130 100644 (file)
@@ -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;
 }
index d518d8524cb36e22014049dfc8e73a60b31711c7..2861d52ff71d0ab7d9ab61f5cfcde2380eb03fac 100644 (file)
@@ -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;
 }
index 671f7da7b7a9de42c3d0ab6b78b3b761ae71e498..3376dffb14488d2f77e49290c4e79cbf41029fa3 100644 (file)
@@ -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;
 }
index 6b987a3d315d862f0c2cc8f9b42bce1a7be8a7cc..00c49e764e393ffcd361d93fd8e0471a26706c9f 100644 (file)
@@ -7,6 +7,10 @@
                        <arg type="u" name="handle" direction="out"/>
                        <arg type="i" name="result" direction="out"/>
                </method>
+               <method name="Close">
+                       <arg type="u" name="handle" direction="in"/>
+                       <arg type="i" name="result" direction="out"/>
+               </method>
        </interface>
        <interface name="org.tizen.peripheral_io.i2c">
                <method name="Open">
                        <arg type="u" name="handle" direction="out"/>
                        <arg type="i" name="result" direction="out"/>
                </method>
+               <method name="Close">
+                       <arg type="u" name="handle" direction="in"/>
+                       <arg type="i" name="result" direction="out"/>
+               </method>
        </interface>
        <interface name="org.tizen.peripheral_io.pwm">
                <method name="Open">
                        <arg type="u" name="handle" direction="out"/>
                        <arg type="i" name="result" direction="out"/>
                </method>
+               <method name="Close">
+                       <arg type="u" name="handle" direction="in"/>
+                       <arg type="i" name="result" direction="out"/>
+               </method>
        </interface>
        <interface name="org.tizen.peripheral_io.uart">
                <method name="Open">
                        <arg type="u" name="handle" direction="out"/>
                        <arg type="i" name="result" direction="out"/>
                </method>
+               <method name="Close">
+                       <arg type="u" name="handle" direction="in"/>
+                       <arg type="i" name="result" direction="out"/>
+               </method>
        </interface>
        <interface name="org.tizen.peripheral_io.spi">
                <method name="Open">
@@ -42,5 +58,9 @@
                        <arg type="u" name="handle" direction="out"/>
                        <arg type="i" name="result" direction="out"/>
                </method>
+               <method name="Close">
+                       <arg type="u" name="handle" direction="in"/>
+                       <arg type="i" name="result" direction="out"/>
+               </method>
        </interface>
 </node>
index 229c831f15da58b9fff3fc561edd99c081767541..4d0579bc649afe25d8b72efb52ec976788bc4ede 100644 (file)
@@ -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;
index 3d9b90868a3bbcf057361768050c81971ccc28a5..c36d72fba996a7732e0d6aa562f35397e2161e1d 100644 (file)
@@ -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;
index 51ad72bb2272d812dcd216a7c25aaf9038b29496..ee0e82966381000d994c10eede7017af7d2586b7 100644 (file)
@@ -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;
index 0014893b6dd8aeaace388fee20f7772fcdda02de..10faddb8be2067c1afb988316ec81400fc401643 100644 (file)
@@ -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;
index e66856c3ce23c9fd9a4d9d6e233f66e16840b763..2b48f857ac11f859c42c759f3d10956da9249363 100644 (file)
@@ -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;