Flutter Engine
dart_binding_macros.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 LIB_TONIC_DART_BINDING_MACROS_H_
6 #define LIB_TONIC_DART_BINDING_MACROS_H_
7 
8 #include "tonic/dart_args.h"
9 
10 #define DART_NATIVE_NO_UI_CHECK_CALLBACK(CLASS, METHOD) \
11  static void CLASS##_##METHOD(Dart_NativeArguments args) { \
12  tonic::DartCall(&CLASS::METHOD, args); \
13  }
14 
15 #define DART_NATIVE_CALLBACK(CLASS, METHOD) \
16  static void CLASS##_##METHOD(Dart_NativeArguments args) { \
17  UIDartState::ThrowIfUIOperationsProhibited(); \
18  tonic::DartCall(&CLASS::METHOD, args); \
19  }
20 
21 #define DART_NATIVE_CALLBACK_STATIC(CLASS, METHOD) \
22  static void CLASS##_##METHOD(Dart_NativeArguments args) { \
23  tonic::DartCallStatic(&CLASS::METHOD, args); \
24  }
25 
26 #define DART_REGISTER_NATIVE(CLASS, METHOD) \
27  {#CLASS "_" #METHOD, CLASS##_##METHOD, \
28  tonic::IndicesForSignature<decltype(&CLASS::METHOD)>::count + 1, true},
29 
30 #define DART_REGISTER_NATIVE_STATIC(CLASS, METHOD) \
31  { \
32 #CLASS "_" #METHOD, CLASS##_##METHOD, \
33  tonic::IndicesForSignature < decltype(&CLASS::METHOD)> ::count, true \
34  }
35 
36 #define DART_BIND_ALL(CLASS, FOR_EACH) \
37  FOR_EACH(DART_NATIVE_CALLBACK) \
38  void CLASS::RegisterNatives(tonic::DartLibraryNatives* natives) { \
39  natives->Register({FOR_EACH(DART_REGISTER_NATIVE)}); \
40  }
41 
42 #endif // LIB_TONIC_DART_BINDING_MACROS_H_