upload tizen1.0 source
[framework/location/libslp-location.git] / tests / property-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.h>
24
25 static GMainLoop *loop = NULL;
26
27 static gboolean
28 exit_program (gpointer data)
29 {
30         g_main_loop_quit (loop);
31         g_debug ("Quit g_main_loop");
32         return FALSE;
33 }
34
35 static void
36 cb_service_updated (GObject *self,
37         guint type,
38         gpointer data,
39         gpointer accuracy,
40         gpointer userdata)
41 {
42         g_debug("cb_service_updated: type(%d) userdata(0x%x)", type, (unsigned int)userdata);
43 }
44
45 static void
46 cb_service_enabled (GObject *self,
47         guint status,
48         gpointer userdata)
49 {
50         g_debug("cb_service_enabled: status(%d) userdata(0x%x)", status, (unsigned int)userdata);
51 }
52
53 static void
54 cb_service_disabled (GObject *self,
55         guint status,
56         gpointer userdata)
57 {
58         g_debug("cb_service_disabled: status(%d) userdata(0x%x)", status, (unsigned int)userdata);
59 }
60
61 int
62 main (int argc, char *argv[])
63 {
64         LocationObject *loc = NULL;
65
66         location_init ();
67
68         loop = g_main_loop_new (NULL, TRUE);
69
70         loc  = location_new (LOCATION_METHOD_GPS);
71         if (!loc) {
72                 g_debug("location_new failed");
73                 return -1;
74         }
75
76         LocationMethod method = LOCATION_METHOD_NONE;
77         g_object_get(loc, "method", &method, NULL);
78         g_debug("Get property>> method:%d", method);
79
80         char* devname = NULL;
81         g_object_get(loc, "dev-name", &devname, NULL);
82         if (devname) {
83                 g_debug("Get property>> dev-name: %s", devname);
84                 g_free(devname);
85         } else g_warning("failed to get property> dev-name");
86
87         g_object_set(loc, "dev-name", "/dev/test", NULL);
88         g_object_get(loc, "dev-name", &devname, NULL);
89         if (devname) {
90                 g_debug("Get property>> dev-name: %s", devname);
91                 g_free(devname);
92         } else g_warning("failed to set property> dev-name");
93
94         g_signal_connect (loc, "service-enabled", G_CALLBACK(cb_service_enabled), loc);
95         g_signal_connect (loc, "service-disabled", G_CALLBACK(cb_service_disabled), loc);
96         g_signal_connect (loc, "service-updated", G_CALLBACK(cb_service_updated), loc);
97
98         if( LOCATION_ERROR_NONE != location_start (loc) ){
99                 g_debug("location_start failed");
100                 return -1;
101         }
102
103         g_timeout_add_seconds (60, exit_program, NULL);
104         g_main_loop_run (loop);
105
106         location_stop (loc);
107
108         LocationPosition *pos = NULL;
109         g_object_get(loc, "last-position", &pos, NULL);
110         if (pos) {
111                 g_debug ("Get property>> last-position> time: %d, lat: %f, long: %f, alt: %f, status: %d",
112                         pos->timestamp, pos->latitude, pos->longitude, pos->altitude, pos->status);
113                 location_position_free(pos);
114         } else  g_warning("failed to get property> last-position");
115
116         location_free (loc);
117
118         return 0;
119 }