forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_dart_native_resolver.h
61 lines (45 loc) · 2.08 KB
/
test_dart_native_resolver.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef FLUTTER_TESTING_TEST_DART_NATIVE_RESOLVER_H_
#define FLUTTER_TESTING_TEST_DART_NATIVE_RESOLVER_H_
#include <functional>
#include <map>
#include <memory>
#include "flutter/fml/macros.h"
#include "third_party/dart/runtime/include/dart_api.h"
#define CREATE_NATIVE_ENTRY(native_entry) \
([&]() { \
static ::flutter::testing::NativeEntry closure; \
static Dart_NativeFunction entrypoint = [](Dart_NativeArguments args) { \
closure(args); \
}; \
closure = (native_entry); \
return entrypoint; \
})()
namespace flutter {
namespace testing {
using NativeEntry = std::function<void(Dart_NativeArguments)>;
class TestDartNativeResolver
: public std::enable_shared_from_this<TestDartNativeResolver> {
public:
TestDartNativeResolver();
~TestDartNativeResolver();
void AddNativeCallback(std::string name, Dart_NativeFunction callback);
void AddFfiNativeCallback(std::string name, void* callback_ptr);
void SetNativeResolverForIsolate();
private:
std::map<std::string, Dart_NativeFunction> native_callbacks_;
std::map<std::string, void*> ffi_native_callbacks_;
Dart_NativeFunction ResolveCallback(std::string name) const;
void* ResolveFfiCallback(std::string name) const;
static Dart_NativeFunction DartNativeEntryResolverCallback(
Dart_Handle dart_name,
int num_of_arguments,
bool* auto_setup_scope);
static void* FfiNativeResolver(const char* name, uintptr_t args_n);
FML_DISALLOW_COPY_AND_ASSIGN(TestDartNativeResolver);
};
} // namespace testing
} // namespace flutter
#endif // FLUTTER_TESTING_TEST_DART_NATIVE_RESOLVER_H_