implement send command

This commit is contained in:
2023-12-06 12:00:27 +01:00
parent 5388d154da
commit 356cb3e541
4 changed files with 55 additions and 40 deletions

View File

@@ -1,7 +1,48 @@
#include "stomp.h"
Stomp::Stomp() {
socket_.setPeerVerifyMode(QSslSocket::VerifyNone);
QObject::connect(&socket_, &QSslSocket::readyRead, [&] {
auto frame = STOMPFrame::receive(socket_);
switch(frame.command()) {
case STOMPFrame::CONNECTED:
qDebug() << "Connected !" << Qt::endl
<< "Version:" << frame.headers().value("version");
notifyConnectConfirmation(true,frame.headers().value("version"));
break;
case STOMPFrame::MESSAGE:
qDebug() << "Message" << Qt::endl;
break;
case STOMPFrame::RECEIPT:
notifySendConfirmation(true);
qDebug() << "Succesfully send" << Qt::endl;
break;
case STOMPFrame::ERROR:
notifyConnectConfirmation(false,frame.headers().value("version"));
notifySendConfirmation(false);
qDebug() << Qt::endl
<< "-----ERROR-----" << Qt::endl
<< "Command: " << frame.command() << Qt::endl
<< "Header: " << frame.headers() << Qt::endl
<< "Body: " << frame.body() << Qt::endl
<< Qt::endl;
break;
default:
qDebug() << Qt::endl
<< "-----Other STOMP frame-----" << Qt::endl
<< "Command: " << frame.command() << Qt::endl
<< "Header: " << frame.headers() << Qt::endl
<< "Body: " << frame.body() << Qt::endl
<< Qt::endl;
break;
}
});
}
Stomp::~Stomp() {
@@ -28,18 +69,6 @@ void Stomp::unsubscribe(interface::iStompObserver* obs) {
}
int Stomp::connectRequest(QString host, int port, QString vhost, QString username, QString password) {
socket_.setPeerVerifyMode(QSslSocket::VerifyNone);
QObject::connect(&socket_, &QSslSocket::readyRead, [&]() {
auto frame = STOMPFrame::receive(socket_);
qDebug() << "Connected:" << (frame.command() == STOMPFrame::CONNECTED) << Qt::endl
<< "Version:" << frame.headers().value("version");
notifyConnectConfirmation((frame.command() == STOMPFrame::CONNECTED),
frame.headers().value("version"));
});
socket_.connectToHostEncrypted(host, port);
if(!socket_.waitForConnected()) return -1;
@@ -55,12 +84,11 @@ int Stomp::connectRequest(QString host, int port, QString vhost, QString usernam
}
void Stomp::sendRequest(QString destination, QString body) {
void Stomp::sendRequest(QString destination, const QByteArray& body) {
QObject::connect(&socket_, &QSslSocket::readyRead, [&] {
auto frame = STOMPFrame::receive(socket_);
notifySendConfirmation(frame.command() == STOMPFrame::RECEIPT);
});
STOMPFrame(STOMPFrame::SEND, {
{"destination", destination},
}, body).send(socket_);
}
void Stomp::subscribeRequest(QString destination, int id) {