Client.cpp
Go to the documentation of this file.
1 #include "Client.h"
2 
4 
5 namespace 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
119  ARMARX_CHECK_NOT_NULL(topic);
120  topic->updateLayers(updates);
121  }
122 
123 
124 } // namespace armarx::viz
Client.h
armarx::viz::Client::commit
CommitResult commit(StagedCommit const &commit)
Definition: Client.cpp:89
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:50
armarx::viz::Client::commitAsync
CommitResultAsync commitAsync(StagedCommit const &commit)
Definition: Client.cpp:99
armarx::ProxyType::component
@ component
armarx::viz::Client::createFromTopic
static Client createFromTopic(std::string const &componentName, armarx::viz::Topic::ProxyType const &topic)
Definition: Client.cpp:40
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:97
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:30
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:62
armarx::viz::Layer::data_
data::LayerUpdate data_
Definition: Layer.h:57
armarx::ProxyType::topic
@ topic
armarx::viz::CommitResultAsync::storage
armarx::viz::StorageInterfacePrx storage
Definition: Client.h:114
armarx::ProxyType
ProxyType
Definition: ProxyPropertyDefinition.h:40
armarx::viz::CommitResult
Definition: Client.h:77
Component.h
armarx::Component
Baseclass for all ArmarX ManagedIceObjects requiring properties.
Definition: Component.h:91
armarx::ManagedIceObject
The ManagedIceObject is the base class for all ArmarX objects.
Definition: ManagedIceObject.h:162
armarx::ManagedIceObject::getTopic
TopicProxyType getTopic(const std::string &name)
Returns a proxy of the specified topic.
Definition: ManagedIceObject.h:480
armarx::ManagedIceObject::getName
std::string getName() const
Retrieve name of object.
Definition: ManagedIceObject.cpp:108
armarx::viz::CommitResult::data_
data::CommitResult data_
Definition: Client.h:94
armarx::viz::Client::layer
Layer layer(std::string const &name) const
Definition: Client.cpp:80
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:407
armarx::viz::Client
Definition: Client.h:117
armarx::viz::Layer
Definition: Layer.h:12
armarx::viz
This file is part of ArmarX.
Definition: ArVizStorage.cpp:418
armarx::viz::CommitResultAsync::async
Ice::AsyncResultPtr async
Definition: Client.h:113