driver.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 #ifndef driverH
15 #define driverH
16 
17 #include "xnode.h"
18 #include "xlistnode.h"
19 #include "measure.h"
20 #include <vector>
21 #include <set>
22 
23 class XRecordDependency;
24 class XScalarEntryList;
25 class XInterfaceList;
26 class XThermometerList;
27 class XDriverList;
28 
29 //! Base class for all instrument drivers
30 class DECLSPEC_KAME XDriver : public XNode {
31 public:
32  XDriver(const char *name, bool runtime, Transaction &tr_meas, const shared_ptr<XMeasure> &meas);
33  virtual ~XDriver() = default;
34 
35  //! Shows all forms belonging to the driver.
36  virtual void showForms() = 0;
37 
38  struct DECLSPEC_KAME Payload : public XNode::Payload {
39  //! Recorded time.
40  //! It is a time stamp when a phenomenon occurred and recorded.
41  //! Following analyses have to be based on this time.
42  //! It is undefined if record is invalid.
43  const XTime &time() const {return m_recordTime;}
44  //! A time stamp when an operator (ones) can see outputs.
45  //! Manual operations (e.g. pushing a clear button) have to be based on this time.
46  //! It is a time when a phenomenon starts if measurement is going on.
47  //! It is a time when a record was read for a non-real-time analysis.
48  //! It is undefined if record is invalid.
49  const XTime &timeAwared() const {return m_awaredTime;}
50 
51  Talker<XDriver*> &onRecord() {return m_tlkOnRecord;}
52  const Talker<XDriver*> &onRecord() const {return m_tlkOnRecord;}
53  private:
54  friend class XDriver;
55 
56  //! \sa time()
58  //! \sa timeAwared()
60 
61  Talker<XDriver*> m_tlkOnRecord;
62  };
63  //! Throwing this exception will cause a reset of record time.
64  //! And, prints error message.
65  struct DECLSPEC_KAME XRecordError : public XKameError {
66  XRecordError(const XString &s, const char *file, int line) : XKameError(s, file, line) {}
67  virtual ~XRecordError() = default;
68  };
69  //! Throwing this exception will skip signal emission, assuming record is kept valid.
70  struct DECLSPEC_KAME XSkippedRecordError : public XRecordError {
71  XSkippedRecordError(const XString &s, const char *file, int line) : XRecordError(s, file, line) {}
72  XSkippedRecordError(const char *file, int line) : XRecordError("", file, line) {}
73  virtual ~XSkippedRecordError() = default;
74  };
75  //! The size of the raw record is not enough to continue analyzing.
76  struct DECLSPEC_KAME XBufferUnderflowRecordError : public XRecordError {
77  XBufferUnderflowRecordError(const char *file, int line);
78  virtual ~XBufferUnderflowRecordError() = default;
79  };
80 protected:
81 
82  //! This function is called after committing XPrimaryDriver::analyzeRaw() or XSecondaryDriver::analyze().
83  //! This might be called even if the record is invalid (time() == false).
84  virtual void visualize(const Snapshot &shot) = 0;
85 
86  //! Sets time stamps.
87  //! \sa time(), timeAwared()
88  void record(Transaction &tr,
89  const XTime &time_awared, const XTime &time_recorded);
90 };
91 
92 class DECLSPEC_KAME XDriverList : public XCustomTypeListNode<XDriver> {
93 public:
94  XDriverList(const char *name, bool runtime, const shared_ptr<XMeasure> &measure);
95 
96  DEFINE_TYPE_HOLDER(
97  reference_wrapper<Transaction>,
98  const shared_ptr<XMeasure> &
99  )
100  virtual shared_ptr<XNode> createByTypename(const XString &type, const XString& name);
101 private:
102  const weak_ptr<XMeasure> m_measure;
103 };
104 //---------------------------------------------------------------------------
105 #endif

Generated for KAME4 by  doxygen 1.8.3