Flutter Engine
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 
6 
7 #include <iostream>
8 #include <map>
9 
10 #include "binary_messenger_impl.h"
13 #include "texture_registrar_impl.h"
14 
15 namespace flutter {
16 
17 // ===== PluginRegistrar =====
18 
20  : registrar_(registrar) {
21  auto core_messenger = FlutterDesktopPluginRegistrarGetMessenger(registrar_);
22  messenger_ = std::make_unique<BinaryMessengerImpl>(core_messenger);
23 
24  auto texture_registrar =
26  texture_registrar_ =
27  std::make_unique<TextureRegistrarImpl>(texture_registrar);
28 }
29 
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 
43  plugins_.clear();
44 }
45 
46 // ===== PluginRegistrarManager =====
47 
48 // static
50  static PluginRegistrarManager* instance = new PluginRegistrarManager();
51  return instance;
52 }
53 
54 PluginRegistrarManager::PluginRegistrarManager() = default;
55 
56 // static
57 void PluginRegistrarManager::OnRegistrarDestroyed(
59  GetInstance()->registrars()->erase(registrar);
60 }
61 
62 } // namespace flutter
FlutterDesktopMessengerRef FlutterDesktopPluginRegistrarGetMessenger(FlutterDesktopPluginRegistrarRef registrar)
void AddPlugin(std::unique_ptr< Plugin > plugin)
PluginRegistrar(FlutterDesktopPluginRegistrarRef core_registrar)
FlutterDesktopTextureRegistrarRef FlutterDesktopRegistrarGetTextureRegistrar(FlutterDesktopPluginRegistrarRef registrar)
static PluginRegistrarManager * GetInstance()
FlutterDesktopPluginRegistrarRef registrar()
TextureRegistrar * texture_registrar()