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

Commit 71617d70 authored by Zach Johnson's avatar Zach Johnson Committed by Hansong Zhang
Browse files

Add syntactic sugar Call and CallOn to handler

Wire module's version to them, to save on code.

This will allow us to skip the Bind -> invoke step.

Test: cert/run --host
Tag: #gd-refactor
Bug: 156859507
Change-Id: I553a6b61f23110a972c9293e4679b8924032689c
parent 50933b2c
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -102,13 +102,12 @@ class Module {

  template <typename Functor, typename... Args>
  void Call(Functor&& functor, Args&&... args) {
    GetHandler()->Post(common::BindOnce(std::forward<Functor>(functor), std::forward<Args>(args)...));
    GetHandler()->Call(std::forward<Functor>(functor), std::forward<Args>(args)...);
  }

  template <typename T, typename Functor, typename... Args>
  void CallOn(T* obj, Functor&& functor, Args&&... args) {
    GetHandler()->Post(
        common::BindOnce(std::forward<Functor>(functor), common::Unretained(obj), std::forward<Args>(args)...));
    GetHandler()->CallOn(obj, std::forward<Functor>(functor), std::forward<Args>(args)...);
  }

 private:
+10 −0
Original line number Diff line number Diff line
@@ -52,6 +52,16 @@ class Handler : public common::IPostableContext {
  // Die if the current reactable doesn't stop before the timeout.  Must be called after Clear()
  void WaitUntilStopped(std::chrono::milliseconds timeout);

  template <typename Functor, typename... Args>
  void Call(Functor&& functor, Args&&... args) {
    Post(common::BindOnce(std::forward<Functor>(functor), std::forward<Args>(args)...));
  }

  template <typename T, typename Functor, typename... Args>
  void CallOn(T* obj, Functor&& functor, Args&&... args) {
    Post(common::BindOnce(std::forward<Functor>(functor), common::Unretained(obj), std::forward<Args>(args)...));
  }

  template <typename Functor, typename... Args>
  common::ContextualOnceCallback<common::MakeUnboundRunType<Functor, Args...>> BindOnce(
      Functor&& functor, Args&&... args) {