Client.cpp
Go to the documentation of this file.
1#include "Client.h"
2
4
5namespace armarx::viz
6{
7
9 std::string const& topicNameProperty,
10 std::string const& storageNameProperty)
11 {
12 componentName = component.getName();
13 component.getTopicFromProperty(topic, topicNameProperty);
14
15 // Optional dependency on ArVizStorage
16 std::string storageName;
17 if (component.hasProperty(storageNameProperty))
18 {
19 storageName = component.getProperty<std::string>(storageNameProperty);
20 }
21 else
22 {
23 storageName = "ArVizStorage";
24 }
25 component.getProxy(storage, storageName);
26 }
27
29 std::string const& topicName,
30 std::string const& storageName)
31 {
32 componentName = obj.getName();
33 ARMARX_CHECK_NOT_EMPTY(componentName)
34 << "ArViz client must be created with non-empty component name.";
35 obj.getTopic(topic, topicName);
36 obj.getProxy(storage, storageName);
37 }
38
39 Client
40 Client::createFromTopic(std::string const& componentName, Topic::ProxyType const& topic)
41 {
42 Client client;
43 ARMARX_CHECK_NOT_EMPTY(componentName);
44 client.componentName = componentName;
45 client.topic = topic;
46 return client;
47 }
48
49 Client
50 Client::createFromProxies(std::string const& componentName,
51 Topic::ProxyType const& topic,
52 StorageAndTopicInterfacePrx const& storage)
53 {
54 Client client;
55 client.componentName = componentName;
56 client.topic = topic;
57 client.storage = storage;
58 return client;
59 }
60
61 Client
63 std::string const& topicName,
64 std::string const& storageName)
65 {
66 Client client;
67 std::string name = component.getName();
68 std::size_t dashPos = name.find('-');
69 if (dashPos != std::string::npos)
70 {
71 name = name.substr(0, dashPos);
72 }
73 client.componentName = name;
74 component.getTopic(client.topic, topicName);
75 component.getProxy(client.storage, storageName);
76 return client;
77 }
78
79 Layer
80 Client::layer(const std::string& name) const
81 {
82 ARMARX_CHECK_NOT_EMPTY(componentName)
83 << "Layers must be created with non-empty component name.";
84 ARMARX_CHECK_NOT_EMPTY(name) << "Layers must be created with non-empty layer name.";
85 return Layer(componentName, name);
86 }
87
90 {
91 CommitResult result;
92
93 ARMARX_CHECK_NOT_NULL(storage);
94 result.data_ = storage->commitAndReceiveInteractions(commit.data_);
95 return result;
96 }
97
100 {
101 CommitResultAsync result;
102
103 ARMARX_CHECK_NOT_NULL(storage);
104 result.async = storage->begin_commitAndReceiveInteractions(commit.data_);
105 result.storage = storage;
106 return result;
107 }
108
109 void
110 Client::commit(const std::vector<Layer>& layers)
111 {
112 data::LayerUpdateSeq updates;
113 updates.reserve(layers.size());
114 for (Layer const& layer : layers)
115 {
116 updates.push_back(layer.data_);
117 }
118 // This commit call still uses the legacy topic API
120 topic->updateLayers(updates);
121 }
123
124} // namespace armarx::viz
#define ARMARX_CHECK_NOT_EMPTY(c)
Baseclass for all ArmarX ManagedIceObjects requiring properties.
Definition Component.h:94
The ManagedIceObject is the base class for all ArmarX objects.
TopicProxyType getTopic(const std::string &name)
Returns a proxy of the specified topic.
std::string getName() const
Retrieve name of object.
Ice::ObjectPrx getProxy(long timeoutMs=0, bool waitForScheduler=true) const
Returns the proxy of this object (optionally it waits for the proxy)
static Client createFromProxies(std::string const &componentName, armarx::viz::Topic::ProxyType const &topic, armarx::viz::StorageAndTopicInterfacePrx const &storage)
Definition Client.cpp:50
virtual Layer layer(std::string const &name) const
Definition Client.cpp:80
CommitResult commit(StagedCommit const &commit)
Definition Client.cpp:89
CommitResultAsync commitAsync(StagedCommit const &commit)
Definition Client.cpp:99
static Client createForGuiPlugin(armarx::Component &component, std::string const &topicName="ArVizTopic", std::string const &storageName="ArVizStorage")
Definition Client.cpp:62
static Client createFromTopic(std::string const &componentName, armarx::viz::Topic::ProxyType const &topic)
Definition Client.cpp:40
#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...
This file is part of ArmarX.
Ice::AsyncResultPtr async
Definition Client.h:112
armarx::viz::StorageInterfacePrx storage
Definition Client.h:113
data::CommitResult data_
Definition Client.h:93
A staged commit prepares multiple layers to be committed.
Definition Client.h:30