implements oberver pattern
This commit is contained in:
80
stomp.cpp
80
stomp.cpp
@@ -4,6 +4,11 @@ Stomp::Stomp() {
|
||||
|
||||
}
|
||||
|
||||
Stomp::~Stomp() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
bool Stomp::subscribe(interface::iStompObserver* obs) {
|
||||
for(int i = 0; i < MAX_OBSERVER; i++) {
|
||||
if (observer_[i] == nullptr) {
|
||||
@@ -14,4 +19,79 @@ bool Stomp::subscribe(interface::iStompObserver* obs) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void Stomp::unsubscribe(interface::iStompObserver* obs) {
|
||||
for(int i = 0; i < MAX_OBSERVER; i++) {
|
||||
if(observer_[i] == obs) {
|
||||
observer_[i] = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
STOMPFrame(STOMPFrame::STOMP, {
|
||||
{"accept-version", "1.2"},
|
||||
{"host", vhost},
|
||||
{"login", username},
|
||||
{"passcode", password}
|
||||
}).send(socket_);
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
void Stomp::sendRequest(QString destination, QString body) {
|
||||
|
||||
QObject::connect(&socket_, &QSslSocket::readyRead, [&] {
|
||||
auto frame = STOMPFrame::receive(socket_);
|
||||
notifySendConfirmation(frame.command() == STOMPFrame::RECEIPT);
|
||||
});
|
||||
}
|
||||
|
||||
void Stomp::subscribeRequest(QString destination, int id) {
|
||||
|
||||
}
|
||||
|
||||
void Stomp::disconnectRequest() {
|
||||
|
||||
}
|
||||
|
||||
void Stomp::notifyConnectConfirmation(bool success, QString version) {
|
||||
|
||||
}
|
||||
|
||||
void Stomp::notifySendConfirmation(bool success) {
|
||||
|
||||
}
|
||||
|
||||
void Stomp::notifySubscribeConfirmation(bool success) {
|
||||
|
||||
}
|
||||
|
||||
void Stomp::notifyReceiveIndication(int id, QString destination, QString body) {
|
||||
|
||||
}
|
||||
|
||||
void Stomp::notifyDisconnectConfirmation() {
|
||||
|
||||
}
|
||||
|
||||
void Stomp::notifyDisconnectIndication() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user