[5/5] fd passing: make fd list and send it to Lib 79/161479/3
authorSegwon <segwon.han@samsung.com>
Thu, 23 Nov 2017 13:11:06 +0000 (22:11 +0900)
committerSegwon <segwon.han@samsung.com>
Fri, 24 Nov 2017 04:51:20 +0000 (13:51 +0900)
Change-Id: Ie76575d1357035abbb32d7af1f9e61d6a5c32c39
Signed-off-by: Segwon <segwon.han@samsung.com>
include/handle/peripheral_handle_gpio.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

index 23e2b17f223300a9c09e8cb964b0399153b84c4d..7d2dc48b3f04fc507534ac325001d4b07c2dfbfb 100644 (file)
@@ -17,7 +17,7 @@
 #ifndef __PERIPHERAL_HANDLE_GPIO_H__
 #define __PERIPHERAL_HANDLE_GPIO_H__
 
-int peripheral_handle_gpio_create(int pin, peripheral_h *handle, gpointer user_data);
+int peripheral_handle_gpio_create(gint pin, peripheral_h *handle, gpointer user_data);
 int peripheral_handle_gpio_destroy(peripheral_h handle);
 
 #endif /* __PERIPHERAL_HANDLE_GPIO_H__ */
index 25327910fea9b23cd544f71714ffe8be7dd82356..be36bff18e2ea0ef7219d08cd2fe822daff2ba63 100644 (file)
@@ -42,10 +42,10 @@ gboolean peripheral_gdbus_gpio_open(
                gint pin,
                gpointer user_data)
 {
-       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+       int ret = PERIPHERAL_ERROR_NONE;
+
        peripheral_info_s *info = (peripheral_info_s*)user_data;
        peripheral_h gpio_handle = NULL;
-
        GUnixFDList *gpio_fd_list = NULL;
 
        ret = peripheral_privilege_check(invocation, info->connection);
@@ -55,8 +55,23 @@ gboolean peripheral_gdbus_gpio_open(
                goto out;
        }
 
-       if ((ret = peripheral_handle_gpio_create(pin, &gpio_handle, user_data)) < PERIPHERAL_ERROR_NONE)
+       gpio_fd_list = g_unix_fd_list_new();
+       if (gpio_fd_list == NULL) {
+               _E("Failed to create gpio fd list");
+               ret = PERIPHERAL_ERROR_OUT_OF_MEMORY;
+               goto out;
+       }
+
+       ret = peripheral_handle_gpio_create(pin, &gpio_handle, user_data);
+       if (ret != PERIPHERAL_ERROR_NONE) {
+               _E("Failed to create peripheral gpio handle");
                goto out;
+       }
+
+       /* Do not change the order of the fd list */
+       g_unix_fd_list_append(gpio_fd_list, gpio_handle->type.gpio.fd_direction, NULL);
+       g_unix_fd_list_append(gpio_fd_list, gpio_handle->type.gpio.fd_edge, NULL);
+       g_unix_fd_list_append(gpio_fd_list, gpio_handle->type.gpio.fd_value, NULL);
 
        gpio_handle->watch_id = g_bus_watch_name(G_BUS_TYPE_SYSTEM,
                        g_dbus_method_invocation_get_sender(invocation),
@@ -69,5 +84,8 @@ gboolean peripheral_gdbus_gpio_open(
 out:
        peripheral_io_gdbus_gpio_complete_open(gpio, invocation, gpio_fd_list, GPOINTER_TO_UINT(gpio_handle), ret);
 
+       if (gpio_fd_list != NULL)
+               g_object_unref(gpio_fd_list);
+
        return true;
 }
\ No newline at end of file
index 367739a56364f3429cd29fbbbcd44111a9f98180..2efc340370d56d4e4799a1d7cf3fe7e2bdfacc34 100644 (file)
@@ -15,6 +15,7 @@
  */
 
 #include <peripheral_io.h>
+#include <gio/gunixfdlist.h>
 
 #include "peripheral_log.h"
 #include "peripheral_privilege.h"
@@ -42,10 +43,10 @@ gboolean peripheral_gdbus_i2c_open(
                gint address,
                gpointer user_data)
 {
+       int ret = PERIPHERAL_ERROR_NONE;
+
        peripheral_info_s *info = (peripheral_info_s*)user_data;
-       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
        peripheral_h i2c_handle = NULL;
-
        GUnixFDList *i2c_fd_list = NULL;
 
        ret = peripheral_privilege_check(invocation, info->connection);
@@ -55,8 +56,21 @@ gboolean peripheral_gdbus_i2c_open(
                goto out;
        }
 
-       if ((ret = peripheral_handle_i2c_create(bus, address, &i2c_handle, user_data)) < PERIPHERAL_ERROR_NONE)
+       i2c_fd_list = g_unix_fd_list_new();
+       if (i2c_fd_list == NULL) {
+               _E("Failed to create i2c fd list");
+               ret = PERIPHERAL_ERROR_OUT_OF_MEMORY;
+               goto out;
+       }
+
+       ret = peripheral_handle_i2c_create(bus, address, &i2c_handle, user_data);
+       if (ret != PERIPHERAL_ERROR_NONE) {
+               _E("Failed to create periphreal i2c handle");
                goto out;
+       }
+
+       /* Do not change the order of the fd list */
+       g_unix_fd_list_append(i2c_fd_list, i2c_handle->type.i2c.fd, NULL);
 
        i2c_handle->watch_id = g_bus_watch_name(G_BUS_TYPE_SYSTEM,
                        g_dbus_method_invocation_get_sender(invocation),
@@ -69,5 +83,8 @@ gboolean peripheral_gdbus_i2c_open(
 out:
        peripheral_io_gdbus_i2c_complete_open(i2c, invocation, i2c_fd_list, GPOINTER_TO_UINT(i2c_handle), ret);
 
+       if (i2c_fd_list != NULL)
+               g_object_unref(i2c_fd_list);
+
        return true;
 }
index 7df9d0e151b024463740e58f9531c508c15973e6..252ba8bc03a050e058335cc97b063c4c6d5830f6 100644 (file)
@@ -15,6 +15,7 @@
  */
 
 #include <peripheral_io.h>
+#include <gio/gunixfdlist.h>
 
 #include "peripheral_log.h"
 #include "peripheral_privilege.h"
@@ -42,10 +43,10 @@ gboolean peripheral_gdbus_pwm_open(
                gint pin,
                gpointer user_data)
 {
+       int ret = PERIPHERAL_ERROR_NONE;
+
        peripheral_info_s *info = (peripheral_info_s*)user_data;
-       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
        peripheral_h pwm_handle = NULL;
-
        GUnixFDList *pwm_fd_list = NULL;
 
        ret = peripheral_privilege_check(invocation, info->connection);
@@ -55,8 +56,24 @@ gboolean peripheral_gdbus_pwm_open(
                goto out;
        }
 
-       if ((ret = peripheral_handle_pwm_create(chip, pin, &pwm_handle, user_data)) <  PERIPHERAL_ERROR_NONE)
+       pwm_fd_list = g_unix_fd_list_new();
+       if (pwm_fd_list == NULL) {
+               _E("Failed to create pwm fd list");
+               ret = PERIPHERAL_ERROR_OUT_OF_MEMORY;
+               goto out;
+       }
+
+       ret = peripheral_handle_pwm_create(chip, pin, &pwm_handle, user_data);
+       if (ret != PERIPHERAL_ERROR_NONE) {
+               _E("Failed to create peripheral pwm handle");
                goto out;
+       }
+
+       /* Do not change the order of the fd list */
+       g_unix_fd_list_append(pwm_fd_list, pwm_handle->type.pwm.fd_period, NULL);
+       g_unix_fd_list_append(pwm_fd_list, pwm_handle->type.pwm.fd_duty_cycle, NULL);
+       g_unix_fd_list_append(pwm_fd_list, pwm_handle->type.pwm.fd_polarity, NULL);
+       g_unix_fd_list_append(pwm_fd_list, pwm_handle->type.pwm.fd_enable, NULL);
 
        pwm_handle->watch_id = g_bus_watch_name(G_BUS_TYPE_SYSTEM,
                        g_dbus_method_invocation_get_sender(invocation),
@@ -69,5 +86,8 @@ gboolean peripheral_gdbus_pwm_open(
 out:
        peripheral_io_gdbus_pwm_complete_open(pwm, invocation, pwm_fd_list, GPOINTER_TO_UINT(pwm_handle), ret);
 
+       if (pwm_fd_list != NULL)
+               g_object_unref(pwm_fd_list);
+
        return true;
 }
index d8e054149bf67dcdf533a67612cd890797e58cd3..f389fb3916673bdbd0f21a0eb58851495579c0dd 100644 (file)
@@ -15,6 +15,7 @@
  */
 
 #include <peripheral_io.h>
+#include <gio/gunixfdlist.h>
 
 #include "peripheral_log.h"
 #include "peripheral_privilege.h"
@@ -42,10 +43,10 @@ gboolean peripheral_gdbus_spi_open(
                gint cs,
                gpointer user_data)
 {
+       int ret = PERIPHERAL_ERROR_NONE;
+
        peripheral_info_s *info = (peripheral_info_s*)user_data;
-       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
        peripheral_h spi_handle = NULL;
-
        GUnixFDList *spi_fd_list = NULL;
 
        ret = peripheral_privilege_check(invocation, info->connection);
@@ -55,8 +56,21 @@ gboolean peripheral_gdbus_spi_open(
                goto out;
        }
 
-       if ((ret = peripheral_handle_spi_create(bus, cs, &spi_handle, user_data)) < PERIPHERAL_ERROR_NONE)
+       spi_fd_list = g_unix_fd_list_new();
+       if (spi_fd_list == NULL) {
+               _E("Failed to create spi fd list");
+               ret = PERIPHERAL_ERROR_OUT_OF_MEMORY;
+               goto out;
+       }
+
+       ret = peripheral_handle_spi_create(bus, cs, &spi_handle, user_data);
+       if (ret != PERIPHERAL_ERROR_NONE) {
+               _E("Failed to create peripheral spi handle");
                goto out;
+       }
+
+       /* Do not change the order of the fd list */
+       g_unix_fd_list_append(spi_fd_list, spi_handle->type.spi.fd, NULL);
 
        spi_handle->watch_id = g_bus_watch_name(G_BUS_TYPE_SYSTEM,
                        g_dbus_method_invocation_get_sender(invocation),
@@ -69,6 +83,9 @@ gboolean peripheral_gdbus_spi_open(
 out:
        peripheral_io_gdbus_spi_complete_open(spi, invocation, spi_fd_list, GPOINTER_TO_UINT(spi_handle), ret);
 
+       if (spi_fd_list != NULL)
+               g_object_unref(spi_fd_list);
+
        return true;
 }
 
index 9442db2ef1bbbf40b133c4f7d5fdb262fcce13ff..497d95edeb2130b2cfcb6405ab88c6564a14697b 100644 (file)
@@ -15,6 +15,7 @@
  */
 
 #include <peripheral_io.h>
+#include <gio/gunixfdlist.h>
 
 #include "peripheral_log.h"
 #include "peripheral_privilege.h"
@@ -41,10 +42,10 @@ gboolean peripheral_gdbus_uart_open(
                gint port,
                gpointer user_data)
 {
+       int ret = PERIPHERAL_ERROR_NONE;
+
        peripheral_info_s *info = (peripheral_info_s*)user_data;
-       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
        peripheral_h uart_handle = NULL;
-
        GUnixFDList *uart_fd_list = NULL;
 
        ret = peripheral_privilege_check(invocation, info->connection);
@@ -54,8 +55,21 @@ gboolean peripheral_gdbus_uart_open(
                goto out;
        }
 
-       if ((ret = peripheral_handle_uart_create(port, &uart_handle, user_data)) < PERIPHERAL_ERROR_NONE)
+       uart_fd_list = g_unix_fd_list_new();
+       if (uart_fd_list == NULL) {
+               _E("Failed to create uart fd list");
+               ret = PERIPHERAL_ERROR_OUT_OF_MEMORY;
+               goto out;
+       }
+
+       ret = peripheral_handle_uart_create(port, &uart_handle, user_data);
+       if (ret != PERIPHERAL_ERROR_NONE) {
+               _E("Failed to create peripheral uart handle");
                goto out;
+       }
+
+       /* Do not change the order of the fd list */
+       g_unix_fd_list_append(uart_fd_list, uart_handle->type.uart.fd, NULL);
 
        uart_handle->watch_id = g_bus_watch_name(G_BUS_TYPE_SYSTEM,
                        g_dbus_method_invocation_get_sender(invocation),
@@ -68,5 +82,8 @@ gboolean peripheral_gdbus_uart_open(
 out:
        peripheral_io_gdbus_uart_complete_open(uart, invocation, uart_fd_list, GPOINTER_TO_UINT(uart_handle), ret);
 
+       if (uart_fd_list != NULL)
+               g_object_unref(uart_fd_list);
+
        return true;
 }