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

200 lines
5.7 KiB
C
Raw Normal View History

/****************************************************************************
**
** Copyright (C) 2020 Elias Steurer (Kelteseth)
** Contact: https://screen-play.app
**
** This file is part of ScreenPlay. ScreenPlay is licensed under a dual license in
** order to ensure its sustainability. When you contribute to ScreenPlay
** you accept that your work will be available under the two following licenses:
**
** $SCREENPLAY_BEGIN_LICENSE$
**
** #### Affero General Public License Usage (AGPLv3)
** Alternatively, this file may be used under the terms of the GNU Affero
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file "ScreenPlay License.md" included in the
** packaging of this App. Please review the following information to
** ensure the GNU Affero Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/agpl-3.0.en.html.
**
** #### Commercial License
** This code is owned by Elias Steurer. By changing/adding to the code you agree to the
** terms written in:
** * Legal/corporate_contributor_license_agreement.md - For corporate contributors
** * Legal/individual_contributor_license_agreement.md - For individual contributors
**
** #### Additional Limitations to the AGPLv3 and Commercial Lincese
** This License does not grant any rights in the trademarks,
** service marks, or logos.
**
**
** $SCREENPLAY_END_LICENSE$
**
****************************************************************************/
2018-10-26 12:05:23 +02:00
#pragma once
#include <QDebug>
2020-10-29 19:17:37 +01:00
#include <QObject>
2018-12-02 21:22:12 +01:00
#include <QTimer>
2021-02-13 20:14:10 +01:00
2018-12-02 21:22:12 +01:00
#ifdef Q_OS_WIN
#include <qt_windows.h>
#endif
2019-04-01 13:03:49 +02:00
#define DWORDLONG unsigned long long
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)
{
2020-10-29 19:17:37 +01:00
if (usedPhysicalMemory == m_usedPhysicalMemory)
2018-12-02 21:22:12 +01:00
return;
m_usedPhysicalMemory = usedPhysicalMemory;
emit usedPhysicalMemoryChanged(m_usedPhysicalMemory);
}
void setTotalPhysicalMemory(DWORDLONG totalPhysicalMemory)
{
2020-10-29 19:17:37 +01:00
if (totalPhysicalMemory == m_totalPhysicalMemory)
2018-12-02 21:22:12 +01:00
return;
m_totalPhysicalMemory = totalPhysicalMemory;
emit totalPhysicalMemoryChanged(m_totalPhysicalMemory);
}
void setUsedVirtualMemory(DWORDLONG usedVirtualMemory)
{
2020-10-29 19:17:37 +01:00
if (usedVirtualMemory == m_usedVirtualMemory)
2018-12-02 21:22:12 +01:00
return;
m_usedVirtualMemory = usedVirtualMemory;
emit usedVirtualMemoryChanged(m_usedVirtualMemory);
}
void setTotalVirtualMemory(DWORDLONG totalVirtualMemory)
{
2020-10-29 19:17:37 +01:00
if (totalVirtualMemory == m_totalVirtualMemory)
2018-12-02 21:22:12 +01:00
return;
m_totalVirtualMemory = totalVirtualMemory;
emit totalVirtualMemoryChanged(m_totalVirtualMemory);
}
void setUsedPagingMemory(DWORDLONG usedPagingMemory)
{
2020-10-29 19:17:37 +01:00
if (usedPagingMemory == m_usedPagingMemory)
2018-12-02 21:22:12 +01:00
return;
m_usedPagingMemory = usedPagingMemory;
emit usedPagingMemoryChanged(m_usedPagingMemory);
}
void setTotalPagingMemory(DWORDLONG totalPagingMemory)
{
2020-10-29 19:17:37 +01:00
if (totalPagingMemory == m_totalPagingMemory)
2018-12-02 21:22:12 +01:00
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
};