ExampleMemoryClient.h
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 RobotAPI::ArmarXObjects::ExampleClient
17  * @author Rainer Kartmann ( rainer dot kartmann at kit dot edu )
18  * @date 2020
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
23 
24 #pragma once
25 
30 #include <RobotAPI/interface/armem/mns/MemoryNameSystemInterface.h>
31 
33 
35 #include <ArmarXCore/interface/observers/ObserverInterface.h>
36 #include <ArmarXCore/util/tasks.h>
37 
38 
39 namespace armarx
40 {
41 
42  /**
43  * @defgroup Component-ExampleClient ExampleClient
44  * @ingroup RobotAPI-Components
45  *
46  * An example for an ArMem Memory Client.
47  *
48  * @class ExampleClient
49  * @ingroup Component-ExampleClient
50  * @brief Brief description of class ExampleClient.
51  *
52  * Connects to the example memory, and commits and queries example data.
53  */
55  virtual public armarx::Component,
58  {
59  public:
60 
61  /// @see armarx::ManagedIceObject::getDefaultName()
62  std::string getDefaultName() const override;
63 
64 
65  // LightweightRemoteGuiComponentPluginUser interface
66  public:
67  void createRemoteGuiTab();
68  void RemoteGui_update() override;
69 
70 
71  protected:
72 
74 
75  void onInitComponent() override;
76  void onConnectComponent() override;
77  void onDisconnectComponent() override;
78  void onExitComponent() override;
79 
80  void run();
81 
82 
83  private:
84 
85  // Callback for updates on `example_entity`.
86  void processExampleEntityUpdate(const armem::MemoryID& id, const std::vector<armem::MemoryID>& snapshotIDs);
87 
88  // Examples
89  void waitForMemory();
90  armem::MemoryID addProviderSegment();
91 
92  armem::MemoryID commitSingleSnapshot(const armem::MemoryID& exampleEntityID);
93  void commitMultipleSnapshots(const armem::MemoryID& exampleEntityID, int num = 3);
94 
95  void queryLatestSnapshot(const armem::MemoryID& exampleEntityID);
96  void queryExactSnapshot(const armem::MemoryID& snapshotID);
97 
98  void commitExampleData();
99  void queryExampleData();
100 
101  void commitExamplesWithIDs();
102  void commitExamplesWithLinks();
103 
104  void commitExampleImages();
105  void commitExamplesWithUntypedData();
106 
107  void queryPredictionEngines();
108 
109 
110  private:
111 
112  struct Properties
113  {
114  std::string usedMemoryName = "Example";
115  float commitFrequency = 10;
116  };
117  Properties p;
118 
119  armem::client::Reader memoryReader;
120  armem::client::Writer memoryWriter;
121 
122  armem::MemoryID exampleProviderID;
123  armem::MemoryID exampleEntityID;
124 
125  armem::MemoryID exampleDataProviderID;
126  armem::MemoryID theAnswerSnapshotID;
127  armem::MemoryID linkedDataProviderID;
128  armem::MemoryID yetMoreDataSnapshotID;
129 
130 
131  armem::Time runStarted;
132  unsigned int imageCounter = 0;
133 
135 
136  armarx::DebugObserverInterfacePrx debugObserver;
137 
138  struct RemoteGuiTab : RemoteGui::Client::Tab
139  {
140  std::atomic_bool rebuild = false;
141 
142  std::optional<armem::wm::Memory> queryResult;
143  RemoteGui::Client::GroupBox queryResultGroup;
144  };
145  RemoteGuiTab tab;
146  };
147 }
armarx::armem::client::Reader
Reads data from a memory server.
Definition: Reader.h:24
Reader.h
Writer.h
armarx::RemoteGui::Client::Tab
Definition: Tab.h:15
armarx::ExampleMemoryClient::onConnectComponent
void onConnectComponent() override
Pure virtual hook for the subclass.
Definition: ExampleMemoryClient.cpp:84
armarx::ExampleMemoryClient::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: ExampleMemoryClient.cpp:57
armarx::ExampleMemoryClient::onInitComponent
void onInitComponent() override
Pure virtual hook for the subclass.
Definition: ExampleMemoryClient.cpp:79
LightweightRemoteGuiComponentPlugin.h
armarx::ExampleMemoryClient
Definition: ExampleMemoryClient.h:54
armarx::armem::MemoryID
A memory ID.
Definition: MemoryID.h:47
armarx::ExampleMemoryClient::createRemoteGuiTab
void createRemoteGuiTab()
Definition: ExampleMemoryClient.cpp:788
armarx::ExampleMemoryClient::onDisconnectComponent
void onDisconnectComponent() override
Hook for subclass.
Definition: ExampleMemoryClient.cpp:130
armarx::RemoteGui::Client::GroupBox
Definition: Widgets.h:193
armarx::armem::client::Writer
Helps a memory client sending data to a memory.
Definition: Writer.h:22
armarx::LightweightRemoteGuiComponentPluginUser
Definition: LightweightRemoteGuiComponentPlugin.h:73
tasks.h
Component.h
memory_definitions.h
armarx::Component
Baseclass for all ArmarX ManagedIceObjects requiring properties.
Definition: Component.h:95
armarx::core::time::DateTime
Represents a point in time.
Definition: DateTime.h:24
armarx::ExampleMemoryClient::onExitComponent
void onExitComponent() override
Hook for subclass.
Definition: ExampleMemoryClient.cpp:136
IceUtil::Handle< class PropertyDefinitionContainer >
IceInternal::ProxyHandle<::IceProxy::armarx::DebugObserverInterface >
armarx::ExampleMemoryClient::getDefaultName
std::string getDefaultName() const override
Definition: ExampleMemoryClient.cpp:73
armarx::armem::client::plugins::ListeningPluginUser
A memory name system client which listens to the memory updates topic (MemoryListenerInterface).
Definition: ListeningPluginUser.h:23
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::ExampleMemoryClient::run
void run()
Definition: ExampleMemoryClient.cpp:141
ListeningPluginUser.h
armarx::ExampleMemoryClient::RemoteGui_update
void RemoteGui_update() override
Definition: ExampleMemoryClient.cpp:801