00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef GENERICASYNCTASK_H
00016 #define GENERICASYNCTASK_H
00017
00018 #include "pandabase.h"
00019
00020 #include "asyncTask.h"
00021
00022
00023
00024
00025
00026
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