[4/6] fd passing: get file descriptor list from daemon through gdbus 99/160099/2
authorSegwon <segwon.han@samsung.com>
Tue, 14 Nov 2017 10:58:32 +0000 (19:58 +0900)
committerSegwon <segwon.han@samsung.com>
Tue, 14 Nov 2017 11:31:27 +0000 (20:31 +0900)
 - save the received fds to handle.
 - it only receive fds when the open function is run.

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

index 42025de30c087fcda7e56637b5fd1517b0a6053d..52fce3e49886633d08c323801f41a43a580f6249 100644 (file)
@@ -16,6 +16,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <gio/gunixfdlist.h>
 
 #include "peripheral_io.h"
 #include "peripheral_gdbus.h"
 #include "peripheral_internal.h"
 #include "peripheral_io_gdbus.h"
 
+#define GPIO_FD_INDEX_DIRECTION 0
+#define GPIO_FD_INDEX_EDGE      1
+#define GPIO_FD_INDEX_VALUE     2
+
 extern int peripheral_gpio_interrupted_cb_handler(int pin, int value, unsigned long long timestamp, int err);
 
 static PeripheralIoGdbusGpio *gpio_proxy = NULL;
@@ -77,14 +82,17 @@ int peripheral_gdbus_gpio_open(peripheral_gpio_h gpio)
 {
        GError *error = NULL;
        gint32 ret = PERIPHERAL_ERROR_NONE;
+       GUnixFDList *fd_list = NULL;
 
        if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
 
        if (peripheral_io_gdbus_gpio_call_open_sync(
                        gpio_proxy,
                        gpio->pin,
+                       NULL,
                        &gpio->handle,
                        &ret,
+                       &fd_list,
                        NULL,
                        &error) == FALSE) {
                _E("Error in %s() : %s", __func__, error->message);
@@ -92,6 +100,29 @@ int peripheral_gdbus_gpio_open(peripheral_gpio_h gpio)
                return PERIPHERAL_ERROR_UNKNOWN;
        }
 
+       gpio->fd_direction = g_unix_fd_list_get(fd_list, GPIO_FD_INDEX_DIRECTION, &error);
+       if (gpio->fd_direction < 0) {
+               _E("Failed to get fd for gpio direction : %s", error->message);
+               g_error_free(error);
+               ret = PERIPHERAL_ERROR_UNKNOWN;
+       }
+
+       gpio->fd_edge = g_unix_fd_list_get(fd_list, GPIO_FD_INDEX_EDGE, &error);
+       if (gpio->fd_edge < 0) {
+               _E("Failed to get fd for gpio edge : %s", error->message);
+               g_error_free(error);
+               ret = PERIPHERAL_ERROR_UNKNOWN;
+       }
+
+       gpio->fd_value = g_unix_fd_list_get(fd_list, GPIO_FD_INDEX_VALUE, &error);
+       if (gpio->fd_value < 0) {
+               _E("Failed to get fd for gpio value : %s", error->message);
+               g_error_free(error);
+               ret = PERIPHERAL_ERROR_UNKNOWN;
+       }
+
+       g_object_unref(fd_list);
+
        return ret;
 }
 
index e0a39ac45c3fb768b719014e8a9b87026c1d88d6..a3290abdf426126faadae77b463e3546fbf6d0c9 100644 (file)
@@ -16,6 +16,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <gio/gunixfdlist.h>
 
 #include "peripheral_io.h"
 #include "peripheral_gdbus.h"
@@ -23,6 +24,8 @@
 #include "peripheral_internal.h"
 #include "peripheral_io_gdbus.h"
 
+#define I2C_FD_INDEX 0
+
 static PeripheralIoGdbusI2c *i2c_proxy = NULL;
 
 void i2c_proxy_init(void)
@@ -56,6 +59,7 @@ int peripheral_gdbus_i2c_open(peripheral_i2c_h i2c, int bus, int address)
 {
        GError *error = NULL;
        peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+       GUnixFDList *fd_list = NULL;
 
        if (i2c_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
 
@@ -63,8 +67,10 @@ int peripheral_gdbus_i2c_open(peripheral_i2c_h i2c, int bus, int address)
                        i2c_proxy,
                        bus,
                        address,
+                       NULL,
                        &i2c->handle,
                        &ret,
+                       &fd_list,
                        NULL,
                        &error) == FALSE) {
                _E("Error in %s() : %s", __func__, error->message);
@@ -72,6 +78,15 @@ int peripheral_gdbus_i2c_open(peripheral_i2c_h i2c, int bus, int address)
                return PERIPHERAL_ERROR_UNKNOWN;
        }
 
