Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

boostification of domainmap cpp #47832

Merged
merged 3 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions src/cpp/proxy/domainmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ class DomainMap::Worker : public QObject

log_info("routes loaded with %d entries", allRules.count());

QMetaObject::invokeMethod(this, "changed", Qt::QueuedConnection);
QMetaObject::invokeMethod(this, "doChanged", Qt::QueuedConnection);
sima-fastly marked this conversation as resolved.
Show resolved Hide resolved
}

// mutex must be locked when calling this method
Expand All @@ -301,9 +301,8 @@ class DomainMap::Worker : public QObject
return true;
}

signals:
void started();
void changed();
Signal started;
Signal changed;

public slots:
void start()
Expand All @@ -316,7 +315,7 @@ public slots:
reload();
}

emit started();
started();
}

void fileChanged(const QString &path)
Expand Down Expand Up @@ -709,6 +708,8 @@ class DomainMap::Thread : public QThread
{
Q_OBJECT

Connection startedConnection;
sima-fastly marked this conversation as resolved.
Show resolved Hide resolved

public:
QString fileName;
Worker *worker;
Expand All @@ -732,13 +733,13 @@ class DomainMap::Thread : public QThread
{
worker = new Worker;
worker->fileName = fileName;
connect(worker, &Worker::started, this, &Thread::worker_started, Qt::DirectConnection);
startedConnection = worker->started.connect(boost::bind(&Thread::worker_started, this));
QMetaObject::invokeMethod(worker, "start", Qt::QueuedConnection);
exec();
delete worker;
}

public slots:
public:
void worker_started()
{
QMutexLocker locker(&m);
Expand All @@ -750,6 +751,8 @@ class DomainMap::Private : public QObject
{
Q_OBJECT

Connection changedConnection;

public:
DomainMap *q;
Thread *thread;
Expand All @@ -773,13 +776,13 @@ class DomainMap::Private : public QObject
thread->start();

// worker guaranteed to exist after starting
connect(thread->worker, &Worker::changed, this, &Private::doChanged);
changedConnection = thread->worker->changed.connect(boost::bind(&Private::doChanged, this));
}

public slots:
public:
void doChanged()
{
emit q->changed();
q->changed();
}
};

Expand Down
1 change: 1 addition & 0 deletions src/cpp/proxy/domainmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <boost/signals2.hpp>

using Signal = boost::signals2::signal<void()>;
using Connection = boost::signals2::scoped_connection;

// this class offers fast access to the routes file. the table is maintained
// by a background thread so that file access doesn't cause blocking.
Expand Down
Loading