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 
30 namespace memoryx
31 {
32 
34  {
35  initializeAttributes();
41  setCount(0);
42  }
43 
44  ProfilerTransition::ProfilerTransition(const std::string& parentStateName, const std::string& sourceStateName, const std::string& targetStateName, const EntityRefBasePtr& sourceStateMemorySnapshotRef, const EntityRefBasePtr& targetStateMemorySnapshotRef, Ice::Int count)
45  {
46  initializeAttributes();
47  setParentStateName(parentStateName);
48  setSourceStateName(sourceStateName);
49  setTargetStateName(targetStateName);
50  setSourceStateMemorySnapshotRef(sourceStateMemorySnapshotRef);
51  setTargetStateMemorySnapshotRef(targetStateMemorySnapshotRef);
52  setCount(count);
53  }
54 
56  IceUtil::Shared(source),
57  ::armarx::Serializable(source),
58  EntityBase(),// dont copy
59  ProfilerEntityBase(source),
60  ProfilerTransitionBase(source),
61  Entity(source),
63  {
64  }
65 
67  {
68  }
69 
70 
71  void ProfilerTransition::output(std::ostream& stream) const
72  {
73  Entity::output(stream);
74  }
75 
76  void ProfilerTransition::initializeAttributes()
77  {
78  putAttribute(new EntityAttribute("parentState"));
79  putAttribute(new EntityAttribute("sourceState"));
80  putAttribute(new EntityAttribute("targetState"));
81  putAttribute(new EntityAttribute("sourceMemorySnapshot"));
82  putAttribute(new EntityAttribute("targetMemorySnapshot"));
83  putAttribute(new EntityAttribute("transitionCount"));
84  }
85 
86 
88  {
89  return this->clone();
90  }
91 
93  {
94  std::shared_lock entityLock(entityMutex);
95  std::scoped_lock attributesLock(attributesMutex);
96  std::scoped_lock wrappersLock(wrappersMutex);
97  return new ProfilerTransition(*this);
98  }
99 
100  std::string ProfilerTransition::getParentStateName(const Ice::Current& context) const
101  {
102  return getAttribute("parentState")->getValue()->getString();
103  }
104 
105  void ProfilerTransition::setParentStateName(const std::string& statename, const Ice::Current& context)
106  {
107  getAttribute("parentState")->setValue(new armarx::Variant(statename));
108  setName(statename);
109  }
110 
111 
112  std::string ProfilerTransition::getSourceStateName(const Ice::Current& context) const
113  {
114  return getAttributeValue("sourceState")->getString();
115  }
116 
117  void ProfilerTransition::setSourceStateName(const std::string& statename, const Ice::Current& context)
118  {
119  getAttribute("sourceState")->setValue(new armarx::Variant(statename));
120  }
121 
122  std::string ProfilerTransition::getTargetStateName(const Ice::Current& context) const
123  {
124  return getAttributeValue("targetState")->getString();
125  }
126 
127  void ProfilerTransition::setTargetStateName(const std::string& statename, const Ice::Current& context)
128  {
129  getAttribute("targetState")->setValue(new armarx::Variant(statename));
130  }
131 
132 
133  EntityRefBasePtr ProfilerTransition::getSourceStateMemorySnapshotRef(const Ice::Current& context) const
134  {
135  return getAttributeValue("sourceMemorySnapshot")->get<EntityRef>();
136  }
137 
138  void ProfilerTransition::setSourceStateMemorySnapshotRef(const EntityRefBasePtr& memorySnapshotRef, const Ice::Current& context)
139  {
140  getAttribute("sourceMemorySnapshot")->setValue(new armarx::Variant(memorySnapshotRef));
141  }
142 
143  EntityRefBasePtr ProfilerTransition::getTargetStateMemorySnapshotRef(const Ice::Current& context) const
144  {
145  return getAttributeValue("targetMemorySnapshot")->get<EntityRef>();
146  }
147 
148  void ProfilerTransition::setTargetStateMemorySnapshotRef(const EntityRefBasePtr& memorySnapshotRef, const Ice::Current& context)
149  {
150  getAttribute("targetMemorySnapshot")->setValue(new armarx::Variant(memorySnapshotRef));
151  }
152 
153 
154  Ice::Int ProfilerTransition::getCount(const Ice::Current& context) const
155  {
156  return getAttributeValue("transitionCount")->getInt();
157  }
158 
159  void ProfilerTransition::setCount(Ice::Int count, const Ice::Current& context)
160  {
161  getAttribute("transitionCount")->setValue(new armarx::Variant(count));
162  }
163 
164  bool memoryx::ProfilerTransition::memorySnapshotIdsEqual(const std::string& sourceSnapshotID, const std::string& targetSnapshotID)
165  {
166  auto sourceStateMemorySnapshotRef = this->getSourceStateMemorySnapshotRef();
167  if (!sourceStateMemorySnapshotRef->getEntity())
168  {
169  return false;
170  }
171  auto targetStateMemorySnapshotRef = this->getTargetStateMemorySnapshotRef();
172  if (!targetStateMemorySnapshotRef->getEntity())
173  {
174  return false;
175  }
176  return ((sourceStateMemorySnapshotRef->entityId == sourceSnapshotID)
177  && (targetStateMemorySnapshotRef->entityId == targetSnapshotID));
178 
179  }
180 
181 }
memoryx::ProfilerTransition::setSourceStateName
void setSourceStateName(const std::string &statename, const Ice::Current &context=Ice::emptyCurrent) override
Definition: ProfilerTransition.cpp:117
armarx::Variant
The Variant class is described here: Variants.
Definition: Variant.h:224
memoryx::ProfilerTransition::getParentStateName
std::string getParentStateName(const Ice::Current &context=Ice::emptyCurrent) const override
Definition: ProfilerTransition.cpp:100
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:327
memoryx::ProfilerTransition::getCount
Ice::Int getCount(const Ice::Current &context=Ice::emptyCurrent) const override
Definition: ProfilerTransition.cpp:154
memoryx::Entity::getAttribute
EntityAttributeBasePtr getAttribute(const ::std::string &attrName, const ::Ice::Current &=Ice::emptyCurrent) const override
Retrieve attribute from entity.
Definition: Entity.cpp:293
memoryx::ProfilerTransition::setTargetStateMemorySnapshotRef
void setTargetStateMemorySnapshotRef(const EntityRefBasePtr &memorySnapshotRef, const Ice::Current &context=Ice::emptyCurrent) override
Definition: ProfilerTransition.cpp:148
memoryx
VirtualRobot headers.
Definition: CommonPlacesTester.cpp:48
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
memoryx::ProfilerTransition::setSourceStateMemorySnapshotRef
void setSourceStateMemorySnapshotRef(const EntityRefBasePtr &memorySnapshotRef, const Ice::Current &context=Ice::emptyCurrent) override
Definition: ProfilerTransition.cpp:138
memoryx::ProfilerTransition::getSourceStateMemorySnapshotRef
EntityRefBasePtr getSourceStateMemorySnapshotRef(const Ice::Current &context=Ice::emptyCurrent) const override
Definition: ProfilerTransition.cpp:133
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:409
memoryx::EntityRef
The EntityRef class is used to store references to Entities as values in other Entity instances.
Definition: EntityRef.h:45
memoryx::Entity::getAttributeValue
virtual armarx::VariantPtr getAttributeValue(const ::std::string &attrName) const
Retrieve value of an attribute from entity.
Definition: Entity.cpp:308
memoryx::ProfilerTransition::setTargetStateName
void setTargetStateName(const std::string &statename, const Ice::Current &context=Ice::emptyCurrent) override
Definition: ProfilerTransition.cpp:127
IceInternal::Handle
Definition: forward_declarations.h:8
memoryx::ProfilerTransition::ProfilerTransition
ProfilerTransition()
Definition: ProfilerTransition.cpp:33
memoryx::ProfilerTransition::setParentStateName
void setParentStateName(const std::string &statename, const Ice::Current &context=Ice::emptyCurrent) override
Definition: ProfilerTransition.cpp:105
memoryx::Entity::attributesMutex
std::mutex attributesMutex
Definition: Entity.h:504
memoryx::ProfilerTransition::~ProfilerTransition
~ProfilerTransition() override
Definition: ProfilerTransition.cpp:66
boost::source
Vertex source(const detail::edge_base< Directed, Vertex > &e, const PCG &)
Definition: point_cloud_graph.h:681
memoryx::Entity::entityMutex
std::shared_mutex entityMutex
Definition: Entity.h:505
memoryx::ProfilerTransition::getSourceStateName
std::string getSourceStateName(const Ice::Current &context=Ice::emptyCurrent) const override
Definition: ProfilerTransition.cpp:112
memoryx::ProfilerTransition::getTargetStateName
std::string getTargetStateName(const Ice::Current &context=Ice::emptyCurrent) const override
Definition: ProfilerTransition.cpp:122
armarx::VariantType::Int
const VariantTypeId Int
Definition: Variant.h:916
memoryx::ProfilerTransition::clone
ProfilerTransitionPtr clone(const Ice::Current &c=Ice::emptyCurrent) const
Definition: ProfilerTransition.cpp:92
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:164
armarx::aron::type::ObjectPtr
std::shared_ptr< Object > ObjectPtr
Definition: Object.h:36
memoryx::ProfilerTransition
Definition: ProfilerTransition.h:39
memoryx::Entity
Definition: Entity.h:246
memoryx::ProfilerTransition::ice_clone
Ice::ObjectPtr ice_clone() const override
Definition: ProfilerTransition.cpp:87
memoryx::Entity::setName
void setName(const ::std::string &name, const ::Ice::Current &=Ice::emptyCurrent) override
Set name of this entity.
Definition: Entity.cpp:179
memoryx::ProfilerTransition::getTargetStateMemorySnapshotRef
EntityRefBasePtr getTargetStateMemorySnapshotRef(const Ice::Current &context=Ice::emptyCurrent) const override
Definition: ProfilerTransition.cpp:143
memoryx::Entity::wrappersMutex
std::recursive_mutex wrappersMutex
Definition: Entity.h:506
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
memoryx::ProfilerTransition::setCount
void setCount(Ice::Int count, const Ice::Current &context=Ice::emptyCurrent) override
Definition: ProfilerTransition.cpp:159