3 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * Licensed under the Apache License, Version 2.0 (the License);
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
23 #include "device-internal.h"
25 #define container_of(ptr, type, member) ({ \
26 const typeof( ((type *)0)->member ) *__mptr = (ptr); \
27 (type *)( (char *)__mptr - offsetof(type,member) );})
29 static GList *dev_head;
30 static void *dlopen_handle;
31 const OEM_sys_devman_plugin_interface *oem_intf;
33 void add_device(const enum device_type *devtype)
35 dev_head = g_list_append(dev_head, (enum device_type *)devtype);
38 void remove_device(const enum device_type *devtype)
40 dev_head = g_list_remove(dev_head, (enum device_type *)devtype);
43 static enum device_type *find_device(enum device_type devtype)
46 enum device_type *type;
48 for (elem = dev_head; elem; elem = elem->next) {
57 API int device_get_property(enum device_type devtype, int property, int *value)
60 enum device_type *type;
63 type = find_device(devtype);
65 _E("devtype cannot find");
70 dev = container_of(type, struct device, type);
72 if (dev->get_prop == NULL) {
73 _E("devtype doesn't have getter function");
78 r = dev->get_prop(property, value);
80 _E("Not support driver");
84 _E("get_prop of %s(%d) return failes", dev->name, property);
93 API int device_set_property(enum device_type devtype, int property, int value)
95 enum device_type *type;
99 type = find_device(devtype);
101 _E("devtype cannot find");
106 dev = container_of(type, struct device, type);
108 if (dev->set_prop == NULL) {
109 _E("devtype doesn't have setter function");
114 r = dev->set_prop(property, value);
116 _E("Not support driver");
119 } else if (r == -1) {
120 _E("set_prop of %s(%d) return failes", dev->name, property);
129 static void __CONSTRUCTOR__ module_init(void)
131 const OEM_sys_devman_plugin_interface *(*OEM_sys_get_devman_plugin_interface) ();
134 dlopen_handle = dlopen(DEVMAN_PLUGIN_PATH, RTLD_NOW);
135 if (!dlopen_handle) {
136 _E("dlopen() failed");
140 OEM_sys_get_devman_plugin_interface = dlsym(dlopen_handle, "OEM_sys_get_devman_plugin_interface");
141 if ((error = dlerror()) != NULL) {
142 _E("dlsym() failed: %s", error);
146 oem_intf = OEM_sys_get_devman_plugin_interface();
148 _E("get_devman_plugin_interface() failed");
156 dlclose(dlopen_handle);
159 static void __DESTRUCTOR__ module_fini(void)
162 dlclose(dlopen_handle);