mirror of
https://github.com/rizinorg/cutter.git
synced 2024-12-19 11:26:11 +00:00
1f36c55f6a
- use -h& command so the thread does end - set the QRCore in the constructor - try to disable the websever with =h-
79 lines
1.5 KiB
C++
79 lines
1.5 KiB
C++
#include "webserverthread.h"
|
|
#include "qrcore.h"
|
|
#include <cassert>
|
|
|
|
WebServerThread::WebServerThread(QRCore *core, QObject *parent) :
|
|
QThread(parent),
|
|
core(core),
|
|
started(false)
|
|
{
|
|
// MEOW
|
|
}
|
|
|
|
WebServerThread::~WebServerThread()
|
|
{
|
|
if (isRunning()) {
|
|
quit();
|
|
wait();
|
|
}
|
|
}
|
|
|
|
void WebServerThread::startServer()
|
|
{
|
|
assert(nullptr != core);
|
|
|
|
if (!isRunning() && !started) {
|
|
QThread::start();
|
|
}
|
|
}
|
|
|
|
void WebServerThread::stopServer()
|
|
{
|
|
assert(nullptr != core);
|
|
|
|
if (!isRunning() && started)
|
|
{
|
|
QThread::start();
|
|
}
|
|
}
|
|
|
|
bool WebServerThread::isStarted() const
|
|
{
|
|
QMutexLocker locker(&mutex);
|
|
return started;
|
|
}
|
|
|
|
void WebServerThread::run() {
|
|
QMutexLocker locker(&mutex);
|
|
|
|
if (core == nullptr)
|
|
return;
|
|
//eprintf ("Starting webserver!");
|
|
|
|
toggleWebServer();
|
|
}
|
|
|
|
void WebServerThread::toggleWebServer()
|
|
{
|
|
// access already locked
|
|
|
|
// see libr/core/rtr.c
|
|
// "=h", " port", "listen for http connections (r2 -qc=H /bin/ls)",
|
|
// "=h-", "", "stop background webserver",
|
|
// "=h*", "", "restart current webserver",
|
|
// "=h&", " port", "start http server in background)",
|
|
|
|
if (started) {
|
|
// after this the only reaction to this commands is:
|
|
// sandbox: connect disabled
|
|
// and the webserver is still running
|
|
// TODO: find out why
|
|
core->cmd("=h-");
|
|
} else {
|
|
core->cmd("=h&");
|
|
}
|
|
|
|
// cmd has no usefull return value for this commands, so just toogle the state
|
|
started = !started;
|
|
}
|