Panda3D

pythonThread.h

00001 // Filename: pythonThread.h
00002 // Created by:  drose (13Apr07)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef PYTHONTHREAD_H
00016 #define PYTHONTHREAD_H
00017 
00018 #include "pandabase.h"
00019 
00020 #include "thread.h"
00021 
00022 #ifdef HAVE_PYTHON
00023 ////////////////////////////////////////////////////////////////////
00024 //       Class : PythonThread
00025 // Description : This class is exposed to Python to allow creation of
00026 //               a Panda thread from the Python level.  It will spawn
00027 //               a thread that executes an arbitrary Python functor.
00028 ////////////////////////////////////////////////////////////////////
00029 class EXPCL_PANDA_PIPELINE PythonThread : public Thread {
00030 PUBLISHED:
00031   PythonThread(PyObject *function, PyObject *args,
00032                const string &name, const string &sync_name);
00033   virtual ~PythonThread();
00034 
00035   BLOCKING PyObject *join();
00036 
00037 protected:
00038   virtual void thread_main();
00039 
00040 private:
00041   PyObject *_function;
00042   PyObject *_args;
00043   PyObject *_result;
00044 
00045 public:
00046   static TypeHandle get_class_type() {
00047     return _type_handle;
00048   }
00049   static void init_type() {
00050     Thread::init_type();
00051     register_type(_type_handle, "PythonThread",
00052                   Thread::get_class_type());
00053   }
00054   virtual TypeHandle get_type() const {
00055     return get_class_type();
00056   }
00057   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00058 
00059 private:
00060   static TypeHandle _type_handle;
00061 };
00062 #endif  // HAVE_PYTHON
00063 
00064 #endif
00065 
 All Classes Functions Variables Enumerations