Merge "sync with latest 3.0" into tizen
[platform/core/location/lbs-location.git] / location / manager / location-ielement.c
1 /*
2  * libslp-location
3  *
4  * Copyright (c) 2010-2013 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Youngae Kang <youngae.kang@samsung.com>, Minjune Kim <sena06.kim@samsung.com>
7  *          Genie Kim <daejins.kim@samsung.com>
8  *
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
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
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.
20  */
21
22 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #endif
25
26 #include "location-log.h"
27 #include "location-ielement.h"
28
29 static void
30 location_ielement_base_init(gpointer g_class)
31 {
32         static gboolean is_initialized = FALSE;
33
34         if (is_initialized) {
35                 /* add properties and signals to the interface here */
36
37                 is_initialized = TRUE;
38         }
39 }
40
41 GType
42 location_ielement_get_type(void)
43 {
44         static GType iface_type = 0;
45
46         if (iface_type == 0) {
47                 static const GTypeInfo info = {
48                         sizeof(LocationIElementInterface),
49                         location_ielement_base_init, /* base_init */
50                         NULL /* base_finalize */
51                 };
52
53                 iface_type = g_type_register_static(G_TYPE_INTERFACE, "LocationIElement", &info, 0);
54         }
55
56         return iface_type;
57 }
58
59 int
60 location_ielement_start(LocationIElement *self)
61 {
62         g_return_val_if_fail(LOCATION_IS_IELEMENT(self), LOCATION_ERROR_PARAMETER);
63         g_return_val_if_fail(LOCATION_IELEMENT_GET_INTERFACE(self), LOCATION_ERROR_NOT_AVAILABLE);
64         g_return_val_if_fail(LOCATION_IELEMENT_GET_INTERFACE(self)->start, LOCATION_ERROR_NOT_AVAILABLE);
65         return LOCATION_IELEMENT_GET_INTERFACE(self)->start(self);
66 }
67
68 int
69 location_ielement_stop(LocationIElement *self)
70 {
71         g_return_val_if_fail(LOCATION_IS_IELEMENT(self), LOCATION_ERROR_PARAMETER);
72         g_return_val_if_fail(LOCATION_IELEMENT_GET_INTERFACE(self), LOCATION_ERROR_NOT_AVAILABLE);
73         g_return_val_if_fail(LOCATION_IELEMENT_GET_INTERFACE(self)->stop, LOCATION_ERROR_NOT_AVAILABLE);
74         return LOCATION_IELEMENT_GET_INTERFACE(self)->stop(self);
75 }
76
77 int
78 location_ielement_start_batch(LocationIElement *self)
79 {
80         g_return_val_if_fail(LOCATION_IS_IELEMENT(self), LOCATION_ERROR_PARAMETER);
81         g_return_val_if_fail(LOCATION_IELEMENT_GET_INTERFACE(self), LOCATION_ERROR_NOT_AVAILABLE);
82         g_return_val_if_fail(LOCATION_IELEMENT_GET_INTERFACE(self)->start_batch, LOCATION_ERROR_NOT_AVAILABLE);
83         return LOCATION_IELEMENT_GET_INTERFACE(self)->start_batch(self);
84 }
85
86 int
87 location_ielement_stop_batch(LocationIElement *self)
88 {
89         g_return_val_if_fail(LOCATION_IS_IELEMENT(self), LOCATION_ERROR_PARAMETER);
90         g_return_val_if_fail(LOCATION_IELEMENT_GET_INTERFACE(self), LOCATION_ERROR_NOT_AVAILABLE);
91         g_return_val_if_fail(LOCATION_IELEMENT_GET_INTERFACE(self)->stop_batch, LOCATION_ERROR_NOT_AVAILABLE);
92         return LOCATION_IELEMENT_GET_INTERFACE(self)->stop_batch(self);
93 }
94
95 int
96 location_ielement_request_single_location(LocationIElement *self, int timeout)
97 {
98         g_return_val_if_fail(LOCATION_IS_IELEMENT(self), LOCATION_ERROR_PARAMETER);
99         g_return_val_if_fail(LOCATION_IELEMENT_GET_INTERFACE(self), LOCATION_ERROR_NOT_AVAILABLE);
100         g_return_val_if_fail(LOCATION_IELEMENT_GET_INTERFACE(self)->request_single_location, LOCATION_ERROR_NOT_AVAILABLE);
101
102         return LOCATION_IELEMENT_GET_INTERFACE(self)->request_single_location(self, timeout);
103 }
104
105 int
106 location_ielement_cancel_single_location(LocationIElement *self)
107 {
108         g_return_val_if_fail(LOCATION_IS_IELEMENT(self), LOCATION_ERROR_PARAMETER);
109         g_return_val_if_fail(LOCATION_IELEMENT_GET_INTERFACE(self), LOCATION_ERROR_NOT_AVAILABLE);
110         g_return_val_if_fail(LOCATION_IELEMENT_GET_INTERFACE(self)->cancel_single_location, LOCATION_ERROR_NOT_AVAILABLE);
111
112         return LOCATION_IELEMENT_GET_INTERFACE(self)->cancel_single_location(self);
113 }
114
115 int
116 location_ielement_get_position(LocationIElement *self, LocationPosition **position, LocationAccuracy **accuracy)
117 {
118         g_return_val_if_fail(LOCATION_IS_IELEMENT(self), LOCATION_ERROR_PARAMETER);
119         g_return_val_if_fail(position, LOCATION_ERROR_PARAMETER);
120         g_return_val_if_fail(accuracy, LOCATION_ERROR_PARAMETER);
121         g_return_val_if_fail(LOCATION_IELEMENT_GET_INTERFACE(self), LOCATION_ERROR_NOT_AVAILABLE);
122         g_return_val_if_fail(LOCATION_IELEMENT_GET_INTERFACE(self)->get_position, LOCATION_ERROR_NOT_AVAILABLE);
123
124         return LOCATION_IELEMENT_GET_INTERFACE(self)->get_position(self, position, accuracy);
125 }
126
127 int
128 location_ielement_get_position_ext(LocationIElement *self, LocationPosition **position, LocationVelocity **velocity, LocationAccuracy **accuracy)
129 {
130         g_return_val_if_fail(LOCATION_IS_IELEMENT(self), LOCATION_ERROR_PARAMETER);
131         g_return_val_if_fail(position, LOCATION_ERROR_PARAMETER);
132         g_return_val_if_fail(velocity, LOCATION_ERROR_PARAMETER);
133         g_return_val_if_fail(accuracy, LOCATION_ERROR_PARAMETER);
134         g_return_val_if_fail(LOCATION_IELEMENT_GET_INTERFACE(self), LOCATION_ERROR_NOT_AVAILABLE);
135         g_return_val_if_fail(LOCATION_IELEMENT_GET_INTERFACE(self)->get_position_ext, LOCATION_ERROR_NOT_AVAILABLE);
136
137         return LOCATION_IELEMENT_GET_INTERFACE(self)->get_position_ext(self, position, velocity, accuracy);
138 }
139
140
141 int
142 location_ielement_get_last_position(LocationIElement *self, LocationPosition **position, LocationAccuracy **accuracy)
143 {
144         g_return_val_if_fail(LOCATION_IS_IELEMENT(self), LOCATION_ERROR_PARAMETER);
145         g_return_val_if_fail(position, LOCATION_ERROR_PARAMETER);
146         g_return_val_if_fail(accuracy, LOCATION_ERROR_PARAMETER);
147         g_return_val_if_fail(LOCATION_IELEMENT_GET_INTERFACE(self), LOCATION_ERROR_NOT_AVAILABLE);
148         g_return_val_if_fail(LOCATION_IELEMENT_GET_INTERFACE(self)->get_last_position, LOCATION_ERROR_NOT_AVAILABLE);
149
150         return LOCATION_IELEMENT_GET_INTERFACE(self)->get_last_position(self, position, accuracy);
151 }
152
153 int
154 location_ielement_get_last_position_ext(LocationIElement *self, LocationPosition **position, LocationVelocity **velocity, LocationAccuracy **accuracy)
155 {
156         g_return_val_if_fail(LOCATION_IS_IELEMENT(self), LOCATION_ERROR_PARAMETER);
157         g_return_val_if_fail(position, LOCATION_ERROR_PARAMETER);
158         g_return_val_if_fail(velocity, LOCATION_ERROR_PARAMETER);
159         g_return_val_if_fail(accuracy, LOCATION_ERROR_PARAMETER);
160         g_return_val_if_fail(LOCATION_IELEMENT_GET_INTERFACE(self), LOCATION_ERROR_NOT_AVAILABLE);
161         g_return_val_if_fail(LOCATION_IELEMENT_GET_INTERFACE(self)->get_last_position_ext, LOCATION_ERROR_NOT_AVAILABLE);
162
163         return LOCATION_IELEMENT_GET_INTERFACE(self)->get_last_position_ext(self, position, velocity, accuracy);
164 }
165
166
167 int
168 location_ielement_get_batch(LocationIElement *self, LocationBatch **batch)
169 {
170         g_return_val_if_fail(LOCATION_IS_IELEMENT(self), LOCATION_ERROR_PARAMETER);
171         g_return_val_if_fail(batch, LOCATION_ERROR_PARAMETER);
172         g_return_val_if_fail(LOCATION_IELEMENT_GET_INTERFACE(self), LOCATION_ERROR_NOT_AVAILABLE);
173         g_return_val_if_fail(LOCATION_IELEMENT_GET_INTERFACE(self)->get_batch, LOCATION_ERROR_NOT_AVAILABLE);
174
175         return LOCATION_IELEMENT_GET_INTERFACE(self)->get_batch(self, batch);
176 }
177
178 int
179 location_ielement_get_satellite(LocationIElement *self,
180                                                                 LocationSatellite **satellite)
181 {
182         g_return_val_if_fail(LOCATION_IS_IELEMENT(self), LOCATION_ERROR_PARAMETER);
183         g_return_val_if_fail(satellite, LOCATION_ERROR_PARAMETER);
184         g_return_val_if_fail(LOCATION_IELEMENT_GET_INTERFACE(self), LOCATION_ERROR_NOT_AVAILABLE);
185         g_return_val_if_fail(LOCATION_IELEMENT_GET_INTERFACE(self)->get_satellite, LOCATION_ERROR_NOT_AVAILABLE);
186
187         return LOCATION_IELEMENT_GET_INTERFACE(self)->get_satellite(self, satellite);
188 }
189
190 int
191 location_ielement_get_last_satellite(LocationIElement *self, LocationSatellite **satellite)
192 {
193         g_return_val_if_fail(LOCATION_IS_IELEMENT(self), LOCATION_ERROR_PARAMETER);
194         g_return_val_if_fail(satellite, LOCATION_ERROR_PARAMETER);
195         g_return_val_if_fail(LOCATION_IELEMENT_GET_INTERFACE(self), LOCATION_ERROR_NOT_AVAILABLE);
196         g_return_val_if_fail(LOCATION_IELEMENT_GET_INTERFACE(self)->get_last_satellite, LOCATION_ERROR_NOT_AVAILABLE);
197
198         return LOCATION_IELEMENT_GET_INTERFACE(self)->get_last_satellite(self, satellite);
199 }
200
201 int
202 location_ielement_get_velocity(LocationIElement *self, LocationVelocity **velocity, LocationAccuracy **accuracy)
203 {
204         g_return_val_if_fail(LOCATION_IS_IELEMENT(self), LOCATION_ERROR_PARAMETER);
205         g_return_val_if_fail(velocity, LOCATION_ERROR_PARAMETER);
206         g_return_val_if_fail(LOCATION_IELEMENT_GET_INTERFACE(self), LOCATION_ERROR_NOT_AVAILABLE);
207         g_return_val_if_fail(LOCATION_IELEMENT_GET_INTERFACE(self)->get_velocity, LOCATION_ERROR_NOT_AVAILABLE);
208         return LOCATION_IELEMENT_GET_INTERFACE(self)->get_velocity(self, velocity, accuracy);
209 }
210
211 int
212 location_ielement_get_last_velocity(LocationIElement *self, LocationVelocity **velocity, LocationAccuracy **accuracy)
213 {
214         g_return_val_if_fail(LOCATION_IS_IELEMENT(self), LOCATION_ERROR_PARAMETER);
215         g_return_val_if_fail(velocity, LOCATION_ERROR_PARAMETER);
216         g_return_val_if_fail(LOCATION_IELEMENT_GET_INTERFACE(self), LOCATION_ERROR_NOT_AVAILABLE);
217         g_return_val_if_fail(LOCATION_IELEMENT_GET_INTERFACE(self)->get_last_velocity, LOCATION_ERROR_NOT_AVAILABLE);
218         return LOCATION_IELEMENT_GET_INTERFACE(self)->get_last_velocity(self, velocity, accuracy);
219 }
220
221 int
222 location_ielement_set_option(LocationIElement *self, const char *option)
223 {
224         g_return_val_if_fail(LOCATION_IS_IELEMENT(self), LOCATION_ERROR_PARAMETER);
225         g_return_val_if_fail(LOCATION_IELEMENT_GET_INTERFACE(self), LOCATION_ERROR_NOT_AVAILABLE);
226         return LOCATION_IELEMENT_GET_INTERFACE(self)->set_option(self, option);
227 }
228
229 int
230 location_ielement_get_nmea(LocationIElement *self, char **nmea)
231 {
232         g_return_val_if_fail(LOCATION_IS_IELEMENT(self), LOCATION_ERROR_PARAMETER);
233         g_return_val_if_fail(nmea, LOCATION_ERROR_PARAMETER);
234         g_return_val_if_fail(LOCATION_IELEMENT_GET_INTERFACE(self), LOCATION_ERROR_NOT_AVAILABLE);
235         g_return_val_if_fail(LOCATION_IELEMENT_GET_INTERFACE(self)->get_nmea, LOCATION_ERROR_NOT_AVAILABLE);
236
237         return LOCATION_IELEMENT_GET_INTERFACE(self)->get_nmea(self, nmea);
238 }
239
240
241 /* Tizen 3.0 */
242 int location_ielement_set_mock_location(LocationIElement *self, const LocationPosition *position, const LocationVelocity *velocity, const LocationAccuracy *accuracy)
243 {
244         g_return_val_if_fail(LOCATION_IS_IELEMENT(self), LOCATION_ERROR_PARAMETER);
245         g_return_val_if_fail(position, LOCATION_ERROR_PARAMETER);
246         g_return_val_if_fail(velocity, LOCATION_ERROR_PARAMETER);
247         g_return_val_if_fail(accuracy, LOCATION_ERROR_PARAMETER);
248         g_return_val_if_fail(LOCATION_IELEMENT_GET_INTERFACE(self), LOCATION_ERROR_NOT_AVAILABLE);
249         g_return_val_if_fail(LOCATION_IELEMENT_GET_INTERFACE(self)->set_mock_location, LOCATION_ERROR_NOT_AVAILABLE);
250
251         return LOCATION_IELEMENT_GET_INTERFACE(self)->set_mock_location(self, position, velocity, accuracy);
252 }
253
254 int location_ielement_clear_mock_location(LocationIElement *self)
255 {
256         g_return_val_if_fail(LOCATION_IS_IELEMENT(self), LOCATION_ERROR_PARAMETER);
257         g_return_val_if_fail(LOCATION_IELEMENT_GET_INTERFACE(self), LOCATION_ERROR_NOT_AVAILABLE);
258         g_return_val_if_fail(LOCATION_IELEMENT_GET_INTERFACE(self)->clear_mock_location, LOCATION_ERROR_NOT_AVAILABLE);
259
260         return LOCATION_IELEMENT_GET_INTERFACE(self)->clear_mock_location(self);
261 }
262