Skip to content

Commit

Permalink
Fix callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
TimSylvester committed Jan 14, 2025
1 parent 0ee7a79 commit b4ebbdf
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 10 deletions.
5 changes: 3 additions & 2 deletions platform/qt/src/mbgl/http_file_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,9 @@ HTTPFileSource::HTTPFileSource(const ResourceOptions& resourceOptions, const Cli

HTTPFileSource::~HTTPFileSource() = default;

std::unique_ptr<AsyncRequest> HTTPFileSource::request(const Resource& resource, Callback callback) {
return std::make_unique<HTTPRequest>(impl.get(), resource, callback);
std::unique_ptr<AsyncRequest> HTTPFileSource::request(const Resource& resource,
FileSource::CopyableCallback<void(Response)> callback) {
return std::make_unique<HTTPRequest>(impl.get(), resource, std::move(callback));
}

void HTTPFileSource::setResourceOptions(ResourceOptions options) {
Expand Down
6 changes: 4 additions & 2 deletions platform/qt/src/mbgl/http_request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@

namespace mbgl {

HTTPRequest::HTTPRequest(HTTPFileSource::Impl* context, const Resource& resource, FileSource::Callback callback)
HTTPRequest::HTTPRequest(HTTPFileSource::Impl* context,
const Resource& resource,
FileSource::CopyableCallback<void(Response)> callback)
: m_context(context),
m_resource(resource),
m_callback(callback) {
m_callback(std::move(callback)) {
m_context->request(this);
}

Expand Down
4 changes: 2 additions & 2 deletions platform/qt/src/mbgl/http_request.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Response;

class HTTPRequest : public AsyncRequest {
public:
HTTPRequest(HTTPFileSource::Impl*, const Resource&, FileSource::Callback);
HTTPRequest(HTTPFileSource::Impl*, const Resource&, FileSource::CopyableCallback<void(Response)>);
virtual ~HTTPRequest();

QUrl requestUrl() const;
Expand All @@ -25,7 +25,7 @@ class HTTPRequest : public AsyncRequest {
private:
HTTPFileSource::Impl* m_context;
Resource m_resource;
FileSource::Callback m_callback;
FileSource::CopyableCallback<void(Response)> m_callback;

bool m_handled = false;
};
Expand Down
2 changes: 1 addition & 1 deletion platform/qt/src/mbgl/run_loop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ void RunLoop::waitForEmpty([[maybe_unused]] const mbgl::util::SimpleIdentity tag
}
}

void RunLoop::addWatch(int fd, Event event, std::function<void(int, Event)>&& cb) {
void RunLoop::addWatch(int fd, Event event, std23::move_only_function<void(int, Event)>&& cb) {
MBGL_VERIFY_THREAD(tid);

if (event == Event::Read || event == Event::ReadWrite) {
Expand Down
2 changes: 1 addition & 1 deletion platform/qt/src/mbgl/run_loop_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
namespace mbgl {
namespace util {

using WatchCallback = std::function<void(int, RunLoop::Event)>;
using WatchCallback = std23::move_only_function<void(int, RunLoop::Event)>;
using WatchPair = std::pair<std::unique_ptr<QSocketNotifier>, WatchCallback>;

class RunLoop::Impl : public QObject {
Expand Down
2 changes: 1 addition & 1 deletion platform/qt/src/utils/scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void Scheduler::schedule(mbgl::util::SimpleIdentity, Task&& function) {
}

void Scheduler::processEvents() {
std::queue<std::function<void()>> taskQueue;
std::queue<Task> taskQueue;
{
const std::unique_lock<std::mutex> lock(m_taskQueueMutex);
std::swap(taskQueue, m_taskQueue);
Expand Down
2 changes: 1 addition & 1 deletion platform/qt/src/utils/scheduler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Scheduler : public QObject, public mbgl::Scheduler {
std::mutex m_taskQueueMutex;
std::condition_variable cvEmpty;
std::atomic<std::size_t> pendingItems;
std::queue<std::function<void()>> m_taskQueue;
std::queue<Task> m_taskQueue;
mapbox::base::WeakPtrFactory<Scheduler> weakFactory{this};
// Do not add members here, see `WeakPtrFactory`
};
Expand Down

0 comments on commit b4ebbdf

Please sign in to comment.