summaryrefslogtreecommitdiff
path: root/unsorted/ecore/efl_net_dialer_websocket_autobahntestee.c
diff options
context:
space:
mode:
authorCedric BAIL <cedric@osg.samsung.com>2018-01-09 16:20:44 -0800
committerCedric BAIL <cedric@osg.samsung.com>2018-01-09 16:29:30 -0800
commit3491976314cb4e43a3a0cab2b0c941d07f35df63 (patch)
tree36f4ad15ba7f10699138a47e34067e8c99116c73 /unsorted/ecore/efl_net_dialer_websocket_autobahntestee.c
parenta43d44200e3a4562003f85cf4e726cefe4b0b134 (diff)
ecore: remove use of efl_main_loop_get from efl_net_dialer_websocket_autobahntestee.
Diffstat (limited to 'unsorted/ecore/efl_net_dialer_websocket_autobahntestee.c')
-rw-r--r--unsorted/ecore/efl_net_dialer_websocket_autobahntestee.c114
1 files changed, 65 insertions, 49 deletions
diff --git a/unsorted/ecore/efl_net_dialer_websocket_autobahntestee.c b/unsorted/ecore/efl_net_dialer_websocket_autobahntestee.c
index fa3dc0f..fd0c098 100644
--- a/unsorted/ecore/efl_net_dialer_websocket_autobahntestee.c
+++ b/unsorted/ecore/efl_net_dialer_websocket_autobahntestee.c
@@ -1,12 +1,8 @@
1#define EFL_BETA_API_SUPPORT 1 1#include <Efl_Net.h>
2#define EFL_EO_API_SUPPORT 1
3#include <Ecore.h>
4#include <Ecore_Con.h>
5#include <Ecore_Getopt.h> 2#include <Ecore_Getopt.h>
6#include <fcntl.h> 3#include <fcntl.h>
7#include <ctype.h> 4#include <ctype.h>
8 5
9static int retval = EXIT_SUCCESS;
10static char *address = NULL; 6static char *address = NULL;
11static char *agent = "efl_net_dialer_websocket"; 7static char *agent = "efl_net_dialer_websocket";
12static unsigned int start_index = 0; 8static unsigned int start_index = 0;
@@ -234,7 +230,7 @@ _error(void *data EINA_UNUSED, const Efl_Event *event)
234 const Eina_Error *perr = event->info; 230 const Eina_Error *perr = event->info;
235 fprintf(stderr, "ERROR: %s error: %d '%s'\n", 231 fprintf(stderr, "ERROR: %s error: %d '%s'\n",
236 efl_name_get(dialer), *perr, eina_error_msg_get(*perr)); 232 efl_name_get(dialer), *perr, eina_error_msg_get(*perr));
237 retval = EXIT_FAILURE; 233 efl_loop_quit(efl_loop_get(event->object), eina_value_int_init(EXIT_FAILURE));
238} 234}
239 235
240static void 236static void
@@ -257,16 +253,16 @@ EFL_CALLBACKS_ARRAY_DEFINE(dialer_cbs,
257 { EFL_EVENT_DEL, _del }); 253 { EFL_EVENT_DEL, _del });
258 254
259static Eo * 255static Eo *
260_websocket_new(const char *name) 256_websocket_new(const char *name, Eo *loop)
261{ 257{
262 Eo *dialer; 258 Eo *dialer;
263 259
264 dialer = efl_add(EFL_NET_DIALER_WEBSOCKET_CLASS, efl_main_loop_get(), 260 dialer = efl_add(EFL_NET_DIALER_WEBSOCKET_CLASS, loop,
265 efl_name_set(efl_added, name), 261 efl_name_set(efl_added, name),
266 efl_event_callback_array_add(efl_added, dialer_cbs(), NULL)); 262 efl_event_callback_array_add(efl_added, dialer_cbs(), NULL));
267 if (!dialer) 263 if (!dialer)
268 { 264 {
269 retval = EXIT_FAILURE; 265 efl_loop_quit(loop, eina_value_int_init(EXIT_FAILURE));
270 fprintf(stderr, "ERROR: could not create WebSockets dialer '%s'\n", name); 266 fprintf(stderr, "ERROR: could not create WebSockets dialer '%s'\n", name);
271 return NULL; 267 return NULL;
272 } 268 }
@@ -285,7 +281,7 @@ _closed_quit(void *data EINA_UNUSED, const Efl_Event *event)
285} 281}
286 282
287static void 283static void
288_tests_finished(void) 284_tests_finished(Eo *loop)
289{ 285{
290 Eo *dialer; 286 Eo *dialer;
291 char url[4096]; 287 char url[4096];
@@ -320,7 +316,7 @@ _tests_finished(void)
320 return; 316 return;
321 } 317 }
322 318
323 dialer = _websocket_new("update-reports"); 319 dialer = _websocket_new("update-reports", loop);
324 if (!dialer) 320 if (!dialer)
325 { 321 {
326 ecore_main_loop_quit(); 322 ecore_main_loop_quit();
@@ -332,11 +328,10 @@ _tests_finished(void)
332 err = efl_net_dialer_dial(dialer, url); 328 err = efl_net_dialer_dial(dialer, url);
333 if (err != 0) 329 if (err != 0)
334 { 330 {
335 retval = EXIT_FAILURE;
336 fprintf(stderr, "ERROR: could not dial '%s': %s", 331 fprintf(stderr, "ERROR: could not dial '%s': %s",
337 url, eina_error_msg_get(err)); 332 url, eina_error_msg_get(err));
338 efl_del(dialer); 333 efl_del(dialer);
339 ecore_main_loop_quit(); 334 efl_loop_quit(loop, eina_value_int_init(EXIT_FAILURE));
340 return; 335 return;
341 } 336 }
342 337
@@ -369,7 +364,7 @@ _echo_binary(void *data EINA_UNUSED, const Efl_Event *event)
369 efl_net_dialer_websocket_binary_send(dialer, *slice); 364 efl_net_dialer_websocket_binary_send(dialer, *slice);
370} 365}
371 366
372static Eina_Bool _websocket_test_next_case_tuple(void); 367static Eina_Bool _websocket_test_next_case_tuple(Eo *loop);
373 368
374static void 369static void
375_test_next_case_closed(void *data EINA_UNUSED, const Efl_Event *event) 370_test_next_case_closed(void *data EINA_UNUSED, const Efl_Event *event)
@@ -377,8 +372,8 @@ _test_next_case_closed(void *data EINA_UNUSED, const Efl_Event *event)
377 Eo *dialer = event->object; 372 Eo *dialer = event->object;
378 efl_del(dialer); 373 efl_del(dialer);
379 374
380 if (!_websocket_test_next_case_tuple()) 375 if (!_websocket_test_next_case_tuple(efl_loop_get(event->object)))
381 _tests_finished(); 376 _tests_finished(efl_loop_get(event->object));
382} 377}
383 378
384EFL_CALLBACKS_ARRAY_DEFINE(_test_next_case_tuple_cbs, 379EFL_CALLBACKS_ARRAY_DEFINE(_test_next_case_tuple_cbs,
@@ -387,7 +382,7 @@ EFL_CALLBACKS_ARRAY_DEFINE(_test_next_case_tuple_cbs,
387 { EFL_IO_CLOSER_EVENT_CLOSED, _test_next_case_closed }); 382 { EFL_IO_CLOSER_EVENT_CLOSED, _test_next_case_closed });
388 383
389static Eina_Bool 384static Eina_Bool
390_websocket_test_next_case_tuple(void) 385_websocket_test_next_case_tuple(Eo *loop)
391{ 386{
392 Eo *dialer; 387 Eo *dialer;
393 char url[4096]; 388 char url[4096];
@@ -423,7 +418,7 @@ _websocket_test_next_case_tuple(void)
423 snprintf(name, sizeof(name), "test_case=%s", str); 418 snprintf(name, sizeof(name), "test_case=%s", str);
424 free(str); 419 free(str);
425 420
426 dialer = _websocket_new(name); 421 dialer = _websocket_new(name, loop);
427 if (!dialer) return EINA_FALSE; 422 if (!dialer) return EINA_FALSE;
428 423
429 efl_event_callback_array_add(dialer, _test_next_case_tuple_cbs(), NULL); 424 efl_event_callback_array_add(dialer, _test_next_case_tuple_cbs(), NULL);
@@ -431,10 +426,10 @@ _websocket_test_next_case_tuple(void)
431 err = efl_net_dialer_dial(dialer, url); 426 err = efl_net_dialer_dial(dialer, url);
432 if (err != 0) 427 if (err != 0)
433 { 428 {
434 retval = EXIT_FAILURE;
435 fprintf(stderr, "ERROR: could not dial '%s': %s", 429 fprintf(stderr, "ERROR: could not dial '%s': %s",
436 url, eina_error_msg_get(err)); 430 url, eina_error_msg_get(err));
437 efl_del(dialer); 431 efl_del(dialer);
432 efl_loop_quit(loop, eina_value_int_init(EXIT_FAILURE));
438 return EINA_FALSE; 433 return EINA_FALSE;
439 } 434 }
440 435
@@ -443,7 +438,7 @@ _websocket_test_next_case_tuple(void)
443 return EINA_TRUE; 438 return EINA_TRUE;
444} 439}
445 440
446static Eina_Bool _websocket_test_index(unsigned int idx); 441static Eina_Bool _websocket_test_index(unsigned int idx, Eo *loop);
447 442
448static void 443static void
449_test_index_closed(void *data EINA_UNUSED, const Efl_Event *event) 444_test_index_closed(void *data EINA_UNUSED, const Efl_Event *event)
@@ -451,8 +446,8 @@ _test_index_closed(void *data EINA_UNUSED, const Efl_Event *event)
451 Eo *dialer = event->object; 446 Eo *dialer = event->object;
452 efl_del(dialer); 447 efl_del(dialer);
453 448
454 if (!_websocket_test_index(current_index + 1)) 449 if (!_websocket_test_index(current_index + 1, efl_loop_get(event->object)))
455 _tests_finished(); 450 _tests_finished(efl_loop_get(event->object));
456} 451}
457 452
458EFL_CALLBACKS_ARRAY_DEFINE(_test_index_cbs, 453EFL_CALLBACKS_ARRAY_DEFINE(_test_index_cbs,
@@ -461,7 +456,7 @@ EFL_CALLBACKS_ARRAY_DEFINE(_test_index_cbs,
461 { EFL_IO_CLOSER_EVENT_CLOSED, _test_index_closed }); 456 { EFL_IO_CLOSER_EVENT_CLOSED, _test_index_closed });
462 457
463static Eina_Bool 458static Eina_Bool
464_websocket_test_index(unsigned int idx) 459_websocket_test_index(unsigned int idx, Eo *loop)
465{ 460{
466 Eo *dialer; 461 Eo *dialer;
467 char url[4096]; 462 char url[4096];
@@ -491,7 +486,7 @@ _websocket_test_index(unsigned int idx)
491 486
492 snprintf(name, sizeof(name), "test_case=%u", idx); 487 snprintf(name, sizeof(name), "test_case=%u", idx);
493 488
494 dialer = _websocket_new(name); 489 dialer = _websocket_new(name, loop);
495 if (!dialer) return EINA_FALSE; 490 if (!dialer) return EINA_FALSE;
496 491
497 efl_event_callback_array_add(dialer, _test_index_cbs(), NULL); 492 efl_event_callback_array_add(dialer, _test_index_cbs(), NULL);
@@ -499,10 +494,10 @@ _websocket_test_index(unsigned int idx)
499 err = efl_net_dialer_dial(dialer, url); 494 err = efl_net_dialer_dial(dialer, url);
500 if (err != 0) 495 if (err != 0)
501 { 496 {
502 retval = EXIT_FAILURE;
503 fprintf(stderr, "ERROR: could not dial '%s': %s", 497 fprintf(stderr, "ERROR: could not dial '%s': %s",
504 url, eina_error_msg_get(err)); 498 url, eina_error_msg_get(err));
505 efl_del(dialer); 499 efl_del(dialer);
500 efl_loop_quit(loop, eina_value_int_init(EXIT_FAILURE));
506 return EINA_FALSE; 501 return EINA_FALSE;
507 } 502 }
508 503
@@ -538,8 +533,8 @@ _load_tests_closed(void *data EINA_UNUSED, const Efl_Event *event)
538 Eo *dialer = event->object; 533 Eo *dialer = event->object;
539 efl_del(dialer); 534 efl_del(dialer);
540 535
541 if (!_websocket_test_index(start_index)) 536 if (!_websocket_test_index(start_index, efl_loop_get(event->object)))
542 _tests_finished(); 537 _tests_finished(efl_loop_get(event->object));
543} 538}
544 539
545EFL_CALLBACKS_ARRAY_DEFINE(_load_tests_cbs, 540EFL_CALLBACKS_ARRAY_DEFINE(_load_tests_cbs,
@@ -547,7 +542,7 @@ EFL_CALLBACKS_ARRAY_DEFINE(_load_tests_cbs,
547 { EFL_IO_CLOSER_EVENT_CLOSED, _load_tests_closed }); 542 { EFL_IO_CLOSER_EVENT_CLOSED, _load_tests_closed });
548 543
549static Eina_Bool 544static Eina_Bool
550_websocket_load_tests(void) 545_websocket_load_tests(Eo *loop)
551{ 546{
552 Eo *dialer; 547 Eo *dialer;
553 char url[4096]; 548 char url[4096];
@@ -568,7 +563,7 @@ _websocket_load_tests(void)
568 return EINA_FALSE; 563 return EINA_FALSE;
569 } 564 }
570 565
571 dialer = _websocket_new("get-case-count"); 566 dialer = _websocket_new("get-case-count", loop);
572 if (!dialer) return EINA_FALSE; 567 if (!dialer) return EINA_FALSE;
573 568
574 efl_event_callback_array_add(dialer, _load_tests_cbs(), NULL); 569 efl_event_callback_array_add(dialer, _load_tests_cbs(), NULL);
@@ -576,10 +571,10 @@ _websocket_load_tests(void)
576 err = efl_net_dialer_dial(dialer, url); 571 err = efl_net_dialer_dial(dialer, url);
577 if (err != 0) 572 if (err != 0)
578 { 573 {
579 retval = EXIT_FAILURE;
580 fprintf(stderr, "ERROR: could not dial '%s': %s", 574 fprintf(stderr, "ERROR: could not dial '%s': %s",
581 url, eina_error_msg_get(err)); 575 url, eina_error_msg_get(err));
582 efl_del(dialer); 576 efl_del(dialer);
577 efl_loop_quit(loop, eina_value_int_init(EXIT_FAILURE));
583 return EINA_FALSE; 578 return EINA_FALSE;
584 } 579 }
585 580
@@ -620,8 +615,36 @@ static const Ecore_Getopt options = {
620 } 615 }
621}; 616};
622 617
623int 618EAPI_MAIN void
624main(int argc, char **argv) 619efl_pause(void *data EINA_UNUSED,
620 const Efl_Event *ev EINA_UNUSED)
621{
622}
623
624EAPI_MAIN void
625efl_resume(void *data EINA_UNUSED,
626 const Efl_Event *ev EINA_UNUSED)
627{
628}
629
630EAPI_MAIN void
631efl_terminate(void *data EINA_UNUSED,
632 const Efl_Event *ev EINA_UNUSED)
633{
634 /* FIXME: For the moment the main loop doesn't get
635 properly destroyed on shutdown which disallow
636 relying on parent destroying their children */
637 if (pending)
638 {
639 efl_del(pending);
640 pending = NULL;
641 }
642 if (verbose) fprintf(stderr, "INFO: main loop finished.\n");
643}
644
645EAPI_MAIN void
646efl_main(void *data EINA_UNUSED,
647 const Efl_Event *ev)
625{ 648{
626 Eina_Bool quit_option = EINA_FALSE; 649 Eina_Bool quit_option = EINA_FALSE;
627 Ecore_Getopt_Value values[] = { 650 Ecore_Getopt_Value values[] = {
@@ -646,48 +669,41 @@ main(int argc, char **argv)
646 int args; 669 int args;
647 Eina_Bool r; 670 Eina_Bool r;
648 671
649 ecore_init(); 672 args = ecore_getopt_parse(&options, values, 0, NULL);
650 ecore_con_init();
651 ecore_con_url_init();
652
653 args = ecore_getopt_parse(&options, values, argc, argv);
654 if (args < 0) 673 if (args < 0)
655 { 674 {
656 fputs("ERROR: Could not parse command line options.\n", stderr); 675 fputs("ERROR: Could not parse command line options.\n", stderr);
657 retval = EXIT_FAILURE;
658 goto end; 676 goto end;
659 } 677 }
660 678
661 if (quit_option) goto end; 679 if (quit_option) goto end;
662 680
663 args = ecore_getopt_parse_positional(&options, values, argc, argv, args); 681 args = ecore_getopt_parse_positional(&options, values, 0, NULL, args);
664 if (args < 0) 682 if (args < 0)
665 { 683 {
666 fputs("ERROR: Could not parse positional arguments.\n", stderr); 684 fputs("ERROR: Could not parse positional arguments.\n", stderr);
667 retval = EXIT_FAILURE;
668 goto end; 685 goto end;
669 } 686 }
670 687
671 if (case_tuples) 688 if (case_tuples)
672 r = _websocket_test_next_case_tuple(); 689 r = _websocket_test_next_case_tuple(ev->object);
673 else if (start_index == end_index) 690 else if (start_index == end_index)
674 r = _websocket_test_index(start_index); 691 r = _websocket_test_index(start_index, ev->object);
675 else 692 else
676 r = _websocket_load_tests(); 693 r = _websocket_load_tests(ev->object);
677 694
678 if (r) 695 if (r)
679 { 696 {
680 ecore_main_loop_begin(); 697 ecore_main_loop_begin();
681 if (verbose) fprintf(stderr, "INFO: main loop finished. retval=%d\n", retval);
682 } 698 }
683 699
684 if (pending) 700 if (pending)
685 efl_del(pending); 701 efl_del(pending);
686 702
687 end: 703 return ;
688 ecore_con_url_shutdown();
689 ecore_con_shutdown();
690 ecore_shutdown();
691 704
692 return retval; 705 end:
706 efl_loop_quit(efl_loop_get(ev->object), eina_value_int_init(EXIT_FAILURE));
693} 707}
708
709EFL_MAIN_EX();