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