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
28
29namespace memoryx
30{
31
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),
66 ProfilerEntity(source)
67 {
68 }
69
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
91 Ice::ObjectPtr
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
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
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
constexpr T c
The Variant class is described here: Variants.
Definition Variant.h:224
The EntityRef class is used to store references to Entities as values in other Entity instances.
Definition EntityRef.h:47
Entity is the superclass for all MemoryX memory chunks.
Definition Entity.h:246
EntityAttributeBasePtr getAttribute(const ::std::string &attrName, const ::Ice::Current &=Ice::emptyCurrent) const override
Retrieve attribute from entity.
Definition Entity.cpp:311
void setName(const ::std::string &name, const ::Ice::Current &=Ice::emptyCurrent) override
Set name of this entity.
Definition Entity.cpp:188
virtual armarx::VariantPtr getAttributeValue(const ::std::string &attrName) const
Retrieve value of an attribute from entity.
Definition Entity.cpp:327
std::mutex attributesMutex
Definition Entity.h:524
std::recursive_mutex wrappersMutex
Definition Entity.h:526
void output(std::ostream &stream) const
Definition Entity.cpp:436
void putAttribute(const ::memoryx::EntityAttributeBasePtr &attr, const ::Ice::Current &=Ice::emptyCurrent) override
Store attribute in entity.
Definition Entity.cpp:347
std::shared_mutex entityMutex
Definition Entity.h:525
Ice::Int getCount(const Ice::Current &context=Ice::emptyCurrent) const override
bool memorySnapshotIdsEqual(const std::string &sourceSnapshotID, const std::string &targetSnapshotID)
equalsMemorySnapshotIDs returns true if the ProfilerMemorySnapshot IDs asssocited with this transitio...
std::string getParentStateName(const Ice::Current &context=Ice::emptyCurrent) const override
void setCount(Ice::Int count, const Ice::Current &context=Ice::emptyCurrent) override
EntityRefBasePtr getTargetStateMemorySnapshotRef(const Ice::Current &context=Ice::emptyCurrent) const override
void setSourceStateName(const std::string &statename, const Ice::Current &context=Ice::emptyCurrent) override
EntityRefBasePtr getSourceStateMemorySnapshotRef(const Ice::Current &context=Ice::emptyCurrent) const override
std::string getSourceStateName(const Ice::Current &context=Ice::emptyCurrent) const override
Ice::ObjectPtr ice_clone() const override
void setSourceStateMemorySnapshotRef(const EntityRefBasePtr &memorySnapshotRef, const Ice::Current &context=Ice::emptyCurrent) override
void setParentStateName(const std::string &statename, const Ice::Current &context=Ice::emptyCurrent) override
void setTargetStateMemorySnapshotRef(const EntityRefBasePtr &memorySnapshotRef, const Ice::Current &context=Ice::emptyCurrent) override
std::string getTargetStateName(const Ice::Current &context=Ice::emptyCurrent) const override
ProfilerTransitionPtr clone(const Ice::Current &c=Ice::emptyCurrent) const
void setTargetStateName(const std::string &statename, const Ice::Current &context=Ice::emptyCurrent) override
This file offers overloads of toIce() and fromIce() functions for STL container types.
VirtualRobot headers.
IceInternal::Handle< ProfilerTransition > ProfilerTransitionPtr