Panda3D
genericAsyncTask.h
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 
15 #ifndef GENERICASYNCTASK_H
16 #define GENERICASYNCTASK_H
17 
18 #include "pandabase.h"
19 
20 #include "asyncTask.h"
21 
22 ////////////////////////////////////////////////////////////////////
23 // Class : GenericAsyncTask
24 // Description : Associates a generic C-style function pointer with an
25 // AsyncTask object. You can use this when you want to
26 // create an AsyncTask without having to subclass.
27 ////////////////////////////////////////////////////////////////////
28 class EXPCL_PANDA_PIPELINE GenericAsyncTask : public AsyncTask {
29 public:
30  typedef DoneStatus TaskFunc(GenericAsyncTask *task, void *user_data);
31  typedef void BirthFunc(GenericAsyncTask *task, void *user_data);
32  typedef void DeathFunc(GenericAsyncTask *task, bool clean_exit, void *user_data);
33 
34  GenericAsyncTask(const string &name = string());
35  GenericAsyncTask(const string &name, TaskFunc *function, void *user_data);
36  ALLOC_DELETED_CHAIN(GenericAsyncTask);
37 
38  INLINE void set_function(TaskFunc *function);
39  INLINE TaskFunc *get_function() const;
40 
41  INLINE void set_upon_birth(BirthFunc *function);
42  INLINE BirthFunc *get_upon_birth() const;
43 
44  INLINE void set_upon_death(DeathFunc *function);
45  INLINE DeathFunc *get_upon_death() const;
46 
47  INLINE void set_user_data(void *user_data);
48  INLINE void *get_user_data() const;
49 
50 protected:
51  virtual bool is_runnable();
52  virtual DoneStatus do_task();
53  virtual void upon_birth(AsyncTaskManager *manager);
54  virtual void upon_death(AsyncTaskManager *manager, bool clean_exit);
55 
56 private:
57  TaskFunc *_function;
58  BirthFunc *_upon_birth;
59  DeathFunc *_upon_death;
60  void *_user_data;
61 
62 public:
63  static TypeHandle get_class_type() {
64  return _type_handle;
65  }
66  static void init_type() {
67  AsyncTask::init_type();
68  register_type(_type_handle, "GenericAsyncTask",
69  AsyncTask::get_class_type());
70  }
71  virtual TypeHandle get_type() const {
72  return get_class_type();
73  }
74  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
75 
76 private:
77  static TypeHandle _type_handle;
78 };
79 
80 #include "genericAsyncTask.I"
81 
82 #endif
83 
A class to manage a loose queue of isolated tasks, which can be performed either synchronously (in th...
Associates a generic C-style function pointer with an AsyncTask object.
This class represents a concrete task performed by an AsyncManager.
Definition: asyncTask.h:43
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85