ProfilerTransition.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2012-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 MemoryX::Core
19  * @author Manfred Kroehnert (Manfred dot Kroehnert at kit dot edu)
20  * @date 2015
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 
25 #include "ProfilerTransition.h"
26 
27 #include "../../../../core/entity/EntityRef.h"
28 
29 namespace memoryx
30 {
31 
33  {
34  initializeAttributes();
40  setCount(0);
41  }
42 
43  ProfilerTransition::ProfilerTransition(const std::string& parentStateName,
44  const std::string& sourceStateName,
45  const std::string& targetStateName,
46  const EntityRefBasePtr& sourceStateMemorySnapshotRef,
47  const EntityRefBasePtr& targetStateMemorySnapshotRef,
48  Ice::Int count)
49  {
50  initializeAttributes();
51  setParentStateName(parentStateName);
52  setSourceStateName(sourceStateName);
53  setTargetStateName(targetStateName);
54  setSourceStateMemorySnapshotRef(sourceStateMemorySnapshotRef);
55  setTargetStateMemorySnapshotRef(targetStateMemorySnapshotRef);
56  setCount(count);
57  }
58 
60  IceUtil::Shared(source),
61  ::armarx::Serializable(source),
62  EntityBase(), // dont copy
63  ProfilerEntityBase(source),
64  ProfilerTransitionBase(source),
65  Entity(source),
67  {
68  }
69 
71  {
72  }
73 
74  void
75  ProfilerTransition::output(std::ostream& stream) const
76  {
77  Entity::output(stream);
78  }
79 
80  void
81  ProfilerTransition::initializeAttributes()
82  {
83  putAttribute(new EntityAttribute("parentState"));
84  putAttribute(new EntityAttribute("sourceState"));
85  putAttribute(new EntityAttribute("targetState"));
86  putAttribute(new EntityAttribute("sourceMemorySnapshot"));
87  putAttribute(new EntityAttribute("targetMemorySnapshot"));
88  putAttribute(new EntityAttribute("transitionCount"));
89  }
90 
93  {
94  return this->clone();
95  }
96 
98  ProfilerTransition::clone(const Ice::Current& c) const
99  {
100  std::shared_lock entityLock(entityMutex);
101  std::scoped_lock attributesLock(attributesMutex);
102  std::scoped_lock wrappersLock(wrappersMutex);
103  return new ProfilerTransition(*this);
104  }
105 
106  std::string
107  ProfilerTransition::getParentStateName(const Ice::Current& context) const
108  {
109  return getAttribute("parentState")->getValue()->getString();
110  }
111 
112  void
113  ProfilerTransition::setParentStateName(const std::string& statename,
114  const Ice::Current& context)
115  {
116  getAttribute("parentState")->setValue(new armarx::Variant(statename));
117  setName(statename);
118  }
119 
120  std::string
121  ProfilerTransition::getSourceStateName(const Ice::Current& context) const
122  {
123  return getAttributeValue("sourceState")->getString();
124  }
125 
126  void
127  ProfilerTransition::setSourceStateName(const std::string& statename,
128  const Ice::Current& context)
129  {
130  getAttribute("sourceState")->setValue(new armarx::Variant(statename));
131  }
132 
133  std::string
134  ProfilerTransition::getTargetStateName(const Ice::Current& context) const
135  {
136  return getAttributeValue("targetState")->getString();
137  }
138 
139  void
140  ProfilerTransition::setTargetStateName(const std::string& statename,
141  const Ice::Current& context)
142  {
143  getAttribute("targetState")->setValue(new armarx::Variant(statename));
144  }
145 
146  EntityRefBasePtr
147  ProfilerTransition::getSourceStateMemorySnapshotRef(const Ice::Current& context) const
148  {
149  return getAttributeValue("sourceMemorySnapshot")->get<EntityRef>();
150  }
151 
152  void
153  ProfilerTransition::setSourceStateMemorySnapshotRef(const EntityRefBasePtr& memorySnapshotRef,
154  const Ice::Current& context)
155  {
156  getAttribute("sourceMemorySnapshot")->setValue(new armarx::Variant(memorySnapshotRef));
157  }
158 
159  EntityRefBasePtr
160  ProfilerTransition::getTargetStateMemorySnapshotRef(const Ice::Current& context) const
161  {
162  return getAttributeValue("targetMemorySnapshot")->get<EntityRef>();
163  }
164 
165  void
166  ProfilerTransition::setTargetStateMemorySnapshotRef(const EntityRefBasePtr& memorySnapshotRef,
167  const Ice::Current& context)
168  {
169  getAttribute("targetMemorySnapshot")->setValue(new armarx::Variant(memorySnapshotRef));
170  }
171 
172  Ice::Int
173  ProfilerTransition::getCount(const Ice::Current& context) const
174  {
175  return getAttributeValue("transitionCount")->getInt();
176  }
177 
178  void
179  ProfilerTransition::setCount(Ice::Int count, const Ice::Current& context)
180  {
181  getAttribute("transitionCount")->setValue(new armarx::Variant(count));
182  }
183 
184  bool
185  memoryx::ProfilerTransition::memorySnapshotIdsEqual(const std::string& sourceSnapshotID,
186  const std::string& targetSnapshotID)
187  {
188  auto sourceStateMemorySnapshotRef = this->getSourceStateMemorySnapshotRef();
189  if (!sourceStateMemorySnapshotRef->getEntity())
190  {
191  return false;
192  }
193  auto targetStateMemorySnapshotRef = this->getTargetStateMemorySnapshotRef();
194  if (!targetStateMemorySnapshotRef->getEntity())
195  {
196  return false;
197  }
198  return ((sourceStateMemorySnapshotRef->entityId == sourceSnapshotID) &&
199  (targetStateMemorySnapshotRef->entityId == targetSnapshotID));
200  }
201 
202 } // namespace memoryx
memoryx::ProfilerTransition::setSourceStateName
void setSourceStateName(const std::string &statename, const Ice::Current &context=Ice::emptyCurrent) override
Definition: ProfilerTransition.cpp:127
armarx::Variant
The Variant class is described here: Variants.
Definition: Variant.h:223
memoryx::ProfilerTransition::getParentStateName
std::string getParentStateName(const Ice::Current &context=Ice::emptyCurrent) const override
Definition: ProfilerTransition.cpp:107
armarx::VariantType::EntityRef
const armarx::VariantTypeId EntityRef
Definition: EntityRef.h:30
memoryx::Entity::putAttribute
void putAttribute(const ::memoryx::EntityAttributeBasePtr &attr, const ::Ice::Current &=Ice::emptyCurrent) override
Store attribute in entity.
Definition: Entity.cpp:347
memoryx::ProfilerTransition::getCount
Ice::Int getCount(const Ice::Current &context=Ice::emptyCurrent) const override
Definition: ProfilerTransition.cpp:173
memoryx::Entity::getAttribute
EntityAttributeBasePtr getAttribute(const ::std::string &attrName, const ::Ice::Current &=Ice::emptyCurrent) const override
Retrieve attribute from entity.
Definition: Entity.cpp:311
memoryx::ProfilerTransition::setTargetStateMemorySnapshotRef
void setTargetStateMemorySnapshotRef(const EntityRefBasePtr &memorySnapshotRef, const Ice::Current &context=Ice::emptyCurrent) override
Definition: ProfilerTransition.cpp:166
memoryx
VirtualRobot headers.
Definition: CommonPlacesTester.cpp:48
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:46
memoryx::ProfilerTransition::setSourceStateMemorySnapshotRef
void setSourceStateMemorySnapshotRef(const EntityRefBasePtr &memorySnapshotRef, const Ice::Current &context=Ice::emptyCurrent) override
Definition: ProfilerTransition.cpp:153
memoryx::ProfilerTransition::getSourceStateMemorySnapshotRef
EntityRefBasePtr getSourceStateMemorySnapshotRef(const Ice::Current &context=Ice::emptyCurrent) const override
Definition: ProfilerTransition.cpp:147
ProfilerTransition.h
memoryx::ProfilerEntity
Definition: ProfilerEntity.h:36
IceUtil
Definition: Instance.h:21
memoryx::Entity::output
void output(std::ostream &stream) const
Definition: Entity.cpp:436
memoryx::EntityRef
The EntityRef class is used to store references to Entities as values in other Entity instances.
Definition: EntityRef.h:46
memoryx::Entity::getAttributeValue
virtual armarx::VariantPtr getAttributeValue(const ::std::string &attrName) const
Retrieve value of an attribute from entity.
Definition: Entity.cpp:327
memoryx::ProfilerTransition::setTargetStateName
void setTargetStateName(const std::string &statename, const Ice::Current &context=Ice::emptyCurrent) override
Definition: ProfilerTransition.cpp:140
IceInternal::Handle
Definition: forward_declarations.h:8
memoryx::ProfilerTransition::ProfilerTransition
ProfilerTransition()
Definition: ProfilerTransition.cpp:32
memoryx::ProfilerTransition::setParentStateName
void setParentStateName(const std::string &statename, const Ice::Current &context=Ice::emptyCurrent) override
Definition: ProfilerTransition.cpp:113
memoryx::Entity::attributesMutex
std::mutex attributesMutex
Definition: Entity.h:524
memoryx::ProfilerTransition::~ProfilerTransition
~ProfilerTransition() override
Definition: ProfilerTransition.cpp:70
boost::source
Vertex source(const detail::edge_base< Directed, Vertex > &e, const PCG &)
Definition: point_cloud_graph.h:661
memoryx::Entity::entityMutex
std::shared_mutex entityMutex
Definition: Entity.h:525
memoryx::ProfilerTransition::getSourceStateName
std::string getSourceStateName(const Ice::Current &context=Ice::emptyCurrent) const override
Definition: ProfilerTransition.cpp:121
memoryx::ProfilerTransition::getTargetStateName
std::string getTargetStateName(const Ice::Current &context=Ice::emptyCurrent) const override
Definition: ProfilerTransition.cpp:134
armarx::VariantType::Int
const VariantTypeId Int
Definition: Variant.h:917
memoryx::ProfilerTransition::clone
ProfilerTransitionPtr clone(const Ice::Current &c=Ice::emptyCurrent) const
Definition: ProfilerTransition.cpp:98
memoryx::ProfilerTransition::memorySnapshotIdsEqual
bool memorySnapshotIdsEqual(const std::string &sourceSnapshotID, const std::string &targetSnapshotID)
equalsMemorySnapshotIDs returns true if the ProfilerMemorySnapshot IDs asssocited with this transitio...
Definition: ProfilerTransition.cpp:185
armarx::aron::type::ObjectPtr
std::shared_ptr< Object > ObjectPtr
Definition: Object.h:36
memoryx::ProfilerTransition
Definition: ProfilerTransition.h:38
memoryx::Entity
Definition: Entity.h:245
memoryx::ProfilerTransition::ice_clone
Ice::ObjectPtr ice_clone() const override
Definition: ProfilerTransition.cpp:92
memoryx::Entity::setName
void setName(const ::std::string &name, const ::Ice::Current &=Ice::emptyCurrent) override
Set name of this entity.
Definition: Entity.cpp:188
memoryx::ProfilerTransition::getTargetStateMemorySnapshotRef
EntityRefBasePtr getTargetStateMemorySnapshotRef(const Ice::Current &context=Ice::emptyCurrent) const override
Definition: ProfilerTransition.cpp:160
memoryx::Entity::wrappersMutex
std::recursive_mutex wrappersMutex
Definition: Entity.h:526
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
memoryx::ProfilerTransition::setCount
void setCount(Ice::Int count, const Ice::Current &context=Ice::emptyCurrent) override
Definition: ProfilerTransition.cpp:179