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 }
yarp::os::SystemInfo::LoadInfo::cpuLoadInstant
int cpuLoadInstant
Definition: SystemInfo.h:76
yarp::os::SystemInfo::ProcessorInfo::model
std::string model
Definition: SystemInfo.h:58
yarp::os::SystemInfo::PlatformInfo::kernel
std::string kernel
Definition: SystemInfo.h:89
yarp::os::ConnectionWriter::appendFloat64
virtual void appendFloat64(yarp::conf::float64_t data)=0
Send a representation of a 64-bit floating point number to the network connection.
ConnectionWriter.h
yarp::os::SystemInfo::getPlatformInfo
static PlatformInfo getPlatformInfo()
getPlatformInfo
Definition: SystemInfo.cpp:600
yarp::os::Property::fromString
void fromString(const std::string &txt, bool wipe=true)
Interprets a string as a list of properties.
Definition: Property.cpp:1046
yarp::os::SystemInfo::LoadInfo::cpuLoad5
double cpuLoad5
Definition: SystemInfo.h:74
yarp::os::SystemInfo::getStorageInfo
static StorageInfo getStorageInfo()
getStorageInfo
Definition: SystemInfo.cpp:318
yarp::os::SystemInfo::getMemoryInfo
static MemoryInfo getMemoryInfo()
getMemoryInfo
Definition: SystemInfo.cpp:258
yarp::os::SystemInfoSerializer::Private::parent
SystemInfoSerializer *const parent
Definition: SystemInfoSerializer.cpp:39
yarp::os::SystemInfo::ProcessorInfo::frequency
double frequency
Definition: SystemInfo.h:64
yarp::os::SystemInfo
A class to get the system (platform) status such as available memory, storage, CPU load and etc.
Definition: SystemInfo.h:29
yarp::os::SystemInfo::UserInfo::userID
int userID
Definition: SystemInfo.h:101
yarp::os::SystemInfoSerializer::processor
yarp::os::SystemInfo::ProcessorInfo processor
system processor type information
Definition: SystemInfoSerializer.h:63
yarp::os::SystemInfo::UserInfo::userName
std::string userName
Definition: SystemInfo.h:98
yarp::os::SystemInfo::ProcessorInfo::modelNumber
int modelNumber
Definition: SystemInfo.h:61
yarp::os::SystemInfoSerializer::storage
yarp::os::SystemInfo::StorageInfo storage
system storage information
Definition: SystemInfoSerializer.h:58
yarp::os::ConnectionReader::expectFloat64
virtual yarp::conf::float64_t expectFloat64()=0
Read a 64-bit floating point number from the network connection.
yarp::os::ConnectionWriter::isError
virtual bool isError() const =0
yarp::os::SystemInfo::StorageInfo::freeSpace
capacity_t freeSpace
Definition: SystemInfo.h:49
yarp::os::ConnectionReader::expectInt32
virtual std::int32_t expectInt32()=0
Read a 32-bit integer from the network connection.
yarp::os::SystemInfoSerializer::Private::Private
Private(SystemInfoSerializer *parent)
Definition: SystemInfoSerializer.cpp:22
yarp::os::SystemInfoSerializer::memory
yarp::os::SystemInfo::MemoryInfo memory
system memory information
Definition: SystemInfoSerializer.h:53
yarp::os::SystemInfoSerializer::~SystemInfoSerializer
virtual ~SystemInfoSerializer()
~SystemInfoSerializer deconstructor
Definition: SystemInfoSerializer.cpp:50
yarp::os::Property::toString
std::string toString() const override
Return a standard text representation of the content of the object.
Definition: Property.cpp:1052
yarp::os::SystemInfo::ProcessorInfo::cores
int cores
Definition: SystemInfo.h:62
yarp::os::ConnectionWriter
An interface for writing to a network connection.
Definition: ConnectionWriter.h:40
yarp::os::SystemInfo::PlatformInfo::release
std::string release
Definition: SystemInfo.h:87
yarp::os::SystemInfo::ProcessorInfo::siblings
int siblings
Definition: SystemInfo.h:63
yarp::os::SystemInfo::LoadInfo::cpuLoad15
double cpuLoad15
Definition: SystemInfo.h:75
yarp::os::SystemInfo::PlatformInfo::distribution
std::string distribution
Definition: SystemInfo.h:86
yarp::os::SystemInfo::ProcessorInfo::vendor
std::string vendor
Definition: SystemInfo.h:59
yarp::os::SystemInfoSerializer::read
bool read(yarp::os::ConnectionReader &connection) override
reads from a ConnectionReader and fill into the SystemInfo structs.
Definition: SystemInfoSerializer.cpp:55
yarp::os::SystemInfo::UserInfo::realName
std::string realName
Definition: SystemInfo.h:99
yarp::os::SystemInfoSerializer::load
yarp::os::SystemInfo::LoadInfo load
current cpu load information
Definition: SystemInfoSerializer.h:73
yarp::os::ConnectionWriter::appendInt32
virtual void appendInt32(std::int32_t data)=0
Send a representation of a 32-bit integer to the network connection.
yarp::os::SystemInfoSerializer::write
bool write(yarp::os::ConnectionWriter &connection) const override
write the SystemInfo structs using a ConnectionWriter.
Definition: SystemInfoSerializer.cpp:103
yarp::os::ConnectionReader
An interface for reading from a network connection.
Definition: ConnectionReader.h:40
yarp::os::SystemInfo::PlatformInfo::environmentVars
yarp::os::Property environmentVars
Definition: SystemInfo.h:90
yarp::os::SystemInfo::LoadInfo::cpuLoad1
double cpuLoad1
Definition: SystemInfo.h:73
yarp::os::SystemInfoSerializer
A helper class to pass the SystemInfo object around the YARP network.
Definition: SystemInfoSerializer.h:24
yarp::os::SystemInfo::getUserInfo
static UserInfo getUserInfo()
getUserInfo
Definition: SystemInfo.cpp:723
yarp::os
An interface to the operating system, including Port based communication.
Definition: AbstractCarrier.h:17
yarp::os::SystemInfo::PlatformInfo::codename
std::string codename
Definition: SystemInfo.h:88
yarp::os::SystemInfoSerializer::Private::updateSystemInfo
void updateSystemInfo()
Definition: SystemInfoSerializer.cpp:27
yarp::os::ConnectionReader::expectText
virtual std::string expectText(const char terminatingChar='\n')=0
Read some text from the network connection.
yarp::os::SystemInfo::StorageInfo::totalSpace
capacity_t totalSpace
Definition: SystemInfo.h:48
yarp::os::SystemInfo::getProcessorInfo
static ProcessorInfo getProcessorInfo()
getProcessorInfo
Definition: SystemInfo.cpp:451
yarp::os::SystemInfoSerializer::user
yarp::os::SystemInfo::UserInfo user
current user information
Definition: SystemInfoSerializer.h:78
yarp::os::SystemInfoSerializer::SystemInfoSerializer
SystemInfoSerializer()
SystemInfoSerializer constructor.
Definition: SystemInfoSerializer.cpp:42
yarp::os::SystemInfoSerializer::Private
Definition: SystemInfoSerializer.cpp:20
yarp::os::SystemInfo::MemoryInfo::totalSpace
capacity_t totalSpace
Definition: SystemInfo.h:38
yarp::os::SystemInfoSerializer::platform
yarp::os::SystemInfo::PlatformInfo platform
operating system information
Definition: SystemInfoSerializer.h:68
yarp::os::SystemInfo::ProcessorInfo::family
int family
Definition: SystemInfo.h:60
yarp::os::SystemInfo::getLoadInfo
static LoadInfo getLoadInfo()
getLoadInfo
Definition: SystemInfo.cpp:754
yarp::os::SystemInfo::ProcessorInfo::architecture
std::string architecture
Definition: SystemInfo.h:57
yarp::os::ConnectionWriter::appendText
virtual void appendText(const std::string &str, const char terminate='\n')=0
Send a terminated string to the network connection.
yarp::os::SystemInfo::UserInfo::homeDir
std::string homeDir
Definition: SystemInfo.h:100
yarp::os::SystemInfo::PlatformInfo::name
std::string name
Definition: SystemInfo.h:85
SystemInfoSerializer.h
yarp::os::SystemInfo::MemoryInfo::freeSpace
capacity_t freeSpace
Definition: SystemInfo.h:39
yarp::os::SystemInfo::StorageInfo
The StorageInfo struct holds the system storage information.
Definition: SystemInfo.h:47
ConnectionReader.h
yarp::os::SystemInfo::LoadInfo
The LoadInfo struct holds the current cpu load information.
Definition: SystemInfo.h:72
SystemInfo.h