Refactor gdbus interface codes 99/128299/2
authorHyeongsik Min <hyeongsik.min@samsung.com>
Mon, 8 May 2017 11:15:55 +0000 (20:15 +0900)
committerHyeongsik Min <hyeongsik.min@samsung.com>
Tue, 9 May 2017 02:45:02 +0000 (11:45 +0900)
Split peripheral_dbus.c into separate files per low-level interface.

Change-Id: Ifdc6bba7d3d4628693e041882ee88b39c763629f
Signed-off-by: Hyeongsik Min <hyeongsik.min@samsung.com>
14 files changed:
CMakeLists.txt
include/peripheral_common.h
include/peripheral_dbus.h [deleted file]
include/peripheral_gdbus.h [new file with mode: 0644]
include/peripheral_gdbus_gpio.h [new file with mode: 0644]
include/peripheral_gdbus_i2c.h [new file with mode: 0644]
include/peripheral_gdbus_pwm.h [new file with mode: 0644]
src/peripheral_dbus.c [deleted file]
src/peripheral_gdbus_gpio.c [new file with mode: 0644]
src/peripheral_gdbus_i2c.c [new file with mode: 0644]
src/peripheral_gdbus_pwm.c [new file with mode: 0644]
src/peripheral_gpio.c
src/peripheral_i2c.c
src/peripheral_pwm.c

index 45ec9ac3bbfb8becbe5d3223622f5574d87cc3a5..0bbc0bd3aa2f9c3d6a65e684fbd2cdfb417b1204 100644 (file)
@@ -42,13 +42,15 @@ SET(CMAKE_C_FLAGS_DEBUG "-O0 -g")
 
 SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--rpath=%{_libdir}")
 
-SET(SOURCES src/peripheral_adc.c
-                       src/peripheral_gpio.c
+SET(SOURCES src/peripheral_gpio.c
+                       src/peripheral_i2c.c
                        src/peripheral_pwm.c
+                       src/peripheral_adc.c
                        src/peripheral_uart.c
-                       src/peripheral_dbus.c
+                       src/peripheral_gdbus_gpio.c
+                       src/peripheral_gdbus_i2c.c
+                       src/peripheral_gdbus_pwm.c
                        src/peripheral_io_gdbus.c
-                       src/peripheral_i2c.c
                        src/peripheral_spi.c)
 
 ADD_LIBRARY(${fw_name} SHARED ${SOURCES})
index 2d2f960488886dd7726ecf276f0eca7928728228..19352be321290ddc90583bba59e63c74e2ec963f 100644 (file)
                if (expr) { \
                        _E("(%s)", #expr); \
                        return; \
-               }\
-       } while(0)
+               } \
+       } while (0)
 #define RETV_IF(expr, val) \
        do {\
                if (expr) { \
                        _E("(%s)", #expr); \
                        return (val); \
                } \
-       } while(0)
+       } while (0)
 #define RETM_IF(expr, fmt, arg...) \
        do {\
                if (expr) { \
                        _E(fmt, ##arg); \
                        return; \
-               }\
-       } while(0)
+               } \
+       } while (0)
 #define RETVM_IF(expr, val, fmt, arg...) \
        do {\
                if (expr) { \
                        _E(fmt, ##arg); \
                        return (val); \
                } \
-       } while(0)
+       } while (0)
 
 #endif /* __PERIPHERAL_COMMON_H__ */
