Panda3D
 All Classes Functions Variables Enumerations
socketStreamRecorder.h
00001 // Filename: socketStreamRecorder.h
00002 // Created by:  drose (28Jan04)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef SOCKETSTREAMRECORDER_H
00016 #define SOCKETSTREAMRECORDER_H
00017 
00018 #include "pandabase.h"
00019 #include "socketStream.h"
00020 #include "recorderBase.h"
00021 #include "pdeque.h"
00022 
00023 class BamReader;
00024 class BamWriter;
00025 class FactoryParams;
00026 class DatagramIterator;
00027 
00028 // At the present, this module is not compiled if OpenSSL is not
00029 // available, since in that case socketStream.h is not compiled
00030 // either.
00031 
00032 #ifdef HAVE_OPENSSL
00033 
00034 ////////////////////////////////////////////////////////////////////
00035 //       Class : SocketStreamRecorder
00036 // Description : Records any data received from the indicated socket
00037 //               stream.  On playback, it will act as if the incoming
00038 //               data is coming over the wire again even if an actual
00039 //               connection is not available.
00040 //
00041 //               Outbound data will not be recorded, but will be sent
00042 //               straight through to the socket if it is connected, or
00043 //               silently ignored if it is not.
00044 ////////////////////////////////////////////////////////////////////
00045 class EXPCL_PANDA_RECORDER SocketStreamRecorder : public RecorderBase {
00046 PUBLISHED:
00047   INLINE SocketStreamRecorder();
00048   INLINE SocketStreamRecorder(SocketStream *stream, bool owns_stream);
00049   INLINE ~SocketStreamRecorder();
00050 
00051   bool receive_datagram(Datagram &dg);
00052   INLINE bool send_datagram(const Datagram &dg);
00053 
00054   INLINE bool is_closed();
00055   INLINE void close();
00056 
00057   INLINE void set_collect_tcp(bool collect_tcp);
00058   INLINE bool get_collect_tcp() const;
00059   INLINE void set_collect_tcp_interval(double interval);
00060   INLINE double get_collect_tcp_interval() const;
00061 
00062   INLINE bool consider_flush();
00063   INLINE bool flush();
00064 
00065 public:
00066   virtual void record_frame(BamWriter *manager, Datagram &dg);
00067   virtual void play_frame(DatagramIterator &scan, BamReader *manager);
00068 
00069 private:
00070   SocketStream *_stream;
00071   bool _owns_stream;
00072 
00073   typedef pdeque<Datagram> Data;
00074   Data _data;
00075   bool _closed;
00076 
00077 public:
00078   static void register_with_read_factory();
00079   virtual void write_recorder(BamWriter *manager, Datagram &dg);
00080 
00081 protected:
00082   static RecorderBase *make_recorder(const FactoryParams &params);
00083   void fillin_recorder(DatagramIterator &scan, BamReader *manager);
00084 
00085 public:
00086   static TypeHandle get_class_type() {
00087     return _type_handle;
00088   }
00089   static void init_type() {
00090     RecorderBase::init_type();
00091     register_type(_type_handle, "SocketStreamRecorder",
00092                   RecorderBase::get_class_type());
00093   }
00094   virtual TypeHandle get_type() const {
00095     return get_class_type();
00096   }
00097   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00098 
00099 private:
00100   static TypeHandle _type_handle;
00101 };
00102 
00103 #include "socketStreamRecorder.I"
00104 
00105 #endif  // HAVE_OPENSSL
00106 
00107 #endif  // SOCKETSTREAMRECORDER_H
 All Classes Functions Variables Enumerations