socketStreamRecorder.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // Filename: socketStreamRecorder.h
  2. // Created by: drose (28Jan04)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. //
  6. // PANDA 3D SOFTWARE
  7. // Copyright (c) 2001 - 2004, 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://etc.cmu.edu/panda3d/docs/license/ .
  13. //
  14. // To contact the maintainers of this program write to
  15. // [email protected] .
  16. //
  17. ////////////////////////////////////////////////////////////////////
  18. #ifndef SOCKETSTREAMRECORDER_H
  19. #define SOCKETSTREAMRECORDER_H
  20. #include "pandabase.h"
  21. #include "socketStream.h"
  22. #include "pdeque.h"
  23. class BamReader;
  24. class BamWriter;
  25. class FactoryParams;
  26. // At the present, this module is not compiled if OpenSSL is not
  27. // available, since in that case socketStream.h is not compiled
  28. // either.
  29. #ifdef HAVE_SSL
  30. ////////////////////////////////////////////////////////////////////
  31. // Class : SocketStreamRecorder
  32. // Description : Records any data received from the indicated socket
  33. // stream. On playback, it will act as if the incoming
  34. // data is coming over the wire again even if an actual
  35. // connection is not available.
  36. //
  37. // Outbound data will not be recorded, but will be sent
  38. // straight through to the socket if it is connected, or
  39. // silently ignored if it is not.
  40. ////////////////////////////////////////////////////////////////////
  41. class EXPCL_PANDA SocketStreamRecorder : public RecorderBase {
  42. PUBLISHED:
  43. INLINE SocketStreamRecorder();
  44. INLINE SocketStreamRecorder(SocketStream *stream, bool owns_stream);
  45. INLINE ~SocketStreamRecorder();
  46. bool receive_datagram(Datagram &dg);
  47. INLINE bool send_datagram(const Datagram &dg);
  48. INLINE bool is_closed();
  49. INLINE void close();
  50. INLINE void set_collect_tcp(bool collect_tcp);
  51. INLINE bool get_collect_tcp() const;
  52. INLINE void set_collect_tcp_interval(double interval);
  53. INLINE double get_collect_tcp_interval() const;
  54. INLINE bool consider_flush();
  55. INLINE bool flush();
  56. public:
  57. virtual void record_frame(BamWriter *manager, Datagram &dg);
  58. virtual void play_frame(DatagramIterator &scan, BamReader *manager);
  59. private:
  60. SocketStream *_stream;
  61. bool _owns_stream;
  62. typedef pdeque<Datagram> Data;
  63. Data _data;
  64. bool _closed;
  65. public:
  66. static void register_with_read_factory();
  67. virtual void write_recorder(BamWriter *manager, Datagram &dg);
  68. protected:
  69. static RecorderBase *make_recorder(const FactoryParams &params);
  70. void fillin_recorder(DatagramIterator &scan, BamReader *manager);
  71. public:
  72. static TypeHandle get_class_type() {
  73. return _type_handle;
  74. }
  75. static void init_type() {
  76. RecorderBase::init_type();
  77. register_type(_type_handle, "SocketStreamRecorder",
  78. RecorderBase::get_class_type());
  79. }
  80. virtual TypeHandle get_type() const {
  81. return get_class_type();
  82. }
  83. virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
  84. private:
  85. static TypeHandle _type_handle;
  86. };
  87. #include "socketStreamRecorder.I"
  88. #endif // HAVE_SSL
  89. #endif // SOCKETSTREAMRECORDER_H