diff --git a/include/peripheral_dbus.h b/include/peripheral_dbus.h
deleted file mode 100644 (file)
index e1002fa..0000000
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * 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_DBUS_H_
-#define __PERIPHERAL_DBUS_H_
-
-#include <gio/gio.h>
-
-#define PERIPHERAL_DBUS_INTERFACE      "org.tizen.peripheral_io"
-#define PERIPHERAL_DBUS_PATH           "/Org/Tizen/Peripheral_io"
-#define PERIPHERAL_DBUS_GPIO_PATH      "/Org/Tizen/Peripheral_io/Gpio"
-#define PERIPHERAL_DBUS_I2C_PATH       "/Org/Tizen/Peripheral_io/I2c"
-#define PERIPHERAL_DBUS_PWM_PATH       "/Org/Tizen/Peripheral_io/Pwm"
-#define PERIPHERAL_DBUS_NAME           "org.tizen.peripheral_io"
-
-#define PERIPHERAL_METHOD_GPIO "gpio"
-#define PERIPHERAL_METHOD_I2C  "i2c"
-#define PERIPHERAL_METHOD_PWM  "pwm"
-#define PERIPHERAL_METHOD_SPI  "spi"
-#define PERIPHERAL_METHOD_UART "uart"
-
-void gpio_proxy_init(void);
-void i2c_proxy_init(void);
-void pwm_proxy_init(void);
-
-void gpio_proxy_deinit();
-void i2c_proxy_deinit();
-void pwm_proxy_deinit();
-
-int peripheral_dbus_gpio_open(peripheral_gpio_h gpio);
-int peripheral_dbus_gpio_close(peripheral_gpio_h gpio);
-int peripheral_dbus_gpio_get_direction(peripheral_gpio_h gpio, peripheral_gpio_direction_e *direction);
-int peripheral_dbus_gpio_set_direction(peripheral_gpio_h gpio, peripheral_gpio_direction_e direction);
-int peripheral_dbus_gpio_read(peripheral_gpio_h gpio, int *value);
-int peripheral_dbus_gpio_write(peripheral_gpio_h gpio, int value);
-int peripheral_dbus_gpio_get_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e *edge);
-int peripheral_dbus_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e edge);
-int peripheral_dbus_gpio_register_cb(peripheral_gpio_h gpio, gpio_isr_cb callback, void *user_data);
-int peripheral_dbus_gpio_unregister_cb(peripheral_gpio_h gpio);
-
-int peripheral_dbus_i2c_open(peripheral_i2c_h i2c, int bus, int address);
-int peripheral_dbus_i2c_close(peripheral_i2c_h i2c);
-int peripheral_dbus_i2c_read(peripheral_i2c_h i2c, uint8_t *data, int length);
-int peripheral_dbus_i2c_write(peripheral_i2c_h i2c, uint8_t *data, int length);
-
-int peripheral_dbus_pwm_open(peripheral_pwm_context_h dev, int device, int channel);
-int peripheral_dbus_pwm_close(peripheral_pwm_context_h dev);
-int peripheral_dbus_pwm_get_duty_cycle(peripheral_pwm_context_h dev, int *duty_cycle);
-int peripheral_dbus_pwm_set_duty_cycle(peripheral_pwm_context_h dev, int duty_cycle);
-int peripheral_dbus_pwm_get_period(peripheral_pwm_context_h dev, int *period);
-int peripheral_dbus_pwm_set_period(peripheral_pwm_context_h dev, int period);
-int peripheral_dbus_pwm_set_enable(peripheral_pwm_context_h dev, peripheral_pwm_state_e enable);
-
-#endif /* __PERIPHERAL_DBUS_H_ */
diff --git a/include/peripheral_gdbus.h b/include/peripheral_gdbus.h
new file mode 100644 (file)
index 0000000..2195320
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 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_GDBUS_H__
+#define __PERIPHERAL_GDBUS_H__
+
+#include <gio/gio.h>
+
+#define PERIPHERAL_GDBUS_INTERFACE     "org.tizen.peripheral_io"
+#define PERIPHERAL_GDBUS_GPIO_PATH     "/Org/Tizen/Peripheral_io/Gpio"
+#define PERIPHERAL_GDBUS_I2C_PATH      "/Org/Tizen/Peripheral_io/I2c"
+#define PERIPHERAL_GDBUS_PWM_PATH      "/Org/Tizen/Peripheral_io/Pwm"
+#define PERIPHERAL_GDBUS_NAME          "org.tizen.peripheral_io"
+
+#endif /* __PERIPHERAL_GDBUS_H__ */
diff --git a/include/peripheral_gdbus_gpio.h b/include/peripheral_gdbus_gpio.h
new file mode 100644 (file)
index 0000000..0d23b91
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * 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_GDBUS_GPIO_H__
+#define __PERIPHERAL_GDBUS_GPIO_H__
+
+void gpio_proxy_init(void);
+void gpio_proxy_deinit(void);
+
+int peripheral_gdbus_gpio_open(peripheral_gpio_h gpio);
+int peripheral_gdbus_gpio_close(peripheral_gpio_h gpio);
+int peripheral_gdbus_gpio_get_direction(peripheral_gpio_h gpio, peripheral_gpio_direction_e *direction);
+int peripheral_gdbus_gpio_set_direction(peripheral_gpio_h gpio, peripheral_gpio_direction_e direction);
+int peripheral_gdbus_gpio_read(peripheral_gpio_h gpio, int *value);
+int peripheral_gdbus_gpio_write(peripheral_gpio_h gpio, int value);
+int peripheral_gdbus_gpio_get_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e *edge);
+int peripheral_gdbus_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e edge);
+int peripheral_gdbus_gpio_register_cb(peripheral_gpio_h gpio, gpio_isr_cb callback, void *user_data);
+int peripheral_gdbus_gpio_unregister_cb(peripheral_gpio_h gpio);
+
+#endif /* __PERIPHERAL_GDBUS_GPIO_H__ */
diff --git a/include/peripheral_gdbus_i2c.h b/include/peripheral_gdbus_i2c.h
new file mode 100644 (file)
index 0000000..c36cb04
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * 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_GDBUS_I2C_H__
+#define __PERIPHERAL_GDBUS_I2C_H__
+
+void i2c_proxy_init(void);
+void i2c_proxy_deinit(void);
+
+int peripheral_gdbus_i2c_open(peripheral_i2c_h i2c, int bus, int address);
+int peripheral_gdbus_i2c_close(peripheral_i2c_h i2c);
+int peripheral_gdbus_i2c_read(peripheral_i2c_h i2c, uint8_t *data, int length);
+int peripheral_gdbus_i2c_write(peripheral_i2c_h i2c, uint8_t *data, int length);
+
+#endif /* __PERIPHERAL_GDBUS_I2C_H__ */
diff --git a/include/peripheral_gdbus_pwm.h b/include/peripheral_gdbus_pwm.h
new file mode 100644 (file)
index 0000000..2d28514
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * 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_GDBUS_PWM_H__
+#define __PERIPHERAL_GDBUS_PWM_H__
+
+void pwm_proxy_init(void);
+void pwm_proxy_deinit(void);
+
+int peripheral_gdbus_pwm_open(peripheral_pwm_context_h dev, int device, int channel);
+int peripheral_gdbus_pwm_close(peripheral_pwm_context_h dev);
+int peripheral_gdbus_pwm_get_duty_cycle(peripheral_pwm_context_h dev, int *duty_cycle);
+int peripheral_gdbus_pwm_set_duty_cycle(peripheral_pwm_context_h dev, int duty_cycle);
+int peripheral_gdbus_pwm_get_period(peripheral_pwm_context_h dev, int *period);
+int peripheral_gdbus_pwm_set_period(peripheral_pwm_context_h dev, int period);
+int peripheral_gdbus_pwm_set_enable(peripheral_pwm_context_h dev, peripheral_pwm_state_e enable);
+
+#endif /* __PERIPHERAL_GDBUS_PWM_H__ */
diff --git a/src/peripheral_dbus.c b/src/peripheral_dbus.c
deleted file mode 100644 (file)
index b9af3d1..0000000
+++ /dev/null
@@ -1,628 +0,0 @@
-/*
- * 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 <stdio.h>
-#include <stdlib.h>
-#include <gio/gio.h>
-
-#include "peripheral_io.h"
-#include "peripheral_dbus.h"
-#include "peripheral_common.h"
-#include "peripheral_internal.h"
-#include "peripheral_io_gdbus.h"
-
-extern int peripheral_gpio_isr_callback(int pin);
-void handle_gpio_changed(PeripheralIoGdbusGpio *gpio, gint pin, gint state, gpointer user_data);
-
-PeripheralIoGdbusGpio *gpio_proxy = NULL;
-PeripheralIoGdbusI2c *i2c_proxy = NULL;
-PeripheralIoGdbusPwm *pwm_proxy = NULL;
-
-void gpio_proxy_init(void)
-{
-       GError *error = NULL;
-
-       if (gpio_proxy != NULL)
-               return;
-
-       gpio_proxy = peripheral_io_gdbus_gpio_proxy_new_for_bus_sync(
-               G_BUS_TYPE_SYSTEM,
-               G_DBUS_PROXY_FLAGS_NONE,
-               PERIPHERAL_DBUS_NAME,
-               PERIPHERAL_DBUS_GPIO_PATH,
-               NULL,
-               &error);
-       if (gpio_proxy == NULL) {
-               _E("Can not create gpio proxy : %s", error->message);
-               g_error_free(error);
-               return;
-       }
-
-       g_signal_connect(gpio_proxy,
-                       "gpio-changed",
-                       G_CALLBACK(handle_gpio_changed),
-                       NULL);
-}
-
-void i2c_proxy_init(void)
-{
-       GError *error = NULL;
-
-       if (i2c_proxy != NULL)
-               return;
-
-       i2c_proxy = peripheral_io_gdbus_i2c_proxy_new_for_bus_sync(
-               G_BUS_TYPE_SYSTEM,
-               G_DBUS_PROXY_FLAGS_NONE,
-               PERIPHERAL_DBUS_NAME,
-               PERIPHERAL_DBUS_I2C_PATH,
-               NULL,
-               &error);
-}
-
-void pwm_proxy_init(void)
-{
-       GError *error = NULL;
-
-       if (pwm_proxy != NULL)
-               return;
-
-       pwm_proxy = peripheral_io_gdbus_pwm_proxy_new_for_bus_sync(
-               G_BUS_TYPE_SYSTEM,
-               G_DBUS_PROXY_FLAGS_NONE,
-               PERIPHERAL_DBUS_NAME,
-               PERIPHERAL_DBUS_PWM_PATH,
-               NULL,
-               &error);
-}
-
-void gpio_proxy_deinit()
-{
-       if (gpio_proxy) {
-               g_object_unref(gpio_proxy);
-               gpio_proxy = NULL;
-       }
-}
-
-void i2c_proxy_deinit()
-{
-       if (i2c_proxy) {
-               g_object_unref(i2c_proxy);
-               i2c_proxy = NULL;
-       }
-}
-
-void pwm_proxy_deinit()
-{
-       if (pwm_proxy) {
-               g_object_unref(pwm_proxy);
-               pwm_proxy = NULL;
-       }
-}
-
-void handle_gpio_changed(
-               PeripheralIoGdbusGpio *gpio,
-               gint pin,
-               gint state,
-               gpointer user_data)
-{
-       if (!gpio)
-               return;
-
-       _D("gpio=%d state=%d", pin, state);
-
-       peripheral_gpio_isr_callback(pin);
-}
-
-int peripheral_dbus_gpio_open(peripheral_gpio_h gpio)
-{
-       GError *error = NULL;
-       gint32 ret = PERIPHERAL_ERROR_NONE;
-
-       if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
-
-       if (peripheral_io_gdbus_gpio_call_open_sync(
-                       gpio_proxy,
-                       gpio->pin,
-                       (gint*)&gpio->edge,
-                       (gint*)&gpio->direction,
-                       &ret,
-                       NULL,
-                       &error) == FALSE) {
-               _E("Error in %s() : %s\n", __func__, error->message);
-               g_error_free(error);
-               return PERIPHERAL_ERROR_UNKNOWN;
-       }
-
-       return ret;
-}
-
-int peripheral_dbus_gpio_close(peripheral_gpio_h gpio)
-{
-       GError *error = NULL;
-       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-
-       if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
-
-       if (peripheral_io_gdbus_gpio_call_close_sync(
-                       gpio_proxy,
-                       gpio->pin,
-                       &ret,
-                       NULL,
-                       &error) == FALSE) {
-               _E("Error in %s() : %s\n", __func__, error->message);
-               g_error_free(error);
-               return PERIPHERAL_ERROR_UNKNOWN;
-       }
-
-       return ret;
-}
-
-int peripheral_dbus_gpio_get_direction(peripheral_gpio_h gpio, peripheral_gpio_direction_e *direction)
-{
-       GError *error = NULL;
-       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-
-       if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
-
-       if (peripheral_io_gdbus_gpio_call_get_direction_sync(
-                       gpio_proxy,
-                       gpio->pin,
-                       (gint*)direction,
-                       &ret,
-                       NULL,
-                       &error) == FALSE) {
-               _E("Error in %s() : %s\n", __func__, error->message);
-               g_error_free(error);
-               return PERIPHERAL_ERROR_UNKNOWN;
-       }
-       gpio->direction = *direction;
-
-       return ret;
-}
-
-int peripheral_dbus_gpio_set_direction(peripheral_gpio_h gpio, peripheral_gpio_direction_e direction)
-{
-       GError *error = NULL;
-       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-
-       if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
-
-       if (peripheral_io_gdbus_gpio_call_set_direction_sync(
-                       gpio_proxy,
-                       gpio->pin,
-                       direction,
-                       &ret,
-                       NULL,
-                       &error) == FALSE) {
-               _E("Error in %s() : %s\n", __func__, error->message);
-               g_error_free(error);
-               return PERIPHERAL_ERROR_UNKNOWN;
-       }
-       gpio->direction = direction;
-
-       return ret;
-}
-
-int peripheral_dbus_gpio_read(peripheral_gpio_h gpio, int *value)
-{
-       GError *error = NULL;
-       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-
-       if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
-
-       if (peripheral_io_gdbus_gpio_call_read_sync(
-                       gpio_proxy,
-                       gpio->pin,
-                       value,
-                       &ret,
-                       NULL,
-                       &error) == FALSE) {
-               _E("Error in %s() : %s\n", __func__, error->message);
-               g_error_free(error);
-               return PERIPHERAL_ERROR_UNKNOWN;
-       }
-
-       return ret;
-}
-
-int peripheral_dbus_gpio_write(peripheral_gpio_h gpio, int value)
-{
-       GError *error = NULL;
-       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-
-       if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
-
-       if (peripheral_io_gdbus_gpio_call_write_sync(
-                       gpio_proxy,
-                       gpio->pin,
-                       value,
-                       &ret,
-                       NULL,
-                       &error) == FALSE) {
-               _E("Error in %s() : %s\n", __func__, error->message);
-               g_error_free(error);
-               return PERIPHERAL_ERROR_UNKNOWN;
-       }
-
-       return ret;
-}
-
-int peripheral_dbus_gpio_get_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e *edge)
-{
-       GError *error = NULL;
-       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-
-       if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
-
-       if (peripheral_io_gdbus_gpio_call_get_edge_mode_sync(
-                       gpio_proxy,
-                       gpio->pin,
-                       (int*)edge,
-                       &ret,
-                       NULL,
-                       &error) == FALSE) {
-               _E("Error in %s() : %s\n", __func__, error->message);
-               g_error_free(error);
-               return PERIPHERAL_ERROR_UNKNOWN;
-       }
-       gpio->edge = *edge;
-
-       return ret;
-}
-
-int peripheral_dbus_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e edge)
-{
-       GError *error = NULL;
-       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-
-       if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
-
-       if (peripheral_io_gdbus_gpio_call_set_edge_mode_sync(
-                       gpio_proxy,
-                       gpio->pin,
-                       edge,
-                       &ret,
-                       NULL,
-                       &error) == FALSE) {
-               _E("Error in %s() : %s\n", __func__, error->message);
-               g_error_free(error);
-               return PERIPHERAL_ERROR_UNKNOWN;
-       }
-       gpio->edge = edge;
-
-       return ret;
-}
-
-int peripheral_dbus_gpio_register_cb(peripheral_gpio_h gpio, gpio_isr_cb callback, void *user_data)
-{
-       GError *error = NULL;
-       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-
-       if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
-
-       if (peripheral_io_gdbus_gpio_call_register_irq_sync(
-                       gpio_proxy,
-                       gpio->pin,
-                       &ret,
-                       NULL,
-                       &error) == FALSE) {
-               _E("Error in %s() : %s\n", __func__, error->message);
-               g_error_free(error);
-               return PERIPHERAL_ERROR_UNKNOWN;
-       }
-
-       return ret;
-}
-
-int peripheral_dbus_gpio_unregister_cb(peripheral_gpio_h gpio)
-{
-       GError *error = NULL;
-       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-
-       if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
-
-       if (peripheral_io_gdbus_gpio_call_unregister_irq_sync(
-                       gpio_proxy,
-                       gpio->pin,
-                       &ret,
-                       NULL,
-                       &error) == FALSE) {
-               _E("Error in %s() : %s\n", __func__, error->message);
-               g_error_free(error);
-               return PERIPHERAL_ERROR_UNKNOWN;
-       }
-
-       return ret;
-}
-
-int peripheral_dbus_i2c_open(peripheral_i2c_h i2c, int bus, int address)
-{
-       GError *error = NULL;
-       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-
-       if (i2c_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
-
-       if (peripheral_io_gdbus_i2c_call_open_sync(
-                       i2c_proxy,
-                       bus,
-                       address,
-                       &i2c->handle,
-                       &ret,
-                       NULL,
-                       &error) == FALSE) {
-               _E("Error in %s() : %s\n", __func__, error->message);
-               g_error_free(error);
-               return PERIPHERAL_ERROR_UNKNOWN;
-       }
-
-       return ret;
-}
-
-int peripheral_dbus_i2c_close(peripheral_i2c_h i2c)
-{
-       GError *error = NULL;
-       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-
-       if (i2c_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
-
-       if (peripheral_io_gdbus_i2c_call_close_sync(
-                       i2c_proxy,
-                       i2c->handle,
-                       &ret,
-                       NULL,
-                       &error) == FALSE) {
-               _E("Error in %s() : %s\n", __func__, error->message);
-               g_error_free(error);
-               return PERIPHERAL_ERROR_UNKNOWN;
-       }
-
-       return ret;
-}
-
-int peripheral_dbus_i2c_read(peripheral_i2c_h i2c, uint8_t *data, int length)
-{
-       GError *error = NULL;
-       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-       GVariant *data_array;
-       GVariantIter *iter;
-       guint8 str;
-       int i = 0;
-
-       if (i2c_proxy == NULL || data == NULL) return PERIPHERAL_ERROR_UNKNOWN;
-
-       if (peripheral_io_gdbus_i2c_call_read_sync(
-                       i2c_proxy,
-                       i2c->handle,
-                       length,
-                       &data_array,
-                       &ret,
-                       NULL,
-                       &error) == FALSE) {
-               _E("Error in %s() : %s\n", __func__, error->message);
-               g_error_free(error);
-               return PERIPHERAL_ERROR_UNKNOWN;
-       }
-
-       g_variant_get(data_array, "a(y)", &iter);
-       while (g_variant_iter_loop(iter, "(y)", &str)) {
-               data[i] = str;
-               if (i++ == length) break;
-       }
-       g_variant_iter_free(iter);
-
-       return ret;
-}
-
-int peripheral_dbus_i2c_write(peripheral_i2c_h i2c, uint8_t *data, int length)
-{
-       GError *error = NULL;
-       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
-       GVariantBuilder *builder;
-       GVariant *g_data;
-       int i = 0;
-
-       if (i2c_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
-
-       builder = g_variant_builder_new(G_VARIANT_TYPE("a(y)"));
-
-       for (i = 0; i < length; i++)
-               g_variant_builder_add(builder, "(y)", data[i]);
-       g_variant_builder_add(builder, "(y)", 0x00);
-
-       g_data = g_variant_new("a(y)", builder);
-       g_variant_builder_unref(builder);
-
-       if (peripheral_io_gdbus_i2c_call_write_sync(
-                       i2c_proxy,
-                       i2c->handle,
-                       length,
-                       g_data,
-                       &ret,
-                       NULL,
-                       &error) == FALSE) {
-               _E("Error in %s() : %s\n", __func__, error->message);
-               g_error_free(error);
-               return PERIPHERAL_ERROR_UNKNOWN;
-       }
-
-       return ret;
-}
-
-int peripheral_dbus_pwm_open(peripheral_pwm_context_h dev, int device, int channel)
-{
-       GError *error = NULL;
-       gint32 ret = PERIPHERAL_ERROR_NONE;
-
-       if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
-
-       /* TODO: Need to reorganize arguments */
-       if (peripheral_io_gdbus_pwm_call_open_sync(
-                       pwm_proxy,
-                       device,
-                       channel,
-                       &ret,
-                       NULL,
-                       &error) == FALSE) {
-               _E("Error in %s() : %s\n", __func__, error->message);
-               g_error_free(error);
-               return PERIPHERAL_ERROR_UNKNOWN;
-       }
-
-       return ret;
-}
-
-int peripheral_dbus_pwm_close(peripheral_pwm_context_h dev)
-{
-       GError *error = NULL;
-       gint32 ret = PERIPHERAL_ERROR_NONE;
-
-       if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
-
-       /* TODO: Need to reorganize arguments */
-       if (peripheral_io_gdbus_pwm_call_close_sync(
-                       pwm_proxy,
-                       dev->device,
-                       dev->channel,
-                       &ret,
-                       NULL,
-                       &error) == FALSE) {
-               _E("Error in %s() : %s\n", __func__, error->message);
-               g_error_free(error);
-               return PERIPHERAL_ERROR_UNKNOWN;
-       }
-
-       return ret;
-}
-
-int peripheral_dbus_pwm_get_duty_cycle(peripheral_pwm_context_h dev, int *duty_cycle)
-{
-       GError *error = NULL;
-       gint32 ret = PERIPHERAL_ERROR_NONE;
-
-       if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
-
-       /* TODO: Need to reorganize arguments */
-       if (peripheral_io_gdbus_pwm_call_get_duty_cycle_sync(
-                       pwm_proxy,
-                       dev->device,
-                       dev->channel,
-                       duty_cycle,
-                       &ret,
-                       NULL,
-                       &error) == FALSE) {
-               _E("Error in %s() : %s\n", __func__, error->message);
-               g_error_free(error);
-               return PERIPHERAL_ERROR_UNKNOWN;
-       }
-
-       return ret;
-}
-int peripheral_dbus_pwm_set_duty_cycle(peripheral_pwm_context_h dev, int duty_cycle)
-{
-       GError *error = NULL;
-       gint32 ret = PERIPHERAL_ERROR_NONE;
-
-       if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
-
-       /* TODO: Need to reorganize arguments */
-       if (peripheral_io_gdbus_pwm_call_set_duty_cycle_sync(
-                       pwm_proxy,
-                       dev->device,
-                       dev->channel,
-                       duty_cycle,
-                       &ret,
-                       NULL,
-                       &error) == FALSE) {
-               _E("Error in %s() : %s\n", __func__, error->message);
-               g_error_free(error);
-               return PERIPHERAL_ERROR_UNKNOWN;
-       }
-
-       return ret;
-}
-
-int peripheral_dbus_pwm_get_period(peripheral_pwm_context_h dev, int *period)
-{
-       GError *error = NULL;
-       gint32 ret = PERIPHERAL_ERROR_NONE;
-
-       if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
-
-       /* TODO: Need to reorganize arguments */
-       if (peripheral_io_gdbus_pwm_call_get_period_sync(
-                       pwm_proxy,
-                       dev->device,
-                       dev->channel,
-                       period,
-                       &ret,
-                       NULL,
-                       &error) == FALSE) {
-               _E("Error in %s() : %s\n", __func__, error->message);
-               g_error_free(error);
-               return PERIPHERAL_ERROR_UNKNOWN;
-       }
-
-       return ret;
-}
-
-int peripheral_dbus_pwm_set_period(peripheral_pwm_context_h dev, int period)
-{
-       GError *error = NULL;
-       gint32 ret = PERIPHERAL_ERROR_NONE;
-
-       if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
-
-       /* TODO: Need to reorganize arguments */
-       if (peripheral_io_gdbus_pwm_call_set_period_sync(
-                       pwm_proxy,
-                       dev->device,
-                       dev->channel,
-                       period,
-                       &ret,
-                       NULL,
-                       &error) == FALSE) {
-               _E("Error in %s() : %s\n", __func__, error->message);
-               g_error_free(error);
-               return PERIPHERAL_ERROR_UNKNOWN;
-       }
-
-       return ret;
-}
-
-int peripheral_dbus_pwm_set_enable(peripheral_pwm_context_h dev, peripheral_pwm_state_e enable)
-{
-       GError *error = NULL;
-       gint32 ret = PERIPHERAL_ERROR_NONE;
-
-       if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
-
-       /* TODO: Need to reorganize arguments */
-       if (peripheral_io_gdbus_pwm_call_set_enable_sync(
-                       pwm_proxy,
-                       dev->device,
-                       dev->channel,
-                       enable,
-                       &ret,
-                       NULL,
-                       &error) == FALSE) {
-               _E("Error in %s() : %s\n", __func__, error->message);
-               g_error_free(error);
-               return PERIPHERAL_ERROR_UNKNOWN;
-       }
-
-       return ret;
-}
diff --git a/src/peripheral_gdbus_gpio.c b/src/peripheral_gdbus_gpio.c
new file mode 100644 (file)
index 0000000..2027f3d
--- /dev/null
@@ -0,0 +1,299 @@
+/*
+ * 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 <stdio.h>
+#include <stdlib.h>
+
+#include "peripheral_io.h"
+#include "peripheral_gdbus.h"
+#include "peripheral_common.h"
+#include "peripheral_internal.h"
+#include "peripheral_io_gdbus.h"
+
+extern int peripheral_gpio_isr_callback(int pin);
+void handle_gpio_changed(PeripheralIoGdbusGpio *gpio, gint pin, gint state, gpointer user_data);
+
+PeripheralIoGdbusGpio *gpio_proxy = NULL;
+
+void gpio_proxy_init(void)
+{
+       GError *error = NULL;
+
+       if (gpio_proxy != NULL)
+               return;
+
+       gpio_proxy = peripheral_io_gdbus_gpio_proxy_new_for_bus_sync(
+               G_BUS_TYPE_SYSTEM,
+               G_DBUS_PROXY_FLAGS_NONE,
+               PERIPHERAL_GDBUS_NAME,
+               PERIPHERAL_GDBUS_GPIO_PATH,
+               NULL,
+               &error);
+       if (gpio_proxy == NULL) {
+               _E("Can not create gpio proxy : %s", error->message);
+               g_error_free(error);
+               return;
+       }
+
+       g_signal_connect(gpio_proxy,
+                       "gpio-changed",
+                       G_CALLBACK(handle_gpio_changed),
+                       NULL);
+}
+
+void gpio_proxy_deinit()
+{
+       if (gpio_proxy) {
+               g_object_unref(gpio_proxy);
+               gpio_proxy = NULL;
+       }
+}
+
+void handle_gpio_changed(
+               PeripheralIoGdbusGpio *gpio,
+               gint pin,
+               gint state,
+               gpointer user_data)
+{
+       if (!gpio)
+               return;
+
+       _D("gpio=%d state=%d", pin, state);
+
+       peripheral_gpio_isr_callback(pin);
+}
+
+int peripheral_gdbus_gpio_open(peripheral_gpio_h gpio)
+{
+       GError *error = NULL;
+       gint32 ret = PERIPHERAL_ERROR_NONE;
+
+       if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
+
+       if (peripheral_io_gdbus_gpio_call_open_sync(
+                       gpio_proxy,
+                       gpio->pin,
+                       (gint*)&gpio->edge,
+                       (gint*)&gpio->direction,
+                       &ret,
+                       NULL,
+                       &error) == FALSE) {
+               _E("Error in %s() : %s\n", __func__, error->message);
+               g_error_free(error);
+               return PERIPHERAL_ERROR_UNKNOWN;
+       }
+
+       return ret;
+}
+
+int peripheral_gdbus_gpio_close(peripheral_gpio_h gpio)
+{
+       GError *error = NULL;
+       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+
+       if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
+
+       if (peripheral_io_gdbus_gpio_call_close_sync(
+                       gpio_proxy,
+                       gpio->pin,
+                       &ret,
+                       NULL,
+                       &error) == FALSE) {
+               _E("Error in %s() : %s\n", __func__, error->message);
+               g_error_free(error);
+               return PERIPHERAL_ERROR_UNKNOWN;
+       }
+
+       return ret;
+}
+
+int peripheral_gdbus_gpio_get_direction(peripheral_gpio_h gpio, peripheral_gpio_direction_e *direction)
+{
+       GError *error = NULL;
+       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+
+       if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
+
+       if (peripheral_io_gdbus_gpio_call_get_direction_sync(
+                       gpio_proxy,
+                       gpio->pin,
+                       (gint*)direction,
+                       &ret,
+                       NULL,
+                       &error) == FALSE) {
+               _E("Error in %s() : %s\n", __func__, error->message);
+               g_error_free(error);
+               return PERIPHERAL_ERROR_UNKNOWN;
+       }
+       gpio->direction = *direction;
+
+       return ret;
+}
+
+int peripheral_gdbus_gpio_set_direction(peripheral_gpio_h gpio, peripheral_gpio_direction_e direction)
+{
+       GError *error = NULL;
+       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+
+       if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
+
+       if (peripheral_io_gdbus_gpio_call_set_direction_sync(
+                       gpio_proxy,
+                       gpio->pin,
+                       direction,
+                       &ret,
+                       NULL,
+                       &error) == FALSE) {
+               _E("Error in %s() : %s\n", __func__, error->message);
+               g_error_free(error);
+               return PERIPHERAL_ERROR_UNKNOWN;
+       }
+       gpio->direction = direction;
+
+       return ret;
+}
+
+int peripheral_gdbus_gpio_read(peripheral_gpio_h gpio, int *value)
+{
+       GError *error = NULL;
+       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+
+       if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
+
+       if (peripheral_io_gdbus_gpio_call_read_sync(
+                       gpio_proxy,
+                       gpio->pin,
+                       value,
+                       &ret,
+                       NULL,
+                       &error) == FALSE) {
+               _E("Error in %s() : %s\n", __func__, error->message);
+               g_error_free(error);
+               return PERIPHERAL_ERROR_UNKNOWN;
+       }
+
+       return ret;
+}
+
+int peripheral_gdbus_gpio_write(peripheral_gpio_h gpio, int value)
+{
+       GError *error = NULL;
+       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+
+       if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
+
+       if (peripheral_io_gdbus_gpio_call_write_sync(
+                       gpio_proxy,
+                       gpio->pin,
+                       value,
+                       &ret,
+                       NULL,
+                       &error) == FALSE) {
+               _E("Error in %s() : %s\n", __func__, error->message);
+               g_error_free(error);
+               return PERIPHERAL_ERROR_UNKNOWN;
+       }
+
+       return ret;
+}
+
+int peripheral_gdbus_gpio_get_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e *edge)
+{
+       GError *error = NULL;
+       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+
+       if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
+
+       if (peripheral_io_gdbus_gpio_call_get_edge_mode_sync(
+                       gpio_proxy,
+                       gpio->pin,
+                       (int*)edge,
+                       &ret,
+                       NULL,
+                       &error) == FALSE) {
+               _E("Error in %s() : %s\n", __func__, error->message);
+               g_error_free(error);
+               return PERIPHERAL_ERROR_UNKNOWN;
+       }
+       gpio->edge = *edge;
+
+       return ret;
+}
+
+int peripheral_gdbus_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e edge)
+{
+       GError *error = NULL;
+       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+
+       if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
+
+       if (peripheral_io_gdbus_gpio_call_set_edge_mode_sync(
+                       gpio_proxy,
+                       gpio->pin,
+                       edge,
+                       &ret,
+                       NULL,
+                       &error) == FALSE) {
+               _E("Error in %s() : %s\n", __func__, error->message);
+               g_error_free(error);
+               return PERIPHERAL_ERROR_UNKNOWN;
+       }
+       gpio->edge = edge;
+
+       return ret;
+}
+
+int peripheral_gdbus_gpio_register_cb(peripheral_gpio_h gpio, gpio_isr_cb callback, void *user_data)
+{
+       GError *error = NULL;
+       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+
+       if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
+
+       if (peripheral_io_gdbus_gpio_call_register_irq_sync(
+                       gpio_proxy,
+                       gpio->pin,
+                       &ret,
+                       NULL,
+                       &error) == FALSE) {
+               _E("Error in %s() : %s\n", __func__, error->message);
+               g_error_free(error);
+               return PERIPHERAL_ERROR_UNKNOWN;
+       }
+
+       return ret;
+}
+
+int peripheral_gdbus_gpio_unregister_cb(peripheral_gpio_h gpio)
+{
+       GError *error = NULL;
+       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+
+       if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
+
+       if (peripheral_io_gdbus_gpio_call_unregister_irq_sync(
+                       gpio_proxy,
+                       gpio->pin,
+                       &ret,
+                       NULL,
+                       &error) == FALSE) {
+               _E("Error in %s() : %s\n", __func__, error->message);
+               g_error_free(error);
+               return PERIPHERAL_ERROR_UNKNOWN;
+       }
+
+       return ret;
+}
diff --git a/src/peripheral_gdbus_i2c.c b/src/peripheral_gdbus_i2c.c
new file mode 100644 (file)
index 0000000..ce42ce5
--- /dev/null
@@ -0,0 +1,163 @@
+/*
+ * 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 <stdio.h>
+#include <stdlib.h>
+
+#include "peripheral_io.h"
+#include "peripheral_gdbus.h"
+#include "peripheral_common.h"
+#include "peripheral_internal.h"
+#include "peripheral_io_gdbus.h"
+
+PeripheralIoGdbusI2c *i2c_proxy = NULL;
+
+void i2c_proxy_init(void)
+{
+       GError *error = NULL;
+
+       if (i2c_proxy != NULL)
+               return;
+
+       i2c_proxy = peripheral_io_gdbus_i2c_proxy_new_for_bus_sync(
+               G_BUS_TYPE_SYSTEM,
+               G_DBUS_PROXY_FLAGS_NONE,
+               PERIPHERAL_GDBUS_NAME,
+               PERIPHERAL_GDBUS_I2C_PATH,
+               NULL,
+               &error);
+}
+
+void i2c_proxy_deinit()
+{
+       if (i2c_proxy) {
+               g_object_unref(i2c_proxy);
+               i2c_proxy = NULL;
+       }
+}
+
+int peripheral_gdbus_i2c_open(peripheral_i2c_h i2c, int bus, int address)
+{
+       GError *error = NULL;
+       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+
+       if (i2c_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
+
+       if (peripheral_io_gdbus_i2c_call_open_sync(
+                       i2c_proxy,
+                       bus,
+                       address,
+                       &i2c->handle,
+                       &ret,
+                       NULL,
+                       &error) == FALSE) {
+               _E("Error in %s() : %s\n", __func__, error->message);
+               g_error_free(error);
+               return PERIPHERAL_ERROR_UNKNOWN;
+       }
+
+       return ret;
+}
+
+int peripheral_gdbus_i2c_close(peripheral_i2c_h i2c)
+{
+       GError *error = NULL;
+       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+
+       if (i2c_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
+
+       if (peripheral_io_gdbus_i2c_call_close_sync(
+                       i2c_proxy,
+                       i2c->handle,
+                       &ret,
+                       NULL,
+                       &error) == FALSE) {
+               _E("Error in %s() : %s\n", __func__, error->message);
+               g_error_free(error);
+               return PERIPHERAL_ERROR_UNKNOWN;
+       }
+
+       return ret;
+}
+
+int peripheral_gdbus_i2c_read(peripheral_i2c_h i2c, uint8_t *data, int length)
+{
+       GError *error = NULL;
+       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+       GVariant *data_array;
+       GVariantIter *iter;
+       guint8 str;
+       int i = 0;
+
+       if (i2c_proxy == NULL || data == NULL) return PERIPHERAL_ERROR_UNKNOWN;
+
+       if (peripheral_io_gdbus_i2c_call_read_sync(
+                       i2c_proxy,
+                       i2c->handle,
+                       length,
+                       &data_array,
+                       &ret,
+                       NULL,
+                       &error) == FALSE) {
+               _E("Error in %s() : %s\n", __func__, error->message);
+               g_error_free(error);
+               return PERIPHERAL_ERROR_UNKNOWN;
+       }
+
+       g_variant_get(data_array, "a(y)", &iter);
+       while (g_variant_iter_loop(iter, "(y)", &str)) {
+               data[i] = str;
+               if (i++ == length) break;
+       }
+       g_variant_iter_free(iter);
+
+       return ret;
+}
+
+int peripheral_gdbus_i2c_write(peripheral_i2c_h i2c, uint8_t *data, int length)
+{
+       GError *error = NULL;
+       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+       GVariantBuilder *builder;
+       GVariant *g_data;
+       int i = 0;
+
+       if (i2c_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
+
+       builder = g_variant_builder_new(G_VARIANT_TYPE("a(y)"));
+
+       for (i = 0; i < length; i++)
+               g_variant_builder_add(builder, "(y)", data[i]);
+       g_variant_builder_add(builder, "(y)", 0x00);
+
+       g_data = g_variant_new("a(y)", builder);
+       g_variant_builder_unref(builder);
+
+       if (peripheral_io_gdbus_i2c_call_write_sync(
+                       i2c_proxy,
+                       i2c->handle,
+                       length,
+                       g_data,
+                       &ret,
+                       NULL,
+                       &error) == FALSE) {
+               _E("Error in %s() : %s\n", __func__, error->message);
+               g_error_free(error);
+               return PERIPHERAL_ERROR_UNKNOWN;
+       }
+
+       return ret;
+}
diff --git a/src/peripheral_gdbus_pwm.c b/src/peripheral_gdbus_pwm.c
new file mode 100644 (file)
index 0000000..db73dee
--- /dev/null
@@ -0,0 +1,215 @@
+/*
+ * 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 <stdio.h>
+#include <stdlib.h>
+
+#include "peripheral_io.h"
+#include "peripheral_gdbus.h"
+#include "peripheral_common.h"
+#include "peripheral_internal.h"
+#include "peripheral_io_gdbus.h"
+
+PeripheralIoGdbusPwm *pwm_proxy = NULL;
+
+void pwm_proxy_init(void)
+{
+       GError *error = NULL;
+
+       if (pwm_proxy != NULL)
+               return;
+
+       pwm_proxy = peripheral_io_gdbus_pwm_proxy_new_for_bus_sync(
+               G_BUS_TYPE_SYSTEM,
+               G_DBUS_PROXY_FLAGS_NONE,
+               PERIPHERAL_GDBUS_NAME,
+               PERIPHERAL_GDBUS_PWM_PATH,
+               NULL,
+               &error);
+}
+
+void pwm_proxy_deinit()
+{
+       if (pwm_proxy) {
+               g_object_unref(pwm_proxy);
+               pwm_proxy = NULL;
+       }
+}
+
+int peripheral_gdbus_pwm_open(peripheral_pwm_context_h dev, int device, int channel)
+{
+       GError *error = NULL;
+       gint32 ret = PERIPHERAL_ERROR_NONE;
+
+       if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
+
+       /* TODO: Need to reorganize arguments */
+       if (peripheral_io_gdbus_pwm_call_open_sync(
+                       pwm_proxy,
+                       device,
+                       channel,
+                       &ret,
+                       NULL,
+                       &error) == FALSE) {
+               _E("Error in %s() : %s\n", __func__, error->message);
+               g_error_free(error);
+               return PERIPHERAL_ERROR_UNKNOWN;
+       }
+
+       return ret;
+}
+
+int peripheral_gdbus_pwm_close(peripheral_pwm_context_h dev)
+{
+       GError *error = NULL;
+       gint32 ret = PERIPHERAL_ERROR_NONE;
+
+       if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
+
+       /* TODO: Need to reorganize arguments */
+       if (peripheral_io_gdbus_pwm_call_close_sync(
+                       pwm_proxy,
+                       dev->device,
+                       dev->channel,
+                       &ret,
+                       NULL,
+                       &error) == FALSE) {
+               _E("Error in %s() : %s\n", __func__, error->message);
+               g_error_free(error);
+               return PERIPHERAL_ERROR_UNKNOWN;
+       }
+
+       return ret;
+}
+
+int peripheral_gdbus_pwm_get_duty_cycle(peripheral_pwm_context_h dev, int *duty_cycle)
+{
+       GError *error = NULL;
+       gint32 ret = PERIPHERAL_ERROR_NONE;
+
+       if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
+
+       /* TODO: Need to reorganize arguments */
+       if (peripheral_io_gdbus_pwm_call_get_duty_cycle_sync(
+                       pwm_proxy,
+                       dev->device,
+                       dev->channel,
+                       duty_cycle,
+                       &ret,
+                       NULL,
+                       &error) == FALSE) {
+               _E("Error in %s() : %s\n", __func__, error->message);
+               g_error_free(error);
+               return PERIPHERAL_ERROR_UNKNOWN;
+       }
+
+       return ret;
+}
+int peripheral_gdbus_pwm_set_duty_cycle(peripheral_pwm_context_h dev, int duty_cycle)
+{
+       GError *error = NULL;
+       gint32 ret = PERIPHERAL_ERROR_NONE;
+
+       if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
+
+       /* TODO: Need to reorganize arguments */
+       if (peripheral_io_gdbus_pwm_call_set_duty_cycle_sync(
+                       pwm_proxy,
+                       dev->device,
+                       dev->channel,
+                       duty_cycle,
+                       &ret,
+                       NULL,
+                       &error) == FALSE) {
+               _E("Error in %s() : %s\n", __func__, error->message);
+               g_error_free(error);
+               return PERIPHERAL_ERROR_UNKNOWN;
+       }
+
+       return ret;
+}
+
+int peripheral_gdbus_pwm_get_period(peripheral_pwm_context_h dev, int *period)
+{
+       GError *error = NULL;
+       gint32 ret = PERIPHERAL_ERROR_NONE;
+
+       if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
+
+       /* TODO: Need to reorganize arguments */
+       if (peripheral_io_gdbus_pwm_call_get_period_sync(
+                       pwm_proxy,
+                       dev->device,
+                       dev->channel,
+                       period,
+                       &ret,
+                       NULL,
+                       &error) == FALSE) {
+               _E("Error in %s() : %s\n", __func__, error->message);
+               g_error_free(error);
+               return PERIPHERAL_ERROR_UNKNOWN;
+       }
+
+       return ret;
+}
+
+int peripheral_gdbus_pwm_set_period(peripheral_pwm_context_h dev, int period)
+{
+       GError *error = NULL;
+       gint32 ret = PERIPHERAL_ERROR_NONE;
+
+       if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
+
+       /* TODO: Need to reorganize arguments */
+       if (peripheral_io_gdbus_pwm_call_set_period_sync(
+                       pwm_proxy,
+                       dev->device,
+                       dev->channel,
+                       period,
+                       &ret,
+                       NULL,
+                       &error) == FALSE) {
+               _E("Error in %s() : %s\n", __func__, error->message);
+               g_error_free(error);
+               return PERIPHERAL_ERROR_UNKNOWN;
+       }
+
+       return ret;
+}
+
+int peripheral_gdbus_pwm_set_enable(peripheral_pwm_context_h dev, peripheral_pwm_state_e enable)
+{
+       GError *error = NULL;
+       gint32 ret = PERIPHERAL_ERROR_NONE;
+
+       if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
+
+       /* TODO: Need to reorganize arguments */
+       if (peripheral_io_gdbus_pwm_call_set_enable_sync(
+                       pwm_proxy,
+                       dev->device,
+                       dev->channel,
+                       enable,
+                       &ret,
+                       NULL,
+                       &error) == FALSE) {
+               _E("Error in %s() : %s\n", __func__, error->message);
+               g_error_free(error);
+               return PERIPHERAL_ERROR_UNKNOWN;
+       }
+
+       return ret;
+}
index f942759d2d2f53123d9171917a830d72c573c4df..2b3bd20ac16f610a5d13c5658f96d07af32eda05 100644 (file)
@@ -20,7 +20,7 @@
 #include <assert.h>
 
 #include "peripheral_io.h"
