tizen 2.4 release
[framework/location/libslp-location.git] / tests / nmea-sample.c
1 /*
2  * libslp-location
3  *
4  * Copyright (c) 2010-2013 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Youngae Kang <youngae.kang@samsung.com>, Minjune Kim <sena06.kim@samsung.com>
7  *          Genie Kim <daejins.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.h>
24
25 static GMainLoop *loop = NULL;
26 GSource *nmea_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         gchar *nmea_data = NULL;
46         g_object_get(self, "nmea", &nmea_data, NULL);
47         if (nmea_data) {
48                 g_debug("SYNC>> Currnet NMEA> nmea_data:\n%s\n", nmea_data);
49                 g_free(nmea_data);
50         } else g_warning("SYNC>> Current NMEA> failed");
51 }
52
53 static void
54 cb_service_enabled(GObject *self,
55                    guint status,
56                    gpointer userdata)
57 {
58         g_debug("cb_service_enabled: status(%d) userdata(0x%x)", status, (unsigned int)userdata);
59 }
60
61 static void
62 cb_service_disabled(GObject *self,
63                     guint status,
64                     gpointer userdata)
65 {
66         g_debug("cb_service_disabled: status(%d) userdata(0x%x)", status, (unsigned int)userdata);
67 }
68
69 int
70 main(int argc, char *argv[])
71 {
72         LocationObject *loc = NULL;
73
74         location_init();
75
76         loop = g_main_loop_new(NULL, TRUE);
77
78         loc  = location_new(LOCATION_METHOD_GPS);
79         if (!loc) {
80                 g_debug("location_new failed");
81                 return -1;
82         }
83
84         g_signal_connect(loc, "service-enabled", G_CALLBACK(cb_service_enabled), loc);
85         g_signal_connect(loc, "service-disabled", G_CALLBACK(cb_service_disabled), loc);
86         g_signal_connect(loc, "service-updated", G_CALLBACK(cb_service_updated), loc);
87
88         if (LOCATION_ERROR_NONE != location_start(loc)) {
89                 g_debug("location_start failed");
90                 return -1;
91         }
92
93         g_timeout_add_seconds(60, exit_program, NULL);
94         g_main_loop_run(loop);
95
96         location_stop(loc);
97         location_free(loc);
98
99         return 0;
100 }