5f4d378bad493ced68f46e6ba87e34274c8777a7
[platform/core/api/location-manager.git] / src / location_internal.c
1 /*
2  * Copyright (c) 2011-2013 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <string.h>
20 #include <system_info.h>
21 #include "location_internal.h"
22
23 int __convert_error_code(int code)
24 {
25         int ret;
26         const char *msg = NULL;
27         switch (code) {
28                 case LOCATION_ERROR_NONE:
29                         ret = LOCATIONS_ERROR_NONE;
30                         msg = "LOCATIONS_ERROR_NONE";
31                         break;
32                 case LOCATION_ERROR_PARAMETER:
33                         ret = LOCATIONS_ERROR_INVALID_PARAMETER;
34                         msg = "LOCATIONS_ERROR_INVALID_PARAMETER";
35                         break;
36                 case LOCATION_ERROR_NOT_ALLOWED:
37                         ret = LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
38                         msg = "LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED";
39                         break;
40                 case LOCATION_ERROR_NOT_SUPPORTED:
41                         ret = LOCATIONS_ERROR_NOT_SUPPORTED;
42                         msg = "LOCATIONS_ERROR_NOT_SUPPORTED";
43                         break;
44                 case LOCATION_ERROR_NETWORK_FAILED:
45                 case LOCATION_ERROR_NETWORK_NOT_CONNECTED:
46                         ret = LOCATIONS_ERROR_NETWORK_FAILED;
47                         msg = "LOCATIONS_ERROR_NETWORK_FAILED";
48                         break;
49                 case LOCATION_ERROR_SETTING_OFF:
50                         ret = LOCATIONS_ERROR_GPS_SETTING_OFF;
51                         msg = "LOCATIONS_ERROR_GPS_SETTING_OFF";
52                         break;
53                 case LOCATION_ERROR_SECURITY_DENIED:
54                         ret = LOCATIONS_ERROR_SECURITY_RESTRICTED;
55                         msg = "LOCATIONS_ERROR_SECURITY_RESTRICTED";
56                         break;
57                 case LOCATION_ERROR_NOT_AVAILABLE:
58                 case LOCATION_ERROR_CONFIGURATION:
59                 case LOCATION_ERROR_UNKNOWN:
60                 default:
61                         msg = "LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE";
62                         ret = LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
63         }
64
65         if (ret != LOCATIONS_ERROR_NONE) {
66                 LOCATIONS_LOGE("%s(0x%08x) : core fw error(0x%x)", msg, ret, code);
67         }
68         return ret;
69 }
70
71 int __is_gps_supported(void)
72 {
73         bool is_supported = false;
74         int retval = 0;
75
76         retval = system_info_get_platform_bool("http://tizen.org/feature/location.gps", &is_supported);
77         if (retval != SYSTEM_INFO_ERROR_NONE) {
78                 LOCATIONS_LOGW("system_info_get_platform_bool failed: retval = %d", retval);
79         }
80         if (is_supported == false) {
81                 return LOCATIONS_ERROR_NOT_SUPPORTED;
82         }
83         return LOCATIONS_ERROR_NONE;
84 }
85
86 int __is_gps_satellite_supported(void)
87 {
88         bool is_supported = false;
89         int retval = 0;
90
91         retval = system_info_get_platform_bool("http://tizen.org/feature/location.gps.satellite", &is_supported);
92         if (retval != SYSTEM_INFO_ERROR_NONE) {
93                 LOCATIONS_LOGW("system_info_get_platform_bool failed: retval = %d", retval);
94         }
95         if (is_supported == false) {
96                 return LOCATIONS_ERROR_NOT_SUPPORTED;
97         }
98         return LOCATIONS_ERROR_NONE;
99 }
100
101 int __is_wps_supported(void)
102 {
103         bool is_supported = false;
104         int retval = 0;
105
106         retval = system_info_get_platform_bool("http://tizen.org/feature/location.wps", &is_supported);
107         if (retval != SYSTEM_INFO_ERROR_NONE) {
108                 LOCATIONS_LOGW("system_info_get_platform_bool failed: retval = %d", retval);
109         }
110         if (is_supported == false) {
111                 return LOCATIONS_ERROR_NOT_SUPPORTED;
112         }
113         return LOCATIONS_ERROR_NONE;
114 }
115
116 int __is_location_supported(void)
117 {
118         if (__is_gps_supported() == LOCATIONS_ERROR_NOT_SUPPORTED) {
119                 if (__is_wps_supported() == LOCATIONS_ERROR_NOT_SUPPORTED) {
120                         return LOCATIONS_ERROR_NOT_SUPPORTED;
121                 } else {
122                         return LOCATIONS_ERROR_NONE;
123                 }
124         }
125
126         return LOCATIONS_ERROR_NONE;
127 }
128
129 int __set_callback(_location_event_e type, location_manager_h manager, void *callback, void *user_data)
130 {
131         LOCATIONS_NULL_ARG_CHECK(manager);
132         LOCATIONS_NULL_ARG_CHECK(callback);
133         location_manager_s *handle = (location_manager_s *) manager;
134         handle->user_cb[type] = callback;
135         handle->user_data[type] = user_data;
136         LOCATIONS_LOGD("event type : %d", type);
137         return LOCATIONS_ERROR_NONE;
138 }
139
140 int __unset_callback(_location_event_e type, location_manager_h manager)
141 {
142         LOCATIONS_NULL_ARG_CHECK(manager);
143         location_manager_s *handle = (location_manager_s *) manager;
144         handle->user_cb[type] = NULL;
145         handle->user_data[type] = NULL;
146         LOCATIONS_LOGD("event type : %d. ", type);
147         return LOCATIONS_ERROR_NONE;
148 }
149