forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_dart_native_resolver.h
57 lines (41 loc) · 1.84 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
// 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 SetNativeResolverForIsolate();
private:
std::map<std::string, Dart_NativeFunction> native_callbacks_;
Dart_NativeFunction ResolveCallback(std::string name) const;
static Dart_NativeFunction DartNativeEntryResolverCallback(
Dart_Handle dart_name,
int num_of_arguments,
bool* auto_setup_scope);
FML_DISALLOW_COPY_AND_ASSIGN(TestDartNativeResolver);
};
} // namespace testing
} // namespace flutter
#endif // FLUTTER_TESTING_TEST_DART_NATIVE_RESOLVER_H_