implement send command
This commit is contained in:
parent
5388d154da
commit
356cb3e541
@ -18,7 +18,7 @@ public:
|
||||
virtual void unsubscribe(iStompObserver* obs) = 0;
|
||||
|
||||
virtual int connectRequest(QString host, int port, QString vhost, QString username, QString password) = 0;
|
||||
virtual void sendRequest(QString destination, QString body) = 0;
|
||||
virtual void sendRequest(QString destination, const QByteArray& body) = 0;
|
||||
virtual void subscribeRequest(QString destination, int id) = 0;
|
||||
virtual void disconnectRequest() = 0;
|
||||
|
||||
|
29
main.cpp
29
main.cpp
@ -1,36 +1,23 @@
|
||||
#include <QApplication>
|
||||
#include <QSslSocket>
|
||||
#include <QThread>
|
||||
|
||||
#include "stompframe.h"
|
||||
#include "stomp.h"
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
QApplication application(argc, argv);
|
||||
|
||||
QSslSocket socket;
|
||||
socket.setPeerVerifyMode(QSslSocket::VerifyNone);
|
||||
Stomp st;
|
||||
st.connectRequest("sdi.hevs.ch", 61614, "/", "sdi10", "809c02f36becb0868da98761fe3209f6");
|
||||
|
||||
st.sendRequest("/topic/sdi10.gem.command", "right");
|
||||
|
||||
QObject::connect(&socket, &QSslSocket::readyRead, [&]() {
|
||||
auto frame = STOMPFrame::receive(socket);
|
||||
st.sendRequest("/topic/sdi10.gem.command", "up");
|
||||
|
||||
qDebug() << "Connected:" << (frame.command() == STOMPFrame::CONNECTED) << Qt::endl
|
||||
<< "Version:" << frame.headers().value("version");
|
||||
});
|
||||
st.sendRequest("/topic/sdi10.gem.command", "left");
|
||||
|
||||
socket.connectToHostEncrypted("sdi.hevs.ch", 61614);
|
||||
if(!socket.waitForConnected()) return -1;
|
||||
st.sendRequest("/topic/sdi10.gem.command", "down");
|
||||
|
||||
STOMPFrame(STOMPFrame::STOMP, {
|
||||
{"accept-version", "1.2"},
|
||||
{"host", "/"},
|
||||
{"login", "sdi10"},
|
||||
{"passcode", "809c02f36becb0868da98761fe3209f6"}
|
||||
}).send(socket);
|
||||
|
||||
|
||||
|
||||
STOMPFrame(STOMPFrame::MESSAGE, {
|
||||
{},
|
||||
}).send(socket);
|
||||
return application.exec();
|
||||
}
|
||||
|
62
stomp.cpp
62
stomp.cpp
@ -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) {
|
||||
|
2
stomp.h
2
stomp.h
@ -19,7 +19,7 @@ public:
|
||||
bool subscribe(interface::iStompObserver* obs);
|
||||
void unsubscribe(interface::iStompObserver* obs);
|
||||
int connectRequest(QString host, int port, QString vhost, QString username, QString password);
|
||||
void sendRequest(QString destination, QString body);
|
||||
void sendRequest(QString destination, const QByteArray& body);
|
||||
void subscribeRequest(QString destination, int id);
|
||||
void disconnectRequest();
|
||||
|
||||
|
Reference in New Issue
Block a user