Flutter Engine
message_loop.h
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef FLUTTER_FML_MESSAGE_LOOP_H_
6 #define FLUTTER_FML_MESSAGE_LOOP_H_
7 
8 #include "flutter/fml/macros.h"
9 #include "flutter/fml/task_runner.h"
10 
11 namespace fml {
12 
13 class TaskRunner;
14 class MessageLoopImpl;
15 
16 /// An event loop associated with a thread.
17 ///
18 /// This class is the generic front-end to the MessageLoop, differences in
19 /// implementation based on the running platform are in the subclasses of
20 /// flutter::MessageLoopImpl (ex flutter::MessageLoopAndroid).
21 ///
22 /// For scheduling events on the message loop see flutter::TaskRunner.
23 ///
24 /// \see fml::TaskRunner
25 /// \see fml::MessageLoopImpl
26 /// \see fml::MessageLoopTaskQueues
27 /// \see fml::Wakeable
28 class MessageLoop {
29  public:
31  static MessageLoop& GetCurrent();
32 
33  void Run();
34 
35  void Terminate();
36 
37  void AddTaskObserver(intptr_t key, const fml::closure& callback);
38 
39  void RemoveTaskObserver(intptr_t key);
40 
42 
43  // Exposed for the embedder shell which allows clients to poll for events
44  // instead of dedicating a thread to the message loop.
45  void RunExpiredTasksNow();
46 
48 
49  /// Returns true if \p EnsureInitializedForCurrentThread has been called on
50  /// this thread already.
51  static bool IsInitializedForCurrentThread();
52 
53  ~MessageLoop();
54 
55  /// Gets the unique identifier for the TaskQueue associated with the current
56  /// thread.
57  /// \see fml::MessageLoopTaskQueues
59 
60  private:
61  friend class TaskRunner;
62  friend class MessageLoopImpl;
63 
65  fml::RefPtr<fml::TaskRunner> task_runner_;
66 
67  MessageLoop();
68 
69  fml::RefPtr<MessageLoopImpl> GetLoopImpl() const;
70 
72 };
73 
74 } // namespace fml
75 
76 #endif // FLUTTER_FML_MESSAGE_LOOP_H_
void AddTaskObserver(intptr_t key, const fml::closure &callback)
Definition: message_loop.cc:64
static FML_EMBEDDER_ONLY MessageLoop & GetCurrent()
Definition: message_loop.cc:19
static void EnsureInitializedForCurrentThread()
Definition: message_loop.cc:27
FlKeyEvent FlKeyResponderAsyncCallback callback
Definition: ascii_trie.cc:9
fml::RefPtr< fml::TaskRunner > GetTaskRunner() const
Definition: message_loop.cc:56
static TaskQueueId GetCurrentTaskQueueId()
Definition: message_loop.cc:76
std::function< void()> closure
Definition: closure.h:14
void RunExpiredTasksNow()
Definition: message_loop.cc:72
void RemoveTaskObserver(intptr_t key)
Definition: message_loop.cc:68
static bool IsInitializedForCurrentThread()
Definition: message_loop.cc:35
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition: macros.h:27
#define FML_EMBEDDER_ONLY
Definition: macros.h:10