+       i2c->fd = g_unix_fd_list_get(fd_list, I2C_FD_INDEX, &error);
+       if (i2c->fd < 0) {
+               _E("Failed to get fd for i2c : %s", error->message);
+               g_error_free(error);
+               ret = PERIPHERAL_ERROR_UNKNOWN;
+       }
+
+       g_object_unref(fd_list);
+
        return ret;
 }
 
index e1fdae98b0d32032d2523c2df5c791250aa54d90..1eb34359cc1292ae569f1711d13311bf04977878 100644 (file)
@@ -16,6 +16,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <gio/gunixfdlist.h>
 
 #include "peripheral_io.h"
 #include "peripheral_gdbus.h"
 #include "peripheral_internal.h"
 #include "peripheral_io_gdbus.h"
 
+#define PWM_FD_INDEX_PERIOD      0
+#define PWM_FD_INDEX_DUTY_CYCLE  1
+#define PWM_FD_INDEX_POLARITY    2
+#define PWM_FD_INDEX_ENABLE      3
+
 static PeripheralIoGdbusPwm *pwm_proxy = NULL;
 
 void pwm_proxy_init(void)
@@ -56,6 +62,7 @@ int peripheral_gdbus_pwm_open(peripheral_pwm_h pwm, int chip, int pin)
 {
        GError *error = NULL;
        peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+       GUnixFDList *fd_list = NULL;
 
        if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
 
@@ -63,8 +70,10 @@ int peripheral_gdbus_pwm_open(peripheral_pwm_h pwm, int chip, int pin)
                        pwm_proxy,
                        chip,
                        pin,
+                       NULL,
                        &pwm->handle,
                        &ret,
+                       &fd_list,
                        NULL,
                        &error) == FALSE) {
                _E("%s", error->message);
@@ -72,6 +81,36 @@ int peripheral_gdbus_pwm_open(peripheral_pwm_h pwm, int chip, int pin)
                return PERIPHERAL_ERROR_UNKNOWN;
        }
 
+       pwm->fd_period = g_unix_fd_list_get(fd_list, PWM_FD_INDEX_PERIOD, &error);
+       if (pwm->fd_period < 0) {
+               _E("Failed to get fd for pwm period : %s", error->message);
+               g_error_free(error);
+               ret = PERIPHERAL_ERROR_UNKNOWN;
+       }
+
+       pwm->fd_duty_cycle = g_unix_fd_list_get(fd_list, PWM_FD_INDEX_DUTY_CYCLE, &error);
+       if (pwm->fd_duty_cycle < 0) {
+               _E("Failed to get fd for pwm duty cycle : %s", error->message);
+               g_error_free(error);
+               ret = PERIPHERAL_ERROR_UNKNOWN;
+       }
+
+       pwm->fd_polarity = g_unix_fd_list_get(fd_list, PWM_FD_INDEX_POLARITY, &error);
+       if (pwm->fd_polarity < 0) {
+               _E("Failed to get fd for pwm polarity : %s", error->message);
+               g_error_free(error);
+               ret = PERIPHERAL_ERROR_UNKNOWN;
+       }
+
+       pwm->fd_enable = g_unix_fd_list_get(fd_list, PWM_FD_INDEX_ENABLE, &error);
+       if (pwm->fd_enable < 0) {
+               _E("Failed to get fd for pwm enable : %s", error->message);
+               g_error_free(error);
+               ret = PERIPHERAL_ERROR_UNKNOWN;
+       }
+
+       g_object_unref(fd_list);
+
        return ret;
 }
 
index cc7a8a52487e8e30175503ffac54c667294f0a5c..2959835d3e1250e37983536edc71123f1cbb5747 100644 (file)
@@ -16,6 +16,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <gio/gunixfdlist.h>
 
 #include "peripheral_io.h"
 #include "peripheral_gdbus.h"
@@ -23,6 +24,8 @@
 #include "peripheral_internal.h"
 #include "peripheral_io_gdbus.h"
 
+#define SPI_FD_INDEX 0
+
 static PeripheralIoGdbusSpi *spi_proxy = NULL;
 
 void spi_proxy_init(void)
