2 * $Id: rb_job.c 351 2006-02-10 15:25:40Z tilman $
4 * Copyright (C) 2004 ruby-ecore team (see AUTHORS)
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.
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.
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
24 #include <Ecore_Job.h>
27 #include "rb_ecore_job.h"
35 static void on_job (void *data)
39 rb_funcall (job->callback, rb_intern ("call"), 0);
43 static void c_mark (RbJob *job)
45 rb_gc_mark (job->callback);
48 static void c_free (RbJob *job)
50 if (job->real && !job->deleted)
51 ecore_job_del (job->real);
58 static VALUE c_alloc (VALUE klass)
64 return Data_Make_Struct (klass, RbJob, c_mark, c_free, job);
69 * Ecore::Job::Job.new { block } => job
71 * Creates an Ecore::Job::Job object.
72 * After execution, the object will be deleted.
74 static VALUE c_init (VALUE self)
78 if (!rb_block_given_p ())
79 rb_raise (rb_eStandardError, "block missing");
81 Data_Get_Struct (self, RbJob, job);
83 job->callback = rb_block_proc ();
85 job->real = ecore_job_add (on_job, job);
96 static VALUE c_delete (VALUE self)
101 Data_Get_Struct (self, RbJob, job);
103 if (job->real && !job->deleted) {
104 ecore_job_del (job->real);
115 VALUE c = rb_define_class_under (mJob, "Job", rb_cObject);
117 rb_define_alloc_func (c, c_alloc);
118 rb_define_method (c, "initialize", c_init, 0);
119 rb_define_method (c, "delete", c_delete, 0);