ecore/job - Improve documentation and add an example.
SVN revision: 60608
This commit is contained in:
parent
af78dafc91
commit
a63e92496a
|
@ -97,6 +97,24 @@
|
|||
* @include ecore_idler_example.c
|
||||
*/
|
||||
|
||||
/**
|
||||
* @page ecore_job_example_c ecore_job - Queuing tasks
|
||||
*
|
||||
* This example shows how an @ref Ecore_Job can be added, how it can be
|
||||
* deleted, and that they always execute in the added order.
|
||||
*
|
||||
* First, 2 callback functions are declared, one that prints strings passed to
|
||||
* it in the @c data pointer, and another one that quits the main loop. In the
|
||||
* @c main function, 3 jobs are added using the first callback, and another one
|
||||
* is added using the second one.
|
||||
*
|
||||
* Then the second added job is deleted just to demonstrate the usage of
|
||||
* ecore_job_del(), and the main loop is finally started. Run this example to
|
||||
* see that @c job1, @c job3 and @c job_quit are ran, in this order.
|
||||
*
|
||||
* @include ecore_job_example.c
|
||||
*/
|
||||
|
||||
/**
|
||||
* @example ecore_idler_example.c
|
||||
* This example shows when @ref Ecore_Idler, @ref Ecore_Idle_Enterer and @ref
|
||||
|
@ -104,6 +122,12 @@
|
|||
* @ref ecore_idler_example_c "the explanation here".
|
||||
*/
|
||||
|
||||
/**
|
||||
* @example ecore_job_example.c
|
||||
* This example shows how to use an @ref Ecore_Job. See
|
||||
* @ref ecore_job_example_c "the explanation here".
|
||||
*/
|
||||
|
||||
/**
|
||||
* @example ecore_time_example.c
|
||||
* Shows the difference between the three time functions. See @ref
|
||||
|
|
|
@ -14,6 +14,7 @@ LDADD = \
|
|||
SRCS = \
|
||||
ecore_idler_example.c \
|
||||
ecore_time_example.c \
|
||||
ecore_job_example.c \
|
||||
client_bench.c \
|
||||
server_bench.c \
|
||||
ecore_con_client_example.c \
|
||||
|
@ -33,6 +34,7 @@ endif
|
|||
if EFL_BUILD_EXAMPLES
|
||||
pkglib_PROGRAMS += \
|
||||
ecore_idler_example \
|
||||
ecore_job_example \
|
||||
ecore_time_example
|
||||
endif
|
||||
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
#include <Ecore.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static void
|
||||
_job_print_cb(void *data)
|
||||
{
|
||||
char *str = data;
|
||||
|
||||
printf("%s\n", str);
|
||||
}
|
||||
|
||||
static void
|
||||
_job_quit_cb(void *data)
|
||||
{
|
||||
ecore_main_loop_quit();
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
Ecore_Job *job1, *job2, *job3, *job_quit;
|
||||
char *str1 = "Job 1 started.";
|
||||
char *str2 = "Job 2 started.";
|
||||
char *str3 = "Job 3 started.";
|
||||
|
||||
if (!ecore_init())
|
||||
{
|
||||
printf("ERROR: Cannot init Ecore!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
job1 = ecore_job_add(_job_print_cb, str1);
|
||||
job2 = ecore_job_add(_job_print_cb, str2);
|
||||
job3 = ecore_job_add(_job_print_cb, str3);
|
||||
|
||||
job_quit = ecore_job_add(_job_quit_cb, NULL);
|
||||
printf("Created jobs 1, 2, 3 and quit.\n");
|
||||
|
||||
if (job2)
|
||||
{
|
||||
char *str;
|
||||
str = ecore_job_del(job2);
|
||||
job2 = NULL;
|
||||
printf("Deleted job 2. Its data was: \"%s\"\n", str);
|
||||
}
|
||||
|
||||
ecore_main_loop_begin();
|
||||
ecore_shutdown();
|
||||
}
|
|
@ -47,6 +47,15 @@ _ecore_job_shutdown(void)
|
|||
* You can queue jobs that are to be done by the main loop when the current
|
||||
* event is dealt with.
|
||||
*
|
||||
* Jobs are processed by the main loop similarly to events. They also will be
|
||||
* executed in the order which they were added.
|
||||
*
|
||||
* A good use for them is when you don't want to execute an action immeditately,
|
||||
* but want to give the control back to the main loop so that it will call your
|
||||
* job callback when jobs start being processed (and if there are other jobs
|
||||
* added before yours, they will be processed first). This also gives the chance
|
||||
* to other actions in your program to cancel the job before it is started.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
|
Loading…
Reference in New Issue