measure.cpp
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 #include "xrubysupport.h"
15 #include "measure.h"
16 #include "kame.h"
17 
18 #include "primarydriver.h"
19 #include "interface.h"
20 #include "analyzer.h"
21 #include "recorder.h"
22 #include "recordreader.h"
23 
24 #include "thermometer.h"
25 #include "caltable.h"
26 
27 #include "analyzer.h"
28 #include "driverlistconnector.h"
29 #include "interfacelistconnector.h"
30 #include "entrylistconnector.h"
31 #include "graphlistconnector.h"
32 #include "recordreaderconnector.h"
33 #include "nodebrowser.h"
34 
35 #include "ui_caltableform.h"
36 #include "ui_drivercreate.h"
37 #include "ui_nodebrowserform.h"
38 #include "ui_recordreaderform.h"
39 #include "ui_rubythreadtool.h"
40 #include "ui_graphtool.h"
41 #include "ui_interfacetool.h"
42 #include "ui_drivertool.h"
43 #include "ui_scalarentrytool.h"
44 
45 #include <QTextBrowser>
46 
47 shared_ptr<XStatusPrinter> g_statusPrinter;
48 
49 XMeasure::XMeasure(const char *name, bool runtime) :
50 XNode(name, runtime),
51 m_thermometers(create<XThermometerList>("Thermometers", false)),
52 m_scalarEntries(create<XScalarEntryList>("ScalarEntries", true)),
53 m_graphList(create<XGraphList>("GraphList", true, scalarEntries())),
54 m_chartList(create<XChartList>("ChartList", true, scalarEntries())),
55 m_interfaces(create<XInterfaceList>("Interfaces", true)),
56 m_drivers(create<XDriverList>("Drivers", false, static_pointer_cast<XMeasure>(shared_from_this()))),
57 m_textWriter(create<XTextWriter>("TextWriter", false, drivers(), scalarEntries())),
58 m_rawStreamRecorder(create<XRawStreamRecorder>("RawStreamRecorder", false, drivers())),
59 m_rawStreamRecordReader(create<XRawStreamRecordReader>("RawStreamRecordReader", false,
60  drivers())),
61 m_conRecordReader(xqcon_create<XRawStreamRecordReaderConnector>(
62  rawStreamRecordReader(),
63  dynamic_cast<FrmKameMain*>(g_pFrmMain)->m_pFrmRecordReader)),
64 m_conDrivers(xqcon_create<XDriverListConnector>(
65  m_drivers, dynamic_cast<FrmKameMain*>(g_pFrmMain)->m_pFrmDriver)),
66 m_conInterfaces(xqcon_create<XInterfaceListConnector>(
67  m_interfaces,
68  dynamic_cast<FrmKameMain*>(g_pFrmMain)->m_pFrmInterface->m_tblInterface)),
69 m_conEntries(xqcon_create<XEntryListConnector>(
70  scalarEntries(),
71  dynamic_cast<FrmKameMain*>(g_pFrmMain)->m_pFrmScalarEntry->m_tblEntries,
72  charts())),
73 m_conGraphs(xqcon_create<XGraphListConnector>(graphs(),
74  dynamic_cast<FrmKameMain*>(g_pFrmMain)->m_pFrmGraphList->m_tblGraphs,
75  dynamic_cast<FrmKameMain*>(g_pFrmMain)->m_pFrmGraphList->btnNewGraph,
76  dynamic_cast<FrmKameMain*>(g_pFrmMain)->m_pFrmGraphList->btnDeleteGraph)),
77 m_conTextWrite(xqcon_create<XQToggleButtonConnector>(
78  textWriter()->recording(),
79  dynamic_cast<FrmKameMain*>(g_pFrmMain)->m_pFrmScalarEntry->m_ckbTextWrite)),
80 m_conTextURL(xqcon_create<XFilePathConnector>(
81  textWriter()->filename(),
82  dynamic_cast<FrmKameMain*>(g_pFrmMain)->m_pFrmScalarEntry->m_edTextWriter,
83  dynamic_cast<FrmKameMain*>(g_pFrmMain)->m_pFrmScalarEntry->m_btnTextWriter,
84  "Data files (*.dat);;All files (*.*)", true)),
85 m_conTextLastLine(xqcon_create<XQLineEditConnector>(
86  textWriter()->lastLine(),
87  dynamic_cast<FrmKameMain*>(g_pFrmMain)->m_pFrmScalarEntry->m_edLastLine)),
88 m_conLogWrite(xqcon_create<XQToggleButtonConnector>(
89  textWriter()->logRecording(),
90  dynamic_cast<FrmKameMain*>(g_pFrmMain)->m_pFrmScalarEntry->m_ckbLoggerWrite)),
91 m_conLogURL(xqcon_create<XFilePathConnector>(
92  textWriter()->logFilename(),
93  dynamic_cast<FrmKameMain*>(g_pFrmMain)->m_pFrmScalarEntry->m_edLogFile,
94  dynamic_cast<FrmKameMain*>(g_pFrmMain)->m_pFrmScalarEntry->m_btnLogFile,
95  "Data files (*.dat);;All files (*.*)", true)),
96 m_conLogEvery(xqcon_create<XQLineEditConnector>(
97  textWriter()->logEvery(),
98  dynamic_cast<FrmKameMain*>(g_pFrmMain)->m_pFrmScalarEntry->m_edLoggerEvery)),
99 m_conBinURL(xqcon_create<XFilePathConnector>(
100  rawStreamRecorder()->filename(),
101  dynamic_cast<FrmKameMain*>(g_pFrmMain)->m_pFrmDriver->m_edRec,
102  dynamic_cast<FrmKameMain*>(g_pFrmMain)->m_pFrmDriver->m_btnRec,
103  "Binary files (*.bin);;All files (*.*)", true)),
104 m_conBinWrite(xqcon_create<XQToggleButtonConnector>(
105  rawStreamRecorder()->recording(),
106  dynamic_cast<FrmKameMain*>(g_pFrmMain)->m_pFrmDriver->m_ckbBinRecWrite)),
107 m_conUrlRubyThread(),
108 m_conCalTable(xqcon_create<XConCalTable>(
109  m_thermometers, dynamic_cast<FrmKameMain*>(g_pFrmMain)->m_pFrmCalTable)),
110 m_conNodeBrowser(xqcon_create<XNodeBrowser>(
111  shared_from_this(), dynamic_cast<FrmKameMain*>(g_pFrmMain)->m_pFrmNodeBrowser)) {
112 
113  g_statusPrinter = XStatusPrinter::create();
114 
115  iterate_commit([=](Transaction &tr){
116  m_lsnOnReleaseDriver = tr[ *drivers()].onRelease().connect(
117  *this, &XMeasure::onReleaseDriver);
118  });
119 
120  m_ruby = createOrphan<XRuby>("RubySupport", true,
121  dynamic_pointer_cast<XMeasure>(shared_from_this()));
122 
123  m_ruby->resume();
124 
125  initialize();
126 }
127 
128 XMeasure::~XMeasure() {
129  printf("terminate\n");
130  m_rawStreamRecordReader->terminate();
131  m_ruby->terminate();
132  m_rawStreamRecordReader->join();
133  m_ruby->join();
134  m_ruby.reset();
135  g_statusPrinter.reset();
136 }
138 }
140  interfaces()->releaseAll();
141  drivers()->releaseAll();
142  thermometers()->releaseAll();
143  initialize();
144 }
146  Snapshot shot( *drivers());
147  if(shot.size()) {
148  const XNode::NodeList &list( *shot.list());
149  for(auto it = list.begin(); it != list.end(); it++) {
150  auto driver = dynamic_pointer_cast<XPrimaryDriver> ( *it);
151  if(driver)
152  driver->stop();
153  }
154  }
155 }
156 void XMeasure::onReleaseDriver(const Snapshot &shot, const XListNodeBase::Payload::ReleaseEvent &e) {
157  auto driver = static_pointer_cast<XDriver>(e.released);
158  auto pridriver = dynamic_pointer_cast<XPrimaryDriver>(driver);
159  if(pridriver)
160  pridriver->stop();
161  for(;;) {
162  shared_ptr<XScalarEntry> entry;
163  Snapshot shot( *scalarEntries());
164  if(shot.size()) {
165  const XNode::NodeList &list( *shot.list());
166  for(auto it = list.begin(); it != list.end(); it++) {
167  auto entr = dynamic_pointer_cast<XScalarEntry> ( *it);
168  if(entr->driver() == driver) {
169  entry = entr;
170  }
171  }
172  }
173  if( !entry)
174  break;
175  scalarEntries()->release(entry);
176  }
177  for(;;) {
178  shared_ptr<XInterface> intf_release;
179  Snapshot shot( *interfaces());
180  if(shot.size()) {
181  const XNode::NodeList &list( *shot.list());
182  for(auto it = list.begin(); it != list.end(); it++) {
183  auto intf = dynamic_pointer_cast<XInterface> ( *it);
184  if(intf->driver() == driver) {
185  intf_release = intf;
186  }
187  }
188  }
189  if( !intf_release)
190  break;
191  interfaces()->release(intf_release);
192  }
193 }

Generated for KAME4 by  doxygen 1.8.3