8 #include "ecore_private.h"
10 static Eina_Bool _ecore_job_event_handler(void *data,
13 static void _ecore_job_event_free(void *data,
16 static int ecore_event_job_type = 0;
17 static Ecore_Event_Handler *_ecore_job_handler = NULL;
26 GENERIC_ALLOC_SIZE_DECLARE(Ecore_Job);
31 ecore_event_job_type = ecore_event_type_new();
32 _ecore_job_handler = ecore_event_handler_add(ecore_event_job_type, _ecore_job_event_handler, NULL);
36 _ecore_job_shutdown(void)
38 _ecore_event_handler_del(_ecore_job_handler);
39 _ecore_job_handler = NULL;
43 * @addtogroup Ecore_Job_Group
49 * Add a job to the event queue.
50 * @param func The function to call when the job gets handled.
51 * @param data Data pointer to be passed to the job function when the job is
53 * @return The handle of the job. @c NULL is returned if the job could not be
55 * @note Once the job has been executed, the job handle is invalid.
58 ecore_job_add(Ecore_Cb func,
63 EINA_MAIN_LOOP_CHECK_RETURN_VAL(NULL);
64 if (!func) return NULL;
66 job = ecore_job_calloc(1);
67 if (!job) return NULL;
68 ECORE_MAGIC_SET(job, ECORE_MAGIC_JOB);
69 job->event = ecore_event_add(ecore_event_job_type, job, _ecore_job_event_free, NULL);
72 ecore_job_mp_free(job);
76 job->data = (void *)data;
81 * Delete a queued job that has not yet been executed.
82 * @param job Handle of the job to delete.
83 * @return The data pointer that was to be passed to the job.
86 ecore_job_del(Ecore_Job *job)
90 EINA_MAIN_LOOP_CHECK_RETURN_VAL(NULL);
91 if (!ECORE_MAGIC_CHECK(job, ECORE_MAGIC_JOB))
93 ECORE_MAGIC_FAIL(job, ECORE_MAGIC_JOB,
98 ECORE_MAGIC_SET(job, ECORE_MAGIC_NONE);
99 ecore_event_del(job->event);
108 _ecore_job_event_handler(void *data __UNUSED__,
115 job->func(job->data);
116 return ECORE_CALLBACK_CANCEL;
120 _ecore_job_event_free(void *data __UNUSED__,
123 ecore_job_mp_free(job);