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
26
27namespace armarx
28{
29 void
33
34 void
38
39 void
43
44 void
48
57
58 bool
59 RobotNameService::registerRobotInfo(const robot_name_service::dto::RobotInfo& robot,
60 const Ice::Current& current)
61 {
62 std::scoped_lock l(robotsMutex);
63 ARMARX_INFO << "Register a new robot with name '" << robot.name << "' in RNS";
64
65 if (auto it = robots.find(robot.name); it != robots.end())
66 {
67 ARMARX_ERROR << "The robot with name '" << robot.name
68 << "' is already registered. Ignoring it.";
69 return false;
70 }
71
72 robots[robot.name].fromIce(robot);
73 return true;
74 }
75
76 void
77 RobotNameService::unregisterRobotInfo(const std::string& name, const Ice::Current& current)
78 {
79 std::scoped_lock l(robotsMutex);
80
81 if (auto it = robots.find(name); it != robots.end())
82 {
83 robots.erase(it);
84 }
85 }
86
87 IceUtil::Optional<robot_name_service::dto::RobotInfo>
88 RobotNameService::getRobotInfo(const std::string& name, const Ice::Current& current)
89 {
90 std::scoped_lock l(robotsMutex);
91
92 if (auto it = robots.find(name); it == robots.end())
93 {
94 return {};
95 }
96
97 return robots[name].toIce();
98 }
99
101} // namespace armarx
#define ARMARX_REGISTER_COMPONENT_EXECUTABLE(ComponentT, applicationName)
Definition Decoupled.h:29
Default component property definition container.
Definition Component.h:70
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition Component.cpp:90
Brief description of class RobotNameService.
bool registerRobotInfo(const robot_name_service::dto::RobotInfo &robot, const Ice::Current &current) override
void onDisconnectComponent() override
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
IceUtil::Optional< robot_name_service::dto::RobotInfo > getRobotInfo(const std::string &name, const Ice::Current &current) override
void unregisterRobotInfo(const std::string &name, const Ice::Current &current) override
void onConnectComponent() override
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
#define ARMARX_ERROR
The logging level for unexpected behaviour, that must be fixed.
Definition Logging.h:196
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.