* limitations under the License.
*/
-#ifndef __PERIPHERAL_BUS_H__
-#define __PERIPHERAL_BUS_H__
+#ifndef __PERIPHERAL_HANDLE_H__
+#define __PERIPHERAL_HANDLE_H__
#include <gio/gio.h>
#include "peripheral_board.h"
#include "peripheral_io_gdbus.h"
-typedef enum {
- PERIPHERAL_BUS_TYPE_GPIO = 0,
- PERIPHERAL_BUS_TYPE_I2C,
- PERIPHERAL_BUS_TYPE_PWM,
- PERIPHERAL_BUS_TYPE_UART,
- PERIPHERAL_BUS_TYPE_SPI,
-} peripheral_bus_type_e;
-
typedef struct {
pb_board_s *board;
/* devices */
GList *uart_list;
GList *spi_list;
/* gdbus variable */
- guint reg_id;
GDBusConnection *connection;
PeripheralIoGdbusGpio *gpio_skeleton;
PeripheralIoGdbusI2c *i2c_skeleton;
PeripheralIoGdbusPwm *pwm_skeleton;
PeripheralIoGdbusUart *uart_skeleton;
PeripheralIoGdbusSpi *spi_skeleton;
-} peripheral_bus_s;
-
-typedef struct {
- char *id;
- pid_t pid;
- pid_t pgid;
-} pb_client_info_s;
+} peripheral_info_s;
typedef struct {
int pin;
-} peripheral_bus_gpio_s;
+} peripheral_handle_gpio_s;
typedef struct {
int bus;
int address;
int fd;
-} peripheral_bus_i2c_s;
+} peripheral_handle_i2c_s;
typedef struct {
int chip;
int pin;
-} peripheral_bus_pwm_s;
+} peripheral_handle_pwm_s;
typedef struct {
int port;
int fd;
-} peripheral_bus_uart_s;
+} peripheral_handle_uart_s;
typedef struct {
int bus;
int cs;
int fd;
-} peripheral_bus_spi_s;
+} peripheral_handle_spi_s;
typedef struct {
- peripheral_bus_type_e type;
uint watch_id;
GList **list;
- /* client info */
- pb_client_info_s client_info;
union {
- peripheral_bus_gpio_s gpio;
- peripheral_bus_i2c_s i2c;
- peripheral_bus_pwm_s pwm;
- peripheral_bus_uart_s uart;
- peripheral_bus_spi_s spi;
- } dev;
-} peripheral_bus_data_s;
+ peripheral_handle_gpio_s gpio;
+ peripheral_handle_i2c_s i2c;
+ peripheral_handle_pwm_s pwm;
+ peripheral_handle_uart_s uart;
+ peripheral_handle_spi_s spi;
+ } type;
+} peripheral_handle_s;
-typedef peripheral_bus_data_s *pb_data_h;
+typedef peripheral_handle_s *peripheral_h;
-#endif /* __PERIPHERAL_BUS_H__ */
+#endif /* __PERIPHERAL_HANDLE_H__ */
#include "peripheral_handle.h"
#include "peripheral_log.h"
-pb_data_h peripheral_handle_new(GList **plist);
-int peripheral_handle_free(pb_data_h handle);
+peripheral_h peripheral_handle_new(GList **plist);
+int peripheral_handle_free(peripheral_h handle);
#endif /* __PERIPHERAL_HANDLE_COMMON_H__ */
#ifndef __PERIPHERAL_HANDLE_GPIO_H__
#define __PERIPHERAL_HANDLE_GPIO_H__
-int peripheral_handle_gpio_create(gint pin, pb_data_h *handle, gpointer user_data);
-int peripheral_handle_gpio_destroy(pb_data_h handle);
+int peripheral_handle_gpio_create(gint pin, peripheral_h *handle, gpointer user_data);
+int peripheral_handle_gpio_destroy(peripheral_h handle);
#endif /* __PERIPHERAL_HANDLE_GPIO_H__ */
#ifndef __PERIPHERAL_HANDLE_I2C_H__
#define __PERIPHERAL_HANDLE_I2C_H__
-int peripheral_handle_i2c_create(int bus, int address, pb_data_h *handle, gpointer user_data);
-int peripheral_handle_i2c_destroy(pb_data_h handle);
+int peripheral_handle_i2c_create(int bus, int address, peripheral_h *handle, gpointer user_data);
+int peripheral_handle_i2c_destroy(peripheral_h handle);
#endif /* __PERIPHERAL_HANDLE_I2C_H__ */
#ifndef __PERIPHERAL_HANDLE_PWM_H__
#define __PERIPHERAL_HANDLE_PWM_H__
-int peripheral_handle_pwm_create(int chip, int pin, pb_data_h *handle, gpointer user_data);
-int peripheral_handle_pwm_destroy(pb_data_h handle);
+int peripheral_handle_pwm_create(int chip, int pin, peripheral_h *handle, gpointer user_data);
+int peripheral_handle_pwm_destroy(peripheral_h handle);
#endif /* __PERIPHERAL_HANDLE_PWM_H__ */
#ifndef __PERIPHERAL_HANDLE_SPI_H__
#define __PERIPHERAL_HANDLE_SPI_H__
-int peripheral_handle_spi_create(int bus, int cs, pb_data_h *handle, gpointer user_data);
-int peripheral_handle_spi_destroy(pb_data_h handle);
+int peripheral_handle_spi_create(int bus, int cs, peripheral_h *handle, gpointer user_data);
+int peripheral_handle_spi_destroy(peripheral_h handle);
#endif /* __PERIPHERAL_HANDLE_SPI_H__ */
#ifndef __PERIPHERAL_HANDLE_UART_H__
#define __PERIPHERAL_HANDLE_UART_H__
-int peripheral_handle_uart_open(int port, pb_data_h *handle, gpointer user_data);
-int peripheral_handle_uart_destroy(pb_data_h handle);
+int peripheral_handle_uart_open(int port, peripheral_h *handle, gpointer user_data);
+int peripheral_handle_uart_destroy(peripheral_h handle);
#endif /* __PERIPHERAL_HANDLE_UART_H__ */
const gchar *name,
gpointer user_data)
{
- pb_data_h gpio_handle = (pb_data_h)user_data;
+ peripheral_h gpio_handle = (peripheral_h)user_data;
_D("appid [%s] vanished ", name);
g_bus_unwatch_name(gpio_handle->watch_id);
gpointer user_data)
{
peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
- peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
- pb_data_h gpio_handle = NULL;
+ peripheral_info_s *info = (peripheral_info_s*)user_data;
+ peripheral_h gpio_handle = NULL;
GUnixFDList *gpio_fd_list = NULL;
- ret = peripheral_privilege_check(invocation, pb_data->connection);
+ ret = peripheral_privilege_check(invocation, info->connection);
if (ret != 0) {
_E("Permission denied.");
ret = PERIPHERAL_ERROR_PERMISSION_DENIED;
const gchar *name,
gpointer user_data)
{
- pb_data_h i2c_handle = (pb_data_h)user_data;
+ peripheral_h i2c_handle = (peripheral_h)user_data;
_D("appid [%s] vanished ", name);
g_bus_unwatch_name(i2c_handle->watch_id);
gint address,
gpointer user_data)
{
- peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
+ peripheral_info_s *info = (peripheral_info_s*)user_data;
peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
- pb_data_h i2c_handle = NULL;
+ peripheral_h i2c_handle = NULL;
GUnixFDList *i2c_fd_list = NULL;
- ret = peripheral_privilege_check(invocation, pb_data->connection);
+ ret = peripheral_privilege_check(invocation, info->connection);
if (ret != 0) {
_E("Permission denied.");
ret = PERIPHERAL_ERROR_PERMISSION_DENIED;
const gchar *name,
gpointer user_data)
{
- pb_data_h pwm_handle = (pb_data_h)user_data;
+ peripheral_h pwm_handle = (peripheral_h)user_data;
_D("appid [%s] vanished ", name);
g_bus_unwatch_name(pwm_handle->watch_id);
gint pin,
gpointer user_data)
{
- peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
+ peripheral_info_s *info = (peripheral_info_s*)user_data;
peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
- pb_data_h pwm_handle = NULL;
+ peripheral_h pwm_handle = NULL;
GUnixFDList *pwm_fd_list = NULL;
- ret = peripheral_privilege_check(invocation, pb_data->connection);
+ ret = peripheral_privilege_check(invocation, info->connection);
if (ret != 0) {
_E("Permission denied.");
ret = PERIPHERAL_ERROR_PERMISSION_DENIED;
const gchar *name,
gpointer user_data)
{
- pb_data_h spi_handle = (pb_data_h)user_data;
+ peripheral_h spi_handle = (peripheral_h)user_data;
_D("appid [%s] vanished ", name);
g_bus_unwatch_name(spi_handle->watch_id);
gint cs,
gpointer user_data)
{
- peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
+ peripheral_info_s *info = (peripheral_info_s*)user_data;
peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
- pb_data_h spi_handle = NULL;
+ peripheral_h spi_handle = NULL;
GUnixFDList *spi_fd_list = NULL;
- ret = peripheral_privilege_check(invocation, pb_data->connection);
+ ret = peripheral_privilege_check(invocation, info->connection);
if (ret != 0) {
_E("Permission denied.");
ret = PERIPHERAL_ERROR_PERMISSION_DENIED;
const gchar *name,
gpointer user_data)
{
- pb_data_h uart_handle = (pb_data_h)user_data;
+ peripheral_h uart_handle = (peripheral_h)user_data;
_D("appid [%s] vanished ", name);
g_bus_unwatch_name(uart_handle->watch_id);
gint port,
gpointer user_data)
{
- peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
+ peripheral_info_s *info = (peripheral_info_s*)user_data;
peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
- pb_data_h uart_handle = NULL;
+ peripheral_h uart_handle = NULL;
GUnixFDList *uart_fd_list = NULL;
- ret = peripheral_privilege_check(invocation, pb_data->connection);
+ ret = peripheral_privilege_check(invocation, info->connection);
if (ret != 0) {
_E("Permission denied.");
ret = PERIPHERAL_ERROR_PERMISSION_DENIED;
#include "peripheral_handle_common.h"
-pb_data_h peripheral_handle_new(GList **plist)
+peripheral_h peripheral_handle_new(GList **plist)
{
GList *list = *plist;
- pb_data_h handle;
+ peripheral_h handle;
- handle = (pb_data_h)calloc(1, sizeof(peripheral_bus_data_s));
+ handle = (peripheral_h)calloc(1, sizeof(peripheral_handle_s));
if (handle == NULL) {
- _E("failed to allocate peripheral_bus_data_s");
+ _E("failed to allocate peripheral_handle_s");
return NULL;
}
return handle;
}
-int peripheral_handle_free(pb_data_h handle)
+int peripheral_handle_free(peripheral_h handle)
{
GList *list = *handle->list;
GList *link;
#include "peripheral_interface_gpio.h"
#include "peripheral_handle_common.h"
-static bool __peripheral_handle_gpio_is_creatable(int pin, peripheral_bus_s *pb_data)
+static bool __peripheral_handle_gpio_is_creatable(int pin, peripheral_info_s *info)
{
pb_board_dev_s *gpio = NULL;
- pb_data_h handle;
+ peripheral_h handle;
GList *link;
- RETV_IF(pb_data == NULL, false);
- RETV_IF(pb_data->board == NULL, false);
+ RETV_IF(info == NULL, false);
+ RETV_IF(info->board == NULL, false);
- gpio = peripheral_bus_board_find_device(PB_BOARD_DEV_GPIO, pb_data->board, pin);
+ gpio = peripheral_bus_board_find_device(PB_BOARD_DEV_GPIO, info->board, pin);
if (gpio == NULL) {
_E("Not supported GPIO pin : %d", pin);
return false;
}
- link = pb_data->gpio_list;
+ link = info->gpio_list;
while (link) {
- handle = (pb_data_h)link->data;
- if (handle->dev.gpio.pin == pin) {
+ handle = (peripheral_h)link->data;
+ if (handle->type.gpio.pin == pin) {
_E("gpio %d is busy", pin);
return false;
}
return true;
}
-int peripheral_handle_gpio_create(gint pin, pb_data_h *handle, gpointer user_data)
+int peripheral_handle_gpio_create(gint pin, peripheral_h *handle, gpointer user_data)
{
- peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
- pb_data_h gpio_handle;
+ peripheral_info_s *info = (peripheral_info_s*)user_data;
+ peripheral_h gpio_handle;
int ret;
- if (!__peripheral_handle_gpio_is_creatable(pin, pb_data)) {
+ if (!__peripheral_handle_gpio_is_creatable(pin, info)) {
_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(&pb_data->gpio_list);
+ gpio_handle = peripheral_handle_new(&info->gpio_list);
if (!gpio_handle) {
_E("peripheral_handle_new error");
ret = PERIPHERAL_ERROR_OUT_OF_MEMORY;
goto err;
}
- gpio_handle->type = PERIPHERAL_BUS_TYPE_GPIO;
- gpio_handle->list = &pb_data->gpio_list;
- gpio_handle->dev.gpio.pin = pin;
+ gpio_handle->list = &info->gpio_list;
+ gpio_handle->type.gpio.pin = pin;
*handle = gpio_handle;
return ret;
}
-int peripheral_handle_gpio_destroy(pb_data_h handle)
+int peripheral_handle_gpio_destroy(peripheral_h handle)
{
int ret = PERIPHERAL_ERROR_NONE;
#define INITIAL_BUFFER_SIZE 128
#define MAX_BUFFER_SIZE 8192
-static bool __peripheral_handle_i2c_is_creatable(int bus, int address, peripheral_bus_s *pb_data)
+static bool __peripheral_handle_i2c_is_creatable(int bus, int address, peripheral_info_s *info)
{
pb_board_dev_s *i2c = NULL;
- pb_data_h handle;
+ peripheral_h handle;
GList *link;
- RETV_IF(pb_data == NULL, false);
- RETV_IF(pb_data->board == NULL, false);
+ RETV_IF(info == NULL, false);
+ RETV_IF(info->board == NULL, false);
- i2c = peripheral_bus_board_find_device(PB_BOARD_DEV_I2C, pb_data->board, bus);
+ i2c = peripheral_bus_board_find_device(PB_BOARD_DEV_I2C, info->board, bus);
if (i2c == NULL) {
_E("Not supported I2C bus : %d", bus);
return false;
}
- link = pb_data->i2c_list;
+ link = info->i2c_list;
while (link) {
- handle = (pb_data_h)link->data;
- if (handle->dev.i2c.bus == bus && handle->dev.i2c.address == address) {
+ handle = (peripheral_h)link->data;
+ if (handle->type.i2c.bus == bus && handle->type.i2c.address == address) {
_E("Resource is in use, bus : %d, address : %d", bus, address);
return false;
}
return true;
}
-int peripheral_handle_i2c_create(int bus, int address, pb_data_h *handle, gpointer user_data)
+int peripheral_handle_i2c_create(int bus, int address, peripheral_h *handle, gpointer user_data)
{
- peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
- pb_data_h i2c_handle;
+ peripheral_info_s *info = (peripheral_info_s*)user_data;
+ peripheral_h i2c_handle;
int ret;
- if (!__peripheral_handle_i2c_is_creatable(bus, address, pb_data)) {
+ if (!__peripheral_handle_i2c_is_creatable(bus, address, info)) {
_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(&pb_data->i2c_list);
+ i2c_handle = peripheral_handle_new(&info->i2c_list);
if (!i2c_handle) {
_E("peripheral_handle_new error");
ret = PERIPHERAL_ERROR_OUT_OF_MEMORY;
goto err;
}
- i2c_handle->type = PERIPHERAL_BUS_TYPE_I2C;
- i2c_handle->list = &pb_data->i2c_list;
- i2c_handle->dev.i2c.bus = bus;
- i2c_handle->dev.i2c.address = address;
+ i2c_handle->list = &info->i2c_list;
+ i2c_handle->type.i2c.bus = bus;
+ i2c_handle->type.i2c.address = address;
*handle = i2c_handle;
return ret;
}
-int peripheral_handle_i2c_destroy(pb_data_h handle)
+int peripheral_handle_i2c_destroy(peripheral_h handle)
{
int ret = PERIPHERAL_ERROR_NONE;
#include "peripheral_interface_pwm.h"
#include "peripheral_handle_common.h"
-static bool __peripheral_handle_pwm_is_creatable(int chip, int pin, peripheral_bus_s *pb_data)
+static bool __peripheral_handle_pwm_is_creatable(int chip, int pin, peripheral_info_s *info)
{
pb_board_dev_s *pwm = NULL;
- pb_data_h handle;
+ peripheral_h handle;
GList *link;
- RETV_IF(pb_data == NULL, false);
- RETV_IF(pb_data->board == NULL, false);
+ RETV_IF(info == NULL, false);
+ RETV_IF(info->board == NULL, false);
- pwm = peripheral_bus_board_find_device(PB_BOARD_DEV_PWM, pb_data->board, chip, pin);
+ pwm = peripheral_bus_board_find_device(PB_BOARD_DEV_PWM, info->board, chip, pin);
if (pwm == NULL) {
_E("Not supported PWM chip : %d, pin : %d", chip, pin);
return false;
}
- link = pb_data->pwm_list;
+ link = info->pwm_list;
while (link) {
- handle = (pb_data_h)link->data;
- if (handle->dev.pwm.chip == chip && handle->dev.pwm.pin == pin) {
+ handle = (peripheral_h)link->data;
+ if (handle->type.pwm.chip == chip && handle->type.pwm.pin == pin) {
_E("Resource is in use, chip : %d, pin : %d", chip, pin);
return false;
}
return true;
}
-int peripheral_handle_pwm_create(int chip, int pin, pb_data_h *handle, gpointer user_data)
+int peripheral_handle_pwm_create(int chip, int pin, peripheral_h *handle, gpointer user_data)
{
- peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
- pb_data_h pwm_handle;
+ peripheral_info_s *info = (peripheral_info_s*)user_data;
+ peripheral_h pwm_handle;
int ret;
- if (!__peripheral_handle_pwm_is_creatable(chip, pin, pb_data)) {
+ if (!__peripheral_handle_pwm_is_creatable(chip, pin, info)) {
_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(&pb_data->pwm_list);
+ pwm_handle = peripheral_handle_new(&info->pwm_list);
if (!pwm_handle) {
_E("peripheral_handle_new error");
ret = PERIPHERAL_ERROR_OUT_OF_MEMORY;
goto err;
}
- pwm_handle->type = PERIPHERAL_BUS_TYPE_PWM;
- pwm_handle->list = &pb_data->pwm_list;
- pwm_handle->dev.pwm.chip = chip;
- pwm_handle->dev.pwm.pin = pin;
+ pwm_handle->list = &info->pwm_list;
+ pwm_handle->type.pwm.chip = chip;
+ pwm_handle->type.pwm.pin = pin;
*handle = pwm_handle;
return PERIPHERAL_ERROR_NONE;
return ret;
}
-int peripheral_handle_pwm_destroy(pb_data_h handle)
+int peripheral_handle_pwm_destroy(peripheral_h handle)
{
int ret = PERIPHERAL_ERROR_NONE;
#include "peripheral_interface_spi.h"
#include "peripheral_handle_common.h"
-static bool __peripheral_handle_spi_is_creatable(int bus, int cs, peripheral_bus_s *pb_data)
+static bool __peripheral_handle_spi_is_creatable(int bus, int cs, peripheral_info_s *info)
{
pb_board_dev_s *spi = NULL;
- pb_data_h handle;
+ peripheral_h handle;
GList *link;
- RETV_IF(pb_data == NULL, false);
- RETV_IF(pb_data->board == NULL, false);
+ RETV_IF(info == NULL, false);
+ RETV_IF(info->board == NULL, false);
- spi = peripheral_bus_board_find_device(PB_BOARD_DEV_SPI, pb_data->board, bus, cs);
+ spi = peripheral_bus_board_find_device(PB_BOARD_DEV_SPI, info->board, bus, cs);
if (spi == NULL) {
_E("Not supported SPI bus : %d, cs : %d", bus, cs);
return false;
}
- link = pb_data->spi_list;
+ link = info->spi_list;
while (link) {
- handle = (pb_data_h)link->data;
- if (handle->dev.spi.bus == bus && handle->dev.spi.cs == cs) {
+ handle = (peripheral_h)link->data;
+ if (handle->type.spi.bus == bus && handle->type.spi.cs == cs) {
_E("Resource is in use, bus : %d, cs : %d", bus, cs);
return false;
}
return true;
}
-int peripheral_handle_spi_create(int bus, int cs, pb_data_h *handle, gpointer user_data)
+int peripheral_handle_spi_create(int bus, int cs, peripheral_h *handle, gpointer user_data)
{
- peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
- pb_data_h spi_handle;
+ peripheral_info_s *info = (peripheral_info_s*)user_data;
+ peripheral_h spi_handle;
int ret = PERIPHERAL_ERROR_NONE;
- if (!__peripheral_handle_spi_is_creatable(bus, cs, pb_data)) {
+ if (!__peripheral_handle_spi_is_creatable(bus, cs, info)) {
_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(&pb_data->spi_list);
+ spi_handle = peripheral_handle_new(&info->spi_list);
if (!spi_handle) {
_E("peripheral_handle_new error");
ret = PERIPHERAL_ERROR_OUT_OF_MEMORY;
goto err_spi_data;
}
- spi_handle->type = PERIPHERAL_BUS_TYPE_SPI;
- spi_handle->list = &pb_data->spi_list;
- spi_handle->dev.spi.bus = bus;
- spi_handle->dev.spi.cs = cs;
+ spi_handle->list = &info->spi_list;
+ spi_handle->type.spi.bus = bus;
+ spi_handle->type.spi.cs = cs;
*handle = spi_handle;
return ret;
}
-int peripheral_handle_spi_destroy(pb_data_h handle)
+int peripheral_handle_spi_destroy(peripheral_h handle)
{
int ret = PERIPHERAL_ERROR_NONE;
#define INITIAL_BUFFER_SIZE 128
#define MAX_BUFFER_SIZE 8192
-static bool __peripheral_handle_uart_is_creatable(int port, peripheral_bus_s *pb_data)
+static bool __peripheral_handle_uart_is_creatable(int port, peripheral_info_s *info)
{
pb_board_dev_s *uart = NULL;
- pb_data_h handle;
+ peripheral_h handle;
GList *link;
- RETV_IF(pb_data == NULL, false);
- RETV_IF(pb_data->board == NULL, false);
+ RETV_IF(info == NULL, false);
+ RETV_IF(info->board == NULL, false);
- uart = peripheral_bus_board_find_device(PB_BOARD_DEV_UART, pb_data->board, port);
+ uart = peripheral_bus_board_find_device(PB_BOARD_DEV_UART, info->board, port);
if (uart == NULL) {
_E("Not supported UART port : %d", port);
return false;
}
- link = pb_data->uart_list;
+ link = info->uart_list;
while (link) {
- handle = (pb_data_h)link->data;
- if (handle->dev.uart.port == port) {
+ handle = (peripheral_h)link->data;
+ if (handle->type.uart.port == port) {
_E("Resource is in use, port : %d", port);
return false;
}
return true;
}
-int peripheral_handle_uart_open(int port, pb_data_h *handle, gpointer user_data)
+int peripheral_handle_uart_open(int port, peripheral_h *handle, gpointer user_data)
{
- peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
- pb_data_h uart_handle;
+ peripheral_info_s *info = (peripheral_info_s*)user_data;
+ peripheral_h uart_handle;
int ret = PERIPHERAL_ERROR_NONE;
- if (!__peripheral_handle_uart_is_creatable(port, pb_data)) {
+ if (!__peripheral_handle_uart_is_creatable(port, info)) {
_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(&pb_data->uart_list);
+ uart_handle = peripheral_handle_new(&info->uart_list);
if (!uart_handle) {
_E("peripheral_handle_new error");
ret = PERIPHERAL_ERROR_OUT_OF_MEMORY;
goto err;
}
- uart_handle->type = PERIPHERAL_BUS_TYPE_UART;
- uart_handle->list = &pb_data->uart_list;
- uart_handle->dev.uart.port = port;
+ uart_handle->list = &info->uart_list;
+ uart_handle->type.uart.port = port;
*handle = uart_handle;
return ret;
}
-int peripheral_handle_uart_destroy(pb_data_h handle)
+int peripheral_handle_uart_destroy(peripheral_h handle)
{
int ret = PERIPHERAL_ERROR_NONE;
#define PERIPHERAL_GDBUS_SPI_PATH "/Org/Tizen/Peripheral_io/Spi"
#define PERIPHERAL_GDBUS_NAME "org.tizen.peripheral_io"
-static gboolean __gpio_init(peripheral_bus_s *pb_data)
+static gboolean __gpio_init(peripheral_info_s *info)
{
GDBusObjectManagerServer *manager;
gboolean ret = FALSE;
GError *error = NULL;
/* Add interface to default object path */
- pb_data->gpio_skeleton = peripheral_io_gdbus_gpio_skeleton_new();
+ info->gpio_skeleton = peripheral_io_gdbus_gpio_skeleton_new();
/* Register for method callbacks as signal callbacks */
- g_signal_connect(pb_data->gpio_skeleton,
+ g_signal_connect(info->gpio_skeleton,
"handle-open",
G_CALLBACK(handle_gpio_open),
- pb_data);
+ info);
manager = g_dbus_object_manager_server_new(PERIPHERAL_GDBUS_GPIO_PATH);
/* Set connection to 'manager' */
- g_dbus_object_manager_server_set_connection(manager, pb_data->connection);
+ g_dbus_object_manager_server_set_connection(manager, info->connection);
/* Export 'manager' interface on peripheral-io DBUS */
ret = g_dbus_interface_skeleton_export(
- G_DBUS_INTERFACE_SKELETON(pb_data->gpio_skeleton),
- pb_data->connection, PERIPHERAL_GDBUS_GPIO_PATH, &error);
+ G_DBUS_INTERFACE_SKELETON(info->gpio_skeleton),
+ info->connection, PERIPHERAL_GDBUS_GPIO_PATH, &error);
if (ret == FALSE) {
_E("Can not skeleton_export %s", error->message);
return true;
}
-static gboolean __i2c_init(peripheral_bus_s *pb_data)
+static gboolean __i2c_init(peripheral_info_s *info)
{
GDBusObjectManagerServer *manager;
gboolean ret = FALSE;
GError *error = NULL;
/* Add interface to default object path */
- pb_data->i2c_skeleton = peripheral_io_gdbus_i2c_skeleton_new();
- g_signal_connect(pb_data->i2c_skeleton,
+ info->i2c_skeleton = peripheral_io_gdbus_i2c_skeleton_new();
+ g_signal_connect(info->i2c_skeleton,
"handle-open",
G_CALLBACK(handle_i2c_open),
- pb_data);
+ info);
manager = g_dbus_object_manager_server_new(PERIPHERAL_GDBUS_I2C_PATH);
/* Set connection to 'manager' */
- g_dbus_object_manager_server_set_connection(manager, pb_data->connection);
+ g_dbus_object_manager_server_set_connection(manager, info->connection);
/* Export 'manager' interface on peripheral-io DBUS */
ret = g_dbus_interface_skeleton_export(
- G_DBUS_INTERFACE_SKELETON(pb_data->i2c_skeleton),
- pb_data->connection, PERIPHERAL_GDBUS_I2C_PATH, &error);
+ G_DBUS_INTERFACE_SKELETON(info->i2c_skeleton),
+ info->connection, PERIPHERAL_GDBUS_I2C_PATH, &error);
if (ret == FALSE) {
_E("Can not skeleton_export %s", error->message);
return true;
}
-static gboolean __pwm_init(peripheral_bus_s *pb_data)
+static gboolean __pwm_init(peripheral_info_s *info)
{
GDBusObjectManagerServer *manager;
gboolean ret = FALSE;
GError *error = NULL;
/* Add interface to default object path */
- pb_data->pwm_skeleton = peripheral_io_gdbus_pwm_skeleton_new();
- g_signal_connect(pb_data->pwm_skeleton,
+ info->pwm_skeleton = peripheral_io_gdbus_pwm_skeleton_new();
+ g_signal_connect(info->pwm_skeleton,
"handle-open",
G_CALLBACK(handle_pwm_open),
- pb_data);
+ info);
manager = g_dbus_object_manager_server_new(PERIPHERAL_GDBUS_PWM_PATH);
/* Set connection to 'manager' */
- g_dbus_object_manager_server_set_connection(manager, pb_data->connection);
+ g_dbus_object_manager_server_set_connection(manager, info->connection);
/* Export 'manager' interface on peripheral-io DBUS */
ret = g_dbus_interface_skeleton_export(
- G_DBUS_INTERFACE_SKELETON(pb_data->pwm_skeleton),
- pb_data->connection, PERIPHERAL_GDBUS_PWM_PATH, &error);
+ G_DBUS_INTERFACE_SKELETON(info->pwm_skeleton),
+ info->connection, PERIPHERAL_GDBUS_PWM_PATH, &error);
if (ret == FALSE) {
_E("Can not skeleton_export %s", error->message);
return true;
}
-static gboolean __uart_init(peripheral_bus_s *pb_data)
+static gboolean __uart_init(peripheral_info_s *info)
{
GDBusObjectManagerServer *manager;
gboolean ret = FALSE;
GError *error = NULL;
/* Add interface to default object path */
- pb_data->uart_skeleton = peripheral_io_gdbus_uart_skeleton_new();
- g_signal_connect(pb_data->uart_skeleton,
+ info->uart_skeleton = peripheral_io_gdbus_uart_skeleton_new();
+ g_signal_connect(info->uart_skeleton,
"handle-open",
G_CALLBACK(handle_uart_open),
- pb_data);
+ info);
manager = g_dbus_object_manager_server_new(PERIPHERAL_GDBUS_UART_PATH);
/* Set connection to 'manager' */
- g_dbus_object_manager_server_set_connection(manager, pb_data->connection);
+ g_dbus_object_manager_server_set_connection(manager, info->connection);
/* Export 'manager' interface on peripheral-io DBUS */
ret = g_dbus_interface_skeleton_export(
- G_DBUS_INTERFACE_SKELETON(pb_data->uart_skeleton),
- pb_data->connection, PERIPHERAL_GDBUS_UART_PATH, &error);
+ G_DBUS_INTERFACE_SKELETON(info->uart_skeleton),
+ info->connection, PERIPHERAL_GDBUS_UART_PATH, &error);
if (ret == FALSE) {
_E("Can not skeleton_export %s", error->message);
return true;
}
-static gboolean __spi_init(peripheral_bus_s *pb_data)
+static gboolean __spi_init(peripheral_info_s *info)
{
GDBusObjectManagerServer *manager;
gboolean ret = FALSE;
GError *error = NULL;
/* Add interface to default object path */
- pb_data->spi_skeleton = peripheral_io_gdbus_spi_skeleton_new();
- g_signal_connect(pb_data->spi_skeleton,
+ info->spi_skeleton = peripheral_io_gdbus_spi_skeleton_new();
+ g_signal_connect(info->spi_skeleton,
"handle-open",
G_CALLBACK(handle_spi_open),
- pb_data);
+ info);
manager = g_dbus_object_manager_server_new(PERIPHERAL_GDBUS_SPI_PATH);
/* Set connection to 'manager' */
- g_dbus_object_manager_server_set_connection(manager, pb_data->connection);
+ g_dbus_object_manager_server_set_connection(manager, info->connection);
/* Export 'manager' interface on peripheral-io DBUS */
ret = g_dbus_interface_skeleton_export(
- G_DBUS_INTERFACE_SKELETON(pb_data->spi_skeleton),
- pb_data->connection, PERIPHERAL_GDBUS_SPI_PATH, &error);
+ G_DBUS_INTERFACE_SKELETON(info->spi_skeleton),
+ info->connection, PERIPHERAL_GDBUS_SPI_PATH, &error);
if (ret == FALSE) {
_E("Can not skeleton_export %s", error->message);
const gchar *name,
gpointer user_data)
{
- peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
+ peripheral_info_s *info = (peripheral_info_s*)user_data;
- pb_data->connection = connection;
+ info->connection = connection;
- if (__gpio_init(pb_data) == FALSE)
+ if (__gpio_init(info) == FALSE)
_E("Can not signal connect");
- if (__i2c_init(pb_data) == FALSE)
+ if (__i2c_init(info) == FALSE)
_E("Can not signal connect");
- if (__pwm_init(pb_data) == FALSE)
+ if (__pwm_init(info) == FALSE)
_E("Can not signal connect");
- if (__uart_init(pb_data) == FALSE)
+ if (__uart_init(info) == FALSE)
_E("Can not signal connect");
- if (__spi_init(pb_data) == FALSE)
+ if (__spi_init(info) == FALSE)
_E("Can not signal connect");
}
{
GMainLoop *loop;
guint owner_id = 0;
- peripheral_bus_s *pb_data;
+ peripheral_info_s *info;
- pb_data = (peripheral_bus_s*)calloc(1, sizeof(peripheral_bus_s));
- if (pb_data == NULL) {
- _E("failed to allocate peripheral_bus_s");
+ info = (peripheral_info_s*)calloc(1, sizeof(peripheral_info_s));
+ if (info == NULL) {
+ _E("failed to allocate peripheral_info_s");
return -1;
}
- pb_data->board = peripheral_bus_board_init();
- if (pb_data->board == NULL) {
+ info->board = peripheral_bus_board_init();
+ if (info->board == NULL) {
_E("failed to init board");
return -1;
}
on_bus_acquired,
on_name_acquired,
on_name_lost,
- pb_data,
+ info,
NULL);
if (!owner_id) {
_E("g_bus_own_name_error");
- free(pb_data);
+ free(info);
return -1;
}
peripheral_privilege_deinit();
- if (pb_data) {
- peripheral_bus_board_deinit(pb_data->board);
- free(pb_data);
+ if (info) {
+ peripheral_bus_board_deinit(info->board);
+ free(info);
}
if (loop != NULL)