gboolean peripheral_gdbus_adc_close(
PeripheralIoGdbusAdc *adc,
GDBusMethodInvocation *invocation,
- gint handle,
+ guint handle,
gpointer user_data);
#endif /* __PERIPHERAL_GDBUS_ADC_H__ */
gboolean peripheral_gdbus_gpio_close(
PeripheralIoGdbusGpio *gpio,
GDBusMethodInvocation *invocation,
- gint handle,
+ guint handle,
gpointer user_data);
#endif /* __PERIPHERAL_GDBUS_GPIO_H__ */
gboolean peripheral_gdbus_i2c_close(
PeripheralIoGdbusI2c *i2c,
GDBusMethodInvocation *invocation,
- gint handle,
+ guint handle,
gpointer user_data);
#endif /* __PERIPHERAL_GDBUS_I2C_H__ */
gboolean peripheral_gdbus_pwm_close(
PeripheralIoGdbusPwm *pwm,
GDBusMethodInvocation *invocation,
- gint handle,
+ guint handle,
gpointer user_data);
#endif /* __PERIPHERAL_GDBUS_PWM_H__ */
gboolean peripheral_gdbus_spi_close(
PeripheralIoGdbusSpi *spi,
GDBusMethodInvocation *invocation,
- gint handle,
+ guint handle,
gpointer user_data);
#endif /* __PERIPHERAL_GDBUS_SPI_H__ */
gboolean peripheral_gdbus_uart_close(
PeripheralIoGdbusUart *uart,
GDBusMethodInvocation *invocation,
- gint handle,
+ guint handle,
gpointer user_data);
#endif /* __PERIPHERAL_GDBUS_UART_H__ */
#define __PERIPHERAL_HANDLE_H__
#include <gio/gio.h>
+#include <stdint.h>
#include "peripheral_board.h"
#include "peripheral_io_gdbus.h"
typedef struct {
uint watch_id;
+ uint32_t handle_id;
GList **list;
union {
peripheral_handle_gpio_s gpio;
typedef peripheral_handle_s *peripheral_h;
+#define PERIPHERAL_H_TO_ID(ph) ((ph) ? (ph->handle_id) : 0)
+
+#include "peripheral_handle_common.h"
#endif /* __PERIPHERAL_HANDLE_H__ */
#include <stdio.h>
#include <stdlib.h>
+#include <stdint.h>
#include <gio/gio.h>
#include <peripheral_io.h>
peripheral_h peripheral_handle_new(GList **plist);
int peripheral_handle_free(peripheral_h handle);
+peripheral_h peripheral_handle_find(GList *list, uint32_t _handle_id);
#endif /* __PERIPHERAL_HANDLE_COMMON_H__ */
Name: peripheral-bus
Summary: Tizen Peripheral Input & Output Service Daemon
-Version: 0.1.2
+Version: 0.1.3
Release: 0
Group: System & System Tools
License: Apache-2.0
NULL);
out:
- peripheral_io_gdbus_adc_complete_open(adc, invocation, adc_fd_list, GPOINTER_TO_UINT(adc_handle), ret);
+ peripheral_io_gdbus_adc_complete_open(adc, invocation, adc_fd_list, PERIPHERAL_H_TO_ID(adc_handle), ret);
peripheral_interface_adc_fd_list_destroy(adc_fd_list);
return true;
gboolean peripheral_gdbus_adc_close(
PeripheralIoGdbusAdc *adc,
GDBusMethodInvocation *invocation,
- gint handle,
+ guint handle,
gpointer user_data)
{
int ret = PERIPHERAL_ERROR_NONE;
- peripheral_h adc_handle = GUINT_TO_POINTER(handle);
+ peripheral_info_s *info = (peripheral_info_s*)user_data;
+ peripheral_h adc_handle = peripheral_handle_find(info->adc_list, handle);
+ if (!adc_handle) {
+ _E("Unable to find handle referenced by client");
+ ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
+ goto out;
+ }
g_bus_unwatch_name(adc_handle->watch_id);
if (ret != PERIPHERAL_ERROR_NONE)
_E("Failed to destroy adc handle");
+out:
peripheral_io_gdbus_adc_complete_close(adc, invocation, ret);
return true;
NULL);
out:
- peripheral_io_gdbus_gpio_complete_open(gpio, invocation, gpio_fd_list, GPOINTER_TO_UINT(gpio_handle), ret);
+ peripheral_io_gdbus_gpio_complete_open(gpio, invocation, gpio_fd_list, PERIPHERAL_H_TO_ID(gpio_handle), ret);
peripheral_interface_gpio_fd_list_destroy(gpio_fd_list);
return true;
gboolean peripheral_gdbus_gpio_close(
PeripheralIoGdbusGpio *gpio,
GDBusMethodInvocation *invocation,
- gint handle,
+ guint handle,
gpointer user_data)
{
int ret = PERIPHERAL_ERROR_NONE;
- peripheral_h gpio_handle = GUINT_TO_POINTER(handle);
+ peripheral_info_s *info = (peripheral_info_s*)user_data;
+ peripheral_h gpio_handle = peripheral_handle_find(info->gpio_list, handle);
+ if (!gpio_handle) {
+ _E("Unable to find handle referenced by client");
+ ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
+ goto out;
+ }
g_bus_unwatch_name(gpio_handle->watch_id);
if (ret != PERIPHERAL_ERROR_NONE)
_E("Failed to destroy gpio handle");
+out:
peripheral_io_gdbus_gpio_complete_close(gpio, invocation, ret);
return true;
NULL);
out:
- peripheral_io_gdbus_i2c_complete_open(i2c, invocation, i2c_fd_list, GPOINTER_TO_UINT(i2c_handle), ret);
+ peripheral_io_gdbus_i2c_complete_open(i2c, invocation, i2c_fd_list, PERIPHERAL_H_TO_ID(i2c_handle), ret);
peripheral_interface_i2c_fd_list_destroy(i2c_fd_list);
return true;
gboolean peripheral_gdbus_i2c_close(
PeripheralIoGdbusI2c *i2c,
GDBusMethodInvocation *invocation,
- gint handle,
+ guint handle,
gpointer user_data)
{
int ret = PERIPHERAL_ERROR_NONE;
- peripheral_h i2c_handle = GUINT_TO_POINTER(handle);
+ peripheral_info_s *info = (peripheral_info_s*)user_data;
+ peripheral_h i2c_handle = peripheral_handle_find(info->i2c_list, handle);
+ if (!i2c_handle) {
+ _E("Unable to find handle referenced by client");
+ ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
+ goto out;
+ }
g_bus_unwatch_name(i2c_handle->watch_id);
if (ret != PERIPHERAL_ERROR_NONE)
_E("Failed to destroy i2c handle");
+out:
peripheral_io_gdbus_i2c_complete_close(i2c, invocation, ret);
return true;
-}
\ No newline at end of file
+}
NULL);
out:
- peripheral_io_gdbus_pwm_complete_open(pwm, invocation, pwm_fd_list, GPOINTER_TO_UINT(pwm_handle), ret);
+ peripheral_io_gdbus_pwm_complete_open(pwm, invocation, pwm_fd_list, PERIPHERAL_H_TO_ID(pwm_handle), ret);
peripheral_interface_pwm_fd_list_destroy(pwm_fd_list);
return true;
gboolean peripheral_gdbus_pwm_close(
PeripheralIoGdbusPwm *pwm,
GDBusMethodInvocation *invocation,
- gint handle,
+ guint handle,
gpointer user_data)
{
int ret = PERIPHERAL_ERROR_NONE;
- peripheral_h pwm_handle = GUINT_TO_POINTER(handle);
+ peripheral_info_s *info = (peripheral_info_s*)user_data;
+ peripheral_h pwm_handle = peripheral_handle_find(info->pwm_list, handle);
+ if (!pwm_handle) {
+ _E("Unable to find handle referenced by client");
+ ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
+ goto out;
+ }
g_bus_unwatch_name(pwm_handle->watch_id);
if (ret != PERIPHERAL_ERROR_NONE)
_E("Failed to destroy pwm handle");
+out:
peripheral_io_gdbus_pwm_complete_close(pwm, invocation, ret);
return true;
-}
\ No newline at end of file
+}
NULL);
out:
- peripheral_io_gdbus_spi_complete_open(spi, invocation, spi_fd_list, GPOINTER_TO_UINT(spi_handle), ret);
+ peripheral_io_gdbus_spi_complete_open(spi, invocation, spi_fd_list, PERIPHERAL_H_TO_ID(spi_handle), ret);
peripheral_interface_spi_fd_list_destroy(spi_fd_list);
return true;
gboolean peripheral_gdbus_spi_close(
PeripheralIoGdbusSpi *spi,
GDBusMethodInvocation *invocation,
- gint handle,
+ guint handle,
gpointer user_data)
{
int ret = PERIPHERAL_ERROR_NONE;
- peripheral_h spi_handle = GUINT_TO_POINTER(handle);
+ peripheral_info_s *info = (peripheral_info_s*)user_data;
+ peripheral_h spi_handle = peripheral_handle_find(info->spi_list, handle);
+ if (!spi_handle) {
+ _E("Unable to find handle referenced by client");
+ ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
+ goto out;
+ }
g_bus_unwatch_name(spi_handle->watch_id);
if (ret != PERIPHERAL_ERROR_NONE)
_E("Failed to destroy spi handle");
+out:
peripheral_io_gdbus_spi_complete_close(spi, invocation, ret);
return true;
-}
\ No newline at end of file
+}
NULL);
out:
- peripheral_io_gdbus_uart_complete_open(uart, invocation, uart_fd_list, GPOINTER_TO_UINT(uart_handle), ret);
+ peripheral_io_gdbus_uart_complete_open(uart, invocation, uart_fd_list, PERIPHERAL_H_TO_ID(uart_handle), ret);
peripheral_interface_uart_fd_list_destroy(uart_fd_list);
return true;
gboolean peripheral_gdbus_uart_close(
PeripheralIoGdbusUart *uart,
GDBusMethodInvocation *invocation,
- gint handle,
+ guint handle,
gpointer user_data)
{
int ret = PERIPHERAL_ERROR_NONE;
- peripheral_h uart_handle = GUINT_TO_POINTER(handle);
+ peripheral_info_s *info = (peripheral_info_s*)user_data;
+ peripheral_h uart_handle = peripheral_handle_find(info->uart_list, handle);
+ if (!uart_handle) {
+ _E("Unable to find handle referenced by client");
+ ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
+ goto out;
+ }
g_bus_unwatch_name(uart_handle->watch_id);
if (ret != PERIPHERAL_ERROR_NONE)
_E("Failed to destroy uart handle");
+out:
peripheral_io_gdbus_uart_complete_close(uart, invocation, ret);
return true;
-}
\ No newline at end of file
+}
#include "peripheral_handle_common.h"
+gint cmp_handle(gconstpointer elem, gconstpointer _handle_id)
+{
+ peripheral_handle_s *ph = (peripheral_handle_s *)elem;
+ uint32_t handle_id = GPOINTER_TO_UINT(_handle_id);
+
+ return ph->handle_id != handle_id;
+}
+
peripheral_h peripheral_handle_new(GList **plist)
{
GList *list = *plist;
_E("failed to allocate peripheral_handle_s");
return NULL;
}
+ do {
+ handle->handle_id = random();
+ } while (handle->handle_id == 0 || g_list_find_custom(list, GUINT_TO_POINTER(handle->handle_id), cmp_handle) != NULL);
*plist = g_list_append(list, handle);
return handle;
}
+peripheral_h peripheral_handle_find(GList *list, uint32_t handle_id)
+{
+ GList *elem = g_list_find_custom(list, GUINT_TO_POINTER(handle_id), cmp_handle);
+ return elem ? elem->data : NULL;
+}
+
int peripheral_handle_free(peripheral_h handle)
{
GList *list = *handle->list;
g_list_free(link);
return 0;
-}
\ No newline at end of file
+}