summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCedric BAIL <cedric@osg.samsung.com>2018-01-08 13:19:48 -0800
committerCedric BAIL <cedric@osg.samsung.com>2018-01-08 13:19:48 -0800
commitdbba64a5f9564c3631975bdf2cbc07f6ad87c001 (patch)
tree84532d7756aa477dfa53d2bf9c4503139d558226
parent8428289c9489c5146d7e6d1eebde380a0d0ce19d (diff)
ecore: remove more use of main loop reference from unified API example.
-rw-r--r--src/examples/ecore/efl_io_copier_example.c95
1 files changed, 57 insertions, 38 deletions
diff --git a/src/examples/ecore/efl_io_copier_example.c b/src/examples/ecore/efl_io_copier_example.c
index 603da4dda0..016b4486f5 100644
--- a/src/examples/ecore/efl_io_copier_example.c
+++ b/src/examples/ecore/efl_io_copier_example.c
@@ -1,7 +1,4 @@
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 4
@@ -200,7 +197,7 @@ _copier_done(void *data EINA_UNUSED, const Efl_Event *event)
200 } 197 }
201 198
202 fprintf(stderr, "INFO: done\n"); 199 fprintf(stderr, "INFO: done\n");
203 ecore_main_loop_quit(); 200 efl_loop_quit(efl_loop_get(event->object), EINA_VALUE_EMPTY);
204} 201}
205 202
206static void 203static void
@@ -209,7 +206,7 @@ _copier_error(void *data EINA_UNUSED, const Efl_Event *event)
209 const Eina_Error *perr = event->info; 206 const Eina_Error *perr = event->info;
210 fprintf(stderr, "INFO: error: %d '%s'\n", *perr, eina_error_msg_get(*perr)); 207 fprintf(stderr, "INFO: error: %d '%s'\n", *perr, eina_error_msg_get(*perr));
211 retval = EXIT_FAILURE; 208 retval = EXIT_FAILURE;
212 ecore_main_loop_quit(); 209 efl_loop_quit(efl_loop_get(event->object), EINA_VALUE_EMPTY);
213} 210}
214 211
215static void 212static void
@@ -362,8 +359,38 @@ static const Ecore_Getopt options = {
362 } 359 }
363}; 360};
364 361
365int 362static Eo *copier = NULL;
366main(int argc, char **argv) 363
364EAPI_MAIN void
365efl_pause(void *data EINA_UNUSED,
366 const Efl_Event *ev EINA_UNUSED)
367{
368}
369
370EAPI_MAIN void
371efl_resume(void *data EINA_UNUSED,
372 const Efl_Event *ev EINA_UNUSED)
373{
374}
375
376EAPI_MAIN void
377efl_terminate(void *data EINA_UNUSED,
378 const Efl_Event *ev EINA_UNUSED)
379{
380 /* FIXME: For the moment the main loop doesn't get
381 properly destroyed on shutdown which disallow
382 relying on parent destroying their children */
383 if (copier)
384 {
385 efl_io_closer_close(copier);
386 efl_del(copier);
387 }
388 copier = NULL;
389}
390
391EAPI_MAIN void
392efl_main(void *data EINA_UNUSED,
393 const Efl_Event *ev)
367{ 394{
368 char *input_fname = NULL; 395 char *input_fname = NULL;
369 char *output_fname = NULL; 396 char *output_fname = NULL;
@@ -394,14 +421,10 @@ main(int argc, char **argv)
394 ECORE_GETOPT_VALUE_NONE /* sentinel */ 421 ECORE_GETOPT_VALUE_NONE /* sentinel */
395 }; 422 };
396 int args; 423 int args;
397 Eo *input, *output, *copier; 424 Eo *input, *output;
398 Eina_Slice line_delm_slice = EINA_SLICE_STR_LITERAL(""); 425 Eina_Slice line_delm_slice = EINA_SLICE_STR_LITERAL("");
399 426
400 ecore_init(); 427 args = ecore_getopt_parse(&options, values, 0, NULL);
401 ecore_con_init();
402 ecore_con_url_init();
403
404 args = ecore_getopt_parse(&options, values, argc, argv);
405 if (args < 0) 428 if (args < 0)
406 { 429 {
407 fputs("ERROR: Could not parse command line options.\n", stderr); 430 fputs("ERROR: Could not parse command line options.\n", stderr);
@@ -411,7 +434,7 @@ main(int argc, char **argv)
411 434
412 if (quit_option) goto end; 435 if (quit_option) goto end;
413 436
414 args = ecore_getopt_parse_positional(&options, values, argc, argv, args); 437 args = ecore_getopt_parse_positional(&options, values, 0, NULL, args);
415 if (args < 0) 438 if (args < 0)
416 { 439 {
417 fputs("ERROR: Could not parse positional arguments.\n", stderr); 440 fputs("ERROR: Could not parse positional arguments.\n", stderr);
@@ -446,7 +469,7 @@ main(int argc, char **argv)
446 */ 469 */
447 const char *address = input_fname + strlen("tcp://"); 470 const char *address = input_fname + strlen("tcp://");
448 Eina_Error err; 471 Eina_Error err;
449 input = efl_add(EFL_NET_DIALER_TCP_CLASS, efl_main_loop_get(), 472 input = efl_add(EFL_NET_DIALER_TCP_CLASS, ev->object,
450 efl_event_callback_array_add(efl_added, input_cbs(), NULL), /* optional */ 473 efl_event_callback_array_add(efl_added, input_cbs(), NULL), /* optional */
451 efl_event_callback_array_add(efl_added, dialer_cbs(), NULL) /* optional */ 474 efl_event_callback_array_add(efl_added, dialer_cbs(), NULL) /* optional */
452 ); 475 );
@@ -470,7 +493,7 @@ main(int argc, char **argv)
470 { 493 {
471 Eina_Error err; 494 Eina_Error err;
472 495
473 input = efl_add(EFL_NET_DIALER_HTTP_CLASS, efl_main_loop_get(), 496 input = efl_add(EFL_NET_DIALER_HTTP_CLASS, ev->object,
474 efl_net_dialer_http_method_set(efl_added, "GET"), 497 efl_net_dialer_http_method_set(efl_added, "GET"),
475 efl_event_callback_array_add(efl_added, input_cbs(), NULL), /* optional */ 498 efl_event_callback_array_add(efl_added, input_cbs(), NULL), /* optional */
476 efl_event_callback_array_add(efl_added, dialer_cbs(), NULL), /* optional */ 499 efl_event_callback_array_add(efl_added, dialer_cbs(), NULL), /* optional */
@@ -496,7 +519,7 @@ main(int argc, char **argv)
496 { 519 {
497 Eina_Error err; 520 Eina_Error err;
498 521
499 input = efl_add(EFL_NET_DIALER_WEBSOCKET_CLASS, efl_main_loop_get(), 522 input = efl_add(EFL_NET_DIALER_WEBSOCKET_CLASS, ev->object,
500 efl_net_dialer_websocket_streaming_mode_set(efl_added, EFL_NET_DIALER_WEBSOCKET_STREAMING_MODE_TEXT), 523 efl_net_dialer_websocket_streaming_mode_set(efl_added, EFL_NET_DIALER_WEBSOCKET_STREAMING_MODE_TEXT),
501 efl_event_callback_array_add(efl_added, input_cbs(), NULL), /* optional */ 524 efl_event_callback_array_add(efl_added, input_cbs(), NULL), /* optional */
502 efl_event_callback_array_add(efl_added, dialer_cbs(), NULL) /* optional */ 525 efl_event_callback_array_add(efl_added, dialer_cbs(), NULL) /* optional */
@@ -525,7 +548,7 @@ main(int argc, char **argv)
525 const char *bind_address = input_fname + strlen("udp://"); 548 const char *bind_address = input_fname + strlen("udp://");
526 const char *address; 549 const char *address;
527 Eina_Error err; 550 Eina_Error err;
528 input = efl_add(EFL_NET_DIALER_UDP_CLASS, efl_main_loop_get(), 551 input = efl_add(EFL_NET_DIALER_UDP_CLASS, ev->object,
529 efl_net_socket_udp_bind_set(efl_added, bind_address), /* use the address as the bind, so we can get data at it */ 552 efl_net_socket_udp_bind_set(efl_added, bind_address), /* use the address as the bind, so we can get data at it */
530 efl_event_callback_array_add(efl_added, input_cbs(), NULL), /* optional */ 553 efl_event_callback_array_add(efl_added, input_cbs(), NULL), /* optional */
531 efl_event_callback_array_add(efl_added, dialer_cbs(), NULL) /* optional */ 554 efl_event_callback_array_add(efl_added, dialer_cbs(), NULL) /* optional */
@@ -557,7 +580,7 @@ main(int argc, char **argv)
557 */ 580 */
558 const char *address = input_fname + strlen("unix://"); 581 const char *address = input_fname + strlen("unix://");
559 Eina_Error err; 582 Eina_Error err;
560 input = efl_add(EFL_NET_DIALER_UNIX_CLASS, efl_main_loop_get(), 583 input = efl_add(EFL_NET_DIALER_UNIX_CLASS, ev->object,
561 efl_event_callback_array_add(efl_added, input_cbs(), NULL), /* optional */ 584 efl_event_callback_array_add(efl_added, input_cbs(), NULL), /* optional */
562 efl_event_callback_array_add(efl_added, dialer_cbs(), NULL) /* optional */ 585 efl_event_callback_array_add(efl_added, dialer_cbs(), NULL) /* optional */
563 ); 586 );
@@ -586,7 +609,7 @@ main(int argc, char **argv)
586 */ 609 */
587 const char *address = input_fname + strlen("windows://"); 610 const char *address = input_fname + strlen("windows://");
588 Eina_Error err; 611 Eina_Error err;
589 input = efl_add(EFL_NET_DIALER_WINDOWS_CLASS, efl_main_loop_get(), 612 input = efl_add(EFL_NET_DIALER_WINDOWS_CLASS, ev->object,
590 efl_event_callback_array_add(efl_added, input_cbs(), NULL), /* optional */ 613 efl_event_callback_array_add(efl_added, input_cbs(), NULL), /* optional */
591 efl_event_callback_array_add(efl_added, dialer_cbs(), NULL) /* optional */ 614 efl_event_callback_array_add(efl_added, dialer_cbs(), NULL) /* optional */
592 ); 615 );
@@ -614,7 +637,7 @@ main(int argc, char **argv)
614 */ 637 */
615 const char *address = input_fname + strlen("ssl://"); 638 const char *address = input_fname + strlen("ssl://");
616 Eina_Error err; 639 Eina_Error err;
617 input = efl_add(EFL_NET_DIALER_SSL_CLASS, efl_main_loop_get(), 640 input = efl_add(EFL_NET_DIALER_SSL_CLASS, ev->object,
618 efl_event_callback_array_add(efl_added, input_cbs(), NULL), /* optional */ 641 efl_event_callback_array_add(efl_added, input_cbs(), NULL), /* optional */
619 efl_event_callback_array_add(efl_added, dialer_cbs(), NULL) /* optional */ 642 efl_event_callback_array_add(efl_added, dialer_cbs(), NULL) /* optional */
620 ); 643 );
@@ -725,7 +748,7 @@ main(int argc, char **argv)
725 */ 748 */
726 const char *address = output_fname + strlen("tcp://"); 749 const char *address = output_fname + strlen("tcp://");
727 Eina_Error err; 750 Eina_Error err;
728 output = efl_add(EFL_NET_DIALER_TCP_CLASS, efl_main_loop_get(), 751 output = efl_add(EFL_NET_DIALER_TCP_CLASS, ev->object,
729 efl_event_callback_array_add(efl_added, output_cbs(), NULL), /* optional */ 752 efl_event_callback_array_add(efl_added, output_cbs(), NULL), /* optional */
730 efl_event_callback_array_add(efl_added, dialer_cbs(), NULL) /* optional */ 753 efl_event_callback_array_add(efl_added, dialer_cbs(), NULL) /* optional */
731 ); 754 );
@@ -749,7 +772,7 @@ main(int argc, char **argv)
749 { 772 {
750 Eina_Error err; 773 Eina_Error err;
751 774
752 output = efl_add(EFL_NET_DIALER_HTTP_CLASS, efl_main_loop_get(), 775 output = efl_add(EFL_NET_DIALER_HTTP_CLASS, ev->object,
753 efl_net_dialer_http_method_set(efl_added, "PUT"), 776 efl_net_dialer_http_method_set(efl_added, "PUT"),
754 efl_event_callback_array_add(efl_added, output_cbs(), NULL), /* optional */ 777 efl_event_callback_array_add(efl_added, output_cbs(), NULL), /* optional */
755 efl_event_callback_array_add(efl_added, dialer_cbs(), NULL), /* optional */ 778 efl_event_callback_array_add(efl_added, dialer_cbs(), NULL), /* optional */
@@ -775,7 +798,7 @@ main(int argc, char **argv)
775 { 798 {
776 Eina_Error err; 799 Eina_Error err;
777 800
778 output = efl_add(EFL_NET_DIALER_WEBSOCKET_CLASS, efl_main_loop_get(), 801 output = efl_add(EFL_NET_DIALER_WEBSOCKET_CLASS, ev->object,
779 efl_net_dialer_websocket_streaming_mode_set(efl_added, EFL_NET_DIALER_WEBSOCKET_STREAMING_MODE_TEXT), 802 efl_net_dialer_websocket_streaming_mode_set(efl_added, EFL_NET_DIALER_WEBSOCKET_STREAMING_MODE_TEXT),
780 efl_event_callback_array_add(efl_added, output_cbs(), NULL), /* optional */ 803 efl_event_callback_array_add(efl_added, output_cbs(), NULL), /* optional */
781 efl_event_callback_array_add(efl_added, dialer_cbs(), NULL) /* optional */ 804 efl_event_callback_array_add(efl_added, dialer_cbs(), NULL) /* optional */
@@ -803,7 +826,7 @@ main(int argc, char **argv)
803 */ 826 */
804 const char *address = output_fname + strlen("udp://"); 827 const char *address = output_fname + strlen("udp://");
805 Eina_Error err; 828 Eina_Error err;
806 output = efl_add(EFL_NET_DIALER_UDP_CLASS, efl_main_loop_get(), 829 output = efl_add(EFL_NET_DIALER_UDP_CLASS, ev->object,
807 efl_event_callback_array_add(efl_added, output_cbs(), NULL), /* optional */ 830 efl_event_callback_array_add(efl_added, output_cbs(), NULL), /* optional */
808 efl_event_callback_array_add(efl_added, dialer_cbs(), NULL) /* optional */ 831 efl_event_callback_array_add(efl_added, dialer_cbs(), NULL) /* optional */
809 ); 832 );
@@ -831,7 +854,7 @@ main(int argc, char **argv)
831 */ 854 */
832 const char *address = output_fname + strlen("unix://"); 855 const char *address = output_fname + strlen("unix://");
833 Eina_Error err; 856 Eina_Error err;
834 output = efl_add(EFL_NET_DIALER_UNIX_CLASS, efl_main_loop_get(), 857 output = efl_add(EFL_NET_DIALER_UNIX_CLASS, ev->object,
835 efl_event_callback_array_add(efl_added, output_cbs(), NULL), /* optional */ 858 efl_event_callback_array_add(efl_added, output_cbs(), NULL), /* optional */
836 efl_event_callback_array_add(efl_added, dialer_cbs(), NULL) /* optional */ 859 efl_event_callback_array_add(efl_added, dialer_cbs(), NULL) /* optional */
837 ); 860 );
@@ -860,7 +883,7 @@ main(int argc, char **argv)
860 */ 883 */
861 const char *address = output_fname + strlen("windows://"); 884 const char *address = output_fname + strlen("windows://");
862 Eina_Error err; 885 Eina_Error err;
863 output = efl_add(EFL_NET_DIALER_WINDOWS_CLASS, efl_main_loop_get(), 886 output = efl_add(EFL_NET_DIALER_WINDOWS_CLASS, ev->object,
864 efl_event_callback_array_add(efl_added, output_cbs(), NULL), /* optional */ 887 efl_event_callback_array_add(efl_added, output_cbs(), NULL), /* optional */
865 efl_event_callback_array_add(efl_added, dialer_cbs(), NULL) /* optional */ 888 efl_event_callback_array_add(efl_added, dialer_cbs(), NULL) /* optional */
866 ); 889 );
@@ -888,7 +911,7 @@ main(int argc, char **argv)
888 */ 911 */
889 const char *address = output_fname + strlen("ssl://"); 912 const char *address = output_fname + strlen("ssl://");
890 Eina_Error err; 913 Eina_Error err;
891 output = efl_add(EFL_NET_DIALER_SSL_CLASS, efl_main_loop_get(), 914 output = efl_add(EFL_NET_DIALER_SSL_CLASS, ev->object,
892 efl_event_callback_array_add(efl_added, output_cbs(), NULL), /* optional */ 915 efl_event_callback_array_add(efl_added, output_cbs(), NULL), /* optional */
893 efl_event_callback_array_add(efl_added, dialer_cbs(), NULL) /* optional */ 916 efl_event_callback_array_add(efl_added, dialer_cbs(), NULL) /* optional */
894 ); 917 );
@@ -941,7 +964,7 @@ main(int argc, char **argv)
941 if (line_delimiter) 964 if (line_delimiter)
942 line_delm_slice = (Eina_Slice)EINA_SLICE_STR(line_delimiter); 965 line_delm_slice = (Eina_Slice)EINA_SLICE_STR(line_delimiter);
943 966
944 copier = efl_add(EFL_IO_COPIER_CLASS, efl_main_loop_get(), 967 copier = efl_add(EFL_IO_COPIER_CLASS, ev->object,
945 efl_io_copier_source_set(efl_added, input), /* mandatory */ 968 efl_io_copier_source_set(efl_added, input), /* mandatory */
946 efl_io_copier_destination_set(efl_added, output), /* optional, see :none: */ 969 efl_io_copier_destination_set(efl_added, output), /* optional, see :none: */
947 efl_io_copier_line_delimiter_set(efl_added, line_delm_slice), /* optional */ 970 efl_io_copier_line_delimiter_set(efl_added, line_delm_slice), /* optional */
@@ -963,10 +986,7 @@ main(int argc, char **argv)
963 output, 986 output,
964 output ? efl_class_name_get(efl_class_get(output)) : ":none:"); 987 output ? efl_class_name_get(efl_class_get(output)) : ":none:");
965 988
966 ecore_main_loop_begin(); 989 return ;
967 efl_io_closer_close(copier);
968 efl_del(copier);
969 copier = NULL;
970 990
971 end_output: 991 end_output:
972 if (output) 992 if (output)
@@ -979,9 +999,8 @@ main(int argc, char **argv)
979 input = NULL; 999 input = NULL;
980 1000
981 end: 1001 end:
982 ecore_con_url_shutdown();
983 ecore_con_shutdown();
984 ecore_shutdown();
985 1002
986 return retval; 1003 efl_loop_quit(ev->object, eina_value_int_init(retval));
987} 1004}
1005
1006EFL_MAIN_EX();