ResourceProfileEntity.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 Lesser 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::MemoryTypes
19  * @author Manfred Kroehnert (Manfred dot Kroehnert at kit dot edu)
20  * @date 2015
21  * @copyright http://www.gnu.org/licenses/gpl.txt
22  * GNU General Public License
23  */
24 
25 #include "ResourceProfileEntity.h"
26 
29 
30 namespace memoryx
31 {
32  const std::string ResourceProfileEntity::DURATION = "duration";
33  const std::string ResourceProfileEntity::CPU_USAGE = "cpuUsage";
34  const std::string ResourceProfileEntity::MEMORY_USAGE = "memoryUsage";
35 
36 
38  {
39  initializeAttributes();
40 
41  // initialize with 0 values
42  setDuration(new StatisticMeasures(0, 0, 0));
43  setCpuUsage(new StatisticMeasures(0, 0, 0));
44  setMemoryUsage(new StatisticMeasures(0, 0, 0));
45  }
46 
47 
48  ResourceProfileEntity::ResourceProfileEntity(const StatisticMeasuresBasePtr& duration, const StatisticMeasuresBasePtr& cpuUsage, const StatisticMeasuresBasePtr& memoryUsage) :
49  Entity()
50  {
51  initializeAttributes();
52 
53  setDuration(duration);
54  setCpuUsage(cpuUsage);
55  setMemoryUsage(memoryUsage);
56  }
57 
58 
59  void ResourceProfileEntity::initializeAttributes()
60  {
61  putAttribute(new EntityAttribute(DURATION));
62  putAttribute(new EntityAttribute(CPU_USAGE));
63  putAttribute(new EntityAttribute(MEMORY_USAGE));
64  }
65 
66 
68  IceUtil::Shared(source),
69  ::armarx::Serializable(source),
70  EntityBase(),// dont copy
71  ResourceProfileEntityBase(source),
72  Entity(source)
73  {
74  }
75 
76 
78  {
79  }
80 
81 
82  void ResourceProfileEntity::output(std::ostream& stream) const
83  {
84  Entity::output(stream);
85  }
86 
87 
89  {
90  return this->clone();
91  }
92 
93 
94  ResourceProfileEntityPtr ResourceProfileEntity::clone(const Ice::Current& context) const
95  {
96  std::shared_lock entityLock(entityMutex);
97  std::scoped_lock attributesLock(attributesMutex);
98  std::scoped_lock wrappersLock(wrappersMutex);
99  return new ResourceProfileEntity(*this);
100  }
101 
102 
103  StatisticMeasuresBasePtr ResourceProfileEntity::getDuration(const Ice::Current& context) const
104  {
105  return getAttributeValue(DURATION)->get<StatisticMeasuresBase>();
106  }
107 
108  void ResourceProfileEntity::setDuration(const StatisticMeasuresBasePtr& duration, const Ice::Current& context)
109  {
110  putAttribute(DURATION, duration);
111  }
112 
113  StatisticMeasuresBasePtr ResourceProfileEntity::getCpuUsage(const Ice::Current& context) const
114  {
115  return getAttributeValue(CPU_USAGE)->get<StatisticMeasuresBase>();
116  }
117 
118  void ResourceProfileEntity::setCpuUsage(const StatisticMeasuresBasePtr& cpuUsage, const Ice::Current& context)
119  {
120  putAttribute(CPU_USAGE, cpuUsage);
121  }
122 
123  StatisticMeasuresBasePtr ResourceProfileEntity::getMemoryUsage(const Ice::Current& context) const
124  {
125  return getAttributeValue(MEMORY_USAGE)->get<StatisticMeasuresBase>();
126  }
127 
128  void ResourceProfileEntity::setMemoryUsage(const StatisticMeasuresBasePtr& memoryUsage, const Ice::Current& context)
129  {
130  putAttribute(MEMORY_USAGE, memoryUsage);
131  }
132 }
memoryx::Entity::putAttribute
void putAttribute(const ::memoryx::EntityAttributeBasePtr &attr, const ::Ice::Current &=Ice::emptyCurrent) override
Store attribute in entity.
Definition: Entity.cpp:327
memoryx::ResourceProfileEntity::ResourceProfileEntity
ResourceProfileEntity()
Definition: ResourceProfileEntity.cpp:37
memoryx
VirtualRobot headers.
Definition: CommonPlacesTester.cpp:48
memoryx::VariantType::StatisticMeasures
const armarx::VariantTypeId StatisticMeasures
Definition: StatisticMeasures.h:32
IceUtil
Definition: Instance.h:21
memoryx::ResourceProfileEntity::getCpuUsage
StatisticMeasuresBasePtr getCpuUsage(const Ice::Current &c=Ice::emptyCurrent) const override
Definition: ResourceProfileEntity.cpp:113
memoryx::Entity::output
void output(std::ostream &stream) const
Definition: Entity.cpp:409
memoryx::Entity::getAttributeValue
virtual armarx::VariantPtr getAttributeValue(const ::std::string &attrName) const
Retrieve value of an attribute from entity.
Definition: Entity.cpp:308
IceInternal::Handle
Definition: forward_declarations.h:8
memoryx::ResourceProfileEntity::getDuration
StatisticMeasuresBasePtr getDuration(const Ice::Current &c=Ice::emptyCurrent) const override
Definition: ResourceProfileEntity.cpp:103
StatisticMeasures.h
memoryx::Entity::attributesMutex
std::mutex attributesMutex
Definition: Entity.h:504
memoryx::ResourceProfileEntity::~ResourceProfileEntity
~ResourceProfileEntity() override
Definition: ResourceProfileEntity.cpp:77
memoryx::ResourceProfileEntity::clone
ResourceProfileEntityPtr clone(const Ice::Current &c=Ice::emptyCurrent) const
Definition: ResourceProfileEntity.cpp:94
boost::source
Vertex source(const detail::edge_base< Directed, Vertex > &e, const PCG &)
Definition: point_cloud_graph.h:681
ResourceProfileEntity.h
memoryx::ResourceProfileEntity::setDuration
void setDuration(const StatisticMeasuresBasePtr &duration, const Ice::Current &c=Ice::emptyCurrent) override
Definition: ResourceProfileEntity.cpp:108
memoryx::Entity::entityMutex
std::shared_mutex entityMutex
Definition: Entity.h:505
memoryx::ResourceProfileEntity::ice_clone
Ice::ObjectPtr ice_clone() const override
Definition: ResourceProfileEntity.cpp:88
memoryx::EntityAttribute
Attribute of MemoryX entities.
Definition: EntityAttribute.h:48
memoryx::ResourceProfileEntity::getMemoryUsage
StatisticMeasuresBasePtr getMemoryUsage(const Ice::Current &c=Ice::emptyCurrent) const override
Definition: ResourceProfileEntity.cpp:123
MemoryXTypesObjectFactories.h
memoryx::ResourceProfileEntity
Definition: ResourceProfileEntity.h:36
armarx::aron::type::ObjectPtr
std::shared_ptr< Object > ObjectPtr
Definition: Object.h:36
memoryx::Entity
Definition: Entity.h:246
memoryx::ResourceProfileEntity::setCpuUsage
void setCpuUsage(const StatisticMeasuresBasePtr &cpuUsage, const Ice::Current &c=Ice::emptyCurrent) override
Definition: ResourceProfileEntity.cpp:118
memoryx::ResourceProfileEntity::setMemoryUsage
void setMemoryUsage(const StatisticMeasuresBasePtr &memoryUsage, const Ice::Current &c=Ice::emptyCurrent) override
Definition: ResourceProfileEntity.cpp:128
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