2 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
12 #include "ecore_private.h"
14 static int _ecore_job_event_handler(void *data, int type, void *ev);
15 static void _ecore_job_event_free(void *data, void *ev);
17 static int ecore_event_job_type = 0;
18 static Ecore_Event_Handler* _ecore_job_handler = NULL;
24 void (*func) (void *data);
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 * Add a job to the event queue.
44 * @param func The function to call when the job gets handled.
45 * @param data Data pointer to be passed to the job function when the job is
47 * @return The handle of the job. @c NULL is returned if the job could not be
49 * @ingroup Ecore_Job_Group
50 * @note Once the job has been executed, the job handle is invalid.
53 ecore_job_add(void (*func) (void *data), const void *data)
57 if (!func) return NULL;
59 job = calloc(1, sizeof(Ecore_Job));
60 if (!job) return NULL;
61 ECORE_MAGIC_SET(job, ECORE_MAGIC_JOB);
62 job->event = ecore_event_add(ecore_event_job_type, job, _ecore_job_event_free, NULL);
69 job->data = (void *)data;
74 * Delete a queued job that has not yet been executed.
75 * @param job Handle of the job to delete.
76 * @return The data pointer that was to be passed to the job.
77 * @ingroup Ecore_Job_Group
80 ecore_job_del(Ecore_Job *job)
84 if (!ECORE_MAGIC_CHECK(job, ECORE_MAGIC_JOB))
86 ECORE_MAGIC_FAIL(job, ECORE_MAGIC_JOB,
91 ECORE_MAGIC_SET(job, ECORE_MAGIC_NONE);
92 ecore_event_del(job->event);
97 _ecore_job_event_handler(void *data __UNUSED__, int type __UNUSED__, void *ev)
102 job->func(job->data);
107 _ecore_job_event_free(void *data __UNUSED__, void *ev)