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]);
38 /*/////////////////////////////////////// */
39 /* Location Manager */
40 /*////////////////////////////////////// */
42 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)
44 LOCATIONS_LOGD("location_manager_set_location_batch_cb");
45 LOCATIONS_NOT_SUPPORTED_CHECK(__is_batch_supported());
47 LOCATIONS_CHECK_CONDITION(batch_interval >= 1 && batch_interval <= 255, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
48 LOCATIONS_CHECK_CONDITION(batch_period >= 1 && batch_period <= 60000, LOCATIONS_ERROR_INVALID_PARAMETER, "LOCATIONS_ERROR_INVALID_PARAMETER");
49 LOCATIONS_CHECK_CONDITION(batch_interval <= batch_period, 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_batch_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_batch_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);
76 LOCATIONS_LOGE("method is not GPS");
79 if (handle->user_cb[_LOCATIONS_EVENT_TYPE_BATCH] != NULL)
80 LOCATIONS_LOGD("batch status set : Start");
82 int ret = location_start_batch(handle->object);
83 if (ret != LOCATION_ERROR_NONE)
84 return __convert_error_code(ret);
86 return LOCATIONS_ERROR_NONE;
89 EXPORT_API int location_manager_stop_batch(location_manager_h manager)
91 LOCATIONS_LOGD("location_manager_stop_batch");
92 LOCATIONS_NOT_SUPPORTED_CHECK(__is_batch_supported());
93 LOCATIONS_NULL_ARG_CHECK(manager);
94 location_manager_s *handle = (location_manager_s *) manager;
96 if (LOCATIONS_METHOD_GPS == handle->method) {
97 if (handle->sig_id[_LOCATION_SIGNAL_BATCH_UPDATED]) {
98 g_signal_handler_disconnect(handle->object, handle->sig_id[_LOCATION_SIGNAL_BATCH_UPDATED]);
99 handle->sig_id[_LOCATION_SIGNAL_BATCH_UPDATED] = 0;
102 LOCATIONS_LOGE("method is not GPS");
105 int ret = location_stop_batch(handle->object);
106 if (ret != LOCATION_ERROR_NONE)
107 return __convert_error_code(ret);
109 return LOCATIONS_ERROR_NONE;
112 EXPORT_API int location_manager_foreach_location_batch(location_manager_h manager, location_batch_get_location_cb callback, void *user_data)
114 LOCATIONS_LOGD("location_manager_foreach_location_batch");
115 LOCATIONS_NOT_SUPPORTED_CHECK(__is_batch_supported());
116 LOCATIONS_NULL_ARG_CHECK(manager);
117 LOCATIONS_NULL_ARG_CHECK(callback);
118 location_manager_s *handle = (location_manager_s *) manager;
119 LocationBatch *batch = NULL;
121 int ret = location_get_batch(handle->object, &batch);
122 if (ret != LOCATION_ERROR_NONE || batch == NULL) {
123 if (ret == LOCATION_ERROR_NOT_SUPPORTED) {
124 LOCATIONS_LOGE("LOCATIONS_ERROR_INCORRECT_METHOD(0x%08x) : method - %d", LOCATIONS_ERROR_INCORRECT_METHOD, handle->method);
125 return LOCATIONS_ERROR_INCORRECT_METHOD;
126 } else if (ret == LOCATION_ERROR_NOT_ALLOWED) {
127 LOCATIONS_LOGE("LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED");
128 return LOCATIONS_ERROR_ACCESSIBILITY_NOT_ALLOWED;
131 LOCATIONS_LOGE("LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE(0x%08x) : batch is NULL ", LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE);
132 return LOCATIONS_ERROR_SERVICE_NOT_AVAILABLE;
136 for (i = 0; i < batch->num_of_location; i++) {
146 location_get_batch_details(batch, i, &latitude, &longitude, &altitude, &speed, &direction, &h_accuracy, &v_accuracy, ×tamp);
147 if (callback(latitude, longitude, altitude, speed, direction, h_accuracy, v_accuracy, timestamp, user_data) != TRUE)
150 location_batch_free(batch);
152 return LOCATIONS_ERROR_NONE;