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 <app_manager.h>
33 #include "ug-module.h"
36 #include <tzplatform_config.h>
38 #define UG_MODULE_INIT_SYM "UG_MODULE_INIT"
39 #define UG_MODULE_EXIT_SYM "UG_MODULE_EXIT"
41 static int file_exist(const char *filename)
44 if ((file = fopen(filename, "r"))) {
52 struct ug_module *ug_module_load(const char *name)
55 struct ug_module *module;
56 char ug_file[PATH_MAX];
57 char *pkg_name = NULL;
59 int (*module_init) (struct ug_module_ops *ops);
61 module = calloc(1, sizeof(struct ug_module));
67 app_manager_get_package(getpid(), &pkg_name);
71 snprintf(ug_file, PATH_MAX, "%s/%s/lib/libug-%s.so", tzplatform_getenv(TZ_SYS_RO_APP), pkg_name, name);
72 if (file_exist(ug_file))
74 snprintf(ug_file, PATH_MAX, "%s/%s/lib/libug-%s.so", tzplatform_getenv(TZ_SYS_RO_APP), 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/usr/ug/lib/libug-%s.so", name);
82 if (file_exist(ug_file))
91 handle = dlopen(ug_file, RTLD_LAZY);
93 _ERR("dlopen failed: %s", dlerror());
97 module_init = dlsym(handle, UG_MODULE_INIT_SYM);
99 _ERR("dlsym failed: %s", dlerror());
103 if (module_init(&module->ops))
106 module->handle = handle;
107 module->module_name = strdup(name);
118 int ug_module_unload(struct ug_module *module)
120 void (*module_exit) (struct ug_module_ops *ops);
127 if (module->handle) {
128 module_exit = dlsym(module->handle, UG_MODULE_EXIT_SYM);
130 module_exit(&module->ops);
132 _ERR("dlsym failed: %s", dlerror());
134 dlclose(module->handle);
135 module->handle = NULL;
138 if(module->module_name)
139 free(module->module_name);
145 int ug_exist(const char* name)
147 char ug_file[PATH_MAX] = {0,};
151 snprintf(ug_file, PATH_MAX, "/usr/ug/lib/libug-%s.so", name);
152 if (file_exist(ug_file)) {
156 snprintf(ug_file, PATH_MAX, "/opt/ug/lib/libug-%s.so", name);
157 if (file_exist(ug_file)) {
161 snprintf(ug_file, PATH_MAX, "/opt/usr/ug/lib/libug-%s.so", name);
162 if (file_exist(ug_file)) {