Remove tv profile dependency for cynara
[platform/core/location/lbs-location.git] / location / manager / location-common-util.c
index 0b533a2..e7aa284 100644 (file)
@@ -3,9 +3,6 @@
  *
  * Copyright (c) 2010-2013 Samsung Electronics Co., Ltd. All rights reserved.
  *
- * Contact: Youngae Kang <youngae.kang@samsung.com>, Minjune Kim <sena06.kim@samsung.com>
- *          Genie Kim <daejins.kim@samsung.com>
- *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
@@ -32,6 +29,7 @@
 #include "location-common-util.h"
 #include "location-setting.h"
 #include "location-log.h"
+#include <app_manager.h>
 
 
 int location_application_get_authority(void)
@@ -49,9 +47,8 @@ static gint compare_position(gconstpointer a, gconstpointer b)
        g_return_val_if_fail(a, 1);
        g_return_val_if_fail(b, -1);
 
-       if (location_position_equal((LocationPosition *) a, (LocationPosition *)b) == TRUE) {
+       if (location_position_equal((LocationPosition *) a, (LocationPosition *)b) == TRUE)
                return 0;
-       }
 
        return -1;
 }
@@ -71,14 +68,14 @@ boundary_compare(gconstpointer comp1, gconstpointer comp2)
                switch (priv1->boundary->type) {
                        case LOCATION_BOUNDARY_CIRCLE: {
                                        if (location_position_equal(priv1->boundary->circle.center, priv2->boundary->circle.center)
-                                           && priv1->boundary->circle.radius == priv2->boundary->circle.radius) {
+                                               && priv1->boundary->circle.radius == priv2->boundary->circle.radius) {
                                                ret = 0;
                                        }
                                        break;
                                }
                        case LOCATION_BOUNDARY_RECT: {
                                        if (location_position_equal(priv1->boundary->rect.left_top, priv2->boundary->rect.left_top)
-                                           && location_position_equal(priv1->boundary->rect.right_bottom, priv2->boundary->rect.right_bottom)) {
+                                               && location_position_equal(priv1->boundary->rect.right_bottom, priv2->boundary->rect.right_bottom)) {
                                                ret = 0;
                                        }
                                        break;
@@ -86,9 +83,8 @@ boundary_compare(gconstpointer comp1, gconstpointer comp2)
                        case LOCATION_BOUNDARY_POLYGON: {
                                        GList *boundary1_next = NULL;
                                        GList *boundary2_start = NULL, *boundary2_prev = NULL, *boundary2_next = NULL;
-                                       if (g_list_length(priv1->boundary->polygon.position_list) != g_list_length(priv2->boundary->polygon.position_list)) {
+                                       if (g_list_length(priv1->boundary->polygon.position_list) != g_list_length(priv2->boundary->polygon.position_list))
                                                return -1;
-                                       }
 
                                        /* Find a matching index of Boundary2 with Boundary1's 1st postion. */
                                        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,18 +92,23 @@ boundary_compare(gconstpointer comp1, gconstpointer comp2)
 
                                        boundary2_prev = g_list_previous(boundary2_start);
                                        boundary2_next = g_list_next(boundary2_start);
-                                       if (boundary2_prev == NULL) boundary2_prev = g_list_last(priv2->boundary->polygon.position_list);
-                                       if (boundary2_next == NULL) boundary2_next = g_list_first(priv2->boundary->polygon.position_list);
+                                       if (boundary2_prev == NULL)
+                                               boundary2_prev = g_list_last(priv2->boundary->polygon.position_list);
+
+                                       if (boundary2_next == NULL)
+                                               boundary2_next = g_list_first(priv2->boundary->polygon.position_list);
 
                                        boundary1_next = g_list_next(priv1->boundary->polygon.position_list);
                                        if (boundary1_next && location_position_equal((LocationPosition *)boundary1_next->data, (LocationPosition *)boundary2_prev->data) == TRUE) {
                                                boundary1_next = g_list_next(boundary1_next);
                                                while (boundary1_next) {
                                                        boundary2_prev = g_list_previous(boundary2_prev);
-                                                       if (boundary2_prev == NULL) boundary2_prev = g_list_last(priv2->boundary->polygon.position_list);
-                                                       if (location_position_equal((LocationPosition *)boundary1_next->data, (LocationPosition *) boundary2_prev->data) == FALSE) {
+                                                       if (boundary2_prev == NULL)
+                                                               boundary2_prev = g_list_last(priv2->boundary->polygon.position_list);
+
+                                                       if (location_position_equal((LocationPosition *)boundary1_next->data, (LocationPosition *) boundary2_prev->data) == FALSE)
                                                                return -1;
-                                                       }
+
                                                        boundary1_next = g_list_next(boundary1_next);
                                                }
                                                ret = 0;
@@ -115,10 +116,12 @@ boundary_compare(gconstpointer comp1, gconstpointer comp2)
                                                boundary1_next = g_list_next(boundary1_next);
                                                while (boundary1_next) {
                                                        boundary2_next = g_list_next(boundary2_next);
-                                                       if (boundary2_next == NULL) boundary2_next = g_list_first(priv2->boundary->polygon.position_list);
-                                                       if (location_position_equal((LocationPosition *)boundary1_next->data, (LocationPosition *) boundary2_next->data) == FALSE) {
+                                                       if (boundary2_next == NULL)
+                                                               boundary2_next = g_list_first(priv2->boundary->polygon.position_list);
+
+                                                       if (location_position_equal((LocationPosition *)boundary1_next->data, (LocationPosition *) boundary2_next->data) == FALSE)
                                                                return -1;
-                                                       }
+
                                                        boundary1_next = g_list_next(boundary1_next);
                                                }
                                                ret = 0;
@@ -140,7 +143,7 @@ boundary_compare(gconstpointer comp1, gconstpointer comp2)
 
 int set_prop_boundary(GList **prev_boundary_priv_list, GList *new_boundary_priv_list)
 {
-       LOCATION_LOGD("ENTER >>>");
+       LOC_FUNC_LOG
        g_return_val_if_fail(new_boundary_priv_list, LOCATION_ERROR_PARAMETER);
 
        int index = 0;
@@ -159,20 +162,18 @@ int set_prop_boundary(GList **prev_boundary_priv_list, GList *new_boundary_priv_
                        copy_priv->zone_status = new_priv->zone_status;
                        *prev_boundary_priv_list = g_list_append(*prev_boundary_priv_list, copy_priv);
 
-                       LOCATION_LOGD("copy_priv: %p, copy_priv->boundary: %p, copy_priv->boundary->type: %d",
-                                     copy_priv, copy_priv->boundary, copy_priv->boundary->type);
+                       LOCATION_LOGD("copy_priv: %p, copy_priv->boundary: %p, copy_priv->boundary->type: %d", copy_priv, copy_priv->boundary, copy_priv->boundary->type);
                }
                location_boundary_free(new_priv->boundary);
                index++;
        }
 
-       LOCATION_LOGD("EXIT <<<");
        return LOCATION_ERROR_NONE;
 }
 
 int set_prop_removal_boundary(GList **prev_boundary_list, LocationBoundary *boundary)
 {
-       LOCATION_LOGD("ENTER >>>");
+       LOC_FUNC_LOG
        g_return_val_if_fail(*prev_boundary_list, LOCATION_ERROR_PARAMETER);
 
        GList *check_list = NULL;
@@ -208,3 +209,67 @@ void free_boundary_list(gpointer data)
        location_boundary_free(priv->boundary);
        g_slice_free(LocationBoundaryPrivate, priv);
 }
+
+int location_get_app_type(char *target_app_id)
+{
+       int ret = 0;
+       pid_t pid = 0;
+       char *app_id = NULL;
+       app_info_h app_info;
+       char *type = NULL;
+
+       if (target_app_id == NULL) {
+               pid = getpid();
+               ret = app_manager_get_app_id(pid, &app_id);
+               LOC_COND_RET(ret != APP_MANAGER_ERROR_NONE, LOCATION_ERROR_NONE, _E, "Fail to get app_id. Err[%d]", ret);
+       } else {
+               app_id = g_strdup(target_app_id);
+       }
+
+       ret = app_info_create(app_id, &app_info);
+       if (ret != APP_MANAGER_ERROR_NONE) {
+               LOCATION_LOGE("Fail to get app_info. Err[%d]", ret);
+               g_free(app_id);
+               return LOCATION_ERROR_NONE;
+       }
+
+       ret = app_info_get_type(app_info, &type);
+       if (ret != APP_MANAGER_ERROR_NONE) {
+               LOCATION_LOGE("Fail to get type. Err[%d]", ret);
+               g_free(app_id);
+               app_info_destroy(app_info);
+               return LOCATION_ERROR_NONE;
+       }
+
+       if (strcmp(type, "c++app") == 0)
+               ret = CPPAPP;
+       else if (strcmp(type, "webapp") == 0)
+               ret = WEBAPP;
+       else
+               ret = CAPP;
+
+       g_free(type);
+       g_free(app_id);
+       app_info_destroy(app_info);
+
+       return ret;
+}
+
+const char* err_msg(int err)
+{
+       switch (err) {
+       case LOCATION_ERROR_NONE: return "LOCATION_ERROR_NONE";
+       case LOCATION_ERROR_NOT_ALLOWED: return "LOCATION_ERROR_NOT_ALLOWED";
+       case LOCATION_ERROR_NOT_AVAILABLE: return "LOCATION_ERROR_NOT_AVAILABLE";
+       case LOCATION_ERROR_NETWORK_FAILED: return "LOCATION_ERROR_NETWORK_FAILED";
+       case LOCATION_ERROR_NETWORK_NOT_CONNECTED: return "LOCATION_ERROR_NETWORK_NOT_CONNECTED";
+       case LOCATION_ERROR_CONFIGURATION: return "LOCATION_ERROR_CONFIGURATION";
+       case LOCATION_ERROR_PARAMETER: return "LOCATION_ERROR_PARAMETER";
+       case LOCATION_ERROR_NOT_FOUND: return "LOCATION_ERROR_NOT_FOUND";
+       case LOCATION_ERROR_NOT_SUPPORTED: return "LOCATION_ERROR_NOT_SUPPORTED";
+       case LOCATION_ERROR_UNKNOWN: return "LOCATION_ERROR_UNKNOWN";
+       case LOCATION_ERROR_SETTING_OFF: return "LOCATION_ERROR_SETTING_OFF";
+       case LOCATION_ERROR_SECURITY_DENIED: return "LOCATION_ERROR_SECURITY_DENIED";
+       default: return "LOCATION_ERROR_UNKNOWN";
+       }
+}