1
0
mirror of https://gitlab.com/kelteseth/ScreenPlay.git synced 2024-11-07 03:22:33 +01:00
ScreenPlay/ScreenPlaySysInfo/ram.h

168 lines
4.2 KiB
C
Raw Normal View History

2018-10-26 12:05:23 +02:00
#pragma once
#include <QObject>
#include <QDebug>
2018-12-02 21:22:12 +01:00
#include <QTimer>
#ifdef Q_OS_WIN
#include <qt_windows.h>
#endif
#include <sysinfoapi.h>
2018-10-26 12:05:23 +02:00
class RAM : public QObject {
Q_OBJECT
2018-12-02 21:22:12 +01:00
2018-10-26 12:05:23 +02:00
Q_PROPERTY(float usage READ usage NOTIFY usageChanged)
2018-12-02 21:22:12 +01:00
Q_PROPERTY(unsigned long long usedPhysicalMemory READ usedPhysicalMemory NOTIFY usedPhysicalMemoryChanged)
Q_PROPERTY(unsigned long long totalPhysicalMemory READ totalPhysicalMemory NOTIFY totalPhysicalMemoryChanged)
Q_PROPERTY(unsigned long long usedVirtualMemory READ usedVirtualMemory NOTIFY usedVirtualMemoryChanged)
Q_PROPERTY(unsigned long long totalVirtualMemory READ totalVirtualMemory NOTIFY totalVirtualMemoryChanged)
Q_PROPERTY(unsigned long long usedPagingMemory READ usedPagingMemory NOTIFY usedPagingMemoryChanged)
Q_PROPERTY(unsigned long long totalPagingMemory READ totalPagingMemory NOTIFY totalPagingMemoryChanged)
2018-10-26 12:05:23 +02:00
public:
explicit RAM(QObject* parent = nullptr);
2018-12-02 21:22:12 +01:00
//total memory usage in percent
2018-10-26 12:05:23 +02:00
float usage() const
{
return m_usage;
}
2018-12-02 21:22:12 +01:00
//used physical memory in byte
DWORDLONG usedPhysicalMemory() const
{
return m_usedPhysicalMemory;
}
//total physical memory in byte
DWORDLONG totalPhysicalMemory() const
{
return m_totalPhysicalMemory;
}
//total virtual memory in byte
DWORDLONG totalVirtualMemory() const
{
return m_totalVirtualMemory;
}
//used virtual memory in byte
DWORDLONG usedVirtualMemory() const
{
return m_usedVirtualMemory;
}
//used paging memory in byte
DWORDLONG usedPagingMemory() const
{
return m_usedPagingMemory;
}
//total paging memory in byte
DWORDLONG totalPagingMemory() const
{
return m_totalPagingMemory;
}
2018-10-26 12:05:23 +02:00
signals:
void usageChanged(float usage);
2018-12-02 21:22:12 +01:00
void usedPhysicalMemoryChanged(DWORDLONG usedPhysicalMemory);
void usedVirtualMemoryChanged(DWORDLONG usedVirtualMemory);
void usedPagingMemoryChanged(DWORDLONG usedPagingMemory);
void totalPhysicalMemoryChanged(DWORDLONG totalPhysicalMemory);
void totalVirtualMemoryChanged(DWORDLONG totalVirtualMemory);
void totalPagingMemoryChanged(DWORDLONG totalPagingMemory);
private slots:
void update();
2018-10-26 12:05:23 +02:00
void setUsage(float usage)
{
if (qFuzzyCompare(m_usage, usage))
return;
m_usage = usage;
emit usageChanged(m_usage);
}
2018-12-02 21:22:12 +01:00
void setUsedPhysicalMemory(DWORDLONG usedPhysicalMemory)
{
if(usedPhysicalMemory == m_usedPhysicalMemory)
return;
m_usedPhysicalMemory = usedPhysicalMemory;
emit usedPhysicalMemoryChanged(m_usedPhysicalMemory);
}
void setTotalPhysicalMemory(DWORDLONG totalPhysicalMemory)
{
if(totalPhysicalMemory == m_totalPhysicalMemory)
return;
m_totalPhysicalMemory = totalPhysicalMemory;
emit totalPhysicalMemoryChanged(m_totalPhysicalMemory);
}
void setUsedVirtualMemory(DWORDLONG usedVirtualMemory)
{
if(usedVirtualMemory == m_usedVirtualMemory)
return;
m_usedVirtualMemory = usedVirtualMemory;
emit usedVirtualMemoryChanged(m_usedVirtualMemory);
}
void setTotalVirtualMemory(DWORDLONG totalVirtualMemory)
{
if(totalVirtualMemory == m_totalVirtualMemory)
return;
m_totalVirtualMemory = totalVirtualMemory;
emit totalVirtualMemoryChanged(m_totalVirtualMemory);
}
void setUsedPagingMemory(DWORDLONG usedPagingMemory)
{
if(usedPagingMemory == m_usedPagingMemory)
return;
m_usedPagingMemory = usedPagingMemory;
emit usedPagingMemoryChanged(m_usedPagingMemory);
}
void setTotalPagingMemory(DWORDLONG totalPagingMemory)
{
if(totalPagingMemory == m_totalPagingMemory)
return;
m_totalPagingMemory = totalPagingMemory;
emit totalPagingMemoryChanged(m_totalPagingMemory);
}
2018-10-26 12:05:23 +02:00
private:
2018-12-02 21:22:12 +01:00
float m_usage = -1.f;
DWORDLONG m_usedPhysicalMemory = 0ul;
DWORDLONG m_totalVirtualMemory = 0ul;
DWORDLONG m_totalPhysicalMemory = 0ul;
DWORDLONG m_usedVirtualMemory = 0ul;
DWORDLONG m_usedPagingMemory = 0ul;
DWORDLONG m_totalPagingMemory = 0ul;
QTimer m_updateTimer;
int m_tickRate = 1000;
2018-10-26 12:05:23 +02:00
};