YARP
Yet Another Robot Platform
primresource.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2021 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__
GenericResource & getPeripheralAt(int index) const
Definition: primresource.h:178
bool satisfy(GenericResource *resource) override
void setProcessor(Processor &proc)
Definition: primresource.h:167
void setNetwork(Network &net)
Definition: primresource.h:168
Processor & getProcessor()
Definition: primresource.h:173
Computer()
Class Computer.
int peripheralCount() const
Definition: primresource.h:177
Platform & getPlatform()
Definition: primresource.h:175
bool addPeripheral(GenericResource &res)
void setPlatform(Platform &os)
Definition: primresource.h:169
void setStorage(Storage &stg)
Definition: primresource.h:166
void setMemory(Memory &mem)
Definition: primresource.h:165
Computer & operator=(const Computer &rhs)
ProcessContainer & getProcesses()
Definition: primresource.h:183
Node * clone() override
Node * clone() override
void setFreeSpace(Capacity c)
Definition: primresource.h:37
Memory()
Class Memory.
bool satisfy(GenericResource *resource) override
void setTotalSpace(Capacity c)
Definition: primresource.h:35
Capacity getFreeSpace()
Definition: primresource.h:38
Capacity getTotalSpace()
Definition: primresource.h:36
const char * getIP6()
Definition: primresource.h:88
Network()
Class Network.
const char * getIP4()
Definition: primresource.h:87
const char * getMAC()
Definition: primresource.h:89
void setIP4(const char *ip)
Definition: primresource.h:84
void setIP6(const char *ip)
Definition: primresource.h:85
bool satisfy(GenericResource *resource) override
Node * clone() override
void setMAC(const char *mac)
Definition: primresource.h:86
a Node of a Graph
Definition: node.h:68
const char * getModel()
Definition: primresource.h:126
bool satisfy(GenericResource *resource) override
const char * getArchitecture()
Definition: primresource.h:125
void setArchitecture(const char *arch)
Definition: primresource.h:119
Processor()
Class Processor.
void setSiblings(size_t n)
Definition: primresource.h:122
void setCPULoad(const LoadAvg &avg)
Definition: primresource.h:124
const LoadAvg & getCPULoad()
Definition: primresource.h:130
void setCores(size_t n)
Definition: primresource.h:121
void setModel(const char *model)
Definition: primresource.h:120
Node * clone() override
void setFrequency(double f)
Definition: primresource.h:123
bool satisfy(GenericResource *resource) override
void setFreeSpace(Capacity c)
Definition: primresource.h:62
Node * clone() override
void setTotalSpace(Capacity c)
Definition: primresource.h:60
Storage()
Class Storage.
Capacity getTotalSpace()
Definition: primresource.h:61
struct yarp::manager::_Process Process
Class Computer.
std::vector< Computer >::iterator ComputerIterator
Definition: primresource.h:207
size_t Capacity
Definition: primresource.h:22
std::vector< Computer > ComputerContainer
Definition: primresource.h:206
std::vector< GenericResource * > ResourcePContainer
Definition: resource.h:62
std::vector< Process >::iterator ProcessIterator
Definition: primresource.h:153
std::vector< Process > ProcessContainer
Definition: primresource.h:152
struct yarp::manager::_LoadAvg LoadAvg
The main, catch-all namespace for YARP.
Definition: dirs.h:19