mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-06-14 12:51:43 -05:00
Remove QtConcurrent dependency
This commit is contained in:
parent
80f9c79907
commit
d5fc3befb8
|
|
@ -12,6 +12,8 @@ Most of this code is based on https://github.com/Palakis/obs-websocket
|
|||
#include <QtCore/QThreadPool>
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
#include <functional>
|
||||
#include <QRunnable>
|
||||
|
||||
#include <websocketpp/config/asio_no_tls_client.hpp>
|
||||
#include <websocketpp/config/asio_no_tls.hpp>
|
||||
|
|
@ -117,3 +119,16 @@ enum class ClientStatus {
|
|||
CONNECTED,
|
||||
FAIL,
|
||||
};
|
||||
|
||||
namespace Compatability {
|
||||
// Reimplement QRunnable for std::function. Retrocompatability for Qt < 5.15
|
||||
class StdFunctionRunnable : public QRunnable {
|
||||
std::function<void()> cb;
|
||||
|
||||
public:
|
||||
StdFunctionRunnable(std::function<void()> func);
|
||||
void run() override;
|
||||
};
|
||||
|
||||
QRunnable *CreateFunctionRunnable(std::function<void()> func);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ Most of this code is based on https://github.com/Palakis/obs-websocket
|
|||
*/
|
||||
|
||||
#include <QtWidgets/QMainWindow>
|
||||
#include <QtConcurrent/QtConcurrent>
|
||||
#include <QTime>
|
||||
#include <QMessageBox>
|
||||
|
||||
|
|
@ -188,11 +187,11 @@ void WSServer::start(quint16 port, bool lockToIPv4)
|
|||
|
||||
_server.start_accept();
|
||||
|
||||
QtConcurrent::run([=]() {
|
||||
_threadPool.start(Compatability::CreateFunctionRunnable([=]() {
|
||||
blog(LOG_INFO, "WSServer::start: io thread started");
|
||||
_server.run();
|
||||
blog(LOG_INFO, "WSServer::start: io thread exited");
|
||||
});
|
||||
}));
|
||||
|
||||
switcher->serverStatus = ServerStatus::RUNNING;
|
||||
blog(LOG_INFO,
|
||||
|
|
@ -320,12 +319,12 @@ void WSServer::onMessage(connection_hdl, server::message_ptr message)
|
|||
return;
|
||||
}
|
||||
|
||||
QtConcurrent::run(&_threadPool, [=]() {
|
||||
_threadPool.start(Compatability::CreateFunctionRunnable([=]() {
|
||||
if (message->get_payload() != "message ok") {
|
||||
blog(LOG_WARNING, "received response: %s",
|
||||
message->get_payload().c_str());
|
||||
}
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
void WSServer::onClose(connection_hdl hdl)
|
||||
|
|
@ -693,3 +692,19 @@ void AdvSceneSwitcher::updateClientStatus()
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Compatability::StdFunctionRunnable::run()
|
||||
{
|
||||
cb();
|
||||
}
|
||||
|
||||
QRunnable *Compatability::CreateFunctionRunnable(std::function<void()> func)
|
||||
{
|
||||
return new Compatability::StdFunctionRunnable(std::move(func));
|
||||
}
|
||||
|
||||
Compatability::StdFunctionRunnable::StdFunctionRunnable(
|
||||
std::function<void()> func)
|
||||
: cb(std::move(func))
|
||||
{
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user