00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef ASYNCUTILITY_H
00019 #define ASYNCUTILITY_H
00020
00021
00022
00023
00024 #include <pandabase.h>
00025 #include <notify.h>
00026 #include <typedef.h>
00027
00028 #ifdef OLD_HAVE_IPC
00029 #include <ipc_mutex.h>
00030 #include <ipc_condition.h>
00031 #include <ipc_thread.h>
00032 #endif
00033
00034
00035
00036
00037
00038
00039 class EXPCL_PANDAEXPRESS AsyncUtility {
00040 PUBLISHED:
00041 INLINE void set_frequency(float frequency);
00042 INLINE float get_frequency(void) const;
00043
00044 void create_thread(void);
00045
00046 public:
00047 AsyncUtility(float frequency = 0.2);
00048 virtual ~AsyncUtility(void);
00049
00050 protected:
00051 void destroy_thread(void);
00052 static void* st_callback(void *arg);
00053 void callback(void);
00054 virtual bool process_request(void) = 0;
00055 void nap(void) const;
00056
00057 protected:
00058 int _next_token;
00059 bool _shutdown;
00060 bool _threaded;
00061 float _frequency;
00062 bool _threads_enabled;
00063
00064 #ifdef OLD_HAVE_IPC
00065 mutex _lock;
00066 condition_variable *_request_cond;
00067 thread *_thread;
00068 #endif
00069 };
00070
00071 #include "asyncUtility.I"
00072
00073 #endif