handle: add fd values to handle and add interface function 21/161421/8
authorSegwon <segwon.han@samsung.com>
Thu, 23 Nov 2017 09:06:47 +0000 (18:06 +0900)
committerSegwon <segwon.han@samsung.com>
Fri, 24 Nov 2017 04:43:21 +0000 (13:43 +0900)
Change-Id: I910023125072b2b3660cbf8d0e5974afabda2a73
Signed-off-by: Segwon <segwon.han@samsung.com>
20 files changed:
include/handle/peripheral_handle.h
include/handle/peripheral_handle_gpio.h
include/handle/peripheral_handle_uart.h
include/interface/peripheral_interface_gpio.h
include/interface/peripheral_interface_i2c.h
include/interface/peripheral_interface_pwm.h
include/interface/peripheral_interface_spi.h
include/interface/peripheral_interface_uart.h
src/gdbus/peripheral_gdbus_uart.c
src/handle/peripheral_handle_gpio.c
src/handle/peripheral_handle_i2c.c
src/handle/peripheral_handle_pwm.c
src/handle/peripheral_handle_spi.c
src/handle/peripheral_handle_uart.c
src/interface/peripheral_interface_gpio.c
src/interface/peripheral_interface_i2c.c
src/interface/peripheral_interface_pwm.c
src/interface/peripheral_interface_spi.c
src/interface/peripheral_interface_uart.c
src/util/peripheral_privilege.c

