ComponentPlugin.cpp
Go to the documentation of this file.
1 #include <memory>
2 #include <string>
3 
9 
12 
18 
19 // ComponentPlugin
20 
22 {
23 
25 
26  void
28  {
29  if (not properties->hasDefinition(PROPERTY_NAME))
30  {
31  properties->defineOptionalProperty<std::string>(
32  PROPERTY_NAME, "navigator", "Name of the Navigator");
33  }
34  }
35 
36  void
38  {
40  parent<armarx::Component>().usingProxyFromProperty(PROPERTY_NAME);
41  }
42 
43  void
45  {
47  parent<armarx::Component>().getProxyFromProperty(navigatorPrx, PROPERTY_NAME);
48 
50  const std::string componentName = parent().getName();
51 
52  ARMARX_CHECK_NOT_NULL(navigatorPrx) << "Navigator proxy is null!";
53  iceNavigator.setNavigatorComponent(navigatorPrx);
54  }
55 
56  void
58  const std::string& configId)
59  {
61 
62  // ARMARX_CHECK_NULL(eventHandler) << "`configureNavigator()` can only be called once!";
63 
64  eventHandler = [&]() -> std::unique_ptr<SimpleEventHandler>
65  {
67  if (parentDerives<armarx::armem::client::plugins::ListeningPluginUser>())
68  {
70  ARMARX_INFO << "Using memory event callbacks.";
71  // must(!!) use a reference here: otherwise the mns events won't work
72  auto& memoryNameSystem =
73  parent<armarx::armem::client::plugins::ListeningPluginUser>()
74  .memoryNameSystem();
75  return std::make_unique<MemorySubscriber>(configId, memoryNameSystem);
76  }
77 
79  << "Cannot use memory event callbacks as this component is not derived from "
80  "`armarx::armem::client::plugins::ListeningPluginUser`";
81 
82  return std::make_unique<SimpleEventHandler>();
83  }();
84 
85  iceNavigator.createConfig(stackConfig, configId);
86 
87  navigator = std::make_unique<Navigator>(Navigator::InjectedServices{
88  .navigator = &iceNavigator, .subscriber = eventHandler.get()});
89  }
90 
91  // ComponentPluginUser
92 
94  {
96  addPlugin(plugin);
97  }
98 
99  void
101  {
102  ARMARX_TRACE;
103  plugin->configureNavigator(stackConfig, getName());
104  }
105 
106  Navigator&
108  {
110  << "You need to call `configureNavigator()` before you can access the navigator!";
111  return *plugin->navigator;
112  }
113 
115 
116 } // namespace armarx::navigation::client
armarx::navigation::client::IceNavigator::setNavigatorComponent
void setNavigatorComponent(const NavigatorInterfacePrx &navigator)
Definition: IceNavigator.cpp:46
Navigator.h
armarx::navigation::client::Navigator
Definition: Navigator.h:116
armarx::navigation::client::ComponentPlugin::configureNavigator
void configureNavigator(const client::NavigationStackConfig &stackConfig, const std::string &configId)
Definition: ComponentPlugin.cpp:57
armarx::navigation::client::Navigator::InjectedServices
Definition: Navigator.h:120
armarx::ManagedIceObjectPlugin::parent
ManagedIceObject & parent()
Definition: ManagedIceObjectPlugin.cpp:72
armarx::navigation::client::ComponentPlugin::~ComponentPlugin
~ComponentPlugin() override
armarx::navigation::client::ComponentPluginUser::getNavigator
Navigator & getNavigator()
Definition: ComponentPlugin.cpp:107
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
trace.h
armarx::ManagedIceObject::addPlugin
PluginT * addPlugin(const std::string prefix="", ParamsT &&... params)
Definition: ManagedIceObject.h:186
armarx::navigation::client
This file is part of ArmarX.
Definition: ComponentPlugin.cpp:21
armarx::navigation::client::ComponentPluginUser::~ComponentPluginUser
~ComponentPluginUser() override
armarx::navigation::client::NavigationStackConfig
Definition: NavigationStackConfig.h:49
armarx::navigation::client::Navigator::InjectedServices::navigator
core::NavigatorInterface * navigator
Definition: Navigator.h:122
armarx::navigation::client::ComponentPluginUser::configureNavigator
void configureNavigator(const client::NavigationStackConfig &stackConfig)
Definition: ComponentPlugin.cpp:100
MemorySubscriber.h
ARMARX_TRACE
#define ARMARX_TRACE
Definition: trace.h:77
NavigationStackConfig.h
ComponentPlugin.h
SimpleEventHandler.h
Component.h
armarx::navigation::client::ComponentPlugin::preOnConnectComponent
void preOnConnectComponent() override
Definition: ComponentPlugin.cpp:44
ExpressionException.h
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:181
PropertyDefinitionContainer.h
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::navigation::client::ComponentPlugin::navigator
std::unique_ptr< Navigator > navigator
Definition: ComponentPlugin.h:53
armarx::navigation::client::IceNavigator::createConfig
void createConfig(const client::NavigationStackConfig &config, const std::string &configId)
Definition: IceNavigator.cpp:52
armarx::ManagedIceObject::getName
std::string getName() const
Retrieve name of object.
Definition: ManagedIceObject.cpp:108
MemoryNameSystem.h
Logging.h
armarx::navigation::client::ComponentPlugin::preOnInitComponent
void preOnInitComponent() override
Definition: ComponentPlugin.cpp:37
armarx::navigation::client::ComponentPlugin::postCreatePropertyDefinitions
void postCreatePropertyDefinitions(armarx::PropertyDefinitionsPtr &properties) override
Definition: ComponentPlugin.cpp:27
ListeningPluginUser.h
armarx::navigation::client::ComponentPluginUser::ComponentPluginUser
ComponentPluginUser()
Definition: ComponentPlugin.cpp:93