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
25namespace armarx
26{
27 void
31
32 void
36
37 void
41
42 void
46
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
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
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.