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 LIB_TONIC_DART_LIBRARY_NATIVES_H_ |
6 | #define LIB_TONIC_DART_LIBRARY_NATIVES_H_ |
7 | |
8 | #include <initializer_list> |
9 | #include <string> |
10 | #include <unordered_map> |
11 | |
12 | #include "third_party/dart/runtime/include/dart_api.h" |
13 | #include "tonic/common/macros.h" |
14 | |
15 | namespace tonic { |
16 | |
17 | class DartLibraryNatives { |
18 | public: |
19 | DartLibraryNatives(); |
20 | ~DartLibraryNatives(); |
21 | |
22 | struct Entry { |
23 | const char* symbol; |
24 | Dart_NativeFunction native_function; |
25 | int argument_count; |
26 | bool auto_setup_scope; |
27 | }; |
28 | |
29 | void Register(std::initializer_list<Entry> entries); |
30 | |
31 | Dart_NativeFunction GetNativeFunction(Dart_Handle name, |
32 | int argument_count, |
33 | bool* auto_setup_scope); |
34 | const uint8_t* GetSymbol(Dart_NativeFunction native_function); |
35 | |
36 | private: |
37 | std::unordered_map<std::string, Entry> entries_; |
38 | std::unordered_map<Dart_NativeFunction, const char*> symbols_; |
39 | |
40 | TONIC_DISALLOW_COPY_AND_ASSIGN(DartLibraryNatives); |
41 | }; |
42 | |
43 | } // namespace tonic |
44 | |
45 | #endif // LIB_TONIC_DART_LIBRARY_NATIVES_H_ |
46 |