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, unsigned int keyLengh, OfflineTokenCallback cb, void *arg);
39 int geoclue_plugin_test_offline_location(const unsigned char *key,
40 unsigned int keyLength,
41 const unsigned char *token,
42 unsigned int tokenSize,
46 static const geoclue_plugin_interface g_geoclue_plugin_interface_test_interface = {
47 geoclue_plugin_test_load,
48 geoclue_plugin_test_unload,
49 geoclue_plugin_test_location,
50 geoclue_plugin_test_cancel,
51 geoclue_plugin_test_get_offline_token,
52 geoclue_plugin_test_offline_location
56 int index; /* used for handle */
57 plugin_LocationInfo *location;
59 LocationCallback location_cb; /* save from location */
60 void *arg; /* save from location */
61 } GeoclueXpsPluginTest;
63 static GeoclueXpsPluginTest *xps_plugint_test = NULL;
65 static gboolean update_fake_position(gpointer data)
67 GeoclueXpsPluginTest *xps_plugin = data;
70 if (xps_plugin->location) {
71 if (xps_plugin->location->latitude < 90) {
72 xps_plugin->location->latitude++;
74 xps_plugin->location->latitude = 0;
76 if (xps_plugin->location->longitude < 180) {
77 xps_plugin->location->longitude++;
79 xps_plugin->location->longitude = 0;
81 if (xps_plugin->location->age < 10000) {
82 xps_plugin->location->age++;
84 xps_plugin->location->age = 0;
86 if (xps_plugin->location->altitude < 5000) {
87 xps_plugin->location->altitude++;
89 xps_plugin->location->altitude = 0;
91 if (xps_plugin->location->bearing < 90) {
92 xps_plugin->location->bearing++;
94 xps_plugin->location->bearing = 0;
96 if (xps_plugin->location->hpe < 100) {
97 xps_plugin->location->hpe++;
99 xps_plugin->location->hpe = 0;
101 if (xps_plugin->location->speed < 250) {
102 xps_plugin->location->speed++;
104 xps_plugin->location->speed = 0;
108 /* called intervals */
109 if (xps_plugin->location_cb) {
110 xps_plugin->location_cb(xps_plugin->arg, xps_plugin->location, NULL);
117 int geoclue_plugin_test_load(void)
119 LOG_PLUGIN(LOG_DEBUG, "geoclue_plugin_test_load called");
122 /* create plugin_LocationInfo *location */
123 if (NULL == xps_plugint_test) {
124 xps_plugint_test = g_new0(GeoclueXpsPluginTest, 1);
125 if (NULL == xps_plugint_test) {
126 LOG_PLUGIN(LOG_ERROR, "[ERROR] GeoclueXpsPluginTest create fail");
129 xps_plugint_test->index = 0;
130 xps_plugint_test->period = 5000; /* 5s */
131 xps_plugint_test->location = g_new0(plugin_LocationInfo, 1);
132 if (NULL == xps_plugint_test->location) {
133 LOG_PLUGIN(LOG_ERROR, "[ERROR] plugin_LocationInfo create fail");
134 g_free(xps_plugint_test);
137 xps_plugint_test->location->latitude = 10;
138 xps_plugint_test->location->longitude = 10;
139 xps_plugint_test->location->hpe = 10;
140 xps_plugint_test->location->altitude = 10;
141 xps_plugint_test->location->age = 10;
142 xps_plugint_test->location->speed = 10;
143 xps_plugint_test->location->bearing = 10;
147 /* create the timer */
148 /*g_timeout_add (xps_plugint_test->period, update_fake_position, xps_plugint_test); */
149 g_timeout_add(5000, update_fake_position, xps_plugint_test);
153 int geoclue_plugin_test_unload(void)
155 LOG_PLUGIN(LOG_DEBUG, "geoclue_plugin_test_unload called");
157 /* free plugin_LocationInfo *location */
158 if (xps_plugint_test) {
159 if (xps_plugint_test->location) {
160 g_free(xps_plugint_test->location);
161 xps_plugint_test->location = NULL;
163 g_free(xps_plugint_test);
164 xps_plugint_test = NULL;
170 int geoclue_plugin_test_location(unsigned long period, LocationCallback cb, void *arg, void **handle)
172 LOG_PLUGIN(LOG_DEBUG, "geoclue_plugin_test_location called");
174 /* update the plugin_LocationInfo *location in the timer */
177 if (xps_plugint_test) {
178 LOG_PLUGIN(LOG_DEBUG, "geoclue_plugin_test_location: before set handle");
179 xps_plugint_test->index++;
180 gchar *tmp = g_strdup_printf("%d", xps_plugint_test->index);
181 *handle = (void *)tmp;
182 LOG_PLUGIN(LOG_DEBUG, "geoclue_plugin_test_location: after set handle, set[%s], handle[%s]", tmp, *handle);
184 /* call LocationCallback */
186 cb(arg, xps_plugint_test->location, NULL);
187 xps_plugint_test->location_cb = cb;
188 xps_plugint_test->arg = arg;
191 LOG_PLUGIN(LOG_DEBUG, "geoclue_plugin_test_location after call callback");
194 return TRUE; /* to test online */
195 /*return FALSE; // to test the offline */
197 int geoclue_plugin_test_cancel(void *handle, CancelCallback cb, void *arg)
199 LOG_PLUGIN(LOG_DEBUG, "geoclue_plugin_test_cancel called");
202 LOG_PLUGIN(LOG_DEBUG, "canel handle %s", handle);
207 /* call CancelCallback */
214 void geoclue_plugin_test_get_offline_token(const unsigned char *key, unsigned int keyLengh, OfflineTokenCallback cb, void *arg)
216 LOG_PLUGIN(LOG_DEBUG, "geoclue_plugin_test_get_offline_token called");
218 unsigned char *key_copied = NULL;
219 if (key && keyLengh > 0) {
220 key_copied = g_memdup(key, keyLengh);
221 key_copied[keyLengh - 1] = '\0';
223 LOG_PLUGIN(LOG_DEBUG, "key_copied [%s]", key_copied);
225 /* call OfflineTokenCallback */
227 char *token = g_strdup("samsung_token");
228 LOG_PLUGIN(LOG_DEBUG, "geoclue_plugin_test_get_offline_token: before callback");
229 cb(arg, token, strlen(token));
230 LOG_PLUGIN(LOG_DEBUG, "geoclue_plugin_test_get_offline_token: after callback");
233 LOG_PLUGIN(LOG_ERROR, "[ERROR] key copy fail");
236 LOG_PLUGIN(LOG_ERROR, "[ERROR] key or keyLengh parameter error");
240 int geoclue_plugin_test_offline_location(const unsigned char *key,
241 unsigned int keyLength,
242 const unsigned char *token,
243 unsigned int tokenSize,
247 LOG_PLUGIN(LOG_DEBUG, "geoclue_plugin_test_offline_location called");
250 if (xps_plugint_test) {
251 LOG_PLUGIN(LOG_DEBUG, "geoclue_plugin_test_offline_location: before callback");
252 cb(arg, xps_plugint_test->location, NULL);
253 LOG_PLUGIN(LOG_DEBUG, "geoclue_plugin_test_offline_location: before callback");
254 xps_plugint_test->location_cb = cb;
255 xps_plugint_test->arg = arg;
261 EXPORT_API const geoclue_plugin_interface *get_geoclue_plugin_interface()
263 LOG_PLUGIN(LOG_DEBUG, "get_geoclue_plugin_interface called");
264 return &g_geoclue_plugin_interface_test_interface;