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