Initialize Tizen 2.3
[framework/telephony/libslp-tapi.git] / mobile / src / tapi_gps.c
1 /*
2  * libslp-tapi
3  *
4  * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Ja-young Gu <jygu@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24
25 #include "tapi_common.h"
26 #include "TapiUtility.h"
27
28 #include "common.h"
29 #include "tapi_log.h"
30 #include "ITapiGps.h"
31
32 static void on_response_default_set(GObject *source_object, GAsyncResult *res, gpointer user_data)
33 {
34         GError *error = NULL;
35         GDBusConnection *conn = NULL;
36         struct tapi_resp_data *evt_cb_data = user_data;
37         int result = -1;
38
39         GVariant *dbus_result;
40
41         conn = G_DBUS_CONNECTION (source_object);
42         dbus_result = g_dbus_connection_call_finish(conn, res, &error);
43         CHECK_DEINIT(error);
44
45         if (!dbus_result) {
46                 if (evt_cb_data->cb_fn) {
47                         evt_cb_data->cb_fn(evt_cb_data->handle, -1, NULL, evt_cb_data->user_data);
48                 }
49
50                 if (error)
51                         g_error_free(error);
52
53                 free(evt_cb_data);
54                 return;
55         }
56
57
58         g_variant_get (dbus_result, "(i)", &result);
59
60         if (evt_cb_data->cb_fn) {
61                 evt_cb_data->cb_fn(evt_cb_data->handle, result, NULL, evt_cb_data->user_data);
62         }
63
64         free(evt_cb_data);
65 }
66
67
68 EXPORT_API int tel_set_gps_frequency_aiding(TapiHandle *handle, unsigned char state, tapi_response_cb callback, void *user_data)
69 {
70         struct tapi_resp_data *evt_cb_data = NULL;
71         GVariant *param;
72
73         dbg("Func Entrance");
74
75         MAKE_RESP_CB_DATA(evt_cb_data, handle, callback, user_data);
76
77         param = g_variant_new("(y)", state);
78
79         g_dbus_connection_call(handle->dbus_connection,
80                         DBUS_TELEPHONY_SERVICE , handle->path, DBUS_TELEPHONY_GPS_INTERFACE,
81                         "SetFrequencyAiding", param, NULL,
82                         G_DBUS_CALL_FLAGS_NONE, -1, handle->ca,
83                         on_response_default_set, evt_cb_data);
84
85         return TAPI_API_SUCCESS;
86 }
87
88 EXPORT_API int tel_confirm_gps_measure_pos(TapiHandle *handle, unsigned char *data, unsigned int data_len)
89 {
90         GVariant *param = NULL;
91         GVariant *rst = NULL;
92         GError *gerr = 0;
93         gchar *encoded_data = NULL;
94         gint result;
95
96         dbg("Func Entrance");
97
98         if (!handle || !handle->dbus_connection || !data){
99                 dbg("invalid parameter");
100                 return TAPI_API_INVALID_INPUT;
101         }
102
103         msg("call tel_confirm_gps_measure_pos(). data_len=%d", data_len);
104         encoded_data = g_base64_encode((const guchar*)data, data_len);
105
106         param = g_variant_new("(s)", encoded_data);
107
108         rst = g_dbus_connection_call_sync(handle->dbus_connection, DBUS_TELEPHONY_SERVICE , handle->path,
109                         DBUS_TELEPHONY_GPS_INTERFACE, "ConfirmMeasurePos", param, NULL, G_DBUS_CALL_FLAGS_NONE, -1, 0, &gerr);
110
111         g_free(encoded_data);
112
113         if(!rst){
114                 dbg( "error to gps measure pos confirm(%s)", gerr->message);
115                 g_error_free (gerr);
116                 return TAPI_API_OPERATION_FAILED;
117         }
118         dbg("send gps user confirm format(%s)", g_variant_get_type_string(rst));
119
120         g_variant_get(rst, "(i)", &result);
121         dbg("result (%d)", result);
122
123         return TAPI_API_SUCCESS;
124 }
125