cisst-saw
Loading...
Searching...
No Matches
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 Author(s): Anton Deguet
6 Created on: 2011-12-15
7
8 (C) Copyright 2011-2023 Johns Hopkins University (JHU), All Rights Reserved.
9
10--- begin cisst license - do not edit ---
11
12This software is provided "as is" under an open source license, with
13no warranty. The complete license can be found in license.txt and
14http://www.cisst.org/cisst/license.txt.
15
16--- end cisst license ---
17*/
18
19
20#ifndef _mtsComponentAddLatency_h
21#define _mtsComponentAddLatency_h
22
25
26// Always include last
28
29// forward declarations for internal types
30class mtsComponentAddLatencyDelayedRead;
31class mtsComponentAddLatencyDelayedQualifiedRead;
32class mtsComponentAddLatencyDelayedVoid;
33class mtsComponentAddLatencyDelayedWrite;
34
65{
67
68 protected:
69
70 typedef std::list<mtsComponentAddLatencyDelayedRead *> DelayedReadList;
72
73 typedef std::list<mtsComponentAddLatencyDelayedQualifiedRead *> DelayedQualifiedReadList;
75
76 typedef std::list<mtsComponentAddLatencyDelayedVoid *> DelayedVoidList;
78
79 typedef std::list<mtsComponentAddLatencyDelayedWrite *> DelayedWriteList;
81
82 public:
83 // constructor
84 mtsComponentAddLatency(const std::string & componentName, double periodInSeconds);
87
88 // methods defined as virtual in base class
89 void Configure(const std::string & filename) override;
90 void Startup(void) override;
91 void Run(void) override;
92 void Cleanup(void) override;
93
94 double SetLatency(double latencyInSeconds);
95
96 protected:
97
104 template <class _elementType>
105 bool AddCommandReadDelayed(mtsInterfaceRequired * interfaceRequired,
106 const std::string & commandRequiredName,
107 mtsInterfaceProvided * interfaceProvided,
108 const std::string & commandProvidedName = "");
109
110 template <class _element1Type, class _element2Type>
112 const std::string & commandRequiredName,
113 mtsInterfaceProvided * interfaceProvided,
114 const std::string & commandProvidedName = "");
115
116
118 const std::string & commandRequiredName,
119 mtsInterfaceProvided * interfaceProvided,
120 const std::string & commandProvidedName = "");
121
122 template <class _elementType>
123 bool AddCommandWriteDelayed(mtsInterfaceRequired * interfaceRequired,
124 const std::string & commandRequiredName,
125 mtsInterfaceProvided * interfaceProvided,
126 const std::string & commandProvidedName = "");
127
129 const std::string & eventRequiredName,
130 mtsInterfaceProvided * interfaceProvided,
131 const std::string & eventProvidedName = "");
132
133 template <class _elementType>
134 bool AddEventWriteDelayed(mtsInterfaceRequired * interfaceRequired,
135 const std::string & eventRequiredName,
136 mtsInterfaceProvided * interfaceProvided,
137 const std::string & eventProvidedName = "");
138
139 double Latency;
141
142 private:
143 bool AddCommandReadDelayedInternal(mtsGenericObject & data,
144 mtsInterfaceRequired * interfaceRequired,
145 const std::string & commandRequiredName);
146
147 bool AddCommandQualifiedReadDelayedInternal(const mtsGenericObject & qualifier,
148 const mtsGenericObject & placeHolder,
149 mtsInterfaceRequired * interfaceRequired,
150 const std::string & commandRequiredName,
151 mtsInterfaceProvided * interfaceProvided,
152 const std::string & commandProvidedName);
153
154 bool AddCommandWriteDelayedInternal(const mtsGenericObject & data,
155 mtsInterfaceRequired * interfaceRequired,
156 const std::string & commandRequiredName,
157 mtsInterfaceProvided * interfaceProvided,
158 const std::string & commandProvidedName);
159
160 bool AddEventWriteDelayedInternal(const mtsGenericObject & data,
161 mtsInterfaceRequired * interfaceRequired,
162 const std::string & eventRequiredName,
163 mtsInterfaceProvided * interfaceProvided,
164 const std::string & eventProvidedName = "");
165
166};
167
168
169
170template <class _elementType>
172 const std::string & commandRequiredName,
173 mtsInterfaceProvided * interfaceProvided,
174 const std::string & commandProvidedName)
175{
176 // data object is used later to store the result of function
177 // reads, state teble will keep a pointer on that object so it
178 // must not be deleted until the task is killed.
179 _elementType * data = new _elementType;
180 this->LatencyStateTable.AddData(*data);
181 interfaceProvided->AddCommandReadStateDelayed(this->LatencyStateTable,
182 *data,
183 commandProvidedName == ""
184 ? commandRequiredName
185 : commandProvidedName);
186 return
187 this->AddCommandReadDelayedInternal(*data, interfaceRequired, commandRequiredName);
188}
189
190
191template <class _element1Type, class _element2Type>
193 const std::string & commandRequiredName,
194 mtsInterfaceProvided * interfaceProvided,
195 const std::string & commandProvidedName)
196{
197 _element1Type qualifier;
198 _element2Type placeHolder;
199 return
200 this->AddCommandQualifiedReadDelayedInternal(qualifier,
201 placeHolder,
202 interfaceRequired,
203 commandRequiredName,
204 interfaceProvided,
205 commandProvidedName == ""
206 ? commandRequiredName
207 : commandProvidedName);
208}
209
210
211template <class _elementType>
213 const std::string & commandRequiredName,
214 mtsInterfaceProvided * interfaceProvided,
215 const std::string & commandProvidedName)
216{
217 // data object is used to create an argument prototype but won't
218 // be used afterwards
219 _elementType data;
220 return
221 this->AddCommandWriteDelayedInternal(data,
222 interfaceRequired,
223 commandRequiredName,
224 interfaceProvided,
225 commandProvidedName == ""
226 ? commandRequiredName
227 : commandProvidedName);
228}
229
230
231template <class _elementType>
233 const std::string & eventRequiredName,
234 mtsInterfaceProvided * interfaceProvided,
235 const std::string & eventProvidedName)
236{
237 // data object is used to create an argument prototype but won't
238 // be used afterwards
239 _elementType data;
240 return
241 this->AddEventWriteDelayedInternal(data,
242 interfaceRequired,
243 eventRequiredName,
244 interfaceProvided,
245 eventProvidedName == ""
246 ? eventRequiredName
247 : eventProvidedName);
248}
249
250
252
253
254#endif // _mtsComponentAddLatency_h
255
Definition mtsComponentAddLatency.h:65
std::list< mtsComponentAddLatencyDelayedQualifiedRead * > DelayedQualifiedReadList
Definition mtsComponentAddLatency.h:73
std::list< mtsComponentAddLatencyDelayedWrite * > DelayedWriteList
Definition mtsComponentAddLatency.h:79
bool AddCommandVoidDelayed(mtsInterfaceRequired *interfaceRequired, const std::string &commandRequiredName, mtsInterfaceProvided *interfaceProvided, const std::string &commandProvidedName="")
void Run(void) override
void Cleanup(void) override
void Configure(const std::string &filename) override
virtual ~mtsComponentAddLatency()
double Latency
Definition mtsComponentAddLatency.h:139
mtsStateTable LatencyStateTable
Definition mtsComponentAddLatency.h:140
bool AddEventWriteDelayed(mtsInterfaceRequired *interfaceRequired, const std::string &eventRequiredName, mtsInterfaceProvided *interfaceProvided, const std::string &eventProvidedName="")
Definition mtsComponentAddLatency.h:232
void Startup(void) override
std::list< mtsComponentAddLatencyDelayedRead * > DelayedReadList
Definition mtsComponentAddLatency.h:70
mtsComponentAddLatency(const mtsTaskPeriodicConstructorArg &arg)
mtsComponentAddLatency(const std::string &componentName, double periodInSeconds)
DelayedVoidList DelayedVoids
Definition mtsComponentAddLatency.h:77
std::list< mtsComponentAddLatencyDelayedVoid * > DelayedVoidList
Definition mtsComponentAddLatency.h:76
double SetLatency(double latencyInSeconds)
bool AddCommandWriteDelayed(mtsInterfaceRequired *interfaceRequired, const std::string &commandRequiredName, mtsInterfaceProvided *interfaceProvided, const std::string &commandProvidedName="")
Definition mtsComponentAddLatency.h:212
DelayedQualifiedReadList DelayedQualifiedReads
Definition mtsComponentAddLatency.h:74
bool AddCommandReadDelayed(mtsInterfaceRequired *interfaceRequired, const std::string &commandRequiredName, mtsInterfaceProvided *interfaceProvided, const std::string &commandProvidedName="")
Definition mtsComponentAddLatency.h:171
bool AddCommandQualifiedReadDelayed(mtsInterfaceRequired *interfaceRequired, const std::string &commandRequiredName, mtsInterfaceProvided *interfaceProvided, const std::string &commandProvidedName="")
Definition mtsComponentAddLatency.h:192
bool AddEventVoidDelayed(mtsInterfaceRequired *interfaceRequired, const std::string &eventRequiredName, mtsInterfaceProvided *interfaceProvided, const std::string &eventProvidedName="")
DelayedWriteList DelayedWrites
Definition mtsComponentAddLatency.h:80
DelayedReadList DelayedReads
Definition mtsComponentAddLatency.h:71
Base class for data object in cisstMultiTask.
Definition mtsGenericObject.h:52
Definition mtsInterfaceProvided.h:98
mtsCommandRead * AddCommandReadStateDelayed(const mtsStateTable &stateTable, const _elementType &stateData, const std::string &commandName)
Definition mtsInterfaceProvided.h:874
Definition mtsInterfaceRequired.h:83
Definition mtsStateTable.h:67
void AddData(_elementType &element, const std::string &name="")
Definition mtsStateTable.h:373
Definition mtsParameterTypes.h:1622
mtsTaskPeriodic(const std::string &name, double periodicityInSeconds, bool isHardRealTime=false, unsigned int sizeStateTable=256, bool newThread=true)
const int CMN_DYNAMIC_CREATION_ONEARG
Definition cmnClassRegisterMacros.h:330
#define CMN_DECLARE_SERVICES_INSTANTIATION(className)
Definition cmnClassRegisterMacros.h:199
#define CISST_EXPORT
Definition cmnExportMacros.h:50
#define CMN_LOG_ALLOW_DEFAULT
Definition cmnLogLoD.h:76
Rules of exporting.
Declaration of mtsInterfaceProvided.
Defines a periodic task.