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.
28 #include <sys/types.h>
32 #include "location-common-util.h"
33 #include "location-setting.h"
34 #include "location-log.h"
35 #include <app_manager.h>
38 int location_application_get_authority(void)
40 return LOCATION_APP_ON;
43 int location_application_set_authority(int auth)
45 return LOCATION_ERROR_NONE;
48 static gint compare_position(gconstpointer a, gconstpointer b)
50 g_return_val_if_fail(a, 1);
51 g_return_val_if_fail(b, -1);
53 if (location_position_equal((LocationPosition *) a, (LocationPosition *)b) == TRUE) {
61 boundary_compare(gconstpointer comp1, gconstpointer comp2)
63 g_return_val_if_fail(comp1, 1);
64 g_return_val_if_fail(comp2, -1);
68 LocationBoundaryPrivate *priv1 = (LocationBoundaryPrivate *)comp1;
69 LocationBoundaryPrivate *priv2 = (LocationBoundaryPrivate *)comp2;
71 if (priv1->boundary->type == priv2->boundary->type) {
72 switch (priv1->boundary->type) {
73 case LOCATION_BOUNDARY_CIRCLE: {
74 if (location_position_equal(priv1->boundary->circle.center, priv2->boundary->circle.center)
75 && priv1->boundary->circle.radius == priv2->boundary->circle.radius) {
80 case LOCATION_BOUNDARY_RECT: {
81 if (location_position_equal(priv1->boundary->rect.left_top, priv2->boundary->rect.left_top)
82 && location_position_equal(priv1->boundary->rect.right_bottom, priv2->boundary->rect.right_bottom)) {
87 case LOCATION_BOUNDARY_POLYGON: {
88 GList *boundary1_next = NULL;
89 GList *boundary2_start = NULL, *boundary2_prev = NULL, *boundary2_next = NULL;
90 if (g_list_length(priv1->boundary->polygon.position_list) != g_list_length(priv2->boundary->polygon.position_list)) {
94 /* Find a matching index of Boundary2 with Boundary1's 1st postion. */
95 boundary2_start = g_list_find_custom(priv2->boundary->polygon.position_list, g_list_nth_data(priv1->boundary->polygon.position_list, 0), (GCompareFunc) compare_position);
96 if (boundary2_start == NULL) return -1;
98 boundary2_prev = g_list_previous(boundary2_start);
99 boundary2_next = g_list_next(boundary2_start);
100 if (boundary2_prev == NULL)
101 boundary2_prev = g_list_last(priv2->boundary->polygon.position_list);
103 if (boundary2_next == NULL)
104 boundary2_next = g_list_first(priv2->boundary->polygon.position_list);
106 boundary1_next = g_list_next(priv1->boundary->polygon.position_list);
107 if (boundary1_next && location_position_equal((LocationPosition *)boundary1_next->data, (LocationPosition *)boundary2_prev->data) == TRUE) {
108 boundary1_next = g_list_next(boundary1_next);
109 while (boundary1_next) {
110 boundary2_prev = g_list_previous(boundary2_prev);
111 if (boundary2_prev == NULL) boundary2_prev = g_list_last(priv2->boundary->polygon.position_list);
112 if (location_position_equal((LocationPosition *)boundary1_next->data, (LocationPosition *) boundary2_prev->data) == FALSE) {
115 boundary1_next = g_list_next(boundary1_next);
118 } else if (boundary1_next && location_position_equal((LocationPosition *)boundary1_next->data, (LocationPosition *)boundary2_next->data) == TRUE) {
119 boundary1_next = g_list_next(boundary1_next);
120 while (boundary1_next) {
121 boundary2_next = g_list_next(boundary2_next);
122 if (boundary2_next == NULL) boundary2_next = g_list_first(priv2->boundary->polygon.position_list);
123 if (location_position_equal((LocationPosition *)boundary1_next->data, (LocationPosition *) boundary2_next->data) == FALSE) {
126 boundary1_next = g_list_next(boundary1_next);
145 int set_prop_boundary(GList **prev_boundary_priv_list, GList *new_boundary_priv_list)
147 LOCATION_LOGD("ENTER >>>");
148 g_return_val_if_fail(new_boundary_priv_list, LOCATION_ERROR_PARAMETER);
151 GList *check_list = NULL;
153 LocationBoundaryPrivate *new_priv = NULL;
155 while ((new_priv = (LocationBoundaryPrivate *) g_list_nth_data(new_boundary_priv_list, index)) != NULL) {
156 *prev_boundary_priv_list = g_list_first(*prev_boundary_priv_list);
157 check_list = g_list_find_custom(*prev_boundary_priv_list, new_priv, (GCompareFunc)boundary_compare);
158 if (check_list == NULL) {
159 LocationBoundaryPrivate *copy_priv = g_slice_new0(LocationBoundaryPrivate);
160 if (!copy_priv) break;
161 copy_priv->boundary = location_boundary_copy(new_priv->boundary);
162 if (!copy_priv->boundary) break;
163 copy_priv->zone_status = new_priv->zone_status;
164 *prev_boundary_priv_list = g_list_append(*prev_boundary_priv_list, copy_priv);
166 LOCATION_LOGD("copy_priv: %p, copy_priv->boundary: %p, copy_priv->boundary->type: %d", copy_priv, copy_priv->boundary, copy_priv->boundary->type);
168 location_boundary_free(new_priv->boundary);
172 return LOCATION_ERROR_NONE;
175 int set_prop_removal_boundary(GList **prev_boundary_list, LocationBoundary *boundary)
177 LOCATION_LOGD("ENTER >>>");
178 g_return_val_if_fail(*prev_boundary_list, LOCATION_ERROR_PARAMETER);
180 GList *check_list = NULL;
181 LocationBoundaryPrivate *remove_priv = g_slice_new0(LocationBoundaryPrivate);
182 g_return_val_if_fail(remove_priv, LOCATION_ERROR_PARAMETER);
184 remove_priv->boundary = location_boundary_copy(boundary);
185 g_return_val_if_fail(remove_priv->boundary, LOCATION_ERROR_PARAMETER);
187 check_list = g_list_find_custom(*prev_boundary_list, remove_priv, (GCompareFunc) boundary_compare);
189 LOCATION_LOGD("Found");
190 *prev_boundary_list = g_list_delete_link(*prev_boundary_list, check_list);
193 if (g_list_length(*prev_boundary_list) == 0) {
194 LOCATION_LOGD("Boundary List is empty");
195 g_list_free(*prev_boundary_list);
196 *prev_boundary_list = NULL;
199 location_boundary_free(remove_priv->boundary);
200 g_slice_free(LocationBoundaryPrivate, remove_priv);
202 LOCATION_LOGD("EXIT <<<");
203 return LOCATION_ERROR_NONE;
206 void free_boundary_list(gpointer data)
208 LocationBoundaryPrivate *priv = (LocationBoundaryPrivate *)data;
210 location_boundary_free(priv->boundary);
211 g_slice_free(LocationBoundaryPrivate, priv);
214 int location_get_app_type(char *target_app_id)
222 if (target_app_id == NULL) {
224 ret = app_manager_get_app_id(pid, &app_id);
225 if (ret != APP_MANAGER_ERROR_NONE) {
226 LOCATION_LOGE("Fail to get app_id. Err[%d]", ret);
227 return LOCATION_ERROR_NONE;
230 app_id = g_strdup(target_app_id);
233 ret = app_info_create(app_id, &app_info);
234 if (ret != APP_MANAGER_ERROR_NONE) {
235 LOCATION_LOGE("Fail to get app_info. Err[%d]", ret);
237 return LOCATION_ERROR_NONE;
240 ret = app_info_get_type(app_info, &type);
241 if (ret != APP_MANAGER_ERROR_NONE) {
242 LOCATION_LOGE("Fail to get type. Err[%d]", ret);
244 app_info_destroy(app_info);
245 return LOCATION_ERROR_NONE;
248 if (strcmp(type, "c++app") == 0)
250 else if (strcmp(type, "webapp") == 0)
257 app_info_destroy(app_info);