Client.h
Go to the documentation of this file.
1#pragma once
2
3#include <vector>
4
5#include "Interaction.h"
6#include "Layer.h"
7
8namespace armarx
9{
10 class Component;
11 class ManagedIceObject;
12
13 namespace viz
14 {
15 /**
16 * A staged commit prepares multiple layers to be committed.
17 *
18 * Add all relevant layer updates via .add(layer).
19 * Add layers for which you want interaction feedback via .requestInteraction(layer).
20 * Then, commit via client.apply(stagedCommit).
21 *
22 * A staged commit can be reused for subsequent commits.
23 * Remember to call .reset() to clear the internal data structures.
24 *
25 * As long as you keep the staged commits separate, this method is thread-safe.
26 * So you can have two threads calling .commit(A) and .commit(B)
27 * simultaneously without any locking mechanism.
28 */
30 {
31 /**
32 * @brief Stage a layer to be committed later via client.apply(*this)
33 * @param layer The layer to be added to this staged commit.
34 */
35 void
36 add(Layer const& layer)
37 {
38 data_.updates.push_back(layer.data_);
39 }
40
41 void
42 add(std::initializer_list<Layer> layers)
43 {
44 data_.updates.reserve(data_.updates.size() + layers.size());
45 for (Layer const& layer : layers)
46 {
47 data_.updates.push_back(layer.data_);
48 }
49 }
50
51 /**
52 * @brief Request interaction feedback for a particular layer.
53 * @param layer The layer you want to get interaction feedback for.
54 */
55 void
57 {
58 data_.interactionComponent = layer.data_.component;
59 data_.interactionLayers.push_back(layer.data_.name);
60 }
61
62 /**
63 * @brief Reset all staged layers and interaction requests.
64 */
65 void
67 {
68 data_.updates.clear();
69 data_.interactionComponent.clear();
70 data_.interactionLayers.clear();
71 }
72
73 viz::data::CommitInput data_;
74 };
75
77 {
78 long
79 revision() const
80 {
81 return data_.revision;
82 }
83
86 {
87 const InteractionFeedback* begin =
88 reinterpret_cast<const InteractionFeedback*>(data_.interactions.data());
89 const InteractionFeedback* end = begin + data_.interactions.size();
90 return InteractionFeedbackRange{begin, end};
91 }
92
93 data::CommitResult data_;
94 };
95
97 {
98 bool
100 {
101 return async && async->isCompleted();
102 }
103
106 {
107 CommitResult result;
108 result.data_ = storage->end_commitAndReceiveInteractions(async);
109 return result;
110 }
111
112 Ice::AsyncResultPtr async;
113 armarx::viz::StorageInterfacePrx storage;
114 };
115
116 class Client
117 {
118 public:
119 Client() = default;
120 Client(const Client&) = default;
121
123 std::string const& topicNameProperty = "ArVizTopicName",
124 std::string const& storageNameProperty = "ArVizStorageName");
125
127 std::string const& topicName = "ArVizTopic",
128 std::string const& storageName = "ArVizStorage");
129
130 virtual ~Client() = default;
131 static Client createFromTopic(std::string const& componentName,
132 armarx::viz::Topic::ProxyType const& topic);
133
134 static Client
135 createFromProxies(std::string const& componentName,
136 armarx::viz::Topic::ProxyType const& topic,
137 armarx::viz::StorageAndTopicInterfacePrx const& storage);
138
140 std::string const& topicName = "ArVizTopic",
141 std::string const& storageName = "ArVizStorage");
142
143 virtual Layer layer(std::string const& name) const;
144
147 {
148 return StagedCommit();
149 }
150
152
154
155 void
157 {
158 std::vector<Layer> layers;
159 layers.push_back(layer);
160 commit(layers);
161 }
162
163 void commit(std::vector<Layer> const& layers);
164
165 void
166 commitLayerContaining(std::string const& name)
167 {
168 std::vector<viz::Layer> layers;
169 layers.push_back(this->layer(name));
170 commit(layers);
171 }
172
173 template <typename ElementT>
174 void
175 commitLayerContaining(std::string const& name, ElementT const& element)
176 {
177 std::vector<viz::Layer> layers;
178 viz::Layer& newLayer = layers.emplace_back(this->layer(name));
179 newLayer.add(element);
180 commit(layers);
181 }
182
183 void
184 commitDeleteLayer(std::string const& name)
185 {
186 std::vector<viz::Layer> layers;
187 viz::Layer& layerToDelete = layers.emplace_back(this->layer(name));
188 layerToDelete.markForDeletion();
189 commit(layers);
190 }
191
192 void
193 updateComponentName(std::string const& name)
194 {
195 this->componentName = name;
196 }
197
198 private:
199 std::string componentName;
200 armarx::viz::StorageInterfacePrx storage;
201 armarx::viz::TopicPrx topic;
202 };
203
204 } // namespace viz
205} // namespace armarx
Baseclass for all ArmarX ManagedIceObjects requiring properties.
Definition Component.h:94
The ManagedIceObject is the base class for all ArmarX objects.
void updateComponentName(std::string const &name)
Definition Client.h:193
static Client createFromProxies(std::string const &componentName, armarx::viz::Topic::ProxyType const &topic, armarx::viz::StorageAndTopicInterfacePrx const &storage)
Definition Client.cpp:50
void commitDeleteLayer(std::string const &name)
Definition Client.h:184
virtual Layer layer(std::string const &name) const
Definition Client.cpp:80
StagedCommit stage()
Definition Client.h:146
void commitLayerContaining(std::string const &name, ElementT const &element)
Definition Client.h:175
CommitResult commit(StagedCommit const &commit)
Definition Client.cpp:89
CommitResultAsync commitAsync(StagedCommit const &commit)
Definition Client.cpp:99
void commit(Layer const &layer)
Definition Client.h:156
static Client createForGuiPlugin(armarx::Component &component, std::string const &topicName="ArVizTopic", std::string const &storageName="ArVizStorage")
Definition Client.cpp:62
void commitLayerContaining(std::string const &name)
Definition Client.h:166
Client(const Client &)=default
virtual ~Client()=default
static Client createFromTopic(std::string const &componentName, armarx::viz::Topic::ProxyType const &topic)
Definition Client.cpp:40
This file is part of ArmarX.
This file offers overloads of toIce() and fromIce() functions for STL container types.
Ice::AsyncResultPtr async
Definition Client.h:112
armarx::viz::StorageInterfacePrx storage
Definition Client.h:113
CommitResult waitAndGet() const
Definition Client.h:105
long revision() const
Definition Client.h:79
data::CommitResult data_
Definition Client.h:93
InteractionFeedbackRange interactions() const
Definition Client.h:85
void markForDeletion()
Definition Layer.h:46
data::LayerUpdate data_
Definition Layer.h:57
void add(ElementT const &element)
Definition Layer.h:31
A staged commit prepares multiple layers to be committed.
Definition Client.h:30
void requestInteraction(Layer const &layer)
Request interaction feedback for a particular layer.
Definition Client.h:56
void add(Layer const &layer)
Stage a layer to be committed later via client.apply(*this)
Definition Client.h:36
void add(std::initializer_list< Layer > layers)
Definition Client.h:42
viz::data::CommitInput data_
Definition Client.h:73
void reset()
Reset all staged layers and interaction requests.
Definition Client.h:66