4 * Copyright (c) 2010-2013 Samsung Electronics Co., Ltd All Rights Reserved
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
23 #include "nps_plugin_module.h"
25 #include "debug_util.h"
27 #define PLUGIN_PATH_POSTFIX ".so"
30 static const nps_plugin_interface *g_plugin = NULL;
31 static int g_is_nps_dummy_module = FALSE;
34 int dummy_unload(void);
35 int dummy_start(unsigned long period, LocationCallback cb, void *arg, void **handle);
36 int dummy_stop(void *handle, CancelCallback cb, void *arg);
37 void dummy_get_offline_token(const unsigned char *key, unsigned int keyLengh, OfflineTokenCallback cb, void *arg);
38 int dummy_offline_location(const unsigned char *key, unsigned int keyLength, const unsigned char *token, unsigned int tokenSize, LocationCallback cb, void *arg);
39 void dummy_cell_location(LocationCallback callback, void *arg);
41 static nps_plugin_interface g_dummy = {
43 .unload = dummy_unload,
46 .getOfflineToken = dummy_get_offline_token,
47 .offlineLocation = dummy_offline_location,
48 .cellLocation = dummy_cell_location
51 int nps_is_dummy_plugin_module()
53 return g_is_nps_dummy_module;
56 int nps_load_plugin_module(void **plugin_handle)
58 LOG_NPS(DBG_LOW, "Begin to load NPS plugin module");
60 char plugin_path[256] = {0};
62 strncpy(plugin_path, NPS_PLUGIN_PATH, sizeof(plugin_path));
64 if (access(plugin_path, R_OK) != 0) {
65 LOG_NPS(DBG_ERR, "Failed to access NPS plugin[%s]. Dummy loading", plugin_path);
67 g_is_nps_dummy_module = TRUE;
71 *plugin_handle = dlopen(plugin_path, RTLD_NOW);
72 if (!*plugin_handle) {
73 LOG_NPS(DBG_ERR, "Failed to load plugin module. [%s]", plugin_path);
74 LOG_NPS(DBG_ERR, "%s", dlerror());
78 const nps_plugin_interface *(*get_nps_plugin_interface)();
79 get_nps_plugin_interface = dlsym(*plugin_handle, "get_nps_plugin_interface");
80 if (!get_nps_plugin_interface) {
81 LOG_NPS(DBG_ERR, "Failed to find entry symbol in plugin module.");
82 dlclose(*plugin_handle);
86 g_plugin = get_nps_plugin_interface();
89 LOG_NPS(DBG_ERR, "Failed to find load symbol in plugin module.");
90 dlclose(*plugin_handle);
93 LOG_NPS(DBG_LOW, "Success to load plugin module (%s).", plugin_path);
98 int nps_unload_plugin_module(void *plugin_handle)
100 if (plugin_handle == NULL) {
101 LOG_NPS(DBG_ERR, "plugin_handle is already NULL.");
105 dlclose(plugin_handle);
113 const nps_plugin_interface *get_nps_plugin_module(void)
120 LOG_NPS(DBG_ERR, "Dummy func.");
124 int dummy_unload(void)
126 LOG_NPS(DBG_ERR, "Dummy func.");
130 int dummy_start(unsigned long period, LocationCallback cb, void *arg, void **handle)
132 LOG_NPS(DBG_ERR, "Dummy func.");
136 int dummy_stop(void *handle, CancelCallback cb, void *arg)
138 LOG_NPS(DBG_ERR, "Dummy func.");
142 void dummy_get_offline_token(const unsigned char *key, unsigned int keyLengh, OfflineTokenCallback cb, void *arg)
144 LOG_NPS(DBG_ERR, "Dummy func.");
147 int dummy_offline_location(const unsigned char *key, unsigned int keyLength, const unsigned char *token, unsigned int tokenSize, LocationCallback cb, void *arg)
149 LOG_NPS(DBG_ERR, "Dummy func.");
153 void dummy_cell_location(LocationCallback callback, void *arg)
155 LOG_NPS(DBG_ERR, "Dummy func.");