Fix the swig bindings for melted++.
[melted] / src / swig / melted.i
1 /**
2  * melted.i - Swig Bindings for melted++
3  * Copyright (C) 2004-2009 Charles Yates
4  * Author: Charles Yates <charles.yates@pandora.be>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published
8  * by the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program 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
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19  */
20
21 %module melted
22 %include "carrays.i"
23 %array_class(unsigned char, unsignedCharArray);
24
25 %{
26 #include <Mlt.h>
27 #include <MltMelted.h>
28 #include <MltResponse.h>
29 %}
30
31 /** These methods return objects which should be gc'd.
32  */
33
34 namespace Mlt {
35 %newobject Melted::execute( char * );
36 %newobject Melted::received( char *, char * );
37 %newobject Melted::push( char *, Service & );
38 %newobject Melted::unit( int );
39 }
40
41 /** Classes to wrap.
42  */
43
44 %include <MltMelted.h>
45 %include <MltResponse.h>
46
47 #if defined(SWIGRUBY)
48
49 %{
50
51 static void ruby_listener( mlt_properties owner, void *object );
52
53 class RubyListener
54 {
55         private:
56                 VALUE callback;
57                 Mlt::Event *event;
58
59         public:
60                 RubyListener( Mlt::Properties &properties, char *id, VALUE callback ) : 
61                         callback( callback ) 
62                 {
63                         event = properties.listen( id, this, ( mlt_listener )ruby_listener );
64                 }
65
66                 ~RubyListener( )
67                 {
68                         delete event;
69                 }
70
71         void mark( ) 
72                 { 
73                         ((void (*)(VALUE))(rb_gc_mark))( callback ); 
74                 }
75
76         void doit( ) 
77                 {
78                 ID method = rb_intern( "call" );
79                 rb_funcall( callback, method, 0 );
80         }
81 };
82
83 static void ruby_listener( mlt_properties owner, void *object )
84 {
85         RubyListener *o = static_cast< RubyListener * >( object );
86         o->doit( );
87 }
88
89 void markRubyListener( void* p ) 
90 {
91     RubyListener *o = static_cast<RubyListener*>( p );
92     o->mark( );
93 }
94
95 %}
96
97 // Ruby wrapper
98 %rename( Listener )  RubyListener;
99 %markfunc RubyListener "markRubyListener";
100
101 class RubyListener 
102 {
103         public:
104                 RubyListener( Mlt::Properties &properties, char *id, VALUE callback );
105 };
106
107 #endif