-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added library and tests for using the stomp protocol
- Loading branch information
Showing
12 changed files
with
813 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
cmake_minimum_required (VERSION 3.10) | ||
project (libStomp) | ||
|
||
cmake_policy(SET CMP0020 NEW) | ||
cmake_policy(SET CMP0043 NEW) | ||
|
||
include_directories( | ||
${CMAKE_CURRENT_SOURCE_DIR}/ | ||
${Qt6Core_INCLUDE_DIRS} | ||
${Qt6Network_INCLUDE_DIRS} | ||
${Qt6WebSockets_INCLUDE_DIRS}) | ||
|
||
|
||
set(STOMP_HEADR | ||
stompframe.h | ||
stompclient.h | ||
stompframecreator.h | ||
) | ||
|
||
set(STOMP_SRCS | ||
stompframe.cpp | ||
stompclient.cpp | ||
stompframecreator.cpp | ||
) | ||
|
||
|
||
add_library(libStomp SHARED ${STOMP_HEADR} ${STOMP_SRCS}) | ||
|
||
target_link_libraries(libStomp | ||
Qt6::Widgets | ||
Qt6::Network | ||
Qt6::WebSockets) | ||
|
||
if (UNIX) | ||
install(TARGETS libStomp DESTINATION lib) | ||
else (UNIX) | ||
install(TARGETS libStomp DESTINATION bin) | ||
endif (UNIX) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
#include "stompclient.h" | ||
|
||
StompClient::StompClient() { | ||
QObject::connect(&m_Socket, &QWebSocket::connected, this, &StompClient::socketConnected); | ||
QObject::connect(&m_Socket, &QWebSocket::disconnected, this, &StompClient::socketDisconnected); | ||
QObject::connect(&m_Socket, &QWebSocket::binaryMessageReceived, this, &StompClient::binaryMessageReceived); | ||
QObject::connect(&m_Socket, &QWebSocket::textMessageReceived, this, &StompClient::textMessageReceived); | ||
QObject::connect(&m_Socket, &QWebSocket::binaryFrameReceived, this, &StompClient::binaryFrameReceived); | ||
QObject::connect(&m_Socket, &QWebSocket::textFrameReceived, this, &StompClient::textFrameReceived); | ||
QObject::connect(&m_Socket, &QWebSocket::errorOccurred, this, &StompClient::errorOccurred); | ||
QObject::connect(&m_Socket, &QWebSocket::alertReceived, this, &StompClient::alertReceived); | ||
QObject::connect(&m_Socket, &QWebSocket::authenticationRequired, this, &StompClient::authenticationRequired); | ||
QObject::connect(&m_Socket, &QWebSocket::handshakeInterruptedOnError, this, &StompClient::handshakeInterruptedOnError); | ||
QObject::connect(&m_Socket, &QWebSocket::peerVerifyError, this, &StompClient::peerVerifyError); | ||
QObject::connect(&m_Socket, &QWebSocket::proxyAuthenticationRequired, this, &StompClient::proxyAuthenticationRequired); | ||
QObject::connect(&m_Socket, &QWebSocket::sslErrors, this, &StompClient::sslErrors); | ||
QObject::connect(&m_Socket, &QWebSocket::stateChanged, this, &StompClient::stateChanged); | ||
|
||
} | ||
|
||
int StompClient::getState() { | ||
return m_Socket.state(); | ||
} | ||
|
||
void StompClient::setUrl(const QString& url) { | ||
m_Url = url; | ||
} | ||
|
||
void StompClient::socketConnected() { | ||
qDebug() << "Connected to socket"; | ||
qDebug() << "Socket version " << m_Socket.version(); | ||
qDebug() << "Max incoming message size " << QWebSocket::maxIncomingMessageSize(); | ||
emit clientConnected(); | ||
} | ||
|
||
void StompClient::socketDisconnected() { | ||
qDebug() << "Disconnected from socket"; | ||
} | ||
|
||
|
||
void StompClient::connectToServer() { | ||
if (m_Url.isEmpty()) | ||
return; | ||
|
||
qDebug() << "Connect to " << m_Url; | ||
m_Socket.open(m_Url); | ||
} | ||
|
||
bool StompClient::sendFrame(std::shared_ptr<StompFrame> stompFrame) { | ||
if (!stompFrame->isBinaryBody()) { | ||
QString str = stompFrame->convertToQString(); | ||
m_Socket.sendTextMessage(str); | ||
qDebug() << "Send stomp frame " << str; | ||
return true; | ||
} | ||
|
||
QByteArray ba = stompFrame->convertToByteArray(); | ||
m_Socket.sendBinaryMessage(ba); | ||
return true; | ||
} | ||
|
||
void StompClient::binaryMessageReceived(const QByteArray& ba) { | ||
qDebug() << "Received stomp binary message " << ba.size() << " bytes "; | ||
} | ||
|
||
void StompClient::textMessageReceived(const QString& message) { | ||
qDebug() << "Received stomp text message " << message; | ||
} | ||
|
||
void StompClient::textFrameReceived(const QString &frame, bool isLastFrame) { | ||
qDebug() << "Received stomp text frame"; | ||
} | ||
|
||
void StompClient::binaryFrameReceived(const QByteArray &frame, bool isLastFrame) { | ||
qDebug() << "Received stomp binary frame"; | ||
} | ||
|
||
void StompClient::errorOccurred(QAbstractSocket::SocketError error) { | ||
qDebug() << "Error occured " << error; | ||
} | ||
|
||
void StompClient::alertReceived(QSsl::AlertLevel level, QSsl::AlertType type, const QString &description) { | ||
qDebug() << "Alert reveived"; | ||
} | ||
|
||
void StompClient::authenticationRequired(QAuthenticator* authenticator) { | ||
qDebug() << "Authentication required"; | ||
} | ||
|
||
void StompClient::handshakeInterruptedOnError(const QSslError &error) { | ||
qDebug() << "Handshkage Interrupted on Error"; | ||
} | ||
|
||
void StompClient::peerVerifyError(const QSslError& error) { | ||
qDebug() << "Peer verify error"; | ||
} | ||
|
||
void StompClient::proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *authenticator) { | ||
qDebug() << "proxyAuthenticationRequired"; | ||
} | ||
|
||
void StompClient::sslErrors(const QList<QSslError> &errors) { | ||
qDebug() << "sslErrors"; | ||
} | ||
|
||
void StompClient::stateChanged(QAbstractSocket::SocketState state) { | ||
qDebug() << "Socket state: " << state; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#ifndef __STOMPCLIENT_H_ | ||
#define __STOMPCLIENT_H_ | ||
|
||
#include <QWebSocket> | ||
#include <QString> | ||
#include <QObject> | ||
|
||
#include "stompframe.h" | ||
|
||
class StompClient : public QObject { | ||
Q_OBJECT | ||
|
||
public: | ||
StompClient(); | ||
void connectToServer(); | ||
void setUrl(const QString& url); | ||
|
||
bool sendFrame(std::shared_ptr<StompFrame>); | ||
|
||
signals: | ||
void clientConnected(); | ||
|
||
private slots: | ||
void socketConnected(); | ||
void socketDisconnected(); | ||
void binaryMessageReceived(const QByteArray& ba); | ||
void textMessageReceived(const QString& message); | ||
void textFrameReceived(const QString &frame, bool isLastFrame); | ||
void binaryFrameReceived(const QByteArray &frame, bool isLastFrame); | ||
void errorOccurred(QAbstractSocket::SocketError error); | ||
void alertReceived(QSsl::AlertLevel level, QSsl::AlertType type, const QString &description); | ||
void authenticationRequired(QAuthenticator *authenticator); | ||
void handshakeInterruptedOnError(const QSslError &error); | ||
void peerVerifyError(const QSslError &error); | ||
void proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *authenticator); | ||
void sslErrors(const QList<QSslError> &errors); | ||
void stateChanged(QAbstractSocket::SocketState state); | ||
|
||
private: | ||
int getState(); | ||
|
||
private: | ||
QWebSocket m_Socket; | ||
QString m_Url; | ||
|
||
}; | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
#endif |
Oops, something went wrong.