Updater.cpp
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5 *
6 * ArmarX is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * ArmarX is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * @package RobotComponents
19 * @author Raphael Grimm ( raphael dot grimm at kit dot edu )
20 * @date 2015
21 * @copyright http://www.gnu.org/licenses/gpl.txt
22 * GNU General Public License
23 */
24#include "Updater.h"
25
27
28void
30{
32 workerId = newId;
33 setWorkerCount(workerId + 1);
34}
35
36void
37armarx::rrtconnect::Updater::addPendingUpdate(const armarx::rrtconnect::Update& u)
38{
39 pendingUpdateLookupTable[UpdateId{u}] = pendingUpdates.size();
40 pendingUpdates.emplace_back(u);
41}
42
43void
45{
46 pendingUpdateLookupTable.clear();
47 pendingUpdates.clear();
48}
49
50void
51armarx::rrtconnect::Updater::applyUpdate(const armarx::rrtconnect::Update& u)
52{
55 ARMARX_CHECK_EXPRESSION(u.updatesPerTree.size() <= trees.size());
56
57 for (std::size_t index = 0; index < u.updatesPerTree.size(); ++index)
58 {
59 trees.at(index).get().applyUpdate(u.updatesPerTree.at(index), u.workerId);
60 }
61 ARMARX_CHECK_EXPRESSION(static_cast<std::size_t>(u.workerId) < appliedUpdateIds.size());
62 ++appliedUpdateIds.at(u.workerId);
63}
64
65bool
66armarx::rrtconnect::Updater::canApplyUpdate(const armarx::rrtconnect::Update& u)
67{
68 for (Ice::Long workerId = 0; static_cast<std::size_t>(workerId) < u.dependetOnUpdateIds.size();
69 ++workerId)
70 {
71 if (!hasAppliedUpdate(workerId, u.dependetOnUpdateIds.at(workerId)))
72 {
73 const UpdateId currUpdateId{u};
74 ARMARX_ERROR_S << "[worker " << workerId << "] missing update " << workerId << "/"
75 << u.dependetOnUpdateIds.at(workerId) << " for update "
76 << currUpdateId.workerId << "/" << currUpdateId.updateSubId;
77 return false;
78 }
79 }
80 return true;
81}
uint8_t index
auto newId
void applyUpdate(const Update &u)
Definition Updater.cpp:51
void setWorkerCount(std::size_t count)
Definition Updater.h:72
void setWorkerId(Ice::Long newId)
Definition Updater.cpp:29
void addPendingUpdate(const Update &u)
Definition Updater.cpp:37
bool canApplyUpdate(const Update &u)
Definition Updater.cpp:66
bool hasAppliedUpdate(Ice::Long workerId, Ice::Long updateSubId) const
Definition Updater.h:240
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
#define ARMARX_ERROR_S
The logging level for unexpected behaviour, that must be fixed.
Definition Logging.h:216