OLD | NEW |
| (Empty) |
1 // Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file | |
2 // for details. All rights reserved. Use of this source code is governed by a | |
3 // BSD-style license that can be found in the LICENSE.md file. | |
4 | |
5 #ifndef INCLUDE_FLETCH_API_H_ | |
6 #define INCLUDE_FLETCH_API_H_ | |
7 | |
8 #include <stdbool.h> | |
9 | |
10 #ifdef _MSC_VER | |
11 // TODO(herhut): Do we need a __declspec here for Windows? | |
12 #define FLETCH_VISIBILITY_DEFAULT | |
13 #else | |
14 #define FLETCH_VISIBILITY_DEFAULT __attribute__((visibility("default"))) | |
15 #endif | |
16 | |
17 #ifdef __cplusplus | |
18 #define FLETCH_EXPORT extern "C" FLETCH_VISIBILITY_DEFAULT | |
19 #else | |
20 #define FLETCH_EXPORT FLETCH_VISIBILITY_DEFAULT | |
21 #endif | |
22 | |
23 typedef void* FletchProgram; | |
24 typedef void* FletchPrintInterceptor; | |
25 typedef void (*PrintInterceptionFunction)( | |
26 const char* message, int out, void* data); | |
27 typedef void (*ProgramExitCallback)(FletchProgram*, int exitcode, void* data); | |
28 | |
29 // Setup must be called before using any of the other API methods. | |
30 FLETCH_EXPORT void FletchSetup(void); | |
31 | |
32 // TearDown should be called when an application is done using the | |
33 // fletch API in order to free up resources. | |
34 FLETCH_EXPORT void FletchTearDown(void); | |
35 | |
36 // Wait for a debugger connection. The debugger will build the program | |
37 // to run in the VM and start it. | |
38 FLETCH_EXPORT void FletchWaitForDebuggerConnection(int port); | |
39 | |
40 // Load a program from a snapshot. | |
41 FLETCH_EXPORT FletchProgram FletchLoadSnapshot(unsigned char* snapshot, | |
42 int length); | |
43 | |
44 // Load the snapshot from the file and load the program from the snapshot. | |
45 FLETCH_EXPORT FletchProgram FletchLoadSnapshotFromFile(const char* path); | |
46 | |
47 // Delete a program. | |
48 FLETCH_EXPORT void FletchDeleteProgram(FletchProgram program); | |
49 | |
50 // Load a program from the given location. Location should point to a | |
51 // reloacted program heap with appended info block, usually build using | |
52 // the flashtool utility or by relocating a loaded program. | |
53 FLETCH_EXPORT FletchProgram FletchLoadProgramFromFlash(void* location, | |
54 size_t size); | |
55 | |
56 // Starts the main method of the program. The given callback will be called once | |
57 // all processes of the program have terminated. | |
58 // | |
59 // The [callback] might be called on FletchVM internal threads and is not | |
60 // allowed to use the Fletch API. | |
61 // TODO(kustermann/herhut): We should | |
62 // * make clear what the callback can do and what not (e.g. | |
63 // FletchDeleteProgram) | |
64 // * use thread-local storage - at least in debug mode - which ensures this. | |
65 FLETCH_EXPORT void FletchStartMain(FletchProgram program, | |
66 ProgramExitCallback callback, | |
67 void* callback_data); | |
68 | |
69 // Run the main method of the program and wait until it is done executing. | |
70 FLETCH_EXPORT int FletchRunMain(FletchProgram program); | |
71 | |
72 // Run the main method of multiple programs and wait until all of them are done | |
73 // executing. | |
74 FLETCH_EXPORT void FletchRunMultipleMain(int count, | |
75 FletchProgram* programs, | |
76 int* exitcodes); | |
77 | |
78 // Load the snapshot from the file, load the program from the | |
79 // snapshot, run the main process of that program and wait until it is done | |
80 // executing. | |
81 FLETCH_EXPORT void FletchRunSnapshotFromFile(const char* path); | |
82 | |
83 // Add a default shared library for the dart:ffi foreign lookups. | |
84 // More than one default shared library can be added. The libraries | |
85 // are used for foreign lookups where no library has been specified. | |
86 // The libraries are searched in the order in which they are added. | |
87 // The library string must be null-terminated and Fletch does not | |
88 // take over ownership of the passed in string. | |
89 FLETCH_EXPORT bool FletchAddDefaultSharedLibrary(const char* library); | |
90 | |
91 // Register a print interception function. When a print occurs the passed | |
92 // function will be called with the message, an output id 2 for stdout or output | |
93 // id 3 for stderr, as well as the data associated with this registration. | |
94 // The result of registration is an interceptor instance that can be used to | |
95 // subsequently unregister the interceptor. | |
96 FLETCH_EXPORT FletchPrintInterceptor FletchRegisterPrintInterceptor( | |
97 PrintInterceptionFunction function, | |
98 void* data); | |
99 | |
100 // Unregister a print interceptor. This must be called with an interceptor | |
101 // instance that was created using the registration function. The interceptor | |
102 // instance is reclaimed and no longer valid after having called this function. | |
103 FLETCH_EXPORT void FletchUnregisterPrintInterceptor( | |
104 FletchPrintInterceptor interceptor); | |
105 | |
106 #endif // INCLUDE_FLETCH_API_H_ | |
OLD | NEW |