summaryrefslogtreecommitdiffstats
path: root/app/taskmanager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'app/taskmanager.cpp')
-rw-r--r--app/taskmanager.cpp31
1 files changed, 14 insertions, 17 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;