| Flutter iOS Embedder |

plugin_registrar.cc
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 #include "include/flutter/plugin_registrar.h"
6
7 #include <iostream>
8 #include <map>
9
10 #include "binary_messenger_impl.h"
11 #include "include/flutter/engine_method_result.h"
12 #include "include/flutter/method_channel.h"
13 #include "texture_registrar_impl.h"
14
15 namespace flutter {
16
17 // ===== PluginRegistrar =====
18
19 PluginRegistrar::PluginRegistrar(FlutterDesktopPluginRegistrarRef registrar)
20 : registrar_(registrar) {
21 auto core_messenger = FlutterDesktopPluginRegistrarGetMessenger(registrar_);
22 messenger_ = std::make_unique<BinaryMessengerImpl>(core_messenger);
23
24 auto texture_registrar =
25 FlutterDesktopRegistrarGetTextureRegistrar(registrar_);
26 texture_registrar_ =
27 std::make_unique<TextureRegistrarImpl>(texture_registrar);
28 }
29
30 PluginRegistrar::~PluginRegistrar() {
31 // This must always be the first call.
32 ClearPlugins();
33
34 // Explicitly cleared to facilitate testing of destruction order.
35 messenger_.reset();
36 }
37
38 void PluginRegistrar::AddPlugin(std::unique_ptr<Plugin> plugin) {
39 plugins_.insert(std::move(plugin));
40 }
41
42 void PluginRegistrar::ClearPlugins() {
43 plugins_.clear();
44 }
45
46 // ===== PluginRegistrarManager =====
47
48 // static
49 PluginRegistrarManager* PluginRegistrarManager::GetInstance() {
50 static PluginRegistrarManager* instance = new PluginRegistrarManager();
51 return instance;
52 }
53
54 PluginRegistrarManager::PluginRegistrarManager() = default;
55
56 // static
57 void PluginRegistrarManager::OnRegistrarDestroyed(
58 FlutterDesktopPluginRegistrarRef registrar) {
59 GetInstance()->registrars()->erase(registrar);
60 }
61
62 } // namespace flutter
engine_method_result.h
plugin_registrar.h
flutter::PluginRegistrar::ClearPlugins
void ClearPlugins()
Definition: plugin_registrar.cc:42
flutter::PluginRegistrar::texture_registrar
TextureRegistrar * texture_registrar()
Definition: plugin_registrar.h:47
FlutterDesktopPluginRegistrarGetMessenger
FLUTTER_EXPORT FlutterDesktopMessengerRef FlutterDesktopPluginRegistrarGetMessenger(FlutterDesktopPluginRegistrarRef registrar)
binary_messenger_impl.h
flutter
Definition: accessibility_bridge.h:28
flutter::PluginRegistrar::AddPlugin
void AddPlugin(std::unique_ptr< Plugin > plugin)
Definition: plugin_registrar.cc:38
flutter::PluginRegistrar::PluginRegistrar
PluginRegistrar(FlutterDesktopPluginRegistrarRef core_registrar)
Definition: plugin_registrar.cc:19
FlutterDesktopRegistrarGetTextureRegistrar
FLUTTER_EXPORT FlutterDesktopTextureRegistrarRef FlutterDesktopRegistrarGetTextureRegistrar(FlutterDesktopPluginRegistrarRef registrar)
method_channel.h
flutter::PluginRegistrar::~PluginRegistrar
virtual ~PluginRegistrar()
Definition: plugin_registrar.cc:30
flutter::PluginRegistrarManager
Definition: plugin_registrar.h:86
texture_registrar_impl.h
FlutterDesktopPluginRegistrarRef
struct FlutterDesktopPluginRegistrar * FlutterDesktopPluginRegistrarRef
Definition: flutter_plugin_registrar.h:20
flutter::PluginRegistrarManager::GetInstance
static PluginRegistrarManager * GetInstance()
Definition: plugin_registrar.cc:49