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-engine.h"
34 #define UG_ENGINE_INIT_SYM "UG_ENGINE_INIT"
35 #define UG_ENGINE_EXIT_SYM "UG_ENGINE_EXIT"
41 static int file_exist(const char *filename)
45 file = fopen(filename, "r");
54 struct ug_engine *ug_engine_load()
57 struct ug_engine *engine;
58 char engine_file[PATH_MAX];
59 enum ug_engine_type type = UG_ENGINE_EFL;
60 int (*engine_init)(struct ug_engine_ops *ops);
62 engine = calloc(1, sizeof(struct ug_engine));
69 if (type == UG_ENGINE_EFL) { /* UG_ENGINE_EFL is default*/
70 if (snprintf(engine_file, PATH_MAX, "/usr/lib/libui-gadget-1-efl-engine.so") < 0){
73 else if (file_exist(engine_file) < 0) {
80 handle = dlopen(engine_file, RTLD_LAZY);
82 _ERR("dlopen failed: %s\n", dlerror());
86 engine_init = dlsym(handle, UG_ENGINE_INIT_SYM);
88 _ERR("dlsym failed: %s\n", dlerror());
92 if (engine_init(&engine->ops))
95 engine->handle = handle;
106 int ug_engine_unload(struct ug_engine *engine)
108 void (*engine_exit)(struct ug_engine_ops *ops);
115 if (engine->handle) {
116 engine_exit = dlsym(engine->handle, UG_ENGINE_EXIT_SYM);
118 engine_exit(&engine->ops);
120 _ERR("dlsym failed: %s\n", dlerror());
122 dlclose(engine->handle);