-#include "peripheral_dbus.h"
+#include "peripheral_gdbus_gpio.h"
 #include "peripheral_common.h"
 #include "peripheral_internal.h"
 #include "peripheral_io_gdbus.h"
@@ -128,7 +128,7 @@ int peripheral_gpio_open(int gpio_pin, peripheral_gpio_h *gpio)
 
        gpio_proxy_init();
 
-       ret = peripheral_dbus_gpio_open(handle);
+       ret = peripheral_gdbus_gpio_open(handle);
 
        if (ret != PERIPHERAL_ERROR_NONE) {
                free(handle);
@@ -153,7 +153,7 @@ int peripheral_gpio_close(peripheral_gpio_h gpio)
                return PERIPHERAL_ERROR_INVALID_PARAMETER;
 
        /* call gpio_close */
-       ret = peripheral_dbus_gpio_close(gpio);
+       ret = peripheral_gdbus_gpio_close(gpio);
        if (ret)
                ret = TIZEN_ERROR_IO_ERROR;
        gpio_proxy_deinit();
@@ -175,7 +175,7 @@ int peripheral_gpio_get_direction(peripheral_gpio_h gpio, peripheral_gpio_direct
        if (gpio == NULL)
                return PERIPHERAL_ERROR_INVALID_PARAMETER;
 
-       ret = peripheral_dbus_gpio_get_direction(gpio, direction);
+       ret = peripheral_gdbus_gpio_get_direction(gpio, direction);
        if (ret == PERIPHERAL_ERROR_NONE)
                gpio->direction = (*direction);
 
@@ -198,7 +198,7 @@ int peripheral_gpio_set_direction(peripheral_gpio_h gpio, peripheral_gpio_direct
                return PERIPHERAL_ERROR_INVALID_PARAMETER;
 
        /* call gpio_set_direction */
-       ret = peripheral_dbus_gpio_set_direction(gpio, direction);
+       ret = peripheral_gdbus_gpio_set_direction(gpio, direction);
        if (ret == PERIPHERAL_ERROR_NONE)
                gpio->direction = direction;
 
@@ -217,7 +217,7 @@ int peripheral_gpio_read(peripheral_gpio_h gpio, int *value)
                return PERIPHERAL_ERROR_INVALID_PARAMETER;
 
        /* call gpio_read */
-       ret = peripheral_dbus_gpio_read(gpio, value);
+       ret = peripheral_gdbus_gpio_read(gpio, value);
 
        return ret;
 }
@@ -234,7 +234,7 @@ int peripheral_gpio_write(peripheral_gpio_h gpio, int value)
                return PERIPHERAL_ERROR_INVALID_PARAMETER;
 
        /* call gpio_write */
-       ret = peripheral_dbus_gpio_write(gpio, value);
+       ret = peripheral_gdbus_gpio_write(gpio, value);
 
        return ret;
 }
@@ -250,7 +250,7 @@ int peripheral_gpio_get_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e
        if (gpio == NULL)
                return PERIPHERAL_ERROR_INVALID_PARAMETER;
 
-       ret = peripheral_dbus_gpio_get_edge_mode(gpio, edge);
+       ret = peripheral_gdbus_gpio_get_edge_mode(gpio, edge);
        if (ret == PERIPHERAL_ERROR_NONE)
                gpio->edge = (*edge);
 
@@ -272,7 +272,7 @@ int peripheral_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e
                return PERIPHERAL_ERROR_INVALID_PARAMETER;
 
        /* call gpio_set_edge_mode */
-       ret = peripheral_dbus_gpio_set_edge_mode(gpio, edge);
+       ret = peripheral_gdbus_gpio_set_edge_mode(gpio, edge);
        if (ret == PERIPHERAL_ERROR_NONE)
                gpio->edge = edge;
 
@@ -290,7 +290,7 @@ int peripheral_gpio_register_cb(peripheral_gpio_h gpio, gpio_isr_cb callback, vo
        if (gpio == NULL)
                return PERIPHERAL_ERROR_INVALID_PARAMETER;
 
-       ret = peripheral_dbus_gpio_register_cb(gpio, callback, user_data);
+       ret = peripheral_gdbus_gpio_register_cb(gpio, callback, user_data);
        if (ret != PERIPHERAL_ERROR_NONE)
                return ret;
 
@@ -311,7 +311,7 @@ int peripheral_gpio_unregister_cb(peripheral_gpio_h gpio)
        if (gpio == NULL)
                return PERIPHERAL_ERROR_INVALID_PARAMETER;
 
-       ret = peripheral_dbus_gpio_unregister_cb(gpio);
+       ret = peripheral_gdbus_gpio_unregister_cb(gpio);
        if (ret != PERIPHERAL_ERROR_NONE)
                return ret;
 
index b8710147a77c41d089754046b97b11e6dda7d15a..fee3a321a6278224bceca0f9fa6a4e7198dbc628 100644 (file)
@@ -20,7 +20,7 @@
 #include <assert.h>
 
 #include "peripheral_io.h"
-#include "peripheral_dbus.h"
+#include "peripheral_gdbus_i2c.h"
 #include "peripheral_common.h"
 #include "peripheral_internal.h"
 
@@ -41,7 +41,7 @@ int peripheral_i2c_open(int bus, int address, peripheral_i2c_h *i2c)
 
        i2c_proxy_init();
 
-       ret = peripheral_dbus_i2c_open(handle, bus, address);
+       ret = peripheral_gdbus_i2c_open(handle, bus, address);
 
        if (ret != PERIPHERAL_ERROR_NONE) {
                _E("[PERIPHERAL] I2C init error\n");
@@ -59,7 +59,7 @@ int peripheral_i2c_close(peripheral_i2c_h i2c)
 
        if (i2c == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER;
 
-       ret = peripheral_dbus_i2c_close(i2c);
+       ret = peripheral_gdbus_i2c_close(i2c);
        i2c_proxy_deinit();
 
        free(i2c);
@@ -74,7 +74,7 @@ int peripheral_i2c_read(peripheral_i2c_h i2c, uint8_t *data, int length)
 
        if (i2c == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER;
 
-       ret = peripheral_dbus_i2c_read(i2c, data, length);
+       ret = peripheral_gdbus_i2c_read(i2c, data, length);
        /*
        _D("I2C read data : ");
        for (int i = 0 ; i < length ; i++)
@@ -87,5 +87,5 @@ int peripheral_i2c_write(peripheral_i2c_h i2c, uint8_t *data, int length)
 {
        if (i2c == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER;
 
-       return peripheral_dbus_i2c_write(i2c, data, length);
+       return peripheral_gdbus_i2c_write(i2c, data, length);
 }
index d4d728ae7316da893d581b5d71c8b05894197678..b3fa3a70d396d0acca25550e51ecbe09146717af 100644 (file)
@@ -20,7 +20,7 @@
 #include <assert.h>
 
 #include "peripheral_io.h"
-#include "peripheral_dbus.h"
+#include "peripheral_gdbus_pwm.h"
 #include "peripheral_common.h"
 
 #define PWM_ENABLE     1
@@ -47,7 +47,7 @@ peripheral_pwm_context_h peripheral_pwm_open(int device, int channel)
        dev->device = device;
        dev->channel = channel;
 
-       ret = peripheral_dbus_pwm_open(dev, device, channel);
+       ret = peripheral_gdbus_pwm_open(dev, device, channel);
 
        if (ret != PERIPHERAL_ERROR_NONE) {
                free(dev);
@@ -61,7 +61,7 @@ int peripheral_pwm_close(peripheral_pwm_context_h pwm)
 {
        int ret = PERIPHERAL_ERROR_NONE;
 
-       ret = peripheral_dbus_pwm_close(pwm);
+       ret = peripheral_gdbus_pwm_close(pwm);
        pwm_proxy_deinit();
 
        if (ret == PERIPHERAL_ERROR_NONE) {
@@ -77,7 +77,7 @@ int   peripheral_pwm_set_duty_cycle(peripheral_pwm_context_h pwm, int duty_cycle)
 {
        int ret = PERIPHERAL_ERROR_NONE;
 
-       ret = peripheral_dbus_pwm_set_duty_cycle(pwm, duty_cycle);
+       ret = peripheral_gdbus_pwm_set_duty_cycle(pwm, duty_cycle);
 
        if (ret != PERIPHERAL_ERROR_NONE)
                pwm->duty_cycle = duty_cycle;
@@ -89,7 +89,7 @@ int peripheral_pwm_set_period(peripheral_pwm_context_h pwm, int period)
 {
        int ret = PERIPHERAL_ERROR_NONE;
 
-       ret = peripheral_dbus_pwm_set_period(pwm, period);
+       ret = peripheral_gdbus_pwm_set_period(pwm, period);
 
        if (ret != PERIPHERAL_ERROR_NONE)
                pwm->period = period;
@@ -101,7 +101,7 @@ int peripheral_pwm_set_enabled(peripheral_pwm_context_h pwm, peripheral_pwm_stat
 {
        int ret = PERIPHERAL_ERROR_NONE;
 
-       ret = peripheral_dbus_pwm_set_enable(pwm, enable);
+       ret = peripheral_gdbus_pwm_set_enable(pwm, enable);
 
        if (ret != PERIPHERAL_ERROR_NONE)
                pwm->enabled = enable;
@@ -121,7 +121,7 @@ int peripheral_pwm_get_duty_cycle(peripheral_pwm_context_h pwm, int *duty_cycle)
 {
        int ret = PERIPHERAL_ERROR_NONE;
 
-       ret = peripheral_dbus_pwm_get_duty_cycle(pwm, duty_cycle);
+       ret = peripheral_gdbus_pwm_get_duty_cycle(pwm, duty_cycle);
 
        if (ret != PERIPHERAL_ERROR_NONE)
                pwm->duty_cycle = *duty_cycle;
@@ -133,7 +133,7 @@ int peripheral_pwm_get_period(peripheral_pwm_context_h pwm, int *period)
 {
        int ret = PERIPHERAL_ERROR_NONE;
 
-       ret = peripheral_dbus_pwm_get_period(pwm, period);
+       ret = peripheral_gdbus_pwm_get_period(pwm, period);
 
        if (ret != PERIPHERAL_ERROR_NONE)
                pwm->period = *period;