2 * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd All Rights Reserved
4 * This file is part of the UI Gadget
5 * Written by Jayoun Lee <airjany@samsung.com>, Jinwoo Nam <jwoo.nam@samsung.com>
7 * PROPRIETARY/CONFIDENTIAL
9 * This software is the confidential and proprietary information of
10 * SAMSUNG ELECTRONICS (Confidential Information).
11 * You shall not disclose such Confidential Information and shall
12 * use it only in accordance with the terms of the license agreement
13 * you entered into with SAMSUNG ELECTRONICS. SAMSUNG make no
14 * representations or warranties about the suitability
15 * of the software, either express or implied, including but not
16 * limited to the implied warranties of merchantability, fitness for a particular purpose, or non-
17 * infringement. SAMSUNG shall not be liable for any damages suffered by licensee as
18 * a result of using, modifying or distributing this software or its derivatives.
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 (ug_file, PATH_MAX, "/opt/apps/%s/lib/libug-%s.so",
72 pkg_name, name) < 0) {
74 } else if (file_exist(ug_file) < 0) {
76 (ug_file, PATH_MAX, "/usr/ug/lib/libug-%s.so",
79 } else if (file_exist(ug_file) < 0) {
82 "/opt/ug/lib/libug-%s.so", name) < 0) {
84 } else if (file_exist(ug_file) < 0) {
90 if (snprintf(ug_file, PATH_MAX, "/usr/ug/lib/libug-%s.so", name)
93 } else if (file_exist(ug_file) < 0) {
95 (ug_file, PATH_MAX, "/opt/ug/lib/libug-%s.so",
98 } else if (file_exist(ug_file) < 0) {
104 handle = dlopen(ug_file, RTLD_LAZY);
106 _ERR("dlopen failed: %s\n", dlerror());
110 module_init = dlsym(handle, UG_MODULE_INIT_SYM);
112 _ERR("dlsym failed: %s\n", dlerror());
116 if (module_init(&module->ops))
119 module->handle = handle;
130 int ug_module_unload(struct ug_module *module)
132 void (*module_exit) (struct ug_module_ops *ops);
139 if (module->handle) {
140 module_exit = dlsym(module->handle, UG_MODULE_EXIT_SYM);
142 module_exit(&module->ops);
144 _ERR("dlsym failed: %s\n", dlerror());
146 dlclose(module->handle);