1
0
mirror of https://gitlab.com/kelteseth/ScreenPlay.git synced 2024-09-15 06:52:34 +02:00

Add basic sysinfo structure

This commit is contained in:
kelteseth 2018-10-26 12:05:23 +02:00
parent 69385d76a1
commit 972e7bcad5
8 changed files with 184 additions and 21 deletions

View File

@ -9,11 +9,15 @@ uri = net.aimber.sysinfo
# Input
SOURCES += \
screenplaysysinfo_plugin.cpp \
sysinfo.cpp
sysinfo.cpp \
cpu.cpp \
ram.cpp
HEADERS += \
screenplaysysinfo_plugin.h \
sysinfo.h
sysinfo.h \
cpu.h \
ram.h
DISTFILES = qmldir

33
ScreenPlaySysInfo/cpu.cpp Normal file
View File

@ -0,0 +1,33 @@
#include "cpu.h"
#include <QtQml/qqml.h>
#define STATUS_SUCCESS 0
#define STATUS_INFO_LENGTH_MISMATCH 0xC0000004
CPU::CPU(QObject *parent) : QObject(parent)
{
}
void CPU::update()
{
// long status = 0;
// unsigned long bufSize = c_BufferSize;
// byte* buf = (bufSize > 0) ? new BYTE[bufSize] : nullptr;
// status = c_NtQuerySystemInformation(SystemProcessorPerformanceInformation, buf, bufSize, &size);
// switch (status) {
// case STATUS_INFO_LENGTH_MISMATCH:
// qWarning() << "Warning: Status info length mismatch!";
// break;
// case STATUS_SUCCESS:
// break;
// default:
// break;
// }
}

56
ScreenPlaySysInfo/cpu.h Normal file
View File

@ -0,0 +1,56 @@
#pragma once
#include <QObject>
#include <QDebug>
#ifdef Q_OS_WIN
#include <qt_windows.h>
#endif
// https://github.com/rainmeter/rainmeter/blob/master/Library/MeasureCPU.cpp
typedef LONG(WINAPI* FPNTQSI)(UINT, PVOID, ULONG, PULONG);
class CPU : public QObject {
Q_OBJECT
Q_PROPERTY(float usage READ usage NOTIFY usageChanged)
public:
explicit CPU(QObject* parent = nullptr);
float usage() const
{
return m_usage;
}
signals:
void usageChanged(float usage);
public slots:
void update();
void setUsage(float usage)
{
qWarning("Floating point comparison needs context sanity check");
if (qFuzzyCompare(m_usage, usage))
return;
m_usage = usage;
emit usageChanged(m_usage);
}
private:
float m_usage = 42.0f;
int m_Processor;
double m_OldTime[2];
static FPNTQSI c_NtQuerySystemInformation;
static int c_NumOfProcessors;
static ULONG c_BufferSize;
};

View File

@ -0,0 +1,8 @@
#include "ram.h"
#include <QtQml/qqml.h>
#include <qmetatype.h>
RAM::RAM(QObject* parent)
: QObject(parent)
{
}

39
ScreenPlaySysInfo/ram.h Normal file
View File

@ -0,0 +1,39 @@
#pragma once
#include <QObject>
#include <QDebug>
class RAM : public QObject {
Q_OBJECT
Q_PROPERTY(float usage READ usage NOTIFY usageChanged)
public:
explicit RAM(QObject* parent = nullptr);
float usage() const
{
return m_usage;
}
signals:
void usageChanged(float usage);
public slots:
void exe(){
qDebug() << "aa";
}
void setUsage(float usage)
{
qWarning("Floating point comparison needs context sanity check");
if (qFuzzyCompare(m_usage, usage))
return;
m_usage = usage;
emit usageChanged(m_usage);
}
private:
float m_usage = 42.0f;
};

View File

@ -1,9 +1,9 @@
#include "screenplaysysinfo_plugin.h"
#include "sysinfo.h"
#include <qmetatype.h>
#include <qqml.h>
QObject *ScreenPlaySysInfoSingleton(QQmlEngine *engine, QJSEngine *scriptEngine)
QObject* ScreenPlaySysInfoSingleton(QQmlEngine* engine, QJSEngine* scriptEngine)
{
Q_UNUSED(engine)
Q_UNUSED(scriptEngine)
@ -11,9 +11,9 @@ QObject *ScreenPlaySysInfoSingleton(QQmlEngine *engine, QJSEngine *scriptEngine)
return new SysInfo();
}
void ScreenPlaySysInfoPlugin::registerTypes(const char *uri)
void ScreenPlaySysInfoPlugin::registerTypes(const char* uri)
{
// @uri net.aimber.sysinfo
qmlRegisterSingletonType<SysInfo>(uri, 1, 0, "SysInfo",ScreenPlaySysInfoSingleton);
}
qmlRegisterSingletonType<SysInfo>(uri, 1, 0, "SysInfo", ScreenPlaySysInfoSingleton);
}

View File

@ -3,13 +3,13 @@
SysInfo::SysInfo(QQuickItem *parent):
QQuickItem(parent)
{
// By default, QQuickItem does not draw anything. If you subclass
// QQuickItem to create a visual item, you will need to uncomment the
// following line and re-implement updatePaintNode()
// setFlag(ItemHasContents, true);
// FIXME Elias 2018 QQmlEngine cannot handle smartpointers yet....
m_ram = new RAM();
m_cpu = new CPU();
}
SysInfo::~SysInfo()
{
delete m_cpu;
delete m_ram;
}

View File

@ -1,16 +1,39 @@
#ifndef SYSINFO_H
#define SYSINFO_H
#pragma once
#include "cpu.h"
#include "ram.h"
#include <QQuickItem>
#include <QSharedPointer>
#include <memory>
class SysInfo : public QQuickItem
{
class SysInfo : public QQuickItem {
Q_OBJECT
Q_DISABLE_COPY(SysInfo)
public:
SysInfo(QQuickItem *parent = nullptr);
~SysInfo();
};
Q_PROPERTY(RAM* ram READ ram NOTIFY ramChanged)
Q_PROPERTY(CPU* cpu READ cpu NOTIFY cpuChanged)
#endif // SYSINFO_H
public:
SysInfo(QQuickItem* parent = nullptr);
~SysInfo();
RAM* ram() const
{
return m_ram;
}
CPU* cpu() const
{
return m_cpu;
}
public slots:
signals:
void ramChanged(RAM* ram);
void cpuChanged(CPU* cpu);
private:
RAM* m_ram;
CPU* m_cpu;
};