add director+thread case
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@7147 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
c5f25b9168
commit
4f7690c2df
2 changed files with 51 additions and 0 deletions
40
SWIG/Examples/test-suite/python/director_thread.i
Normal file
40
SWIG/Examples/test-suite/python/director_thread.i
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
%module(directors="1") director_thread
|
||||||
|
|
||||||
|
%{
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
class Foo;
|
||||||
|
extern "C" void* working(void* t);
|
||||||
|
%}
|
||||||
|
|
||||||
|
|
||||||
|
%feature("director") Foo;
|
||||||
|
|
||||||
|
%inline {
|
||||||
|
class Foo {
|
||||||
|
public:
|
||||||
|
virtual ~Foo() {}
|
||||||
|
|
||||||
|
void run() {
|
||||||
|
pthread_t *t = new pthread_t;
|
||||||
|
pthread_create(t,NULL,working,this);
|
||||||
|
sleep(5);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void do_foo() {
|
||||||
|
std::cout << "foo" << std::endl;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
%inline {
|
||||||
|
extern "C" void* working(void* t) {
|
||||||
|
Foo* f = static_cast<Foo*>(t);
|
||||||
|
while (1) {
|
||||||
|
sleep(1);
|
||||||
|
std::cout << "invoked" << std::endl;
|
||||||
|
f->do_foo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
11
SWIG/Examples/test-suite/python/director_thread_runme.py
Normal file
11
SWIG/Examples/test-suite/python/director_thread_runme.py
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
from director_thread import Foo
|
||||||
|
|
||||||
|
class Derived(Foo) :
|
||||||
|
def __init__(self):
|
||||||
|
Foo.__init__(self)
|
||||||
|
print "too"
|
||||||
|
def do_foo(self):
|
||||||
|
print "at drived class"
|
||||||
|
|
||||||
|
d = Derived()
|
||||||
|
d.run()
|
||||||
Loading…
Add table
Add a link
Reference in a new issue