Panda3D
|
00001 // Filename: genericAsyncTask.h 00002 // Created by: drose (16Sep08) 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 GENERICASYNCTASK_H 00016 #define GENERICASYNCTASK_H 00017 00018 #include "pandabase.h" 00019 00020 #include "asyncTask.h" 00021 00022 //////////////////////////////////////////////////////////////////// 00023 // Class : GenericAsyncTask 00024 // Description : Associates a generic C-style function pointer with an 00025 // AsyncTask object. You can use this when you want to 00026 // create an AsyncTask without having to subclass. 00027 //////////////////////////////////////////////////////////////////// 00028 class EXPCL_PANDA_PIPELINE GenericAsyncTask : public AsyncTask { 00029 public: 00030 typedef DoneStatus TaskFunc(GenericAsyncTask *task, void *user_data); 00031 typedef void BirthFunc(GenericAsyncTask *task, void *user_data); 00032 typedef void DeathFunc(GenericAsyncTask *task, bool clean_exit, void *user_data); 00033 00034 GenericAsyncTask(const string &name = string()); 00035 GenericAsyncTask(const string &name, TaskFunc *function, void *user_data); 00036 ALLOC_DELETED_CHAIN(GenericAsyncTask); 00037 00038 INLINE void set_function(TaskFunc *function); 00039 INLINE TaskFunc *get_function() const; 00040 00041 INLINE void set_upon_birth(BirthFunc *function); 00042 INLINE BirthFunc *get_upon_birth() const; 00043 00044 INLINE void set_upon_death(DeathFunc *function); 00045 INLINE DeathFunc *get_upon_death() const; 00046 00047 INLINE void set_user_data(void *user_data); 00048 INLINE void *get_user_data() const; 00049 00050 protected: 00051 virtual bool is_runnable(); 00052 virtual DoneStatus do_task(); 00053 virtual void upon_birth(AsyncTaskManager *manager); 00054 virtual void upon_death(AsyncTaskManager *manager, bool clean_exit); 00055 00056 private: 00057 TaskFunc *_function; 00058 BirthFunc *_upon_birth; 00059 DeathFunc *_upon_death; 00060 void *_user_data; 00061 00062 public: 00063 static TypeHandle get_class_type() { 00064 return _type_handle; 00065 } 00066 static void init_type() { 00067 AsyncTask::init_type(); 00068 register_type(_type_handle, "GenericAsyncTask", 00069 AsyncTask::get_class_type()); 00070 } 00071 virtual TypeHandle get_type() const { 00072 return get_class_type(); 00073 } 00074 virtual TypeHandle force_init_type() {init_type(); return get_class_type();} 00075 00076 private: 00077 static TypeHandle _type_handle; 00078 }; 00079 00080 #include "genericAsyncTask.I" 00081 00082 #endif 00083