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