Refactoring dbus interface functions 79/139979/2
authorSungguk Na <sungguk.na@samsung.com>
Fri, 21 Jul 2017 07:15:41 +0000 (16:15 +0900)
committerSungguk Na <sungguk.na@samsung.com>
Fri, 21 Jul 2017 08:19:56 +0000 (17:19 +0900)
Change-Id: Ide717e39235e5b87583e93dfd05485efc59e9a3b
Signed-off-by: Sungguk Na <sungguk.na@samsung.com>
18 files changed:
CMakeLists.txt
src/daemon/include/peripheral_bus.h
src/daemon/include/peripheral_bus_gdbus_adc.h [new file with mode: 0644]
src/daemon/include/peripheral_bus_gdbus_gpio.h [new file with mode: 0644]
src/daemon/include/peripheral_bus_gdbus_i2c.h [new file with mode: 0644]
src/daemon/include/peripheral_bus_gdbus_pwm.h [new file with mode: 0644]
src/daemon/include/peripheral_bus_gdbus_spi.h [new file with mode: 0644]
src/daemon/include/peripheral_bus_gdbus_uart.h [new file with mode: 0644]
src/daemon/include/peripheral_bus_util.h
src/daemon/peripheral_bus.c
src/daemon/peripheral_bus_gdbus_adc.c [new file with mode: 0644]
src/daemon/peripheral_bus_gdbus_gpio.c [new file with mode: 0644]
src/daemon/peripheral_bus_gdbus_i2c.c [new file with mode: 0644]
src/daemon/peripheral_bus_gdbus_pwm.c [new file with mode: 0644]
src/daemon/peripheral_bus_gdbus_spi.c [new file with mode: 0644]
src/daemon/peripheral_bus_gdbus_uart.c [new file with mode: 0644]
src/daemon/peripheral_bus_gpio.c
src/daemon/peripheral_bus_util.c

