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.
19 #include <gio/gunixfdlist.h>
21 #include "peripheral_io.h"
22 #include "peripheral_gdbus.h"
23 #include "peripheral_common.h"
24 #include "peripheral_internal.h"
25 #include "peripheral_io_gdbus.h"
27 #define I2C_FD_INDEX 0
29 static PeripheralIoGdbusI2c *i2c_proxy = NULL;
31 void i2c_proxy_init(void)
35 if (i2c_proxy != NULL) {
36 g_object_ref(i2c_proxy);
40 i2c_proxy = peripheral_io_gdbus_i2c_proxy_new_for_bus_sync(
42 G_DBUS_PROXY_FLAGS_NONE,
43 PERIPHERAL_GDBUS_NAME,
44 PERIPHERAL_GDBUS_I2C_PATH,
49 void i2c_proxy_deinit()
52 g_object_unref(i2c_proxy);
53 if (!G_IS_OBJECT(i2c_proxy))
58 int peripheral_gdbus_i2c_open(peripheral_i2c_h i2c, int bus, int address)
61 peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
62 GUnixFDList *fd_list = NULL;
64 if (i2c_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
66 if (peripheral_io_gdbus_i2c_call_open_sync(
76 _E("Error in %s() : %s", __func__, error->message);
78 return PERIPHERAL_ERROR_UNKNOWN;
81 i2c->fd = g_unix_fd_list_get(fd_list, I2C_FD_INDEX, &error);
83 _E("Failed to get fd for i2c : %s", error->message);
85 ret = PERIPHERAL_ERROR_UNKNOWN;
88 g_object_unref(fd_list);
93 int peripheral_gdbus_i2c_close(peripheral_i2c_h i2c)
96 peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
98 if (i2c_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
100 if (peripheral_io_gdbus_i2c_call_close_sync(
106 _E("Error in %s() : %s", __func__, error->message);
108 return PERIPHERAL_ERROR_UNKNOWN;