genericAsyncTask.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // Filename: genericAsyncTask.h
  2. // Created by: drose (16Sep08)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. //
  6. // PANDA 3D SOFTWARE
  7. // Copyright (c) Carnegie Mellon University. All rights reserved.
  8. //
  9. // All use of this software is subject to the terms of the revised BSD
  10. // license. You should have received a copy of this license along
  11. // with this source code in a file named "LICENSE."
  12. //
  13. ////////////////////////////////////////////////////////////////////
  14. #ifndef GENERICASYNCTASK_H
  15. #define GENERICASYNCTASK_H
  16. #include "pandabase.h"
  17. #include "asyncTask.h"
  18. ////////////////////////////////////////////////////////////////////
  19. // Class : GenericAsyncTask
  20. // Description : Associates a generic C-style function pointer with an
  21. // AsyncTask object. You can use this when you want to
  22. // create an AsyncTask without having to subclass.
  23. ////////////////////////////////////////////////////////////////////
  24. class EXPCL_PANDA_PIPELINE GenericAsyncTask : public AsyncTask {
  25. public:
  26. typedef DoneStatus TaskFunc(GenericAsyncTask *task, void *user_data);
  27. typedef void BirthFunc(GenericAsyncTask *task, void *user_data);
  28. typedef void DeathFunc(GenericAsyncTask *task, bool clean_exit, void *user_data);
  29. GenericAsyncTask(const string &name = string());
  30. GenericAsyncTask(const string &name, TaskFunc *function, void *user_data);
  31. ALLOC_DELETED_CHAIN(GenericAsyncTask);
  32. INLINE void set_function(TaskFunc *function);
  33. INLINE TaskFunc *get_function() const;
  34. INLINE void set_upon_birth(BirthFunc *function);
  35. INLINE BirthFunc *get_upon_birth() const;
  36. INLINE void set_upon_death(DeathFunc *function);
  37. INLINE DeathFunc *get_upon_death() const;
  38. INLINE void set_user_data(void *user_data);
  39. INLINE void *get_user_data() const;
  40. protected:
  41. virtual bool is_runnable();
  42. virtual DoneStatus do_task();
  43. virtual void upon_birth(AsyncTaskManager *manager);
  44. virtual void upon_death(AsyncTaskManager *manager, bool clean_exit);
  45. private:
  46. TaskFunc *_function;
  47. BirthFunc *_upon_birth;
  48. DeathFunc *_upon_death;
  49. void *_user_data;
  50. public:
  51. static TypeHandle get_class_type() {
  52. return _type_handle;
  53. }
  54. static void init_type() {
  55. AsyncTask::init_type();
  56. register_type(_type_handle, "GenericAsyncTask",
  57. AsyncTask::get_class_type());
  58. }
  59. virtual TypeHandle get_type() const {
  60. return get_class_type();
  61. }
  62. virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
  63. private:
  64. static TypeHandle _type_handle;
  65. };
  66. #include "genericAsyncTask.I"
  67. #endif