summaryrefslogtreecommitdiff
path: root/src/bin/efl
diff options
context:
space:
mode:
authorGustavo Sverzut Barbieri <barbieri@profusion.mobi>2016-11-25 17:42:17 -0200
committerGustavo Sverzut Barbieri <barbieri@profusion.mobi>2016-11-25 17:42:17 -0200
commit3346e6973b5e831e0db6ad3cd9034d5f6b663799 (patch)
tree48fe1a5d1e469fe7c16bbe9f9fd1712957707d09 /src/bin/efl
parent167ff29ea004f6d2d22e5f94a3b0b64fb19da44b (diff)
efl_debug: use new efl_net_dialer_simple, remove lots of code.
this is what led me to create the efl_net_dialer_simple, this kind of code was being repeated in too many places.
Diffstat (limited to 'src/bin/efl')
-rw-r--r--src/bin/efl/efl_debug.c77
1 files changed, 14 insertions, 63 deletions
diff --git a/src/bin/efl/efl_debug.c b/src/bin/efl/efl_debug.c
index 4cb4b03c58..5c0ee959c0 100644
--- a/src/bin/efl/efl_debug.c
+++ b/src/bin/efl/efl_debug.c
@@ -21,10 +21,6 @@
21#include "efl_debug_common.h" 21#include "efl_debug_common.h"
22 22
23static Eo *dialer; 23static Eo *dialer;
24static Eo *input;
25static Eo *output;
26static Eo *send_copier;
27static Eo *recv_copier;
28 24
29static Eina_List *waiting; 25static Eina_List *waiting;
30 26
@@ -71,7 +67,7 @@ _on_data(void *data EINA_UNUSED, const Efl_Event *event EINA_UNUSED)
71 Eina_Slice slice, payload; 67 Eina_Slice slice, payload;
72 Efl_Debug_Message_Header msgheader; 68 Efl_Debug_Message_Header msgheader;
73 69
74 if (!efl_io_queue_slice_get(output, &slice)) 70 if (!efl_io_buffered_stream_slice_get(dialer, &slice))
75 return; 71 return;
76 72
77 if (slice.len < sizeof(msgheader)) 73 if (slice.len < sizeof(msgheader))
@@ -94,7 +90,7 @@ _on_data(void *data EINA_UNUSED, const Efl_Event *event EINA_UNUSED)
94 90
95 _process_reply(msgheader.op, payload); 91 _process_reply(msgheader.op, payload);
96 92
97 efl_io_queue_discard(output, sizeof(msgheader) + payload.len); 93 efl_io_buffered_stream_discard(dialer, sizeof(msgheader) + payload.len);
98} 94}
99 95
100static Eina_Bool 96static Eina_Bool
@@ -111,14 +107,14 @@ _command_send(const char op[static 4], const void *data, unsigned int len)
111 s.mem = &msghdr; 107 s.mem = &msghdr;
112 s.len = sizeof(msghdr); 108 s.len = sizeof(msghdr);
113 109
114 err = efl_io_writer_write(input, &s, &r); 110 err = efl_io_writer_write(dialer, &s, &r);
115 if (err || r.len) goto end; 111 if (err || r.len) goto end;
116 112
117 if (!len) goto end; 113 if (!len) goto end;
118 114
119 s.mem = data; 115 s.mem = data;
120 s.len = len; 116 s.len = len;
121 err = efl_io_writer_write(input, &s, &r); 117 err = efl_io_writer_write(dialer, &s, &r);
122 118
123 end: 119 end:
124 if (err) 120 if (err)
@@ -139,19 +135,19 @@ _command_send(const char op[static 4], const void *data, unsigned int len)
139} 135}
140 136
141static void 137static void
142_finished_sending(void *data EINA_UNUSED, const Efl_Event *event EINA_UNUSED) 138_write_finished(void *data EINA_UNUSED, const Efl_Event *event EINA_UNUSED)
143{ 139{
144 if (!waiting) ecore_main_loop_quit(); 140 if (!waiting) ecore_main_loop_quit();
145} 141}
146 142
147static void 143static void
148_dialer_eos(void *data EINA_UNUSED, const Efl_Event *event EINA_UNUSED) 144_finished(void *data EINA_UNUSED, const Efl_Event *event EINA_UNUSED)
149{ 145{
150 ecore_main_loop_quit(); 146 ecore_main_loop_quit();
151} 147}
152 148
153static void 149static void
154_dialer_error(void *data EINA_UNUSED, const Efl_Event *event) 150_error(void *data EINA_UNUSED, const Efl_Event *event)
155{ 151{
156 Eina_Error *perr = event->info; 152 Eina_Error *perr = event->info;
157 153
@@ -213,7 +209,8 @@ main(int argc, char **argv)
213 loop = ecore_main_loop_get(); 209 loop = ecore_main_loop_get();
214 210
215#ifdef EFL_NET_DIALER_UNIX_CLASS 211#ifdef EFL_NET_DIALER_UNIX_CLASS
216 dialer = efl_add(EFL_NET_DIALER_UNIX_CLASS, loop); 212 dialer = efl_add(EFL_NET_DIALER_SIMPLE_CLASS, loop,
213 efl_net_dialer_simple_inner_class_set(efl_added, EFL_NET_DIALER_UNIX_CLASS));
217#else 214#else
218 /* TODO: maybe start a TCP using locahost:12345? 215 /* TODO: maybe start a TCP using locahost:12345?
219 * Right now eina_debug_monitor is only for AF_UNIX, so not an issue. 216 * Right now eina_debug_monitor is only for AF_UNIX, so not an issue.
@@ -226,48 +223,10 @@ main(int argc, char **argv)
226 retval = EXIT_FAILURE; 223 retval = EXIT_FAILURE;
227 goto end; 224 goto end;
228 } 225 }
229 efl_event_callback_add(dialer, EFL_NET_DIALER_EVENT_ERROR, _dialer_error, NULL); 226 efl_event_callback_add(dialer, EFL_IO_BUFFERED_STREAM_EVENT_ERROR, _error, NULL);
230 efl_event_callback_add(dialer, EFL_IO_READER_EVENT_EOS, _dialer_eos, NULL); 227 efl_event_callback_add(dialer, EFL_IO_BUFFERED_STREAM_EVENT_SLICE_CHANGED, _on_data, NULL);
231 228 efl_event_callback_add(dialer, EFL_IO_BUFFERED_STREAM_EVENT_WRITE_FINISHED, _write_finished, NULL);
232 input = efl_add(EFL_IO_QUEUE_CLASS, loop); 229 efl_event_callback_add(dialer, EFL_IO_BUFFERED_STREAM_EVENT_FINISHED, _finished, NULL);
233 if (!input)
234 {
235 fprintf(stderr, "ERROR: could not create input queue\n");
236 retval = EXIT_FAILURE;
237 goto end;
238 }
239
240 output = efl_add(EFL_IO_QUEUE_CLASS, loop,
241 efl_event_callback_add(efl_added, EFL_IO_QUEUE_EVENT_SLICE_CHANGED, _on_data, NULL));
242 if (!output)
243 {
244 fprintf(stderr, "ERROR: could not create output queue\n");
245 retval = EXIT_FAILURE;
246 goto end;
247 }
248
249 send_copier = efl_add(EFL_IO_COPIER_CLASS, loop,
250 efl_io_copier_source_set(efl_added, input),
251 efl_io_copier_destination_set(efl_added, dialer),
252 efl_io_closer_close_on_destructor_set(efl_added, EINA_FALSE),
253 efl_event_callback_add(efl_added, EFL_IO_COPIER_EVENT_DONE, _finished_sending, NULL));
254 if (!send_copier)
255 {
256 fprintf(stderr, "ERROR: could not create send copier\n");
257 retval = EXIT_FAILURE;
258 goto end;
259 }
260
261 recv_copier = efl_add(EFL_IO_COPIER_CLASS, loop,
262 efl_io_copier_source_set(efl_added, dialer),
263 efl_io_copier_destination_set(efl_added, output),
264 efl_io_closer_close_on_destructor_set(efl_added, EINA_FALSE));
265 if (!recv_copier)
266 {
267 fprintf(stderr, "ERROR: could not create receive copier\n");
268 retval = EXIT_FAILURE;
269 goto end;
270 }
271 230
272 for (i = 1; i < argc; i++) 231 for (i = 1; i < argc; i++)
273 { 232 {
@@ -350,7 +309,7 @@ main(int argc, char **argv)
350 goto end; 309 goto end;
351 } 310 }
352 } 311 }
353 efl_io_queue_eos_mark(input); 312 efl_io_buffered_stream_eos_mark(dialer);
354 313
355 err = efl_net_dialer_dial(dialer, path); 314 err = efl_net_dialer_dial(dialer, path);
356 if (err) 315 if (err)
@@ -362,17 +321,9 @@ main(int argc, char **argv)
362 321
363 ecore_main_loop_begin(); 322 ecore_main_loop_begin();
364 323
365 while ((!efl_io_closer_closed_get(dialer)) &&
366 efl_io_queue_usage_get(input))
367 efl_io_copier_flush(send_copier, EINA_TRUE, EINA_TRUE);
368
369 end: 324 end:
370 eina_list_free(waiting); 325 eina_list_free(waiting);
371 efl_del(input);
372 efl_del(output);
373 efl_del(dialer); 326 efl_del(dialer);
374 efl_del(send_copier);
375 efl_del(recv_copier);
376 free(path); 327 free(path);
377 328
378 ecore_con_shutdown(); 329 ecore_con_shutdown();