Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | List of all members
dart_runner::DartComponentController Class Reference

Starts a Dart component written in CFv2. More...

#include <dart_component_controller.h>

Inheritance diagram for dart_runner::DartComponentController:

Public Member Functions

 DartComponentController (fuchsia::component::runner::ComponentStartInfo start_info, std::shared_ptr< sys::ServiceDirectory > runner_incoming_services, fidl::InterfaceRequest< fuchsia::component::runner::ComponentController > controller)
 
 ~DartComponentController () override
 
bool SetUp ()
 
void Run ()
 

Private Member Functions

void EchoString (fidl::StringPtr value, EchoStringCallback callback) override
 
void Kill () override
 
void Stop () override
 

Detailed Description

Starts a Dart component written in CFv2.

Definition at line 29 of file dart_component_controller.h.

Constructor & Destructor Documentation

◆ DartComponentController()

dart_runner::DartComponentController::DartComponentController ( fuchsia::component::runner::ComponentStartInfo  start_info,
std::shared_ptr< sys::ServiceDirectory >  runner_incoming_services,
fidl::InterfaceRequest< fuchsia::component::runner::ComponentController >  controller 
)

Definition at line 100 of file dart_component_controller.cc.

105 : loop_(new async::Loop(&kLoopConfig)),
106 label_(GetLabelFromUrl(start_info.resolved_url())),
107 url_(start_info.resolved_url()),
108 runner_incoming_services_(std::move(runner_incoming_services)),
109 dart_outgoing_dir_(new vfs::PseudoDir()),
110 start_info_(std::move(start_info)),
111 binding_(this, std::move(controller)) {
112 binding_.set_error_handler([this](zx_status_t status) { Kill(); });
113
114 // TODO(fxb/84537): This data path is configured based how we build Flutter
115 // applications in tree currently, but the way we build the Flutter
116 // application may change. We should avoid assuming the data path and let the
117 // CML file specify this data path instead.
118 const std::string component_name = GetComponentNameFromUrl(url_);
119 data_path_ = "pkg/data/" + component_name;
120
121 zx_status_t idle_timer_status =
122 zx::timer::create(ZX_TIMER_SLACK_LATE, ZX_CLOCK_MONOTONIC, &idle_timer_);
123 if (idle_timer_status != ZX_OK) {
124 FML_LOG(INFO) << "Idle timer creation failed: "
125 << zx_status_get_string(idle_timer_status);
126 } else {
127 idle_wait_.set_object(idle_timer_.get());
128 idle_wait_.set_trigger(ZX_TIMER_SIGNALED);
129 idle_wait_.Begin(async_get_default_dispatcher());
130 }
131
132 // Close the runtime_dir channel if we don't intend to serve it. Otherwise any
133 // access to the runtime_dir will hang forever.
134 start_info_.clear_runtime_dir();
135}
#define FML_LOG(severity)
Definition logging.h:82

◆ ~DartComponentController()

dart_runner::DartComponentController::~DartComponentController ( )
override

Definition at line 137 of file dart_component_controller.cc.

137 {
138 if (namespace_) {
139 fdio_ns_destroy(namespace_);
140 namespace_ = nullptr;
141 }
142 close(stdout_fd_);
143 close(stderr_fd_);
144}

Member Function Documentation

◆ EchoString()

void dart_runner::DartComponentController::EchoString ( fidl::StringPtr  value,
EchoStringCallback  callback 
)
overrideprivate

Definition at line 538 of file dart_component_controller.cc.

