diff options
author | 2023-10-25 09:09:07 -0700 | |
---|---|---|
committer | 2023-11-09 10:15:51 -0800 | |
commit | 815e6381ec261da89175284108520ab962af2414 (patch) | |
tree | b157b7e2fc11fefa387780f665d74609a307a7f2 | |
parent | b7016244c9f70fc8389a6d0c87cb9e4f4578fbd8 (diff) |
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
-rw-r--r-- | system/common/message_loop_thread.h | 43 | ||||
-rw-r--r-- | system/gd/common/contextual_callback.h | 6 |
2 files changed, 45 insertions, 4 deletions
diff --git a/system/common/message_loop_thread.h b/system/common/message_loop_thread.h index 342cf15ace..2f0c5a3517 100644 --- a/system/common/message_loop_thread.h +++ b/system/common/message_loop_thread.h @@ -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 diff --git a/system/gd/common/contextual_callback.h b/system/gd/common/contextual_callback.h index 87ffc3e861..af4929663a 100644 --- a/system/gd/common/contextual_callback.h +++ b/system/gd/common/contextual_callback.h @@ -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 { |