2 * Copyright (c) 2011-2013 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 #include <system_info.h>
21 #include "location_internal.h"
22 #include "location_batch.h"
26 * Internal Implementation
29 static void __cb_batch_updated(GObject *self, guint num_of_location, gpointer userdata)
31 LOCATIONS_LOGD("Batch callback function has been invoked.");
32 location_manager_s *handle = (location_manager_s *) userdata;
34 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_BATCH]) {
35 ((location_batch_cb) handle->user_cb[_LOCATIONS_EVENT_TYPE_BATCH])(num_of_location, handle->user_data[_LOCATIONS_EVENT_TYPE_BATCH]);
39 /*/////////////////////////////////////// */
40 /* Location Manager */
41 /*////////////////////////////////////// */
43 EXPORT_API int location_manager_set_location_batch_cb(location_manager_h manager, location_batch_cb callback, int batch_interval, int batch_period, void *user_data)
45 LOCATIONS_LOGD("location_manager_set_location_batch_cb");
46 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
48 LOCATIONS_CHECK_CONDITION(batch_interval >= 1 && batch_interval <= 120, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
49 LOCATIONS_CHECK_CONDITION(batch_period >= 120 && batch_period <= 600, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
50 LOCATIONS_NULL_ARG_CHECK(manager);
51 LOCATIONS_NULL_ARG_CHECK(callback);
52 location_manager_s *handle = (location_manager_s *) manager;
53 g_object_set(handle->object, "batch-period", batch_period, NULL);
54 g_object_set(handle->object, "batch-interval", batch_interval, NULL);
55 return __set_callback(_LOCATIONS_EVENT_TYPE_BATCH, manager, callback, user_data);
58 EXPORT_API int location_manager_unset_location_batch_cb(location_manager_h manager)
60 LOCATIONS_LOGD("location_manager_unset_location_batch_cb");
61 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
62 return __unset_callback(_LOCATIONS_EVENT_TYPE_BATCH, manager);
65 EXPORT_API int location_manager_start_batch(location_manager_h manager)
67 LOCATIONS_LOGD("location_manager_start_batch");
68 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
69 LOCATIONS_NULL_ARG_CHECK(manager);
70 location_manager_s *handle = (location_manager_s *) manager;
72 if (LOCATIONS_METHOD_GPS == handle->method) {
73 if (!handle->sig_id[_LOCATION_SIGNAL_BATCH_UPDATED]) {
74 handle->sig_id[_LOCATION_SIGNAL_BATCH_UPDATED] = g_signal_connect(handle->object, "batch-updated", G_CALLBACK(__cb_batch_updated), handle);
77 LOCATIONS_LOGE("method is not GPS");
80 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_BATCH] != NULL) {
81 LOCATIONS_LOGI("batch status set : Start");
84 int ret = location_start_batch(handle->object);
85 if (ret != LOCATION_ERROR_NONE) {
86 return __convert_error_code(ret);
89 return LOCATIONS_ERROR_NONE;
92 EXPORT_API int location_manager_stop_batch(location_manager_h manager)
94 LOCATIONS_LOGD("location_manager_stop_batch");
95 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
96 LOCATIONS_NULL_ARG_CHECK(manager);
97 location_manager_s *handle = (location_manager_s *) manager;
99 if (LOCATIONS_METHOD_GPS == handle->method) {
100 if (handle->sig_id[_LOCATION_SIGNAL_BATCH_UPDATED]) {
101 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_BATCH_UPDATED]);
102 handle->sig_id[_LOCATION_SIGNAL_BATCH_UPDATED] = 0;
105 LOCATIONS_LOGE("method is not GPS");
108 int ret = location_stop_batch(handle->object);
109 if (ret != LOCATION_ERROR_NONE) {
110 return __convert_error_code(ret);
113 return LOCATIONS_ERROR_NONE;
116 EXPORT_API int location_manager_foreach_location_batch(location_manager_h manager, location_batch_get_location_cb callback, void *user_data)
118 LOCATIONS_LOGD("location_manager_foreach_location_batch");
119 LOCATIONS_NOT_SUPPORTED_CHECK(__is_location_supported());
120 LOCATIONS_NULL_ARG_CHECK(manager);
121 LOCATIONS_NULL_ARG_CHECK(callback);
122 location_manager_s *handle = (location_manager_s *) manager;
123 LocationBatch *batch = NULL;
125 int ret = location_get_batch(handle->object, &batch);
126 if (ret != LOCATION_ERROR_NONE || batch == NULL) {
127 if (ret == LOCATION_ERROR_NOT_SUPPORTED) {
128 LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d", LOCATIONS_ERROR_INCORRECT_METHOD, handle->method);
129 return LOCATIONS_ERROR_INCORRECT_METHOD;
130 } else if (ret == LOCATION_ERROR_NOT_ALLOWED) {
131 LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED");
132 return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
135 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : batch is NULL ",
136 LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
137 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
141 for (i = 0; i < batch->num_of_location; i++) {
151 location_get_batch_details(batch, i, &latitude, &longitude, &altitude, &speed, &direction, &h_accuracy, &v_accuracy, ×tamp);
152 if (callback(latitude, longitude, altitude, speed, direction, h_accuracy, v_accuracy, timestamp, user_data) != TRUE) {
156 location_batch_free(batch);
158 return LOCATIONS_ERROR_NONE;