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 
29 {
31  workerId = newId;
32  setWorkerCount(workerId + 1);
33 }
34 
35 void armarx::rrtconnect::Updater::addPendingUpdate(const armarx::rrtconnect::Update& u)
36 {
37  pendingUpdateLookupTable[UpdateId {u}] = pendingUpdates.size();
38  pendingUpdates.emplace_back(u);
39 }
40 
42 {
43  pendingUpdateLookupTable.clear();
44  pendingUpdates.clear();
45 }
46 
47 void armarx::rrtconnect::Updater::applyUpdate(const armarx::rrtconnect::Update& u)
48 {
49  ARMARX_CHECK_EXPRESSION(!hasAppliedUpdate(u));
50  ARMARX_CHECK_EXPRESSION(canApplyUpdate(u));
51  ARMARX_CHECK_EXPRESSION(u.updatesPerTree.size() <= trees.size());
52 
53  for (std::size_t index = 0; index < u.updatesPerTree.size(); ++index)
54  {
55  trees.at(index).get().applyUpdate(u.updatesPerTree.at(index), u.workerId);
56  }
57  ARMARX_CHECK_EXPRESSION(static_cast<std::size_t>(u.workerId) < appliedUpdateIds.size());
58  ++appliedUpdateIds.at(u.workerId);
59 }
60 
61 bool armarx::rrtconnect::Updater::canApplyUpdate(const armarx::rrtconnect::Update& u)
62 {
63  for (Ice::Long workerId = 0; static_cast<std::size_t>(workerId) < u.dependetOnUpdateIds.size(); ++workerId)
64  {
65  if (!hasAppliedUpdate(workerId, u.dependetOnUpdateIds.at(workerId)))
66  {
67  const UpdateId currUpdateId
68  {
69  u
70  };
71  ARMARX_ERROR_S << "[worker " << workerId << "] missing update " << workerId << "/" << u.dependetOnUpdateIds.at(workerId) << " for update " << currUpdateId.workerId << "/" << currUpdateId.updateSubId;
72  return false;
73  }
74  }
75  return true;
76 }
Updater.h
index
uint8_t index
Definition: EtherCATFrame.h:59
armarx::rrtconnect::Updater::setWorkerCount
void setWorkerCount(std::size_t count)
Definition: Updater.h:70
armarx::rrtconnect::Updater::applyUpdate
void applyUpdate(const Update &u)
Definition: Updater.cpp:47
armarx::rrtconnect::UpdateId
Definition: Updater.h:38
newId
auto newId
Definition: GraspingManager.cpp:90
ARMARX_ERROR_S
#define ARMARX_ERROR_S
Definition: Logging.h:209
armarx::rrtconnect::Updater::clearPendingUpdates
void clearPendingUpdates()
Definition: Updater.cpp:41
armarx::VariantType::Long
const VariantTypeId Long
Definition: Variant.h:917
ARMARX_CHECK_EXPRESSION
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
Definition: ExpressionException.h:73
armarx::rrtconnect::Updater::addPendingUpdate
void addPendingUpdate(const Update &u)
Definition: Updater.cpp:35
armarx::rrtconnect::Updater::setWorkerId
void setWorkerId(Ice::Long newId)
Definition: Updater.cpp:28
armarx::rrtconnect::Updater::canApplyUpdate
bool canApplyUpdate(const Update &u)
Definition: Updater.cpp:61
Logging.h