RobotNameService.cpp
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::RobotNameService
17  * @author [Author Name] ( [Author Email] )
18  * @date 2018
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
23 #include "RobotNameService.h"
24 
25 namespace armarx
26 {
27  void
29  {
30  }
31 
32  void
34  {
35  }
36 
37  void
39  {
40  }
41 
42  void
44  {
45  }
46 
49  {
52 
53  return defs;
54  }
55 
56  bool
57  RobotNameService::registerRobotInfo(const robot_name_service::dto::RobotInfo& robot,
58  const Ice::Current& current)
59  {
60  std::scoped_lock l(robotsMutex);
61  ARMARX_INFO << "Register a new robot with name '" << robot.name << "' in RNS";
62 
63  if (auto it = robots.find(robot.name); it != robots.end())
64  {
65  ARMARX_ERROR << "The robot with name '" << robot.name
66  << "' is already registered. Ignoring it.";
67  return false;
68  }
69 
70  robots[robot.name].fromIce(robot);
71  return true;
72  }
73 
74  void
75  RobotNameService::unregisterRobotInfo(const std::string& name, const Ice::Current& current)
76  {
77  std::scoped_lock l(robotsMutex);
78 
79  if (auto it = robots.find(name); it != robots.end())
80  {
81  robots.erase(it);
82  }
83  }
84 
85  IceUtil::Optional<robot_name_service::dto::RobotInfo>
86  RobotNameService::getRobotInfo(const std::string& name, const Ice::Current& current)
87  {
88  std::scoped_lock l(robotsMutex);
89 
90  if (auto it = robots.find(name); it == robots.end())
91  {
92  return {};
93  }
94 
95  return robots[name].toIce();
96  }
97 } // namespace armarx
armarx::RobotNameService::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: RobotNameService.cpp:48
armarx::RobotNameService::unregisterRobotInfo
void unregisterRobotInfo(const std::string &name, const Ice::Current &current) override
Definition: RobotNameService.cpp:75
armarx::RobotNameService::onInitComponent
void onInitComponent() override
Definition: RobotNameService.cpp:28
RobotNameService.h
armarx::RobotNameService::onDisconnectComponent
void onDisconnectComponent() override
Definition: RobotNameService.cpp:38
ARMARX_ERROR
#define ARMARX_ERROR
Definition: Logging.h:189
armarx::RobotNameService::registerRobotInfo
bool registerRobotInfo(const robot_name_service::dto::RobotInfo &robot, const Ice::Current &current) override
Definition: RobotNameService.cpp:57
armarx::RobotNameService::onConnectComponent
void onConnectComponent() override
Definition: RobotNameService.cpp:33
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:74
armarx::RobotNameService::getRobotInfo
IceUtil::Optional< robot_name_service::dto::RobotInfo > getRobotInfo(const std::string &name, const Ice::Current &current) override
Definition: RobotNameService.cpp:86
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:70
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
IceUtil::Handle< class PropertyDefinitionContainer >
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::RobotNameService::onExitComponent
void onExitComponent() override
Definition: RobotNameService.cpp:43