Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Namespaces | Macros | Functions
fuchsia.cc File Reference
#include "dart-pkg/fuchsia/sdk_ext/fuchsia.h"
#include <zircon/syscalls.h>
#include <cstdio>
#include <cstring>
#include <memory>
#include <vector>
#include "dart-pkg/zircon/sdk_ext/handle.h"
#include "dart-pkg/zircon/sdk_ext/natives.h"
#include "dart-pkg/zircon/sdk_ext/system.h"
#include "flutter/fml/size.h"
#include "third_party/dart/runtime/include/dart_api.h"
#include "third_party/tonic/dart_binding_macros.h"
#include "third_party/tonic/dart_class_library.h"
#include "third_party/tonic/dart_class_provider.h"
#include "third_party/tonic/dart_library_natives.h"
#include "third_party/tonic/dart_state.h"
#include "third_party/tonic/logging/dart_invoke.h"
#include "third_party/tonic/typed_data/typed_list.h"

Go to the source code of this file.

Namespaces

namespace  fuchsia
 
namespace  fuchsia::dart
 

Macros

#define REGISTER_FUNCTION(name, count)   {"" #name, name, count},
 
#define DECLARE_FUNCTION(name, count)    extern void name(Dart_NativeArguments args);
 
#define FIDL_NATIVE_LIST(V)   V(SetReturnCode, 1)
 

Functions

void fuchsia::dart::Initialize (zx::channel directory_request, std::optional< zx::eventpair > view_ref)
 Initializes Dart bindings for the Fuchsia application model.
 

Macro Definition Documentation

◆ DECLARE_FUNCTION

#define DECLARE_FUNCTION (   name,
  count 
)     extern void name(Dart_NativeArguments args);

Definition at line 42 of file fuchsia.cc.

48 {
49 const char* name;
50 Dart_NativeFunction function;
52} Entries[] = {FIDL_NATIVE_LIST(REGISTER_FUNCTION)};
53
56 bool* auto_setup_scope) {
57 const char* function_name = nullptr;
59 if (Dart_IsError(result)) {
61 }
62 FML_DCHECK(function_name != nullptr);
63 FML_DCHECK(auto_setup_scope != nullptr);
64 *auto_setup_scope = true;
65 size_t num_entries = fml::size(Entries);
66 for (size_t i = 0; i < num_entries; ++i) {
67 const struct NativeEntries& entry = Entries[i];
68 if (!strcmp(function_name, entry.name) &&
69 (entry.argument_count == argument_count)) {
70 return entry.function;
71 }
72 }
73 if (!g_natives)
74 g_natives = InitNatives();
75 return g_natives->GetNativeFunction(name, argument_count, auto_setup_scope);
76}
77
78const uint8_t* NativeSymbol(Dart_NativeFunction native_function) {
79 size_t num_entries = fml::size(Entries);
80 for (size_t i = 0; i < num_entries; ++i) {
81 const struct NativeEntries& entry = Entries[i];
82 if (entry.function == native_function) {
83 return reinterpret_cast<const uint8_t*>(entry.name);
84 }
85 }
86 if (!g_natives)
87 g_natives = InitNatives();
88 return g_natives->GetSymbol(native_function);
89}
90
91void SetReturnCode(Dart_NativeArguments arguments) {
92 int64_t return_code;
93 Dart_Handle status =
94 Dart_GetNativeIntegerArgument(arguments, 0, &return_code);
95 if (!tonic::CheckAndHandleError(status)) {
97 }
98}
99
100} // namespace
101
102void Initialize(zx::channel directory_request,
103 std::optional<zx::eventpair> view_ref) {
105
106 Dart_Handle library = Dart_LookupLibrary(ToDart("dart:fuchsia"));
109 library, fuchsia::dart::NativeLookup, fuchsia::dart::NativeSymbol);
111
112 auto dart_state = tonic::DartState::Current();
113 std::unique_ptr<tonic::DartClassProvider> fuchsia_class_provider(
114 new tonic::DartClassProvider(dart_state, "dart:fuchsia"));
115 dart_state->class_library().add_provider("fuchsia",
116 std::move(fuchsia_class_provider));
117
118 if (directory_request) {
120 library, ToDart("_outgoingServices"),
121 ToDart(zircon::dart::Handle::Create(std::move(directory_request))));
123 }
124
125 if (view_ref) {
127 library, ToDart("_viewRef"),
128 ToDart(zircon::dart::Handle::Create((*view_ref).release())));
130 }
131}
132
133} // namespace dart
134} // namespace fuchsia
void SetReturnCode(uint32_t return_code)
Definition dart_state.cc:66
static DartState * Current()
Definition dart_state.cc:56
static fml::RefPtr< Handle > Create(zx_handle_t handle)
Definition handle.cc:28
DART_EXPORT Dart_Handle Dart_SetNativeResolver(Dart_Handle library, Dart_NativeEntryResolver resolver, Dart_NativeEntrySymbol symbol)
struct _Dart_Handle * Dart_Handle
Definition dart_api.h:258
DART_EXPORT void Dart_PropagateError(Dart_Handle handle)
DART_EXPORT Dart_Handle Dart_LookupLibrary(Dart_Handle url)
struct _Dart_NativeArguments * Dart_NativeArguments
Definition dart_api.h:3066
DART_EXPORT DART_WARN_UNUSED_RESULT Dart_Handle Dart_SetField(Dart_Handle container, Dart_Handle name, Dart_Handle value)
DART_EXPORT Dart_Handle Dart_GetNativeIntegerArgument(Dart_NativeArguments args, int index, int64_t *value)
DART_EXPORT Dart_Handle Dart_StringToCString(Dart_Handle str, const char **cstr)
void(* Dart_NativeFunction)(Dart_NativeArguments arguments)
Definition dart_api.h:3254
DART_EXPORT bool Dart_IsError(Dart_Handle handle)
GAsyncResult * result
#define FML_CHECK(condition)
Definition logging.h:85
#define FML_DCHECK(condition)
Definition logging.h:103
const char * name
Definition fuchsia.cc:50
#define FIDL_NATIVE_LIST(V)
Definition fuchsia.cc:45
#define REGISTER_FUNCTION(name, count)
Definition fuchsia.cc:41
int argument_count
Definition fuchsia.cc:52
const char *const function_name
constexpr std::size_t size(T(&array)[N])
Definition size.h:13
void Initialize(zx::channel directory_request, std::optional< zx::eventpair > view_ref)
Initializes Dart bindings for the Fuchsia application model.
Definition fuchsia.cc:103
Dart_Handle ToDart(const T &object)
bool CheckAndHandleError(Dart_Handle handle)
Definition dart_error.cc:33
void Initialize()
Definition natives.cc:68

◆ FIDL_NATIVE_LIST

#define FIDL_NATIVE_LIST (   V)    V(SetReturnCode, 1)

Definition at line 45 of file fuchsia.cc.

◆ REGISTER_FUNCTION

#define REGISTER_FUNCTION (   name,
  count 
)    {"" #name, name, count},

Definition at line 41 of file fuchsia.cc.

Variable Documentation

◆ argument_count

int argument_count

Definition at line 52 of file fuchsia.cc.

◆ function

Definition at line 51 of file fuchsia.cc.

◆ name

const char* name

Definition at line 50 of file fuchsia.cc.