Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
tonic::DartMessageHandler Class Reference

#include <dart_message_handler.h>

Public Types

using TaskDispatcher = std::function< void(std::function< void(void)>)>
 

Public Member Functions

 DartMessageHandler ()
 
 ~DartMessageHandler ()
 
void Initialize (TaskDispatcher dispatcher)
 
void UnhandledError (Dart_Handle error)
 
bool isolate_exited () const
 
bool isolate_had_uncaught_exception_error () const
 
DartErrorHandleType isolate_last_error () const
 

Protected Member Functions

void OnMessage (DartState *dart_state)
 
void OnHandleMessage (DartState *dart_state)
 
bool handled_first_message () const
 
void set_handled_first_message (bool handled_first_message)
 

Protected Attributes

bool handled_first_message_
 
bool isolate_exited_
 
bool isolate_had_uncaught_exception_error_
 
bool isolate_had_fatal_error_
 
DartErrorHandleType isolate_last_error_
 
TaskDispatcher task_dispatcher_
 

Detailed Description

Definition at line 16 of file dart_message_handler.h.

Member Typedef Documentation

◆ TaskDispatcher

using tonic::DartMessageHandler::TaskDispatcher = std::function<void(std::function<void(void)>)>

Definition at line 18 of file dart_message_handler.h.

Constructor & Destructor Documentation

◆ DartMessageHandler()

tonic::DartMessageHandler::DartMessageHandler ( )

◆ ~DartMessageHandler()

tonic::DartMessageHandler::~DartMessageHandler ( )

Definition at line 24 of file dart_message_handler.cc.

24 {
25 task_dispatcher_ = nullptr;
26}

Member Function Documentation

◆ handled_first_message()

bool tonic::DartMessageHandler::handled_first_message ( ) const
inlineprotected

Definition at line 47 of file dart_message_handler.h.

47{ return handled_first_message_; }

◆ Initialize()

void tonic::DartMessageHandler::Initialize ( TaskDispatcher  dispatcher)

Definition at line 28 of file dart_message_handler.cc.

28 {
29 // Only can be called once.
30 TONIC_CHECK(!task_dispatcher_ && dispatcher);
31 task_dispatcher_ = dispatcher;
32 Dart_SetMessageNotifyCallback(MessageNotifyCallback);
33}
DART_EXPORT void Dart_SetMessageNotifyCallback(Dart_MessageNotifyCallback message_notify_callback)
#define TONIC_CHECK(condition)
Definition macros.h:23

◆ isolate_exited()

bool tonic::DartMessageHandler::isolate_exited ( ) const
inline

Definition at line 32 of file dart_message_handler.h.

32{ return isolate_exited_; }

◆ isolate_had_uncaught_exception_error()

bool tonic::DartMessageHandler::isolate_had_uncaught_exception_error ( ) const
inline

Definition at line 35 of file dart_message_handler.h.

◆ isolate_last_error()

DartErrorHandleType tonic::DartMessageHandler::isolate_last_error ( ) const
inline

Definition at line 39 of file dart_message_handler.h.

39{ return isolate_last_error_; }

◆ OnHandleMessage()

void tonic::DartMessageHandler::OnHandleMessage ( DartState dart_state)
protected

Definition at line 63 of file dart_message_handler.cc.

