2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.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.tizenopensource.org/license
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.
21 #include <linux/limits.h>
28 #include <sys/types.h>
30 #include "ug-module.h"
33 #define UG_MODULE_INIT_SYM "UG_MODULE_INIT"
34 #define UG_MODULE_EXIT_SYM "UG_MODULE_EXIT"
36 static int file_exist(const char *filename)
39 if ((file = fopen(filename, "r"))) {
47 struct ug_module *ug_module_load(const char *name)
50 struct ug_module *module;
51 char ug_file[PATH_MAX];
53 char *pkg_name = NULL;
56 int (*module_init) (struct ug_module_ops *ops);
58 module = calloc(1, sizeof(struct ug_module));
65 pkg_name = getenv("PKG_NAME");
70 (ug_file, PATH_MAX, "/opt/apps/%s/lib/libug-%s.so",
71 pkg_name, name) < 0) {
73 } else if (file_exist(ug_file) < 0) {
75 (ug_file, PATH_MAX, "/usr/ug/lib/libug-%s.so",
78 } else if (file_exist(ug_file) < 0) {
81 "/opt/ug/lib/libug-%s.so", name) < 0) {
83 } else if (file_exist(ug_file) < 0) {
89 if (snprintf(ug_file, PATH_MAX, "/usr/ug/lib/libug-%s.so", name)
92 } else if (file_exist(ug_file) < 0) {
94 (ug_file, PATH_MAX, "/opt/ug/lib/libug-%s.so",
97 } else if (file_exist(ug_file) < 0) {
103 handle = dlopen(ug_file, RTLD_LAZY);
105 _ERR("dlopen failed: %s\n", dlerror());
109 module_init = dlsym(handle, UG_MODULE_INIT_SYM);
111 _ERR("dlsym failed: %s\n", dlerror());
115 if (module_init(&module->ops))
118 module->handle = handle;
129 int ug_module_unload(struct ug_module *module)
131 void (*module_exit) (struct ug_module_ops *ops);
138 if (module->handle) {
139 module_exit = dlsym(module->handle, UG_MODULE_EXIT_SYM);
141 module_exit(&module->ops);
143 _ERR("dlsym failed: %s\n", dlerror());
145 dlclose(module->handle);