secondarydriver.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 SECONDARYDRIVER_H_
15 #define SECONDARYDRIVER_H_
16 
17 #include "driver.h"
18 #include "xitemnode.h"
19 
20 //!
21 template <class T>
22 class DECLSPEC_MODULE XSecondaryDriverInterface : public T {
23 public:
24  XSecondaryDriverInterface(const char *name, bool runtime, Transaction &tr_meas, const shared_ptr<XMeasure> &meas);
25  virtual ~XSecondaryDriverInterface();
26 
27 //! Shows all forms belonging to driver
28  virtual void showForms() = 0;
29 
30  struct DECLSPEC_MODULE Payload : public T::Payload {
31  private:
32  friend class XSecondaryDriverInterface<T>;
33  struct Connection {
34  shared_ptr<XListener> m_lsnOnRecord;
35  shared_ptr<XPointerItemNode<XDriverList> > m_selecter;
36  bool operator==(const XItemNodeBase *p) const {return p == m_selecter.get();}
37  };
38  typedef std::vector<Connection> ConnectionList;
39  ConnectionList m_connections;
40  };
41 protected:
42  //! Call this to receive signal/data.
43  void connect(const shared_ptr<XPointerItemNode<XDriverList> > &selecter);
44  //! check dependencies and lock all records and analyze
45  //! null pointer will be passed to analyze()
46  //! emitter is driver itself.
47  //! \sa analyze(), checkDependency()
48  void requestAnalysis();
49 
50  //! This function is called when a connected driver emit a signal
51  virtual void analyze(Transaction &tr, const Snapshot &shot_emitter, const Snapshot &shot_others,
52  XDriver *emitter) throw (typename T::XRecordError&) = 0;
53  //! This function is called inside analyze() or analyzeRaw()
54  //! this must be reentrant unlike analyze()
55  virtual void visualize(const Snapshot &shot) = 0;
56  //! Checks if the connected drivers have valid time stamps.
57  //! \return true if dependency is resolved.
58  //! This function must be reentrant unlike analyze().
59  virtual bool checkDependency(const Snapshot &shot_this,
60  const Snapshot &shot_emitter, const Snapshot &shot_others,
61  XDriver *emitter) const = 0;
62 
63  //! usually nothing to do
64  virtual void start() {}
65  //! usually nothing to do
66  virtual void stop() {}
67 private:
68  shared_ptr<XListener> m_lsnOnItemChanged;
69  //! called by connected drivers,
70  //! checks dependency, takes snapshot for drivers,
71  //! and finally calls purely virtual function analyze();
72  void onConnectedRecorded(const Snapshot &shot, XDriver *driver);
73 
74  void onItemChanged(const Snapshot &shot, XValueNodeBase *item);
75 
76  weak_ptr<XDriverList> m_drivers;
77 };
78 
80 
81 //class XSecondaryDriver : public XSecondaryDriverInterface<XDriver> {
82 //public:
83 // XSecondaryDriver(const char *name, bool runtime, Transaction &tr_meas, const shared_ptr<XMeasure> &meas) :
84 // XSecondaryDriverInterface<XDriver>(name, runtime, ref(tr_meas), meas) {}
85 //};
86 
87 #endif /*SECONDARYDRIVER_H_*/

Generated for KAME4 by  doxygen 1.8.3