63 {
65 // Don't handle any more messages.
66 return;
67 }
68
69 DartIsolateScope scope(dart_state->isolate());
70 DartApiScope dart_api_scope;
72 bool error = false;
73
74 // On the first message, check if we should pause on isolate start.
75 if (!handled_first_message()) {
78 // Mark that we are paused on isolate start.
80 }
81 }
82
84 // We are paused on isolate start. Only handle service messages until we are
85 // requested to resume.
87 bool resume = Dart_HandleServiceMessages();
88 if (!resume) {
89 return;
90 }
92 // We've resumed, handle normal messages that are in the queue.
95 dart_state->MessageEpilogue(result);
96 if (!Dart_CurrentIsolate()) {
97 isolate_exited_ = true;
98 return;
99 }
100 }
101 } else if (Dart_IsPausedOnExit()) {
102 // We are paused on isolate exit. Only handle service messages until we are
103 // requested to resume.
105 bool resume = Dart_HandleServiceMessages();
106 if (!resume) {
107 return;
108 }
110 }
111 } else {
112 // We are processing messages normally.
114 // If the Dart program has set a return code, then it is intending to shut
115 // down by way of a fatal error, and so there is no need to emit a log
116 // message.
117 if (dart_state->has_set_return_code() && Dart_IsError(result) &&
119 error = true;
120 } else {
122 }
123 dart_state->MessageEpilogue(result);
124 if (!Dart_CurrentIsolate()) {
125 isolate_exited_ = true;
126 return;
127 }
128 }
129
130 if (error) {
132 } else if (!Dart_HasLivePorts()) {
133 // The isolate has no live ports and would like to exit.
135 // Mark that we are paused on exit.
137 } else {
138 isolate_exited_ = true;
139 }
140 }
141}
void UnhandledError(Dart_Handle error)
void set_handled_first_message(bool handled_first_message)
DART_EXPORT void Dart_SetPausedOnExit(bool paused)
DART_EXPORT void Dart_SetPausedOnStart(bool paused)
DART_EXPORT bool Dart_HandleServiceMessages(void)
DART_EXPORT bool Dart_HasServiceMessages(void)
DART_EXPORT bool Dart_ShouldPauseOnExit(void)
struct _Dart_Handle * Dart_Handle
Definition dart_api.h:258
DART_EXPORT bool Dart_IsPausedOnExit(void)
DART_EXPORT bool Dart_IsPausedOnStart(void)
DART_EXPORT bool Dart_IsFatalError(Dart_Handle handle)
DART_EXPORT Dart_Isolate Dart_CurrentIsolate(void)
DART_EXPORT Dart_Handle Dart_Null(void)
DART_EXPORT bool Dart_IsError(Dart_Handle handle)
DART_EXPORT bool Dart_ShouldPauseOnStart(void)
DART_EXPORT bool Dart_HasLivePorts(void)
DART_EXPORT DART_WARN_UNUSED_RESULT Dart_Handle Dart_HandleMessage(void)
const uint8_t uint32_t uint32_t GError ** error
GAsyncResult * result
bool CheckAndHandleError(Dart_Handle handle)
Definition dart_error.cc:33

◆ OnMessage()

void tonic::DartMessageHandler::OnMessage ( DartState dart_state)
protected

Definition at line 35 of file dart_message_handler.cc.

35 {
36 auto task_dispatcher_ = dart_state->message_handler().task_dispatcher_;
37
38 // Schedule a task to run on the message loop thread.
39 auto weak_dart_state = dart_state->GetWeakPtr();
40 task_dispatcher_([weak_dart_state]() {
41 if (auto dart_state = weak_dart_state.lock()) {
42 dart_state->message_handler().OnHandleMessage(dart_state.get());
43 }
44 });
45}

◆ set_handled_first_message()

void tonic::DartMessageHandler::set_handled_first_message ( bool  handled_first_message)
inlineprotected

Definition at line 49 of file dart_message_handler.h.

◆ UnhandledError()

void tonic::DartMessageHandler::UnhandledError ( Dart_Handle  error)

Definition at line 47 of file dart_message_handler.cc.

47 {
50
52 // Remember that we had an uncaught exception error.
56 // Stop handling messages.
58 // Shut down the isolate.
60 }
61}
DART_EXPORT void Dart_ShutdownIsolate(void)
DartErrorHandleType GetErrorHandleType(Dart_Handle handle)
Definition dart_error.cc:56
#define TONIC_DCHECK
Definition macros.h:32

Member Data Documentation

◆ handled_first_message_

bool tonic::DartMessageHandler::handled_first_message_
protected

Definition at line 53 of file dart_message_handler.h.

◆ isolate_exited_

bool tonic::DartMessageHandler::isolate_exited_
protected

Definition at line 54 of file dart_message_handler.h.

◆ isolate_had_fatal_error_

bool tonic::DartMessageHandler::isolate_had_fatal_error_
protected

Definition at line 56 of file dart_message_handler.h.

◆ isolate_had_uncaught_exception_error_

bool tonic::DartMessageHandler::isolate_had_uncaught_exception_error_
protected

Definition at line 55 of file dart_message_handler.h.

◆ isolate_last_error_

DartErrorHandleType tonic::DartMessageHandler::isolate_last_error_
protected

Definition at line 57 of file dart_message_handler.h.

◆ task_dispatcher_

TaskDispatcher tonic::DartMessageHandler::task_dispatcher_
protected

Definition at line 58 of file dart_message_handler.h.


The documentation for this class was generated from the following files: