4 * Copyright (c) 2010-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 <dbus/dbus-glib.h>
32 #include "location-log.h"
33 #include "location-setting.h"
34 #include "location-ielement.h"
35 #include "location-hybrid.h"
36 #include "location-gps.h"
37 #include "location-wps.h"
38 #include "location-position.h"
39 #include "map-service.h"
40 #include "module-internal.h"
41 #include "location-common-util.h"
44 int location_init (void)
46 LOCATION_LOGD("location_init");
49 #if !GLIB_CHECK_VERSION (2, 31, 0)
50 if (!g_thread_supported()) g_thread_init (NULL);
52 dbus_g_thread_init ();
53 if( FALSE == module_init() )
54 return LOCATION_ERROR_NOT_AVAILABLE;
56 return LOCATION_ERROR_NONE;
59 EXPORT_API LocationObject*
60 location_new (LocationMethod method)
62 LocationObject *self = NULL;
65 case LOCATION_METHOD_HYBRID:
66 self = g_object_new (LOCATION_TYPE_HYBRID, NULL);
68 case LOCATION_METHOD_GPS:
69 self = g_object_new (LOCATION_TYPE_GPS, NULL);
71 case LOCATION_METHOD_WPS:
72 self = g_object_new (LOCATION_TYPE_WPS, NULL);
74 case LOCATION_METHOD_CPS:
79 if (!self) LOCATION_LOGD("Fail to create location object. Method [%d]", method);
84 location_free (LocationObject *obj)
86 g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER);
89 return LOCATION_ERROR_NONE;
93 location_start (LocationObject *obj)
95 g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER);
96 g_return_val_if_fail (G_OBJECT_TYPE(obj) != MAP_TYPE_SERVICE, LOCATION_ERROR_PARAMETER);
98 int ret = LOCATION_ERROR_NONE;
99 ret = location_ielement_start (LOCATION_IELEMENT(obj));
100 if (ret != LOCATION_ERROR_NONE) LOCATION_LOGD("Fail to start. Error [%d]", ret);
106 location_stop (LocationObject *obj)
108 g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER);
109 g_return_val_if_fail (G_OBJECT_TYPE(obj) != MAP_TYPE_SERVICE, LOCATION_ERROR_PARAMETER);
110 int ret = LOCATION_ERROR_NONE;
111 ret = location_ielement_stop (LOCATION_IELEMENT(obj));
112 if (ret != LOCATION_ERROR_NONE) LOCATION_LOGD("Fail to stop. Error [%d]", ret);
118 location_is_supported_method(LocationMethod method)
120 gboolean is_supported = FALSE;
123 case LOCATION_METHOD_HYBRID:
124 if(module_is_supported("gps") || module_is_supported("wps"))
127 case LOCATION_METHOD_GPS:
128 is_supported = module_is_supported("gps");
130 case LOCATION_METHOD_WPS:
131 is_supported = module_is_supported("wps");
133 case LOCATION_METHOD_CPS:
142 location_is_enabled_gps(LocationObject *obj)
144 g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER);
145 g_return_val_if_fail (G_OBJECT_TYPE(obj) != MAP_TYPE_SERVICE, LOCATION_ERROR_PARAMETER);
147 return (gboolean) location_setting_get_int(VCONFKEY_LOCATION_ENABLED);
151 location_get_position (LocationObject *obj,
152 LocationPosition **position,
153 LocationAccuracy **accuracy)
155 g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER);
156 g_return_val_if_fail (G_OBJECT_TYPE(obj) != MAP_TYPE_SERVICE, LOCATION_ERROR_PARAMETER);
157 g_return_val_if_fail (position, LOCATION_ERROR_PARAMETER);
158 g_return_val_if_fail (accuracy, LOCATION_ERROR_PARAMETER);
160 int ret = LOCATION_ERROR_NONE;
161 ret = location_ielement_get_position (LOCATION_IELEMENT(obj), position, accuracy);
162 if (ret != LOCATION_ERROR_NONE) LOCATION_LOGD("Fail to get_position. Error [%d]", ret);
168 location_get_position_ext (LocationObject *obj,
169 LocationPosition **position,
170 LocationVelocity **velocity,
171 LocationAccuracy **accuracy)
173 g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER);
174 g_return_val_if_fail (G_OBJECT_TYPE(obj) != MAP_TYPE_SERVICE, LOCATION_ERROR_PARAMETER);
175 g_return_val_if_fail (position, LOCATION_ERROR_PARAMETER);
176 g_return_val_if_fail (velocity, LOCATION_ERROR_PARAMETER);
177 g_return_val_if_fail (accuracy, LOCATION_ERROR_PARAMETER);
179 int ret = LOCATION_ERROR_NONE;
180 ret = location_ielement_get_position_ext (LOCATION_IELEMENT(obj), position, velocity, accuracy);
181 if (ret != LOCATION_ERROR_NONE) LOCATION_LOGD("Fail to get_position_ext. Error [%d]", ret);
187 location_get_last_position (LocationObject *obj,
188 LocationPosition **position,
189 LocationAccuracy **accuracy)
191 g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER);
192 g_return_val_if_fail (G_OBJECT_TYPE(obj) != MAP_TYPE_SERVICE, LOCATION_ERROR_PARAMETER);
193 g_return_val_if_fail (position, LOCATION_ERROR_PARAMETER);
194 g_return_val_if_fail (accuracy, LOCATION_ERROR_PARAMETER);
196 int ret = LOCATION_ERROR_NONE;
197 ret = location_ielement_get_last_position (LOCATION_IELEMENT(obj), position, accuracy);
198 if (ret != LOCATION_ERROR_NONE) LOCATION_LOGD("Fail to get_last_position. Error [%d]", ret);
204 location_get_last_position_ext (LocationObject *obj,
205 LocationPosition **position,
206 LocationVelocity **velocity,
207 LocationAccuracy **accuracy)
209 g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER);
210 g_return_val_if_fail (G_OBJECT_TYPE(obj) != MAP_TYPE_SERVICE, LOCATION_ERROR_PARAMETER);
211 g_return_val_if_fail (position, LOCATION_ERROR_PARAMETER);
212 g_return_val_if_fail (velocity, LOCATION_ERROR_PARAMETER);
213 g_return_val_if_fail (accuracy, LOCATION_ERROR_PARAMETER);
215 int ret = LOCATION_ERROR_NONE;
216 ret = location_ielement_get_last_position_ext (LOCATION_IELEMENT(obj), position, accuracy);
217 if (ret != LOCATION_ERROR_NONE) LOCATION_LOGD("Fail to get_last_position_ext. Error [%d]", ret);
223 location_get_satellite (LocationObject *obj, LocationSatellite **satellite)
225 g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER);
226 g_return_val_if_fail (G_OBJECT_TYPE(obj) != MAP_TYPE_SERVICE, LOCATION_ERROR_PARAMETER);
227 g_return_val_if_fail (satellite, LOCATION_ERROR_PARAMETER);
229 int ret = LOCATION_ERROR_NONE;
230 ret = location_ielement_get_satellite (LOCATION_IELEMENT(obj), satellite);
231 if (ret != LOCATION_ERROR_NONE) LOCATION_LOGD("Fail to get_satellite. Error [%d]", ret);
237 location_get_last_satellite (LocationObject *obj, LocationSatellite **satellite)
239 g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER);
240 g_return_val_if_fail (G_OBJECT_TYPE(obj) != MAP_TYPE_SERVICE, LOCATION_ERROR_PARAMETER);
241 g_return_val_if_fail (satellite, LOCATION_ERROR_PARAMETER);
243 int ret = LOCATION_ERROR_NONE;
244 ret = location_ielement_get_last_satellite (LOCATION_IELEMENT(obj), satellite);
245 if (ret != LOCATION_ERROR_NONE) LOCATION_LOGD("Fail to get_last_satellite. Error [%d]", ret);
251 location_get_velocity (LocationObject *obj,
252 LocationVelocity **velocity,
253 LocationAccuracy **accuracy)
255 g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER);
256 g_return_val_if_fail (G_OBJECT_TYPE(obj) != MAP_TYPE_SERVICE, LOCATION_ERROR_PARAMETER);
257 g_return_val_if_fail (velocity, LOCATION_ERROR_PARAMETER);
258 g_return_val_if_fail (accuracy, LOCATION_ERROR_PARAMETER);
260 int ret = LOCATION_ERROR_NONE;
261 ret = location_ielement_get_velocity (LOCATION_IELEMENT(obj), velocity, accuracy);
262 if (ret != LOCATION_ERROR_NONE) LOCATION_LOGD("Fail to get_velocity. Error [%d]", ret);
268 location_get_last_velocity (LocationObject *obj,
269 LocationVelocity **velocity,
270 LocationAccuracy **accuracy)
272 g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER);
273 g_return_val_if_fail (G_OBJECT_TYPE(obj) != MAP_TYPE_SERVICE, LOCATION_ERROR_PARAMETER);
274 g_return_val_if_fail (velocity, LOCATION_ERROR_PARAMETER);
275 g_return_val_if_fail (accuracy, LOCATION_ERROR_PARAMETER);
277 int ret = LOCATION_ERROR_NONE;
278 ret = location_ielement_get_last_velocity (LOCATION_IELEMENT(obj), velocity, accuracy);
279 if (ret != LOCATION_ERROR_NONE) LOCATION_LOGD("Fail to get_last_velocity. Error [%d]", ret);
285 location_get_accessibility_state (LocationAccessState *state)
287 int auth = location_application_get_authority ();
289 case LOCATION_APP_OFF:
290 *state = LOCATION_ACCESS_DENIED;
292 case LOCATION_APP_ON:
293 *state = LOCATION_ACCESS_ALLOWED;
295 case LOCATION_APP_NOT_FOUND:
296 *state = LOCATION_ACCESS_NONE;
299 return LOCATION_ERROR_UNKNOWN;
302 LOCATION_LOGD("get_accessibility_state [%d]", auth);
303 return LOCATION_ERROR_NONE;
307 location_set_accessibility_state (LocationAccessState state)
309 int auth = LOCATION_APP_NOT_FOUND;
310 int ret = LOCATION_ERROR_NONE;
313 case LOCATION_ACCESS_DENIED:
314 auth = LOCATION_APP_OFF;
316 case LOCATION_ACCESS_ALLOWED:
317 auth = LOCATION_APP_ON;
319 case LOCATION_ACCESS_NONE:
321 return LOCATION_ERROR_PARAMETER;
324 ret = location_application_set_authority(auth);
325 LOCATION_LOGD("set_accessibility_state [%d], Error[%d]", auth, ret);
330 location_send_command(const char *cmd)
332 g_return_val_if_fail (cmd, LOCATION_ERROR_PARAMETER);
333 return LOCATION_ACCESS_NONE;
337 location_set_option (LocationObject *obj, const char *option)
339 g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER);
340 int ret = LOCATION_ERROR_NONE;