4 * Copyright (c) 2011-2013 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Youngae Kang <youngae.kang@samsung.com>, Minjune Kim <sena06.kim@samsung.com>
7 * Genie Kim <daejins.kim@samsung.com>
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
26 #include <sys/types.h>
28 #include "gps_plugin_module.h"
30 #include "debug_util.h"
32 #define SPECIFIC_PLUGIN_PATH_PREFIX LIB_DIR"/liblbs-server-plugin-"
33 #define SPECIFIC_PLUGIN_PATH_POSTFIX ".so"
35 static const gps_plugin_interface *g_plugin = NULL;
37 int load_plugin_module(char *specific_name, void **plugin_handle)
39 char plugin_path[256];
41 if (specific_name[0] == '\0') {
42 strncpy(plugin_path, GPS_PLUGIN_PATH, sizeof(plugin_path));
44 snprintf(plugin_path, sizeof(plugin_path),
45 SPECIFIC_PLUGIN_PATH_PREFIX"%s"
46 SPECIFIC_PLUGIN_PATH_POSTFIX,
51 if (stat(plugin_path, &st) != 0) {
52 strncpy(plugin_path, GPS_PLUGIN_PATH, sizeof(plugin_path));
53 /* To support real GPS when additional plugin is added*/
54 /* setting_set_int(VCONFKEY_LOCATION_REPLAY_ENABLED, 1); */
58 *plugin_handle = dlopen(plugin_path, RTLD_NOW);
59 if (!*plugin_handle) {
60 LOG_GPS(DBG_ERR, "Failed to load plugin module: %s", plugin_path);
61 /* LOG_GPS(DBG_ERR, "%s", dlerror()); */
65 const gps_plugin_interface *(*get_gps_plugin_interface)();
66 get_gps_plugin_interface = dlsym(*plugin_handle, "get_gps_plugin_interface");
67 if (!get_gps_plugin_interface) {
68 LOG_GPS(DBG_ERR, "Failed to find entry symbol in plugin module.");
69 dlclose(*plugin_handle);
73 g_plugin = get_gps_plugin_interface();
76 LOG_GPS(DBG_ERR, "Failed to find load symbol in plugin module.");
77 dlclose(*plugin_handle);
80 LOG_GPS(DBG_LOW, "Success to load plugin module");
85 int unload_plugin_module(void *plugin_handle)
87 if (plugin_handle == NULL) {
88 LOG_GPS(DBG_ERR, "plugin_handle is already NULL.");
92 dlclose(plugin_handle);
97 const gps_plugin_interface *get_plugin_module(void)