YARP
Yet Another Robot Platform
SystemInfoSerializer.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
3  * Copyright (C) 2006-2010 RobotCub Consortium
4  * All rights reserved.
5  *
6  * This software may be modified and distributed under the terms of the
7  * BSD-3-Clause license. See the accompanying LICENSE file for details.
8  */
9 
11 
14 #include <yarp/os/SystemInfo.h>
15 
16 using namespace yarp::os;
17 
18 
20 {
21 public:
23  parent(parent)
24  {
25  }
26 
28  {
29  // updating system info
32  //parent->network = SystemInfo::getNetworkInfo();
37  }
38 
40 };
41 
43  memory(SystemInfo::MemoryInfo{0, 0}),
44  storage(SystemInfo::StorageInfo{0, 0}),
45  load(SystemInfo::LoadInfo{.0, .0, .0, 0}),
46  mPriv(new Private(this))
47 {
48 }
49 
51 {
52  delete mPriv;
53 }
54 
56 {
57  // reading memory
58  memory.totalSpace = connection.expectInt32();
59  memory.freeSpace = connection.expectInt32();
60 
61  // reading storage
62  storage.totalSpace = connection.expectInt32();
63  storage.freeSpace = connection.expectInt32();
64 
65  // reading network
66  //network.mac = connection.expectText();
67  //network.ip4 = connection.expectText();
68  //network.ip6 = connection.expectText();
69 
70  // reading processor
71  processor.architecture = connection.expectText();
72  processor.model = connection.expectText();
73  processor.vendor = connection.expectText();
74  processor.family = connection.expectInt32();
75  processor.modelNumber = connection.expectInt32();
76  processor.cores = connection.expectInt32();
77  processor.siblings = connection.expectInt32();
78  processor.frequency = connection.expectFloat64();
79 
80  // reading load
81  load.cpuLoad1 = connection.expectFloat64();
82  load.cpuLoad5 = connection.expectFloat64();
83  load.cpuLoad15 = connection.expectFloat64();
84  load.cpuLoadInstant = connection.expectInt32();
85 
86  // reading platform
87  platform.name = connection.expectText();
88  platform.distribution = connection.expectText();
89  platform.release = connection.expectText();
90  platform.codename = connection.expectText();
91  platform.kernel = connection.expectText();
93 
94  // reading user
95  user.userName = connection.expectText();
96  user.realName = connection.expectText();
97  user.homeDir = connection.expectText();
98  user.userID = connection.expectInt32();
99  return true;
100 }
101 
102 
104 {
105  mPriv->updateSystemInfo();
106 
107  // serializing memory
108  connection.appendInt32(memory.totalSpace);
109  connection.appendInt32(memory.freeSpace);
110 
111  // serializing storage
112  connection.appendInt32(storage.totalSpace);
113  connection.appendInt32(storage.freeSpace);
114 
115  // serializing network
116  //connection.appendText(network.mac);
117  //connection.appendText(network.ip4);
118  //connection.appendText(network.ip6);
119 
120  // serializing processor
121  connection.appendText(processor.architecture);
122  connection.appendText(processor.model);
123  connection.appendText(processor.vendor);
124  connection.appendInt32(processor.family);
125  connection.appendInt32(processor.modelNumber);
126  connection.appendInt32(processor.cores);
127  connection.appendInt32(processor.siblings);
128  connection.appendFloat64(processor.frequency);
129 
130  // serializing load
131  connection.appendFloat64(load.cpuLoad1);
132  connection.appendFloat64(load.cpuLoad5);
133  connection.appendFloat64(load.cpuLoad15);
134  connection.appendInt32(load.cpuLoadInstant);
135 
136  // serializing platform
137  connection.appendText(platform.name);
138  connection.appendText(platform.distribution);
139  connection.appendText(platform.release);
140  connection.appendText(platform.codename);
141  connection.appendText(platform.kernel);
143 
144  // serializing user
145  connection.appendText(user.userName);
146  connection.appendText(user.realName);
147  connection.appendText(user.homeDir);
148  connection.appendInt32(user.userID);
149 
150  return !connection.isError();
151 }
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:1052
void fromString(const std::string &txt, bool wipe=true)
Interprets a string as a list of properties.
Definition: Property.cpp:1046
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
SystemInfoSerializer()
SystemInfoSerializer constructor.
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:29
static MemoryInfo getMemoryInfo()
getMemoryInfo
Definition: SystemInfo.cpp:258
static PlatformInfo getPlatformInfo()
getPlatformInfo
Definition: SystemInfo.cpp:600
static UserInfo getUserInfo()
getUserInfo
Definition: SystemInfo.cpp:723
static LoadInfo getLoadInfo()
getLoadInfo
Definition: SystemInfo.cpp:754
static StorageInfo getStorageInfo()
getStorageInfo
Definition: SystemInfo.cpp:318
static ProcessorInfo getProcessorInfo()
getProcessorInfo
Definition: SystemInfo.cpp:451
An interface to the operating system, including Port based communication.
yarp::os::Property environmentVars
Definition: SystemInfo.h:90