forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 2
/
dart_message_handler.h
66 lines (47 loc) · 1.93 KB
/
dart_message_handler.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef LIB_TONIC_DART_MESSAGE_HANDLER_H_
#define LIB_TONIC_DART_MESSAGE_HANDLER_H_
#include <functional>
#include "third_party/dart/runtime/include/dart_api.h"
#include "tonic/logging/dart_error.h"
namespace tonic {
class DartState;
class DartMessageHandler {
public:
using TaskDispatcher = std::function<void(std::function<void(void)>)>;
DartMessageHandler();
~DartMessageHandler();
// Messages for the current isolate will be scheduled on |runner|.
void Initialize(TaskDispatcher dispatcher);
// Handle an unhandled error. If the error is fatal then shut down the
// isolate. The message handler's isolate must be the current isolate.
void UnhandledError(Dart_Handle error);
// Did the isolate exit?
bool isolate_exited() const { return isolate_exited_; }
// Did the isolate have an uncaught exception error?
bool isolate_had_uncaught_exception_error() const {
return isolate_had_uncaught_exception_error_;
}
DartErrorHandleType isolate_last_error() const { return isolate_last_error_; }
protected:
// Called from an unknown thread for each message.
void OnMessage(DartState* dart_state);
// By default, called on the task runner's thread for each message.
void OnHandleMessage(DartState* dart_state);
bool handled_first_message() const { return handled_first_message_; }
void set_handled_first_message(bool handled_first_message) {
handled_first_message_ = handled_first_message;
}
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_;
private:
static void MessageNotifyCallback(Dart_Isolate dest_isolate);
};
} // namespace tonic
#endif // LIB_TONIC_DART_MESSAGE_HANDLER_H_