Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 815e6381 authored by Myles Watson's avatar Myles Watson
Browse files

Add ContextualCallback to message_loop_thread

This is just syntactic sugar for posting to the main message loop.

Bug: 301661850
Test: mma -j32
Change-Id: Idc820c0edca3644b2eba7ff031535710d307d7c3
parent b7016244
Loading
Loading
Loading
Loading
+42 −1
Original line number Diff line number Diff line
@@ -23,11 +23,11 @@
#include <unistd.h>

#include <future>
#include <memory>
#include <string>
#include <thread>

#include "abstract_message_loop.h"
#include "gd/common/contextual_callback.h"
#include "gd/common/i_postable_context.h"

namespace bluetooth {
@@ -172,6 +172,47 @@ class MessageLoopThread final : public IPostableContext {
   */
  void Post(base::OnceClosure closure) override;

  template <typename Functor, typename... Args>
  common::ContextualOnceCallback<common::MakeUnboundRunType<Functor, Args...>>
  BindOnce(Functor&& functor, Args&&... args) {
    return common::ContextualOnceCallback<
        common::MakeUnboundRunType<Functor, Args...>>(
        common::BindOnce(std::forward<Functor>(functor),
                         std::forward<Args>(args)...),
        this);
  }

  template <typename Functor, typename T, typename... Args>
  common::ContextualOnceCallback<
      common::MakeUnboundRunType<Functor, T, Args...>>
  BindOnceOn(T* obj, Functor&& functor, Args&&... args) {
    return common::ContextualOnceCallback<
        common::MakeUnboundRunType<Functor, T, Args...>>(
        common::BindOnce(std::forward<Functor>(functor),
                         common::Unretained(obj), std::forward<Args>(args)...),
        this);
  }

  template <typename Functor, typename... Args>
  common::ContextualCallback<common::MakeUnboundRunType<Functor, Args...>> Bind(
      Functor&& functor, Args&&... args) {
    return common::ContextualCallback<
        common::MakeUnboundRunType<Functor, Args...>>(
        common::Bind(std::forward<Functor>(functor),
                     std::forward<Args>(args)...),
        this);
  }

  template <typename Functor, typename T, typename... Args>
  common::ContextualCallback<common::MakeUnboundRunType<Functor, T, Args...>>
  BindOn(T* obj, Functor&& functor, Args&&... args) {
    return common::ContextualCallback<
        common::MakeUnboundRunType<Functor, T, Args...>>(
        common::Bind(std::forward<Functor>(functor), common::Unretained(obj),
                     std::forward<Args>(args)...),
        this);
  }

 private:
  /**
   * Static method to run the thread
+3 −3
Original line number Diff line number Diff line
@@ -16,9 +16,9 @@

#pragma once

#include "common/bind.h"
#include "common/callback.h"
#include "common/i_postable_context.h"
#include "bind.h"
#include "callback.h"
#include "i_postable_context.h"

namespace bluetooth {
namespace common {