summaryrefslogtreecommitdiff
path: root/src/bin/eeze/eeze_scanner_monitor
diff options
context:
space:
mode:
authorMarcel Hollerbach <marcel-hollerbach@t-online.de>2017-02-03 00:04:19 +0100
committerMarcel Hollerbach <marcel-hollerbach@t-online.de>2017-02-03 10:59:04 +0100
commit94ddd709dbae52a729179d8ad7ac4f8b06845ea3 (patch)
tree4c52f7f8a329a59beb3a9e552af4f5d7a92c0043 /src/bin/eeze/eeze_scanner_monitor
parenteab798c753e72eece526ceccf3c9beb441b5f5ff (diff)
eeze: move binaries into subdirectories
in order to move to cmake we are moving every binary into its own subdirectory.
Diffstat (limited to 'src/bin/eeze/eeze_scanner_monitor')
-rw-r--r--src/bin/eeze/eeze_scanner_monitor/eeze_scanner_monitor.c216
1 files changed, 216 insertions, 0 deletions
diff --git a/src/bin/eeze/eeze_scanner_monitor/eeze_scanner_monitor.c b/src/bin/eeze/eeze_scanner_monitor/eeze_scanner_monitor.c
new file mode 100644
index 0000000000..b6b8e146db
--- /dev/null
+++ b/src/bin/eeze/eeze_scanner_monitor/eeze_scanner_monitor.c
@@ -0,0 +1,216 @@
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/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 slice = efl_io_buffered_stream_slice_get(dialer);
74 if (slice.len == 0) return;
75
76 if (eet_connection_received(ec, slice.mem, slice.len) != 0)
77 {
78 fprintf(stderr, "ERROR: received invalid data\n");
79 goto error;
80 }
81
82 efl_io_buffered_stream_discard(dialer, slice.len);
83
84 return;
85
86 error:
87 retval = EXIT_FAILURE;
88 ecore_main_loop_quit();
89}
90
91static void
92_finished(void *data EINA_UNUSED, const Efl_Event *event EINA_UNUSED)
93{
94 ecore_main_loop_quit();
95}
96
97static void
98_error(void *data EINA_UNUSED, const Efl_Event *event)
99{
100 Eo *dialer = event->object;
101 Eina_Error *perr = event->info;
102
103 fprintf(stderr, "ERROR: error communicating to %s: %s\n",
104 efl_net_dialer_address_dial_get(dialer),
105 eina_error_msg_get(*perr));
106 retval = EXIT_FAILURE;
107 ecore_main_loop_quit();
108}
109
110int
111main(int argc EINA_UNUSED, char **argv EINA_UNUSED)
112{
113 Eet_Data_Descriptor_Class eddc;
114 Eo *loop;
115 char *path;
116 Eo *dialer;
117 Eet_Connection *ec;
118 Eina_Error err;
119
120 ecore_app_no_system_modules();
121
122 eina_init();
123 ecore_init();
124 eet_init();
125 ecore_con_init();
126
127 if (!eet_eina_stream_data_descriptor_class_set(&eddc, sizeof(eddc), "eeze_scanner_event", sizeof(Eeze_Scanner_Event)))
128 {
129 fprintf(stderr, "ERROR: could not create eet data descriptor!\n");
130 retval = EXIT_FAILURE;
131 goto error_edd;
132 }
133 edd = eet_data_descriptor_stream_new(&eddc);
134 if (!edd)
135 {
136 fprintf(stderr, "ERROR: could not create eet data descriptor!\n");
137 retval = EXIT_FAILURE;
138 goto error_edd;
139 }
140#define DAT(MEMBER, TYPE) EET_DATA_DESCRIPTOR_ADD_BASIC(edd, Eeze_Scanner_Event, #MEMBER, MEMBER, EET_T_##TYPE)
141 DAT(device, INLINED_STRING);
142 DAT(type, UINT);
143 DAT(volume, UCHAR);
144#undef DAT
145
146 path = ecore_con_local_path_new(EINA_TRUE, "eeze_scanner", 0);
147 if (!path)
148 {
149 fprintf(stderr, "ERROR: could not get local communication path\n");
150 retval = EXIT_FAILURE;
151 goto error_path;
152 }
153
154 loop = ecore_main_loop_get();
155
156#ifdef EFL_NET_DIALER_UNIX_CLASS
157 dialer = efl_add(EFL_NET_DIALER_SIMPLE_CLASS, loop,
158 efl_net_dialer_simple_inner_class_set(efl_added, EFL_NET_DIALER_UNIX_CLASS));
159#else
160 fprintf(stderr, "ERROR: your platform doesn't support Efl.Net.Dialer.Unix\n");
161#endif
162 if (!dialer)
163 {
164 fprintf(stderr, "ERROR: could not create communication dialer\n");
165 retval = EXIT_FAILURE;
166 goto end;
167 }
168
169 ec = eet_connection_new(_eet_read, _eet_write, dialer);
170 if (!ec)
171 {
172 fprintf(stderr, "ERROR: could not create Eet_Connection\n");
173 retval = EXIT_FAILURE;
174 goto end;
175 }
176 efl_event_callback_add(dialer, EFL_IO_BUFFERED_STREAM_EVENT_SLICE_CHANGED, _on_data, ec);
177
178
179 efl_event_callback_add(dialer, EFL_IO_BUFFERED_STREAM_EVENT_ERROR, _error, NULL);
180 efl_event_callback_add(dialer, EFL_IO_BUFFERED_STREAM_EVENT_READ_FINISHED, _finished, NULL);
181
182 err = efl_net_dialer_dial(dialer, path);
183 if (err)
184 {
185 fprintf(stderr, "ERROR: could not connect '%s': %s\n", path, eina_error_msg_get(err));
186 retval = EXIT_FAILURE;
187 goto end_dial;
188 }
189
190 ecore_main_loop_begin();
191
192 end_dial:
193 if (!efl_io_closer_closed_get(dialer))
194 efl_io_closer_close(dialer);
195
196 efl_event_callback_del(dialer, EFL_IO_BUFFERED_STREAM_EVENT_SLICE_CHANGED, _on_data, ec);
197 eet_connection_close(ec, NULL);
198 ec = NULL;
199
200 end:
201 efl_del(dialer);
202 dialer = NULL;
203
204 free(path);
205 path = NULL;
206 error_path:
207 eet_data_descriptor_free(edd);
208 edd = NULL;
209
210 error_edd:
211 ecore_con_shutdown();
212 eet_shutdown();
213 ecore_shutdown();
214 eina_shutdown();
215 return retval;
216}