@@ -56,6 +59,7 @@ int peripheral_gdbus_spi_open(peripheral_spi_h spi, int bus, int cs)
 {
        GError *error = NULL;
        peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+       GUnixFDList *fd_list = NULL;
 
        if (spi_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
 
@@ -63,8 +67,10 @@ int peripheral_gdbus_spi_open(peripheral_spi_h spi, int bus, int cs)
                        spi_proxy,
                        bus,
                        cs,
+                       NULL,
                        &spi->handle,
                        &ret,
+                       &fd_list,
                        NULL,
                        &error) == FALSE) {
                _E("%s", error->message);
@@ -72,6 +78,15 @@ int peripheral_gdbus_spi_open(peripheral_spi_h spi, int bus, int cs)
                return PERIPHERAL_ERROR_UNKNOWN;
        }
 
+       spi->fd = g_unix_fd_list_get(fd_list, SPI_FD_INDEX, &error);
+       if (spi->fd < 0) {
+               _E("Failed to get fd for spi : %s", error->message);
+               g_error_free(error);
+               ret = PERIPHERAL_ERROR_UNKNOWN;
+       }
+
+       g_object_unref(fd_list);
+
        return ret;
 }
 
index 78bc0c0b039ad36adf31c76112ca1c0e0124ff14..e7e57b692599041020601080567c50f7d8feb1ea 100644 (file)
@@ -16,6 +16,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <gio/gunixfdlist.h>
 
 #include "peripheral_io.h"
 #include "peripheral_gdbus.h"
@@ -23,6 +24,8 @@
 #include "peripheral_internal.h"
 #include "peripheral_io_gdbus.h"
 
+#define UART_FD_INDEX 0
+
 static PeripheralIoGdbusUart *uart_proxy = NULL;
 
 void uart_proxy_init(void)
@@ -56,14 +59,17 @@ int peripheral_gdbus_uart_open(peripheral_uart_h uart, int port)
 {
        GError *error = NULL;
        peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+       GUnixFDList *fd_list = NULL;
 
        if (uart_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
 
        if (peripheral_io_gdbus_uart_call_open_sync(
                        uart_proxy,
                        port,
+                       NULL,
                        &uart->handle,
                        &ret,
+                       &fd_list,
                        NULL,
                        &error) == FALSE) {
                _E("Error in %s() : %s", __func__, error->message);
@@ -71,6 +77,15 @@ int peripheral_gdbus_uart_open(peripheral_uart_h uart, int port)
                return PERIPHERAL_ERROR_UNKNOWN;
        }
 
+       uart->fd = g_unix_fd_list_get(fd_list, UART_FD_INDEX, &error);
+       if (uart->fd < 0) {
+               _E("Failed to get fd for uart : %s", error->message);
+               g_error_free(error);
+               ret = PERIPHERAL_ERROR_UNKNOWN;
+       }
+
+       g_object_unref(fd_list);
+
        return ret;
 }
 
index 466efac26db3187e0bba513f30b1025778fa6719..30ceaa6bc6c19ed36edb0de69f0fd835a5581d58 100644 (file)
@@ -2,6 +2,7 @@
 <node>
        <interface name="org.tizen.peripheral_io.gpio">
                <method name="Open">
+                       <annotation name="org.gtk.GDBus.C.UnixFD" value="true"/>
                        <arg type="i" name="pin" direction="in"/>
                        <arg type="u" name="handle" direction="out"/>
                        <arg type="i" name="result" direction="out"/>
@@ -46,6 +47,7 @@
        </interface>
        <interface name="org.tizen.peripheral_io.i2c">
                <method name="Open">
+                       <annotation name="org.gtk.GDBus.C.UnixFD" value="true"/>
                        <arg type="i" name="bus" direction="in"/>
                        <arg type="i" name="address" direction="in"/>
                        <arg type="u" name="handle" direction="out"/>
@@ -83,6 +85,7 @@
        </interface>
        <interface name="org.tizen.peripheral_io.pwm">
                <method name="Open">
+                       <annotation name="org.gtk.GDBus.C.UnixFD" value="true"/>
                        <arg type="i" name="chip" direction="in"/>
                        <arg type="i" name="pin" direction="in"/>
                        <arg type="u" name="handle" direction="out"/>
        </interface>
        <interface name="org.tizen.peripheral_io.uart">
                <method name="Open">
+                       <annotation name="org.gtk.GDBus.C.UnixFD" value="true"/>
                        <arg type="i" name="port" direction="in"/>
                        <arg type="u" name="handle" direction="out"/>
                        <arg type="i" name="result" direction="out"/>
        </interface>
        <interface name="org.tizen.peripheral_io.spi">
                <method name="Open">
+                       <annotation name="org.gtk.GDBus.C.UnixFD" value="true"/>
                        <arg type="i" name="bus" direction="in"/>
                        <arg type="i" name="cs" direction="in"/>
                        <arg type="u" name="handle" direction="out"/>