Flutter Engine
The Flutter Engine
test_dart_native_resolver.h
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#ifndef FLUTTER_TESTING_TEST_DART_NATIVE_RESOLVER_H_
6#define FLUTTER_TESTING_TEST_DART_NATIVE_RESOLVER_H_
7
8#include <functional>
9#include <map>
10#include <memory>
11#include <string>
12
13#include "flutter/fml/macros.h"
14#include "third_party/dart/runtime/include/dart_api.h"
15
16#define CREATE_NATIVE_ENTRY(native_entry) \
17 ([&]() { \
18 static ::flutter::testing::NativeEntry closure; \
19 static Dart_NativeFunction entrypoint = [](Dart_NativeArguments args) { \
20 closure(args); \
21 }; \
22 closure = (native_entry); \
23 return entrypoint; \
24 })()
25
26namespace flutter {
27namespace testing {
28
30
32 : public std::enable_shared_from_this<TestDartNativeResolver> {
33 public:
35
37
38 void AddNativeCallback(const std::string& name, Dart_NativeFunction callback);
39 void AddFfiNativeCallback(const std::string& name, void* callback_ptr);
40
42
43 private:
44 std::map<std::string, Dart_NativeFunction> native_callbacks_;
45 std::map<std::string, void*> ffi_native_callbacks_;
46
47 Dart_NativeFunction ResolveCallback(const std::string& name) const;
48 void* ResolveFfiCallback(const std::string& name) const;
49
50 static Dart_NativeFunction DartNativeEntryResolverCallback(
51 Dart_Handle dart_name,
52 int num_of_arguments,
53 bool* auto_setup_scope);
54 static void* FfiNativeResolver(const char* name, uintptr_t args_n);
55
56 FML_DISALLOW_COPY_AND_ASSIGN(TestDartNativeResolver);
57};
58
59} // namespace testing
60} // namespace flutter
61
62#endif // FLUTTER_TESTING_TEST_DART_NATIVE_RESOLVER_H_
void AddFfiNativeCallback(const std::string &name, void *callback_ptr)
void AddNativeCallback(const std::string &name, Dart_NativeFunction callback)
struct _Dart_Handle * Dart_Handle
Definition: dart_api.h:258
struct _Dart_NativeArguments * Dart_NativeArguments
Definition: dart_api.h:3019
void(* Dart_NativeFunction)(Dart_NativeArguments arguments)
Definition: dart_api.h:3207
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
Dart_NativeFunction function
Definition: fuchsia.cc:51
std::function< void(Dart_NativeArguments)> NativeEntry
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32