cisst-saw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
mtsCollectorState.h
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ex: set filetype=cpp softtabstop=4 shiftwidth=4 tabstop=4 cindent expandtab: */
3 
4 /*
5 
6  Author(s): Min Yang Jung, Anton Deguet
7  Created on: 2009-03-20
8 
9  (C) Copyright 2009-2011 Johns Hopkins University (JHU), All Rights
10  Reserved.
11 
12 --- begin cisst license - do not edit ---
13 
14 This software is provided "as is" under an open source license, with
15 no warranty. The complete license can be found in license.txt and
16 http://www.cisst.org/cisst/license.txt.
17 
18 --- end cisst license ---
19 
20 */
21 
22 #ifndef _mtsCollectorState_h
23 #define _mtsCollectorState_h
24 
29 
30 #include <string>
31 
32 // Always include last
34 
45 {
46  friend class mtsCollectorStateTest;
47  friend class mtsStateTable;
48 
50 
53  typedef struct {
54  std::string Name;
55  unsigned int ID;
56  } SignalElement;
57 
58  typedef std::vector<SignalElement> RegisteredSignalElementType;
59  RegisteredSignalElementType RegisteredSignalElements;
60 
62  size_t OffsetForNextRead;
63 
65  ptrdiff_t LastReadIndex;
66 
68  size_t TableHistoryLength;
69 
71  size_t SamplingInterval;
72 
74  mtsComponent * TargetComponent;
75  mtsStateTable * TargetStateTable;
76 
78  void Run(void);
79 
80  void Startup(void);
81 
83  void Initialize(void);
84 
85  // documented in base class
86  virtual std::string GetDefaultOutputName(void);
87 
88  mtsFunctionWrite StateTableStartCollection;
89  mtsFunctionWrite StateTableStopCollection;
90 
93  bool IsRegisteredSignal(const std::string & signalName) const;
94 
96  bool AddSignalElement(const std::string & signalName, const unsigned int signalID);
97 
99  bool FetchStateTableData(const mtsStateTable * table,
100  const size_t startIdx,
101  const size_t endIdx);
102 
104  void PrintHeader(const CollectorFileFormat & fileFormat);
105 
107  void MarkHeaderEnd(std::ostream & logFile);
108 
110  static bool IsHeaderEndMark(const char * buffer);
111 
114  void BatchReadyHandler(const mtsStateTable::IndexRange & range);
115 
119  void CollectionStartedHandler(void);
120 
124  void CollectionStoppedHandler(const mtsUInt & count);
125 
129  void ProgressHandler(const mtsUInt & count);
130 
132  void BatchCollect(const mtsStateTable::IndexRange & range);
133 
134 public:
136  mtsCollectorState(const std::string & collectorName);
137 
139  mtsCollectorState(const std::string & targetComponentName,
140  const std::string & targetStateTableName,
141  const CollectorFileFormat fileFormat);
142 
143  ~mtsCollectorState(void);
144 
149  bool SetStateTable(const std::string & componentName,
150  const std::string & stateTableName = "");
151 
153  bool AddSignal(const std::string & signalName = "");
154 
158  void SetSamplingInterval(const unsigned int samplingInterval) {
159  SamplingInterval = (samplingInterval > 0 ? samplingInterval : 1);
160  }
161 
166  bool Connect(void);
167 
170  bool Disconnect(void);
171 
173  static bool ConvertBinaryToText(const std::string sourceBinaryLogFileName,
174  const std::string targetPlainTextLogFileName,
175  const char delimiter = ',');
176 
182  void StartCollection(const mtsDouble & delayInSeconds);
183  void StopCollection(const mtsDouble & delayInSeconds);
185 };
186 
188 
189 #endif // _mtsCollectorState_h
#define CISST_EXPORT
Definition: cmnExportMacros.h:50
Defines the state data table.
A data collection tool.
void Initialize(void)
virtual void StopCollection(const mtsDouble &delayInSeconds)=0
Definition: mtsStateTable.h:67
Definition: mtsComponent.h:150
#define CMN_DECLARE_SERVICES(hasDynamicCreation, lod)
Definition: cmnClassRegisterMacros.h:116
Defines a periodic task.
virtual void Startup(void)=0
Defines a command with no argument.
virtual void Run(void)=0
virtual std::string GetDefaultOutputName(void)=0
Rules of exporting.
Definition: mtsCollectorState.h:44
Definition: mtsFunctionWrite.h:37
Definition: mtsGenericObjectProxy.h:45
virtual void StartCollection(const mtsDouble &delayInSeconds)=0
const int CMN_NO_DYNAMIC_CREATION
Definition: cmnClassRegisterMacros.h:328
#define CMN_DECLARE_SERVICES_INSTANTIATION(className)
Definition: cmnClassRegisterMacros.h:202
Definition: mtsStateTable.h:80
void SetSamplingInterval(const unsigned int samplingInterval)
Definition: mtsCollectorState.h:158
#define CMN_LOG_ALLOW_DEFAULT
Definition: cmnLogLoD.h:76
unsigned char ID
Definition: CiA301.h:13
Definition: mtsCollectorBase.h:48