index 9893aae..f9b346d 100644 (file)
@@ -23,6 +23,12 @@ SET(PERIPHERAL-BUS "peripheral-bus")
 SET(SRCS
        src/daemon/peripheral_bus.c
        src/daemon/peripheral_bus_util.c
+       src/daemon/peripheral_bus_gdbus_gpio.c
+       src/daemon/peripheral_bus_gdbus_i2c.c
+       src/daemon/peripheral_bus_gdbus_pwm.c
+       src/daemon/peripheral_bus_gdbus_spi.c
+       src/daemon/peripheral_bus_gdbus_uart.c
+       src/daemon/peripheral_bus_gdbus_adc.c
        src/daemon/peripheral_bus_pwm.c
        src/daemon/peripheral_bus_adc.c
        src/daemon/peripheral_bus_i2c.c
index a547f92..2844153 100644 (file)
@@ -122,8 +122,4 @@ typedef struct {
 
 typedef peripheral_bus_data_s *pb_data_h;
 
-void peripheral_bus_emit_gpio_changed(PeripheralIoGdbusGpio *gpio,
-                                                                       gint pin,
-                                                                       gint value,
-                                                                       guint64 timestamp);
 #endif /* __PERIPHERAL_BUS_H__ */
diff --git a/src/daemon/include/peripheral_bus_gdbus_adc.h b/src/daemon/include/peripheral_bus_gdbus_adc.h
new file mode 100644 (file)
index 0000000..07471c8
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __PERIPHERAL_BUS_GDBUS_ADC_H__
+#define __PERIPHERAL_BUS_GDBUS_ADC_H__
+
+#include "peripheral_io_gdbus.h"
+
+gboolean handle_adc_read(
+               PeripheralIoGdbusAdc *adc,
+               GDBusMethodInvocation *invocation,
+               guint device,
+               guint channel,
+               gpointer user_data);
+
+#endif /* __PERIPHERAL_BUS_GDBUS_ADC_H__ */
diff --git a/src/daemon/include/peripheral_bus_gdbus_gpio.h b/src/daemon/include/peripheral_bus_gdbus_gpio.h
new file mode 100644 (file)
index 0000000..5c75924
--- /dev/null
@@ -0,0 +1,91 @@
+/*
+ * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __PERIPHERAL_BUS_GDBUS_GPIO_H__
+#define __PERIPHERAL_BUS_GDBUS_GPIO_H__
+
+#include "peripheral_io_gdbus.h"
+
+gboolean handle_gpio_open(
+               PeripheralIoGdbusGpio *gpio,
+               GDBusMethodInvocation *invocation,
+               gint pin,
+               gpointer user_data);
+
+gboolean handle_gpio_close(
+               PeripheralIoGdbusGpio *gpio,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gpointer user_data);
+
+gboolean handle_gpio_get_direction(
+               PeripheralIoGdbusGpio *gpio,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gpointer user_data);
+
+gboolean handle_gpio_set_direction(
+               PeripheralIoGdbusGpio *gpio,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gint direction,
+               gpointer user_data);
+
+gboolean handle_gpio_read(
+               PeripheralIoGdbusGpio *gpio,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gpointer user_data);
+
+gboolean handle_gpio_write(
+               PeripheralIoGdbusGpio *gpio,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gint value,
+               gpointer user_data);
+
+gboolean handle_gpio_get_edge_mode(
+               PeripheralIoGdbusGpio *gpio,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gpointer user_data);
+
+gboolean handle_gpio_set_edge_mode(
+               PeripheralIoGdbusGpio *gpio,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gint edge,
+               gpointer user_data);
+
+gboolean handle_gpio_register_irq(
+               PeripheralIoGdbusGpio *gpio,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gpointer user_data);
+
+gboolean handle_gpio_unregister_irq(
+               PeripheralIoGdbusGpio *gpio,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gpointer user_data);
+
+void peripheral_bus_emit_gpio_changed(
+               PeripheralIoGdbusGpio *gpio,
+               gint pin,
+               gint value,
+               guint64 timestamp);
+
+#endif /* __PERIPHERAL_BUS_GDBUS_GPIO_H__ */
diff --git a/src/daemon/include/peripheral_bus_gdbus_i2c.h b/src/daemon/include/peripheral_bus_gdbus_i2c.h
new file mode 100644 (file)
index 0000000..72f3004
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __PERIPHERAL_BUS_GDBUS_I2C_H__
+#define __PERIPHERAL_BUS_GDBUS_I2C_H__
+
+#include "peripheral_io_gdbus.h"
+
+gboolean handle_i2c_open(
+               PeripheralIoGdbusI2c *i2c,
+               GDBusMethodInvocation *invocation,
+               gint bus,
+               gint address,
+               gpointer user_data);
+
+gboolean handle_i2c_close(
+               PeripheralIoGdbusI2c *i2c,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gpointer user_data);
+
+gboolean handle_i2c_read(
+               PeripheralIoGdbusI2c *i2c,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gint length,
+               gpointer user_data);
+
+gboolean handle_i2c_write(
+               PeripheralIoGdbusI2c *i2c,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gint length,
+               GVariant *data_array,
+               gpointer user_data);
+
+gboolean handle_i2c_smbus_ioctl(
+               PeripheralIoGdbusI2c *i2c,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               guchar read_write,
+               guchar command,
+               guint size,
+               guint16 data_in,
+               gpointer user_data);
+
+#endif /* __PERIPHERAL_BUS_GDBUS_I2C_H__ */
diff --git a/src/daemon/include/peripheral_bus_gdbus_pwm.h b/src/daemon/include/peripheral_bus_gdbus_pwm.h
new file mode 100644 (file)
index 0000000..817d243
--- /dev/null
@@ -0,0 +1,87 @@
+/*
+ * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __PERIPHERAL_BUS_GDBUS_PWM_H__
+#define __PERIPHERAL_BUS_GDBUS_PWM_H__
+
+#include "peripheral_io_gdbus.h"
+
+gboolean handle_pwm_open(
+               PeripheralIoGdbusPwm *pwm,
+               GDBusMethodInvocation *invocation,
+               gint device,
+               gint channel,
+               gpointer user_data);
+
+gboolean handle_pwm_close(
+               PeripheralIoGdbusPwm *pwm,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gpointer user_data);
+
+gboolean handle_pwm_set_period(
+               PeripheralIoGdbusPwm *pwm,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gint period,
+               gpointer user_data);
+
+gboolean handle_pwm_get_period(
+               PeripheralIoGdbusPwm *pwm,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gpointer user_data);
+
+gboolean handle_pwm_set_duty_cycle(
+               PeripheralIoGdbusPwm *pwm,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gint duty_cycle,
+               gpointer user_data);
+
+gboolean handle_pwm_get_duty_cycle(
+               PeripheralIoGdbusPwm *pwm,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gpointer user_data);
+
+gboolean handle_pwm_set_polarity(
+               PeripheralIoGdbusPwm *pwm,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gint polarity,
+               gpointer user_data);
+
+gboolean handle_pwm_get_polarity(
+               PeripheralIoGdbusPwm *pwm,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gpointer user_data);
+
+gboolean handle_pwm_set_enable(
+               PeripheralIoGdbusPwm *pwm,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gint enable,
+               gpointer user_data);
+
+gboolean handle_pwm_get_enable(
+               PeripheralIoGdbusPwm *pwm,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gpointer user_data);
+
+#endif /* __PERIPHERAL_BUS_GDBUS_PWM_H__ */
diff --git a/src/daemon/include/peripheral_bus_gdbus_spi.h b/src/daemon/include/peripheral_bus_gdbus_spi.h
new file mode 100644 (file)
index 0000000..7032806
--- /dev/null
@@ -0,0 +1,110 @@
+/*
+ * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __PERIPHERAL_BUS_GDBUS_SPI_H__
+#define __PERIPHERAL_BUS_GDBUS_SPI_H__
+
+#include "peripheral_io_gdbus.h"
+
+gboolean handle_spi_open(
+               PeripheralIoGdbusSpi *spi,
+               GDBusMethodInvocation *invocation,
+               gint bus,
+               gint cs,
+               gpointer user_data);
+
+gboolean handle_spi_close(
+               PeripheralIoGdbusSpi *spi,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gpointer user_data);
+
+gboolean handle_spi_set_mode(
+               PeripheralIoGdbusSpi *spi,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               guchar mode,
+               gpointer user_data);
+
+gboolean handle_spi_get_mode(
+               PeripheralIoGdbusSpi *spi,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gpointer user_data);
+
+gboolean handle_spi_set_lsb_first(
+               PeripheralIoGdbusSpi *spi,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gboolean lsb,
+               gpointer user_data);
+
+gboolean handle_spi_get_lsb_first(
+               PeripheralIoGdbusSpi *spi,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gpointer user_data);
+
+gboolean handle_spi_set_bits(
+               PeripheralIoGdbusSpi *spi,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               guchar bits,
+               gpointer user_data);
+
+gboolean handle_spi_get_bits(
+               PeripheralIoGdbusSpi *spi,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gpointer user_data);
+
+gboolean handle_spi_set_frequency(
+               PeripheralIoGdbusSpi *spi,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               guint freq,
+               gpointer user_data);
+
+gboolean handle_spi_get_frequency(
+               PeripheralIoGdbusSpi *spi,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gpointer user_data);
+
+gboolean handle_spi_read(
+               PeripheralIoGdbusSpi *spi,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gint length,
+               gpointer user_data);
+
+gboolean handle_spi_write(
+               PeripheralIoGdbusSpi *spi,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gint length,
+               GVariant *data_array,
+               gpointer user_data);
+
+gboolean handle_spi_read_write(
+               PeripheralIoGdbusSpi *spi,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gint length,
+               GVariant *tx_data_array,
+               gpointer user_data);
+
+#endif /* __PERIPHERAL_BUS_GDBUS_SPI_H__ */
diff --git a/src/daemon/include/peripheral_bus_gdbus_uart.h b/src/daemon/include/peripheral_bus_gdbus_uart.h
new file mode 100644 (file)
index 0000000..68eef7f
--- /dev/null
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __PERIPHERAL_BUS_GDBUS_UART_H__
+#define __PERIPHERAL_BUS_GDBUS_UART_H__
+
+#include "peripheral_io_gdbus.h"
+
+gboolean handle_uart_open(
+               PeripheralIoGdbusUart *uart,
+               GDBusMethodInvocation *invocation,
+               gint port,
+               gpointer user_data);
+
+gboolean handle_uart_close(
+               PeripheralIoGdbusUart *uart,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gpointer user_data);
+
+gboolean handle_uart_flush(
+               PeripheralIoGdbusUart *uart,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gpointer user_data);
+
+gboolean handle_uart_set_baudrate(
+               PeripheralIoGdbusUart *uart,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               guint baudrate,
+               gpointer user_data);
+
+gboolean handle_uart_set_mode(
+               PeripheralIoGdbusUart *uart,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               guint byte_size,
+               guint parity,
+               guint stop_bits,
+               gpointer user_data);
+
+gboolean handle_uart_set_flowcontrol(
+               PeripheralIoGdbusUart *uart,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gboolean xonxoff,
+               gboolean rtscts,
+               gpointer user_data);
+
+gboolean handle_uart_read(
+               PeripheralIoGdbusUart *uart,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gint length,
+               gpointer user_data);
+
+gboolean handle_uart_write(
+               PeripheralIoGdbusUart *uart,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gint length,
+               GVariant *data_array,
+               gpointer user_data);
+
+#endif /* __PERIPHERAL_BUS_GDBUS_UART_H__ */
index 103956b..45b8053 100644 (file)
@@ -21,4 +21,14 @@ GVariant *peripheral_bus_build_variant_ay(uint8_t *data, int length);
 pb_data_h peripheral_bus_data_new(GList **plist);
 int peripheral_bus_data_free(pb_data_h handle);
 
+int peripheral_bus_get_client_info(
+               GDBusMethodInvocation *invocation,
+               peripheral_bus_s *pb_data,
+               pb_client_info_s *client_info);
+
+int peripheral_bus_handle_is_valid(
+               GDBusMethodInvocation *invocation,
+               pb_data_h handle,
+               GList *list);
+
 #endif /* __PERIPHERAL_UTIL_H__ */
index 65d97f1..369974e 100644 (file)
 
 #include "peripheral_io_gdbus.h"
 #include "peripheral_bus.h"
-#include "peripheral_bus_gpio.h"
-#include "peripheral_bus_i2c.h"
-#include "peripheral_bus_pwm.h"
-#include "peripheral_bus_adc.h"
-#include "peripheral_bus_uart.h"
-#include "peripheral_bus_spi.h"
 #include "peripheral_common.h"
-#include "peripheral_bus_util.h"
-
-static void __gpio_on_name_vanished(GDBusConnection *connection,
-               const gchar     *name,
-               gpointer         user_data)
-{
-       pb_data_h gpio_handle = (pb_data_h)user_data;
-       _D("appid [%s] vanished ", name);
-
-       g_bus_unwatch_name(gpio_handle->watch_id);
-       peripheral_bus_gpio_close(gpio_handle);
-}
-
-static void __i2c_on_name_vanished(GDBusConnection *connection,
-               const gchar     *name,
-               gpointer         user_data)
-{
-       pb_data_h i2c_handle = (pb_data_h)user_data;
-       _D("appid [%s] vanished ", name);
-
-       g_bus_unwatch_name(i2c_handle->watch_id);
-       peripheral_bus_i2c_close(i2c_handle);
-}
-
-static void __pwm_on_name_vanished(GDBusConnection *connection,
-               const gchar     *name,
-               gpointer         user_data)
-{
-       pb_data_h pwm_handle = (pb_data_h)user_data;
-       _D("appid [%s] vanished ", name);
-
-       g_bus_unwatch_name(pwm_handle->watch_id);
-       peripheral_bus_pwm_close(pwm_handle);
-}
-
-static void __uart_on_name_vanished(GDBusConnection *connection,
-               const gchar     *name,
-               gpointer         user_data)
-{
-       pb_data_h uart_handle = (pb_data_h)user_data;
-       _D("appid [%s] vanished ", name);
-
-       g_bus_unwatch_name(uart_handle->watch_id);
-       peripheral_bus_uart_close(uart_handle);
-}
-
-static void __spi_on_name_vanished(GDBusConnection *connection,
-               const gchar     *name,
-               gpointer         user_data)
-{
-       pb_data_h spi_handle = (pb_data_h)user_data;
-       _D("appid [%s] vanished ", name);
-
-       g_bus_unwatch_name(spi_handle->watch_id);
-       peripheral_bus_spi_close(spi_handle);
-}
-
-static int peripheral_bus_get_client_info(
-               GDBusMethodInvocation *invocation,
-               peripheral_bus_s *pb_data,
-               pb_client_info_s *client_info)
-{
-       guint pid = 0;
-       GError *error = NULL;
-       GVariant *_ret;
-       const gchar *id;
-
-       id = g_dbus_method_invocation_get_sender(invocation);
-       _ret = g_dbus_connection_call_sync(pb_data->connection,
-               "org.freedesktop.DBus",
-               "/org/freedesktop/DBus",
-               "org.freedesktop.DBus",
-               "GetConnectionUnixProcessID",
-               g_variant_new("(s)", id),
-               NULL,
-               G_DBUS_CALL_FLAGS_NONE,
-               -1,
-               NULL,
-               &error);
-
-       if (_ret == NULL) {
-               _E("Failed to get client pid, %s", error->message);
-               g_error_free(error);
-
-               return -1;
-       }
-
-       g_variant_get(_ret, "(u)", &pid);
-       g_variant_unref(_ret);
-
-       client_info->pid = (pid_t)pid;
-       client_info->pgid = getpgid(pid);
-       client_info->id = strdup(id);
-
-       return 0;
-}
-
-static int peripheral_bus_handle_is_valid(
-               GDBusMethodInvocation *invocation,
-               pb_data_h handle,
-               GList *list)
-{
-       const gchar *id;
-
-       if (!g_list_find(list, handle)) {
-               _E("Cannot find handle");
-               return -1;
-       }
-
-       id = g_dbus_method_invocation_get_sender(invocation);
-       if (strcmp(handle->client_info.id, id)) {
-               _E("Invalid access, handle id : %s, current id : %s", handle->client_info.id, id);
-               return -1;
-       }
-
-       return 0;
-}
-
-gboolean handle_gpio_open(
-               PeripheralIoGdbusGpio *gpio,
-               GDBusMethodInvocation *invocation,
-               gint pin,
-               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;
-
-       if ((ret = peripheral_bus_gpio_open(pin, &gpio_handle, user_data)) < PERIPHERAL_ERROR_NONE)
-               goto out;
-
-       if (peripheral_bus_get_client_info(invocation, pb_data, &gpio_handle->client_info) < 0) {
-               peripheral_bus_gpio_close(gpio_handle);
-               ret = PERIPHERAL_ERROR_UNKNOWN;
-               goto out;
-       }
-
-       gpio_handle->watch_id = g_bus_watch_name(G_BUS_TYPE_SYSTEM ,
-                       gpio_handle->client_info.id,
-                       G_BUS_NAME_WATCHER_FLAGS_NONE ,
-                       NULL,
-                       __gpio_on_name_vanished,
-                       gpio_handle,
-                       NULL);
-       _D("gpio : %d, id = %s", gpio_handle->dev.gpio.pin, gpio_handle->client_info.id);
-
-out:
-       peripheral_io_gdbus_gpio_complete_open(gpio, invocation, GPOINTER_TO_UINT(gpio_handle), ret);
-
-       return true;
-}
-
-gboolean handle_gpio_close(
-               PeripheralIoGdbusGpio *gpio,
-               GDBusMethodInvocation *invocation,
-               gint handle,
-               gpointer user_data)
-{
-       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
-       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-       pb_data_h gpio_handle = GUINT_TO_POINTER(handle);
-
-       if (peripheral_bus_handle_is_valid(invocation, gpio_handle, pb_data->gpio_list) != 0) {
-               _E("gpio handle is not valid");
-               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
-       } else {
-               g_bus_unwatch_name(gpio_handle->watch_id);
-               ret = peripheral_bus_gpio_close(gpio_handle);
-       }
-
-       peripheral_io_gdbus_gpio_complete_close(gpio, invocation, ret);
-
-       return true;
-}
-
-gboolean handle_gpio_get_direction(
-               PeripheralIoGdbusGpio *gpio,
-               GDBusMethodInvocation *invocation,
-               gint handle,
-               gpointer user_data)
-{
-       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
-       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-       pb_data_h gpio_handle = GUINT_TO_POINTER(handle);
-       gint direction = 0;
-
-       if (peripheral_bus_handle_is_valid(invocation, gpio_handle, pb_data->gpio_list) != 0) {
-               _E("gpio handle is not valid");
-               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
-       } else
-               ret = peripheral_bus_gpio_get_direction(gpio_handle, &direction);
-
-       peripheral_io_gdbus_gpio_complete_get_direction(gpio, invocation, direction, ret);
-
-       return true;
-}
-
-gboolean handle_gpio_set_direction(
-               PeripheralIoGdbusGpio *gpio,
-               GDBusMethodInvocation *invocation,
-               gint handle,
-               gint direction,
-               gpointer user_data)
-{
-       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
-       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-       pb_data_h gpio_handle = GUINT_TO_POINTER(handle);
-
-       if (peripheral_bus_handle_is_valid(invocation, gpio_handle, pb_data->gpio_list) != 0) {
-               _E("gpio handle is not valid");
-               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
-       } else
-               ret = peripheral_bus_gpio_set_direction(gpio_handle, direction);
-
-       peripheral_io_gdbus_gpio_complete_set_direction(gpio, invocation, ret);
-
-       return true;
-}
-
-gboolean handle_gpio_read(
-               PeripheralIoGdbusGpio *gpio,
-               GDBusMethodInvocation *invocation,
-               gint handle,
-               gpointer user_data)
-{
-       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
-       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-       pb_data_h gpio_handle = GUINT_TO_POINTER(handle);
-       gint read_value = 0;
-
-       if (peripheral_bus_handle_is_valid(invocation, gpio_handle, pb_data->gpio_list) != 0) {
-               _E("gpio handle is not valid");
-               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
-       } else
-               ret = peripheral_bus_gpio_read(gpio_handle, &read_value);
-
-       peripheral_io_gdbus_gpio_complete_read(gpio, invocation, read_value, ret);
-
-       return true;
-}
-
-gboolean handle_gpio_write(
-               PeripheralIoGdbusGpio *gpio,
-               GDBusMethodInvocation *invocation,
-               gint handle,
-               gint value,
-               gpointer user_data)
-{
-       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
-       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-       pb_data_h gpio_handle = GUINT_TO_POINTER(handle);
-
-       if (peripheral_bus_handle_is_valid(invocation, gpio_handle, pb_data->gpio_list) != 0) {
-               _E("gpio handle is not valid");
-               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
-       } else
-               ret = peripheral_bus_gpio_write(gpio_handle, value);
-
-       peripheral_io_gdbus_gpio_complete_write(gpio, invocation, ret);
-
-       return true;
-}
-
-gboolean handle_gpio_get_edge_mode(
-               PeripheralIoGdbusGpio *gpio,
-               GDBusMethodInvocation *invocation,
-               gint handle,
-               gpointer user_data)
-{
-       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
-       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-       pb_data_h gpio_handle = GUINT_TO_POINTER(handle);
-       gint edge = 0;
-
-       if (peripheral_bus_handle_is_valid(invocation, gpio_handle, pb_data->gpio_list) != 0) {
-               _E("gpio handle is not valid");
-               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
-       } else
-               ret = peripheral_bus_gpio_get_edge(gpio_handle, &edge);
-
-       peripheral_io_gdbus_gpio_complete_get_edge_mode(gpio, invocation, edge, ret);
-
-       return true;
-}
-
-gboolean handle_gpio_set_edge_mode(
-               PeripheralIoGdbusGpio *gpio,
-               GDBusMethodInvocation *invocation,
-               gint handle,
-               gint edge,
-               gpointer user_data)
-{
-       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
-       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-       pb_data_h gpio_handle = GUINT_TO_POINTER(handle);
-
-       if (peripheral_bus_handle_is_valid(invocation, gpio_handle, pb_data->gpio_list) != 0) {
-               _E("gpio handle is not valid");
-               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
-       } else
-               ret = peripheral_bus_gpio_set_edge(gpio_handle, edge);
-
-       peripheral_io_gdbus_gpio_complete_set_edge_mode(gpio, invocation, ret);
-
-       return true;
-}
-
-gboolean handle_gpio_register_irq(
-               PeripheralIoGdbusGpio *gpio,
-               GDBusMethodInvocation *invocation,
-               gint handle,
-               gpointer user_data)
-{
-       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
-       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-       pb_data_h gpio_handle = GUINT_TO_POINTER(handle);
-
-       if (peripheral_bus_handle_is_valid(invocation, gpio_handle, pb_data->gpio_list) != 0) {
-               _E("gpio handle is not valid");
-               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
-       } else
-               ret = peripheral_bus_gpio_register_irq(gpio_handle);
-
-       peripheral_io_gdbus_gpio_complete_register_irq(gpio, invocation, ret);
-
-       return true;
-}
-
-gboolean handle_gpio_unregister_irq(
-               PeripheralIoGdbusGpio *gpio,
-               GDBusMethodInvocation *invocation,
-               gint handle,
-               gpointer user_data)
-{
-       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
-       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-       pb_data_h gpio_handle = GUINT_TO_POINTER(handle);
-
-       if (peripheral_bus_handle_is_valid(invocation, gpio_handle, pb_data->gpio_list) != 0) {
-               _E("gpio handle is not valid");
-               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
-       } else
-               ret = peripheral_bus_gpio_unregister_irq(gpio_handle);
-
-       peripheral_io_gdbus_gpio_complete_unregister_irq(gpio, invocation, ret);
-
-       return true;
-}
-
-gboolean handle_i2c_open(
-               PeripheralIoGdbusI2c *i2c,
-               GDBusMethodInvocation *invocation,
-               gint bus,
-               gint address,
-               gpointer user_data)
-{
-       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
-       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-       pb_data_h i2c_handle;
-
-       if ((ret = peripheral_bus_i2c_open(bus, address, &i2c_handle, user_data)) < PERIPHERAL_ERROR_NONE)
-               goto out;
-
-       if (peripheral_bus_get_client_info(invocation, pb_data, &i2c_handle->client_info) < 0) {
-               peripheral_bus_i2c_close(i2c_handle);
-               ret = PERIPHERAL_ERROR_UNKNOWN;
-               goto out;
-       }
-
-       i2c_handle->watch_id = g_bus_watch_name(G_BUS_TYPE_SYSTEM ,
-                       i2c_handle->client_info.id,
-                       G_BUS_NAME_WATCHER_FLAGS_NONE ,
-                       NULL,
-                       __i2c_on_name_vanished,
-                       i2c_handle,
-                       NULL);
-       _D("bus : %d, address : %d, id = %s", bus, address, i2c_handle->client_info.id);
-
-out:
-       peripheral_io_gdbus_i2c_complete_open(i2c, invocation, GPOINTER_TO_UINT(i2c_handle), ret);
-
-       return true;
-}
-
-gboolean handle_i2c_close(
-               PeripheralIoGdbusI2c *i2c,
-               GDBusMethodInvocation *invocation,
-               gint handle,
-               gpointer user_data)
-{
-       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
-       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-       pb_data_h i2c_handle = GUINT_TO_POINTER(handle);
-
-       if (peripheral_bus_handle_is_valid(invocation, i2c_handle, pb_data->i2c_list) != 0) {
-               _E("i2c handle is not valid");
-               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
-       } else {
-               g_bus_unwatch_name(i2c_handle->watch_id);
-               ret = peripheral_bus_i2c_close(i2c_handle);
-       }
-
-       peripheral_io_gdbus_i2c_complete_close(i2c, invocation, ret);
-
-       return true;
-}
-
-gboolean handle_i2c_read(
-               PeripheralIoGdbusI2c *i2c,
-               GDBusMethodInvocation *invocation,
-               gint handle,
-               gint length,
-               gpointer user_data)
-{
-       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
-       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-       pb_data_h i2c_handle = GUINT_TO_POINTER(handle);
-       GVariant *data_array = NULL;
-       uint8_t err_buf[2] = {0, };
-
-       if (peripheral_bus_handle_is_valid(invocation, i2c_handle, pb_data->i2c_list) != 0) {
-               _E("i2c handle is not valid");
-               data_array = peripheral_bus_build_variant_ay(err_buf, sizeof(err_buf));
-               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
-       } else
-               ret = peripheral_bus_i2c_read(i2c_handle, length, &data_array);
-
-       peripheral_io_gdbus_i2c_complete_read(i2c, invocation, data_array, ret);
-
-       return true;
-}
-
-gboolean handle_i2c_write(
-               PeripheralIoGdbusI2c *i2c,
-               GDBusMethodInvocation *invocation,
-               gint handle,
-               gint length,
-               GVariant *data_array,
-               gpointer user_data)
-{
-       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
-       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-       pb_data_h i2c_handle = GUINT_TO_POINTER(handle);
-
-       if (peripheral_bus_handle_is_valid(invocation, i2c_handle, pb_data->i2c_list) != 0) {
-               _E("i2c handle is not valid");
-               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
-       } else
-               ret = peripheral_bus_i2c_write(i2c_handle, length, data_array);
-
-       peripheral_io_gdbus_i2c_complete_write(i2c, invocation, ret);
-
-       return true;
-}
-
-gboolean handle_i2c_smbus_ioctl(
-               PeripheralIoGdbusI2c *i2c,
-               GDBusMethodInvocation *invocation,
-               gint handle,
-               guchar read_write,
-               guchar command,
-               guint size,
-               guint16 data_in,
-               gpointer user_data)
-{
-       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
-       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-       pb_data_h i2c_handle = GUINT_TO_POINTER(handle);
-       uint16_t data = 0xFFFF;
-
-       if (peripheral_bus_handle_is_valid(invocation, i2c_handle, pb_data->i2c_list) != 0) {
-               _E("i2c handle is not valid");
-               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
-       } else
-               ret = peripheral_bus_i2c_smbus_ioctl(i2c_handle, read_write, command, size, data_in, &data);
-
-       peripheral_io_gdbus_i2c_complete_smbus_ioctl(i2c, invocation, data, ret);
-
-       return true;
-}
-
-gboolean handle_pwm_open(
-               PeripheralIoGdbusPwm *pwm,
-               GDBusMethodInvocation *invocation,
-               gint device,
-               gint channel,
-               gpointer user_data)
-{
-       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
-       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-       pb_data_h pwm_handle;
-
-       if ((ret = peripheral_bus_pwm_open(device, channel, &pwm_handle, user_data)) <  PERIPHERAL_ERROR_NONE)
-               goto out;
-
-       if (peripheral_bus_get_client_info(invocation, pb_data, &pwm_handle->client_info) < 0) {
-               peripheral_bus_pwm_close(pwm_handle);
-               ret = PERIPHERAL_ERROR_UNKNOWN;
-               goto out;
-       }
-
-       pwm_handle->watch_id = g_bus_watch_name(G_BUS_TYPE_SYSTEM ,
-                       pwm_handle->client_info.id,
-                       G_BUS_NAME_WATCHER_FLAGS_NONE ,
-                       NULL,
-                       __pwm_on_name_vanished,
-                       pwm_handle,
-                       NULL);
-       _D("device : %d, channel : %d, id = %s", device, channel, pwm_handle->client_info.id);
-
-out:
-       peripheral_io_gdbus_pwm_complete_open(pwm, invocation, GPOINTER_TO_UINT(pwm_handle), ret);
-
-       return true;
-}
-
-gboolean handle_pwm_close(
-               PeripheralIoGdbusPwm *pwm,
-               GDBusMethodInvocation *invocation,
-               gint handle,
-               gpointer user_data)
-{
-       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
-       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-       pb_data_h pwm_handle = GUINT_TO_POINTER(handle);
-
-       if (peripheral_bus_handle_is_valid(invocation, pwm_handle, pb_data->pwm_list) != 0) {
-               _E("pwm handle is not valid");
-               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
-       } else {
-               g_bus_unwatch_name(pwm_handle->watch_id);
-               ret = peripheral_bus_pwm_close(pwm_handle);
-       }
-
-       peripheral_io_gdbus_pwm_complete_close(pwm, invocation, ret);
-
-       return true;
-}
-
-gboolean handle_pwm_set_period(
-               PeripheralIoGdbusPwm *pwm,
-               GDBusMethodInvocation *invocation,
-               gint handle,
-               gint period,
-               gpointer user_data)
-{
-       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
-       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-       pb_data_h pwm_handle = GUINT_TO_POINTER(handle);
-
-       if (peripheral_bus_handle_is_valid(invocation, pwm_handle, pb_data->pwm_list) != 0) {
-               _E("pwm handle is not valid");
-               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
-       } else
-               ret = peripheral_bus_pwm_set_period(pwm_handle, period);
-
-       peripheral_io_gdbus_pwm_complete_set_period(pwm, invocation, ret);
-
-       return true;
-}
-
-gboolean handle_pwm_get_period(
-               PeripheralIoGdbusPwm *pwm,
-               GDBusMethodInvocation *invocation,
-               gint handle,
-               gpointer user_data)
-{
-       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
-       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-       pb_data_h pwm_handle = GUINT_TO_POINTER(handle);
-       int period = 0;
-
-       if (peripheral_bus_handle_is_valid(invocation, pwm_handle, pb_data->pwm_list) != 0) {
-               _E("pwm handle is not valid");
-               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
-       } else
-               ret = peripheral_bus_pwm_get_period(pwm_handle, &period);
-
-       peripheral_io_gdbus_pwm_complete_get_period(pwm, invocation, period, ret);
-
-       return true;
-}
-
-gboolean handle_pwm_set_duty_cycle(
-               PeripheralIoGdbusPwm *pwm,
-               GDBusMethodInvocation *invocation,
-               gint handle,
-               gint duty_cycle,
-               gpointer user_data)
-{
-       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
-       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-       pb_data_h pwm_handle = GUINT_TO_POINTER(handle);
-
-       if (peripheral_bus_handle_is_valid(invocation, pwm_handle, pb_data->pwm_list) != 0) {
-               _E("pwm handle is not valid");
-               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
-       } else
-               ret = peripheral_bus_pwm_set_duty_cycle(pwm_handle, duty_cycle);
-
-       peripheral_io_gdbus_pwm_complete_set_duty_cycle(pwm, invocation, ret);
-
-       return true;
-}
-
-gboolean handle_pwm_get_duty_cycle(
-               PeripheralIoGdbusPwm *pwm,
-               GDBusMethodInvocation *invocation,
-               gint handle,
-               gpointer user_data)
-{
-       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
-       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-       pb_data_h pwm_handle = GUINT_TO_POINTER(handle);
-       int duty_cycle = 0;
-
-       if (peripheral_bus_handle_is_valid(invocation, pwm_handle, pb_data->pwm_list) != 0) {
-               _E("pwm handle is not valid");
-               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
-       } else
-               ret = peripheral_bus_pwm_get_duty_cycle(pwm_handle, &duty_cycle);
-
-       peripheral_io_gdbus_pwm_complete_get_duty_cycle(pwm, invocation, duty_cycle, ret);
-
-       return true;
-}
-
-gboolean handle_pwm_set_polarity(
-               PeripheralIoGdbusPwm *pwm,
-               GDBusMethodInvocation *invocation,
-               gint handle,
-               gint polarity,
-               gpointer user_data)
-{
-       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
-       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-       pb_data_h pwm_handle = GUINT_TO_POINTER(handle);
-
-       if (peripheral_bus_handle_is_valid(invocation, pwm_handle, pb_data->pwm_list) != 0) {
-               _E("pwm handle is not valid");
-               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
-       } else
-               ret = peripheral_bus_pwm_set_polarity(pwm_handle, polarity);
-
-       peripheral_io_gdbus_pwm_complete_set_polarity(pwm, invocation, ret);
-
-       return true;
-}
-
-gboolean handle_pwm_get_polarity(
-               PeripheralIoGdbusPwm *pwm,
-               GDBusMethodInvocation *invocation,
-               gint handle,
-               gpointer user_data)
-{
-       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
-       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-       pb_data_h pwm_handle = GUINT_TO_POINTER(handle);
-       int polarity = 0;
-
-       if (peripheral_bus_handle_is_valid(invocation, pwm_handle, pb_data->pwm_list) != 0) {
-               _E("pwm handle is not valid");
-               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
-       } else
-       ret = peripheral_bus_pwm_get_polarity(pwm_handle, &polarity);
-
-       peripheral_io_gdbus_pwm_complete_get_polarity(pwm, invocation, polarity, ret);
-
-       return true;
-}
-
-gboolean handle_pwm_set_enable(
-               PeripheralIoGdbusPwm *pwm,
-               GDBusMethodInvocation *invocation,
-               gint handle,
-               gint enable,
-               gpointer user_data)
-{
-       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
-       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-       pb_data_h pwm_handle = GUINT_TO_POINTER(handle);
-
-       if (peripheral_bus_handle_is_valid(invocation, pwm_handle, pb_data->pwm_list) != 0) {
-               _E("pwm handle is not valid");
-               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
-       } else
-               ret = peripheral_bus_pwm_set_enable(pwm_handle, enable);
-
-       peripheral_io_gdbus_pwm_complete_set_enable(pwm, invocation, ret);
-
-       return true;
-}
-
-gboolean handle_pwm_get_enable(
-               PeripheralIoGdbusPwm *pwm,
-               GDBusMethodInvocation *invocation,
-               gint handle,
-               gpointer user_data)
-{
-       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
-       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-       pb_data_h pwm_handle = GUINT_TO_POINTER(handle);
-       bool enable = false;
-
-       if (peripheral_bus_handle_is_valid(invocation, pwm_handle, pb_data->pwm_list) != 0) {
-               _E("pwm handle is not valid");
-               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
-       } else
-               ret = peripheral_bus_pwm_get_enable(pwm_handle, &enable);
-
-       peripheral_io_gdbus_pwm_complete_get_enable(pwm, invocation, enable, ret);
-
-       return true;
-}
-
-gboolean handle_adc_read(
-               PeripheralIoGdbusAdc *adc,
-               GDBusMethodInvocation *invocation,
-               guint device,
-               guint channel,
-               gpointer user_data)
-{
-       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
-       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-       int data = 0;
-
-       if (pb_data->adc_path == NULL) {
-               pb_data->adc_path = peripheral_bus_adc_get_path(device);
-               if (pb_data->adc_path == NULL) {
-                       ret = PERIPHERAL_ERROR_UNKNOWN;
-                       goto out;
-               }
-       }
-
-       ret = peripheral_bus_adc_read(device, channel, pb_data->adc_path, &data);
-
-out:
-       peripheral_io_gdbus_adc_complete_read(adc, invocation, data, ret);
-
-       return true;
-}
-
-gboolean handle_uart_open(
-               PeripheralIoGdbusUart *uart,
-               GDBusMethodInvocation *invocation,
-               gint port,
-               gpointer user_data)
-{
-       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
-       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-       pb_data_h uart_handle;
-
-       if ((ret = peripheral_bus_uart_open(port, &uart_handle, user_data)) < PERIPHERAL_ERROR_NONE)
-               goto out;
-
-       if (peripheral_bus_get_client_info(invocation, pb_data, &uart_handle->client_info) < 0) {
-               peripheral_bus_uart_close(uart_handle);
-               ret = PERIPHERAL_ERROR_UNKNOWN;
-               goto out;
-       }
-
-       uart_handle->watch_id = g_bus_watch_name(G_BUS_TYPE_SYSTEM ,
-                       uart_handle->client_info.id,
-                       G_BUS_NAME_WATCHER_FLAGS_NONE ,
-                       NULL,
-                       __uart_on_name_vanished,
-                       uart_handle,
-                       NULL);
-       _D("port : %d, id = %s", port, uart_handle->client_info.id);
-
-out:
-       peripheral_io_gdbus_uart_complete_open(uart, invocation, GPOINTER_TO_UINT(uart_handle), ret);
-
-       return true;
-}
-
-gboolean handle_uart_close(
-               PeripheralIoGdbusUart *uart,
-               GDBusMethodInvocation *invocation,
-               gint handle,
-               gpointer user_data)
-{
-       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
-       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-       pb_data_h uart_handle = GUINT_TO_POINTER(handle);
-
-       if (peripheral_bus_handle_is_valid(invocation, uart_handle, pb_data->uart_list) != 0) {
-               _E("uart handle is not valid");
-               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
-       } else {
-               g_bus_unwatch_name(uart_handle->watch_id);
-               ret = peripheral_bus_uart_close(uart_handle);
-       }
-
-       peripheral_io_gdbus_uart_complete_close(uart, invocation, ret);
-
-       return true;
-}
-
-gboolean handle_uart_flush(
-               PeripheralIoGdbusUart *uart,
-               GDBusMethodInvocation *invocation,
-               gint handle,
-               gpointer user_data)
-{
-       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
-       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-       pb_data_h uart_handle = GUINT_TO_POINTER(handle);
-
-       if (peripheral_bus_handle_is_valid(invocation, uart_handle, pb_data->uart_list) != 0) {
-               _E("uart handle is not valid");
-               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
-       } else
-               ret = peripheral_bus_uart_flush(uart_handle);
-
-       peripheral_io_gdbus_uart_complete_flush(uart, invocation, ret);
-
-       return true;
-}
-
-gboolean handle_uart_set_baudrate(
-               PeripheralIoGdbusUart *uart,
-               GDBusMethodInvocation *invocation,
-               gint handle,
-               guint baudrate,
-               gpointer user_data)
-{
-       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
-       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-       pb_data_h uart_handle = GUINT_TO_POINTER(handle);
-
-       if (peripheral_bus_handle_is_valid(invocation, uart_handle, pb_data->uart_list) != 0) {
-               _E("uart handle is not valid");
-               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
-       } else
-               ret = peripheral_bus_uart_set_baudrate(uart_handle, baudrate);
-
-       peripheral_io_gdbus_uart_complete_set_baudrate(uart, invocation, ret);
-
-       return true;
-}
-gboolean handle_uart_set_mode(
-               PeripheralIoGdbusUart *uart,
-               GDBusMethodInvocation *invocation,
-               gint handle,
-               guint byte_size,
-               guint parity,
-               guint stop_bits,
-               gpointer user_data)
-{
-       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
-       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-       pb_data_h uart_handle = GUINT_TO_POINTER(handle);
-
-       if (peripheral_bus_handle_is_valid(invocation, uart_handle, pb_data->uart_list) != 0) {
-               _E("uart handle is not valid");
-               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
-       } else
-               ret = peripheral_bus_uart_set_mode(uart_handle, byte_size, parity, stop_bits);
-
-       peripheral_io_gdbus_uart_complete_set_mode(uart, invocation, ret);
-
-       return true;
-}
-gboolean handle_uart_set_flowcontrol(
-               PeripheralIoGdbusUart *uart,
-               GDBusMethodInvocation *invocation,
-               gint handle,
-               gboolean xonxoff,
-               gboolean rtscts,
-               gpointer user_data)
-{
-       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
-       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-       pb_data_h uart_handle = GUINT_TO_POINTER(handle);
-
-       if (peripheral_bus_handle_is_valid(invocation, uart_handle, pb_data->uart_list) != 0) {
-               _E("uart handle is not valid");
-               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
-       } else
-               ret = peripheral_bus_uart_set_flowcontrol(uart_handle, xonxoff, rtscts);
-
-       peripheral_io_gdbus_uart_complete_set_flowcontrol(uart, invocation, ret);
-
-       return true;
-}
-
-gboolean handle_uart_read(
-               PeripheralIoGdbusUart *uart,
-               GDBusMethodInvocation *invocation,
-               gint handle,
-               gint length,
-               gpointer user_data)
-{
-       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
-       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-       pb_data_h uart_handle = GUINT_TO_POINTER(handle);
-       uint8_t err_buf[2] = {0, };
-       GVariant *data_array = NULL;
-
-       if (peripheral_bus_handle_is_valid(invocation, uart_handle, pb_data->uart_list) != 0) {
-               _E("uart handle is not valid");
-               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
-       } else
-               ret = peripheral_bus_uart_read(uart_handle, &data_array, length);
-
-       if (!data_array)
-               data_array = peripheral_bus_build_variant_ay(err_buf, sizeof(err_buf));
-
-       peripheral_io_gdbus_uart_complete_read(uart, invocation, data_array, ret);
-
-       return true;
-}
-
-gboolean handle_uart_write(
-               PeripheralIoGdbusUart *uart,
-               GDBusMethodInvocation *invocation,
-               gint handle,
-               gint length,
-               GVariant *data_array,
-               gpointer user_data)
-{
-       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
-       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-       pb_data_h uart_handle = GUINT_TO_POINTER(handle);
-
-       if (peripheral_bus_handle_is_valid(invocation, uart_handle, pb_data->uart_list) != 0) {
-               _E("uart handle is not valid");
-               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
-       } else
-               ret = peripheral_bus_uart_write(uart_handle, data_array, length);
-
-       peripheral_io_gdbus_uart_complete_write(uart, invocation, ret);
-
-       return true;
-}
-
-gboolean handle_spi_open(
-               PeripheralIoGdbusSpi *spi,
-               GDBusMethodInvocation *invocation,
-               gint bus,
-               gint cs,
-               gpointer user_data)
-{
-       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
-       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-       pb_data_h spi_handle;
-
-       if ((ret = peripheral_bus_spi_open(bus, cs, &spi_handle, user_data)) < PERIPHERAL_ERROR_NONE)
-               goto out;
-
-       if (peripheral_bus_get_client_info(invocation, pb_data, &spi_handle->client_info) < 0) {
-               peripheral_bus_spi_close(spi_handle);
-               ret = PERIPHERAL_ERROR_UNKNOWN;
-               goto out;
-       }
-
-       spi_handle->watch_id = g_bus_watch_name(G_BUS_TYPE_SYSTEM ,
-                       spi_handle->client_info.id,
-                       G_BUS_NAME_WATCHER_FLAGS_NONE ,
-                       NULL,
-                       __spi_on_name_vanished,
-                       spi_handle,
-                       NULL);
-       _D("bus : %d, cs : %d, id = %s", bus, cs, spi_handle->client_info.id);
-
-out:
-       peripheral_io_gdbus_spi_complete_open(spi, invocation, GPOINTER_TO_UINT(spi_handle), ret);
-
-       return true;
-}
-
-gboolean handle_spi_close(
-               PeripheralIoGdbusSpi *spi,
-               GDBusMethodInvocation *invocation,
-               gint handle,
-               gpointer user_data)
-{
-       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
-       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-       pb_data_h spi_handle = GUINT_TO_POINTER(handle);
-
-       if (peripheral_bus_handle_is_valid(invocation, spi_handle, pb_data->spi_list) != 0) {
-               _E("spi handle is not valid");
-               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
-       } else {
-               g_bus_unwatch_name(spi_handle->watch_id);
-               ret = peripheral_bus_spi_close(spi_handle);
-       }
-
-       peripheral_io_gdbus_spi_complete_close(spi, invocation, ret);
-
-       return true;
-}
-
-gboolean handle_spi_set_mode(
-               PeripheralIoGdbusSpi *spi,
-               GDBusMethodInvocation *invocation,
-               gint handle,
-               guchar mode,
-               gpointer user_data)
-{
-       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
-       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-       pb_data_h spi_handle = GUINT_TO_POINTER(handle);
-
-       if (peripheral_bus_handle_is_valid(invocation, spi_handle, pb_data->spi_list) != 0) {
-               _E("spi handle is not valid");
-               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
-       } else
-               ret = peripheral_bus_spi_set_mode(spi_handle, mode);
-
-       peripheral_io_gdbus_spi_complete_set_mode(spi, invocation, ret);
-
-       return true;
-}
-
-gboolean handle_spi_get_mode(
-               PeripheralIoGdbusSpi *spi,
-               GDBusMethodInvocation *invocation,
-               gint handle,
-               gpointer user_data)
-{
-       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
-       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-       pb_data_h spi_handle = GUINT_TO_POINTER(handle);
-       uint8_t mode = 0;
-
-       if (peripheral_bus_handle_is_valid(invocation, spi_handle, pb_data->spi_list) != 0) {
-               _E("spi handle is not valid");
-               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
-       } else
-               ret = peripheral_bus_spi_get_mode(spi_handle, &mode);
-
-       peripheral_io_gdbus_spi_complete_get_mode(spi, invocation, mode, ret);
-
-       return true;
-}
-
-gboolean handle_spi_set_lsb_first(
-               PeripheralIoGdbusSpi *spi,
-               GDBusMethodInvocation *invocation,
-               gint handle,
-               gboolean lsb,
-               gpointer user_data)
-{
-       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
-       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-       pb_data_h spi_handle = GUINT_TO_POINTER(handle);
-
-       if (peripheral_bus_handle_is_valid(invocation, spi_handle, pb_data->spi_list) != 0) {
-               _E("spi handle is not valid");
-               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
-       } else
-               ret = peripheral_bus_spi_set_lsb_first(spi_handle, lsb);
-
-       peripheral_io_gdbus_spi_complete_set_lsb_first(spi, invocation, ret);
-
-       return true;
-}
-
-gboolean handle_spi_get_lsb_first(
-               PeripheralIoGdbusSpi *spi,
-               GDBusMethodInvocation *invocation,
-               gint handle,
-               gpointer user_data)
-{
-       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
-       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-       pb_data_h spi_handle = GUINT_TO_POINTER(handle);
-       gboolean lsb = 0;
-
-       if (peripheral_bus_handle_is_valid(invocation, spi_handle, pb_data->spi_list) != 0) {
-               _E("spi handle is not valid");
-               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
-       } else
-               ret = peripheral_bus_spi_get_lsb_first(spi_handle, &lsb);
-
-       peripheral_io_gdbus_spi_complete_get_lsb_first(spi, invocation, lsb, ret);
-
-       return true;
-}
-
-gboolean handle_spi_set_bits(
-               PeripheralIoGdbusSpi *spi,
-               GDBusMethodInvocation *invocation,
-               gint handle,
-               guchar bits,
-               gpointer user_data)
-{
-       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
-       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-       pb_data_h spi_handle = GUINT_TO_POINTER(handle);
-
-       if (peripheral_bus_handle_is_valid(invocation, spi_handle, pb_data->spi_list) != 0) {
-               _E("spi handle is not valid");
-               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
-       } else
-               ret = peripheral_bus_spi_set_bits(spi_handle, bits);
-
-       peripheral_io_gdbus_spi_complete_set_bits(spi, invocation, ret);
-
-       return true;
-}
-
-gboolean handle_spi_get_bits(
-               PeripheralIoGdbusSpi *spi,
-               GDBusMethodInvocation *invocation,
-               gint handle,
-               gpointer user_data)
-{
-       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
-       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-       pb_data_h spi_handle = GUINT_TO_POINTER(handle);
-       uint8_t bits = 0;
-
-       if (peripheral_bus_handle_is_valid(invocation, spi_handle, pb_data->spi_list) != 0) {
-               _E("spi handle is not valid");
-               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
-       } else
-               ret = peripheral_bus_spi_get_bits(spi_handle, &bits);
-
-       peripheral_io_gdbus_spi_complete_get_bits(spi, invocation, bits, ret);
-
-       return true;
-}
-
-gboolean handle_spi_set_frequency(
-               PeripheralIoGdbusSpi *spi,
-               GDBusMethodInvocation *invocation,
-               gint handle,
-               guint freq,
-               gpointer user_data)
-{
-       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
-       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-       pb_data_h spi_handle = GUINT_TO_POINTER(handle);
-
-       if (peripheral_bus_handle_is_valid(invocation, spi_handle, pb_data->spi_list) != 0) {
-               _E("spi handle is not valid");
-               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
-       } else
-               ret = peripheral_bus_spi_set_frequency(spi_handle, freq);
-
-       peripheral_io_gdbus_spi_complete_set_frequency(spi, invocation, ret);
-
-       return true;
-}
-
-gboolean handle_spi_get_frequency(
-               PeripheralIoGdbusSpi *spi,
-               GDBusMethodInvocation *invocation,
-               gint handle,
-               gpointer user_data)
-{
-       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
-       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-       pb_data_h spi_handle = GUINT_TO_POINTER(handle);
-       unsigned int freq = 0;
-
-       if (peripheral_bus_handle_is_valid(invocation, spi_handle, pb_data->spi_list) != 0) {
-               _E("spi handle is not valid");
-               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
-       } else
-               ret = peripheral_bus_spi_get_frequency(spi_handle, &freq);
-
-       peripheral_io_gdbus_spi_complete_get_frequency(spi, invocation, freq, ret);
-
-       return true;
-}
-
-gboolean handle_spi_read(
-               PeripheralIoGdbusSpi *spi,
-               GDBusMethodInvocation *invocation,
-               gint handle,
-               gint length,
-               gpointer user_data)
-{
-       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
-       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-       pb_data_h spi_handle = GUINT_TO_POINTER(handle);
-       GVariant *data_array = NULL;
-       uint8_t err_buf[2] = {0, };
-
-       if (peripheral_bus_handle_is_valid(invocation, spi_handle, pb_data->spi_list) != 0) {
-               _E("spi handle is not valid");
-               data_array = peripheral_bus_build_variant_ay(err_buf, sizeof(err_buf));
-               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
-       } else
-               ret = peripheral_bus_spi_read(spi_handle, &data_array, length);
-
-       peripheral_io_gdbus_spi_complete_read(spi, invocation, data_array, ret);
-
-       return true;
-}
-
-gboolean handle_spi_write(
-               PeripheralIoGdbusSpi *spi,
-               GDBusMethodInvocation *invocation,
-               gint handle,
-               gint length,
-               GVariant *data_array,
-               gpointer user_data)
-{
-       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
-       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-       pb_data_h spi_handle = GUINT_TO_POINTER(handle);
-
-       if (peripheral_bus_handle_is_valid(invocation, spi_handle, pb_data->spi_list) != 0) {
-               _E("spi handle is not valid");
-               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
-       } else
-               ret = peripheral_bus_spi_write(spi_handle, data_array, length);
-
-       peripheral_io_gdbus_spi_complete_write(spi, invocation, ret);
-
-       return true;
-}
-
-gboolean handle_spi_read_write(
-               PeripheralIoGdbusSpi *spi,
-               GDBusMethodInvocation *invocation,
-               gint handle,
-               gint length,
-               GVariant *tx_data_array,
-               gpointer user_data)
-{
-       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
-       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-       pb_data_h spi_handle = GUINT_TO_POINTER(handle);
-       GVariant *rx_data_array = NULL;
-       uint8_t err_buf[2] = {0, };
-
-       if (peripheral_bus_handle_is_valid(invocation, spi_handle, pb_data->spi_list) != 0) {
-               _E("spi handle is not valid");
-               rx_data_array = peripheral_bus_build_variant_ay(err_buf, sizeof(err_buf));
-               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
-       } else
-               ret = peripheral_bus_spi_read_write(spi_handle, tx_data_array, &rx_data_array, length);
-
-       peripheral_io_gdbus_spi_complete_read_write(spi, invocation, rx_data_array, ret);
-
-       return true;
-}
-
-void peripheral_bus_emit_gpio_changed(
-               PeripheralIoGdbusGpio *gpio,
-               gint pin,
-               gint value,
-               guint64 timestamp)
-{
-       g_assert(gpio != NULL);
-
-       peripheral_io_gdbus_gpio_emit_gpio_changed(gpio, pin, value, timestamp);
-}
+#include "peripheral_bus_gdbus_gpio.h"
+#include "peripheral_bus_gdbus_i2c.h"
+#include "peripheral_bus_gdbus_pwm.h"
+#include "peripheral_bus_gdbus_spi.h"
+#include "peripheral_bus_gdbus_uart.h"
+#include "peripheral_bus_gdbus_adc.h"
 
 static gboolean __gpio_init(peripheral_bus_s *pb_data)
 {
diff --git a/src/daemon/peripheral_bus_gdbus_adc.c b/src/daemon/peripheral_bus_gdbus_adc.c
new file mode 100644 (file)
index 0000000..517354b
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <peripheral_io.h>
+
+#include "peripheral_io_gdbus.h"
+#include "peripheral_bus.h"
+#include "peripheral_bus_adc.h"
+#include "peripheral_common.h"
+#include "peripheral_bus_util.h"
+#include "peripheral_bus_gdbus_adc.h"
+
+gboolean handle_adc_read(
+               PeripheralIoGdbusAdc *adc,
+               GDBusMethodInvocation *invocation,
+               guint device,
+               guint channel,
+               gpointer user_data)
+{
+       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
+       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+       int data = 0;
+
+       if (pb_data->adc_path == NULL) {
+               pb_data->adc_path = peripheral_bus_adc_get_path(device);
+               if (pb_data->adc_path == NULL) {
+                       ret = PERIPHERAL_ERROR_UNKNOWN;
+                       goto out;
+               }
+       }
+
+       ret = peripheral_bus_adc_read(device, channel, pb_data->adc_path, &data);
+
+out:
+       peripheral_io_gdbus_adc_complete_read(adc, invocation, data, ret);
+
+       return true;
+}
diff --git a/src/daemon/peripheral_bus_gdbus_gpio.c b/src/daemon/peripheral_bus_gdbus_gpio.c
new file mode 100644 (file)
index 0000000..d4ee8ee
--- /dev/null
@@ -0,0 +1,277 @@
+/*
+ * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <peripheral_io.h>
+
+#include "peripheral_io_gdbus.h"
+#include "peripheral_bus.h"
+#include "peripheral_bus_gpio.h"
+#include "peripheral_common.h"
+#include "peripheral_bus_util.h"
+#include "peripheral_bus_gdbus_gpio.h"
+
+static void __gpio_on_name_vanished(GDBusConnection *connection,
+               const gchar     *name,
+               gpointer         user_data)
+{
+       pb_data_h gpio_handle = (pb_data_h)user_data;
+       _D("appid [%s] vanished ", name);
+
+       g_bus_unwatch_name(gpio_handle->watch_id);
+       peripheral_bus_gpio_close(gpio_handle);
+}
+
+gboolean handle_gpio_open(
+               PeripheralIoGdbusGpio *gpio,
+               GDBusMethodInvocation *invocation,
+               gint pin,
+               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;
+
+       if ((ret = peripheral_bus_gpio_open(pin, &gpio_handle, user_data)) < PERIPHERAL_ERROR_NONE)
+               goto out;
+
+       if (peripheral_bus_get_client_info(invocation, pb_data, &gpio_handle->client_info) < 0) {
+               peripheral_bus_gpio_close(gpio_handle);
+               ret = PERIPHERAL_ERROR_UNKNOWN;
+               goto out;
+       }
+
+       gpio_handle->watch_id = g_bus_watch_name(G_BUS_TYPE_SYSTEM ,
+                       gpio_handle->client_info.id,
+                       G_BUS_NAME_WATCHER_FLAGS_NONE ,
+                       NULL,
+                       __gpio_on_name_vanished,
+                       gpio_handle,
+                       NULL);
+       _D("gpio : %d, id = %s", gpio_handle->dev.gpio.pin, gpio_handle->client_info.id);
+
+out:
+       peripheral_io_gdbus_gpio_complete_open(gpio, invocation, GPOINTER_TO_UINT(gpio_handle), ret);
+
+       return true;
+}
+
+gboolean handle_gpio_close(
+               PeripheralIoGdbusGpio *gpio,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gpointer user_data)
+{
+       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
+       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+       pb_data_h gpio_handle = GUINT_TO_POINTER(handle);
+
+       if (peripheral_bus_handle_is_valid(invocation, gpio_handle, pb_data->gpio_list) != 0) {
+               _E("gpio handle is not valid");
+               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
+       } else {
+               g_bus_unwatch_name(gpio_handle->watch_id);
+               ret = peripheral_bus_gpio_close(gpio_handle);
+       }
+
+       peripheral_io_gdbus_gpio_complete_close(gpio, invocation, ret);
+
+       return true;
+}
+
+gboolean handle_gpio_get_direction(
+               PeripheralIoGdbusGpio *gpio,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gpointer user_data)
+{
+       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
+       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+       pb_data_h gpio_handle = GUINT_TO_POINTER(handle);
+       gint direction = 0;
+
+       if (peripheral_bus_handle_is_valid(invocation, gpio_handle, pb_data->gpio_list) != 0) {
+               _E("gpio handle is not valid");
+               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
+       } else
+               ret = peripheral_bus_gpio_get_direction(gpio_handle, &direction);
+
+       peripheral_io_gdbus_gpio_complete_get_direction(gpio, invocation, direction, ret);
+
+       return true;
+}
+
+gboolean handle_gpio_set_direction(
+               PeripheralIoGdbusGpio *gpio,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gint direction,
+               gpointer user_data)
+{
+       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
+       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+       pb_data_h gpio_handle = GUINT_TO_POINTER(handle);
+
+       if (peripheral_bus_handle_is_valid(invocation, gpio_handle, pb_data->gpio_list) != 0) {
+               _E("gpio handle is not valid");
+               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
+       } else
+               ret = peripheral_bus_gpio_set_direction(gpio_handle, direction);
+
+       peripheral_io_gdbus_gpio_complete_set_direction(gpio, invocation, ret);
+
+       return true;
+}
+
+gboolean handle_gpio_read(
+               PeripheralIoGdbusGpio *gpio,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gpointer user_data)
+{
+       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
+       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+       pb_data_h gpio_handle = GUINT_TO_POINTER(handle);
+       gint read_value = 0;
+
+       if (peripheral_bus_handle_is_valid(invocation, gpio_handle, pb_data->gpio_list) != 0) {
+               _E("gpio handle is not valid");
+               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
+       } else
+               ret = peripheral_bus_gpio_read(gpio_handle, &read_value);
+
+       peripheral_io_gdbus_gpio_complete_read(gpio, invocation, read_value, ret);
+
+       return true;
+}
+
+gboolean handle_gpio_write(
+               PeripheralIoGdbusGpio *gpio,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gint value,
+               gpointer user_data)
+{
+       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
+       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+       pb_data_h gpio_handle = GUINT_TO_POINTER(handle);
+
+       if (peripheral_bus_handle_is_valid(invocation, gpio_handle, pb_data->gpio_list) != 0) {
+               _E("gpio handle is not valid");
+               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
+       } else
+               ret = peripheral_bus_gpio_write(gpio_handle, value);
+
+       peripheral_io_gdbus_gpio_complete_write(gpio, invocation, ret);
+
+       return true;
+}
+
+gboolean handle_gpio_get_edge_mode(
+               PeripheralIoGdbusGpio *gpio,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gpointer user_data)
+{
+       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
+       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+       pb_data_h gpio_handle = GUINT_TO_POINTER(handle);
+       gint edge = 0;
+
+       if (peripheral_bus_handle_is_valid(invocation, gpio_handle, pb_data->gpio_list) != 0) {
+               _E("gpio handle is not valid");
+               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
+       } else
+               ret = peripheral_bus_gpio_get_edge(gpio_handle, &edge);
+
+       peripheral_io_gdbus_gpio_complete_get_edge_mode(gpio, invocation, edge, ret);
+
+       return true;
+}
+
+gboolean handle_gpio_set_edge_mode(
+               PeripheralIoGdbusGpio *gpio,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gint edge,
+               gpointer user_data)
+{
+       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
+       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+       pb_data_h gpio_handle = GUINT_TO_POINTER(handle);
+
+       if (peripheral_bus_handle_is_valid(invocation, gpio_handle, pb_data->gpio_list) != 0) {
+               _E("gpio handle is not valid");
+               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
+       } else
+               ret = peripheral_bus_gpio_set_edge(gpio_handle, edge);
+
+       peripheral_io_gdbus_gpio_complete_set_edge_mode(gpio, invocation, ret);
+
+       return true;
+}
+
+gboolean handle_gpio_register_irq(
+               PeripheralIoGdbusGpio *gpio,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gpointer user_data)
+{
+       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
+       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+       pb_data_h gpio_handle = GUINT_TO_POINTER(handle);
+
+       if (peripheral_bus_handle_is_valid(invocation, gpio_handle, pb_data->gpio_list) != 0) {
+               _E("gpio handle is not valid");
+               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
+       } else
+               ret = peripheral_bus_gpio_register_irq(gpio_handle);
+
+       peripheral_io_gdbus_gpio_complete_register_irq(gpio, invocation, ret);
+
+       return true;
+}
+
+gboolean handle_gpio_unregister_irq(
+               PeripheralIoGdbusGpio *gpio,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gpointer user_data)
+{
+       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
+       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+       pb_data_h gpio_handle = GUINT_TO_POINTER(handle);
+
+       if (peripheral_bus_handle_is_valid(invocation, gpio_handle, pb_data->gpio_list) != 0) {
+               _E("gpio handle is not valid");
+               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
+       } else
+               ret = peripheral_bus_gpio_unregister_irq(gpio_handle);
+
+       peripheral_io_gdbus_gpio_complete_unregister_irq(gpio, invocation, ret);
+
+       return true;
+}
+
+void peripheral_bus_emit_gpio_changed(
+               PeripheralIoGdbusGpio *gpio,
+               gint pin,
+               gint value,
+               guint64 timestamp)
+{
+       g_assert(gpio != NULL);
+
+       peripheral_io_gdbus_gpio_emit_gpio_changed(gpio, pin, value, timestamp);
+}
diff --git a/src/daemon/peripheral_bus_gdbus_i2c.c b/src/daemon/peripheral_bus_gdbus_i2c.c
new file mode 100644 (file)
index 0000000..01d9bc6
--- /dev/null
@@ -0,0 +1,167 @@
+/*
+ * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <peripheral_io.h>
+
+#include "peripheral_io_gdbus.h"
+#include "peripheral_bus.h"
+#include "peripheral_bus_i2c.h"
+#include "peripheral_common.h"
+#include "peripheral_bus_util.h"
+#include "peripheral_bus_gdbus_i2c.h"
+
+static void __i2c_on_name_vanished(GDBusConnection *connection,
+               const gchar     *name,
+               gpointer         user_data)
+{
+       pb_data_h i2c_handle = (pb_data_h)user_data;
+       _D("appid [%s] vanished ", name);
+
+       g_bus_unwatch_name(i2c_handle->watch_id);
+       peripheral_bus_i2c_close(i2c_handle);
+}
+
+gboolean handle_i2c_open(
+               PeripheralIoGdbusI2c *i2c,
+               GDBusMethodInvocation *invocation,
+               gint bus,
+               gint address,
+               gpointer user_data)
+{
+       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
+       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+       pb_data_h i2c_handle;
+
+       if ((ret = peripheral_bus_i2c_open(bus, address, &i2c_handle, user_data)) < PERIPHERAL_ERROR_NONE)
+               goto out;
+
+       if (peripheral_bus_get_client_info(invocation, pb_data, &i2c_handle->client_info) < 0) {
+               peripheral_bus_i2c_close(i2c_handle);
+               ret = PERIPHERAL_ERROR_UNKNOWN;
+               goto out;
+       }
+
+       i2c_handle->watch_id = g_bus_watch_name(G_BUS_TYPE_SYSTEM ,
+                       i2c_handle->client_info.id,
+                       G_BUS_NAME_WATCHER_FLAGS_NONE ,
+                       NULL,
+                       __i2c_on_name_vanished,
+                       i2c_handle,
+                       NULL);
+       _D("bus : %d, address : %d, id = %s", bus, address, i2c_handle->client_info.id);
+
+out:
+       peripheral_io_gdbus_i2c_complete_open(i2c, invocation, GPOINTER_TO_UINT(i2c_handle), ret);
+
+       return true;
+}
+
+gboolean handle_i2c_close(
+               PeripheralIoGdbusI2c *i2c,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gpointer user_data)
+{
+       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
+       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+       pb_data_h i2c_handle = GUINT_TO_POINTER(handle);
+
+       if (peripheral_bus_handle_is_valid(invocation, i2c_handle, pb_data->i2c_list) != 0) {
+               _E("i2c handle is not valid");
+               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
+       } else {
+               g_bus_unwatch_name(i2c_handle->watch_id);
+               ret = peripheral_bus_i2c_close(i2c_handle);
+       }
+
+       peripheral_io_gdbus_i2c_complete_close(i2c, invocation, ret);
+
+       return true;
+}
+
+gboolean handle_i2c_read(
+               PeripheralIoGdbusI2c *i2c,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gint length,
+               gpointer user_data)
+{
+       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
+       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+       pb_data_h i2c_handle = GUINT_TO_POINTER(handle);
+       GVariant *data_array = NULL;
+       uint8_t err_buf[2] = {0, };
+
+       if (peripheral_bus_handle_is_valid(invocation, i2c_handle, pb_data->i2c_list) != 0) {
+               _E("i2c handle is not valid");
+               data_array = peripheral_bus_build_variant_ay(err_buf, sizeof(err_buf));
+               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
+       } else
+               ret = peripheral_bus_i2c_read(i2c_handle, length, &data_array);
+
+       peripheral_io_gdbus_i2c_complete_read(i2c, invocation, data_array, ret);
+
+       return true;
+}
+
+gboolean handle_i2c_write(
+               PeripheralIoGdbusI2c *i2c,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gint length,
+               GVariant *data_array,
+               gpointer user_data)
+{
+       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
+       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+       pb_data_h i2c_handle = GUINT_TO_POINTER(handle);
+
+       if (peripheral_bus_handle_is_valid(invocation, i2c_handle, pb_data->i2c_list) != 0) {
+               _E("i2c handle is not valid");
+               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
+       } else
+               ret = peripheral_bus_i2c_write(i2c_handle, length, data_array);
+
+       peripheral_io_gdbus_i2c_complete_write(i2c, invocation, ret);
+
+       return true;
+}
+
+gboolean handle_i2c_smbus_ioctl(
+               PeripheralIoGdbusI2c *i2c,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               guchar read_write,
+               guchar command,
+               guint size,
+               guint16 data_in,
+               gpointer user_data)
+{
+       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
+       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+       pb_data_h i2c_handle = GUINT_TO_POINTER(handle);
+       uint16_t data = 0xFFFF;
+
+       if (peripheral_bus_handle_is_valid(invocation, i2c_handle, pb_data->i2c_list) != 0) {
+               _E("i2c handle is not valid");
+               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
+       } else
+               ret = peripheral_bus_i2c_smbus_ioctl(i2c_handle, read_write, command, size, data_in, &data);
+
+       peripheral_io_gdbus_i2c_complete_smbus_ioctl(i2c, invocation, data, ret);
+
+       return true;
+}
diff --git a/src/daemon/peripheral_bus_gdbus_pwm.c b/src/daemon/peripheral_bus_gdbus_pwm.c
new file mode 100644 (file)
index 0000000..33d5123
--- /dev/null
@@ -0,0 +1,269 @@
+/*
+ * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <peripheral_io.h>
+
+#include "peripheral_io_gdbus.h"
+#include "peripheral_bus.h"
+#include "peripheral_bus_pwm.h"
+#include "peripheral_common.h"
+#include "peripheral_bus_util.h"
+#include "peripheral_bus_gdbus_pwm.h"
+
+static void __pwm_on_name_vanished(GDBusConnection *connection,
+               const gchar     *name,
+               gpointer         user_data)
+{
+       pb_data_h pwm_handle = (pb_data_h)user_data;
+       _D("appid [%s] vanished ", name);
+
+       g_bus_unwatch_name(pwm_handle->watch_id);
+       peripheral_bus_pwm_close(pwm_handle);
+}
+
+gboolean handle_pwm_open(
+               PeripheralIoGdbusPwm *pwm,
+               GDBusMethodInvocation *invocation,
+               gint device,
+               gint channel,
+               gpointer user_data)
+{
+       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
+       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+       pb_data_h pwm_handle;
+
+       if ((ret = peripheral_bus_pwm_open(device, channel, &pwm_handle, user_data)) <  PERIPHERAL_ERROR_NONE)
+               goto out;
+
+       if (peripheral_bus_get_client_info(invocation, pb_data, &pwm_handle->client_info) < 0) {
+               peripheral_bus_pwm_close(pwm_handle);
+               ret = PERIPHERAL_ERROR_UNKNOWN;
+               goto out;
+       }
+
+       pwm_handle->watch_id = g_bus_watch_name(G_BUS_TYPE_SYSTEM ,
+                       pwm_handle->client_info.id,
+                       G_BUS_NAME_WATCHER_FLAGS_NONE ,
+                       NULL,
+                       __pwm_on_name_vanished,
+                       pwm_handle,
+                       NULL);
+       _D("device : %d, channel : %d, id = %s", device, channel, pwm_handle->client_info.id);
+
+out:
+       peripheral_io_gdbus_pwm_complete_open(pwm, invocation, GPOINTER_TO_UINT(pwm_handle), ret);
+
+       return true;
+}
+
+gboolean handle_pwm_close(
+               PeripheralIoGdbusPwm *pwm,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gpointer user_data)
+{
+       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
+       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+       pb_data_h pwm_handle = GUINT_TO_POINTER(handle);
+
+       if (peripheral_bus_handle_is_valid(invocation, pwm_handle, pb_data->pwm_list) != 0) {
+               _E("pwm handle is not valid");
+               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
+       } else {
+               g_bus_unwatch_name(pwm_handle->watch_id);
+               ret = peripheral_bus_pwm_close(pwm_handle);
+       }
+
+       peripheral_io_gdbus_pwm_complete_close(pwm, invocation, ret);
+
+       return true;
+}
+
+gboolean handle_pwm_set_period(
+               PeripheralIoGdbusPwm *pwm,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gint period,
+               gpointer user_data)
+{
+       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
+       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+       pb_data_h pwm_handle = GUINT_TO_POINTER(handle);
+
+       if (peripheral_bus_handle_is_valid(invocation, pwm_handle, pb_data->pwm_list) != 0) {
+               _E("pwm handle is not valid");
+               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
+       } else
+               ret = peripheral_bus_pwm_set_period(pwm_handle, period);
+
+       peripheral_io_gdbus_pwm_complete_set_period(pwm, invocation, ret);
+
+       return true;
+}
+
+gboolean handle_pwm_get_period(
+               PeripheralIoGdbusPwm *pwm,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gpointer user_data)
+{
+       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
+       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+       pb_data_h pwm_handle = GUINT_TO_POINTER(handle);
+       int period = 0;
+
+       if (peripheral_bus_handle_is_valid(invocation, pwm_handle, pb_data->pwm_list) != 0) {
+               _E("pwm handle is not valid");
+               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
+       } else
+               ret = peripheral_bus_pwm_get_period(pwm_handle, &period);
+
+       peripheral_io_gdbus_pwm_complete_get_period(pwm, invocation, period, ret);
+
+       return true;
+}
+
+gboolean handle_pwm_set_duty_cycle(
+               PeripheralIoGdbusPwm *pwm,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gint duty_cycle,
+               gpointer user_data)
+{
+       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
+       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+       pb_data_h pwm_handle = GUINT_TO_POINTER(handle);
+
+       if (peripheral_bus_handle_is_valid(invocation, pwm_handle, pb_data->pwm_list) != 0) {
+               _E("pwm handle is not valid");
+               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
+       } else
+               ret = peripheral_bus_pwm_set_duty_cycle(pwm_handle, duty_cycle);
+
+       peripheral_io_gdbus_pwm_complete_set_duty_cycle(pwm, invocation, ret);
+
+       return true;
+}
+
+gboolean handle_pwm_get_duty_cycle(
+               PeripheralIoGdbusPwm *pwm,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gpointer user_data)
+{
+       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
+       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+       pb_data_h pwm_handle = GUINT_TO_POINTER(handle);
+       int duty_cycle = 0;
+
+       if (peripheral_bus_handle_is_valid(invocation, pwm_handle, pb_data->pwm_list) != 0) {
+               _E("pwm handle is not valid");
+               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
+       } else
+               ret = peripheral_bus_pwm_get_duty_cycle(pwm_handle, &duty_cycle);
+
+       peripheral_io_gdbus_pwm_complete_get_duty_cycle(pwm, invocation, duty_cycle, ret);
+
+       return true;
+}
+
+gboolean handle_pwm_set_polarity(
+               PeripheralIoGdbusPwm *pwm,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gint polarity,
+               gpointer user_data)
+{
+       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
+       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+       pb_data_h pwm_handle = GUINT_TO_POINTER(handle);
+
+       if (peripheral_bus_handle_is_valid(invocation, pwm_handle, pb_data->pwm_list) != 0) {
+               _E("pwm handle is not valid");
+               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
+       } else
+               ret = peripheral_bus_pwm_set_polarity(pwm_handle, polarity);
+
+       peripheral_io_gdbus_pwm_complete_set_polarity(pwm, invocation, ret);
+
+       return true;
+}
+
+gboolean handle_pwm_get_polarity(
+               PeripheralIoGdbusPwm *pwm,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gpointer user_data)
+{
+       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
+       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+       pb_data_h pwm_handle = GUINT_TO_POINTER(handle);
+       int polarity = 0;
+
+       if (peripheral_bus_handle_is_valid(invocation, pwm_handle, pb_data->pwm_list) != 0) {
+               _E("pwm handle is not valid");
+               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
+       } else
+       ret = peripheral_bus_pwm_get_polarity(pwm_handle, &polarity);
+
+       peripheral_io_gdbus_pwm_complete_get_polarity(pwm, invocation, polarity, ret);
+
+       return true;
+}
+
+gboolean handle_pwm_set_enable(
+               PeripheralIoGdbusPwm *pwm,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gint enable,
+               gpointer user_data)
+{
+       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
+       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+       pb_data_h pwm_handle = GUINT_TO_POINTER(handle);
+
+       if (peripheral_bus_handle_is_valid(invocation, pwm_handle, pb_data->pwm_list) != 0) {
+               _E("pwm handle is not valid");
+               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
+       } else
+               ret = peripheral_bus_pwm_set_enable(pwm_handle, enable);
+
+       peripheral_io_gdbus_pwm_complete_set_enable(pwm, invocation, ret);
+
+       return true;
+}
+
+gboolean handle_pwm_get_enable(
+               PeripheralIoGdbusPwm *pwm,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gpointer user_data)
+{
+       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
+       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+       pb_data_h pwm_handle = GUINT_TO_POINTER(handle);
+       bool enable = false;
+
+       if (peripheral_bus_handle_is_valid(invocation, pwm_handle, pb_data->pwm_list) != 0) {
+               _E("pwm handle is not valid");
+               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
+       } else
+               ret = peripheral_bus_pwm_get_enable(pwm_handle, &enable);
+
+       peripheral_io_gdbus_pwm_complete_get_enable(pwm, invocation, enable, ret);
+
+       return true;
+}
diff --git a/src/daemon/peripheral_bus_gdbus_spi.c b/src/daemon/peripheral_bus_gdbus_spi.c
new file mode 100644 (file)
index 0000000..36ff6d1
--- /dev/null
@@ -0,0 +1,343 @@
+/*
+ * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <peripheral_io.h>
+
+#include "peripheral_io_gdbus.h"
+#include "peripheral_bus.h"
+#include "peripheral_bus_spi.h"
+#include "peripheral_common.h"
+#include "peripheral_bus_util.h"
+#include "peripheral_bus_gdbus_spi.h"
+
+static void __spi_on_name_vanished(GDBusConnection *connection,
+               const gchar     *name,
+               gpointer         user_data)
+{
+       pb_data_h spi_handle = (pb_data_h)user_data;
+       _D("appid [%s] vanished ", name);
+
+       g_bus_unwatch_name(spi_handle->watch_id);
+       peripheral_bus_spi_close(spi_handle);
+}
+
+gboolean handle_spi_open(
+               PeripheralIoGdbusSpi *spi,
+               GDBusMethodInvocation *invocation,
+               gint bus,
+               gint cs,
+               gpointer user_data)
+{
+       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
+       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+       pb_data_h spi_handle;
+
+       if ((ret = peripheral_bus_spi_open(bus, cs, &spi_handle, user_data)) < PERIPHERAL_ERROR_NONE)
+               goto out;
+
+       if (peripheral_bus_get_client_info(invocation, pb_data, &spi_handle->client_info) < 0) {
+               peripheral_bus_spi_close(spi_handle);
+               ret = PERIPHERAL_ERROR_UNKNOWN;
+               goto out;
+       }
+
+       spi_handle->watch_id = g_bus_watch_name(G_BUS_TYPE_SYSTEM ,
+                       spi_handle->client_info.id,
+                       G_BUS_NAME_WATCHER_FLAGS_NONE ,
+                       NULL,
+                       __spi_on_name_vanished,
+                       spi_handle,
+                       NULL);
+       _D("bus : %d, cs : %d, id = %s", bus, cs, spi_handle->client_info.id);
+
+out:
+       peripheral_io_gdbus_spi_complete_open(spi, invocation, GPOINTER_TO_UINT(spi_handle), ret);
+
+       return true;
+}
+
+gboolean handle_spi_close(
+               PeripheralIoGdbusSpi *spi,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gpointer user_data)
+{
+       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
+       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+       pb_data_h spi_handle = GUINT_TO_POINTER(handle);
+
+       if (peripheral_bus_handle_is_valid(invocation, spi_handle, pb_data->spi_list) != 0) {
+               _E("spi handle is not valid");
+               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
+       } else {
+               g_bus_unwatch_name(spi_handle->watch_id);
+               ret = peripheral_bus_spi_close(spi_handle);
+       }
+
+       peripheral_io_gdbus_spi_complete_close(spi, invocation, ret);
+
+       return true;
+}
+
+gboolean handle_spi_set_mode(
+               PeripheralIoGdbusSpi *spi,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               guchar mode,
+               gpointer user_data)
+{
+       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
+       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+       pb_data_h spi_handle = GUINT_TO_POINTER(handle);
+
+       if (peripheral_bus_handle_is_valid(invocation, spi_handle, pb_data->spi_list) != 0) {
+               _E("spi handle is not valid");
+               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
+       } else
+               ret = peripheral_bus_spi_set_mode(spi_handle, mode);
+
+       peripheral_io_gdbus_spi_complete_set_mode(spi, invocation, ret);
+
+       return true;
+}
+
+gboolean handle_spi_get_mode(
+               PeripheralIoGdbusSpi *spi,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gpointer user_data)
+{
+       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
+       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+       pb_data_h spi_handle = GUINT_TO_POINTER(handle);
+       uint8_t mode = 0;
+
+       if (peripheral_bus_handle_is_valid(invocation, spi_handle, pb_data->spi_list) != 0) {
+               _E("spi handle is not valid");
+               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
+       } else
+               ret = peripheral_bus_spi_get_mode(spi_handle, &mode);
+
+       peripheral_io_gdbus_spi_complete_get_mode(spi, invocation, mode, ret);
+
+       return true;
+}
+
+gboolean handle_spi_set_lsb_first(
+               PeripheralIoGdbusSpi *spi,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gboolean lsb,
+               gpointer user_data)
+{
+       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
+       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+       pb_data_h spi_handle = GUINT_TO_POINTER(handle);
+
+       if (peripheral_bus_handle_is_valid(invocation, spi_handle, pb_data->spi_list) != 0) {
+               _E("spi handle is not valid");
+               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
+       } else
+               ret = peripheral_bus_spi_set_lsb_first(spi_handle, lsb);
+
+       peripheral_io_gdbus_spi_complete_set_lsb_first(spi, invocation, ret);
+
+       return true;
+}
+
+gboolean handle_spi_get_lsb_first(
+               PeripheralIoGdbusSpi *spi,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gpointer user_data)
+{
+       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
+       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+       pb_data_h spi_handle = GUINT_TO_POINTER(handle);
+       gboolean lsb = 0;
+
+       if (peripheral_bus_handle_is_valid(invocation, spi_handle, pb_data->spi_list) != 0) {
+               _E("spi handle is not valid");
+               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
+       } else
+               ret = peripheral_bus_spi_get_lsb_first(spi_handle, &lsb);
+
+       peripheral_io_gdbus_spi_complete_get_lsb_first(spi, invocation, lsb, ret);
+
+       return true;
+}
+
+gboolean handle_spi_set_bits(
+               PeripheralIoGdbusSpi *spi,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               guchar bits,
+               gpointer user_data)
+{
+       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
+       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+       pb_data_h spi_handle = GUINT_TO_POINTER(handle);
+
+       if (peripheral_bus_handle_is_valid(invocation, spi_handle, pb_data->spi_list) != 0) {
+               _E("spi handle is not valid");
+               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
+       } else
+               ret = peripheral_bus_spi_set_bits(spi_handle, bits);
+
+       peripheral_io_gdbus_spi_complete_set_bits(spi, invocation, ret);
+
+       return true;
+}
+
+gboolean handle_spi_get_bits(
+               PeripheralIoGdbusSpi *spi,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gpointer user_data)
+{
+       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
+       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+       pb_data_h spi_handle = GUINT_TO_POINTER(handle);
+       uint8_t bits = 0;
+
+       if (peripheral_bus_handle_is_valid(invocation, spi_handle, pb_data->spi_list) != 0) {
+               _E("spi handle is not valid");
+               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
+       } else
+               ret = peripheral_bus_spi_get_bits(spi_handle, &bits);
+
+       peripheral_io_gdbus_spi_complete_get_bits(spi, invocation, bits, ret);
+
+       return true;
+}
+
+gboolean handle_spi_set_frequency(
+               PeripheralIoGdbusSpi *spi,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               guint freq,
+               gpointer user_data)
+{
+       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
+       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+       pb_data_h spi_handle = GUINT_TO_POINTER(handle);
+
+       if (peripheral_bus_handle_is_valid(invocation, spi_handle, pb_data->spi_list) != 0) {
+               _E("spi handle is not valid");
+               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
+       } else
+               ret = peripheral_bus_spi_set_frequency(spi_handle, freq);
+
+       peripheral_io_gdbus_spi_complete_set_frequency(spi, invocation, ret);
+
+       return true;
+}
+
+gboolean handle_spi_get_frequency(
+               PeripheralIoGdbusSpi *spi,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gpointer user_data)
+{
+       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
+       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+       pb_data_h spi_handle = GUINT_TO_POINTER(handle);
+       unsigned int freq = 0;
+
+       if (peripheral_bus_handle_is_valid(invocation, spi_handle, pb_data->spi_list) != 0) {
+               _E("spi handle is not valid");
+               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
+       } else
+               ret = peripheral_bus_spi_get_frequency(spi_handle, &freq);
+
+       peripheral_io_gdbus_spi_complete_get_frequency(spi, invocation, freq, ret);
+
+       return true;
+}
+
+gboolean handle_spi_read(
+               PeripheralIoGdbusSpi *spi,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gint length,
+               gpointer user_data)
+{
+       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
+       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+       pb_data_h spi_handle = GUINT_TO_POINTER(handle);
+       GVariant *data_array = NULL;
+       uint8_t err_buf[2] = {0, };
+
+       if (peripheral_bus_handle_is_valid(invocation, spi_handle, pb_data->spi_list) != 0) {
+               _E("spi handle is not valid");
+               data_array = peripheral_bus_build_variant_ay(err_buf, sizeof(err_buf));
+               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
+       } else
+               ret = peripheral_bus_spi_read(spi_handle, &data_array, length);
+
+       peripheral_io_gdbus_spi_complete_read(spi, invocation, data_array, ret);
+
+       return true;
+}
+
+gboolean handle_spi_write(
+               PeripheralIoGdbusSpi *spi,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gint length,
+               GVariant *data_array,
+               gpointer user_data)
+{
+       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
+       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+       pb_data_h spi_handle = GUINT_TO_POINTER(handle);
+
+       if (peripheral_bus_handle_is_valid(invocation, spi_handle, pb_data->spi_list) != 0) {
+               _E("spi handle is not valid");
+               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
+       } else
+               ret = peripheral_bus_spi_write(spi_handle, data_array, length);
+
+       peripheral_io_gdbus_spi_complete_write(spi, invocation, ret);
+
+       return true;
+}
+
+gboolean handle_spi_read_write(
+               PeripheralIoGdbusSpi *spi,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gint length,
+               GVariant *tx_data_array,
+               gpointer user_data)
+{
+       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
+       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+       pb_data_h spi_handle = GUINT_TO_POINTER(handle);
+       GVariant *rx_data_array = NULL;
+       uint8_t err_buf[2] = {0, };
+
+       if (peripheral_bus_handle_is_valid(invocation, spi_handle, pb_data->spi_list) != 0) {
+               _E("spi handle is not valid");
+               rx_data_array = peripheral_bus_build_variant_ay(err_buf, sizeof(err_buf));
+               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
+       } else
+               ret = peripheral_bus_spi_read_write(spi_handle, tx_data_array, &rx_data_array, length);
+
+       peripheral_io_gdbus_spi_complete_read_write(spi, invocation, rx_data_array, ret);
+
+       return true;
+}
diff --git a/src/daemon/peripheral_bus_gdbus_uart.c b/src/daemon/peripheral_bus_gdbus_uart.c
new file mode 100644 (file)
index 0000000..136fb45
--- /dev/null
@@ -0,0 +1,232 @@
+/*
+ * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <peripheral_io.h>
+
+#include "peripheral_io_gdbus.h"
+#include "peripheral_bus.h"
+#include "peripheral_bus_uart.h"
+#include "peripheral_common.h"
+#include "peripheral_bus_util.h"
+#include "peripheral_bus_gdbus_uart.h"
+
+static void __uart_on_name_vanished(GDBusConnection *connection,
+               const gchar     *name,
+               gpointer         user_data)
+{
+       pb_data_h uart_handle = (pb_data_h)user_data;
+       _D("appid [%s] vanished ", name);
+
+       g_bus_unwatch_name(uart_handle->watch_id);
+       peripheral_bus_uart_close(uart_handle);
+}
+
+gboolean handle_uart_open(
+               PeripheralIoGdbusUart *uart,
+               GDBusMethodInvocation *invocation,
+               gint port,
+               gpointer user_data)
+{
+       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
+       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+       pb_data_h uart_handle;
+
+       if ((ret = peripheral_bus_uart_open(port, &uart_handle, user_data)) < PERIPHERAL_ERROR_NONE)
+               goto out;
+
+       if (peripheral_bus_get_client_info(invocation, pb_data, &uart_handle->client_info) < 0) {
+               peripheral_bus_uart_close(uart_handle);
+               ret = PERIPHERAL_ERROR_UNKNOWN;
+               goto out;
+       }
+
+       uart_handle->watch_id = g_bus_watch_name(G_BUS_TYPE_SYSTEM ,
+                       uart_handle->client_info.id,
+                       G_BUS_NAME_WATCHER_FLAGS_NONE ,
+                       NULL,
+                       __uart_on_name_vanished,
+                       uart_handle,
+                       NULL);
+       _D("port : %d, id = %s", port, uart_handle->client_info.id);
+
+out:
+       peripheral_io_gdbus_uart_complete_open(uart, invocation, GPOINTER_TO_UINT(uart_handle), ret);
+
+       return true;
+}
+
+gboolean handle_uart_close(
+               PeripheralIoGdbusUart *uart,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gpointer user_data)
+{
+       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
+       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+       pb_data_h uart_handle = GUINT_TO_POINTER(handle);
+
+       if (peripheral_bus_handle_is_valid(invocation, uart_handle, pb_data->uart_list) != 0) {
+               _E("uart handle is not valid");
+               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
+       } else {
+               g_bus_unwatch_name(uart_handle->watch_id);
+               ret = peripheral_bus_uart_close(uart_handle);
+       }
+
+       peripheral_io_gdbus_uart_complete_close(uart, invocation, ret);
+
+       return true;
+}
+
+gboolean handle_uart_flush(
+               PeripheralIoGdbusUart *uart,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gpointer user_data)
+{
+       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
+       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+       pb_data_h uart_handle = GUINT_TO_POINTER(handle);
+
+       if (peripheral_bus_handle_is_valid(invocation, uart_handle, pb_data->uart_list) != 0) {
+               _E("uart handle is not valid");
+               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
+       } else
+               ret = peripheral_bus_uart_flush(uart_handle);
+
+       peripheral_io_gdbus_uart_complete_flush(uart, invocation, ret);
+
+       return true;
+}
+
+gboolean handle_uart_set_baudrate(
+               PeripheralIoGdbusUart *uart,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               guint baudrate,
+               gpointer user_data)
+{
+       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
+       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+       pb_data_h uart_handle = GUINT_TO_POINTER(handle);
+
+       if (peripheral_bus_handle_is_valid(invocation, uart_handle, pb_data->uart_list) != 0) {
+               _E("uart handle is not valid");
+               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
+       } else
+               ret = peripheral_bus_uart_set_baudrate(uart_handle, baudrate);
+
+       peripheral_io_gdbus_uart_complete_set_baudrate(uart, invocation, ret);
+
+       return true;
+}
+
+gboolean handle_uart_set_mode(
+               PeripheralIoGdbusUart *uart,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               guint byte_size,
+               guint parity,
+               guint stop_bits,
+               gpointer user_data)
+{
+       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
+       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+       pb_data_h uart_handle = GUINT_TO_POINTER(handle);
+
+       if (peripheral_bus_handle_is_valid(invocation, uart_handle, pb_data->uart_list) != 0) {
+               _E("uart handle is not valid");
+               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
+       } else
+               ret = peripheral_bus_uart_set_mode(uart_handle, byte_size, parity, stop_bits);
+
+       peripheral_io_gdbus_uart_complete_set_mode(uart, invocation, ret);
+
+       return true;
+}
+
+gboolean handle_uart_set_flowcontrol(
+               PeripheralIoGdbusUart *uart,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gboolean xonxoff,
+               gboolean rtscts,
+               gpointer user_data)
+{
+       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
+       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+       pb_data_h uart_handle = GUINT_TO_POINTER(handle);
+
+       if (peripheral_bus_handle_is_valid(invocation, uart_handle, pb_data->uart_list) != 0) {
+               _E("uart handle is not valid");
+               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
+       } else
+               ret = peripheral_bus_uart_set_flowcontrol(uart_handle, xonxoff, rtscts);
+
+       peripheral_io_gdbus_uart_complete_set_flowcontrol(uart, invocation, ret);
+
+       return true;
+}
+
+gboolean handle_uart_read(
+               PeripheralIoGdbusUart *uart,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gint length,
+               gpointer user_data)
+{
+       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
+       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+       pb_data_h uart_handle = GUINT_TO_POINTER(handle);
+       uint8_t err_buf[2] = {0, };
+       GVariant *data_array = NULL;
+
+       if (peripheral_bus_handle_is_valid(invocation, uart_handle, pb_data->uart_list) != 0) {
+               _E("uart handle is not valid");
+               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
+       } else
+               ret = peripheral_bus_uart_read(uart_handle, &data_array, length);
+
+       if (!data_array)
+               data_array = peripheral_bus_build_variant_ay(err_buf, sizeof(err_buf));
+
+       peripheral_io_gdbus_uart_complete_read(uart, invocation, data_array, ret);
+
+       return true;
+}
+
+gboolean handle_uart_write(
+               PeripheralIoGdbusUart *uart,
+               GDBusMethodInvocation *invocation,
+               gint handle,
+               gint length,
+               GVariant *data_array,
+               gpointer user_data)
+{
+       peripheral_bus_s *pb_data = (peripheral_bus_s*)user_data;
+       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+       pb_data_h uart_handle = GUINT_TO_POINTER(handle);
+
+       if (peripheral_bus_handle_is_valid(invocation, uart_handle, pb_data->uart_list) != 0) {
+               _E("uart handle is not valid");
+               ret = PERIPHERAL_ERROR_INVALID_PARAMETER;
+       } else
+               ret = peripheral_bus_uart_write(uart_handle, data_array, length);
+
+       peripheral_io_gdbus_uart_complete_write(uart, invocation, ret);
+
+       return true;
+}
index 2eb60c2..c6854ce 100644 (file)
@@ -25,6 +25,7 @@
 
 #include "gpio.h"
 #include "peripheral_bus.h"
+#include "peripheral_bus_gdbus_gpio.h"
 #include "peripheral_common.h"
 #include "peripheral_bus_util.h"
 
index 92cb445..aaad11d 100644 (file)
@@ -97,3 +97,64 @@ int peripheral_bus_data_free(pb_data_h handle)
 
        return 0;
 }
+
+int peripheral_bus_get_client_info(
+               GDBusMethodInvocation *invocation,
+               peripheral_bus_s *pb_data,
+               pb_client_info_s *client_info)
+{
+       guint pid = 0;
+       GError *error = NULL;
+       GVariant *_ret;
+       const gchar *id;
+
+       id = g_dbus_method_invocation_get_sender(invocation);
+       _ret = g_dbus_connection_call_sync(pb_data->connection,
+               "org.freedesktop.DBus",
+               "/org/freedesktop/DBus",
+               "org.freedesktop.DBus",
+               "GetConnectionUnixProcessID",
+               g_variant_new("(s)", id),
+               NULL,
+               G_DBUS_CALL_FLAGS_NONE,
+               -1,
+               NULL,
+               &error);
+
+       if (_ret == NULL) {
+               _E("Failed to get client pid, %s", error->message);
+               g_error_free(error);
+
+               return -1;
+       }
+
+       g_variant_get(_ret, "(u)", &pid);
+       g_variant_unref(_ret);
+
+       client_info->pid = (pid_t)pid;
+       client_info->pgid = getpgid(pid);
+       client_info->id = strdup(id);
+
+       return 0;
+}
+
+int peripheral_bus_handle_is_valid(
+               GDBusMethodInvocation *invocation,
+               pb_data_h handle,
+               GList *list)
+{
+       const gchar *id;
+
+       if (!g_list_find(list, handle)) {
+               _E("Cannot find handle");
+               return -1;
+       }
+
+       id = g_dbus_method_invocation_get_sender(invocation);
+       if (strcmp(handle->client_info.id, id)) {
+               _E("Invalid access, handle id : %s, current id : %s", handle->client_info.id, id);
+               return -1;
+       }
+
+       return 0;
+}