| 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 [_name release];
42 [_engines release];
43 [_project release];
44 [super dealloc];
45 }
46
47 - (FlutterEngine*)makeEngineWithEntrypoint:(nullable NSString*)entrypoint
48 libraryURI:(nullable NSString*)libraryURI {
49 return [self makeEngineWithEntrypoint:entrypoint libraryURI:libraryURI initialRoute:nil];
50 }
51
52 - (FlutterEngine*)makeEngineWithEntrypoint:(nullable NSString*)entrypoint
53 libraryURI:(nullable NSString*)libraryURI
54 initialRoute:(nullable NSString*)initialRoute {
55 FlutterEngineGroupOptions* options = [[[FlutterEngineGroupOptions alloc] init] autorelease];
56 options.entrypoint = entrypoint;
57 options.libraryURI = libraryURI;
58 options.initialRoute = initialRoute;
59 return [self makeEngineWithOptions:options];
60 }
61
62 - (FlutterEngine*)makeEngineWithOptions:(nullable FlutterEngineGroupOptions*)options {
63 NSString* entrypoint = options.entrypoint;
64 NSString* libraryURI = options.libraryURI;
65 NSString* initialRoute = options.initialRoute;
66 NSArray<NSString*>* entrypointArgs = options.entrypointArgs;
67
68 FlutterEngine* engine;
69 if (self.engines.count <= 0) {
70 engine = [self makeEngine];
71 [engine runWithEntrypoint:entrypoint
72 libraryURI:libraryURI
73 initialRoute:initialRoute
74 entrypointArgs:entrypointArgs];
75 } else {
76 FlutterEngine* spawner = (FlutterEngine*)[self.engines[0] pointerValue];
77 engine = [spawner spawnWithEntrypoint:entrypoint
78 libraryURI:libraryURI
79 initialRoute:initialRoute
80 entrypointArgs:entrypointArgs];
81 }
82 [_engines addObject:[NSValue valueWithPointer:engine]];
83
84 NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
85 [center addObserver:self
86 selector:@selector(onEngineWillBeDealloced:)
87 name:kFlutterEngineWillDealloc
88 object:engine];
89
90 return engine;
91 }
92
93 - (FlutterEngine*)makeEngine {
94 NSString* engineName = [NSString stringWithFormat:@"%@.%d", self.name, ++_enginesCreatedCount];
95 FlutterEngine* result = [[FlutterEngine alloc] initWithName:engineName project:self.project];
96 return [result autorelease];
97 }
98
99 - (void)onEngineWillBeDealloced:(NSNotification*)notification {
100 [_engines removeObject:[NSValue valueWithPointer:notification.object]];
101 }
102
103 @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:52
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:262
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:62