Skip to content

Commit

Permalink
boostification of domainmap cpp (#47832)
Browse files Browse the repository at this point in the history
* boostification of domainmap cpp
  • Loading branch information
sima-fastly authored Dec 13, 2023
1 parent 9f75a36 commit ec53d00
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
26 changes: 16 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);
}

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

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

public slots:
void doChanged()
{
changed();
}

void start()
{
if(!fileName.isEmpty())
Expand All @@ -316,7 +320,7 @@ public slots:
reload();
}

emit started();
started();
}

void fileChanged(const QString &path)
Expand Down Expand Up @@ -732,13 +736,13 @@ class DomainMap::Thread : public QThread
{
worker = new Worker;
worker->fileName = fileName;
connect(worker, &Worker::started, this, &Thread::worker_started, Qt::DirectConnection);
Connection 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 +754,8 @@ class DomainMap::Private : public QObject
{
Q_OBJECT

Connection changedConnection;

public:
DomainMap *q;
Thread *thread;
Expand All @@ -773,13 +779,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

0 comments on commit ec53d00

Please sign in to comment.