#pragma once #include #include #include #include #include "CppCommon/Common/Basic/JDefines.h" #include "CppCommon/Common/Basic/JTerminal.h" #include "ExeGet.h" namespace Incart::Net::WebApi { class exeGetEvent : public exeGet { // создать канал для отправки SSE-сообщаний Q_OBJECT private: const bool MYDEBUG = false; QList m_SSE_Sockets; public: exeGetEvent() : exeGet() {} void exe(ParsingURI&, QTcpSocket* socket) override { m_SSE_Sockets.append(socket); m_resp->retSse(); socket->write(m_resp->getResponse()); } public: void make_event(QByteArray& body) { // специальный формат события - реализован частично QByteArray data; data.append(QString("data: ").toUtf8()); data.append(body); data.append(QString("\n\n").toUtf8()); Common::JT() << __FUNCTION__<< QString(data); for( QTcpSocket* obj : m_SSE_Sockets) obj->write(data); } void CloseOneEvent(QTcpSocket* socket) { if ( m_SSE_Sockets.contains(socket) ) m_SSE_Sockets.removeOne(socket); } void ClearEvents() { for( QTcpSocket* obj : m_SSE_Sockets) { obj->close(); obj->deleteLater(); } } public slots: //void slot_make_event(QByteArray body) { make_event(body); } }; } // namespace Incart::Net::WebApi