2 * Copyright 2008-2010, Axel Dörfler, axeld@pinc-software.de.
3 * Distributed under the terms of the MIT License.
7 #include "SystemInfo.h"
9 #include <NetworkInterface.h>
10 #include <NetworkRoster.h>
12 #include "SystemInfoHandler.h"
15 SystemInfo::SystemInfo(SystemInfoHandler
* handler
)
18 fRetrievedNetwork(false),
21 fClipboardTextSize(0),
26 get_system_info(&fSystemInfo
);
27 fCPUInfos
= new cpu_info
[fSystemInfo
.cpu_count
];
28 get_cpu_info(0, fSystemInfo
.cpu_count
, fCPUInfos
);
30 if (handler
!= NULL
) {
31 fRunningApps
= handler
->RunningApps();
32 fClipboardSize
= handler
->ClipboardSize();
33 fClipboardTextSize
= handler
->ClipboardTextSize();
34 fMediaNodes
= handler
->MediaNodes();
35 fMediaConnections
= handler
->MediaConnections();
36 fMediaBuffers
= handler
->MediaBuffers();
41 SystemInfo::~SystemInfo()
48 SystemInfo::CachedMemory() const
51 return fSystemInfo
.cached_pages
* B_PAGE_SIZE
;
59 SystemInfo::BlockCacheMemory() const
61 return fSystemInfo
.block_cache_pages
* B_PAGE_SIZE
;
66 SystemInfo::UsedMemory() const
68 return fSystemInfo
.used_pages
* B_PAGE_SIZE
;
73 SystemInfo::MaxMemory() const
75 return fSystemInfo
.max_pages
* B_PAGE_SIZE
;
80 SystemInfo::PageFaults() const
82 return fSystemInfo
.page_faults
;
87 SystemInfo::UsedSwapSpace() const
89 return (fSystemInfo
.max_swap_pages
- fSystemInfo
.free_swap_pages
)
95 SystemInfo::MaxSwapSpace() const
97 return fSystemInfo
.max_swap_pages
* B_PAGE_SIZE
;
102 SystemInfo::UsedSemaphores() const
104 return fSystemInfo
.used_sems
;
109 SystemInfo::MaxSemaphores() const
111 return fSystemInfo
.max_sems
;
116 SystemInfo::UsedPorts() const
118 return fSystemInfo
.used_ports
;
123 SystemInfo::MaxPorts() const
125 return fSystemInfo
.max_ports
;
130 SystemInfo::UsedThreads() const
132 return fSystemInfo
.used_threads
;
137 SystemInfo::MaxThreads() const
139 return fSystemInfo
.max_threads
;
144 SystemInfo::UsedTeams() const
146 return fSystemInfo
.used_teams
;
151 SystemInfo::MaxTeams() const
153 return fSystemInfo
.max_teams
;
158 SystemInfo::_RetrieveNetwork()
160 if (fRetrievedNetwork
)
165 fRetrievedNetwork
= true;
167 BNetworkRoster
& roster
= BNetworkRoster::Default();
169 BNetworkInterface interface
;
171 while (roster
.GetNextInterface(&cookie
, interface
) == B_OK
) {
173 if (interface
.GetStats(stats
) == B_OK
) {
174 fBytesReceived
+= stats
.receive
.bytes
;
175 fBytesSent
+= stats
.send
.bytes
;
182 SystemInfo::NetworkReceived()
185 return fBytesReceived
;
190 SystemInfo::NetworkSent()
198 SystemInfo::UsedRunningApps() const
205 SystemInfo::MaxRunningApps() const
207 return fSystemInfo
.max_teams
;
212 SystemInfo::ClipboardSize() const
214 return fClipboardSize
;
219 SystemInfo::ClipboardTextSize() const
221 return fClipboardTextSize
;
226 SystemInfo::MediaNodes() const
233 SystemInfo::MediaConnections() const
235 return fMediaConnections
;
240 SystemInfo::MediaBuffers() const
242 return fMediaBuffers
;