clientBase.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // Filename: clientBase.h
  2. // Created by: jason (04Aug00)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. #ifndef CLIENTBASE_H
  6. #define CLIENTBASE_H
  7. #include <pandabase.h>
  8. #include "clientDevice.h"
  9. #include <typedReferenceCount.h>
  10. #include <luse.h>
  11. #include <vector_string.h>
  12. #include <vector_int.h>
  13. #include <clockObject.h>
  14. #include <pointerTo.h>
  15. #ifdef HAVE_IPC
  16. #include <ipc_thread.h>
  17. #endif
  18. #include <map>
  19. ////////////////////////////////////////////////////////////////////
  20. // Class : ClientBase
  21. // Description : An abstract base class for a family of of client
  22. // device interfaces--including trackers, buttons,
  23. // dials, and other analog inputs.
  24. //
  25. // This provides a common interface to connect to such
  26. // devices and extract their data; it is used by
  27. // TrackerNode etc. to put these devices in the data
  28. // graph.
  29. ////////////////////////////////////////////////////////////////////
  30. class EXPCL_PANDA ClientBase : public TypedReferenceCount {
  31. protected:
  32. ClientBase();
  33. PUBLISHED:
  34. ~ClientBase();
  35. bool fork_asynchronous_thread(double poll_time);
  36. INLINE bool is_forked() const;
  37. INLINE bool poll();
  38. INLINE double get_last_poll_time() const;
  39. public:
  40. PT(ClientDevice) get_device(TypeHandle device_type,
  41. const string &device_name);
  42. protected:
  43. virtual PT(ClientDevice) make_device(TypeHandle device_type,
  44. const string &device_name)=0;
  45. virtual bool disconnect_device(TypeHandle device_type,
  46. const string &device_name,
  47. ClientDevice *device);
  48. virtual void do_poll();
  49. private:
  50. typedef map<string, ClientDevice *> DevicesByName;
  51. typedef map<TypeHandle, DevicesByName> Devices;
  52. Devices _devices;
  53. bool _forked;
  54. double _last_poll_time;
  55. int _last_poll_frame;
  56. #ifdef HAVE_IPC
  57. int _sleep_time;
  58. thread *_client_thread;
  59. bool _shutdown;
  60. static void* st_callback(void *arg);
  61. void callback();
  62. #endif
  63. public:
  64. static TypeHandle get_class_type() {
  65. return _type_handle;
  66. }
  67. static void init_type() {
  68. TypedReferenceCount::init_type();
  69. register_type(_type_handle, "ClientBase",
  70. TypedReferenceCount::get_class_type());
  71. }
  72. virtual TypeHandle get_type() const {
  73. return get_class_type();
  74. }
  75. virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
  76. private:
  77. static TypeHandle _type_handle;
  78. friend class ClientDevice;
  79. };
  80. #include "clientBase.I"
  81. #endif