4 * Copyright (c) 2010-2013 Samsung Electronics Co., Ltd. All rights reserved.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
23 #define MAX_BATCH_ITEM 8
24 #define BATCH_SENTENCE_SIZE 256
29 #include <tzplatform_config.h>
31 #include "location-batch.h"
32 #include "location-log.h"
35 EXPORT_API LocationBatch *
36 location_batch_new(int num_of_location)
38 LocationBatch *batch = g_slice_new0(LocationBatch);
39 g_return_val_if_fail(batch, NULL);
41 batch->num_of_location = num_of_location;
42 batch->batch_data = g_new0(LocationBatchDetail, batch->num_of_location);
46 #if defined(TIZEN_DEVICE)
47 EXPORT_API gboolean location_set_sensor_batch(LocationBatch *batch, sensor_event_s *event)
49 g_return_val_if_fail(batch, FALSE);
50 g_return_val_if_fail(event, FALSE);
51 g_return_val_if_fail(batch->num_of_location > event->values[4], FALSE);
52 unsigned long long timestamp = event->timestamp;
53 float latitude = event->values[0];
54 float longitude = event->values[1];
55 float altitude = event->values[2];
56 float speed = event->values[3];
57 int idx = (int)(event->values[4]);
59 batch->batch_data[idx].timestamp = batch->start_time - (time_t)((timestamp / 1001000) % 100000);
60 batch->batch_data[idx].latitude = latitude;
61 batch->batch_data[idx].longitude = longitude;
62 batch->batch_data[idx].altitude = altitude;
63 batch->batch_data[idx].speed = speed;
64 batch->batch_data[idx].direction = 0;
65 batch->batch_data[idx].horizontal_accuracy = 0;
66 batch->batch_data[idx].vertical_accuracy = 0;
72 EXPORT_API LocationBatch *
73 location_batch_copy(const LocationBatch *batch)
75 g_return_val_if_fail(batch, NULL);
76 LocationBatch *batch_dup = location_batch_new(batch->num_of_location);
77 batch_dup->num_of_location = batch->num_of_location;
79 for (i = 0 ; i < batch_dup->num_of_location; i++)
80 location_set_batch_details(batch_dup, i,
81 batch->batch_data[i].latitude, batch->batch_data[i].longitude, batch->batch_data[i].altitude,
82 batch->batch_data[i].speed, batch->batch_data[i].direction,
83 batch->batch_data[i].horizontal_accuracy, batch->batch_data[i].vertical_accuracy,
84 batch->batch_data[i].timestamp);
90 location_get_batch_details(const LocationBatch *batch, guint index,
91 gdouble *latitude, gdouble *longitude, gdouble *altitude,
92 gdouble *speed, gdouble *direction, gdouble *h_accuracy, gdouble *v_accuracy, guint *timestamp)
94 g_return_val_if_fail(batch, FALSE);
95 g_return_val_if_fail(latitude, FALSE);
96 g_return_val_if_fail(longitude, FALSE);
97 g_return_val_if_fail(altitude, FALSE);
98 g_return_val_if_fail(speed, FALSE);
99 g_return_val_if_fail(direction, FALSE);
100 g_return_val_if_fail(h_accuracy, FALSE);
101 g_return_val_if_fail(v_accuracy, FALSE);
102 g_return_val_if_fail(timestamp, FALSE);
103 g_return_val_if_fail(batch->batch_data, FALSE);
105 *latitude = batch->batch_data[index].latitude;
106 *longitude = batch->batch_data[index].longitude;
107 *altitude = batch->batch_data[index].altitude;
108 *speed = batch->batch_data[index].speed;
109 *direction = batch->batch_data[index].direction;
110 *h_accuracy = batch->batch_data[index].horizontal_accuracy;
111 *v_accuracy = batch->batch_data[index].vertical_accuracy;
112 *timestamp = batch->batch_data[index].timestamp;
118 location_set_batch_details(LocationBatch *batch, guint index,
119 gdouble latitude, gdouble longitude, gdouble altitude,
120 gdouble speed, gdouble direction, gdouble h_accuracy, gdouble v_accuracy, guint timestamp)
122 g_return_val_if_fail(batch, FALSE);
123 g_return_val_if_fail(batch->batch_data, FALSE);
124 g_return_val_if_fail(index < batch->num_of_location, FALSE);
126 batch->batch_data[index].latitude = latitude;
127 batch->batch_data[index].longitude = longitude;
128 batch->batch_data[index].altitude = altitude;
129 batch->batch_data[index].speed = speed;
130 batch->batch_data[index].direction = direction;
131 batch->batch_data[index].horizontal_accuracy = h_accuracy;
132 batch->batch_data[index].vertical_accuracy = v_accuracy;
133 batch->batch_data[index].timestamp = timestamp;
139 location_batch_free(LocationBatch *batch)
141 g_return_if_fail(batch);
142 g_free(batch->batch_data);
143 g_slice_free(LocationBatch, batch);