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
29namespace armarx::detail
30{
31 std::string
32 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} // namespace armarx::detail
45
46namespace armarx
47{
48
49 void
51 {
53 _float_fallback_for_big_too_large_ints = useFallback;
54 }
55
56 DebugObserverHelper::DebugObserverHelper::DebugObserverHelper(
58 bool batchmode) :
59 _observer{prx}, _batchMode{batchmode}
60 {
61 }
62
63 void
65 {
67 _batchMode = enable;
68 }
69
70 void
72 {
74 ARMARX_CHECK_NOT_NULL(_observer);
75 for (const auto& [chname, data] : _batch)
76 {
77 _observer->setDebugChannel(chname, data);
78 }
79 _batch.clear();
80 }
81
82 void
83 DebugObserverHelper::setDebugObserverDatafield(const std::string& channelName,
84 const std::string& datafieldName,
85 const TimedVariantPtr& value) const
86 {
89 const auto fixedChName = detail::fix_channel_name(channelName);
90 if (_batchMode)
91 {
92 _batch[fixedChName][datafieldName] = value;
93 }
94 else
95 {
96 ARMARX_CHECK_NOT_NULL(_observer);
97 _observer->setDebugDatafield(fixedChName, datafieldName, value);
98 }
99 }
100
101 void
103 const std::string& datafieldName,
104 const VariantPtr& value) const
105 {
107 const auto fixedChName = detail::fix_channel_name(channelName);
108 setDebugObserverDatafield(fixedChName, datafieldName, IceUtil::Time::now(), value);
109 }
110
111 void
113 const std::string& datafieldName,
114 const VariantBasePtr& value) const
115 {
117 const auto fixedChName = detail::fix_channel_name(channelName);
119 if (const auto ptr = TimedVariantPtr::dynamicCast(value); ptr)
120 {
121 setDebugObserverDatafield(fixedChName, datafieldName, ptr);
122 }
123 const auto ptr = VariantPtr::dynamicCast(value);
124 ARMARX_CHECK_NOT_NULL(ptr) << "not derived from Variant";
125 setDebugObserverDatafield(fixedChName, datafieldName, ptr);
126 }
127
128 void
130 const std::string& datafieldName,
131 const IceUtil::Time& time,
132 const VariantPtr& value) const
133 {
136 datafieldName,
137 TimedVariantPtr{new TimedVariant(value, time)});
138 }
139
140 void
142 const std::string& datafieldName,
143 const IceUtil::Time& time,
144 const Variant& value) const
145 {
148 datafieldName,
149 TimedVariantPtr{new TimedVariant(value, time)});
150 }
151
152 void
153 DebugObserverHelper::setDebugObserverChannel(const std::string& channelName,
154 StringVariantBaseMap valueMap) const
155 {
157 ARMARX_CHECK_NOT_NULL(_observer);
158 _observer->setDebugChannel(detail::fix_channel_name(channelName), valueMap);
159 }
160
161 void
162 DebugObserverHelper::removeDebugObserverChannel(const std::string& channelname) const
163 {
165 ARMARX_CHECK_NOT_NULL(_observer);
166 _observer->removeDebugChannel(detail::fix_channel_name(channelname));
167 }
168
169 void
171 const std::string& datafieldName) const
172 {
174 ARMARX_CHECK_NOT_NULL(_observer);
175 _observer->removeDebugDatafield(detail::fix_channel_name(channelName), datafieldName);
176 }
177
178 void
180 {
182 ARMARX_CHECK_NOT_NULL(_observer);
183 _observer->removeAllChannels();
184 }
185
188 {
190 return _observer;
191 }
192
193 void
195 {
197 _observer = prx;
198 }
199
200 const std::string&
202 {
204 return _channelName;
205 }
206
207 void
208 DebugObserverHelper::setChannelName(const std::string& name)
209 {
211 _channelName = name;
212 }
213
214 void
220
221 void
228
229 void
235
236 void
243} // namespace armarx
constexpr T c
void setDebugObserverDatafield(const std::string &channelName, const std::string &datafieldName, const TimedVariantPtr &value) const
void setDebugObserverChannel(const std::string &channelName, StringVariantBaseMap valueMap) const
void removeDebugObserverDatafield(const std::string &channelName, const std::string &datafieldName) const
void setChannelName(const std::string &name)
const DebugObserverInterfacePrx & getDebugObserver() const
void removeDebugObserverChannel(const std::string &channelname) const
void setDebugObserver(const DebugObserverInterfacePrx &prx)
void setDebugObserverBatchModeEnabled(bool enable)
void setFloatFallbackForBigTooLargeInts(bool useFallback)
const std::string & getChannelName() const
The ManagedIceObject is the base class for all ArmarX objects.
std::string getName() const
Retrieve name of object.
The Variant class is described here: Variants.
Definition Variant.h:224
#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...
std::string fix_channel_name(const std::string &channelName)
This file offers overloads of toIce() and fromIce() functions for STL container types.
::IceInternal::ProxyHandle<::IceProxy::armarx::DebugObserverInterface > DebugObserverInterfacePrx
std::map< std::string, VariantBasePtr > StringVariantBaseMap
IceInternal::Handle< TimedVariant > TimedVariantPtr
IceInternal::Handle< Variant > VariantPtr
Definition Variant.h:41
::IceInternal::Handle<::armarx::VariantBase > VariantBasePtr
#define ARMARX_TRACE
Definition trace.h:77