diff --git a/ScreenPlaySysInfo/ScreenPlaySysInfo.pro b/ScreenPlaySysInfo/ScreenPlaySysInfo.pro index 77fdc807..6d6dfc15 100644 --- a/ScreenPlaySysInfo/ScreenPlaySysInfo.pro +++ b/ScreenPlaySysInfo/ScreenPlaySysInfo.pro @@ -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 diff --git a/ScreenPlaySysInfo/cpu.cpp b/ScreenPlaySysInfo/cpu.cpp new file mode 100644 index 00000000..da602d8e --- /dev/null +++ b/ScreenPlaySysInfo/cpu.cpp @@ -0,0 +1,33 @@ +#include "cpu.h" +#include + +#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; +// } +} diff --git a/ScreenPlaySysInfo/cpu.h b/ScreenPlaySysInfo/cpu.h new file mode 100644 index 00000000..a730be0c --- /dev/null +++ b/ScreenPlaySysInfo/cpu.h @@ -0,0 +1,56 @@ +#pragma once + +#include +#include + +#ifdef Q_OS_WIN +#include +#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; +}; diff --git a/ScreenPlaySysInfo/ram.cpp b/ScreenPlaySysInfo/ram.cpp new file mode 100644 index 00000000..3f813dfc --- /dev/null +++ b/ScreenPlaySysInfo/ram.cpp @@ -0,0 +1,8 @@ +#include "ram.h" +#include +#include +RAM::RAM(QObject* parent) + : QObject(parent) +{ + +} diff --git a/ScreenPlaySysInfo/ram.h b/ScreenPlaySysInfo/ram.h new file mode 100644 index 00000000..f5fe98ae --- /dev/null +++ b/ScreenPlaySysInfo/ram.h @@ -0,0 +1,39 @@ +#pragma once + +#include +#include + +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; +}; + diff --git a/ScreenPlaySysInfo/screenplaysysinfo_plugin.cpp b/ScreenPlaySysInfo/screenplaysysinfo_plugin.cpp index c7f1bec1..250b64ed 100644 --- a/ScreenPlaySysInfo/screenplaysysinfo_plugin.cpp +++ b/ScreenPlaySysInfo/screenplaysysinfo_plugin.cpp @@ -1,9 +1,9 @@ #include "screenplaysysinfo_plugin.h" #include "sysinfo.h" - +#include #include -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(uri, 1, 0, "SysInfo",ScreenPlaySysInfoSingleton); -} + qmlRegisterSingletonType(uri, 1, 0, "SysInfo", ScreenPlaySysInfoSingleton); +} diff --git a/ScreenPlaySysInfo/sysinfo.cpp b/ScreenPlaySysInfo/sysinfo.cpp index b1dc6f68..9db4bcea 100644 --- a/ScreenPlaySysInfo/sysinfo.cpp +++ b/ScreenPlaySysInfo/sysinfo.cpp @@ -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; } diff --git a/ScreenPlaySysInfo/sysinfo.h b/ScreenPlaySysInfo/sysinfo.h index cf22e58a..27f8a7be 100644 --- a/ScreenPlaySysInfo/sysinfo.h +++ b/ScreenPlaySysInfo/sysinfo.h @@ -1,16 +1,39 @@ -#ifndef SYSINFO_H -#define SYSINFO_H +#pragma once +#include "cpu.h" +#include "ram.h" #include +#include +#include -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; +};