DebugObserverHelper.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * ArmarX is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * ArmarX is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * @package ArmarXCore::ArmarXObjects::DebugObserverHelper
17  * @author Raphael Grimm ( raphael dot grimm at kit dot edu )
18  * @date 2021
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
23 
24 #include "DebugObserverHelper.h"
25 
28 
29 
30 namespace armarx::detail
31 {
32  std::string fix_channel_name(const std::string& channelName)
33  {
34  std::string result = channelName;
35  for (auto& c : result)
36  {
37  if (c == '.')
38  {
39  c = '_';
40  }
41  }
42  return result;
43  }
44 }
45 
46 namespace armarx
47 {
48 
50  {
52  _float_fallback_for_big_too_large_ints = useFallback;
53  }
54  DebugObserverHelper::DebugObserverHelper::DebugObserverHelper(const DebugObserverInterfacePrx& prx, bool batchmode) :
55  _observer{prx}, _batchMode{batchmode}
56  {}
57 
59  {
61  _batchMode = enable;
62  }
64  {
66  ARMARX_CHECK_NOT_NULL(_observer);
67  for (const auto& [chname, data] : _batch)
68  {
69  _observer->setDebugChannel(chname, data);
70  }
71  _batch.clear();
72  }
73 
74  void DebugObserverHelper::setDebugObserverDatafield(const std::string& channelName, const std::string& datafieldName, const TimedVariantPtr& value) const
75  {
78  const auto fixedChName = detail::fix_channel_name(channelName);
79  if (_batchMode)
80  {
81  _batch[fixedChName][datafieldName] = value;
82  }
83  else
84  {
85  ARMARX_CHECK_NOT_NULL(_observer);
86  _observer->setDebugDatafield(fixedChName, datafieldName, value);
87  }
88  }
89  void DebugObserverHelper::setDebugObserverDatafield(const std::string& channelName, const std::string& datafieldName, const VariantPtr& value) const
90  {
92  const auto fixedChName = detail::fix_channel_name(channelName);
93  setDebugObserverDatafield(fixedChName, datafieldName, IceUtil::Time::now(), value);
94  }
95  void DebugObserverHelper::setDebugObserverDatafield(const std::string& channelName, const std::string& datafieldName, const VariantBasePtr& value) const
96  {
98  const auto fixedChName = detail::fix_channel_name(channelName);
100  if (const auto ptr = TimedVariantPtr::dynamicCast(value); ptr)
101  {
102  setDebugObserverDatafield(fixedChName, datafieldName, ptr);
103  }
104  const auto ptr = VariantPtr::dynamicCast(value);
105  ARMARX_CHECK_NOT_NULL(ptr) << "not derived from Variant";
106  setDebugObserverDatafield(fixedChName, datafieldName, ptr);
107  }
108 
109  void DebugObserverHelper::setDebugObserverDatafield(const std::string& channelName, const std::string& datafieldName, const IceUtil::Time& time, const VariantPtr& value) const
110  {
111  ARMARX_TRACE;
112  setDebugObserverDatafield(detail::fix_channel_name(channelName), datafieldName, TimedVariantPtr{new TimedVariant(value, time)});
113  }
114  void DebugObserverHelper::setDebugObserverDatafield(const std::string& channelName, const std::string& datafieldName, const IceUtil::Time& time, const Variant& value) const
115  {
116  ARMARX_TRACE;
117  setDebugObserverDatafield(detail::fix_channel_name(channelName), datafieldName, TimedVariantPtr{new TimedVariant(value, time)});
118  }
119 
120 
121  void DebugObserverHelper::setDebugObserverChannel(const std::string& channelName, StringVariantBaseMap valueMap) const
122  {
123  ARMARX_TRACE;
124  ARMARX_CHECK_NOT_NULL(_observer);
125  _observer->setDebugChannel(detail::fix_channel_name(channelName), valueMap);
126  }
127 
128  void DebugObserverHelper::removeDebugObserverChannel(const std::string& channelname) const
129  {
130  ARMARX_TRACE;
131  ARMARX_CHECK_NOT_NULL(_observer);
132  _observer->removeDebugChannel(detail::fix_channel_name(channelname));
133  }
134 
135  void DebugObserverHelper::removeDebugObserverDatafield(const std::string& channelName, const std::string& datafieldName) const
136  {
137  ARMARX_TRACE;
138  ARMARX_CHECK_NOT_NULL(_observer);
139  _observer->removeDebugDatafield(detail::fix_channel_name(channelName), datafieldName);
140  }
141 
143  {
144  ARMARX_TRACE;
145  ARMARX_CHECK_NOT_NULL(_observer);
146  _observer->removeAllChannels();
147  }
148 
150  {
151  ARMARX_TRACE;
152  return _observer;
153  }
155  {
156  ARMARX_TRACE;
157  _observer = prx;
158  }
159 
160  const std::string& DebugObserverHelper::getChannelName() const
161  {
162  ARMARX_TRACE;
163  return _channelName;
164  }
165 
166  void DebugObserverHelper::setChannelName(const std::string& name)
167  {
168  ARMARX_TRACE;
169  _channelName = name;
170  }
171 
173  {
174  ARMARX_TRACE;
175  setChannelName(obj.getName());
176  }
177 
179  {
180  ARMARX_TRACE;
182  setChannelName(*obj);
183  }
184 
186  {
187  ARMARX_TRACE;
188  setChannelName(obj.parent());
189  }
190 
192  {
193  ARMARX_TRACE;
195  setChannelName(*obj);
196  }
197 }
armarx::Variant
The Variant class is described here: Variants.
Definition: Variant.h:224
armarx::StringVariantBaseMap
std::map< std::string, VariantBasePtr > StringVariantBaseMap
Definition: ManagedIceObject.h:111
armarx::detail::fix_channel_name
std::string fix_channel_name(const std::string &channelName)
Definition: DebugObserverHelper.cpp:32
armarx::ManagedIceObjectPlugin::parent
ManagedIceObject & parent()
Definition: ManagedIceObjectPlugin.cpp:69
ARMARX_CHECK_NOT_NULL
#define ARMARX_CHECK_NOT_NULL(ptr)
This macro evaluates whether ptr is not null and if it turns out to be false it will throw an Express...
Definition: ExpressionException.h:206
armarx::DebugObserverHelper::sendDebugObserverBatch
void sendDebugObserverBatch()
Definition: DebugObserverHelper.cpp:63
armarx::DebugObserverHelper::removeDebugObserverDatafield
void removeDebugObserverDatafield(const std::string &channelName, const std::string &datafieldName) const
Definition: DebugObserverHelper.cpp:135
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
armarx::DebugObserverHelper::setDebugObserverBatchModeEnabled
void setDebugObserverBatchModeEnabled(bool enable)
Definition: DebugObserverHelper.cpp:58
IceInternal::Handle
Definition: forward_declarations.h:8
armarx::DebugObserverHelper::getChannelName
const std::string & getChannelName() const
Definition: DebugObserverHelper.cpp:160
ARMARX_TRACE
#define ARMARX_TRACE
Definition: trace.h:69
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
armarx::DebugObserverHelper::getDebugObserver
const DebugObserverInterfacePrx & getDebugObserver() const
Definition: DebugObserverHelper.cpp:149
ManagedIceObject.h
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
armarx::DebugObserverHelper::setChannelName
void setChannelName(const std::string &name)
Definition: DebugObserverHelper.cpp:166
armarx::detail
Definition: ApplicationNetworkStats.cpp:34
armarx::DebugObserverHelper::removeDebugObserverChannel
void removeDebugObserverChannel(const std::string &channelname) const
Definition: DebugObserverHelper.cpp:128
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
ExpressionException.h
DebugObserverHelper.h
armarx::ManagedIceObject
The ManagedIceObject is the base class for all ArmarX objects.
Definition: ManagedIceObject.h:163
armarx::DebugObserverHelper::setDebugObserverDatafield
void setDebugObserverDatafield(const std::string &channelName, const std::string &datafieldName, const TimedVariantPtr &value) const
Definition: DebugObserverHelper.cpp:74
armarx::DebugObserverHelper::setDebugObserver
void setDebugObserver(const DebugObserverInterfacePrx &prx)
Definition: DebugObserverHelper.cpp:154
IceInternal::ProxyHandle<::IceProxy::armarx::DebugObserverInterface >
armarx::DebugObserverHelper::setFloatFallbackForBigTooLargeInts
void setFloatFallbackForBigTooLargeInts(bool useFallback)
Definition: DebugObserverHelper.cpp:49
armarx::ManagedIceObject::getName
std::string getName() const
Retrieve name of object.
Definition: ManagedIceObject.cpp:107
armarx::ManagedIceObjectPlugin
Definition: ManagedIceObjectPlugin.h:50
armarx::DebugObserverHelper::removeAllDebugObserverChannels
void removeAllDebugObserverChannels() const
Definition: DebugObserverHelper.cpp:142
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::TimedVariant
Definition: TimedVariant.h:40
armarx::DebugObserverHelper::setDebugObserverChannel
void setDebugObserverChannel(const std::string &channelName, StringVariantBaseMap valueMap) const
Definition: DebugObserverHelper.cpp:121