clientBase.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. // Filename: clientBase.h
  2. // Created by: jason (04Aug00)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. //
  6. // PANDA 3D SOFTWARE
  7. // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved
  8. //
  9. // All use of this software is subject to the terms of the Panda 3d
  10. // Software license. You should have received a copy of this license
  11. // along with this source code; you will also find a current copy of
  12. // the license at http://www.panda3d.org/license.txt .
  13. //
  14. // To contact the maintainers of this program write to
  15. // [email protected] .
  16. //
  17. ////////////////////////////////////////////////////////////////////
  18. #ifndef CLIENTBASE_H
  19. #define CLIENTBASE_H
  20. #include "pandabase.h"
  21. #include "clientDevice.h"
  22. #include "typedReferenceCount.h"
  23. #include "luse.h"
  24. #include "vector_string.h"
  25. #include "vector_int.h"
  26. #include "clockObject.h"
  27. #include "pointerTo.h"
  28. #include "coordinateSystem.h"
  29. #ifdef OLD_HAVE_IPC
  30. #include "ipc_thread.h"
  31. #endif
  32. #include "pmap.h"
  33. ////////////////////////////////////////////////////////////////////
  34. // Class : ClientBase
  35. // Description : An abstract base class for a family of client
  36. // device interfaces--including trackers, buttons,
  37. // dials, and other analog inputs.
  38. //
  39. // This provides a common interface to connect to such
  40. // devices and extract their data; it is used by
  41. // TrackerNode etc. to put these devices in the data
  42. // graph.
  43. ////////////////////////////////////////////////////////////////////
  44. class EXPCL_PANDA ClientBase : public TypedReferenceCount {
  45. protected:
  46. ClientBase();
  47. PUBLISHED:
  48. ~ClientBase();
  49. bool fork_asynchronous_thread(double poll_time);
  50. INLINE bool is_forked() const;
  51. INLINE bool poll();
  52. INLINE double get_last_poll_time() const;
  53. INLINE void set_coordinate_system(CoordinateSystem cs);
  54. INLINE CoordinateSystem get_coordinate_system() const;
  55. public:
  56. PT(ClientDevice) get_device(TypeHandle device_type,
  57. const string &device_name);
  58. protected:
  59. virtual PT(ClientDevice) make_device(TypeHandle device_type,
  60. const string &device_name)=0;
  61. virtual bool disconnect_device(TypeHandle device_type,
  62. const string &device_name,
  63. ClientDevice *device);
  64. virtual void do_poll();
  65. private:
  66. typedef pmap<string, ClientDevice *> DevicesByName;
  67. typedef pmap<TypeHandle, DevicesByName> Devices;
  68. Devices _devices;
  69. bool _forked;
  70. double _last_poll_time;
  71. int _last_poll_frame;
  72. CoordinateSystem _cs;
  73. #ifdef OLD_HAVE_IPC
  74. int _sleep_time;
  75. thread *_client_thread;
  76. bool _shutdown;
  77. static void* st_callback(void *arg);
  78. void callback();
  79. #endif
  80. public:
  81. static TypeHandle get_class_type() {
  82. return _type_handle;
  83. }
  84. static void init_type() {
  85. TypedReferenceCount::init_type();
  86. register_type(_type_handle, "ClientBase",
  87. TypedReferenceCount::get_class_type());
  88. }
  89. virtual TypeHandle get_type() const {
  90. return get_class_type();
  91. }
  92. virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
  93. private:
  94. static TypeHandle _type_handle;
  95. friend class ClientDevice;
  96. };
  97. #include "clientBase.I"
  98. #endif