Panda3D
 All Classes Functions Variables Enumerations
socketStreamRecorder.h
1 // Filename: socketStreamRecorder.h
2 // Created by: drose (28Jan04)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef SOCKETSTREAMRECORDER_H
16 #define SOCKETSTREAMRECORDER_H
17 
18 #include "pandabase.h"
19 #include "socketStream.h"
20 #include "recorderBase.h"
21 #include "pdeque.h"
22 
23 class BamReader;
24 class BamWriter;
25 class FactoryParams;
26 class DatagramIterator;
27 
28 // At the present, this module is not compiled if OpenSSL is not
29 // available, since in that case socketStream.h is not compiled
30 // either.
31 
32 #ifdef HAVE_OPENSSL
33 
34 ////////////////////////////////////////////////////////////////////
35 // Class : SocketStreamRecorder
36 // Description : Records any data received from the indicated socket
37 // stream. On playback, it will act as if the incoming
38 // data is coming over the wire again even if an actual
39 // connection is not available.
40 //
41 // Outbound data will not be recorded, but will be sent
42 // straight through to the socket if it is connected, or
43 // silently ignored if it is not.
44 ////////////////////////////////////////////////////////////////////
45 class EXPCL_PANDA_RECORDER SocketStreamRecorder : public RecorderBase,
46  public ReferenceCount {
47 PUBLISHED:
48  INLINE SocketStreamRecorder();
49  INLINE SocketStreamRecorder(SocketStream *stream, bool owns_stream);
50  INLINE ~SocketStreamRecorder();
51 
52  bool receive_datagram(Datagram &dg);
53  INLINE bool send_datagram(const Datagram &dg);
54 
55  INLINE bool is_closed();
56  INLINE void close();
57 
58  INLINE void set_collect_tcp(bool collect_tcp);
59  INLINE bool get_collect_tcp() const;
60  INLINE void set_collect_tcp_interval(double interval);
61  INLINE double get_collect_tcp_interval() const;
62 
63  INLINE bool consider_flush();
64  INLINE bool flush();
65 
66 public:
67  virtual void record_frame(BamWriter *manager, Datagram &dg);
68  virtual void play_frame(DatagramIterator &scan, BamReader *manager);
69 
70 private:
71  SocketStream *_stream;
72  bool _owns_stream;
73 
74  typedef pdeque<Datagram> Data;
75  Data _data;
76  bool _closed;
77 
78 public:
79  static void register_with_read_factory();
80  virtual void write_recorder(BamWriter *manager, Datagram &dg);
81 
82  INLINE virtual void ref() const FINAL { ReferenceCount::ref(); };
83  INLINE virtual bool unref() const FINAL { return ReferenceCount::unref(); };
84 
85 protected:
86  static RecorderBase *make_recorder(const FactoryParams &params);
87  void fillin_recorder(DatagramIterator &scan, BamReader *manager);
88 
89 public:
90  static TypeHandle get_class_type() {
91  return _type_handle;
92  }
93  static void init_type() {
94  RecorderBase::init_type();
95  register_type(_type_handle, "SocketStreamRecorder",
96  RecorderBase::get_class_type());
97  }
98  virtual TypeHandle get_type() const {
99  return get_class_type();
100  }
101  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
102 
103 private:
104  static TypeHandle _type_handle;
105 };
106 
107 #include "socketStreamRecorder.I"
108 
109 #endif // HAVE_OPENSSL
110 
111 #endif // SOCKETSTREAMRECORDER_H
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:122
virtual void play_frame(DatagramIterator &scan, BamReader *manager)
Reloads the most recent data collected from the indicated datagram.
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:73
This describes the structure of a single array within a Geom data.
virtual void record_frame(BamWriter *manager, Datagram &dg)
Records the most recent data collected into the indicated datagram.
virtual bool unref() const
Explicitly decrements the reference count.
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:40
This is the base class to a number of objects that record particular kinds of user input (like a Mous...
Definition: recorderBase.h:55
virtual void write_recorder(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for encoding in the session file.
A base class for all things that want to be reference-counted.
void ref() const
Explicitly increments the reference count.
A class to retrieve the individual data elements previously stored in a Datagram. ...
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:43