projects
/
ruby-ecore.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Use ecore_evas_data_set/get to store a pointer to self.
[ruby-ecore.git]
/
src
/
ecore
/
rb_idler.c
diff --git
a/src/ecore/rb_idler.c
b/src/ecore/rb_idler.c
index ce6bc03817828da9f55585eb9517ad22adfa1b72..263b7149b4561349ed567e5f6500cd8f04e90315 100644
(file)
--- a/
src/ecore/rb_idler.c
+++ b/
src/ecore/rb_idler.c
@@
-1,7
+1,7
@@
/*
/*
- * $Id: rb_idler.c
40 2004-07-25 13:14:34
Z tilman $
+ * $Id: rb_idler.c
77 2004-08-19 17:39:29
Z tilman $
*
*
- * Copyright (C) 2004
Tilman Sauerbeck (tilman at code-monkey de
)
+ * Copyright (C) 2004
ruby-ecore team (see AUTHORS
)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@
-19,24
+19,24
@@
*/
#include <ruby.h>
*/
#include <ruby.h>
+#include <stdbool.h>
#include <Ecore.h>
#include <Ecore.h>
-#include <stdbool.h>
#include "rb_ecore.h"
typedef struct {
#include "rb_ecore.h"
typedef struct {
- Ecore_Idler *
idler
;
-
void *cb
;
+ Ecore_Idler *
real
;
+
VALUE callback
;
bool deleted;
bool deleted;
-} Rb
Ecore
Idler;
+} RbIdler;
static int on_idler (void *data)
{
VALUE r;
static int on_idler (void *data)
{
VALUE r;
- Rb
Ecore
Idler *idler = data;
+ RbIdler *idler = data;
- r = rb_funcall (
(VALUE) idler->cb
, rb_intern ("call"), 0);
+ r = rb_funcall (
idler->callback
, rb_intern ("call"), 0);
/* if the callback returns false, we return 0 and Ecore
* will remove the idler
/* if the callback returns false, we return 0 and Ecore
* will remove the idler
@@
-47,45
+47,63
@@
static int on_idler (void *data)
return (r != Qfalse);
}
return (r != Qfalse);
}
-static void c_free (RbEcoreIdler *idler)
+static void c_mark (RbIdler *idler)
+{
+ rb_gc_mark (idler->callback);
+}
+
+static void c_free (RbIdler *idler)
{
{
- if (idler->
idler
&& !idler->deleted)
- ecore_idler_del (idler->
idler
);
+ if (idler->
real
&& !idler->deleted)
+ ecore_idler_del (idler->
real
);
ecore_shutdown ();
free (idler);
}
ecore_shutdown ();
free (idler);
}
+/*
+ * call-seq:
+ * Ecore::Idler.new { block } => idler
+ *
+ * Creates an Ecore::Idler object.
+ * When Ecore is idle, the specified block will be called.
+ * If the block returns false, the idler is deleted.
+ */
static VALUE c_new (VALUE klass)
{
VALUE self;
static VALUE c_new (VALUE klass)
{
VALUE self;
- Rb
Ecore
Idler *idler;
+ RbIdler *idler;
if (!rb_block_given_p ())
return Qnil;
if (!rb_block_given_p ())
return Qnil;
- self = Data_Make_Struct (klass, Rb
EcoreIdler, NULL
, c_free, idler);
+ self = Data_Make_Struct (klass, Rb
Idler, c_mark
, c_free, idler);
ecore_init ();
ecore_init ();
- idler->cb = (void *) rb_block_proc ();
- idler->idler = ecore_idler_add (on_idler, idler);
+ idler->callback = rb_block_proc ();
+ idler->deleted = false;
+ idler->real = ecore_idler_add (on_idler, idler);
rb_obj_call_init (self, 0, NULL);
return self;
}
rb_obj_call_init (self, 0, NULL);
return self;
}
+/*
+ * call-seq:
+ * idler.delete => nil
+ *
+ * Deletes <i>idler</i>.
+ */
static VALUE c_delete (VALUE self)
{
static VALUE c_delete (VALUE self)
{
- RbEcoreIdler *idler = NULL;
-
- Data_Get_Struct (self, RbEcoreIdler, idler);
+ GET_OBJ (self, RbIdler, idler);
- if (idler->
idler
&& !idler->deleted) {
- ecore_idler_del (idler->
idler
);
- idler->
idler
= NULL;
+ if (idler->
real
&& !idler->deleted) {
+ ecore_idler_del (idler->
real
);
+ idler->
real
= NULL;
idler->deleted = true;
} else
rb_raise (rb_eException, "Idler already deleted!");
idler->deleted = true;
} else
rb_raise (rb_eException, "Idler already deleted!");