4 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (the License);
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
29 #include "core/common.h"
30 #include "core/devices.h"
31 #include "core/edbus-handler.h"
32 #include "core/list.h"
35 static dd_list *gpio_head;
37 static const struct gpio_device default_gpio = {
38 .name = "default-gpio",
41 void register_gpio_device(const struct gpio_device *gpio)
43 DD_LIST_APPEND(gpio_head, (void*)gpio);
46 void unregister_gpio_device(const struct gpio_device *gpio)
48 DD_LIST_REMOVE(gpio_head, (void*)gpio);
51 int check_default_gpio_device(const struct gpio_device *gpio)
53 return (gpio == &default_gpio);
56 const struct gpio_device *find_gpio_device(const char *name)
59 const struct gpio_device *gpio;
61 DD_LIST_FOREACH(gpio_head, elem, gpio) {
62 if (!strcmp(gpio->name, name))
70 static DBusMessage *check_gpio_status(E_DBus_Object *obj, DBusMessage *msg)
74 const struct gpio_device *gpio;
77 int status = GPIO_DEVICE_UNKNOWN;
79 ret = dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &name,
86 gpio = find_gpio_device(name);
87 if (check_default_gpio_device(gpio))
89 status = gpio->status();
90 _D("%s %d", name, status);
92 reply = dbus_message_new_method_return(msg);
93 dbus_message_iter_init_append(reply, &iter);
94 dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &status);
98 static const struct edbus_method edbus_methods[] = {
99 { "GetStatus", "s", "i", check_gpio_status },
102 static void gpio_init(void *data)
104 struct gpio_device *gpio;
108 DD_LIST_FOREACH(gpio_head, elem, gpio) {
113 ret = register_edbus_method(DEVICED_PATH_GPIO, edbus_methods, ARRAY_SIZE(edbus_methods));
115 _E("fail to init edbus method(%d)", ret);
118 const struct device_ops gpio_device_ops = {
119 .priority = DEVICE_PRIORITY_NORMAL,
124 DEVICE_OPS_REGISTER(&gpio_device_ops)