ecore: remove use of efl_main_loop_get from efl_net_dialer_websocket_example.

This commit is contained in:
Cedric BAIL 2018-01-09 16:28:59 -08:00
parent 6667a914ac
commit dda427dc51
1 changed files with 44 additions and 31 deletions

View File

@ -1,13 +1,8 @@
#define EFL_BETA_API_SUPPORT 1
#define EFL_EO_API_SUPPORT 1
#include <Ecore.h>
#include <Ecore_Con.h>
#include <Efl_Net.h>
#include <Ecore_Getopt.h>
#include <fcntl.h>
#include <ctype.h>
static int retval = EXIT_SUCCESS;
static int lines_text = 0;
static int lines_binary = 0;
@ -102,7 +97,7 @@ _closed(void *data EINA_UNUSED, const Efl_Event *event)
{
fprintf(stderr, "INFO: closed %s\n",
efl_name_get(event->object));
ecore_main_loop_quit();
efl_loop_quit(efl_loop_get(event->object), EINA_VALUE_EMPTY);
}
static void
@ -141,8 +136,7 @@ _error(void *data EINA_UNUSED, const Efl_Event *event)
{
const Eina_Error *perr = event->info;
fprintf(stderr, "INFO: error: %d '%s'\n", *perr, eina_error_msg_get(*perr));
retval = EXIT_FAILURE;
ecore_main_loop_quit();
efl_loop_quit(efl_loop_get(event->object), eina_value_int_init(EXIT_FAILURE));
}
EFL_CALLBACKS_ARRAY_DEFINE(dialer_cbs,
@ -226,8 +220,39 @@ static const Ecore_Getopt options = {
}
};
int
main(int argc, char **argv)
static Eo *dialer = NULL;
EAPI_MAIN void
efl_pause(void *data EINA_UNUSED,
const Efl_Event *ev EINA_UNUSED)
{
}
EAPI_MAIN void
efl_resume(void *data EINA_UNUSED,
const Efl_Event *ev EINA_UNUSED)
{
}
EAPI_MAIN void
efl_terminate(void *data EINA_UNUSED,
const Efl_Event *ev EINA_UNUSED)
{
/* FIXME: For the moment the main loop doesn't get
properly destroyed on shutdown which disallow
relying on parent destroying their children */
if (dialer)
{
efl_del(dialer);
dialer = NULL;
}
fprintf(stderr, "INFO: main loop finished.\n");
}
EAPI_MAIN void
efl_main(void *data EINA_UNUSED,
const Efl_Event *ev)
{
char *address = NULL;
char *username = NULL;
@ -265,34 +290,28 @@ main(int argc, char **argv)
ECORE_GETOPT_VALUE_NONE /* sentinel */
};
int args;
Eo *dialer, *loop;
Eo *loop;
Efl_Net_Http_Authentication_Method authentication_method;
Efl_Net_Http_Header *header;
Eina_Iterator *itr;
Eina_Error err;
char *str;
ecore_init();
ecore_con_init();
ecore_con_url_init();
args = ecore_getopt_parse(&options, values, argc, argv);
args = ecore_getopt_parse(&options, values, 0, NULL);
if (args < 0)
{
fputs("ERROR: Could not parse command line options.\n", stderr);
retval = EXIT_FAILURE;
goto end;
}
if (quit_option) goto end;
loop = efl_main_loop_get();
loop = ev->object;
args = ecore_getopt_parse_positional(&options, values, argc, argv, args);
args = ecore_getopt_parse_positional(&options, values, 0, NULL, args);
if (args < 0)
{
fputs("ERROR: Could not parse positional arguments.\n", stderr);
retval = EXIT_FAILURE;
goto end;
}
@ -311,7 +330,6 @@ main(int argc, char **argv)
efl_event_callback_array_add(efl_added, dialer_cbs(), NULL));
if (!dialer)
{
retval = EXIT_FAILURE;
fprintf(stderr, "ERROR: could not create WebSockets dialer\n");
goto end;
}
@ -339,7 +357,6 @@ main(int argc, char **argv)
err = efl_net_dialer_dial(dialer, address);
if (err != 0)
{
retval = EXIT_FAILURE;
fprintf(stderr, "ERROR: could not dial '%s': %s",
address, eina_error_msg_get(err));
goto no_mainloop;
@ -368,17 +385,13 @@ main(int argc, char **argv)
fprintf(stderr, "INFO: %s\n", str);
eina_iterator_free(itr);
ecore_main_loop_begin();
fprintf(stderr, "INFO: main loop finished.\n");
return ;
no_mainloop:
efl_del(dialer);
end:
ecore_con_url_shutdown();
ecore_con_shutdown();
ecore_shutdown();
return retval;
efl_loop_quit(efl_loop_get(ev->object), eina_value_int_init(EXIT_FAILURE));
}
EFL_MAIN_EX();