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 | #include "tonic/dart_library_natives.h" |
6 | |
7 | #include "tonic/converter/dart_converter.h" |
8 | |
9 | namespace tonic { |
10 | |
11 | DartLibraryNatives::DartLibraryNatives() {} |
12 | |
13 | DartLibraryNatives::~DartLibraryNatives() {} |
14 | |
15 | void DartLibraryNatives::Register(std::initializer_list<Entry> entries) { |
16 | for (const Entry& entry : entries) { |
17 | symbols_.emplace(entry.native_function, entry.symbol); |
18 | entries_.emplace(entry.symbol, entry); |
19 | } |
20 | } |
21 | |
22 | Dart_NativeFunction DartLibraryNatives::GetNativeFunction( |
23 | Dart_Handle name, |
24 | int argument_count, |
25 | bool* auto_setup_scope) { |
26 | std::string name_string = StdStringFromDart(name); |
27 | auto it = entries_.find(name_string); |
28 | if (it == entries_.end()) |
29 | return nullptr; |
30 | const Entry& entry = it->second; |
31 | if (entry.argument_count != argument_count) |
32 | return nullptr; |
33 | *auto_setup_scope = entry.auto_setup_scope; |
34 | return entry.native_function; |
35 | } |
36 | |
37 | const uint8_t* DartLibraryNatives::GetSymbol( |
38 | Dart_NativeFunction native_function) { |
39 | auto it = symbols_.find(native_function); |
40 | if (it == symbols_.end()) |
41 | return nullptr; |
42 | return reinterpret_cast<const uint8_t*>(it->second); |
43 | } |
44 | |
45 | } // namespace tonic |
46 |