Flutter iOS Embedder
FlutterEngineGroup.mm
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 
7 
9 
10 @implementation FlutterEngineGroupOptions
11 @end
12 
13 @interface FlutterEngineGroup ()
14 @property(nonatomic, copy) NSString* name;
15 @property(nonatomic, strong) NSMutableArray<NSValue*>* engines;
16 @property(nonatomic, copy) FlutterDartProject* project;
17 @property(nonatomic, assign) NSUInteger enginesCreatedCount;
18 @end
19 
20 @implementation FlutterEngineGroup
21 
22 - (instancetype)initWithName:(NSString*)name project:(nullable FlutterDartProject*)project {
23  self = [super init];
24  if (self) {
25  _name = [name copy];
26  _engines = [[NSMutableArray<NSValue*> alloc] init];
27  _project = project;
28  }
29  return self;
30 }
31 
32 - (FlutterEngine*)makeEngineWithEntrypoint:(nullable NSString*)entrypoint
33  libraryURI:(nullable NSString*)libraryURI {
34  return [self makeEngineWithEntrypoint:entrypoint libraryURI:libraryURI initialRoute:nil];
35 }
36 
37 - (FlutterEngine*)makeEngineWithEntrypoint:(nullable NSString*)entrypoint
38  libraryURI:(nullable NSString*)libraryURI
39  initialRoute:(nullable NSString*)initialRoute {
40  FlutterEngineGroupOptions* options = [[FlutterEngineGroupOptions alloc] init];
41  options.entrypoint = entrypoint;
42  options.libraryURI = libraryURI;
43  options.initialRoute = initialRoute;
44  return [self makeEngineWithOptions:options];
45 }
46 
47 - (FlutterEngine*)makeEngineWithOptions:(nullable FlutterEngineGroupOptions*)options {
48  NSString* entrypoint = options.entrypoint;
49  NSString* libraryURI = options.libraryURI;
50  NSString* initialRoute = options.initialRoute;
51  NSArray<NSString*>* entrypointArgs = options.entrypointArgs;
52 
54  if (self.engines.count <= 0) {
55  engine = [self makeEngine];
56  [engine runWithEntrypoint:entrypoint
57  libraryURI:libraryURI
58  initialRoute:initialRoute
59  entrypointArgs:entrypointArgs];
60  } else {
61  FlutterEngine* spawner = (FlutterEngine*)[self.engines[0] pointerValue];
62  engine = [spawner spawnWithEntrypoint:entrypoint
63  libraryURI:libraryURI
64  initialRoute:initialRoute
65  entrypointArgs:entrypointArgs];
66  }
67  // TODO(cbracken): https://github.com/flutter/flutter/issues/155943
68  [self.engines addObject:[NSValue valueWithPointer:(__bridge void*)engine]];
69 
70  NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
71  [center addObserver:self
72  selector:@selector(onEngineWillBeDealloced:)
73  name:kFlutterEngineWillDealloc
74  object:engine];
75 
76  return engine;
77 }
78 
79 - (FlutterEngine*)makeEngine {
80  NSString* engineName =
81  [NSString stringWithFormat:@"%@.%lu", self.name, ++self.enginesCreatedCount];
82  return [[FlutterEngine alloc] initWithName:engineName project:self.project];
83 }
84 
85 - (void)onEngineWillBeDealloced:(NSNotification*)notification {
86  // TODO(cbracken): https://github.com/flutter/flutter/issues/155943
87  [self.engines removeObject:[NSValue valueWithPointer:(__bridge void*)notification.object]];
88 }
89 
90 @end
FlutterEngine
Definition: FlutterEngine.h:61
FlutterEngineGroup.h
-[FlutterEngineGroup makeEngineWithEntrypoint:libraryURI:initialRoute:]
FlutterEngine * makeEngineWithEntrypoint:libraryURI:initialRoute:(nullable NSString *entrypoint,[libraryURI] nullable NSString *libraryURI,[initialRoute] nullable NSString *initialRoute)
Definition: FlutterEngineGroup.mm:37
FlutterEngineGroupOptions::libraryURI
NSString * libraryURI
Definition: FlutterEngineGroup.h:30
FlutterEngine_Internal.h
FlutterEngineGroupOptions::entrypoint
NSString * entrypoint
Definition: FlutterEngineGroup.h:24
FlutterEngineGroupOptions::initialRoute
NSString * initialRoute
Definition: FlutterEngineGroup.h:36
FlutterEngineGroupOptions
Definition: FlutterEngineGroup.h:16
engine
id engine
Definition: FlutterTextInputPluginTest.mm:89
_name
NSString * _name
Definition: FlutterChannels.mm:68
FlutterEngineGroupOptions::entrypointArgs
NSArray< NSString * > * entrypointArgs
Definition: FlutterEngineGroup.h:41
FlutterDartProject
Definition: FlutterDartProject.mm:258
FlutterEngineGroup
Definition: FlutterEngineGroup.h:56
-[FlutterEngine spawnWithEntrypoint:libraryURI:initialRoute:entrypointArgs:]
FlutterEngine * spawnWithEntrypoint:libraryURI:initialRoute:entrypointArgs:(/*nullable */NSString *entrypoint,[libraryURI]/*nullable */NSString *libraryURI,[initialRoute]/*nullable */NSString *initialRoute,[entrypointArgs]/*nullable */NSArray< NSString * > *entrypointArgs)
FLUTTER_ASSERT_ARC
Definition: FlutterChannelKeyResponder.mm:13
-[FlutterEngine runWithEntrypoint:libraryURI:initialRoute:entrypointArgs:]
BOOL runWithEntrypoint:libraryURI:initialRoute:entrypointArgs:(nullable NSString *entrypoint,[libraryURI] nullable NSString *libraryURI,[initialRoute] nullable NSString *initialRoute,[entrypointArgs] nullable NSArray< NSString * > *entrypointArgs)
-[FlutterEngineGroup makeEngineWithOptions:]
FlutterEngine * makeEngineWithOptions:(nullable FlutterEngineGroupOptions *options)
Definition: FlutterEngineGroup.mm:47