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