summaryrefslogtreecommitdiff
path: root/src/bin/eeze
diff options
context:
space:
mode:
authorGustavo Sverzut Barbieri <barbieri@profusion.mobi>2016-11-28 11:14:50 -0200
committerGustavo Sverzut Barbieri <barbieri@profusion.mobi>2016-11-28 12:15:38 -0200
commit211eb3f00a214200cebd295c7ab84402874c5c76 (patch)
tree2453a9cc01e0dd710896fd9f6ed4efb1365b6691 /src/bin/eeze
parent9effe44d8b3098848e9582b8888150c1319aca12 (diff)
eeze_scanner: add monitor (client)
In order to test eeze_scanner it's handful to have a client to monitor for broadcasted events.
Diffstat (limited to 'src/bin/eeze')
-rw-r--r--src/bin/eeze/.gitignore1
-rw-r--r--src/bin/eeze/eeze_scanner_monitor.c220
2 files changed, 221 insertions, 0 deletions
diff --git a/src/bin/eeze/.gitignore b/src/bin/eeze/.gitignore
index e3025d683b..2cb6973af0 100644
--- a/src/bin/eeze/.gitignore
+++ b/src/bin/eeze/.gitignore
@@ -1,6 +1,7 @@
1/eeze_disk_ls 1/eeze_disk_ls
2/eeze_mount 2/eeze_mount
3/eeze_scanner 3/eeze_scanner
4/eeze_scanner_monitor
4/eeze_sensor_test 5/eeze_sensor_test
5/eeze_udev_test 6/eeze_udev_test
6/eeze_umount 7/eeze_umount
diff --git a/src/bin/eeze/eeze_scanner_monitor.c b/src/bin/eeze/eeze_scanner_monitor.c
new file mode 100644
index 0000000000..9985015598
--- /dev/null
+++ b/src/bin/eeze/eeze_scanner_monitor.c
@@ -0,0 +1,220 @@
1#ifdef HAVE_CONFIG_H
2# include "config.h"
3#endif
4
5#define EFL_BETA_API_SUPPORT 1
6#define EFL_EO_API_SUPPORT 1
7#include <Eet.h>
8#include <Ecore.h>
9#include <Ecore_Con.h>
10#include "eeze_scanner.h"
11
12static Eet_Data_Descriptor *edd;
13
14static int retval = EXIT_SUCCESS;
15
16static Eina_Bool
17_eet_read(const void *eet_data, size_t size, void *user_data EINA_UNUSED)
18{
19 Eeze_Scanner_Event *ev = eet_data_descriptor_decode(edd, eet_data, size);
20
21 if (!ev)
22 {
23 fprintf(stderr, "ERROR: could not decode event!\n");
24 goto error;
25 }
26
27 switch (ev->type)
28 {
29 case EEZE_SCANNER_EVENT_TYPE_ADD:
30 printf("ADD ");
31 break;
32 case EEZE_SCANNER_EVENT_TYPE_REMOVE:
33 printf("DEL ");
34 break;
35 case EEZE_SCANNER_EVENT_TYPE_CHANGE:
36 printf("CHG ");
37 break;
38 default:
39 fprintf(stderr, "ERROR: unknown event type %d\n", ev->type);
40 goto error;
41 }
42
43 if (ev->volume)
44 printf("VOLUME ");
45
46 printf("'%s'\n", ev->device);
47 free(ev);
48
49 return EINA_TRUE;
50
51 error:
52 retval = EXIT_FAILURE;
53 ecore_main_loop_quit();
54 return EINA_FALSE;
55}
56
57static Eina_Bool
58_eet_write(const void *eet_data EINA_UNUSED, size_t size EINA_UNUSED, void *user_data EINA_UNUSED)
59{
60 fprintf(stderr, "ERROR: should not write data!\n");
61 retval = EXIT_FAILURE;
62 ecore_main_loop_quit();
63 return EINA_FALSE;
64}
65
66static void
67_on_data(void *data, const Efl_Event *event)
68{
69 Eet_Connection *ec = data;
70 Eo *dialer = event->object;
71 Eina_Slice slice;
72
73 if (!efl_io_buffered_stream_slice_get(dialer, &slice))
74 {
75 fprintf(stderr, "ERROR: could not get buffered stream slice\n");
76 goto error;
77 }
78 if (slice.len == 0) return;
79
80 if (eet_connection_received(ec, slice.mem, slice.len) != 0)
81 {
82 fprintf(stderr, "ERROR: received invalid data\n");
83 goto error;
84 }
85
86 efl_io_buffered_stream_discard(dialer, slice.len);
87
88 return;
89
90 error:
91 retval = EXIT_FAILURE;
92 ecore_main_loop_quit();
93}
94
95static void
96_finished(void *data EINA_UNUSED, const Efl_Event *event EINA_UNUSED)
97{
98 ecore_main_loop_quit();
99}
100
101static void
102_error(void *data EINA_UNUSED, const Efl_Event *event)
103{
104 Eo *dialer = event->object;
105 Eina_Error *perr = event->info;
106
107 fprintf(stderr, "ERROR: error communicating to %s: %s\n",
108 efl_net_dialer_address_dial_get(dialer),
109 eina_error_msg_get(*perr));
110 retval = EXIT_FAILURE;
111 ecore_main_loop_quit();
112}
113
114int
115main(int argc EINA_UNUSED, char **argv EINA_UNUSED)
116{
117 Eet_Data_Descriptor_Class eddc;
118 Eo *loop;
119 char *path;
120 Eo *dialer;
121 Eet_Connection *ec;
122 Eina_Error err;
123
124 ecore_app_no_system_modules();
125
126 eina_init();
127 ecore_init();
128 eet_init();
129 ecore_con_init();
130
131 if (!eet_eina_stream_data_descriptor_class_set(&eddc, sizeof(eddc), "eeze_scanner_event", sizeof(Eeze_Scanner_Event)))
132 {
133 fprintf(stderr, "ERROR: could not create eet data descriptor!\n");
134 retval = EXIT_FAILURE;
135 goto error_edd;
136 }
137 edd = eet_data_descriptor_stream_new(&eddc);
138 if (!edd)
139 {
140 fprintf(stderr, "ERROR: could not create eet data descriptor!\n");
141 retval = EXIT_FAILURE;
142 goto error_edd;
143 }
144#define DAT(MEMBER, TYPE) EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Eeze_Scanner_Event, #MEMBER, MEMBER, EET_T_##TYPE)
145 DAT(device, INLINED_STRING);
146 DAT(type, UINT);
147 DAT(volume, UCHAR);
148#undef DAT
149
150 path = ecore_con_local_path_new(EINA_TRUE, "eeze_scanner", 0);
151 if (!path)
152 {
153 fprintf(stderr, "ERROR: could not get local communication path\n");
154 retval = EXIT_FAILURE;
155 goto end;
156 }
157
158 loop = ecore_main_loop_get();
159
160#ifdef EFL_NET_DIALER_UNIX_CLASS
161 dialer = efl_add(EFL_NET_DIALER_SIMPLE_CLASS, loop,
162 efl_net_dialer_simple_inner_class_set(efl_added, EFL_NET_DIALER_UNIX_CLASS));
163#else
164 fprintf(stderr, "ERROR: your platform doesn't support Efl.Net.Dialer.Unix\n");
165#endif
166 if (!dialer)
167 {
168 fprintf(stderr, "ERROR: could not create communication dialer\n");
169 retval = EXIT_FAILURE;
170 goto end;
171 }
172
173 ec = eet_connection_new(_eet_read, _eet_write, dialer);
174 if (!ec)
175 {
176 fprintf(stderr, "ERROR: could not create Eet_Connection\n");
177 retval = EXIT_FAILURE;
178 goto end;
179 }
180 efl_event_callback_add(dialer, EFL_IO_BUFFERED_STREAM_EVENT_SLICE_CHANGED, _on_data, ec);
181
182
183 efl_event_callback_add(dialer, EFL_IO_BUFFERED_STREAM_EVENT_ERROR, _error, NULL);
184 efl_event_callback_add(dialer, EFL_IO_BUFFERED_STREAM_EVENT_READ_FINISHED, _finished, NULL);
185
186 err = efl_net_dialer_dial(dialer, path);
187 if (err)
188 {
189 fprintf(stderr, "ERROR: could not connect '%s': %s\n", path, eina_error_msg_get(err));
190 retval = EXIT_FAILURE;
191 goto end_dial;
192 }
193
194 ecore_main_loop_begin();
195
196 end_dial:
197 if (!efl_io_closer_closed_get(dialer))
198 efl_io_closer_close(dialer);
199
200 efl_event_callback_del(dialer, EFL_IO_BUFFERED_STREAM_EVENT_SLICE_CHANGED, _on_data, ec);
201 eet_connection_close(ec, NULL);
202 ec = NULL;
203
204 end:
205 efl_del(dialer);
206 dialer = NULL;
207
208 free(path);
209 path = NULL;
210
211 eet_data_descriptor_free(edd);
212 edd = NULL;
213
214 error_edd:
215 ecore_con_shutdown();
216 eet_shutdown();
217 ecore_shutdown();
218 eina_shutdown();
219 return retval;
220}