YARP
Yet Another Robot Platform
primresource.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
3  * All rights reserved.
4  *
5  * This software may be modified and distributed under the terms of the
6  * BSD-3-Clause license. See the accompanying LICENSE file for details.
7  */
8 
9 #ifndef YARP_MANAGER_PRIMRESOURCE
10 #define YARP_MANAGER_PRIMRESOURCE
11 
12 #include <yarp/manager/ymm-types.h>
13 #include <yarp/manager/node.h>
14 #include <yarp/manager/utility.h>
15 #include <yarp/manager/resource.h>
17 #include <yarp/conf/api.h>
18 
19 namespace yarp {
20 namespace manager {
21 
22 typedef size_t Capacity;
23 
27 class Memory : public GenericResource {
28 public:
29  Memory();
30  Memory(const char* szName);
31  ~Memory() override;
32  Node* clone() override;
33  bool satisfy(GenericResource* resource) override;
34 
35  void setTotalSpace(Capacity c) { totalSpace = c; }
36  Capacity getTotalSpace() { return totalSpace; }
37  void setFreeSpace(Capacity c) { freeSpace = c; }
38  Capacity getFreeSpace() { return freeSpace; }
39 
40 protected:
41 
42 private:
43  Capacity totalSpace;
44  Capacity freeSpace;
45 
46 };
47 
48 
49 /*
50  * class Storage
51  */
52 class Storage : public GenericResource {
53 public:
54  Storage();
55  Storage(const char* szName);
56  virtual ~Storage();
57  Node* clone() override;
58  bool satisfy(GenericResource* resource) override;
59 
60  void setTotalSpace(Capacity c) { totalSpace = c; }
61  Capacity getTotalSpace() { return totalSpace; }
62  void setFreeSpace(Capacity c) { freeSpace = c; }
63  Capacity getFreeSpace() { return freeSpace; }
64 
65 protected:
66 
67 private:
68  Capacity totalSpace;
69  Capacity freeSpace;
70 };
71 
72 
73 /*
74  * Class Network
75  */
76 class Network : public GenericResource {
77 public:
78  Network();
79  Network(const char* szName);
80  virtual ~Network();
81  Node* clone() override;
82  bool satisfy(GenericResource* resource) override;
83 
84  void setIP4(const char* ip) { if(ip) strIP4 = ip; }
85  void setIP6(const char* ip) { if(ip) strIP6 = ip; }
86  void setMAC(const char* mac) { if(mac) strMAC = mac; }
87  const char* getIP4() { return strIP4.c_str(); }
88  const char* getIP6() { return strIP6.c_str(); }
89  const char* getMAC() { return strMAC.c_str(); }
90 
91 protected:
92 
93 private:
94  std::string strIP4;
95  std::string strIP6;
96  std::string strMAC;
97 };
98 
99 
100 typedef struct _LoadAvg {
102  double loadAverage1;
103  double loadAverage5;
106 
107 
108 /*
109  * Class Processor
110  */
111 class Processor : public GenericResource {
112 public:
113  Processor();
114  Processor(const char* szName);
115  virtual ~Processor();
116  Node* clone() override;
117  bool satisfy(GenericResource* resource) override;
118 
119  void setArchitecture(const char* arch) {if(arch) strArchitecure = arch; }
120  void setModel(const char* model) {if(model) strModel = model; }
121  void setCores(size_t n) { cores = n; }
122  void setSiblings(size_t n) { siblings = n; }
123  void setFrequency(double f) { frequency = f; }
124  void setCPULoad(const LoadAvg &avg) { cpuload = avg; }
125  const char* getArchitecture() { return strArchitecure.c_str(); }
126  const char* getModel() { return strModel.c_str(); }
127  size_t getCores() { return cores; }
128  size_t getSiblings() { return siblings; }
129  double getFrequency() { return frequency; }
130  const LoadAvg& getCPULoad() { return cpuload; }
131 
132 protected:
133 
134 private:
135  std::string strArchitecure;
136  std::string strModel;
137  size_t cores;
138  size_t siblings;
139  double frequency;
140  LoadAvg cpuload;
141 };
142 
143 
147 typedef struct _Process {
148  std::string command;
149  int pid;
151 
152 typedef std::vector<Process> ProcessContainer;
153 typedef std::vector<Process>::iterator ProcessIterator;
154 
155 class Computer : public GenericResource {
156 public:
157  Computer();
158  Computer(const char* szName);
159  Computer(const Computer& rhs);
160  virtual ~Computer();
161  Computer& operator=(const Computer& rhs);
162  Node* clone() override;
163  bool satisfy(GenericResource* resource) override;
164 
165  void setMemory(Memory& mem) { memory = mem; }
166  void setStorage(Storage& stg) { storage = stg; }
167  void setProcessor(Processor& proc) { processor = proc; }
168  void setNetwork(Network& net) { network = net; }
169  void setPlatform(Platform& os) {platform = os; }
170 
171  Memory& getMemory() { return memory; }
172  Storage& getStorage() { return storage; }
173  Processor& getProcessor() { return processor; }
174  Network& getNetwork() { return network; }
175  Platform& getPlatform() { return platform; }
176 
177  int peripheralCount() const { return peripheralResources.size(); }
178  GenericResource& getPeripheralAt(int index) const { return *(peripheralResources[index]); }
179  bool addPeripheral(GenericResource& res);
180  void clear();
181 
182  // processes list
183  ProcessContainer& getProcesses() { return processes; }
184 
185 protected:
186 
187 private:
188  Memory memory;
189  Storage storage;
190  Processor processor;
191  Network network;
192  Platform platform;
193  ResourcePContainer peripheralResources;
194 
195  // Processes are not actually part of a resource and only
196  // will be used by yarpmanager for listing processes running
197  // on Computer
198  ProcessContainer processes;
199 
200  bool satisfyComputer(Computer* comp);
201  bool satisfyComputerResource(GenericResource* resource);
202  void swap(const Computer &comp);
203 
204 };
205 
206 typedef std::vector<Computer> ComputerContainer;
207 typedef std::vector<Computer>::iterator ComputerIterator;
208 
209 } // namespace yarp
210 } // namespace manager
211 
212 
213 #endif // __YARP_MANAGER_PRIMRESOURCE__
yarp::manager::Processor::setModel
void setModel(const char *model)
Definition: primresource.h:120
yarp::manager::Computer::clone
Node * clone() override
Definition: primresource.cpp:291
yarp::manager::_LoadAvg::loadAverageInstant
double loadAverageInstant
Definition: primresource.h:101
yarp::manager::Processor::~Processor
virtual ~Processor()
yarp::manager::Processor::getCPULoad
const LoadAvg & getCPULoad()
Definition: primresource.h:130
yarp::manager::Processor::getSiblings
size_t getSiblings()
Definition: primresource.h:128
yarp::manager::Storage::Storage
Storage()
Class Storage.
Definition: primresource.cpp:60
yarp::manager::Processor
Definition: primresource.h:111
yarp::manager::Computer::clear
void clear()
Definition: primresource.cpp:311
yarp::manager::Storage::~Storage
virtual ~Storage()
yarp::manager::Computer::setProcessor
void setProcessor(Processor &proc)
Definition: primresource.h:167
yarp::manager::ProcessIterator
std::vector< Process >::iterator ProcessIterator
Definition: primresource.h:153
yarp::manager::Processor::setArchitecture
void setArchitecture(const char *arch)
Definition: primresource.h:119
yarp::manager::Memory::getTotalSpace
Capacity getTotalSpace()
Definition: primresource.h:36
yarp::manager::Processor::getCores
size_t getCores()
Definition: primresource.h:127
yarp::manager::Computer::setMemory
void setMemory(Memory &mem)
Definition: primresource.h:165
yarp::manager::Processor::getFrequency
double getFrequency()
Definition: primresource.h:129
yarp::manager::Processor::clone
Node * clone() override
Definition: primresource.cpp:180
yarp::manager::Network::clone
Node * clone() override
Definition: primresource.cpp:124
yarp::manager::Computer::satisfy
bool satisfy(GenericResource *resource) override
Definition: primresource.cpp:229
yarp::manager::Computer
Definition: primresource.h:155
yarp::manager::Computer::getPeripheralAt
GenericResource & getPeripheralAt(int index) const
Definition: primresource.h:178
yarp::manager::Storage::satisfy
bool satisfy(GenericResource *resource) override
Definition: primresource.cpp:74
yarp::manager::Network::setIP6
void setIP6(const char *ip)
Definition: primresource.h:85
yarp::manager::Memory::setTotalSpace
void setTotalSpace(Capacity c)
Definition: primresource.h:35
yarp::manager::Processor::setFrequency
void setFrequency(double f)
Definition: primresource.h:123
yarp::manager::Process
struct yarp::manager::_Process Process
Class Computer.
yarp::manager::Storage::setFreeSpace
void setFreeSpace(Capacity c)
Definition: primresource.h:62
yarp::manager::Processor::Processor
Processor()
Class Processor.
Definition: primresource.cpp:138
yarp::manager::Network::getIP4
const char * getIP4()
Definition: primresource.h:87
yarp::manager::ResourcePContainer
std::vector< GenericResource * > ResourcePContainer
Definition: resource.h:62
utility.h
yarp::manager::Computer::Computer
Computer()
Class Computer.
Definition: primresource.cpp:195
yarp::manager::Network::satisfy
bool satisfy(GenericResource *resource) override
Definition: primresource.cpp:110
yarp::manager::Computer::operator=
Computer & operator=(const Computer &rhs)
Definition: primresource.cpp:213
yarp::manager::Network
Definition: primresource.h:76
yarp::manager::Storage
Definition: primresource.h:52
yarp::manager::Platform
Definition: logicresource.h:23
yarp::manager::Computer::peripheralCount
int peripheralCount() const
Definition: primresource.h:177
yarp::manager::Storage::clone
Node * clone() override
Definition: primresource.cpp:86
yarp::manager::Computer::getProcessor
Processor & getProcessor()
Definition: primresource.h:173
yarp::manager::Memory
Class Memory.
Definition: primresource.h:27
yarp::manager::Memory::getFreeSpace
Capacity getFreeSpace()
Definition: primresource.h:38
yarp::manager::_LoadAvg::loadAverage15
double loadAverage15
Definition: primresource.h:104
yarp::manager::Network::setMAC
void setMAC(const char *mac)
Definition: primresource.h:86
node.h
yarp::manager::Network::getMAC
const char * getMAC()
Definition: primresource.h:89
yarp::manager::Memory::Memory
Memory()
Class Memory.
Definition: primresource.cpp:20
yarp::manager::Node
a Node of a Graph
Definition: node.h:68
yarp::manager::Computer::~Computer
virtual ~Computer()
Definition: primresource.cpp:323
yarp::manager::ProcessContainer
std::vector< Process > ProcessContainer
Definition: primresource.h:152
resource.h
yarp::manager::Computer::getStorage
Storage & getStorage()
Definition: primresource.h:172
yarp::manager::Processor::setCPULoad
void setCPULoad(const LoadAvg &avg)
Definition: primresource.h:124
yarp::manager::Memory::setFreeSpace
void setFreeSpace(Capacity c)
Definition: primresource.h:37
ymm-types.h
yarp::manager::Network::Network
Network()
Class Network.
Definition: primresource.cpp:100
yarp::manager::Capacity
size_t Capacity
Definition: primresource.h:22
yarp::manager::_LoadAvg
Definition: primresource.h:100
yarp::manager::Memory::clone
Node * clone() override
Definition: primresource.cpp:46
yarp::manager::Computer::addPeripheral
bool addPeripheral(GenericResource &res)
Definition: primresource.cpp:221
yarp::manager::Processor::satisfy
bool satisfy(GenericResource *resource) override
Definition: primresource.cpp:162
yarp::manager::Network::~Network
virtual ~Network()
yarp::manager::Computer::setPlatform
void setPlatform(Platform &os)
Definition: primresource.h:169
yarp::manager::ComputerIterator
std::vector< Computer >::iterator ComputerIterator
Definition: primresource.h:207
yarp::manager::_Process
Class Computer.
Definition: primresource.h:147
yarp::manager::GenericResource
Definition: resource.h:21
yarp::manager::Storage::getTotalSpace
Capacity getTotalSpace()
Definition: primresource.h:61
yarp::manager::Memory::~Memory
~Memory() override
yarp::manager::Computer::getMemory
Memory & getMemory()
Definition: primresource.h:171
yarp::manager::Computer::getProcesses
ProcessContainer & getProcesses()
Definition: primresource.h:183
yarp::manager::Storage::getFreeSpace
Capacity getFreeSpace()
Definition: primresource.h:63
yarp::manager::_LoadAvg::loadAverage5
double loadAverage5
Definition: primresource.h:103
yarp::manager::Memory::satisfy
bool satisfy(GenericResource *resource) override
Definition: primresource.cpp:34
yarp
The main, catch-all namespace for YARP.
Definition: environment.h:18
yarp::manager::Computer::getPlatform
Platform & getPlatform()
Definition: primresource.h:175
yarp::manager::Computer::setNetwork
void setNetwork(Network &net)
Definition: primresource.h:168
yarp::manager::_LoadAvg::loadAverage1
double loadAverage1
Definition: primresource.h:102
yarp::manager::Processor::setCores
void setCores(size_t n)
Definition: primresource.h:121
logicresource.h
yarp::manager::Network::getIP6
const char * getIP6()
Definition: primresource.h:88
yarp::manager::Processor::getArchitecture
const char * getArchitecture()
Definition: primresource.h:125
yarp::manager::ComputerContainer
std::vector< Computer > ComputerContainer
Definition: primresource.h:206
yarp::manager::Computer::setStorage
void setStorage(Storage &stg)
Definition: primresource.h:166
yarp::manager::_Process::pid
int pid
Definition: primresource.h:149
yarp::manager::Processor::getModel
const char * getModel()
Definition: primresource.h:126
yarp::manager::_Process::command
std::string command
Definition: primresource.h:148
yarp::manager::LoadAvg
struct yarp::manager::_LoadAvg LoadAvg
yarp::manager::Processor::setSiblings
void setSiblings(size_t n)
Definition: primresource.h:122
api.h
yarp::manager::Computer::getNetwork
Network & getNetwork()
Definition: primresource.h:174
yarp::manager::Network::setIP4
void setIP4(const char *ip)
Definition: primresource.h:84
yarp::manager::Storage::setTotalSpace
void setTotalSpace(Capacity c)
Definition: primresource.h:60