7 #include "ecore_private.h"
8 #include "ecore_job_private.h"
11 static int _ecore_job_event_handler(void *data, int type, void *ev);
12 static void _ecore_job_event_free(void *data, void *ev);
14 static int ecore_event_job_type = 0;
15 static int _ecore_init_job_count = 0;
16 static Ecore_Event_Handler* _ecore_job_handler = NULL;
21 if (++_ecore_init_job_count == 1)
24 ecore_event_job_type = ecore_event_type_new();
25 _ecore_job_handler = ecore_event_handler_add(ecore_event_job_type, _ecore_job_event_handler, NULL);
28 return _ecore_init_job_count;
32 ecore_job_shutdown(void)
34 if (--_ecore_init_job_count)
35 return _ecore_init_job_count;
37 ecore_event_handler_del(_ecore_job_handler);
38 _ecore_job_handler = NULL;
41 return _ecore_init_job_count;
45 * Add a job to the event queue.
46 * @param func The function to call when the job gets handled.
47 * @param data Data pointer to be passed to the job function when the job is
49 * @return The handle of the job. @c NULL is returned if the job could not be
51 * @ingroup Ecore_Job_Group
52 * @note Once the job has been executed, the job handle is invalid.
55 ecore_job_add(void (*func) (void *data), const void *data)
59 if (!func) return NULL;
61 job = calloc(1, sizeof(Ecore_Job));
62 if (!job) return NULL;
63 ECORE_MAGIC_SET(job, ECORE_MAGIC_JOB);
64 job->event = ecore_event_add(ecore_event_job_type, job, _ecore_job_event_free, NULL);
71 job->data = (void *)data;
76 * Delete a queued job that has not yet been executed.
77 * @param job Handle of the job to delete.
78 * @return The data pointer that was to be passed to the job.
79 * @ingroup Ecore_Job_Group
82 ecore_job_del(Ecore_Job *job)
86 if (!ECORE_MAGIC_CHECK(job, ECORE_MAGIC_JOB))
88 ECORE_MAGIC_FAIL(job, ECORE_MAGIC_JOB,
93 ECORE_MAGIC_SET(job, ECORE_MAGIC_NONE);
94 ecore_event_del(job->event);
99 _ecore_job_event_handler(void *data __UNUSED__, int type __UNUSED__, void *ev)
104 job->func(job->data);
109 _ecore_job_event_free(void *data __UNUSED__, void *ev)