clientDevice.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. // Filename: clientDevice.h
  2. // Created by: drose (25Jan01)
  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 CLIENTDEVICE_H
  19. #define CLIENTDEVICE_H
  20. #include <pandabase.h>
  21. #include <typedReferenceCount.h>
  22. #ifdef OLD_HAVE_IPC
  23. #include <ipc_mutex.h>
  24. #endif
  25. class ClientBase;
  26. ////////////////////////////////////////////////////////////////////
  27. // Class : ClientDevice
  28. // Description : Any of a number of different devices that might be
  29. // attached to a ClientBase, including trackers, etc.
  30. // This is an abstract interface; the actual
  31. // implementations are in ClientTrackerDevice, etc.
  32. ////////////////////////////////////////////////////////////////////
  33. class EXPCL_PANDA ClientDevice : public TypedReferenceCount {
  34. protected:
  35. ClientDevice(ClientBase *client, TypeHandle device_type,
  36. const string &device_name);
  37. public:
  38. virtual ~ClientDevice();
  39. INLINE ClientBase *get_client() const;
  40. INLINE TypeHandle get_device_type() const;
  41. INLINE const string &get_device_name() const;
  42. INLINE bool is_connected() const;
  43. void disconnect();
  44. void poll();
  45. INLINE void lock();
  46. INLINE void unlock();
  47. virtual void output(ostream &out) const;
  48. virtual void write(ostream &out, int indent_level = 0) const;
  49. private:
  50. ClientBase *_client;
  51. TypeHandle _device_type;
  52. string _device_name;
  53. bool _is_connected;
  54. #ifdef OLD_HAVE_IPC
  55. mutex _lock;
  56. #endif
  57. public:
  58. static TypeHandle get_class_type() {
  59. return _type_handle;
  60. }
  61. static void init_type() {
  62. TypedReferenceCount::init_type();
  63. register_type(_type_handle, "ClientDevice",
  64. TypedReferenceCount::get_class_type());
  65. }
  66. virtual TypeHandle get_type() const {
  67. return get_class_type();
  68. }
  69. virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
  70. private:
  71. static TypeHandle _type_handle;
  72. friend class ClientBase;
  73. };
  74. INLINE ostream &operator <<(ostream &out, const ClientDevice &device) {
  75. device.output(out);
  76. return out;
  77. }
  78. #include "clientDevice.I"
  79. #endif