539 {
541
542 Dart_Handle builtin_lib = Dart_LookupLibrary(ToDart("dart:fuchsia.builtin"));
544
545 Dart_Handle receive_echo_string = ToDart("_receiveEchoString");
546 Dart_Handle string_to_echo =
547 value.has_value() ? tonic::ToDart(*value) : Dart_Null();
549 Dart_Invoke(builtin_lib, receive_echo_string, 1, &string_to_echo);
551
552 fidl::StringPtr echo_string;
553 if (!Dart_IsNull(result)) {
554 echo_string = tonic::StdStringFromDart(result);
555 }
556 callback(std::move(echo_string));
557
559}
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_WARN_UNUSED_RESULT Dart_Handle Dart_Invoke(Dart_Handle target, Dart_Handle name, int number_of_arguments, Dart_Handle *arguments)
DART_EXPORT Dart_Handle Dart_LookupLibrary(Dart_Handle url)
DART_EXPORT Dart_Handle Dart_Null(void)
DART_EXPORT bool Dart_IsNull(Dart_Handle object)
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
uint8_t value
GAsyncResult * result
#define FML_CHECK(condition)
Definition logging.h:85
Dart_Handle ToDart(const T &object)
bool CheckAndHandleError(Dart_Handle handle)
Definition dart_error.cc:33
std::string StdStringFromDart(Dart_Handle handle)

◆ Kill()

void dart_runner::DartComponentController::Kill ( )
overrideprivate

Definition at line 561 of file dart_component_controller.cc.

561 {
562 if (Dart_CurrentIsolate()) {
565 if (queue) {
566 queue->Destroy();
567 }
568
569 loop_->Quit();
570
571 // TODO(rosswang): The docs warn of threading issues if doing this again,
572 // but without this, attempting to shut down the isolate finalizes app
573 // contexts that can't tell a shutdown is in progress and so fatal.
575
577 }
578}
static DartMicrotaskQueue * GetForCurrentThread()
DART_EXPORT void Dart_ShutdownIsolate(void)
DART_EXPORT Dart_Isolate Dart_CurrentIsolate(void)
DART_EXPORT void Dart_SetMessageNotifyCallback(Dart_MessageNotifyCallback message_notify_callback)
VkQueue queue
Definition main.cc:55

◆ Run()

void dart_runner::DartComponentController::Run ( )

Runs the Dart component in a task, sending the return code back to the Fuchsia component controller.

This should be called after |SetUp|.

Definition at line 428 of file dart_component_controller.cc.

428 {
429 async::PostTask(loop_->dispatcher(), [loop = loop_.get(), app = this] {
430 if (!app->RunDartMain()) {
431 loop->Quit();
432 }
433 });
434 loop_->Run();
435
436 if (binding_.is_bound()) {
437 // From the documentation for ComponentController, ZX_OK should be sent when
438 // the ComponentController receives a termination request. However, if the
439 // component exited with a non-zero return code, we indicate this by sending
440 // an INTERNAL epitaph instead.
441 //
442 // TODO(fxb/86666): Communicate return code from the ComponentController
443 // once v2 has support.
444 if (return_code_ == 0) {
445 binding_.Close(ZX_OK);
446 } else {
447 FML_LOG(ERROR) << "Component exited with non-zero return code: "
448 << return_code_;
449 binding_.Close(zx_status_t(fuchsia::component::Error::INTERNAL));
450 }
451 }
452}
#define ERROR(message)

◆ SetUp()

bool dart_runner::DartComponentController::SetUp ( )

Sets up the controller.

This should be called before |Run|.

Definition at line 146 of file dart_component_controller.cc.

146 {
147 // Name the thread after the url of the component being launched.
148 zx::thread::self()->set_property(ZX_PROP_NAME, label_.c_str(), label_.size());
149 Dart_SetThreadName(label_.c_str());
150
151 if (!CreateAndBindNamespace()) {
152 return false;
153 }
154
155 if (SetUpFromAppSnapshot()) {
156 FML_LOG(INFO) << url_ << " is running from an app snapshot";
157 } else if (SetUpFromKernel()) {
158 FML_LOG(INFO) << url_ << " is running from kernel";
159 } else {
160 FML_LOG(ERROR) << "Failed to set up component controller for " << url_;
161 return false;
162 }
163
164 return true;
165}
DART_EXPORT void Dart_SetThreadName(const char *name)

◆ Stop()

void dart_runner::DartComponentController::Stop ( )
overrideprivate

Definition at line 580 of file dart_component_controller.cc.

580 {
581 Kill();
582}

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