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