ecore_init and ecore_shutdown aren't exported anymore.
[ruby-ecore.git] / src / ecore_job / rb_job.c
1 /*
2  * $Id: rb_job.c 27 2004-07-08 18:25:05Z tilman $
3  *
4  * Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de)
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include <ruby.h>
22
23 #include <Ecore.h>
24 #include <Ecore_Job.h>
25 #include <stdbool.h>
26
27 #include "rb_ecore_job.h"
28
29 typedef struct {
30         Ecore_Job *job;
31         void *cb;
32         bool deleted;
33 } RbEcoreJob;
34
35 static VALUE cJob;
36
37 static void on_job (void *data)
38 {
39         RbEcoreJob *job = data;
40
41         rb_funcall ((VALUE) job->cb, rb_intern ("call"), 0);
42         job->deleted = true;
43 }
44
45 static void c_free (RbEcoreJob *job)
46 {
47         if (job->job && !job->deleted)
48                 ecore_job_del (job->job);
49
50         ecore_shutdown ();
51
52         free (job);
53 }
54
55 static VALUE c_new (VALUE klass)
56 {
57         VALUE self;
58         RbEcoreJob *job;
59
60         if (!rb_block_given_p ())
61                 return Qnil;
62
63         self = Data_Make_Struct (klass, RbEcoreJob, NULL, c_free, job);
64
65         ecore_init ();
66
67         job->cb = (void *) rb_block_proc ();
68         job->job = ecore_job_add (on_job, job);
69
70         rb_obj_call_init (self, 0, NULL);
71
72         return self;
73 }
74
75 static VALUE c_delete (VALUE self)
76 {
77         VALUE ret = Qfalse;
78         RbEcoreJob *job = NULL;
79
80         Data_Get_Struct (self, RbEcoreJob, job);
81
82         if (job->job && !job->deleted) {
83                 ecore_job_del (job->job);
84                 job->deleted = true;
85                 job->job = NULL;
86                 ret = Qtrue;
87         }
88
89         return ret;
90 }
91
92 void Init_Job (void)
93 {
94         cJob = rb_define_class_under (mJob, "Job", rb_cObject);
95
96         rb_define_singleton_method (cJob, "new", c_new, 0);
97         rb_define_method (cJob, "delete", c_delete, 0);
98 }
99