cisst-saw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
mtsComponentAddLatency.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): Anton Deguet
7  Created on: 2011-12-15
8 
9  (C) Copyright 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 _mtsComponentAddLatency_h
23 #define _mtsComponentAddLatency_h
24 
27 
28 // Always include last
30 
31 // forward declarations for internal types
32 class mtsComponentAddLatencyDelayedRead;
33 class mtsComponentAddLatencyDelayedQualifiedRead;
34 class mtsComponentAddLatencyDelayedVoid;
35 class mtsComponentAddLatencyDelayedWrite;
36 
67 {
69 
70  protected:
71 
72  typedef std::list<mtsComponentAddLatencyDelayedRead *> DelayedReadList;
74 
75  typedef std::list<mtsComponentAddLatencyDelayedQualifiedRead *> DelayedQualifiedReadList;
77 
78  typedef std::list<mtsComponentAddLatencyDelayedVoid *> DelayedVoidList;
80 
81  typedef std::list<mtsComponentAddLatencyDelayedWrite *> DelayedWriteList;
83 
84  public:
85  // constructor
86  mtsComponentAddLatency(const std::string & componentName, double periodInSeconds);
88  virtual ~mtsComponentAddLatency();
89 
90  // methods defined as virtual in base class
91  void Configure(const std::string & filename);
92  void Startup(void);
93  void Run(void);
94  void Cleanup(void);
95 
96  double SetLatency(double latencyInSeconds);
97 
98  protected:
99 
106  template <class _elementType>
107  bool AddCommandReadDelayed(mtsInterfaceRequired * interfaceRequired,
108  const std::string & commandRequiredName,
109  mtsInterfaceProvided * interfaceProvided,
110  const std::string & commandProvidedName = "");
111 
112  template <class _element1Type, class _element2Type>
113  bool AddCommandQualifiedReadDelayed(mtsInterfaceRequired * interfaceRequired,
114  const std::string & commandRequiredName,
115  mtsInterfaceProvided * interfaceProvided,
116  const std::string & commandProvidedName = "");
117 
118 
119  bool AddCommandVoidDelayed(mtsInterfaceRequired * interfaceRequired,
120  const std::string & commandRequiredName,
121  mtsInterfaceProvided * interfaceProvided,
122  const std::string & commandProvidedName = "");
123 
124  template <class _elementType>
125  bool AddCommandWriteDelayed(mtsInterfaceRequired * interfaceRequired,
126  const std::string & commandRequiredName,
127  mtsInterfaceProvided * interfaceProvided,
128  const std::string & commandProvidedName = "");
129 
130  bool AddEventVoidDelayed(mtsInterfaceRequired * interfaceRequired,
131  const std::string & eventRequiredName,
132  mtsInterfaceProvided * interfaceProvided,
133  const std::string & eventProvidedName = "");
134 
135  template <class _elementType>
136  bool AddEventWriteDelayed(mtsInterfaceRequired * interfaceRequired,
137  const std::string & eventRequiredName,
138  mtsInterfaceProvided * interfaceProvided,
139  const std::string & eventProvidedName = "");
140 
141  double Latency;
143 
144  private:
145  bool AddCommandReadDelayedInternal(mtsGenericObject & data,
146  mtsInterfaceRequired * interfaceRequired,
147  const std::string & commandRequiredName);
148 
149  bool AddCommandQualifiedReadDelayedInternal(const mtsGenericObject & qualifier,
150  const mtsGenericObject & placeHolder,
151  mtsInterfaceRequired * interfaceRequired,
152  const std::string & commandRequiredName,
153  mtsInterfaceProvided * interfaceProvided,
154  const std::string & commandProvidedName);
155 
156  bool AddCommandWriteDelayedInternal(const mtsGenericObject & data,
157  mtsInterfaceRequired * interfaceRequired,
158  const std::string & commandRequiredName,
159  mtsInterfaceProvided * interfaceProvided,
160  const std::string & commandProvidedName);
161 
162  bool AddEventWriteDelayedInternal(const mtsGenericObject & data,
163  mtsInterfaceRequired * interfaceRequired,
164  const std::string & eventRequiredName,
165  mtsInterfaceProvided * interfaceProvided,
166  const std::string & eventProvidedName = "");
167 
168 };
169 
170 
171 
172 template <class _elementType>
174  const std::string & commandRequiredName,
175  mtsInterfaceProvided * interfaceProvided,
176  const std::string & commandProvidedName)
177 {
178  // data object is used later to store the result of function
179  // reads, state teble will keep a pointer on that object so it
180  // must not be deleted until the task is killed.
181  _elementType * data = new _elementType;
182  this->LatencyStateTable.AddData(*data);
183  interfaceProvided->AddCommandReadStateDelayed(this->LatencyStateTable,
184  *data,
185  commandProvidedName == ""
186  ? commandRequiredName
187  : commandProvidedName);
188  return
189  this->AddCommandReadDelayedInternal(*data, interfaceRequired, commandRequiredName);
190 }
191 
192 
193 template <class _element1Type, class _element2Type>
195  const std::string & commandRequiredName,
196  mtsInterfaceProvided * interfaceProvided,
197  const std::string & commandProvidedName)
198 {
199  _element1Type qualifier;
200  _element2Type placeHolder;
201  return
202  this->AddCommandQualifiedReadDelayedInternal(qualifier,
203  placeHolder,
204  interfaceRequired,
205  commandRequiredName,
206  interfaceProvided,
207  commandProvidedName == ""
208  ? commandRequiredName
209  : commandProvidedName);
210 }
211 
212 
213 template <class _elementType>
215  const std::string & commandRequiredName,
216  mtsInterfaceProvided * interfaceProvided,
217  const std::string & commandProvidedName)
218 {
219  // data object is used to create an argument prototype but won't
220  // be used afterwards
221  _elementType data;
222  return
223  this->AddCommandWriteDelayedInternal(data,
224  interfaceRequired,
225  commandRequiredName,
226  interfaceProvided,
227  commandProvidedName == ""
228  ? commandRequiredName
229  : commandProvidedName);
230 }
231 
232 
233 template <class _elementType>
235  const std::string & eventRequiredName,
236  mtsInterfaceProvided * interfaceProvided,
237  const std::string & eventProvidedName)
238 {
239  // data object is used to create an argument prototype but won't
240  // be used afterwards
241  _elementType data;
242  return
243  this->AddEventWriteDelayedInternal(data,
244  interfaceRequired,
245  eventRequiredName,
246  interfaceProvided,
247  eventProvidedName == ""
248  ? eventRequiredName
249  : eventProvidedName);
250 }
251 
252 
254 
255 
256 #endif // _mtsComponentAddLatency_h
257 
#define CISST_EXPORT
Definition: cmnExportMacros.h:50
DelayedVoidList DelayedVoids
Definition: mtsComponentAddLatency.h:79
bool AddCommandWriteDelayed(mtsInterfaceRequired *interfaceRequired, const std::string &commandRequiredName, mtsInterfaceProvided *interfaceProvided, const std::string &commandProvidedName="")
Definition: mtsComponentAddLatency.h:214
double Latency
Definition: mtsComponentAddLatency.h:141
mtsCommandRead * AddCommandReadStateDelayed(const mtsStateTable &stateTable, const _elementType &stateData, const std::string &commandName)
Definition: mtsInterfaceProvided.h:745
DelayedQualifiedReadList DelayedQualifiedReads
Definition: mtsComponentAddLatency.h:76
Definition: mtsInterfaceRequired.h:85
bool AddCommandReadDelayed(mtsInterfaceRequired *interfaceRequired, const std::string &commandRequiredName, mtsInterfaceProvided *interfaceProvided, const std::string &commandProvidedName="")
Definition: mtsComponentAddLatency.h:173
DelayedWriteList DelayedWrites
Definition: mtsComponentAddLatency.h:82
std::list< mtsComponentAddLatencyDelayedVoid * > DelayedVoidList
Definition: mtsComponentAddLatency.h:78
Definition: mtsTaskPeriodic.h:38
std::list< mtsComponentAddLatencyDelayedQualifiedRead * > DelayedQualifiedReadList
Definition: mtsComponentAddLatency.h:75
Definition: mtsComponentAddLatency.h:66
Base class for data object in cisstMultiTask.
Definition: mtsGenericObject.h:56
const int CMN_DYNAMIC_CREATION_ONEARG
Definition: cmnClassRegisterMacros.h:333
virtual void Startup(void)
Definition: mtsComponent.h:262
DelayedReadList DelayedReads
Definition: mtsComponentAddLatency.h:73
mtsStateTable LatencyStateTable
Definition: mtsComponentAddLatency.h:142
virtual void Configure(const std::string &CMN_UNUSED(filename)="")
Definition: mtsTask.h:218
bool AddEventWriteDelayed(mtsInterfaceRequired *interfaceRequired, const std::string &eventRequiredName, mtsInterfaceProvided *interfaceProvided, const std::string &eventProvidedName="")
Definition: mtsComponentAddLatency.h:234
Definition: mtsStateTable.h:67
#define CMN_DECLARE_SERVICES(hasDynamicCreation, lod)
Definition: cmnClassRegisterMacros.h:116
void AddData(_elementType &element, const std::string &name="")
Definition: mtsStateTable.h:369
Defines a periodic task.
Definition: mtsInterfaceProvided.h:96
std::list< mtsComponentAddLatencyDelayedRead * > DelayedReadList
Definition: mtsComponentAddLatency.h:72
virtual void Run(void)=0
Declaration of mtsInterfaceProvided.
Rules of exporting.
bool AddCommandQualifiedReadDelayed(mtsInterfaceRequired *interfaceRequired, const std::string &commandRequiredName, mtsInterfaceProvided *interfaceProvided, const std::string &commandProvidedName="")
Definition: mtsComponentAddLatency.h:194
Definition: mtsTaskPeriodic.h:80
#define CMN_DECLARE_SERVICES_INSTANTIATION(className)
Definition: cmnClassRegisterMacros.h:202
virtual void Cleanup(void)
Definition: mtsComponent.h:267
std::list< mtsComponentAddLatencyDelayedWrite * > DelayedWriteList
Definition: mtsComponentAddLatency.h:81
#define CMN_LOG_ALLOW_DEFAULT
Definition: cmnLogLoD.h:76