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 FLUTTER_RUNTIME_DART_VM_DATA_H_ |
6 | #define FLUTTER_RUNTIME_DART_VM_DATA_H_ |
7 | |
8 | #include "flutter/fml/macros.h" |
9 | #include "flutter/runtime/dart_snapshot.h" |
10 | |
11 | namespace flutter { |
12 | |
13 | //------------------------------------------------------------------------------ |
14 | /// @brief Provides thread-safe access to data that is necessary to |
15 | /// bootstrap a new Dart VM instance. All snapshots referenced by |
16 | /// this object are read-only. |
17 | /// |
18 | class DartVMData { |
19 | public: |
20 | //---------------------------------------------------------------------------- |
21 | /// @brief Creates a new instance of `DartVMData`. Both the VM and |
22 | /// isolate snapshot members are optional and may be `nullptr`. If |
23 | /// `nullptr`, the snapshot resolvers present in the settings |
24 | /// object are used to infer the snapshots. If the snapshots |
25 | /// cannot be inferred from the settings object, this method |
26 | /// return `nullptr`. |
27 | /// |
28 | /// @param[in] settings The settings used to infer the VM and |
29 | /// isolate snapshots if they are not provided |
30 | /// directly. |
31 | /// @param[in] vm_snapshot The VM snapshot or `nullptr`. |
32 | /// @param[in] isolate_snapshot The isolate snapshot or `nullptr`. |
33 | /// |
34 | /// @return A new instance of VM data that can be used to bootstrap a Dart |
35 | /// VM. `nullptr` if the snapshots are not provided and cannot be |
36 | /// inferred from the settings object. |
37 | /// |
38 | static std::shared_ptr<const DartVMData> Create( |
39 | Settings settings, |
40 | fml::RefPtr<DartSnapshot> vm_snapshot, |
41 | fml::RefPtr<DartSnapshot> isolate_snapshot); |
42 | |
43 | //---------------------------------------------------------------------------- |
44 | /// @brief Collect the DartVMData instance. |
45 | /// |
46 | ~DartVMData(); |
47 | |
48 | //---------------------------------------------------------------------------- |
49 | /// @brief The settings object from which the Dart snapshots were |
50 | /// inferred. |
51 | /// |
52 | /// @return The settings. |
53 | /// |
54 | const Settings& GetSettings() const; |
55 | |
56 | //---------------------------------------------------------------------------- |
57 | /// @brief Gets the VM snapshot. This can be in the call to bootstrap |
58 | /// the Dart VM via `Dart_Initialize`. |
59 | /// |
60 | /// @return The VM snapshot. |
61 | /// |
62 | const DartSnapshot& GetVMSnapshot() const; |
63 | |
64 | //---------------------------------------------------------------------------- |
65 | /// @brief Get the isolate snapshot necessary to launch isolates in the |
66 | /// Dart VM. The Dart VM instance in which these isolates are |
67 | /// launched must be the same as the VM created using snapshot |
68 | /// accessed via `GetVMSnapshot`. |
69 | /// |
70 | /// @return The isolate snapshot. |
71 | /// |
72 | fml::RefPtr<const DartSnapshot> GetIsolateSnapshot() const; |
73 | |
74 | private: |
75 | const Settings settings_; |
76 | const fml::RefPtr<const DartSnapshot> vm_snapshot_; |
77 | const fml::RefPtr<const DartSnapshot> isolate_snapshot_; |
78 | |
79 | DartVMData(Settings settings, |
80 | fml::RefPtr<const DartSnapshot> vm_snapshot, |
81 | fml::RefPtr<const DartSnapshot> isolate_snapshot); |
82 | |
83 | FML_DISALLOW_COPY_AND_ASSIGN(DartVMData); |
84 | }; |
85 | |
86 | } // namespace flutter |
87 | |
88 | #endif // FLUTTER_RUNTIME_DART_VM_DATA_H_ |
89 | |