summaryrefslogtreecommitdiff
path: root/src/examples/elocation
diff options
context:
space:
mode:
authorStefan Schmidt <s.schmidt@samsung.com>2014-10-28 13:00:11 +0100
committerStefan Schmidt <s.schmidt@samsung.com>2014-11-11 11:03:23 +0100
commita80b88c0ea76017195d6f6db07b35717915380a1 (patch)
tree71408f5c5fc27665a5324a2892f5332bd0ee05e5 /src/examples/elocation
parenta2d2cdaf9f258ec4c6c7c33d912bbe41625e8532 (diff)
elocation: Add example for using the elocation API
Basic example to show API usage.
Diffstat (limited to 'src/examples/elocation')
-rw-r--r--src/examples/elocation/Makefile.am51
-rw-r--r--src/examples/elocation/elocation.c169
2 files changed, 220 insertions, 0 deletions
diff --git a/src/examples/elocation/Makefile.am b/src/examples/elocation/Makefile.am
new file mode 100644
index 0000000000..3c843f8b6e
--- /dev/null
+++ b/src/examples/elocation/Makefile.am
@@ -0,0 +1,51 @@
1MAINTAINERCLEANFILES = Makefile.in
2
3AM_CPPFLAGS = \
4-I$(top_builddir)/src/lib/efl \
5-I$(top_srcdir)/src/lib/eina \
6-I$(top_srcdir)/src/lib/eo \
7-I$(top_srcdir)/src/lib/ecore \
8-I$(top_srcdir)/src/lib/eldbus \
9-I$(top_srcdir)/src/lib/elocation \
10-I$(top_builddir)/src/lib/eina \
11-I$(top_builddir)/src/lib/eo \
12-I$(top_builddir)/src/lib/ecore \
13-I$(top_builddir)/src/lib/eldbus \
14-I$(top_builddir)/src/lib/elocation
15
16EXTRA_PROGRAMS = \
17elocation
18
19elocation_SOURCES = elocation.c
20elocation_LDADD = \
21$(top_builddir)/src/lib/elocation/libelocation.la \
22$(top_builddir)/src/lib/eo/libeo.la \
23$(top_builddir)/src/lib/ecore/libecore.la \
24$(top_builddir)/src/lib/eldbus/libeldbus.la \
25$(top_builddir)/src/lib/eina/libeina.la \
26@ELOCATION_LDFLAGS@
27
28SRCS = \
29elocation.c
30
31DATA_FILES = Makefile.examples
32
33EXTRA_DIST = $(DATA_FILES)
34
35examples: $(EXTRA_PROGRAMS)
36
37clean-local:
38 rm -f $(EXTRA_PROGRAMS)
39
40install-examples:
41 mkdir -p $(datadir)/elocation/examples
42 cd $(srcdir) && $(install_sh_DATA) -c $(SRCS) $(DATA_FILES) $(datadir)/elocation/examples
43
44uninstall-local:
45 for f in $(SRCS) $(DATA_FILES); do \
46 rm -f $(datadir)/elocation/examples/$$f ; \
47 done
48
49if ALWAYS_BUILD_EXAMPLES
50noinst_PROGRAMS = $(EXTRA_PROGRAMS)
51endif
diff --git a/src/examples/elocation/elocation.c b/src/examples/elocation/elocation.c
new file mode 100644
index 0000000000..300684443e
--- /dev/null
+++ b/src/examples/elocation/elocation.c
@@ -0,0 +1,169 @@
1#ifdef HAVE_CONFIG_H
2#include "config.h"
3#endif
4
5#include <stdio.h>
6
7#include <Ecore.h>
8#include <Elocation.h>
9
10/* A set of callbacks to react on incoming elocation events. They are standard
11 * ecore events and we register callbacks based on these events in the main
12 * function.
13 */
14static Eina_Bool
15status_changed(void *data, int ev_type, void *event)
16{
17 int *status = event;
18
19 printf("Status changed to: %i\n", *status);
20 printf("\n");
21
22 return ECORE_CALLBACK_DONE;
23}
24
25static Eina_Bool
26rgeocode_arrived(void *data, int ev_type, void *event)
27{
28 Elocation_Address *address;
29
30 address = event;
31 printf("Geocode reply:\n");
32 printf("Country: %s\n", address->country);
33 printf("Countrycode: %s\n", address->countrycode);
34 printf("Locality: %s\n", address->locality);
35 printf("Postalcode: %s\n", address->postalcode);
36 printf("Region: %s\n", address->region);
37 printf("Timezone: %s\n", address->timezone);
38 printf("Accuracy level: %i\n", address->accur->level);
39 printf("Accuracy horizontal: %f\n", address->accur->horizontal);
40 printf("Accuracy vertical: %f\n", address->accur->vertical);
41 printf("\n");
42
43 return ECORE_CALLBACK_DONE;
44}
45
46static Eina_Bool
47geocode_arrived(void *data, int ev_type, void *event)
48{
49 Elocation_Position *position;
50
51 position = event;
52 printf("Reverse geocode reply:\n");
53 printf("Latitude:\t %f\n", position->latitude);
54 printf("Longitude:\t %f\n", position->longitude);
55 printf("Altitude:\t %f\n", position->altitude);
56 printf("Accuracy level: %i\n", position->accur->level);
57 printf("Accuracy horizontal: %f\n", position->accur->horizontal);
58 printf("Accuracy vertical: %f\n", position->accur->vertical);
59 printf("\n");
60
61 return ECORE_CALLBACK_DONE;
62}
63
64static Eina_Bool
65address_changed(void *data, int ev_type, void *event)
66{
67 Elocation_Address *address;
68
69 address = event;
70 printf("Address update with data from timestamp: %i\n", address->timestamp);
71 printf("Country: %s\n", address->country);
72 printf("Countrycode: %s\n", address->countrycode);
73 printf("Locality: %s\n", address->locality);
74 printf("Postalcode: %s\n", address->postalcode);
75 printf("Region: %s\n", address->region);
76 printf("Timezone: %s\n", address->timezone);
77 printf("Accuracy level: %i\n", address->accur->level);
78 printf("Accuracy horizontal: %f\n", address->accur->horizontal);
79 printf("Accuracy vertical: %f\n", address->accur->vertical);
80 printf("\n");
81
82 return ECORE_CALLBACK_DONE;
83}
84
85static Eina_Bool
86position_changed(void *data, int ev_type, void *event)
87{
88 Elocation_Position *position;
89
90 position = event;
91 printf("GeoClue position reply with data from timestamp %i\n", position->timestamp);
92 printf("Latitude:\t %f\n", position->latitude);
93 printf("Longitude:\t %f\n", position->longitude);
94 printf("Altitude:\t %f\n", position->altitude);
95 printf("Accuracy level: %i\n", position->accur->level);
96 printf("Accuracy horizontal: %f\n", position->accur->horizontal);
97 printf("Accuracy vertical: %f\n", position->accur->vertical);
98 printf("\n");
99
100 return ECORE_CALLBACK_DONE;
101}
102
103int
104main(void)
105{
106 Elocation_Address *address, *addr_geocode;
107 Elocation_Position *position, *pos_geocode;
108 int status;
109
110 /* Init the needed efl subsystems so we can safely use them */
111 ecore_init();
112 eldbus_init();
113 elocation_init();
114
115 /* Create an address and positon object that we use for all our operations.
116 * Needs to be freed manually with elocation_*_free when we now longer use
117 * them */
118 address = elocation_address_new();
119 position = elocation_position_new();
120
121 /* Register callback so we get updates later on */
122 ecore_event_handler_add(ELOCATION_EVENT_STATUS, status_changed, NULL);
123 ecore_event_handler_add(ELOCATION_EVENT_POSITION, position_changed, NULL);
124 ecore_event_handler_add(ELOCATION_EVENT_ADDRESS, address_changed, NULL);
125 ecore_event_handler_add(ELOCATION_EVENT_GEOCODE, geocode_arrived, NULL);
126 ecore_event_handler_add(ELOCATION_EVENT_REVERSEGEOCODE, rgeocode_arrived, NULL);
127
128 /* To the initial request for status address and position. This fills in the
129 * objects with the data from GeoClue */
130 elocation_status_get(&status);
131 elocation_position_get(position);
132 elocation_address_get(address);
133
134 /* Another set of address and position object. This time for demonstrating
135 * the GeoCode functionalities */
136 addr_geocode = elocation_address_new();
137 pos_geocode = elocation_position_new();
138
139 /* The Freeform API could use any string to transform it into position
140 * coordinates. How good that works depends on the used GeoClue provider */
141 elocation_freeform_address_to_position("London", pos_geocode);
142
143 /* Some demo values to show the position to address conversion */
144 pos_geocode->latitude = 51.7522;
145 pos_geocode->longitude = -1.25596;
146 pos_geocode->accur->level = 3;
147 elocation_position_to_address(pos_geocode, addr_geocode);
148
149 /* And now from address to position */
150 addr_geocode->locality = "Cambridge";
151 addr_geocode->countrycode = "UK";
152 elocation_address_to_position(addr_geocode, pos_geocode);
153
154 /* Enter the mainloop now that we are setup with initial data and waiting for
155 * events. */
156 ecore_main_loop_begin();
157
158 /* Cleanup allocated memory now that we shut down */
159 elocation_address_free(addr_geocode);
160 elocation_position_free(pos_geocode);
161 elocation_address_free(address);
162 elocation_position_free(position);
163
164 /* Make sure we also shut down the initialized subsystems */
165 elocation_shutdown();
166 eldbus_shutdown();
167 ecore_shutdown();
168 return 0;
169}