interface: do not close request to daemon by gdbus. 02/160402/1
authorSegwon <segwon.han@samsung.com>
Thu, 16 Nov 2017 05:03:25 +0000 (14:03 +0900)
committerSegwon <segwon.han@samsung.com>
Thu, 16 Nov 2017 05:12:00 +0000 (14:12 +0900)
 - daemon will be detect gdbus disconnection by g_bus_watch_name()

Signed-off-by: Segwon <segwon.han@samsung.com>
Change-Id: Id9882a8b576b9110eb21aa66a94b3fa7e9c4b14c

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 c63aeba..1ffe214 100644 (file)
@@ -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__ */
index e1b1722..9d9f9a5 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(peripheral_i2c_h i2c);
+int peripheral_gdbus_i2c_close();
 
 #endif /* __PERIPHERAL_GDBUS_I2C_H__ */
index 70a4b02..c0764c6 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(peripheral_pwm_h pwm);
+int peripheral_gdbus_pwm_close();
 
 #endif /* __PERIPHERAL_GDBUS_PWM_H__ */
index 94b2242..6f4aaa3 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(peripheral_spi_h spi);
+int peripheral_gdbus_spi_close();
 
 #endif /* __PERIPHERAL_GDBUS_SPI_H_ */
index bf7af68..048eed5 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(peripheral_uart_h uart);
+int peripheral_gdbus_uart_close();
 
 #endif /* __PERIPHERAL_GDBUS_UART_H_ */
index c8a6d8c..c935a4c 100644 (file)
@@ -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
index 29ba888..cc5f300 100644 (file)
@@ -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;
 }
index 48ff164..4c1d916 100644 (file)
@@ -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;
 }
index fce5a41..b0653e4 100644 (file)
@@ -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;
 }
index 852e244..a15e566 100644 (file)
@@ -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;
 }
index 00c49e7..6b987a3 100644 (file)
@@ -7,10 +7,6 @@
                        <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">
@@ -58,9 +42,5 @@
                        <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 040d862..1333122 100644 (file)
@@ -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);
 
index e89e401..44d6052 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(i2c);
+       ret = peripheral_gdbus_i2c_close();
        if (ret != PERIPHERAL_ERROR_NONE)
                _E("Failed to close i2c communcation, ret : %d", ret);
 
index fb1ed14..12e6fc2 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");
 
-       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);
index 13c2b05..9b25a2e 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(spi);
+       ret = peripheral_gdbus_spi_close();
        if (ret < PERIPHERAL_ERROR_NONE)
                _E("Failed to close SPI device, continuing anyway, ret : %d", ret);
 
index d7d3577..b18ccff 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(uart);
+       ret = peripheral_gdbus_uart_close();
        if (ret < PERIPHERAL_ERROR_NONE)
                _E("Failed to close uart communication, continuing anyway, ret : %d", ret);