aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/taskmanager.cpp31
-rw-r--r--app/taskmanager.h7
2 files changed, 18 insertions, 20 deletions
diff --git a/app/taskmanager.cpp b/app/taskmanager.cpp
index d52ecd8..f880b6b 100644
--- a/app/taskmanager.cpp
+++ b/app/taskmanager.cpp
@@ -5,7 +5,7 @@
#include <unistd.h>
#include <iostream>
#include <QtCore>
-#include <message.h>
+#include <responsemessage.h>
#include "taskmanager.h"
TaskManager::TaskManager(QObject* parent) : QObject(parent), m_loop(nullptr) {
@@ -19,7 +19,6 @@ void TaskManager::open(const QUrl &bindingAddress)
{
m_loop = new MessageEngine(bindingAddress);
QObject::connect(m_loop, &MessageEngine::connected, this, &TaskManager::onConnected);
- QObject::connect(m_loop, &MessageEngine::messageReceived, this, &TaskManager::onMessageReceived);
}
void TaskManager::onConnected()
@@ -52,41 +51,39 @@ void TaskManager::query() {
callService("get_netstat", QJsonValue());
}
-void TaskManager::callService(const QString& command, QJsonValue value) {
- Message *msg = new Message();
- msg->createRequest("taskmanager", command, value);
- qDebug() << "sending message " << msg->toJson();
- m_loop->sendMessage(msg);
- delete msg;
+void TaskManager::callService(const QString&, QJsonValue) {
}
-void TaskManager::onMessageReceived(MessageType type, Message *message)
+void TaskManager::onMessageReceived(std::shared_ptr<Message> message)
{
+ if (!message)
+ return;
+
if (message->isReply())
ProcessResponse(message);
}
-void TaskManager::ProcessResponse(Message *message)
+void TaskManager::ProcessResponse(std::shared_ptr<Message> message)
{
- qDebug() << "got message " << message->toJson();
- QString msgType = message->replyData()["msgType"].toString();
+ std::shared_ptr<ResponseMessage> rmsg = std::static_pointer_cast<ResponseMessage>(message);
+ QString msgType = rmsg->replyData()["msgType"].toString();
if (msgType.isNull())
return; // no type supplied, ignoring
if (QString::compare(msgType, "processList") == 0) {
- QJsonArray processes = message->replyData()["processes"].toArray();
+ QJsonArray processes = rmsg->replyData()["processes"].toArray();
ProcessResponseTasklist(processes);
}
if (QString::compare(msgType, "extraInfo") == 0) {
- QJsonObject info = message->replyData()["info"].toObject();
+ QJsonObject info = rmsg->replyData()["info"].toObject();
ProcessResponseExtraInfo(info);
}
if (QString::compare(msgType, "loadAvgInfo") == 0) {
- QJsonObject loadInfo = message->replyData()["loadInfo"].toObject();
+ QJsonObject loadInfo = rmsg->replyData()["loadInfo"].toObject();
ProcessResponseLoadAvg(loadInfo);
}
if (QString::compare(msgType, "netStatInfo") == 0) {
- QJsonObject netstat = message->replyData()["netstat"].toObject();
+ QJsonObject netstat = rmsg->replyData()["netstat"].toObject();
ProcessResponseNetStat(netstat);
}
// more response types to follow
@@ -110,7 +107,7 @@ void TaskManager::ProcessResponseTasklist(QJsonArray& processes)
if(m_procinfos.empty()){
for(auto it = procs.begin(); it != procs.end(); ++it){ // if m_procinfos is empty then this is first call
emit addProcess(it->cmd(), it->tid(), it->euid(), it->scpu(), it->ucpu(), it->resident_memory(), it->state());
- }
+ }
} else {
for(auto it = procs.begin(); it != procs.end(); ++it){ // loop through procs, it = procs element (ProcInfo obj)
flag = 0;
diff --git a/app/taskmanager.h b/app/taskmanager.h
index 1ee351d..87ca4b2 100644
--- a/app/taskmanager.h
+++ b/app/taskmanager.h
@@ -4,6 +4,7 @@
#include <QStringList>
#include <QVector>
#include <QtCore>
+#include <memory>
#include <messageengine.h>
#include "procinfo.h"
@@ -34,9 +35,9 @@ signals:
private slots:
void query();
- void callService(const QString& ccommand, QJsonValue value);
+ void callService(const QString&, QJsonValue);
void onConnected();
- void onMessageReceived(MessageType type, Message *message);
+ void onMessageReceived(std::shared_ptr<Message>);
void loadAvg();
private:
@@ -44,7 +45,7 @@ private:
std::vector<ProcInfo> m_procinfos;
unsigned int inOctets, outOctets;
- void ProcessResponse(Message *message);
+ void ProcessResponse(std::shared_ptr<Message>);
void ProcessResponseTasklist(QJsonArray& processes);
void ProcessResponseExtraInfo(QJsonObject& info);
void ProcessResponseLoadAvg(QJsonObject& loadInfo);