Flutter Engine
The Flutter Engine
dart_state.cc
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#include "tonic/dart_state.h"
6
11
12namespace tonic {
13
15 : scope_(dart_state->isolate()) {}
16
17DartState::Scope::Scope(std::shared_ptr<DartState> dart_state)
18 : scope_(dart_state->isolate()) {}
19
21
23 std::function<void(Dart_Handle)> message_epilogue)
24 : isolate_(nullptr),
25 private_constructor_name_(),
26 class_library_(new DartClassLibrary),
27 message_handler_(new DartMessageHandler()),
28 file_loader_(new FileLoader(dirfd)),
29 message_epilogue_(message_epilogue),
30 has_set_return_code_(false),
31 is_shutting_down_(false) {}
32
34
36 isolate_ = isolate;
37
38 if (!isolate_)
39 return;
40
41 private_constructor_name_.Clear();
43 private_constructor_name_.Set(
46
48}
49
51 auto isolate_data =
52 static_cast<std::shared_ptr<DartState>*>(Dart_IsolateData(isolate));
53 return isolate_data->get();
54}
55
57 auto isolate_data =
58 static_cast<std::shared_ptr<DartState>*>(Dart_CurrentIsolateData());
59 return isolate_data ? isolate_data->get() : nullptr;
60}
61
62std::weak_ptr<DartState> DartState::GetWeakPtr() {
63 return shared_from_this();
64}
65
66void DartState::SetReturnCode(uint32_t return_code) {
67 if (set_return_code_callback_) {
68 set_return_code_callback_(return_code);
69 }
70 has_set_return_code_ = true;
71}
72
74 set_return_code_callback_ = callback;
75}
76
78
80 Dart_Handle library,
81 Dart_Handle url) {
82 return Current()->file_loader().HandleLibraryTag(tag, library, url);
83}
84
85} // namespace tonic
void Set(DartState *dart_state, Dart_Handle value)
Scope(DartState *dart_state)
Definition: dart_state.cc:14
virtual void DidSetIsolate()
Definition: dart_state.cc:77
void SetReturnCode(uint32_t return_code)
Definition: dart_state.cc:66
Dart_Isolate isolate()
Definition: dart_state.h:51
static DartState * From(Dart_Isolate isolate)
Definition: dart_state.cc:50
virtual ~DartState()
Definition: dart_state.cc:33
void SetIsolate(Dart_Isolate isolate)
Definition: dart_state.cc:35
DartState(int dirfd=-1, std::function< void(Dart_Handle)> message_epilogue=nullptr)
Definition: dart_state.cc:22
FileLoader & file_loader()
Definition: dart_state.h:62
void SetReturnCodeCallback(std::function< void(uint32_t)> callback)
Definition: dart_state.cc:73
std::weak_ptr< DartState > GetWeakPtr()
Definition: dart_state.cc:62
static DartState * Current()
Definition: dart_state.cc:56
static Dart_Handle HandleLibraryTag(Dart_LibraryTag tag, Dart_Handle library, Dart_Handle url)
Definition: dart_state.cc:79
Dart_Handle HandleLibraryTag(Dart_LibraryTag tag, Dart_Handle library, Dart_Handle url)
Definition: file_loader.cc:118
DART_EXPORT void * Dart_CurrentIsolateData(void)
DART_EXPORT void Dart_EnterScope(void)
DART_EXPORT void Dart_ExitScope(void)
struct _Dart_Handle * Dart_Handle
Definition: dart_api.h:258
DART_EXPORT Dart_PersistentHandle Dart_NewPersistentHandle(Dart_Handle object)
struct _Dart_Isolate * Dart_Isolate
Definition: dart_api.h:88
Dart_LibraryTag
Definition: dart_api.h:3419
DART_EXPORT void * Dart_IsolateData(Dart_Isolate isolate)
DART_EXPORT Dart_Handle Dart_NewStringFromCString(const char *str)
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
Dart_NativeFunction function
Definition: fuchsia.cc:51