4 * Copyright (c) 2010-2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Youngae Kang <youngae.kang@samsung.com>, Yunhan Kim <yhan.kim@samsung.com>,
7 * Genie Kim <daejins.kim@samsung.com>, Minjune Kim <sena06.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.
28 #include <dbus/dbus-glib.h>
31 #include "location-log.h"
32 #include "location-setting.h"
33 #include "location-ielement.h"
34 #include "location-hybrid.h"
35 #include "location-gps.h"
36 #include "location-wps.h"
37 #include "location-cps.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:
75 self = g_object_new (LOCATION_TYPE_CPS, NULL);
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);
97 if (FALSE == location_application_enabled()) {
98 LOCATION_LOGD("Application dose not have permission");
99 return LOCATION_ERROR_NOT_ALLOWED;
101 return location_ielement_start (LOCATION_IELEMENT(obj));
105 location_stop (LocationObject *obj)
107 g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER);
108 g_return_val_if_fail (G_OBJECT_TYPE(obj) != MAP_TYPE_SERVICE, LOCATION_ERROR_PARAMETER);
109 return location_ielement_stop (LOCATION_IELEMENT(obj));
113 location_is_supported_method(LocationMethod method)
115 gboolean is_supported = FALSE;
118 case LOCATION_METHOD_HYBRID:
119 if(module_is_supported("gps") || module_is_supported("wps"))
122 case LOCATION_METHOD_GPS:
123 is_supported = module_is_supported("gps");
125 case LOCATION_METHOD_WPS:
126 is_supported = module_is_supported("wps");
128 case LOCATION_METHOD_CPS:
129 is_supported = module_is_supported("cps");
139 location_is_enabled_gps(LocationObject *obj)
141 g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER);
142 g_return_val_if_fail (G_OBJECT_TYPE(obj) != MAP_TYPE_SERVICE, LOCATION_ERROR_PARAMETER);
144 return (gboolean) location_setting_get_int(VCONFKEY_LOCATION_ENABLED);
148 location_get_position (LocationObject *obj,
149 LocationPosition **position,
150 LocationAccuracy **accuracy)
152 g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER);
153 g_return_val_if_fail (G_OBJECT_TYPE(obj) != MAP_TYPE_SERVICE, LOCATION_ERROR_PARAMETER);
154 g_return_val_if_fail (position, LOCATION_ERROR_PARAMETER);
155 g_return_val_if_fail (accuracy, LOCATION_ERROR_PARAMETER);
156 return location_ielement_get_position (LOCATION_IELEMENT(obj), position, accuracy);
160 location_get_last_position (LocationObject *obj,
161 LocationPosition **position,
162 LocationAccuracy **accuracy)
164 g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER);
165 g_return_val_if_fail (G_OBJECT_TYPE(obj) != MAP_TYPE_SERVICE, LOCATION_ERROR_PARAMETER);
166 g_return_val_if_fail (position, LOCATION_ERROR_PARAMETER);
167 g_return_val_if_fail (accuracy, LOCATION_ERROR_PARAMETER);
168 return location_ielement_get_last_position (LOCATION_IELEMENT(obj), position, accuracy);
172 location_get_satellite (LocationObject *obj, LocationSatellite **satellite)
174 g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER);
175 g_return_val_if_fail (G_OBJECT_TYPE(obj) != MAP_TYPE_SERVICE, LOCATION_ERROR_PARAMETER);
176 g_return_val_if_fail (satellite, LOCATION_ERROR_PARAMETER);
178 return location_ielement_get_satellite (LOCATION_IELEMENT(obj), satellite);
182 location_get_last_satellite (LocationObject *obj, LocationSatellite **satellite)
184 g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER);
185 g_return_val_if_fail (G_OBJECT_TYPE(obj) != MAP_TYPE_SERVICE, LOCATION_ERROR_PARAMETER);
186 g_return_val_if_fail (satellite, LOCATION_ERROR_PARAMETER);
188 return location_ielement_get_last_satellite (LOCATION_IELEMENT(obj), satellite);
192 location_get_velocity (LocationObject *obj,
193 LocationVelocity **velocity,
194 LocationAccuracy **accuracy)
196 g_return_val_if_fail (obj, LOCATION_ERROR_PARAMETER);
197 g_return_val_if_fail (G_OBJECT_TYPE(obj) != MAP_TYPE_SERVICE, LOCATION_ERROR_PARAMETER);
198 g_return_val_if_fail (velocity, LOCATION_ERROR_PARAMETER);
199 g_return_val_if_fail (accuracy, LOCATION_ERROR_PARAMETER);
201 return location_ielement_get_velocity (LOCATION_IELEMENT(obj), velocity, accuracy);
205 location_get_last_velocity (LocationObject *obj,
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 (velocity, LOCATION_ERROR_PARAMETER);
212 g_return_val_if_fail (accuracy, LOCATION_ERROR_PARAMETER);
214 return location_ielement_get_last_velocity (LOCATION_IELEMENT(obj), velocity, accuracy);
219 location_send_command(const char *cmd)
221 g_return_val_if_fail (cmd, LOCATION_ERROR_PARAMETER);
223 return LOCATION_ERROR_NONE;