gdbus: communicate via gdbus when close 15/162915/2
authorSegwon <segwon.han@samsung.com>
Wed, 6 Dec 2017 07:18:54 +0000 (16:18 +0900)
committerSegwon <segwon.han@samsung.com>
Wed, 6 Dec 2017 07:41:39 +0000 (16:41 +0900)
 - in the past, when Lib was closed, gdbus disconnected and the daemon received a disconnection callback.
 - the problem is gdbus disconnection callback is called late
 - if App repeat open and close, daemon get the problem of handling open before close is processed.

Change-Id: If358b283389eebc5dfe97f6c182defef37acfce4
Signed-off-by: Segwon <segwon.han@samsung.com>
12 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_bus.c

index c9a54ee7c94dda2c1378af36173c758625ba2b85..0fa281963a18834c23373c25d8acc8483d08b313 100644 (file)
@@ -26,4 +26,10 @@ gboolean peripheral_gdbus_gpio_open(
                gint pin,
                gpointer user_data);
 
+gboolean peripheral_gdbus_gpio_close(
+               PeripheralIoGdbusGpio *gpio,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gpointer user_data);
+
 #endif /* __PERIPHERAL_GDBUS_GPIO_H__ */
index 17ae05de2a4d0616fea44f7439917754a57cf501..81b59fadae2528d2ee9dac746cf1c7e1ba6b2896 100644 (file)
@@ -27,4 +27,10 @@ gboolean peripheral_gdbus_i2c_open(
                gint address,
                gpointer user_data);
 
+gboolean peripheral_gdbus_i2c_close(
+               PeripheralIoGdbusI2c *i2c,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gpointer user_data);
+
 #endif /* __PERIPHERAL_GDBUS_I2C_H__ */
index 96807e72004e1c1eb00b3636dc579b825be19469..b61a8163a9ce1822052b3c53c80cd11785d8a113 100644 (file)
@@ -27,4 +27,10 @@ gboolean peripheral_gdbus_pwm_open(
                gint pin,
                gpointer user_data);
 
+gboolean peripheral_gdbus_pwm_close(
+               PeripheralIoGdbusPwm *pwm,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gpointer user_data);
+
 #endif /* __PERIPHERAL_GDBUS_PWM_H__ */
index ef2255cb365011fd8c4d82ec34dbecbc8d7fc2a1..c3765085c67ce323b9c25554e5f90c5de856ceb0 100644 (file)
@@ -27,4 +27,10 @@ gboolean peripheral_gdbus_spi_open(
                gint cs,
                gpointer user_data);
 
+gboolean peripheral_gdbus_spi_close(
+               PeripheralIoGdbusSpi *spi,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gpointer user_data);
+
 #endif /* __PERIPHERAL_GDBUS_SPI_H__ */
index 4e9f312d2b3cb47dc4c8dd1d413696568c576993..393a7caf3db1f28a39f3b112ed040e23d1ca9eab 100644 (file)
@@ -26,4 +26,10 @@ gboolean peripheral_gdbus_uart_open(
                gint port,
                gpointer user_data);
 
+gboolean peripheral_gdbus_uart_close(
+               PeripheralIoGdbusUart *uart,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gpointer user_data);
+
 #endif /* __PERIPHERAL_GDBUS_UART_H__ */
index be36bff18e2ea0ef7219d08cd2fe822daff2ba63..32ae9883abd4f1c39460a3b9e6548380e025574c 100644 (file)
@@ -87,5 +87,23 @@ out:
        if (gpio_fd_list != NULL)
                g_object_unref(gpio_fd_list);
 
+       return true;
+}
+
+gboolean peripheral_gdbus_gpio_close(
+               PeripheralIoGdbusGpio *gpio,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gpointer user_data)
+{
+       int ret = PERIPHERAL_ERROR_NONE;
+
+       peripheral_h gpio_handle = GUINT_TO_POINTER(handle);
+
+       g_bus_unwatch_name(gpio_handle->watch_id);
+       ret = peripheral_handle_gpio_destroy(gpio_handle);
+
+       peripheral_io_gdbus_gpio_complete_close(gpio, invocation, ret);
+
        return true;
 }
\ No newline at end of file
index 2efc340370d56d4e4799a1d7cf3fe7e2bdfacc34..4522cb63734c49e68e1d4a73e48127785463f20f 100644 (file)
@@ -88,3 +88,21 @@ out:
 
        return true;
 }
+
+gboolean peripheral_gdbus_i2c_close(
+               PeripheralIoGdbusI2c *i2c,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gpointer user_data)
+{
+       int ret = PERIPHERAL_ERROR_NONE;
+
+       peripheral_h i2c_handle = GUINT_TO_POINTER(handle);
+
+       g_bus_unwatch_name(i2c_handle->watch_id);
+       ret = peripheral_handle_i2c_destroy(i2c_handle);
+
+       peripheral_io_gdbus_i2c_complete_close(i2c, invocation, ret);
+
+       return true;
+}
\ No newline at end of file
index 252ba8bc03a050e058335cc97b063c4c6d5830f6..379dd1f35e5c74bd08710d2fbb87d6293798d361 100644 (file)
@@ -91,3 +91,21 @@ out:
 
        return true;
 }