index 90e4d79a3310e73c3cfe178ee1571eab220bc60d..871f31170ee8afe0d6b623935ec6bd39e17c27a4 100644 (file)
@@ -41,6 +41,9 @@ typedef struct {
 
 typedef struct {
        int pin;
+       int fd_direction;
+       int fd_edge;
+       int fd_value;
 } peripheral_handle_gpio_s;
 
 typedef struct {
@@ -52,6 +55,10 @@ typedef struct {
 typedef struct {
        int chip;
        int pin;
+       int fd_period;
+       int fd_duty_cycle;
+       int fd_polarity;
+       int fd_enable;
 } peripheral_handle_pwm_s;
 
 typedef struct {
index 7d2dc48b3f04fc507534ac325001d4b07c2dfbfb..23e2b17f223300a9c09e8cb964b0399153b84c4d 100644 (file)
@@ -17,7 +17,7 @@
 #ifndef __PERIPHERAL_HANDLE_GPIO_H__
 #define __PERIPHERAL_HANDLE_GPIO_H__
 
-int peripheral_handle_gpio_create(gint pin, peripheral_h *handle, gpointer user_data);
+int peripheral_handle_gpio_create(int pin, peripheral_h *handle, gpointer user_data);
 int peripheral_handle_gpio_destroy(peripheral_h handle);
 
 #endif /* __PERIPHERAL_HANDLE_GPIO_H__ */
index c72dedcaf5ea8e64ad7acd24552019b209352db0..960d66b3cf22d0219f0a2c347627953ecd8d63bd 100644 (file)
@@ -17,7 +17,7 @@
 #ifndef __PERIPHERAL_HANDLE_UART_H__
 #define __PERIPHERAL_HANDLE_UART_H__
 
-int peripheral_handle_uart_open(int port, peripheral_h *handle, gpointer user_data);
+int peripheral_handle_uart_create(int port, peripheral_h *handle, gpointer user_data);
 int peripheral_handle_uart_destroy(peripheral_h handle);
 
 #endif /* __PERIPHERAL_HANDLE_UART_H__ */
index 6edf3bded258f296e70367f1c69031515a63bbeb..10b5f54035a51fd4b0d85348593527697d140c5d 100644 (file)
 #ifndef __PERIPHERAL_INTERFACE_GPIO_H__
 #define __PERIPHERAL_INTERFACE_GPIO_H__
 
-int peripheral_interface_gpio_open(int pin);
-int peripheral_interface_gpio_close(int pin);
-int peripheral_interface_gpio_open_file_direction(int pin, int *fd_out);
-int peripheral_interface_gpio_open_file_edge(int pin, int *fd_out);
-int peripheral_interface_gpio_open_file_value(int pin, int *fd_out);
+int peripheral_interface_gpio_export(int pin);
+int peripheral_interface_gpio_unexport(int pin);
+
+int peripheral_interface_gpio_fd_direction_open(int pin, int *fd_out);
+int peripheral_interface_gpio_fd_direction_close(int fd);
+
+int peripheral_interface_gpio_fd_edge_open(int pin, int *fd_out);
+int peripheral_interface_gpio_fd_edge_close(int fd);
+
+int peripheral_interface_gpio_fd_value_open(int pin, int *fd_out);
+int peripheral_interface_gpio_fd_value_close(int fd);
 
 #endif /*__PERIPHERAL_INTERFACE_GPIO_H__*/
index e21199b9d29600b151927f2edb6abf7b7f1d3086..e0e5ecb0406c136fbe771d18eff119b1b44ea771 100644 (file)
@@ -17,7 +17,7 @@
 #ifndef __PERIPHERAL_INTERFACE_I2C_H__
 #define __PERIPHERAL_INTERFACE_I2C_H__
 
-int peripheral_interface_i2c_open_file(int bus, int address, int *fd_out);
-int peripheral_interface_i2c_close(int fd);
+int peripheral_interface_i2c_fd_open(int bus, int address, int *fd_out);
+int peripheral_interface_i2c_fd_close(int fd);
 
 #endif /* __PERIPHERAL_INTERFACE_I2C_H__ */
index ffc7a84accbc61ddc19cc8bb377e6576c2a35ef1..1a257ca30422a1183a3226874f0dfc10b6b1d8d3 100644 (file)
 #ifndef __PERIPHERAL_INTERFACE_PWM_H__
 #define __PERIPHERAL_INTERFACE_PWM_H__
 
-int peripheral_interface_pwm_open(int chip, int pin);
-int peripheral_interface_pwm_close(int chip, int pin);
-int peripheral_interface_pwm_open_file_period(int chip, int pin, int *fd_out);
-int peripheral_interface_pwm_open_file_duty_cycle(int chip, int pin, int *fd_out);
-int peripheral_interface_pwm_open_file_polarity(int chip, int pin, int *fd_out);
-int peripheral_interface_pwm_open_file_enable(int chip, int pin, int *fd_out);
+int peripheral_interface_pwm_export(int chip, int pin);
+int peripheral_interface_pwm_unexport(int chip, int pin);
+
+int peripheral_interface_pwm_fd_period_open(int chip, int pin, int *fd_out);
+int peripheral_interface_pwm_fd_period_close(int fd);
+
+int peripheral_interface_pwm_fd_duty_cycle_open(int chip, int pin, int *fd_out);
+int peripheral_interface_pwm_fd_duty_cycle_close(int fd);
+
+int peripheral_interface_pwm_fd_polarity_open(int chip, int pin, int *fd_out);
+int peripheral_interface_pwm_fd_polarity_close(int fd);
+
+int peripheral_interface_pwm_fd_enable_open(int chip, int pin, int *fd_out);
+int peripheral_interface_pwm_fd_enable_close(int fd);
 
 #endif /* __PERIPHERAL_INTERFACE_PWM_H__ */
index c08f6b2b5028fc1efb3f793d0273f76a397a58c7..581d68393b2b1aca7e3687b2a2423500356dcb3e 100644 (file)
@@ -17,7 +17,7 @@
 #ifndef __PERIPHERAL_INTERFACE_SPI_H__
 #define __PERIPHERAL_INTERFACE_SPI_H__
 
-int peripheral_interface_spi_open_file(int bus, int cs, int *fd_out);
-int peripheral_interface_spi_close(int fd);
+int peripheral_interface_spi_fd_open(int bus, int cs, int *fd_out);
+int peripheral_interface_spi_fd_close(int fd);
 
 #endif /* __PERIPHERAL_INTERFACE_SPI_H__ */
index 343353a6c6653e845fe4a6892f6688a5c4fedcda..aa5d5c4fdc117b51d1b09791c050df930bbfb535 100644 (file)
@@ -17,8 +17,8 @@
 #ifndef __PERIPHERAL_INTERFACE_UART_H__
 #define __PERIPHERAL_INTERFACE_UART_H__
 
-int peripheral_interface_uart_open_file(int port, int *fd_out);
-int peripheral_interface_uart_close(int fd);
+int peripheral_interface_uart_fd_open(int port, int *fd_out);
+int peripheral_interface_uart_fd_close(int fd);
 
 #endif /* __PERIPHERAL_INTERFACE_UART_H__ */
 
index cb9b89734d25324ffd2f1850787fe051b0b6c6a2..b808779edeab15b47b10d71f0779baaae305f4cf 100644 (file)
@@ -54,7 +54,7 @@ gboolean handle_uart_open(
                goto out;
        }
 
-       if ((ret = peripheral_handle_uart_open(port, &uart_handle, user_data)) < PERIPHERAL_ERROR_NONE)
+       if ((ret = peripheral_handle_uart_create(port, &uart_handle, user_data)) < PERIPHERAL_ERROR_NONE)
                goto out;
 
        uart_handle->watch_id = g_bus_watch_name(G_BUS_TYPE_SYSTEM,
index 6faafc2fcef7959193e9ba6e7a84310b1f9839cf..8833e66fed54cf89ca6af4333e51f2e2251351d3 100644 (file)
@@ -50,45 +50,95 @@ static bool __peripheral_handle_gpio_is_creatable(int pin, peripheral_info_s *in
        return true;
 }
 
-int peripheral_handle_gpio_create(gint pin, peripheral_h *handle, gpointer user_data)
+int peripheral_handle_gpio_destroy(peripheral_h handle)
+{
+       RETVM_IF(handle == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid gpio handle");
+
+       int ret = PERIPHERAL_ERROR_NONE;
+
+       ret = peripheral_interface_gpio_fd_direction_close(handle->type.gpio.fd_direction);
+       if (ret != PERIPHERAL_ERROR_NONE)
+               _E("Failed to gpio close direction fd");
+
+       ret = peripheral_interface_gpio_fd_edge_close(handle->type.gpio.fd_edge);
+       if (ret != PERIPHERAL_ERROR_NONE)
+               _E("Failed to gpio close edge fd");
+
+       peripheral_interface_gpio_fd_value_close(handle->type.gpio.fd_value);
+       if (ret != PERIPHERAL_ERROR_NONE)
+               _E("Failed to gpio close value fd");
+
+       ret = peripheral_interface_gpio_unexport(handle->type.gpio.pin);
+       if (ret != PERIPHERAL_ERROR_NONE)
+               _E("Failed to gpio unexport");
+
+       ret = peripheral_handle_free(handle);
+       if (ret != PERIPHERAL_ERROR_NONE) {
+               _E("Failed to free gpio handle");
+               return PERIPHERAL_ERROR_UNKNOWN;
+       }
+
+       return PERIPHERAL_ERROR_NONE;
+}
+
+int peripheral_handle_gpio_create(int pin, peripheral_h *handle, gpointer user_data)
 {
+       RETVM_IF(pin < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid gpio pin");
+       RETVM_IF(handle == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid gpio handle");
+
+       int ret = PERIPHERAL_ERROR_NONE;
+
        peripheral_info_s *info = (peripheral_info_s*)user_data;
-       peripheral_h gpio_handle;
-       int ret;
 
-       if (!__peripheral_handle_gpio_is_creatable(pin, info)) {
+       peripheral_h gpio_handle = NULL;
+       bool is_handle_creatable = false;
+
+       is_handle_creatable = __peripheral_handle_gpio_is_creatable(pin, info);
+       if (is_handle_creatable == false) {
                _E("gpio %d is not available", pin);
                return PERIPHERAL_ERROR_RESOURCE_BUSY;
        }
 
-       // TODO : make fd list using the interface function
-
        gpio_handle = peripheral_handle_new(&info->gpio_list);
-       if (!gpio_handle) {
+       if (gpio_handle == NULL) {
                _E("peripheral_handle_new error");
-               ret = PERIPHERAL_ERROR_OUT_OF_MEMORY;
-               goto err;
+               return PERIPHERAL_ERROR_OUT_OF_MEMORY;
        }
 
        gpio_handle->list = &info->gpio_list;
        gpio_handle->type.gpio.pin = pin;
+       gpio_handle->type.gpio.fd_direction = -1;
+       gpio_handle->type.gpio.fd_edge = -1;
+       gpio_handle->type.gpio.fd_value = -1;
+
+       ret = peripheral_interface_gpio_export(pin);
+       if (ret != PERIPHERAL_ERROR_NONE) {
+               _E("Failed to gpio export");
+               goto out;
+       }
 
-       *handle = gpio_handle;
-
-       return PERIPHERAL_ERROR_NONE;
-
-err:
-       return ret;
-}
+       ret = peripheral_interface_gpio_fd_direction_open(pin, &gpio_handle->type.gpio.fd_direction);
+       if (ret != PERIPHERAL_ERROR_NONE) {
+               _E("Failed to gpio open direction fd");
+               goto out;
+       }
 
-int peripheral_handle_gpio_destroy(peripheral_h handle)
-{
-       int ret = PERIPHERAL_ERROR_NONE;
+       ret = peripheral_interface_gpio_fd_edge_open(pin, &gpio_handle->type.gpio.fd_edge);
+       if (ret != PERIPHERAL_ERROR_NONE) {
+               _E("Failed to gpio open edge fd");
+               goto out;
+       }
 
-       if (peripheral_handle_free(handle) < 0) {
-               _E("Failed to free gpio data");
-               ret = PERIPHERAL_ERROR_UNKNOWN;
+       ret = peripheral_interface_gpio_fd_value_open(pin, &gpio_handle->type.gpio.fd_value);
+       if (ret != PERIPHERAL_ERROR_NONE) {
+               _E("Failed to gpio open value fd");
+               goto out;
        }
 
-       return ret;;
-}
+       *handle = gpio_handle;
+       return PERIPHERAL_ERROR_NONE;
+
+out:
+       peripheral_handle_gpio_destroy(gpio_handle);
+       return ret;
+}
\ No newline at end of file
index ba97cda591f8f76c5489f0188dfcb886ba5d978f..8ed154b1168c617b084cd733edb0c1cfaebdd892 100644 (file)
@@ -23,9 +23,6 @@
 #include "peripheral_interface_i2c.h"
 #include "peripheral_handle_common.h"
 
-#define INITIAL_BUFFER_SIZE 128
-#define MAX_BUFFER_SIZE 8192
-
 static bool __peripheral_handle_i2c_is_creatable(int bus, int address, peripheral_info_s *info)
 {
        pb_board_dev_s *i2c = NULL;
@@ -54,46 +51,65 @@ static bool __peripheral_handle_i2c_is_creatable(int bus, int address, periphera
        return true;
 }
 
+int peripheral_handle_i2c_destroy(peripheral_h handle)
+{
+       RETVM_IF(handle == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid i2c handle");
+
+       int ret = PERIPHERAL_ERROR_NONE;
+
+       ret = peripheral_interface_i2c_fd_close(handle->type.i2c.fd);
+       if (ret != PERIPHERAL_ERROR_NONE)
+               _E("Failed to i2c close fd");
+
+       ret = peripheral_handle_free(handle);
+       if (ret != PERIPHERAL_ERROR_NONE) {
+               _E("Failed to free i2c handle");
+               return PERIPHERAL_ERROR_UNKNOWN;
+       }
+
+       return PERIPHERAL_ERROR_NONE;
+}
+
 int peripheral_handle_i2c_create(int bus, int address, peripheral_h *handle, gpointer user_data)
 {
+       RETVM_IF(bus < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid i2c bus");
+       RETVM_IF(address < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid i2c address");
+       RETVM_IF(handle == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid i2c handle");
+
+       int ret = PERIPHERAL_ERROR_NONE;
+
        peripheral_info_s *info = (peripheral_info_s*)user_data;
-       peripheral_h i2c_handle;
-       int ret;
 
-       if (!__peripheral_handle_i2c_is_creatable(bus, address, info)) {
+       peripheral_h i2c_handle = NULL;
+       bool is_handle_creatable = false;
+
+       is_handle_creatable = __peripheral_handle_i2c_is_creatable(bus, address, info);
+       if (is_handle_creatable == false) {
                _E("bus : %d, address : 0x%x is not available", bus, address);
                return PERIPHERAL_ERROR_RESOURCE_BUSY;
        }
 
-       // TODO : make fd list using the interface function
-
        i2c_handle = peripheral_handle_new(&info->i2c_list);
-       if (!i2c_handle) {
+       if (i2c_handle == NULL) {
                _E("peripheral_handle_new error");
-               ret = PERIPHERAL_ERROR_OUT_OF_MEMORY;
-               goto err;
+               return PERIPHERAL_ERROR_OUT_OF_MEMORY;
        }
 
        i2c_handle->list = &info->i2c_list;
        i2c_handle->type.i2c.bus = bus;
        i2c_handle->type.i2c.address = address;
+       i2c_handle->type.i2c.fd = -1;
 
-       *handle = i2c_handle;
+       ret = peripheral_interface_i2c_fd_open(bus, address, &i2c_handle->type.i2c.fd);
+       if (ret != PERIPHERAL_ERROR_NONE) {
+               _E("Failed to i2c fd open");
+               goto out;
+       }
 
+       *handle = i2c_handle;
        return PERIPHERAL_ERROR_NONE;
 
-err:
+out:
+       peripheral_handle_i2c_destroy(i2c_handle);
        return ret;
-}
-
-int peripheral_handle_i2c_destroy(peripheral_h handle)
-{
-       int ret = PERIPHERAL_ERROR_NONE;
-
-       if (peripheral_handle_free(handle) < 0) {
-               _E("Failed to free i2c data");
-               ret = PERIPHERAL_ERROR_UNKNOWN;
-       }
-
-       return ret;
-}
+}
\ No newline at end of file
index 0cc71c567b63a655d0c4fb3b7e60abca77ab1193..2dc0a37e2174ae47532e8881a23012e192cc8f3c 100644 (file)
@@ -51,45 +51,109 @@ static bool __peripheral_handle_pwm_is_creatable(int chip, int pin, peripheral_i
        return true;
 }
 
+int peripheral_handle_pwm_destroy(peripheral_h handle)
+{
+       RETVM_IF(handle == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid pwm handle");
+
+       int ret = PERIPHERAL_ERROR_NONE;
+
+       ret = peripheral_interface_pwm_fd_period_close(handle->type.pwm.fd_period);
+       if (ret != PERIPHERAL_ERROR_NONE)
+               _E("Failed to pwm close period fd");
+
+       ret = peripheral_interface_pwm_fd_duty_cycle_close(handle->type.pwm.fd_duty_cycle);
+       if (ret != PERIPHERAL_ERROR_NONE)
+               _E("Failed to pwm close duty cycle fd");
+
+       ret = peripheral_interface_pwm_fd_polarity_close(handle->type.pwm.fd_polarity);
+       if (ret != PERIPHERAL_ERROR_NONE)
+               _E("Failed to pwm close polarity fd");
+
+       ret = peripheral_interface_pwm_fd_enable_close(handle->type.pwm.fd_enable);
+       if (ret != PERIPHERAL_ERROR_NONE)
+               _E("Failed to pwm close enable fd");
+
+       ret = peripheral_interface_pwm_unexport(handle->type.pwm.chip, handle->type.pwm.pin);
+       if (ret != PERIPHERAL_ERROR_NONE)
+               _E("Failed to pwm unexport");
+
+       ret = peripheral_handle_free(handle);
+       if (ret != PERIPHERAL_ERROR_NONE) {
+               _E("Failed to free pwm handle");
+               return PERIPHERAL_ERROR_UNKNOWN;
+       }
+
+       return PERIPHERAL_ERROR_NONE;
+}
+
 int peripheral_handle_pwm_create(int chip, int pin, peripheral_h *handle, gpointer user_data)
 {
+       RETVM_IF(chip < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid pwm chip");
+       RETVM_IF(pin < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid pwm pin");
+       RETVM_IF(handle == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid pwm handle");
+
+       int ret = PERIPHERAL_ERROR_NONE;
+
        peripheral_info_s *info = (peripheral_info_s*)user_data;
-       peripheral_h pwm_handle;
-       int ret;
 
-       if (!__peripheral_handle_pwm_is_creatable(chip, pin, info)) {
+       peripheral_h pwm_handle = NULL;
+       bool is_handle_creatable = false;
+
+       is_handle_creatable = __peripheral_handle_pwm_is_creatable(chip, pin, info);
+       if (is_handle_creatable == false) {
                _E("pwm %d.%d is not available", chip, pin);
                return PERIPHERAL_ERROR_RESOURCE_BUSY;
        }
 
-       // TODO : make fd list using the interface function
-
        pwm_handle = peripheral_handle_new(&info->pwm_list);
-       if (!pwm_handle) {
+       if (pwm_handle == NULL) {
                _E("peripheral_handle_new error");
                ret = PERIPHERAL_ERROR_OUT_OF_MEMORY;
-               goto err;
+               goto out;
        }
 
        pwm_handle->list = &info->pwm_list;
        pwm_handle->type.pwm.chip = chip;
        pwm_handle->type.pwm.pin = pin;
-       *handle = pwm_handle;
+       pwm_handle->type.pwm.fd_period = -1;
+       pwm_handle->type.pwm.fd_duty_cycle = -1;
+       pwm_handle->type.pwm.fd_polarity = -1;
+       pwm_handle->type.pwm.fd_enable = -1;
+
+       ret = peripheral_interface_pwm_export(chip, pin);
+       if (ret != PERIPHERAL_ERROR_NONE) {
+               _E("Failed to pwm export");
+               goto out;
+       }
 
-       return PERIPHERAL_ERROR_NONE;
+       ret = peripheral_interface_pwm_fd_period_open(chip, pin, &pwm_handle->type.pwm.fd_period);
+       if (ret != PERIPHERAL_ERROR_NONE) {
+               _E("Failed to pwm open period fd");
+               goto out;
+       }
 
-err:
-       return ret;
-}
+       ret = peripheral_interface_pwm_fd_duty_cycle_open(chip, pin, &pwm_handle->type.pwm.fd_duty_cycle);
+       if (ret != PERIPHERAL_ERROR_NONE) {
+               _E("Failed to pwm open duty cycle fd");
+               goto out;
+       }
 
-int peripheral_handle_pwm_destroy(peripheral_h handle)
-{
-       int ret = PERIPHERAL_ERROR_NONE;
+       ret = peripheral_interface_pwm_fd_polarity_open(chip, pin, &pwm_handle->type.pwm.fd_polarity);
+       if (ret != PERIPHERAL_ERROR_NONE) {
+               _E("Failed to pwm open polarity fd");
+               goto out;
+       }
 
-       if (peripheral_handle_free(handle) < 0) {
-               _E("Failed to free i2c data");
-               ret = PERIPHERAL_ERROR_UNKNOWN;
+       ret = peripheral_interface_pwm_fd_enable_open(chip, pin, &pwm_handle->type.pwm.fd_enable);
+       if (ret != PERIPHERAL_ERROR_NONE) {
+               _E("Failed to pwm open enable fd");
+               goto out;
        }
 
+       *handle = pwm_handle;
+       return PERIPHERAL_ERROR_NONE;
+
+out:
+       peripheral_handle_pwm_destroy(pwm_handle);
        return ret;
-}
+}
\ No newline at end of file
index fe7a2b6c9bb7a375dd1365084c5587c23baef560..730d949ac06b2305cc83d1ec86e2bbfde9200c77 100644 (file)
@@ -51,46 +51,65 @@ static bool __peripheral_handle_spi_is_creatable(int bus, int cs, peripheral_inf
        return true;
 }
 
+int peripheral_handle_spi_destroy(peripheral_h handle)
+{
+       RETVM_IF(handle == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid spi handle");
+
+       int ret = PERIPHERAL_ERROR_NONE;
+
+       ret = peripheral_interface_spi_fd_close(handle->type.spi.fd);
+       if (ret != PERIPHERAL_ERROR_NONE)
+               _E("Failed to spi close fd");
+
+       ret = peripheral_handle_free(handle);
+       if (ret != PERIPHERAL_ERROR_NONE) {
+               _E("Failed to free spi handle");
+               return PERIPHERAL_ERROR_UNKNOWN;
+       }
+
+       return PERIPHERAL_ERROR_NONE;
+}
+
 int peripheral_handle_spi_create(int bus, int cs, peripheral_h *handle, gpointer user_data)
 {
-       peripheral_info_s *info = (peripheral_info_s*)user_data;
-       peripheral_h spi_handle;
+       RETVM_IF(bus < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid spi bus");
+       RETVM_IF(cs < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid spi cs");
+       RETVM_IF(handle == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid spi handle");
+
        int ret = PERIPHERAL_ERROR_NONE;
 
-       if (!__peripheral_handle_spi_is_creatable(bus, cs, info)) {
+       peripheral_info_s *info = (peripheral_info_s*)user_data;
+
+       peripheral_h spi_handle = NULL;
+       bool is_handle_creatable = false;
+
+       is_handle_creatable = __peripheral_handle_spi_is_creatable(bus, cs, info);
+       if (is_handle_creatable == false) {
                _E("spi %d.%d is not available", bus, cs);
                return PERIPHERAL_ERROR_RESOURCE_BUSY;
        }
 
-       // TODO : make fd list using the interface function
-
        spi_handle = peripheral_handle_new(&info->spi_list);
-       if (!spi_handle) {
+       if (spi_handle == NULL) {
                _E("peripheral_handle_new error");
-               ret = PERIPHERAL_ERROR_OUT_OF_MEMORY;
-               goto err_spi_data;
+               return PERIPHERAL_ERROR_OUT_OF_MEMORY;
        }
 
        spi_handle->list = &info->spi_list;
        spi_handle->type.spi.bus = bus;
        spi_handle->type.spi.cs = cs;
+       spi_handle->type.spi.fd = -1;
 
-       *handle = spi_handle;
+       ret = peripheral_interface_spi_fd_open(bus, cs, &spi_handle->type.spi.fd);
+       if (ret != PERIPHERAL_ERROR_NONE) {
+               _E("Failed to spi fd open");
+               goto out;
+       }
 
+       *handle = spi_handle;
        return PERIPHERAL_ERROR_NONE;
 
-err_spi_data:
-       return ret;
-}
-
-int peripheral_handle_spi_destroy(peripheral_h handle)
-{
-       int ret = PERIPHERAL_ERROR_NONE;
-
-       if (peripheral_handle_free(handle) < 0) {
-               _E("Failed to free spi data");
-               ret = PERIPHERAL_ERROR_UNKNOWN;
-       }
-
+out:
+       peripheral_handle_spi_destroy(spi_handle);
        return ret;
 }
\ No newline at end of file
index ae92440a6a9482a270a26d1255b0085128d8157e..f05d9edd57c847413f6b0f3f2b24b3df80db7300 100644 (file)
@@ -23,9 +23,6 @@
 #include "peripheral_interface_uart.h"
 #include "peripheral_handle_common.h"
 
-#define INITIAL_BUFFER_SIZE 128
-#define MAX_BUFFER_SIZE 8192
-
 static bool __peripheral_handle_uart_is_creatable(int port, peripheral_info_s *info)
 {
        pb_board_dev_s *uart = NULL;
@@ -54,45 +51,63 @@ static bool __peripheral_handle_uart_is_creatable(int port, peripheral_info_s *i
        return true;
 }
 
-int peripheral_handle_uart_open(int port, peripheral_h *handle, gpointer user_data)
+int peripheral_handle_uart_destroy(peripheral_h handle)
 {
-       peripheral_info_s *info = (peripheral_info_s*)user_data;
-       peripheral_h uart_handle;
+       RETVM_IF(handle == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid uart handle");
+
        int ret = PERIPHERAL_ERROR_NONE;
 
-       if (!__peripheral_handle_uart_is_creatable(port, info)) {
+       ret = peripheral_interface_uart_fd_close(handle->type.uart.fd);
+       if (ret != PERIPHERAL_ERROR_NONE)
+               _E("Failed to uart close fd");
+
+       ret = peripheral_handle_free(handle);
+       if (ret != PERIPHERAL_ERROR_NONE) {
+               _E("Failed to free uart handle");
+               return PERIPHERAL_ERROR_UNKNOWN;
+       }
+
+       return PERIPHERAL_ERROR_NONE;
+}
+
+int peripheral_handle_uart_create(int port, peripheral_h *handle, gpointer user_data)
+{
+       RETVM_IF(port < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid uart port");
+       RETVM_IF(handle == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid uart handle");
+
+       int ret = PERIPHERAL_ERROR_NONE;
+
+       peripheral_info_s *info = (peripheral_info_s*)user_data;
+
+       peripheral_h uart_handle = NULL;
+       bool is_handle_creatable = false;
+
+       is_handle_creatable = __peripheral_handle_uart_is_creatable(port, info);
+       if (is_handle_creatable == false) {
                _E("uart %d is not available", port);
                return PERIPHERAL_ERROR_RESOURCE_BUSY;
        }
 
-       // TODO : make fd list using the interface function
-
        uart_handle = peripheral_handle_new(&info->uart_list);
-       if (!uart_handle) {
+       if (uart_handle == NULL) {
                _E("peripheral_handle_new error");
-               ret = PERIPHERAL_ERROR_OUT_OF_MEMORY;
-               goto err;
+               return PERIPHERAL_ERROR_OUT_OF_MEMORY;
        }
 
        uart_handle->list = &info->uart_list;
        uart_handle->type.uart.port = port;
+       uart_handle->type.uart.fd = -1;
 
-       *handle = uart_handle;
+       ret = peripheral_interface_uart_fd_open(port, &uart_handle->type.uart.fd);
+       if (ret != PERIPHERAL_ERROR_NONE) {
+               _E("Failed to uart fd open");
+               goto out;
+       }
 
+       *handle = uart_handle;
        return PERIPHERAL_ERROR_NONE;
 
-err:
-       return ret;
-}
-
-int peripheral_handle_uart_destroy(peripheral_h handle)
-{
-       int ret = PERIPHERAL_ERROR_NONE;
-
-       if (peripheral_handle_free(handle) < 0) {
-               _E("Failed to free uart data");
-               ret = PERIPHERAL_ERROR_UNKNOWN;
-       }
-
+out:
+       peripheral_handle_uart_destroy(uart_handle);
        return ret;
 }
\ No newline at end of file
index d7b8e84b64240442c836400350086eccdb3f748f..8cd45a2cabb0c0969ae19d9f2f0b8651752433c1 100644 (file)
@@ -84,7 +84,7 @@ out:
        return ret;
 }
 
-int peripheral_interface_gpio_open(int pin)
+int peripheral_interface_gpio_export(int pin)
 {
        RETVM_IF(pin < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid gpio pin");
 
@@ -112,7 +112,7 @@ int peripheral_interface_gpio_open(int pin)
        return PERIPHERAL_ERROR_NONE;
 }
 
-int peripheral_interface_gpio_close(int pin)
+int peripheral_interface_gpio_unexport(int pin)
 {
        RETVM_IF(pin < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid gpio pin");
 
@@ -134,7 +134,7 @@ int peripheral_interface_gpio_close(int pin)
        return PERIPHERAL_ERROR_NONE;
 }
 
-int peripheral_interface_gpio_open_file_direction(int pin, int *fd_out)
+int peripheral_interface_gpio_fd_direction_open(int pin, int *fd_out)
 {
        RETVM_IF(pin < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid gpio pin");
        RETVM_IF(fd_out == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid fd_out for gpio direction");
@@ -151,7 +151,19 @@ int peripheral_interface_gpio_open_file_direction(int pin, int *fd_out)
        return PERIPHERAL_ERROR_NONE;
 }
 
-int peripheral_interface_gpio_open_file_edge(int pin, int *fd_out)
+int peripheral_interface_gpio_fd_direction_close(int fd)
+{
+       RETVM_IF(fd < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid fd for gpio direction");
+
+       int ret;
+
+       ret = close(fd);
+       IF_ERROR_RETURN(ret != 0);
+
+       return PERIPHERAL_ERROR_NONE;
+}
+
+int peripheral_interface_gpio_fd_edge_open(int pin, int *fd_out)
 {
        RETVM_IF(pin < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid gpio pin");
        RETVM_IF(fd_out == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid fd_out for gpio edge");
@@ -168,7 +180,19 @@ int peripheral_interface_gpio_open_file_edge(int pin, int *fd_out)
        return PERIPHERAL_ERROR_NONE;
 }
 
-int peripheral_interface_gpio_open_file_value(int pin, int *fd_out)
+int peripheral_interface_gpio_fd_edge_close(int fd)
+{
+       RETVM_IF(fd < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid fd for gpio edge");
+
+       int ret;
+
+       ret = close(fd);
+       IF_ERROR_RETURN(ret != 0);
+
+       return PERIPHERAL_ERROR_NONE;
+}
+
+int peripheral_interface_gpio_fd_value_open(int pin, int *fd_out)
 {
        RETVM_IF(pin < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid gpio pin");
        RETVM_IF(fd_out == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid fd_out for gpio value");
@@ -184,3 +208,16 @@ int peripheral_interface_gpio_open_file_value(int pin, int *fd_out)
 
        return PERIPHERAL_ERROR_NONE;
 }
+
+int peripheral_interface_gpio_fd_value_close(int fd)
+{
+       RETVM_IF(fd < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid fd for gpio value");
+
+       int ret;
+
+       ret = close(fd);
+       IF_ERROR_RETURN(ret != 0);
+
+       return PERIPHERAL_ERROR_NONE;
+}
+
index fc9f5b9fadaea95f4ef47856848cbe7cbde630f3..000aad5e736eebb5bee16603d1345f85ccb467bf 100644 (file)
@@ -21,7 +21,7 @@
 
 #define I2C_SLAVE      0x0703  /* Use this slave address */
 
-int peripheral_interface_i2c_open_file(int bus, int address, int *fd_out)
+int peripheral_interface_i2c_fd_open(int bus, int address, int *fd_out)
 {
        RETVM_IF(bus < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid i2c bus");
        RETVM_IF(address < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid i2c address");
@@ -43,7 +43,7 @@ int peripheral_interface_i2c_open_file(int bus, int address, int *fd_out)
        return PERIPHERAL_ERROR_NONE;
 }
 
-int peripheral_interface_i2c_close(int fd)
+int peripheral_interface_i2c_fd_close(int fd)
 {
        RETVM_IF(fd < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid fd for i2c");
 
index 905ee8953599a8eef00caf401e11d2199f1e7b65..843a88c8c8b3df97c4f7acd9f6ec75291d80bb76 100644 (file)
@@ -17,7 +17,7 @@
 #include "peripheral_interface_pwm.h"
 #include "peripheral_interface_common.h"
 
-int peripheral_interface_pwm_open(int chip, int pin)
+int peripheral_interface_pwm_export(int chip, int pin)
 {
        RETVM_IF(chip < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid pwm chip");
        RETVM_IF(pin < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid pwm pin");
@@ -42,7 +42,7 @@ int peripheral_interface_pwm_open(int chip, int pin)
        return PERIPHERAL_ERROR_NONE;
 }
 
-int peripheral_interface_pwm_close(int chip, int pin)
+int peripheral_interface_pwm_unexport(int chip, int pin)
 {
        RETVM_IF(chip < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid pwm chip");
        RETVM_IF(pin < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid pwm pin");
@@ -69,7 +69,7 @@ int peripheral_interface_pwm_close(int chip, int pin)
        return PERIPHERAL_ERROR_NONE;
 }
 
-int peripheral_interface_pwm_open_file_period(int chip, int pin, int *fd_out)
+int peripheral_interface_pwm_fd_period_open(int chip, int pin, int *fd_out)
 {
        RETVM_IF(chip < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid pwm chip");
        RETVM_IF(pin < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid pwm pin");
@@ -87,7 +87,19 @@ int peripheral_interface_pwm_open_file_period(int chip, int pin, int *fd_out)
        return PERIPHERAL_ERROR_NONE;
 }
 
-int peripheral_interface_pwm_open_file_duty_cycle(int chip, int pin, int *fd_out)
+int peripheral_interface_pwm_fd_period_close(int fd)
+{
+       RETVM_IF(fd < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid fd for pwm period");
+
+       int ret;
+
+       ret = close(fd);
+       IF_ERROR_RETURN(ret != 0);
+
+       return PERIPHERAL_ERROR_NONE;
+}
+
+int peripheral_interface_pwm_fd_duty_cycle_open(int chip, int pin, int *fd_out)
 {
        RETVM_IF(chip < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid pwm chip");
        RETVM_IF(pin < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid pwm pin");
@@ -105,7 +117,19 @@ int peripheral_interface_pwm_open_file_duty_cycle(int chip, int pin, int *fd_out
        return PERIPHERAL_ERROR_NONE;
 }
 
-int peripheral_interface_pwm_open_file_polarity(int chip, int pin, int *fd_out)
+int peripheral_interface_pwm_fd_duty_cycle_close(int fd)
+{
+       RETVM_IF(fd < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid fd for pwm duty cycle");
+
+       int ret;
+
+       ret = close(fd);
+       IF_ERROR_RETURN(ret != 0);
+
+       return PERIPHERAL_ERROR_NONE;
+}
+
+int peripheral_interface_pwm_fd_polarity_open(int chip, int pin, int *fd_out)
 {
        RETVM_IF(chip < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid pwm chip");
        RETVM_IF(pin < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid pwm pin");
@@ -123,7 +147,19 @@ int peripheral_interface_pwm_open_file_polarity(int chip, int pin, int *fd_out)
        return PERIPHERAL_ERROR_NONE;
 }
 
-int peripheral_interface_pwm_open_file_enable(int chip, int pin, int *fd_out)
+int peripheral_interface_pwm_fd_polarity_close(int fd)
+{
+       RETVM_IF(fd < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid fd for pwm polarity");
+
+       int ret;
+
+       ret = close(fd);
+       IF_ERROR_RETURN(ret != 0);
+
+       return PERIPHERAL_ERROR_NONE;
+}
+
+int peripheral_interface_pwm_fd_enable_open(int chip, int pin, int *fd_out)
 {
        RETVM_IF(chip < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid pwm chip");
        RETVM_IF(pin < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid pwm pin");
@@ -138,5 +174,17 @@ int peripheral_interface_pwm_open_file_enable(int chip, int pin, int *fd_out)
 
        *fd_out = fd;
 
+       return PERIPHERAL_ERROR_NONE;
+}
+
+int peripheral_interface_pwm_fd_enable_close(int fd)
+{
+       RETVM_IF(fd < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid fd for pwm enable");
+
+       int ret;
+
+       ret = close(fd);
+       IF_ERROR_RETURN(ret != 0);
+
        return PERIPHERAL_ERROR_NONE;
 }
\ No newline at end of file
index 2921d81b66e35951865a5b034b93bc44dda741cb..d19ca91958a7ed407c717d83051be64cfd7c9e92 100644 (file)
@@ -17,7 +17,7 @@
 #include "peripheral_interface_spi.h"
 #include "peripheral_interface_common.h"
 
-int peripheral_interface_spi_open_file(int bus, int cs, int *fd_out)
+int peripheral_interface_spi_fd_open(int bus, int cs, int *fd_out)
 {
        RETVM_IF(bus < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid spi bus");
        RETVM_IF(cs < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid spi cs");
@@ -36,9 +36,9 @@ int peripheral_interface_spi_open_file(int bus, int cs, int *fd_out)
        return PERIPHERAL_ERROR_NONE;
 }
 
-int peripheral_interface_spi_close(int fd)
+int peripheral_interface_spi_fd_close(int fd)
 {
-       RETVM_IF(fd < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid fd_out for spi");
+       RETVM_IF(fd < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid fd for spi");
 
        int ret;
 
index 42c3ade2b878c85c1fd1264a9d7f1715581bb4cc..7d056e70b14253266dc417e67dc212db79d00b4c 100644 (file)
@@ -23,7 +23,7 @@
 #define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0]))
 #endif
 
-int peripheral_interface_uart_open_file(int port, int *fd_out)
+int peripheral_interface_uart_fd_open(int port, int *fd_out)
 {
        RETVM_IF(port < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid uart port");
        RETVM_IF(fd_out == NULL, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid fd_out for uart");
@@ -52,9 +52,9 @@ int peripheral_interface_uart_open_file(int port, int *fd_out)
        return PERIPHERAL_ERROR_NONE;
 }
 
-int peripheral_interface_uart_close(int fd)
+int peripheral_interface_uart_fd_close(int fd)
 {
-       RETVM_IF(fd < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid fd_out for uart");
+       RETVM_IF(fd < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid fd for uart");
        int ret;
 
        ret = close(fd);
index 4abddd1b9d9a7048f290e4b0f2a0a49ffa8bc14e..cfc7bd7db761881a1341d5193c17e57369b859bb 100644 (file)
@@ -63,6 +63,8 @@ void peripheral_privilege_deinit(void)
 
 int peripheral_privilege_check(GDBusMethodInvocation *invocation, GDBusConnection *connection)
 {
+       RETVM_IF(!__cynara, -1, "Cynara does not initialized");
+
        int ret;
        int pid;
        const char *sender;
@@ -85,6 +87,7 @@ int peripheral_privilege_check(GDBusMethodInvocation *invocation, GDBusConnectio
 
        ret = cynara_check(__cynara, client, session, user, PERIPHERAL_PRIVILEGE);
        if (ret != 0) {
+               _E("Failed to check privilege");
                g_free(session);
                g_free(client);
                g_free(user);