1 | /* |
2 | * Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file |
3 | * for details. All rights reserved. Use of this source code is governed by a |
4 | * BSD-style license that can be found in the LICENSE file. |
5 | */ |
6 | |
7 | #ifndef RUNTIME_INCLUDE_DART_API_DL_H_ |
8 | #define RUNTIME_INCLUDE_DART_API_DL_H_ |
9 | |
10 | #include "include/dart_api.h" |
11 | #include "include/dart_native_api.h" |
12 | |
13 | /** \mainpage Dynamically Linked Dart API |
14 | * |
15 | * This exposes a subset of symbols from dart_api.h and dart_native_api.h |
16 | * available in every Dart embedder through dynamic linking. |
17 | * |
18 | * All symbols are postfixed with _DL to indicate that they are dynamically |
19 | * linked and to prevent conflicts with the original symbol. |
20 | * |
21 | * Link `dart_api_dl.c` file into your library and invoke |
22 | * `Dart_InitializeApiDL` with `NativeApi.initializeApiDLData`. |
23 | */ |
24 | |
25 | #ifdef __cplusplus |
26 | #define DART_EXTERN extern "C" |
27 | #else |
28 | #define DART_EXTERN extern |
29 | #endif |
30 | |
31 | DART_EXTERN intptr_t Dart_InitializeApiDL(void* data); |
32 | |
33 | // ============================================================================ |
34 | // IMPORTANT! Never update these signatures without properly updating |
35 | // DART_API_DL_MAJOR_VERSION and DART_API_DL_MINOR_VERSION. |
36 | // |
37 | // Verbatim copy of `dart_native_api.h` and `dart_api.h` symbol names and types |
38 | // to trigger compile-time errors if the sybols in those files are updated |
39 | // without updating these. |
40 | // |
41 | // Function return and argument types, and typedefs are carbon copied. Structs |
42 | // are typechecked nominally in C/C++, so they are not copied, instead a |
43 | // comment is added to their definition. |
44 | typedef int64_t Dart_Port_DL; |
45 | |
46 | typedef void (*Dart_NativeMessageHandler_DL)(Dart_Port_DL dest_port_id, |
47 | Dart_CObject* message); |
48 | |
49 | // dart_native_api.h symbols can be called on any thread. |
50 | #define DART_NATIVE_API_DL_SYMBOLS(F) \ |
51 | /***** dart_native_api.h *****/ \ |
52 | /* Dart_Port */ \ |
53 | F(Dart_PostCObject, bool, (Dart_Port_DL port_id, Dart_CObject * message)) \ |
54 | F(Dart_PostInteger, bool, (Dart_Port_DL port_id, int64_t message)) \ |
55 | F(Dart_NewNativePort, Dart_Port_DL, \ |
56 | (const char* name, Dart_NativeMessageHandler_DL handler, \ |
57 | bool handle_concurrently)) \ |
58 | F(Dart_CloseNativePort, bool, (Dart_Port_DL native_port_id)) |
59 | |
60 | // dart_api.h symbols can only be called on Dart threads. |
61 | #define DART_API_DL_SYMBOLS(F) \ |
62 | /***** dart_api.h *****/ \ |
63 | /* Errors */ \ |
64 | F(Dart_IsError, bool, (Dart_Handle handle)) \ |
65 | F(Dart_IsApiError, bool, (Dart_Handle handle)) \ |
66 | F(Dart_IsUnhandledExceptionError, bool, (Dart_Handle handle)) \ |
67 | F(Dart_IsCompilationError, bool, (Dart_Handle handle)) \ |
68 | F(Dart_IsFatalError, bool, (Dart_Handle handle)) \ |
69 | F(Dart_GetError, const char*, (Dart_Handle handle)) \ |
70 | F(Dart_ErrorHasException, bool, (Dart_Handle handle)) \ |
71 | F(Dart_ErrorGetException, Dart_Handle, (Dart_Handle handle)) \ |
72 | F(Dart_ErrorGetStackTrace, Dart_Handle, (Dart_Handle handle)) \ |
73 | F(Dart_NewApiError, Dart_Handle, (const char* error)) \ |
74 | F(Dart_NewCompilationError, Dart_Handle, (const char* error)) \ |
75 | F(Dart_NewUnhandledExceptionError, Dart_Handle, (Dart_Handle exception)) \ |
76 | F(Dart_PropagateError, void, (Dart_Handle handle)) \ |
77 | /* Dart_Handle, Dart_PersistentHandle, Dart_WeakPersistentHandle */ \ |
78 | F(Dart_HandleFromPersistent, Dart_Handle, (Dart_PersistentHandle object)) \ |
79 | F(Dart_HandleFromWeakPersistent, Dart_Handle, \ |
80 | (Dart_WeakPersistentHandle object)) \ |
81 | F(Dart_NewPersistentHandle, Dart_PersistentHandle, (Dart_Handle object)) \ |
82 | F(Dart_SetPersistentHandle, void, \ |
83 | (Dart_PersistentHandle obj1, Dart_Handle obj2)) \ |
84 | F(Dart_DeletePersistentHandle, void, (Dart_PersistentHandle object)) \ |
85 | F(Dart_NewWeakPersistentHandle, Dart_WeakPersistentHandle, \ |
86 | (Dart_Handle object, void* peer, intptr_t external_allocation_size, \ |
87 | Dart_WeakPersistentHandleFinalizer callback)) \ |
88 | F(Dart_DeleteWeakPersistentHandle, void, (Dart_WeakPersistentHandle object)) \ |
89 | F(Dart_UpdateExternalSize, void, \ |
90 | (Dart_WeakPersistentHandle object, intptr_t external_allocation_size)) \ |
91 | F(Dart_NewFinalizableHandle, Dart_FinalizableHandle, \ |
92 | (Dart_Handle object, void* peer, intptr_t external_allocation_size, \ |
93 | Dart_HandleFinalizer callback)) \ |
94 | F(Dart_DeleteFinalizableHandle, void, \ |
95 | (Dart_FinalizableHandle object, Dart_Handle strong_ref_to_object)) \ |
96 | F(Dart_UpdateFinalizableExternalSize, void, \ |
97 | (Dart_FinalizableHandle object, Dart_Handle strong_ref_to_object, \ |
98 | intptr_t external_allocation_size)) \ |
99 | /* Dart_Port */ \ |
100 | F(Dart_Post, bool, (Dart_Port_DL port_id, Dart_Handle object)) \ |
101 | F(Dart_NewSendPort, Dart_Handle, (Dart_Port_DL port_id)) \ |
102 | F(Dart_SendPortGetId, Dart_Handle, \ |
103 | (Dart_Handle port, Dart_Port_DL * port_id)) \ |
104 | /* Scopes */ \ |
105 | F(Dart_EnterScope, void, ()) \ |
106 | F(Dart_ExitScope, void, ()) |
107 | |
108 | #define DART_API_ALL_DL_SYMBOLS(F) \ |
109 | DART_NATIVE_API_DL_SYMBOLS(F) \ |
110 | DART_API_DL_SYMBOLS(F) |
111 | // IMPORTANT! Never update these signatures without properly updating |
112 | // DART_API_DL_MAJOR_VERSION and DART_API_DL_MINOR_VERSION. |
113 | // |
114 | // End of verbatim copy. |
115 | // ============================================================================ |
116 | |
117 | #define DART_API_DL_DECLARATIONS(name, R, A) \ |
118 | typedef R(*name##_Type) A; \ |
119 | DART_EXTERN name##_Type name##_DL; |
120 | |
121 | DART_API_ALL_DL_SYMBOLS(DART_API_DL_DECLARATIONS) |
122 | |
123 | #undef DART_API_DL_DEFINITIONS |
124 | |
125 | #undef DART_EXTERN |
126 | |
127 | #endif /* RUNTIME_INCLUDE_DART_API_DL_H_ */ /* NOLINT */ |
128 | |