+
+gboolean peripheral_gdbus_pwm_close(
+               PeripheralIoGdbusPwm *pwm,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gpointer user_data)
+{
+       int ret = PERIPHERAL_ERROR_NONE;
+
+       peripheral_h pwm_handle = GUINT_TO_POINTER(handle);
+
+       g_bus_unwatch_name(pwm_handle->watch_id);
+       ret = peripheral_handle_pwm_destroy(pwm_handle);
+
+       peripheral_io_gdbus_pwm_complete_close(pwm, invocation, ret);
+
+       return true;
+}
\ No newline at end of file
index f389fb3916673bdbd0f21a0eb58851495579c0dd..c395ad669323da8b9dcca51f17327bc5a2af5833 100644 (file)
@@ -89,3 +89,20 @@ out:
        return true;
 }
 
+gboolean peripheral_gdbus_spi_close(
+               PeripheralIoGdbusSpi *spi,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gpointer user_data)
+{
+       int ret = PERIPHERAL_ERROR_NONE;
+
+       peripheral_h spi_handle = GUINT_TO_POINTER(handle);
+
+       g_bus_unwatch_name(spi_handle->watch_id);
+       ret = peripheral_handle_spi_destroy(spi_handle);
+
+       peripheral_io_gdbus_spi_complete_close(spi, invocation, ret);
+
+       return true;
+}
\ No newline at end of file
index 497d95edeb2130b2cfcb6405ab88c6564a14697b..35c1facdfb8a0d56affb1e03c14e0d591d7cf22b 100644 (file)
@@ -87,3 +87,21 @@ out:
 
        return true;
 }
+
+gboolean peripheral_gdbus_uart_close(
+               PeripheralIoGdbusUart *uart,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gpointer user_data)
+{
+       int ret = PERIPHERAL_ERROR_NONE;
+
+       peripheral_h uart_handle = GUINT_TO_POINTER(handle);
+
+       g_bus_unwatch_name(uart_handle->watch_id);
+       ret = peripheral_handle_uart_destroy(uart_handle);
+
+       peripheral_io_gdbus_uart_complete_close(uart, invocation, ret);
+
+       return true;
+}
\ No newline at end of file
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 7edbaabf9990937654e9486ed1d931e530f7e000..e7ddcfbe7e953d96eb6018616c9058d6c6fbdab9 100644 (file)
@@ -52,6 +52,10 @@ static gboolean __gpio_init(peripheral_info_s *info)
                        "handle-open",
                        G_CALLBACK(peripheral_gdbus_gpio_open),
                        info);
+       g_signal_connect(info->gpio_skeleton,
+                       "handle-close",
+                       G_CALLBACK(peripheral_gdbus_gpio_close),
+                       info);
 
        manager = g_dbus_object_manager_server_new(PERIPHERAL_GDBUS_GPIO_PATH);
 
@@ -83,6 +87,10 @@ static gboolean __i2c_init(peripheral_info_s *info)
                        "handle-open",
                        G_CALLBACK(peripheral_gdbus_i2c_open),
                        info);
+       g_signal_connect(info->i2c_skeleton,
+                       "handle-close",
+                       G_CALLBACK(peripheral_gdbus_i2c_close),
+                       info);
 
        manager = g_dbus_object_manager_server_new(PERIPHERAL_GDBUS_I2C_PATH);
 
@@ -114,6 +122,10 @@ static gboolean __pwm_init(peripheral_info_s *info)
                        "handle-open",
                        G_CALLBACK(peripheral_gdbus_pwm_open),
                        info);
+       g_signal_connect(info->pwm_skeleton,
+                       "handle-close",
+                       G_CALLBACK(peripheral_gdbus_pwm_close),
+                       info);
 
        manager = g_dbus_object_manager_server_new(PERIPHERAL_GDBUS_PWM_PATH);
 
@@ -145,6 +157,10 @@ static gboolean __uart_init(peripheral_info_s *info)
                        "handle-open",
                        G_CALLBACK(peripheral_gdbus_uart_open),
                        info);
+       g_signal_connect(info->uart_skeleton,
+                       "handle-close",
+                       G_CALLBACK(peripheral_gdbus_uart_close),
+                       info);
 
        manager = g_dbus_object_manager_server_new(PERIPHERAL_GDBUS_UART_PATH);
 
@@ -176,6 +192,10 @@ static gboolean __spi_init(peripheral_info_s *info)
                        "handle-open",
                        G_CALLBACK(peripheral_gdbus_spi_open),
                        info);
+       g_signal_connect(info->spi_skeleton,
+                       "handle-close",
+                       G_CALLBACK(peripheral_gdbus_spi_close),
+                       info);
 
        manager = g_dbus_object_manager_server_new(PERIPHERAL_GDBUS_SPI_PATH);