4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jayoun Lee <airjany@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
22 #include <linux/limits.h>
29 #include <sys/types.h>
31 #include "ug-module.h"
34 #define UG_MODULE_INIT_SYM "UG_MODULE_INIT"
35 #define UG_MODULE_EXIT_SYM "UG_MODULE_EXIT"
37 static int file_exist(const char *filename)
40 if ((file = fopen(filename, "r"))) {
48 struct ug_module *ug_module_load(const char *name)
51 struct ug_module *module;
52 char ug_file[PATH_MAX];
54 char *pkg_name = NULL;
57 int (*module_init) (struct ug_module_ops *ops);
59 module = calloc(1, sizeof(struct ug_module));
66 pkg_name = getenv("PKG_NAME");
71 snprintf(ug_file, PATH_MAX, "/usr/apps/%s/lib/libug-%s.so", pkg_name, name);
72 if (file_exist(ug_file))
74 snprintf(ug_file, PATH_MAX, "/opt/apps/%s/lib/libug-%s.so", pkg_name, name);
75 if (file_exist(ug_file))
78 snprintf(ug_file, PATH_MAX, "/usr/ug/lib/libug-%s.so", name);
79 if (file_exist(ug_file))
81 snprintf(ug_file, PATH_MAX, "/opt/ug/lib/libug-%s.so", name);
82 if (file_exist(ug_file))
86 handle = dlopen(ug_file, RTLD_LAZY);
88 _ERR("dlopen failed: %s\n", dlerror());
92 module_init = dlsym(handle, UG_MODULE_INIT_SYM);
94 _ERR("dlsym failed: %s\n", dlerror());
98 if (module_init(&module->ops))
101 module->handle = handle;
112 int ug_module_unload(struct ug_module *module)
114 void (*module_exit) (struct ug_module_ops *ops);
121 if (module->handle) {
122 module_exit = dlsym(module->handle, UG_MODULE_EXIT_SYM);
124 module_exit(&module->ops);
126 _ERR("dlsym failed: %s\n", dlerror());
128 dlclose(module->handle);