-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathDeviceInfo.h
238 lines (207 loc) · 7.69 KB
/
DeviceInfo.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
#ifndef DEVICEINFO_DEVICEINFO_H
#define DEVICEINFO_DEVICEINFO_H
#include "Module.h"
namespace WPEFramework {
namespace Plugin {
class DeviceInfo : public PluginHost::IPlugin, public PluginHost::IWeb {
public:
class Data : public Core::JSON::Container {
public:
class SocketPortInfo : public Core::JSON::Container {
private:
SocketPortInfo(const SocketPortInfo&) = delete;
SocketPortInfo& operator=(const SocketPortInfo&) = delete;
public:
SocketPortInfo()
: Core::JSON::Container()
, Total(0)
, Open(0)
, Link(0)
, Exception(0)
, Shutdown(0)
, Runs(0)
{
Add(_T("total"), &Total);
Add(_T("link"), &Link);
Add(_T("open"), &Open);
Add(_T("exception"), &Exception);
Add(_T("shutdown"), &Shutdown);
Add(_T("runs"), &Runs);
}
~SocketPortInfo()
{
}
public:
Core::JSON::DecUInt32 Total;
Core::JSON::DecUInt32 Open;
Core::JSON::DecUInt32 Link;
Core::JSON::DecUInt32 Exception;
Core::JSON::DecUInt32 Shutdown;
Core::JSON::DecUInt32 Runs;
};
class SysInfo : public Core::JSON::Container {
private:
SysInfo(const SysInfo&) = delete;
SysInfo& operator=(const SysInfo&) = delete;
public:
SysInfo()
: Time("No information")
, Version("0.0")
, Uptime(0)
, TotalRam(0)
, FreeRam(0)
, Hostname("No information")
, CpuLoad("No information")
, TotalGpuRam(0)
, FreeGpuRam(0)
, SerialNumber("No information")
, DeviceId("No information")
{
Add(_T("version"), &Version);
Add(_T("uptime"), &Uptime);
Add(_T("totalram"), &TotalRam);
Add(_T("freeram"), &FreeRam);
Add(_T("devicename"), &Hostname);
Add(_T("cpuload"), &CpuLoad);
Add(_T("totalgpuram"), &TotalGpuRam);
Add(_T("freegpuram"), &FreeGpuRam);
Add(_T("serialnumber"), &SerialNumber);
Add(_T("deviceid"), &DeviceId);
Add(_T("time"), &Time);
}
~SysInfo()
{
}
void Update(void);
public:
Core::JSON::String Time;
Core::JSON::String Version;
Core::JSON::DecUInt32 Uptime;
Core::JSON::DecUInt64 TotalRam;
Core::JSON::DecUInt64 FreeRam;
Core::JSON::String Hostname;
Core::JSON::String CpuLoad;
Core::JSON::DecUInt64 TotalGpuRam;
Core::JSON::DecUInt64 FreeGpuRam;
Core::JSON::String SerialNumber;
Core::JSON::String DeviceId;
};
class AddressInfo : public Core::JSON::Container {
public:
AddressInfo()
: Core::JSON::Container()
, Name()
, MACAddress()
, IPAddress()
{
Add(_T("name"), &Name);
Add(_T("mac"), &MACAddress);
Add(_T("ip"), &IPAddress);
}
AddressInfo(const string& name, const string& mac)
: Core::JSON::Container()
, Name(name)
, MACAddress(mac)
, IPAddress()
{
Add(_T("name"), &Name);
Add(_T("mac"), &MACAddress);
Add(_T("ip"), &IPAddress);
}
AddressInfo(const AddressInfo& copy)
: Core::JSON::Container()
, Name(copy.Name)
, MACAddress(copy.MACAddress)
, IPAddress()
{
Add(_T("name"), &Name);
Add(_T("mac"), &MACAddress);
Add(_T("ip"), &IPAddress);
auto index(copy.IPAddress.Elements());
while (index.Next() == true) {
IPAddress.Add(index.Current());
}
}
AddressInfo& operator=(const AddressInfo& RHS)
{
auto index(RHS.IPAddress.Elements());
Name = RHS.Name;
MACAddress = RHS.MACAddress;
while (index.Next() == true) {
IPAddress.Add(index.Current());
}
return *this;
}
virtual ~AddressInfo()
{
}
public:
Core::JSON::String Name;
Core::JSON::String MACAddress;
Core::JSON::ArrayType<Core::JSON::String> IPAddress;
};
private:
Data(const Data&) = delete;
Data& operator=(const Data&) = delete;
public:
Data()
: Core::JSON::Container()
, Addresses()
, SystemInfo()
{
Add(_T("addresses"), &Addresses);
Add(_T("systeminfo"), &SystemInfo);
Add(_T("sockets"), &Sockets);
}
virtual ~Data()
{
}
public:
Core::JSON::ArrayType<AddressInfo> Addresses;
SysInfo SystemInfo;
SocketPortInfo Sockets;
};
private:
DeviceInfo(const DeviceInfo&) = delete;
DeviceInfo& operator=(const DeviceInfo&) = delete;
public:
DeviceInfo()
: _skipURL(0)
, _service(nullptr)
, _subSystem(nullptr)
, _systemId()
, _deviceId()
{
}
virtual ~DeviceInfo()
{
}
BEGIN_INTERFACE_MAP(DeviceInfo)
INTERFACE_ENTRY(PluginHost::IPlugin)
INTERFACE_ENTRY(PluginHost::IWeb)
END_INTERFACE_MAP
public:
// IPlugin methods
// -------------------------------------------------------------------------------------------------------
virtual const string Initialize(PluginHost::IShell* service) override;
virtual void Deinitialize(PluginHost::IShell* service) override;
virtual string Information() const override;
// IWeb methods
// -------------------------------------------------------------------------------------------------------
virtual void Inbound(Web::Request& request) override;
virtual Core::ProxyType<Web::Response> Process(const Web::Request& request) override;
private:
void SysInfo(Data::SysInfo& systemInfo);
void AddressInfo(Core::JSON::ArrayType<Data::AddressInfo>& addressInfo);
void SocketPortInfo(Data::SocketPortInfo& socketPortInfo);
string GetDeviceId() const;
private:
uint8_t _skipURL;
PluginHost::IShell* _service;
PluginHost::ISubSystem* _subSystem;
string _systemId;
string _deviceId;
};
} // namespace Plugin
} // namespace WPEFramework
#endif // DEVICEINFO_DEVICEINFO_H