update for beta universally
[framework/location/libslp-location.git] / tests / satellite-sample.c
1 /*
2  * libslp-location
3  *
4  * Copyright (c) 2010-2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Youngae Kang <youngae.kang@samsung.com>, Yunhan Kim <yhan.kim@samsung.com>,
7  *          Genie Kim <daejins.kim@samsung.com>, Minjune Kim <sena06.kim@samsung.com>
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */
21
22 #include <glib.h>
23 #include <location/location.h>
24
25 static GMainLoop *loop = NULL;
26 GSource* sat_src = NULL;
27
28 static gboolean
29 exit_program (gpointer data)
30 {
31         g_main_loop_quit (loop);
32         g_debug ("Quit g_main_loop");
33         return FALSE;
34 }
35
36 static void
37 cb_service_updated (GObject *self,
38         guint type,
39         gpointer data,
40         gpointer accuracy,
41         gpointer userdata)
42 {
43         g_debug("cb_service_updated: type(%d) userdata(0x%x)", type, (unsigned int)userdata);
44
45         LocationObject *loc = (LocationObject*)userdata;
46         LocationSatellite *sat = NULL;
47         int idx = 0;
48
49         g_object_get (loc, "satellite", &sat, NULL);
50         if (sat) {
51                 g_debug ("SYNC>> Current Sattelite> satellite in view = %d, satellite in used = %d", sat->num_of_sat_inview, sat->num_of_sat_used);
52                 g_debug ("\tinview satellite information = ");
53                 for (idx=0; idx<sat->num_of_sat_inview; idx++) {
54                         guint prn;
55                         gboolean used;
56                         guint elevation;
57                         guint azimuth;
58                         gint snr;
59                         location_satellite_get_satellite_details(sat, idx, &prn, &used, &elevation, &azimuth, &snr);
60                         g_debug ("\t\t[%02d] used: %d, prn: %d, elevation: %d, azimuth: %d, snr: %d",
61                                 idx, used, prn, elevation, azimuth, snr);
62                 }
63                 location_satellite_free (sat);
64         } else g_warning ("SYNC>> Current Sattelite> failed");
65 }
66
67 static void
68 cb_service_enabled (GObject *self,
69         guint status,
70         gpointer userdata)
71 {
72         g_debug("cb_service_enabled: status(%d) userdata(0x%x)", status, (unsigned int)userdata);
73 }
74
75 static void
76 cb_service_disabled (GObject *self,
77         guint status,
78         gpointer userdata)
79 {
80         g_debug("cb_service_disabled: status(%d) userdata(0x%x)", status, (unsigned int)userdata);
81 }
82
83 int
84 main (int argc, char *argv[])
85 {
86         LocationObject *loc = NULL;
87
88         location_init ();
89
90         loop = g_main_loop_new (NULL, TRUE);
91
92         loc  = location_new (LOCATION_METHOD_GPS);
93         if (!loc) {
94                 g_debug("location_new failed");
95                 return -1;
96         }
97
98         g_signal_connect (loc, "service-enabled", G_CALLBACK(cb_service_enabled), loc);
99         g_signal_connect (loc, "service-disabled", G_CALLBACK(cb_service_disabled), loc);
100         g_signal_connect (loc, "service-updated", G_CALLBACK(cb_service_updated), loc);
101
102         if( LOCATION_ERROR_NONE != location_start (loc) ){
103                 g_debug("location_start failed");
104                 return -1;
105         }
106
107         g_timeout_add_seconds(60, exit_program, NULL);
108         g_main_loop_run (loop);
109
110         location_stop (loc);
111         location_free (loc);
112
113         return 0;
114 }