YARP
Yet Another Robot Platform
SystemInfoSerializer.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-FileCopyrightText: 2006-2010 RobotCub Consortium
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
8
11#include <yarp/os/SystemInfo.h>
12
13using namespace yarp::os;
14
15
17{
18public:
21 {
22 }
23
25 {
26 // updating system info
27 parent->memory = SystemInfo::getMemoryInfo();
28 parent->storage = SystemInfo::getStorageInfo();
29 //parent->network = SystemInfo::getNetworkInfo();
30 parent->processor = SystemInfo::getProcessorInfo();
31 parent->platform = SystemInfo::getPlatformInfo();
32 parent->load = SystemInfo::getLoadInfo();
33 parent->user = SystemInfo::getUserInfo();
34 }
35
37};
38
39SystemInfoSerializer::SystemInfoSerializer() :
40 memory(SystemInfo::MemoryInfo{0, 0}),
41 storage(SystemInfo::StorageInfo{0, 0}),
42 load(SystemInfo::LoadInfo{.0, .0, .0, 0}),
43 mPriv(new Private(this))
44{
45}
46
48{
49 delete mPriv;
50}
51
53{
54 // reading memory
55 memory.totalSpace = connection.expectInt32();
56 memory.freeSpace = connection.expectInt32();
57
58 // reading storage
59 storage.totalSpace = connection.expectInt32();
60 storage.freeSpace = connection.expectInt32();
61
62 // reading network
63 //network.mac = connection.expectText();
64 //network.ip4 = connection.expectText();
65 //network.ip6 = connection.expectText();
66
67 // reading processor
68 processor.architecture = connection.expectText();
69 processor.model = connection.expectText();
70 processor.vendor = connection.expectText();
71 processor.family = connection.expectInt32();
72 processor.modelNumber = connection.expectInt32();
73 processor.cores = connection.expectInt32();
74 processor.siblings = connection.expectInt32();
75 processor.frequency = connection.expectFloat64();
76
77 // reading load
78 load.cpuLoad1 = connection.expectFloat64();
79 load.cpuLoad5 = connection.expectFloat64();
80 load.cpuLoad15 = connection.expectFloat64();
81 load.cpuLoadInstant = connection.expectInt32();
82
83 // reading platform
84 platform.name = connection.expectText();
85 platform.distribution = connection.expectText();
86 platform.release = connection.expectText();
87 platform.codename = connection.expectText();
88 platform.kernel = connection.expectText();
90
91 // reading user
92 user.userName = connection.expectText();
93 user.realName = connection.expectText();
94 user.homeDir = connection.expectText();
95 user.userID = connection.expectInt32();
96 return true;
97}
98
99
101{
102 mPriv->updateSystemInfo();
103
104 // serializing memory
105 connection.appendInt32(memory.totalSpace);
106 connection.appendInt32(memory.freeSpace);
107
108 // serializing storage
109 connection.appendInt32(storage.totalSpace);
110 connection.appendInt32(storage.freeSpace);
111
112 // serializing network
113 //connection.appendText(network.mac);
114 //connection.appendText(network.ip4);
115 //connection.appendText(network.ip6);
116
117 // serializing processor
119 connection.appendText(processor.model);
120 connection.appendText(processor.vendor);
121 connection.appendInt32(processor.family);
123 connection.appendInt32(processor.cores);
124 connection.appendInt32(processor.siblings);
126
127 // serializing load
128 connection.appendFloat64(load.cpuLoad1);
129 connection.appendFloat64(load.cpuLoad5);
130 connection.appendFloat64(load.cpuLoad15);
131 connection.appendInt32(load.cpuLoadInstant);
132
133 // serializing platform
134 connection.appendText(platform.name);
135 connection.appendText(platform.distribution);
136 connection.appendText(platform.release);
137 connection.appendText(platform.codename);
138 connection.appendText(platform.kernel);
140
141 // serializing user
142 connection.appendText(user.userName);
143 connection.appendText(user.realName);
144 connection.appendText(user.homeDir);
145 connection.appendInt32(user.userID);
146
147 return !connection.isError();
148}
An interface for reading from a network connection.
virtual std::int32_t expectInt32()=0
Read a 32-bit integer from the network connection.
virtual std::string expectText(const char terminatingChar='\n')=0
Read some text from the network connection.
virtual yarp::conf::float64_t expectFloat64()=0
Read a 64-bit floating point number from the network connection.
An interface for writing to a network connection.
virtual bool isError() const =0
virtual void appendText(const std::string &str, const char terminate='\n')=0
Send a terminated string to the network connection.
virtual void appendInt32(std::int32_t data)=0
Send a representation of a 32-bit integer to the network connection.
virtual void appendFloat64(yarp::conf::float64_t data)=0
Send a representation of a 64-bit floating point number to the network connection.
std::string toString() const override
Return a standard text representation of the content of the object.
Definition: Property.cpp:1069
void fromString(const std::string &txt, bool wipe=true)
Interprets a string as a list of properties.
Definition: Property.cpp:1063
A helper class to pass the SystemInfo object around the YARP network.
yarp::os::SystemInfo::LoadInfo load
current cpu load information
bool read(yarp::os::ConnectionReader &connection) override
reads from a ConnectionReader and fill into the SystemInfo structs.
yarp::os::SystemInfo::UserInfo user
current user information
virtual ~SystemInfoSerializer()
~SystemInfoSerializer deconstructor
yarp::os::SystemInfo::StorageInfo storage
system storage information
bool write(yarp::os::ConnectionWriter &connection) const override
write the SystemInfo structs using a ConnectionWriter.
yarp::os::SystemInfo::PlatformInfo platform
operating system information
yarp::os::SystemInfo::MemoryInfo memory
system memory information
yarp::os::SystemInfo::ProcessorInfo processor
system processor type information
A class to get the system (platform) status such as available memory, storage, CPU load and etc.
Definition: SystemInfo.h:25
An interface to the operating system, including Port based communication.
yarp::os::Property environmentVars
Definition: SystemInfo.h:86