2 * gps-manager replay plugin
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.
29 #include <geoclue_plugin_intf.h>
31 #include "geoclue_plugin_debug.h"
34 int geoclue_plugin_test_load(void);
35 int geoclue_plugin_test_unload(void);
36 int geoclue_plugin_test_location(unsigned long period, LocationCallback cb, void *arg, void **handle);
37 int geoclue_plugin_test_cancel(void *handle, CancelCallback cb, void *arg);
38 void geoclue_plugin_test_get_offline_token(const unsigned char *key,
39 unsigned int keyLengh,
40 OfflineTokenCallback cb,
42 int geoclue_plugin_test_offline_location(const unsigned char *key,
43 unsigned int keyLength,
44 const unsigned char *token,
45 unsigned int tokenSize,
49 static const geoclue_plugin_interface g_geoclue_plugin_interface_test_interface = {
50 geoclue_plugin_test_load,
51 geoclue_plugin_test_unload,
52 geoclue_plugin_test_location,
53 geoclue_plugin_test_cancel,
54 geoclue_plugin_test_get_offline_token,
55 geoclue_plugin_test_offline_location
59 int index; // used for handle
60 plugin_LocationInfo *location;
62 LocationCallback location_cb; // save from location
63 void *arg; // save from location
64 } GeoclueXpsPluginTest;
66 static GeoclueXpsPluginTest *xps_plugint_test = NULL;
68 static gboolean update_fake_position(gpointer data)
70 GeoclueXpsPluginTest *xps_plugin = data;
73 if (xps_plugin->location) {
74 if (xps_plugin->location->latitude < 90) {
75 xps_plugin->location->latitude++;
77 xps_plugin->location->latitude = 0;
79 if (xps_plugin->location->longitude< 180) {
80 xps_plugin->location->longitude++;
82 xps_plugin->location->longitude = 0;
84 if (xps_plugin->location->age < 10000) {
85 xps_plugin->location->age++;
87 xps_plugin->location->age = 0;
89 if (xps_plugin->location->altitude < 5000) {
90 xps_plugin->location->altitude++;
92 xps_plugin->location->altitude = 0;
94 if (xps_plugin->location->bearing < 90) {
95 xps_plugin->location->bearing++;
97 xps_plugin->location->bearing = 0;
99 if (xps_plugin->location->hpe < 100) {
100 xps_plugin->location->hpe++;
102 xps_plugin->location->hpe = 0;
104 if (xps_plugin->location->speed < 250) {
105 xps_plugin->location->speed++;
107 xps_plugin->location->speed = 0;
112 if (xps_plugin->location_cb) {
113 xps_plugin->location_cb(xps_plugin->arg, xps_plugin->location, NULL);
120 int geoclue_plugin_test_load(void)
122 LOG_PLUGIN(LOG_DEBUG, "geoclue_plugin_test_load called");
125 // create plugin_LocationInfo *location
126 if (NULL == xps_plugint_test) {
127 xps_plugint_test = g_new0(GeoclueXpsPluginTest, 1);
128 if (NULL == xps_plugint_test) {
129 LOG_PLUGIN(LOG_ERROR, "[ERROR] GeoclueXpsPluginTest create fail");
132 xps_plugint_test->index = 0;
133 xps_plugint_test->period = 5000; // 5s
134 xps_plugint_test->location = g_new0(plugin_LocationInfo, 1);
135 if (NULL == xps_plugint_test->location) {
136 LOG_PLUGIN(LOG_ERROR, "[ERROR] plugin_LocationInfo create fail");
137 g_free(xps_plugint_test);
140 xps_plugint_test->location->latitude = 10;
141 xps_plugint_test->location->longitude = 10;
142 xps_plugint_test->location->hpe = 10;
143 xps_plugint_test->location->altitude= 10;
144 xps_plugint_test->location->age = 10;
145 xps_plugint_test->location->speed = 10;
146 xps_plugint_test->location->bearing = 10;
151 //g_timeout_add (xps_plugint_test->period, update_fake_position, xps_plugint_test);
152 g_timeout_add (5000, update_fake_position, xps_plugint_test);
156 int geoclue_plugin_test_unload(void)
158 LOG_PLUGIN(LOG_DEBUG, "geoclue_plugin_test_unload called");
160 // free plugin_LocationInfo *location
161 if (xps_plugint_test) {
162 if (xps_plugint_test->location) {
163 g_free(xps_plugint_test->location);
164 xps_plugint_test->location = NULL;
166 g_free(xps_plugint_test);
167 xps_plugint_test = NULL;
173 int geoclue_plugin_test_location(unsigned long period, LocationCallback cb, void *arg, void **handle)
175 LOG_PLUGIN(LOG_DEBUG, "geoclue_plugin_test_location called");
177 // update the plugin_LocationInfo *location in the timer
180 if (xps_plugint_test) {
181 LOG_PLUGIN(LOG_DEBUG, "geoclue_plugin_test_location: before set handle");
182 xps_plugint_test->index++;
183 gchar *tmp = g_strdup_printf("%d", xps_plugint_test->index);
184 *handle = (void *)tmp;
185 LOG_PLUGIN(LOG_DEBUG, "geoclue_plugin_test_location: after set handle, set[%s], handle[%s]", tmp, *handle);
187 // call LocationCallback
189 cb(arg, xps_plugint_test->location, NULL);
190 xps_plugint_test->location_cb = cb;
191 xps_plugint_test->arg = arg;
194 LOG_PLUGIN(LOG_DEBUG, "geoclue_plugin_test_location after call callback");
197 return TRUE; // to test online
198 //return FALSE; // to test the offline
200 int geoclue_plugin_test_cancel(void *handle, CancelCallback cb, void *arg)
202 LOG_PLUGIN(LOG_DEBUG, "geoclue_plugin_test_cancel called");
205 LOG_PLUGIN(LOG_DEBUG, "canel handle %s", handle);
210 // call CancelCallback
217 void geoclue_plugin_test_get_offline_token(const unsigned char *key,
218 unsigned int keyLengh,
219 OfflineTokenCallback cb,
222 LOG_PLUGIN(LOG_DEBUG, "geoclue_plugin_test_get_offline_token called");
224 unsigned char *key_copied = NULL;
225 if (key && keyLengh > 0) {
226 key_copied = g_memdup(key, keyLengh);
227 key_copied[keyLengh - 1] = '\0';
229 LOG_PLUGIN(LOG_DEBUG, "key_copied [%s]", key_copied);
231 // call OfflineTokenCallback
233 char *token = g_strdup("samsung_token");
234 LOG_PLUGIN(LOG_DEBUG, "geoclue_plugin_test_get_offline_token: before callback");
235 cb(arg, token, strlen(token));
236 LOG_PLUGIN(LOG_DEBUG, "geoclue_plugin_test_get_offline_token: after callback");
239 LOG_PLUGIN(LOG_ERROR, "[ERROR] key copy fail");
242 LOG_PLUGIN(LOG_ERROR, "[ERROR] key or keyLengh parameter error");
246 int geoclue_plugin_test_offline_location(const unsigned char *key,
247 unsigned int keyLength,
248 const unsigned char *token,
249 unsigned int tokenSize,
253 LOG_PLUGIN(LOG_DEBUG, "geoclue_plugin_test_offline_location called");
256 if (xps_plugint_test) {
257 LOG_PLUGIN(LOG_DEBUG, "geoclue_plugin_test_offline_location: before callback");
258 cb(arg, xps_plugint_test->location, NULL);
259 LOG_PLUGIN(LOG_DEBUG, "geoclue_plugin_test_offline_location: before callback");
260 xps_plugint_test->location_cb = cb;
261 xps_plugint_test->arg = arg;
267 EXPORT_API const geoclue_plugin_interface *get_geoclue_plugin_interface()
269 LOG_PLUGIN(LOG_DEBUG, "get_geoclue_plugin_interface called");
270 return &g_geoclue_plugin_interface_test_interface;