summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorRaquel Medina <raquel.medina@konsulko.com>2020-03-23 20:33:49 +0100
committerRaquel Medina <raquel.medina@konsulko.com>2020-03-31 11:28:16 +0200
commit228e9cea6cbb48025f5f5b38560edc4fc69d1d55 (patch)
tree2c2c74a4cbda5f886fbc6efb5f40dbc1b63a496f /app
parent6fc7d70cb8a8915a4382380cbec8fe3c6d28b7a0 (diff)
adapt to use new libqtappfw Message hierarchy
Rework TaskManager to use new libqtappfw Message hierarchy in 2 steps: i) add changes maintaining build compatibility with current and next libqtappfw versions; ii) complete changes once libqtappfw rolls to next version. This commit covers step i). Bug-AGL: SPEC-3112 Signed-off-by: Raquel Medina <raquel.medina@konsulko.com> Change-Id: I650832b2406958adf0ee7fe9cbd7f16c6e36ecc8
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);