From: Segwon Date: Tue, 14 Nov 2017 10:58:32 +0000 (+0900) Subject: [4/6] fd passing: get file descriptor list from daemon through gdbus X-Git-Tag: submit/tizen_4.0/20171220.125806^2~30 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F99%2F160099%2F2;p=platform%2Fcore%2Fapi%2Fperipheral-io.git [4/6] fd passing: get file descriptor list from daemon through gdbus - save the received fds to handle. - it only receive fds when the open function is run. Change-Id: Iaa3c87adaab0254c519b2f695068ae79850e3a23 Signed-off-by: Segwon --- diff --git a/src/gdbus/peripheral_gdbus_gpio.c b/src/gdbus/peripheral_gdbus_gpio.c index 42025de..52fce3e 100644 --- a/src/gdbus/peripheral_gdbus_gpio.c +++ b/src/gdbus/peripheral_gdbus_gpio.c @@ -16,6 +16,7 @@ #include #include +#include #include "peripheral_io.h" #include "peripheral_gdbus.h" @@ -23,6 +24,10 @@ #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; } diff --git a/src/gdbus/peripheral_gdbus_i2c.c b/src/gdbus/peripheral_gdbus_i2c.c index e0a39ac..a3290ab 100644 --- a/src/gdbus/peripheral_gdbus_i2c.c +++ b/src/gdbus/peripheral_gdbus_i2c.c @@ -16,6 +16,7 @@ #include #include +#include #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; } diff --git a/src/gdbus/peripheral_gdbus_pwm.c b/src/gdbus/peripheral_gdbus_pwm.c index e1fdae9..1eb3435 100644 --- a/src/gdbus/peripheral_gdbus_pwm.c +++ b/src/gdbus/peripheral_gdbus_pwm.c @@ -16,6 +16,7 @@ #include #include +#include #include "peripheral_io.h" #include "peripheral_gdbus.h" @@ -23,6 +24,11 @@ #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; } diff --git a/src/gdbus/peripheral_gdbus_spi.c b/src/gdbus/peripheral_gdbus_spi.c index cc7a8a5..2959835 100644 --- a/src/gdbus/peripheral_gdbus_spi.c +++ b/src/gdbus/peripheral_gdbus_spi.c @@ -16,6 +16,7 @@ #include #include +#include #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; } diff --git a/src/gdbus/peripheral_gdbus_uart.c b/src/gdbus/peripheral_gdbus_uart.c index 78bc0c0..e7e57b6 100644 --- a/src/gdbus/peripheral_gdbus_uart.c +++ b/src/gdbus/peripheral_gdbus_uart.c @@ -16,6 +16,7 @@ #include #include +#include #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; } diff --git a/src/gdbus/peripheral_io.xml b/src/gdbus/peripheral_io.xml index 466efac..30ceaa6 100644 --- a/src/gdbus/peripheral_io.xml +++ b/src/gdbus/peripheral_io.xml @@ -2,6 +2,7 @@ + @@ -46,6 +47,7 @@ + @@ -83,6 +85,7 @@ + @@ -115,6 +118,7 @@ + @@ -168,6 +172,7 @@ +