2 * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #include "peripheral_io.h"
21 #include "peripheral_gdbus.h"
22 #include "peripheral_common.h"
23 #include "peripheral_internal.h"
24 #include "peripheral_io_gdbus.h"
26 extern int peripheral_gpio_interrupted_cb_handler(int pin, int value, unsigned long long timestamp, int err);
28 static PeripheralIoGdbusGpio *gpio_proxy = NULL;
30 static void __peripheral_gpio_interrupted_cb(PeripheralIoGdbusGpio *gpio, gint pin, gint value, guint64 timestamp, gpointer user_data)
32 int err = PERIPHERAL_ERROR_NONE;
34 err = PERIPHERAL_ERROR_IO_ERROR;
36 peripheral_gpio_interrupted_cb_handler(pin, value, timestamp, err);
39 void gpio_proxy_init(void)
43 if (gpio_proxy != NULL) {
44 g_object_ref(gpio_proxy);
48 gpio_proxy = peripheral_io_gdbus_gpio_proxy_new_for_bus_sync(
50 G_DBUS_PROXY_FLAGS_NONE,
51 PERIPHERAL_GDBUS_NAME,
52 PERIPHERAL_GDBUS_GPIO_PATH,
55 if (gpio_proxy == NULL) {
56 _E("Can not create gpio proxy : %s", error->message);
61 g_signal_connect(gpio_proxy,
63 G_CALLBACK(__peripheral_gpio_interrupted_cb),
67 void gpio_proxy_deinit()
70 g_object_unref(gpio_proxy);
71 if (!G_IS_OBJECT(gpio_proxy))
76 int peripheral_gdbus_gpio_open(peripheral_gpio_h gpio)
79 gint32 ret = PERIPHERAL_ERROR_NONE;
81 if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
83 if (peripheral_io_gdbus_gpio_call_open_sync(
90 _E("Error in %s() : %s", __func__, error->message);
92 return PERIPHERAL_ERROR_UNKNOWN;
98 int peripheral_gdbus_gpio_close(peripheral_gpio_h gpio)
100 GError *error = NULL;
101 peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
103 if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
105 if (peripheral_io_gdbus_gpio_call_close_sync(
111 _E("Error in %s() : %s", __func__, error->message);
113 return PERIPHERAL_ERROR_UNKNOWN;
119 int peripheral_gdbus_gpio_set_direction(peripheral_gpio_h gpio, peripheral_gpio_direction_e direction)
121 GError *error = NULL;
122 peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
124 if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
126 if (peripheral_io_gdbus_gpio_call_set_direction_sync(
133 _E("Error in %s() : %s", __func__, error->message);
135 return PERIPHERAL_ERROR_UNKNOWN;
141 int peripheral_gdbus_gpio_set_edge_mode(peripheral_gpio_h gpio, peripheral_gpio_edge_e edge)
143 GError *error = NULL;
144 peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
146 if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
148 if (peripheral_io_gdbus_gpio_call_set_edge_mode_sync(
155 _E("Error in %s() : %s", __func__, error->message);
157 return PERIPHERAL_ERROR_UNKNOWN;
163 int peripheral_gdbus_gpio_set_interrupted_cb(peripheral_gpio_h gpio, peripheral_gpio_interrupted_cb callback, void *user_data)
165 GError *error = NULL;
166 peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
168 if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
170 if (peripheral_io_gdbus_gpio_call_set_interrupted_cb_sync(
176 _E("Error in %s() : %s", __func__, error->message);
178 return PERIPHERAL_ERROR_UNKNOWN;
184 int peripheral_gdbus_gpio_unset_interrupted_cb(peripheral_gpio_h gpio)
186 GError *error = NULL;
187 peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
189 if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
191 if (peripheral_io_gdbus_gpio_call_unset_interrupted_cb_sync(
197 _E("Error in %s() : %s", __func__, error->message);
199 return PERIPHERAL_ERROR_UNKNOWN;
205 int peripheral_gdbus_gpio_read(peripheral_gpio_h gpio, int *value)
207 GError *error = NULL;
208 peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
210 if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
212 if (peripheral_io_gdbus_gpio_call_read_sync(
219 _E("Error in %s() : %s", __func__, error->message);
221 return PERIPHERAL_ERROR_UNKNOWN;
227 int peripheral_gdbus_gpio_write(peripheral_gpio_h gpio, int value)
229 GError *error = NULL;
230 peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
232 if (gpio_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
234 if (peripheral_io_gdbus_gpio_call_write_sync(
241 _E("Error in %s() : %s", __func__, error->message);
243 return PERIPHERAL_ERROR_UNKNOWN;