Skip to content

Commit

Permalink
Adds PluginRegistry to the C++ client wrapper API (flutter#12287)
Browse files Browse the repository at this point in the history
Makes the plugin registration structure consistent with macOS. This will
be used in generated plugin registrant files rather than a specific
implemenation class, so this helps unblock the creation of generated
registrants on Windows and Linux.
  • Loading branch information
stuartmorgan committed Sep 17, 2019
1 parent d54ed1f commit 709fc6e
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 18 deletions.
1 change: 1 addition & 0 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,7 @@ FILE: ../../../flutter/shell/platform/common/cpp/client_wrapper/include/flutter/
FILE: ../../../flutter/shell/platform/common/cpp/client_wrapper/include/flutter/method_codec.h
FILE: ../../../flutter/shell/platform/common/cpp/client_wrapper/include/flutter/method_result.h
FILE: ../../../flutter/shell/platform/common/cpp/client_wrapper/include/flutter/plugin_registrar.h
FILE: ../../../flutter/shell/platform/common/cpp/client_wrapper/include/flutter/plugin_registry.h
FILE: ../../../flutter/shell/platform/common/cpp/client_wrapper/include/flutter/standard_message_codec.h
FILE: ../../../flutter/shell/platform/common/cpp/client_wrapper/include/flutter/standard_method_codec.h
FILE: ../../../flutter/shell/platform/common/cpp/client_wrapper/json_message_codec.cc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ core_cpp_client_wrapper_includes =
"include/flutter/method_codec.h",
"include/flutter/method_result.h",
"include/flutter/plugin_registrar.h",
"include/flutter/plugin_registry.h",
"include/flutter/standard_message_codec.h",
"include/flutter/standard_method_codec.h",
],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef FLUTTER_SHELL_PLATFORM_COMMON_CPP_CLIENT_WRAPPER_INCLUDE_FLUTTER_PLUGIN_REGISTRY_H_
#define FLUTTER_SHELL_PLATFORM_COMMON_CPP_CLIENT_WRAPPER_INCLUDE_FLUTTER_PLUGIN_REGISTRY_H_

#include <string>

#include <flutter_plugin_registrar.h>

namespace flutter {

// Vends PluginRegistrars for named plugins.
//
// Plugins are identified by unique string keys, typically the name of the
// plugin's main class.
class PluginRegistry {
public:
PluginRegistry() = default;
virtual ~PluginRegistry() = default;

// Prevent copying.
PluginRegistry(PluginRegistry const&) = delete;
PluginRegistry& operator=(PluginRegistry const&) = delete;

// Returns the FlutterDesktopPluginRegistrarRef to register a plugin with the
// given name.
//
// The name must be unique across the application.
virtual FlutterDesktopPluginRegistrarRef GetRegistrarForPlugin(
const std::string& plugin_name) = 0;
};

} // namespace flutter

#endif // FLUTTER_SHELL_PLATFORM_COMMON_CPP_CLIENT_WRAPPER_INCLUDE_FLUTTER_PLUGIN_REGISTRY_H_
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include "flutter_window.h"
#include "plugin_registrar.h"
#include "plugin_registry.h"

namespace flutter {

Expand All @@ -40,14 +41,14 @@ struct WindowProperties {
// requires control of the application's event loop, and is thus useful
// primarily for building a simple one-window shell hosting a Flutter
// application. The final implementation and API will be very different.
class FlutterWindowController {
class FlutterWindowController : public PluginRegistry {
public:
// There must be only one instance of this class in an application at any
// given time, as Flutter does not support multiple engines in one process,
// or multiple views in one engine.
explicit FlutterWindowController(const std::string& icu_data_path);

~FlutterWindowController();
virtual ~FlutterWindowController();

// Prevent copying.
FlutterWindowController(FlutterWindowController const&) = delete;
Expand All @@ -68,13 +69,6 @@ class FlutterWindowController {
const std::string& assets_path,
const std::vector<std::string>& arguments);

// Returns the FlutterDesktopPluginRegistrarRef to register a plugin with the
// given name.
//
// The name must be unique across the application.
FlutterDesktopPluginRegistrarRef GetRegistrarForPlugin(
const std::string& plugin_name);

// The FlutterWindow managed by this controller, if any. Returns nullptr
// before CreateWindow is called, and after RunEventLoop returns;
FlutterWindow* window() { return window_.get(); }
Expand All @@ -89,6 +83,10 @@ class FlutterWindowController {
// Deprecated. Use RunEventLoopWithTimeout.
void RunEventLoop();

// flutter::PluginRegistry:
FlutterDesktopPluginRegistrarRef GetRegistrarForPlugin(
const std::string& plugin_name) override;

private:
// The path to the ICU data file. Set at creation time since it is the same
// for any window created.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <vector>

#include "plugin_registrar.h"
#include "plugin_registry.h"

namespace flutter {

Expand All @@ -19,7 +20,7 @@ namespace flutter {
// This is the primary wrapper class for the desktop C API.
// If you use this class, you should not call any of the setup or teardown
// methods in the C API directly, as this class will do that internally.
class FlutterViewController {
class FlutterViewController : public PluginRegistry {
public:
// There must be only one instance of this class in an application at any
// given time, as Flutter does not support multiple engines in one process,
Expand All @@ -41,26 +42,23 @@ class FlutterViewController {
const std::string& assets_path,
const std::vector<std::string>& arguments);

~FlutterViewController();
virtual ~FlutterViewController();

// Prevent copying.
FlutterViewController(FlutterViewController const&) = delete;
FlutterViewController& operator=(FlutterViewController const&) = delete;

// Returns the FlutterDesktopPluginRegistrarRef to register a plugin with the
// given name.
//
// The name must be unique across the application.
FlutterDesktopPluginRegistrarRef GetRegistrarForPlugin(
const std::string& plugin_name);

// Return backing HWND for manipulation in host application.
HWND GetNativeWindow();

// Must be called in run loop to enable the view to do work on each tick of
// loop.
void ProcessMessages();

// flutter::PluginRegistry:
FlutterDesktopPluginRegistrarRef GetRegistrarForPlugin(
const std::string& plugin_name) override;

private:
// The path to the ICU data file. Set at creation time since it is the same
// for any view created.
Expand Down

0 comments on commit 709fc6e

Please sign in to comment.