cisst-saw
Loading...
Searching...
No Matches
mtsStateData.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): Peter Kazanzides
6
7 (C) Copyright 2007-2020 Johns Hopkins University (JHU), All Rights Reserved.
8
9--- begin cisst license - do not edit ---
10
11This software is provided "as is" under an open source license, with
12no warranty. The complete license can be found in license.txt and
13http://www.cisst.org/cisst/license.txt.
14
15--- end cisst license ---
16*/
17
18
23
24#ifndef _mtsStateData_h
25#define _mtsStateData_h
26
32
33// PKAZ 3/17/09: this entire class is deprecated and exists just for backward compatibility.
34//
35// This class handles the interface to the state table. Note that there are a few things mixed
36// in here that could be separated:
37//
38// 1) The class can be used for variables that just need to be set (write-only). In this case, the
39// the Id and Table fields are not used, and AddToStateTable() would not be called. It would
40// only be necessary to call AddWriteCommandToInterface(). This functionality could be moved
41// to a base class.
42//
43// 2) The reading of data from the state table does not need to use the Data field.
44//
45// Also, it would be better to have a return value for a null table pointer. In general, we
46// should rethink whether the underlying command methods (such as Get, GetLatest, Set) should
47// return void.
48
49template <class _elementType>
51protected:
54 typedef _elementType value_type;
58
59public: // PKAZ (was protected, but needed access for daVinci example)
60 void Get(const mtsStateIndex & when, value_type & data) const {
61 //if (!Table) return mtsExecutionResult::DEV_NOT_OK;
62 //return Table->ReadFromReader(Id, when, data)?mtsExecutionResult::DEV_OK:mtsExecutionResult::DEV_NOT_OK;
63 //if (Table) Table->ReadFromReader(Id, when, data);
64 if (Accessor) Accessor->Get(when, data);
65 }
66
67 void GetLatest(value_type & obj) const {
68 //if (!Table) return mtsExecutionResult::DEV_NOT_OK;
69 //return Get(Table->GetIndexReader(), obj);
70 //if (Table) Get(Table->GetIndexReader(), obj);
71 if (Accessor) Accessor->GetLatest(obj);
72 }
73
74 // Get a vector of data, starting and ending at the specified time indices (inclusive).
75 // For now, set the start index based on the vector size. In the future, we
76 // should define a new parameter type that consists of a pair of mtsStateIndex.
77 void GetHistory(const mtsStateIndex & end, mtsVector<value_type> & data) const {
78 if (data.size() > 0) {
79 //mtsStateIndex start = end;
80 //start -= (data.size()-1);
81 //if (Table) Table->ReadVectorFromReader(Id, start, end, data);
82 if (Accessor) Accessor->GetHistory(end, data);
83 }
84 }
85
86 void Set(const value_type & obj) {
87 Data = obj;
88 }
89
90public:
92
93 mtsStateData() : Id(-1), Table(0), Accessor(0) {}
95
99 inline ThisType & operator=(value_type data) {
100 Data = data;
101 return *this;
102 }
103
107 inline operator value_type & (void) {
108 return Data;
109 }
110
114 void AddToStateTable(mtsStateTable & table, const std::string & dataName = "") {
115 Table = &table;
116 Id = Table->NewElement(dataName, &Data);
117 Accessor = dynamic_cast<const AccessorType *>(table.GetAccessorByName(dataName));
118 if (!Accessor) {
119 CMN_LOG_INIT_ERROR << "mtsStateData: could not get data accessor for " << dataName << std::endl;
120 }
121 }
122
130 const std::string & commandName) {
131 interfaceProvided->AddCommandRead(&ThisType::GetLatest, this, commandName, this->Data);
132 interfaceProvided->AddCommandQualifiedRead(&ThisType::Get, this, commandName, mtsStateIndex(), this->Data);
133#ifdef CISST_GETVECTOR
134 // PK: fix the following
135 interfaceProvided->AddCommandQualifiedRead(&ThisType::GetHistory, this, commandName+"History", mtsStateIndex(), mtsVector<value_type>());
136#endif
137 }
138
142 const std::string & commandName) {
143 interfaceProvided->AddCommandWrite(&ThisType::Set, this, commandName);
144 }
145
146};
147
148
149// overload mtsObjectName to provide the class name
150template <class _elementType>
152{
153 return "mtsStateData";
154}
155
156
157#endif // _mtsStateData_h
Definition mtsInterfaceProvided.h:98
mtsCommandQualifiedRead * AddCommandQualifiedRead(void(__classType::*method)(const __argument1Type &, __argument2Type &) const, __classType *classInstantiation, const std::string &commandName, const __argument1Type &argument1Prototype, const __argument2Type &argument2Prototype)
Definition mtsInterfaceProvided.h:463
mtsCommandRead * AddCommandRead(void(__classType::*method)(__argumentType &) const, __classType *classInstantiation, const std::string &commandName, const __argumentType &argumentPrototype)
Definition mtsInterfaceProvided.h:389
mtsCommandWriteBase * AddCommandWrite(void(__classType::*method)(const __argumentType &), __classType *classInstantiation, const std::string &commandName, const __argumentType &argumentPrototype, mtsCommandQueueingPolicy queueingPolicy=MTS_INTERFACE_COMMAND_POLICY)
Definition mtsInterfaceProvided.h:330
Definition mtsStateData.h:50
void AddWriteCommandToInterface(mtsInterfaceProvided *interfaceProvided, const std::string &commandName)
Definition mtsStateData.h:141
void AddToStateTable(mtsStateTable &table, const std::string &dataName="")
Definition mtsStateData.h:114
void GetLatest(value_type &obj) const
Definition mtsStateData.h:67
~mtsStateData()
Definition mtsStateData.h:94
mtsStateData()
Definition mtsStateData.h:93
mtsStateTable::Accessor< _elementType > AccessorType
Definition mtsStateData.h:53
value_type Data
Definition mtsStateData.h:91
const AccessorType * Accessor
Definition mtsStateData.h:57
void Set(const value_type &obj)
Definition mtsStateData.h:86
void GetHistory(const mtsStateIndex &end, mtsVector< value_type > &data) const
Definition mtsStateData.h:77
void Get(const mtsStateIndex &when, value_type &data) const
Definition mtsStateData.h:60
mtsStateTable * Table
Definition mtsStateData.h:56
ThisType & operator=(value_type data)
Definition mtsStateData.h:99
mtsStateData< _elementType > ThisType
Definition mtsStateData.h:52
void AddReadCommandToInterface(mtsInterfaceProvided *interfaceProvided, const std::string &commandName)
Definition mtsStateData.h:129
mtsStateDataId Id
Definition mtsStateData.h:55
_elementType value_type
Definition mtsStateData.h:54
Definition mtsStateIndex.h:50
mtsStateIndex()
Definition mtsStateIndex.h:74
Definition mtsStateTable.h:169
bool Get(const mtsStateIndex &when, value_type &data) const
Definition mtsStateTable.h:185
bool GetLatest(value_type &data) const
Definition mtsStateTable.h:211
Definition mtsStateTable.h:67
mtsStateTable::AccessorBase * GetAccessorByName(const std::string &name) const
mtsStateDataId NewElement(const std::string &name="", _elementType *element=0)
Definition mtsStateTable.h:538
Definition mtsVector.h:32
#define CMN_LOG_INIT_ERROR
Definition cmnLogger.h:162
#define CMN_UNUSED(argument)
Definition cmnPortability.h:497
std::string mtsObjectName(const mtsComponent *object)
Definition mtsComponent.h:588
Declaration of mtsInterfaceProvided.
Defines the state data table.
int mtsStateDataId
Definition mtsStateTable.h:52
Defines a periodic task.
const_iterator end(void) const
Definition vctDynamicConstMatrixBase.h:209