typedef struct {
int pin;
- int fd_direction;
- int fd_edge;
- int fd_value;
} peripheral_handle_gpio_s;
typedef struct {
int bus;
int address;
- int fd;
} peripheral_handle_i2c_s;
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 {
int port;
- int fd;
} peripheral_handle_uart_s;
typedef struct {
int bus;
int cs;
- int fd;
} peripheral_handle_spi_s;
typedef struct {
#ifndef __PERIPHERAL_INTERFACE_GPIO_H__
#define __PERIPHERAL_INTERFACE_GPIO_H__
+#include <gio/gunixfdlist.h>
+
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);
+int peripheral_interface_gpio_fd_list_create(int pin, GUnixFDList **list_out);
+void peripheral_interface_gpio_fd_list_destroy(GUnixFDList *list);
#endif /*__PERIPHERAL_INTERFACE_GPIO_H__*/
#ifndef __PERIPHERAL_INTERFACE_I2C_H__
#define __PERIPHERAL_INTERFACE_I2C_H__
-int peripheral_interface_i2c_fd_open(int bus, int address, int *fd_out);
-int peripheral_interface_i2c_fd_close(int fd);
+#include <gio/gunixfdlist.h>
+
+int peripheral_interface_i2c_fd_list_create(int bus, int address, GUnixFDList **list_out);
+void peripheral_interface_i2c_fd_list_destroy(GUnixFDList *list);
#endif /* __PERIPHERAL_INTERFACE_I2C_H__ */
#ifndef __PERIPHERAL_INTERFACE_PWM_H__
#define __PERIPHERAL_INTERFACE_PWM_H__
+#include <gio/gunixfdlist.h>
+
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);
+int peripheral_interface_pwm_fd_list_create(int chip, int pin, GUnixFDList **list_out);
+void peripheral_interface_pwm_fd_list_destroy(GUnixFDList *list);
#endif /* __PERIPHERAL_INTERFACE_PWM_H__ */
#ifndef __PERIPHERAL_INTERFACE_SPI_H__
#define __PERIPHERAL_INTERFACE_SPI_H__
-int peripheral_interface_spi_fd_open(int bus, int cs, int *fd_out);
-int peripheral_interface_spi_fd_close(int fd);
+#include <gio/gunixfdlist.h>
+
+int peripheral_interface_spi_fd_list_create(int bus, int cs, GUnixFDList **list_out);
+void peripheral_interface_spi_fd_list_destroy(GUnixFDList *list);
#endif /* __PERIPHERAL_INTERFACE_SPI_H__ */
#ifndef __PERIPHERAL_INTERFACE_UART_H__
#define __PERIPHERAL_INTERFACE_UART_H__
-int peripheral_interface_uart_fd_open(int port, int *fd_out);
-int peripheral_interface_uart_fd_close(int fd);
+#include <gio/gunixfdlist.h>
+
+int peripheral_interface_uart_fd_list_create(int port, GUnixFDList **list_out);
+void peripheral_interface_uart_fd_list_destroy(GUnixFDList *list);
#endif /* __PERIPHERAL_INTERFACE_UART_H__ */
#include "peripheral_io_gdbus.h"
#include "peripheral_handle.h"
#include "peripheral_handle_gpio.h"
+#include "peripheral_interface_gpio.h"
#include "peripheral_gdbus_gpio.h"
static void __gpio_on_name_vanished(GDBusConnection *connection,
- const gchar *name,
- gpointer user_data)
+ const gchar *name,
+ gpointer user_data)
{
+ int ret = PERIPHERAL_ERROR_NONE;
+
peripheral_h gpio_handle = (peripheral_h)user_data;
_D("appid [%s] vanished ", name);
g_bus_unwatch_name(gpio_handle->watch_id);
- peripheral_handle_gpio_destroy(gpio_handle);
+
+ ret = peripheral_interface_gpio_unexport(gpio_handle->type.gpio.pin);
+ if (ret != PERIPHERAL_ERROR_NONE)
+ _E("Failed to unexport gpio");
+
+ ret = peripheral_handle_gpio_destroy(gpio_handle);
+ if (ret != PERIPHERAL_ERROR_NONE)
+ _E("Failed to destroy gpio handle");
}
gboolean peripheral_gdbus_gpio_open(
goto out;
}
- gpio_fd_list = g_unix_fd_list_new();
- if (gpio_fd_list == NULL) {
+ ret = peripheral_interface_gpio_export(pin);
+ if (ret != PERIPHERAL_ERROR_NONE) {
+ _E("Failed to export gpio");
+ goto out;
+ }
+
+ ret = peripheral_interface_gpio_fd_list_create(pin, &gpio_fd_list);
+ if (ret != PERIPHERAL_ERROR_NONE) {
_E("Failed to create gpio fd list");
- ret = PERIPHERAL_ERROR_OUT_OF_MEMORY;
+ peripheral_interface_gpio_unexport(pin);
goto out;
}
ret = peripheral_handle_gpio_create(pin, &gpio_handle, user_data);
if (ret != PERIPHERAL_ERROR_NONE) {
- _E("Failed to create peripheral gpio handle");
+ _E("Failed to create gpio handle");
+ peripheral_interface_gpio_unexport(pin);
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),
G_BUS_NAME_WATCHER_FLAGS_NONE,
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);
+ peripheral_interface_gpio_fd_list_destroy(gpio_fd_list);
return true;
}
peripheral_h gpio_handle = GUINT_TO_POINTER(handle);
g_bus_unwatch_name(gpio_handle->watch_id);
+
+ ret = peripheral_interface_gpio_unexport(gpio_handle->type.gpio.pin);
+ if (ret != PERIPHERAL_ERROR_NONE)
+ _E("Failed to gpio unexport");
+
ret = peripheral_handle_gpio_destroy(gpio_handle);
+ if (ret != PERIPHERAL_ERROR_NONE)
+ _E("Failed to destroy gpio handle");
peripheral_io_gdbus_gpio_complete_close(gpio, invocation, ret);
#include "peripheral_io_gdbus.h"
#include "peripheral_handle.h"
#include "peripheral_handle_i2c.h"
+#include "peripheral_interface_i2c.h"
#include "peripheral_gdbus_i2c.h"
static void __i2c_on_name_vanished(GDBusConnection *connection,
- const gchar *name,
- gpointer user_data)
+ const gchar *name,
+ gpointer user_data)
{
+ int ret = PERIPHERAL_ERROR_NONE;
+
peripheral_h i2c_handle = (peripheral_h)user_data;
_D("appid [%s] vanished ", name);
g_bus_unwatch_name(i2c_handle->watch_id);
- peripheral_handle_i2c_destroy(i2c_handle);
+
+ ret = peripheral_handle_i2c_destroy(i2c_handle);
+ if (ret != PERIPHERAL_ERROR_NONE)
+ _E("Failed to destroy i2c handle");
}
gboolean peripheral_gdbus_i2c_open(
goto out;
}
- i2c_fd_list = g_unix_fd_list_new();
- if (i2c_fd_list == NULL) {
+ ret = peripheral_interface_i2c_fd_list_create(bus, address, &i2c_fd_list);
+ if (ret != PERIPHERAL_ERROR_NONE) {
_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");
+ _E("Failed to create 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),
G_BUS_NAME_WATCHER_FLAGS_NONE,
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);
+ peripheral_interface_i2c_fd_list_destroy(i2c_fd_list);
return true;
}
peripheral_h i2c_handle = GUINT_TO_POINTER(handle);
g_bus_unwatch_name(i2c_handle->watch_id);
+
ret = peripheral_handle_i2c_destroy(i2c_handle);
+ if (ret != PERIPHERAL_ERROR_NONE)
+ _E("Failed to destroy i2c handle");
peripheral_io_gdbus_i2c_complete_close(i2c, invocation, ret);
#include "peripheral_io_gdbus.h"
#include "peripheral_handle.h"
#include "peripheral_handle_pwm.h"
+#include "peripheral_interface_pwm.h"
#include "peripheral_gdbus_pwm.h"
static void __pwm_on_name_vanished(GDBusConnection *connection,
- const gchar *name,
- gpointer user_data)
+ const gchar *name,
+ gpointer user_data)
{
+ int ret = PERIPHERAL_ERROR_NONE;
+
peripheral_h pwm_handle = (peripheral_h)user_data;
_D("appid [%s] vanished ", name);
g_bus_unwatch_name(pwm_handle->watch_id);
- peripheral_handle_pwm_destroy(pwm_handle);
+
+ ret = peripheral_interface_pwm_unexport(pwm_handle->type.pwm.chip, pwm_handle->type.pwm.pin);
+ if (ret != PERIPHERAL_ERROR_NONE)
+ _E("Failed to unexport pwm");
+
+ ret = peripheral_handle_pwm_destroy(pwm_handle);
+ if (ret != PERIPHERAL_ERROR_NONE)
+ _E("Failed to destroy pwm handle");
}
gboolean peripheral_gdbus_pwm_open(
goto out;
}
- pwm_fd_list = g_unix_fd_list_new();
- if (pwm_fd_list == NULL) {
+ ret = peripheral_interface_pwm_export(chip, pin);
+ if (ret != PERIPHERAL_ERROR_NONE) {
+ _E("Failed to export pwm");
+ goto out;
+ }
+
+ ret = peripheral_interface_pwm_fd_list_create(chip, pin, &pwm_fd_list);
+ if (ret != PERIPHERAL_ERROR_NONE) {
_E("Failed to create pwm fd list");
- ret = PERIPHERAL_ERROR_OUT_OF_MEMORY;
+ peripheral_interface_pwm_unexport(chip, pin);
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");
+ _E("Failed to create pwm handle");
+ peripheral_interface_pwm_unexport(chip, pin);
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),
G_BUS_NAME_WATCHER_FLAGS_NONE,
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);
+ peripheral_interface_pwm_fd_list_destroy(pwm_fd_list);
return true;
}
peripheral_h pwm_handle = GUINT_TO_POINTER(handle);
g_bus_unwatch_name(pwm_handle->watch_id);
+
+ ret = peripheral_interface_pwm_unexport(pwm_handle->type.pwm.chip, pwm_handle->type.pwm.pin);
+ if (ret != PERIPHERAL_ERROR_NONE)
+ _E("Failed to unexport pwm");
+
ret = peripheral_handle_pwm_destroy(pwm_handle);
+ if (ret != PERIPHERAL_ERROR_NONE)
+ _E("Failed to destroy pwm handle");
peripheral_io_gdbus_pwm_complete_close(pwm, invocation, ret);
#include "peripheral_io_gdbus.h"
#include "peripheral_handle.h"
#include "peripheral_handle_spi.h"
+#include "peripheral_interface_spi.h"
#include "peripheral_gdbus_spi.h"
static void __spi_on_name_vanished(GDBusConnection *connection,
- const gchar *name,
- gpointer user_data)
+ const gchar *name,
+ gpointer user_data)
{
+ int ret = PERIPHERAL_ERROR_NONE;
+
peripheral_h spi_handle = (peripheral_h)user_data;
_D("appid [%s] vanished ", name);
g_bus_unwatch_name(spi_handle->watch_id);
- peripheral_handle_spi_destroy(spi_handle);
+
+ ret = peripheral_handle_spi_destroy(spi_handle);
+ if (ret != PERIPHERAL_ERROR_NONE)
+ _E("Failed to destroy spi handle");
}
gboolean peripheral_gdbus_spi_open(
goto out;
}
- spi_fd_list = g_unix_fd_list_new();
- if (spi_fd_list == NULL) {
+ ret = peripheral_interface_spi_fd_list_create(bus, cs, &spi_fd_list);
+ if (ret != PERIPHERAL_ERROR_NONE) {
_E("Failed to create spi fd list");
- ret = PERIPHERAL_ERROR_OUT_OF_MEMORY;
goto out;
}
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),
G_BUS_NAME_WATCHER_FLAGS_NONE,
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);
+ peripheral_interface_spi_fd_list_destroy(spi_fd_list);
return true;
}
peripheral_h spi_handle = GUINT_TO_POINTER(handle);
g_bus_unwatch_name(spi_handle->watch_id);
+
ret = peripheral_handle_spi_destroy(spi_handle);
+ if (ret != PERIPHERAL_ERROR_NONE)
+ _E("Failed to destroy spi handle");
peripheral_io_gdbus_spi_complete_close(spi, invocation, ret);
#include "peripheral_io_gdbus.h"
#include "peripheral_handle.h"
#include "peripheral_handle_uart.h"
+#include "peripheral_interface_uart.h"
#include "peripheral_gdbus_uart.h"
static void __uart_on_name_vanished(GDBusConnection *connection,
- const gchar *name,
- gpointer user_data)
+ const gchar *name,
+ gpointer user_data)
{
+ int ret = PERIPHERAL_ERROR_NONE;
+
peripheral_h uart_handle = (peripheral_h)user_data;
_D("appid [%s] vanished ", name);
g_bus_unwatch_name(uart_handle->watch_id);
- peripheral_handle_uart_destroy(uart_handle);
+
+ ret = peripheral_handle_uart_destroy(uart_handle);
+ if (ret != PERIPHERAL_ERROR_NONE)
+ _E("Failed to destroy uart handle");
}
gboolean peripheral_gdbus_uart_open(
goto out;
}
- uart_fd_list = g_unix_fd_list_new();
- if (uart_fd_list == NULL) {
+ ret = peripheral_interface_uart_fd_list_create(port, &uart_fd_list);
+ if (ret != PERIPHERAL_ERROR_NONE) {
_E("Failed to create uart fd list");
- ret = PERIPHERAL_ERROR_OUT_OF_MEMORY;
goto out;
}
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),
G_BUS_NAME_WATCHER_FLAGS_NONE,
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);
+ peripheral_interface_uart_fd_list_destroy(uart_fd_list);
return true;
}
peripheral_h uart_handle = GUINT_TO_POINTER(handle);
g_bus_unwatch_name(uart_handle->watch_id);
+
ret = peripheral_handle_uart_destroy(uart_handle);
+ if (ret != PERIPHERAL_ERROR_NONE)
+ _E("Failed to destroy uart handle");
peripheral_io_gdbus_uart_complete_close(uart, invocation, ret);
* limitations under the License.
*/
-#include "peripheral_interface_gpio.h"
#include "peripheral_handle_common.h"
static bool __peripheral_handle_gpio_is_creatable(int pin, peripheral_info_s *info)
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) {
+ if (ret != PERIPHERAL_ERROR_NONE)
_E("Failed to free gpio handle");
- return PERIPHERAL_ERROR_UNKNOWN;
- }
- return PERIPHERAL_ERROR_NONE;
+ return ret;
}
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 = NULL;
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;
- }
-
- 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;
- }
-
- 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;
- }
-
- 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;
- }
*handle = gpio_handle;
- return PERIPHERAL_ERROR_NONE;
-out:
- peripheral_handle_gpio_destroy(gpio_handle);
- return ret;
+ return PERIPHERAL_ERROR_NONE;
}
* limitations under the License.
*/
-#include "peripheral_interface_i2c.h"
#include "peripheral_handle_common.h"
static bool __peripheral_handle_i2c_is_creatable(int bus, int address, peripheral_info_s *info)
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) {
+ if (ret != PERIPHERAL_ERROR_NONE)
_E("Failed to free i2c handle");
- return PERIPHERAL_ERROR_UNKNOWN;
- }
- return PERIPHERAL_ERROR_NONE;
+ return ret;
}
int peripheral_handle_i2c_create(int bus, int address, peripheral_h *handle, gpointer user_data)
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 = NULL;
i2c_handle->list = &info->i2c_list;
i2c_handle->type.i2c.bus = bus;
i2c_handle->type.i2c.address = address;
- i2c_handle->type.i2c.fd = -1;
-
- 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;
-out:
- peripheral_handle_i2c_destroy(i2c_handle);
- return ret;
+ return PERIPHERAL_ERROR_NONE;
}
* limitations under the License.
*/
-#include "peripheral_interface_pwm.h"
#include "peripheral_handle_common.h"
static bool __peripheral_handle_pwm_is_creatable(int chip, int pin, peripheral_info_s *info)
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) {
+ if (ret != PERIPHERAL_ERROR_NONE)
_E("Failed to free pwm handle");
- return PERIPHERAL_ERROR_UNKNOWN;
- }
- return PERIPHERAL_ERROR_NONE;
+ return ret;
}
int peripheral_handle_pwm_create(int chip, int pin, peripheral_h *handle, gpointer user_data)
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 = NULL;
pwm_handle = peripheral_handle_new(&info->pwm_list);
if (pwm_handle == NULL) {
_E("peripheral_handle_new error");
- ret = PERIPHERAL_ERROR_OUT_OF_MEMORY;
- goto out;
+ return PERIPHERAL_ERROR_OUT_OF_MEMORY;
}
pwm_handle->list = &info->pwm_list;
pwm_handle->type.pwm.chip = chip;
pwm_handle->type.pwm.pin = pin;
- 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;
- }
-
- 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;
- }
-
- 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;
- }
-
- 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;
- }
-
- 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;
+ return PERIPHERAL_ERROR_NONE;
}
* limitations under the License.
*/
-#include "peripheral_interface_spi.h"
#include "peripheral_handle_common.h"
static bool __peripheral_handle_spi_is_creatable(int bus, int cs, peripheral_info_s *info)
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) {
+ if (ret != PERIPHERAL_ERROR_NONE)
_E("Failed to free spi handle");
- return PERIPHERAL_ERROR_UNKNOWN;
- }
- return PERIPHERAL_ERROR_NONE;
+ return ret;
}
int peripheral_handle_spi_create(int bus, int cs, peripheral_h *handle, gpointer user_data)
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;
-
peripheral_info_s *info = (peripheral_info_s*)user_data;
peripheral_h spi_handle = NULL;
spi_handle->list = &info->spi_list;
spi_handle->type.spi.bus = bus;
spi_handle->type.spi.cs = cs;
- spi_handle->type.spi.fd = -1;
-
- 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;
-out:
- peripheral_handle_spi_destroy(spi_handle);
- return ret;
+ return PERIPHERAL_ERROR_NONE;
}
* limitations under the License.
*/
-#include "peripheral_interface_uart.h"
#include "peripheral_handle_common.h"
static bool __peripheral_handle_uart_is_creatable(int port, peripheral_info_s *info)
int ret = PERIPHERAL_ERROR_NONE;
- 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) {
+ if (ret != PERIPHERAL_ERROR_NONE)
_E("Failed to free uart handle");
- return PERIPHERAL_ERROR_UNKNOWN;
- }
- return PERIPHERAL_ERROR_NONE;
+ return ret;
}
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;
uart_handle->list = &info->uart_list;
uart_handle->type.uart.port = port;
- uart_handle->type.uart.fd = -1;
-
- 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;
-out:
- peripheral_handle_uart_destroy(uart_handle);
- return ret;
+ return PERIPHERAL_ERROR_NONE;
}
return PERIPHERAL_ERROR_NONE;
}
-int peripheral_interface_gpio_fd_direction_open(int pin, int *fd_out)
+static 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");
return PERIPHERAL_ERROR_NONE;
}
-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)
+static 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");
return PERIPHERAL_ERROR_NONE;
}
-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)
+static 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");
return PERIPHERAL_ERROR_NONE;
}
-int peripheral_interface_gpio_fd_value_close(int fd)
+int peripheral_interface_gpio_fd_list_create(int pin, GUnixFDList **list_out)
{
- RETVM_IF(fd < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid fd for gpio value");
+ RETVM_IF(pin < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid gpio pin");
int ret;
- ret = close(fd);
- IF_ERROR_RETURN(ret != 0);
+ GUnixFDList *list = NULL;
+ int fd_direction = -1;
+ int fd_edge = -1;
+ int fd_value = -1;
- return PERIPHERAL_ERROR_NONE;
+ ret = __peripheral_interface_gpio_fd_direction_open(pin, &fd_direction);
+ if (ret != PERIPHERAL_ERROR_NONE) {
+ _E("Failed to open gpio direction fd");
+ goto out;
+ }
+
+ ret = __peripheral_interface_gpio_fd_edge_open(pin, &fd_edge);
+ if (ret != PERIPHERAL_ERROR_NONE) {
+ _E("Failed to open gpio edge fd");
+ goto out;
+ }
+
+ ret = __peripheral_interface_gpio_fd_value_open(pin, &fd_value);
+ if (ret != PERIPHERAL_ERROR_NONE) {
+ _E("Failed to open gpio value fd");
+ goto out;
+ }
+
+ list = g_unix_fd_list_new();
+ if (list == NULL) {
+ _E("Failed to create gpio fd list");
+ ret = PERIPHERAL_ERROR_OUT_OF_MEMORY;
+ goto out;
+ }
+
+ /* Do not change the order of the fd list */
+ g_unix_fd_list_append(list, fd_direction, NULL);
+ g_unix_fd_list_append(list, fd_edge, NULL);
+ g_unix_fd_list_append(list, fd_value, NULL);
+
+ *list_out = list;
+
+out:
+ close(fd_direction);
+ close(fd_edge);
+ close(fd_value);
+
+ return ret;
}
+void peripheral_interface_gpio_fd_list_destroy(GUnixFDList *list)
+{
+ if (list != NULL)
+ g_object_unref(list); // file descriptors in list is closed in hear.
+}
#define I2C_SLAVE 0x0703 /* Use this slave address */
-int peripheral_interface_i2c_fd_open(int bus, int address, int *fd_out)
+static 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");
return PERIPHERAL_ERROR_NONE;
}
-int peripheral_interface_i2c_fd_close(int fd)
+int peripheral_interface_i2c_fd_list_create(int bus, int address, GUnixFDList **list_out)
{
- RETVM_IF(fd < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid fd for i2c");
+ RETVM_IF(bus < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid i2c bus");
+ RETVM_IF(address < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid i2c address");
int ret;
- ret = close(fd);
- IF_ERROR_RETURN(ret != 0);
+ GUnixFDList *list = NULL;
+ int fd = -1;
- return PERIPHERAL_ERROR_NONE;
+
+ ret = __peripheral_interface_i2c_fd_open(bus, address, &fd);
+ if (ret != PERIPHERAL_ERROR_NONE) {
+ _E("Failed to open i2c fd");
+ }
+
+ list = g_unix_fd_list_new();
+ if (list == NULL) {
+ _E("Failed to create i2c fd list");
+ ret = PERIPHERAL_ERROR_OUT_OF_MEMORY;
+ goto out;
+ }
+
+ /* Do not change the order of the fd list */
+ g_unix_fd_list_append(list, fd, NULL);
+
+ *list_out = list;
+
+out:
+ close(fd);
+
+ return ret;
+}
+
+void peripheral_interface_i2c_fd_list_destroy(GUnixFDList *list)
+{
+ if (list != NULL)
+ g_object_unref(list);
}
\ No newline at end of file
return PERIPHERAL_ERROR_NONE;
}
-int peripheral_interface_pwm_fd_period_open(int chip, int pin, int *fd_out)
+static 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");
return PERIPHERAL_ERROR_NONE;
}
-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)
+static 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");
return PERIPHERAL_ERROR_NONE;
}
-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)
+static 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");
return PERIPHERAL_ERROR_NONE;
}
-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)
+static 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");
return PERIPHERAL_ERROR_NONE;
}
-int peripheral_interface_pwm_fd_enable_close(int fd)
+int peripheral_interface_pwm_fd_list_create(int chip, int pin, GUnixFDList **list_out)
{
- RETVM_IF(fd < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid fd for pwm enable");
+ RETVM_IF(chip < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid pwm chip");
+ RETVM_IF(pin < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid pwm pin");
int ret;
- ret = close(fd);
- IF_ERROR_RETURN(ret != 0);
+ GUnixFDList *list = NULL;
+ int fd_period = -1;
+ int fd_duty_cycle = -1;
+ int fd_polarity = -1;
+ int fd_enable = -1;
+
+ ret = __peripheral_interface_pwm_fd_period_open(chip, pin, &fd_period);
+ if (ret != PERIPHERAL_ERROR_NONE) {
+ _E("Failed to open pwm period fd");
+ goto out;
+ }
+
+ ret = __peripheral_interface_pwm_fd_duty_cycle_open(chip, pin, &fd_duty_cycle);
+ if (ret != PERIPHERAL_ERROR_NONE) {
+ _E("Failed to open pwm duty cycle fd");
+ goto out;
+ }
+
+ ret = __peripheral_interface_pwm_fd_polarity_open(chip, pin, &fd_polarity);
+ if (ret != PERIPHERAL_ERROR_NONE) {
+ _E("Failed to open pwm polarity fd");
+ goto out;
+ }
+
+ ret = __peripheral_interface_pwm_fd_enable_open(chip, pin, &fd_enable);
+ if (ret != PERIPHERAL_ERROR_NONE) {
+ _E("Failed to open pwm enable fd");
+ goto out;
+ }
+
+ list = g_unix_fd_list_new();
+ if (list == NULL) {
+ _E("Failed to create pwm fd list");
+ ret = PERIPHERAL_ERROR_OUT_OF_MEMORY;
+ goto out;
+ }
+
+ /* Do not change the order of the fd list */
+ g_unix_fd_list_append(list, fd_period, NULL);
+ g_unix_fd_list_append(list, fd_duty_cycle, NULL);
+ g_unix_fd_list_append(list, fd_polarity, NULL);
+ g_unix_fd_list_append(list, fd_enable, NULL);
+
+ *list_out = list;
+
+out:
+ close(fd_period);
+ close(fd_duty_cycle);
+ close(fd_polarity);
+ close(fd_enable);
+
+ return ret;
+}
- return PERIPHERAL_ERROR_NONE;
+void peripheral_interface_pwm_fd_list_destroy(GUnixFDList *list)
+{
+ if (list != NULL)
+ g_object_unref(list); // file descriptors in list is closed in hear.
}
\ No newline at end of file
#include "peripheral_interface_spi.h"
#include "peripheral_interface_common.h"
-int peripheral_interface_spi_fd_open(int bus, int cs, int *fd_out)
+static 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");
return PERIPHERAL_ERROR_NONE;
}
-int peripheral_interface_spi_fd_close(int fd)
+int peripheral_interface_spi_fd_list_create(int bus, int cs, GUnixFDList **list_out)
{
- RETVM_IF(fd < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid fd for spi");
+ RETVM_IF(bus < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid spi bus");
+ RETVM_IF(cs < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid spi chip select");
int ret;
- ret = close(fd);
- IF_ERROR_RETURN(ret != 0);
+ GUnixFDList *list = NULL;
+ int fd = -1;
- return PERIPHERAL_ERROR_NONE;
+
+ ret = __peripheral_interface_spi_fd_open(bus, cs, &fd);
+ if (ret != PERIPHERAL_ERROR_NONE) {
+ _E("Failed to open spi fd");
+ }
+
+ list = g_unix_fd_list_new();
+ if (list == NULL) {
+ _E("Failed to create spi fd list");
+ ret = PERIPHERAL_ERROR_OUT_OF_MEMORY;
+ goto out;
+ }
+
+ /* Do not change the order of the fd list */
+ g_unix_fd_list_append(list, fd, NULL);
+
+ *list_out = list;
+
+out:
+ close(fd);
+
+ return ret;
+}
+
+void peripheral_interface_spi_fd_list_destroy(GUnixFDList *list)
+{
+ if (list != NULL)
+ g_object_unref(list);
}
\ No newline at end of file
#define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0]))
#endif
-int peripheral_interface_uart_fd_open(int port, int *fd_out)
+static 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");
return PERIPHERAL_ERROR_NONE;
}
-int peripheral_interface_uart_fd_close(int fd)
+int peripheral_interface_uart_fd_list_create(int port, GUnixFDList **list_out)
{
- RETVM_IF(fd < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid fd for uart");
+ RETVM_IF(port < 0, PERIPHERAL_ERROR_INVALID_PARAMETER, "Invalid uart port");
+
int ret;
- ret = close(fd);
- IF_ERROR_RETURN(ret != 0);
+ GUnixFDList *list = NULL;
+ int fd = -1;
- return PERIPHERAL_ERROR_NONE;
+
+ ret = __peripheral_interface_uart_fd_open(port, &fd);
+ if (ret != PERIPHERAL_ERROR_NONE) {
+ _E("Failed to open uart fd");
+ }
+
+ list = g_unix_fd_list_new();
+ if (list == NULL) {
+ _E("Failed to create uart fd list");
+ ret = PERIPHERAL_ERROR_OUT_OF_MEMORY;
+ goto out;
+ }
+
+ /* Do not change the order of the fd list */
+ g_unix_fd_list_append(list, fd, NULL);
+
+ *list_out = list;
+
+out:
+ close(fd);
+
+ return ret;
+}
+
+void peripheral_interface_uart_fd_list_destroy(GUnixFDList *list)
+{
+ if (list != NULL)
+ g_object_unref(list);
}
\ No newline at end of file