recorder.h
1 /***************************************************************************
2  Copyright (C) 2002-2015 Kentaro Kitagawa
3  kitagawa@phys.s.u-tokyo.ac.jp
4 
5  This program is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License as published by the Free Software Foundation; either
8  version 2 of the License, or (at your option) any later version.
9 
10  You should have received a copy of the GNU Library General
11  Public License and a list of authors along with this program;
12  see the files COPYING and AUTHORS.
13 ***************************************************************************/
14 //---------------------------------------------------------------------------
15 
16 #ifndef recorderH
17 #define recorderH
18 //---------------------------------------------------------------------------
19 #include "xnode.h"
20 #include "xnodeconnector.h"
21 #include "driver.h"
22 
23 #include <fstream>
24 
25 #define MAX_RAW_RECORD_SIZE 1000000
26 
27 class XRawStream : public XNode {
28 public:
29  XRawStream(const char *name, bool runtime, const shared_ptr<XDriverList> &driverlist);
30  virtual ~XRawStream();
31  const shared_ptr<XStringNode> &filename() const {return m_filename;}
32 protected:
33  shared_ptr<XDriverList> m_drivers;
34  //! file descriptor of GZip
35  void *m_pGFD;
36  XMutex m_filemutex;
37 private:
38  shared_ptr<XStringNode> m_filename;
39 
40 };
42 public:
43  XRawStreamRecorder(const char *name, bool runtime, const shared_ptr<XDriverList> &driverlist);
44  virtual ~XRawStreamRecorder() = default;
45  const shared_ptr<XBoolNode> &recording() const {return m_recording;}
46 protected:
47  virtual void onCatch(const Snapshot &shot, const XListNodeBase::Payload::CatchEvent &e);
48  virtual void onRelease(const Snapshot &shot, const XListNodeBase::Payload::ReleaseEvent &e);
49 private:
50  void onOpen(const Snapshot &shot, XValueNodeBase *);
51 
52  shared_ptr<XListener> m_lsnOnRecord;
53  shared_ptr<XListener> m_lsnOnCatch;
54  shared_ptr<XListener> m_lsnOnRelease;
55  shared_ptr<XListener> m_lsnOnFlush;
56  shared_ptr<XListener> m_lsnOnOpen;
57 
58  void onRecord(const Snapshot &shot, XDriver *driver);
59  void onFlush(const Snapshot &shot, XValueNodeBase *);
60  const shared_ptr<XBoolNode> m_recording;
61 };
62 
63 
64 class XScalarEntryList;
65 
66 class XTextWriter : public XNode {
67 public:
68  XTextWriter(const char *name, bool runtime,
69  const shared_ptr<XDriverList> &driverlist, const shared_ptr<XScalarEntryList> &entrylist);
70  virtual ~XTextWriter() = default;
71 
72  const shared_ptr<XStringNode> &filename() const {return m_filename;}
73  const shared_ptr<XBoolNode> &recording() const {return m_recording;}
74  const shared_ptr<XStringNode> &lastLine() const {return m_lastLine;}
75  const shared_ptr<XStringNode> &logFilename() const {return m_logFilename;}
76  const shared_ptr<XBoolNode> &logRecording() const {return m_logRecording;}
77  const shared_ptr<XUIntNode> &logEvery() const {return m_logEvery;}
78 protected:
79  virtual void onCatch(const Snapshot &shot, const XListNodeBase::Payload::CatchEvent &e);
80  virtual void onRelease(const Snapshot &shot, const XListNodeBase::Payload::ReleaseEvent &e);
81 private:
82  const shared_ptr<XDriverList> m_drivers;
83  const shared_ptr<XScalarEntryList> m_entries;
84  const shared_ptr<XStringNode> m_filename;
85  const shared_ptr<XStringNode> m_lastLine;
86  const shared_ptr<XBoolNode> m_recording;
87  const shared_ptr<XStringNode> m_logFilename;
88  const shared_ptr<XBoolNode> m_logRecording;
89  const shared_ptr<XUIntNode> m_logEvery;
90  shared_ptr<XListener> m_lsnOnRecord;
91  shared_ptr<XListener> m_lsnOnFlush;
92  shared_ptr<XListener> m_lsnOnCatch;
93  shared_ptr<XListener> m_lsnOnRelease;
94  shared_ptr<XListener> m_lsnOnLastLineChanged;
95  shared_ptr<XListener> m_lsnOnFilenameChanged;
96  shared_ptr<XListener> m_lsnOnLogFilenameChanged;
97  shared_ptr<XListener> m_lsnOnLogRecord;
98  void onRecord(const Snapshot &shot, XDriver *);
99  void onFlush(const Snapshot &shot, XValueNodeBase *);
100  void onLastLineChanged(const Snapshot &shot, XValueNodeBase *);
101  void onFilenameChanged(const Snapshot &shot, XValueNodeBase *);
102  void onLogFilenameChanged(const Snapshot &shot, XValueNodeBase *);
103 
104  std::fstream m_stream;
105  std::fstream m_logStream;
106  XRecursiveMutex m_filemutex;
107  XRecursiveMutex m_logFilemutex;
108  XTime m_loggedTime;
109 };
110 
111 
112 #endif

Generated for KAME4 by  doxygen 1.8.3