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 | class MessageLoop { |
17 | public: |
18 | FML_EMBEDDER_ONLY |
19 | static MessageLoop& GetCurrent(); |
20 | |
21 | bool IsValid() const; |
22 | |
23 | void Run(); |
24 | |
25 | void Terminate(); |
26 | |
27 | void AddTaskObserver(intptr_t key, const fml::closure& callback); |
28 | |
29 | void RemoveTaskObserver(intptr_t key); |
30 | |
31 | fml::RefPtr<fml::TaskRunner> GetTaskRunner() const; |
32 | |
33 | // Exposed for the embedder shell which allows clients to poll for events |
34 | // instead of dedicating a thread to the message loop. |
35 | void RunExpiredTasksNow(); |
36 | |
37 | static void EnsureInitializedForCurrentThread(); |
38 | |
39 | static bool IsInitializedForCurrentThread(); |
40 | |
41 | ~MessageLoop(); |
42 | |
43 | static TaskQueueId GetCurrentTaskQueueId(); |
44 | |
45 | private: |
46 | friend class TaskRunner; |
47 | friend class MessageLoopImpl; |
48 | |
49 | fml::RefPtr<MessageLoopImpl> loop_; |
50 | fml::RefPtr<fml::TaskRunner> task_runner_; |
51 | |
52 | MessageLoop(); |
53 | |
54 | fml::RefPtr<MessageLoopImpl> GetLoopImpl() const; |
55 | |
56 | FML_DISALLOW_COPY_AND_ASSIGN(MessageLoop); |
57 | }; |
58 | |
59 | } // namespace fml |
60 | |
61 | #endif // FLUTTER_FML_MESSAGE_LOOP_H_ |
62 | |