4
4
5
5
import '../generator_tools.dart' ;
6
6
7
+ /// Name for the generated InstanceManager for ProxyApis.
8
+ ///
9
+ /// This lowers the chances of variable name collisions with user defined
10
+ /// parameters.
11
+ const String dartInstanceManagerClassName =
12
+ '${proxyApiClassNamePrefix }InstanceManager' ;
13
+
14
+ /// Name for the generated InstanceManager API for ProxyApis.
15
+ ///
16
+ /// This lowers the chances of variable name collisions with user defined
17
+ /// parameters.
18
+ const String dartInstanceManagerApiClassName =
19
+ '_${classNamePrefix }InstanceManagerApi' ;
20
+
7
21
/// Creates the `InstanceManager` with the passed string values.
8
22
String instanceManagerTemplate ({
9
23
required Iterable <String > allProxyApiNames,
@@ -30,9 +44,9 @@ String instanceManagerTemplate({
30
44
/// is added as a weak reference with the same identifier. This prevents a
31
45
/// scenario where the weak referenced instance was released and then later
32
46
/// returned by the host platform.
33
- class $instanceManagerClassName {
34
- /// Constructs a [$instanceManagerClassName ].
35
- $instanceManagerClassName ({required void Function(int) onWeakReferenceRemoved}) {
47
+ class $dartInstanceManagerClassName {
48
+ /// Constructs a [$dartInstanceManagerClassName ].
49
+ $dartInstanceManagerClassName ({required void Function(int) onWeakReferenceRemoved}) {
36
50
this.onWeakReferenceRemoved = (int identifier) {
37
51
_weakInstances.remove(identifier);
38
52
onWeakReferenceRemoved(identifier);
@@ -46,12 +60,12 @@ class $instanceManagerClassName {
46
60
// 0 <= n < 2^16.
47
61
static const int _maxDartCreatedIdentifier = 65536;
48
62
49
- /// The default [$instanceManagerClassName ] used by ProxyApis.
63
+ /// The default [$dartInstanceManagerClassName ] used by ProxyApis.
50
64
///
51
65
/// On creation, this manager makes a call to clear the native
52
66
/// InstanceManager. This is to prevent identifier conflicts after a host
53
67
/// restart.
54
- static final $instanceManagerClassName instance = _initInstance();
68
+ static final $dartInstanceManagerClassName instance = _initInstance();
55
69
56
70
// Expando is used because it doesn't prevent its keys from becoming
57
71
// inaccessible. This allows the manager to efficiently retrieve an identifier
@@ -72,17 +86,17 @@ class $instanceManagerClassName {
72
86
/// or becomes inaccessible.
73
87
late final void Function(int) onWeakReferenceRemoved;
74
88
75
- static $instanceManagerClassName _initInstance() {
89
+ static $dartInstanceManagerClassName _initInstance() {
76
90
WidgetsFlutterBinding.ensureInitialized();
77
- final _${ instanceManagerClassName }Api api = _${ instanceManagerClassName }Api ();
78
- // Clears the native `$instanceManagerClassName ` on the initial use of the Dart one.
91
+ final $ dartInstanceManagerApiClassName api = $ dartInstanceManagerApiClassName ();
92
+ // Clears the native `$dartInstanceManagerClassName ` on the initial use of the Dart one.
79
93
api.clear();
80
- final $instanceManagerClassName instanceManager = $instanceManagerClassName (
94
+ final $dartInstanceManagerClassName instanceManager = $dartInstanceManagerClassName (
81
95
onWeakReferenceRemoved: (int identifier) {
82
96
api.removeStrongReference(identifier);
83
97
},
84
98
);
85
- _${ instanceManagerClassName }Api .setUpMessageHandlers(instanceManager: instanceManager);
99
+ $ dartInstanceManagerApiClassName .setUpMessageHandlers(instanceManager: instanceManager);
86
100
${apiHandlerSetUps .join ('\n\t\t ' )}
87
101
return instanceManager;
88
102
}
@@ -229,9 +243,9 @@ abstract class $proxyApiBaseClassName {
229
243
/// Construct a [$proxyApiBaseClassName ].
230
244
$proxyApiBaseClassName ({
231
245
this.$_proxyApiBaseClassMessengerVarName ,
232
- $instanceManagerClassName ? $_proxyApiBaseClassInstanceManagerVarName ,
246
+ $dartInstanceManagerClassName ? $_proxyApiBaseClassInstanceManagerVarName ,
233
247
}) : $_proxyApiBaseClassInstanceManagerVarName =
234
- $_proxyApiBaseClassInstanceManagerVarName ?? $instanceManagerClassName .instance;
248
+ $_proxyApiBaseClassInstanceManagerVarName ?? $dartInstanceManagerClassName .instance;
235
249
236
250
/// Sends and receives binary data across the Flutter platform barrier.
237
251
///
@@ -242,12 +256,12 @@ abstract class $proxyApiBaseClassName {
242
256
243
257
/// Maintains instances stored to communicate with native language objects.
244
258
@protected
245
- final $instanceManagerClassName $_proxyApiBaseClassInstanceManagerVarName ;
259
+ final $dartInstanceManagerClassName $_proxyApiBaseClassInstanceManagerVarName ;
246
260
247
261
/// Instantiates and returns a functionally identical object to oneself.
248
262
///
249
263
/// Outside of tests, this method should only ever be called by
250
- /// [$instanceManagerClassName ].
264
+ /// [$dartInstanceManagerClassName ].
251
265
///
252
266
/// Subclasses should always override their parent's implementation of this
253
267
/// method.
@@ -264,11 +278,11 @@ abstract class $proxyApiBaseClassName {
264
278
const String proxyApiBaseCodec = '''
265
279
class $_proxyApiCodecName extends _PigeonCodec {
266
280
const $_proxyApiCodecName (this.instanceManager);
267
- final $instanceManagerClassName instanceManager;
281
+ final $dartInstanceManagerClassName instanceManager;
268
282
@override
269
283
void writeValue(WriteBuffer buffer, Object? value) {
270
284
if (value is $proxyApiBaseClassName ) {
271
- buffer.putUint8(128 );
285
+ buffer.putUint8($ proxyApiCodecInstanceManagerKey );
272
286
writeValue(buffer, instanceManager.getIdentifier(value));
273
287
} else {
274
288
super.writeValue(buffer, value);
@@ -277,7 +291,7 @@ class $_proxyApiCodecName extends _PigeonCodec {
277
291
@override
278
292
Object? readValueOfType(int type, ReadBuffer buffer) {
279
293
switch (type) {
280
- case 128 :
294
+ case $ proxyApiCodecInstanceManagerKey :
281
295
return instanceManager
282
296
.getInstanceWithWeakReference(readValue(buffer)! as int);
283
297
default:
0 commit comments