| 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
5 #import "flutter/shell/platform/darwin/ios/framework/Headers/FlutterEngineGroup.h"
6 #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterEngine_Internal.h"
7
8 @implementation FlutterEngineGroupOptions
9
10 - (void)dealloc {
11 [_entrypoint release];
12 [_libraryURI release];
13 [_initialRoute release];
14 [_entrypointArgs release];
15 [super dealloc];
16 }
17
18 @end
19
20 @interface FlutterEngineGroup ()
21 @property(nonatomic, copy) NSString* name;
22 @property(nonatomic, retain) NSMutableArray<NSValue*>* engines;
23 @property(nonatomic, retain) FlutterDartProject* project;
24 @end
25
26 @implementation FlutterEngineGroup {
27 int _enginesCreatedCount;
28 }
29
30 - (instancetype)initWithName:(NSString*)name project:(nullable FlutterDartProject*)project {
31 self = [super init];
32 if (self) {
33 _name = [name copy];
34 _engines = [[NSMutableArray<NSValue*> alloc] init];
35 _project = [project retain];
36 }
37 return self;
38 }
39
40 - (void)dealloc {
41 NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
42 [center removeObserver:self];
43 [_name release];
44 [_engines release];
45 [_project release];
46 [super dealloc];
47 }
48
49 - (FlutterEngine*)makeEngineWithEntrypoint:(nullable NSString*)entrypoint
50 libraryURI:(nullable NSString*)libraryURI {
51 return [self makeEngineWithEntrypoint:entrypoint libraryURI:libraryURI initialRoute:nil];
52 }
53
54 - (FlutterEngine*)makeEngineWithEntrypoint:(nullable NSString*)entrypoint
55 libraryURI:(nullable NSString*)libraryURI
56 initialRoute:(nullable NSString*)initialRoute {
57 FlutterEngineGroupOptions* options = [[[FlutterEngineGroupOptions alloc] init] autorelease];
58 options.entrypoint = entrypoint;
59 options.libraryURI = libraryURI;
60 options.initialRoute = initialRoute;
61 return [self makeEngineWithOptions:options];
62 }
63
64 - (FlutterEngine*)makeEngineWithOptions:(nullable FlutterEngineGroupOptions*)options {
65 NSString* entrypoint = options.entrypoint;
66 NSString* libraryURI = options.libraryURI;
67 NSString* initialRoute = options.initialRoute;
68 NSArray<NSString*>* entrypointArgs = options.entrypointArgs;
69
70 FlutterEngine* engine;
71 if (self.engines.count <= 0) {
72 engine = [self makeEngine];
73 [engine runWithEntrypoint:entrypoint
74 libraryURI:libraryURI
75 initialRoute:initialRoute
76 entrypointArgs:entrypointArgs];
77 } else {
78 FlutterEngine* spawner = (FlutterEngine*)[self.engines[0] pointerValue];
79 engine = [spawner spawnWithEntrypoint:entrypoint
80 libraryURI:libraryURI
81 initialRoute:initialRoute
82 entrypointArgs:entrypointArgs];
83 }
84 [_engines addObject:[NSValue valueWithPointer:engine]];
85
86 NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
87 [center addObserver:self
88 selector:@selector(onEngineWillBeDealloced:)
89 name:kFlutterEngineWillDealloc
90 object:engine];
91
92 return engine;
93 }
94
95 - (FlutterEngine*)makeEngine {
96 NSString* engineName = [NSString stringWithFormat:@"%@.%d", self.name, ++_enginesCreatedCount];
97 FlutterEngine* result = [[FlutterEngine alloc] initWithName:engineName project:self.project];
98 return [result autorelease];
99 }
100
101 - (void)onEngineWillBeDealloced:(NSNotification*)notification {
102 [_engines removeObject:[NSValue valueWithPointer:notification.object]];
103 }
104
105 @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:54
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:264
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)
-[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:64