Panda3D
genericAsyncTask.h
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file genericAsyncTask.h
10  * @author drose
11  * @date 2008-09-16
12  */
13 
14 #ifndef GENERICASYNCTASK_H
15 #define GENERICASYNCTASK_H
16 
17 #include "pandabase.h"
18 
19 #include "asyncTask.h"
20 
21 /**
22  * Associates a generic C-style function pointer with an AsyncTask object.
23  * You can use this when you want to create an AsyncTask without having to
24  * subclass.
25  */
26 class EXPCL_PANDA_EVENT GenericAsyncTask : public AsyncTask {
27 public:
28  typedef DoneStatus TaskFunc(GenericAsyncTask *task, void *user_data);
29  typedef void BirthFunc(GenericAsyncTask *task, void *user_data);
30  typedef void DeathFunc(GenericAsyncTask *task, bool clean_exit, void *user_data);
31 
32  GenericAsyncTask(const std::string &name = std::string());
33  GenericAsyncTask(const std::string &name, TaskFunc *function, void *user_data);
34  ALLOC_DELETED_CHAIN(GenericAsyncTask);
35 
36  INLINE void set_function(TaskFunc *function);
37  INLINE TaskFunc *get_function() const;
38 
39  INLINE void set_upon_birth(BirthFunc *function);
40  INLINE BirthFunc *get_upon_birth() const;
41 
42  INLINE void set_upon_death(DeathFunc *function);
43  INLINE DeathFunc *get_upon_death() const;
44 
45  INLINE void set_user_data(void *user_data);
46  INLINE void *get_user_data() const;
47 
48 protected:
49  virtual bool is_runnable();
50  virtual DoneStatus do_task();
51  virtual void upon_birth(AsyncTaskManager *manager);
52  virtual void upon_death(AsyncTaskManager *manager, bool clean_exit);
53 
54 private:
55  TaskFunc *_function;
56  BirthFunc *_upon_birth;
57  DeathFunc *_upon_death;
58  void *_user_data;
59 
60 public:
61  static TypeHandle get_class_type() {
62  return _type_handle;
63  }
64  static void init_type() {
65  AsyncTask::init_type();
66  register_type(_type_handle, "GenericAsyncTask",
67  AsyncTask::get_class_type());
68  }
69  virtual TypeHandle get_type() const {
70  return get_class_type();
71  }
72  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
73 
74 private:
75  static TypeHandle _type_handle;
76 };
77 
78 #include "genericAsyncTask.I"
79 
80 #endif
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A class to manage a loose queue of isolated tasks, which can be performed either synchronously (in th...
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
Definition: register_type.I:22
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Associates a generic C-style function pointer with an AsyncTask object.
This class represents a concrete task performed by an AsyncManager.
Definition: asyncTask.h:32
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81