5#include "flutter/runtime/dart_service_isolate.h"
10#include "flutter/fml/logging.h"
11#include "flutter/fml/posix_wrappers.h"
12#include "flutter/runtime/embedder_resources.h"
13#include "third_party/dart/runtime/include/dart_api.h"
18#define RETURN_ERROR_HANDLE(handle) \
19 if (Dart_IsError(handle)) { \
23#define SHUTDOWN_ON_ERROR(handle) \
24 if (Dart_IsError(handle)) { \
25 *error = fml::strdup(Dart_GetError(handle)); \
27 Dart_ShutdownIsolate(); \
36static std::string g_vm_service_uri;
40 bool* auto_setup_scope) {
47 return g_natives->
GetSymbol(native_function);
52std::mutex DartServiceIsolate::callbacks_mutex_;
54std::set<std::unique_ptr<DartServiceIsolate::DartVMServiceServerStateCallback>>
55 DartServiceIsolate::callbacks_;
66 g_vm_service_uri = uri;
70 std::vector<DartServiceIsolate::DartVMServiceServerStateCallback>
73 std::scoped_lock lock(callbacks_mutex_);
75 callbacks_to_fire.push_back(*
callback.get());
79 for (
const auto& callback_to_fire : callbacks_to_fire) {
80 callback_to_fire(uri);
90 auto callback_pointer =
91 std::make_unique<DartServiceIsolate::DartVMServiceServerStateCallback>(
94 auto handle =
reinterpret_cast<CallbackHandle>(callback_pointer.get());
97 std::scoped_lock lock(callbacks_mutex_);
98 callbacks_.insert(std::move(callback_pointer));
101 if (!g_vm_service_uri.empty()) {
110 std::scoped_lock lock(callbacks_mutex_);
111 auto found = std::find_if(
112 callbacks_.begin(), callbacks_.end(),
113 [callback_handle](
const auto& item) {
114 return reinterpret_cast<CallbackHandle>(item.get()) == callback_handle;
117 if (found == callbacks_.end()) {
121 callbacks_.erase(found);
130 intptr_t server_port,
132 bool disable_origin_check,
133 bool disable_service_auth_codes,
134 bool enable_service_port_fallback,
140 g_embedder_tag_handler = embedder_tag_handler;
146 g_natives->Register({
147 {
"VMServiceIO_NotifyServerState", NotifyServerState, 1,
true},
148 {
"VMServiceIO_Shutdown", Shutdown, 0,
true},
168 bool auto_start = server_port >= 0;
169 if (server_port < 0) {
static CallbackHandle AddServerStatusCallback(const DartVMServiceServerStateCallback &callback)
Add a callback that will get invoked when the VM Service starts up. If the VM Service has already sta...
static bool RemoveServerStatusCallback(CallbackHandle handle)
Removed a callback previously registered via AddServiceStatusCallback.
std::function< void(const std::string &vm_service_uri)> DartVMServiceServerStateCallback
static bool Startup(const std::string &server_ip, intptr_t server_port, Dart_LibraryTagHandler embedder_tag_handler, bool disable_origin_check, bool disable_service_auth_codes, bool enable_service_port_fallback, char **error)
Start the service isolate. This call may only be made in the Dart VM initiated isolate creation callb...
const uint8_t * GetSymbol(Dart_NativeFunction native_function)
Dart_NativeFunction GetNativeFunction(Dart_Handle name, int argument_count, bool *auto_setup_scope)
DART_EXPORT DART_WARN_UNUSED_RESULT char * Dart_IsolateMakeRunnable(Dart_Isolate isolate)
DART_EXPORT Dart_Handle Dart_SetNativeResolver(Dart_Handle library, Dart_NativeEntryResolver resolver, Dart_NativeEntrySymbol symbol)
DART_EXPORT void Dart_EnterScope(void)
DART_EXPORT void Dart_ExitScope(void)
DART_EXPORT void Dart_ShutdownIsolate(void)
struct _Dart_Handle * Dart_Handle
struct _Dart_Isolate * Dart_Isolate
DART_EXPORT Dart_Handle Dart_LookupLibrary(Dart_Handle url)
struct _Dart_NativeArguments * Dart_NativeArguments
DART_EXPORT DART_WARN_UNUSED_RESULT Dart_Handle Dart_SetField(Dart_Handle container, Dart_Handle name, Dart_Handle value)
DART_EXPORT Dart_Isolate Dart_CurrentIsolate(void)
DART_EXPORT Dart_Handle Dart_NewStringFromCString(const char *str)
void(* Dart_NativeFunction)(Dart_NativeArguments arguments)
DART_EXPORT Dart_Handle Dart_NewInteger(int64_t value)
Dart_Handle(* Dart_LibraryTagHandler)(Dart_LibraryTag tag, Dart_Handle library_or_package_map_url, Dart_Handle url)
DART_EXPORT Dart_Handle Dart_NewBoolean(bool value)
DART_EXPORT void Dart_EnterIsolate(Dart_Isolate isolate)
DART_EXPORT void Dart_ExitIsolate(void)
DART_EXPORT Dart_Handle Dart_RootLibrary(void)
DART_EXPORT Dart_Handle Dart_SetRootLibrary(Dart_Handle library)
#define SHUTDOWN_ON_ERROR(handle)
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
const uint8_t uint32_t uint32_t GError ** error
#define FML_CHECK(condition)
DEF_SWITCHES_START aot vmservice shared library name