forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add FlPluginRegistry and FlPluginRegistrar (flutter#18453)
* Add FlPluginRegistry and FlPluginRegistrar
- Loading branch information
1 parent
79b1365
commit 63ed5b1
Showing
9 changed files
with
273 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// 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. | ||
|
||
#include "flutter/shell/platform/linux/public/flutter_linux/fl_plugin_registrar.h" | ||
#include "flutter/shell/platform/linux/fl_plugin_registrar_private.h" | ||
|
||
#include <gmodule.h> | ||
|
||
struct _FlPluginRegistrar { | ||
GObject parent_instance; | ||
|
||
// View that plugin is controlling. | ||
FlView* view; | ||
|
||
// Messenger to communicate on. | ||
FlBinaryMessenger* messenger; | ||
}; | ||
|
||
G_DEFINE_TYPE(FlPluginRegistrar, fl_plugin_registrar, G_TYPE_OBJECT) | ||
|
||
static void view_weak_notify_cb(gpointer user_data, GObject* object) { | ||
FlPluginRegistrar* self = FL_PLUGIN_REGISTRAR(user_data); | ||
self->view = nullptr; | ||
} | ||
|
||
static void fl_plugin_registrar_dispose(GObject* object) { | ||
FlPluginRegistrar* self = FL_PLUGIN_REGISTRAR(object); | ||
|
||
if (self->view != nullptr) { | ||
g_object_weak_unref(G_OBJECT(self->view), view_weak_notify_cb, self); | ||
self->view = nullptr; | ||
} | ||
|
||
g_clear_object(&self->messenger); | ||
|
||
G_OBJECT_CLASS(fl_plugin_registrar_parent_class)->dispose(object); | ||
} | ||
|
||
static void fl_plugin_registrar_class_init(FlPluginRegistrarClass* klass) { | ||
G_OBJECT_CLASS(klass)->dispose = fl_plugin_registrar_dispose; | ||
} | ||
|
||
static void fl_plugin_registrar_init(FlPluginRegistrar* self) {} | ||
|
||
FlPluginRegistrar* fl_plugin_registrar_new(FlView* view, | ||
FlBinaryMessenger* messenger) { | ||
g_return_val_if_fail(FL_IS_VIEW(view), nullptr); | ||
g_return_val_if_fail(FL_IS_BINARY_MESSENGER(messenger), nullptr); | ||
|
||
FlPluginRegistrar* self = FL_PLUGIN_REGISTRAR( | ||
g_object_new(fl_plugin_registrar_get_type(), nullptr)); | ||
|
||
self->view = view; | ||
g_object_weak_ref(G_OBJECT(view), view_weak_notify_cb, self); | ||
self->messenger = FL_BINARY_MESSENGER(g_object_ref(messenger)); | ||
|
||
return self; | ||
} | ||
|
||
G_MODULE_EXPORT FlBinaryMessenger* fl_plugin_registrar_get_messenger( | ||
FlPluginRegistrar* self) { | ||
g_return_val_if_fail(FL_IS_PLUGIN_REGISTRAR(self), nullptr); | ||
|
||
return self->messenger; | ||
} | ||
|
||
G_MODULE_EXPORT FlView* fl_plugin_registrar_get_view(FlPluginRegistrar* self) { | ||
g_return_val_if_fail(FL_IS_PLUGIN_REGISTRAR(self), nullptr); | ||
|
||
return self->view; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// 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_LINUX_FL_PLUGIN_REGISTRAR_PRIVATE_H_ | ||
#define FLUTTER_SHELL_PLATFORM_LINUX_FL_PLUGIN_REGISTRAR_PRIVATE_H_ | ||
|
||
#include "flutter/shell/platform/linux/public/flutter_linux/fl_binary_messenger.h" | ||
#include "flutter/shell/platform/linux/public/flutter_linux/fl_plugin_registrar.h" | ||
|
||
G_BEGIN_DECLS | ||
|
||
/** | ||
* fl_plugin_registrar_new: | ||
* @view: the #FlView that is being plugged into. | ||
* @messenger: the #FlBinaryMessenger to communicate with. | ||
* | ||
* Creates a new #FlPluginRegistrar. | ||
* | ||
* Returns: a new #FlPluginRegistrar. | ||
*/ | ||
FlPluginRegistrar* fl_plugin_registrar_new(FlView* view, | ||
FlBinaryMessenger* messenger); | ||
|
||
G_END_DECLS | ||
|
||
#endif // FLUTTER_SHELL_PLATFORM_LINUX_FL_PLUGIN_REGISTRAR_PRIVATE_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// 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. | ||
|
||
#include "flutter/shell/platform/linux/public/flutter_linux/fl_plugin_registry.h" | ||
|
||
#include <gmodule.h> | ||
|
||
// Added here to stop the compiler from optimising this function away. | ||
G_MODULE_EXPORT GType fl_plugin_registry_get_type(); | ||
|
||
G_DEFINE_INTERFACE(FlPluginRegistry, fl_plugin_registry, G_TYPE_OBJECT) | ||
|
||
void fl_plugin_registry_default_init(FlPluginRegistryInterface* self) {} | ||
|
||
G_MODULE_EXPORT FlPluginRegistrar* fl_plugin_registry_get_registrar_for_plugin( | ||
FlPluginRegistry* self, | ||
const gchar* name) { | ||
g_return_val_if_fail(FL_IS_PLUGIN_REGISTRY(self), nullptr); | ||
g_return_val_if_fail(name != nullptr, nullptr); | ||
|
||
return FL_PLUGIN_REGISTRY_GET_IFACE(self)->get_registrar_for_plugin(self, | ||
name); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
shell/platform/linux/public/flutter_linux/fl_plugin_registrar.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// 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_LINUX_FL_PLUGIN_REGISTRAR_H_ | ||
#define FLUTTER_SHELL_PLATFORM_LINUX_FL_PLUGIN_REGISTRAR_H_ | ||
|
||
#if !defined(__FLUTTER_LINUX_INSIDE__) && !defined(FLUTTER_LINUX_COMPILATION) | ||
#error "Only <flutter_linux/flutter_linux.h> can be included directly." | ||
#endif | ||
|
||
#include <glib-object.h> | ||
#include "fl_binary_messenger.h" | ||
#include "fl_view.h" | ||
|
||
G_BEGIN_DECLS | ||
|
||
G_DECLARE_FINAL_TYPE(FlPluginRegistrar, | ||
fl_plugin_registrar, | ||
FL, | ||
PLUGIN_REGISTRAR, | ||
GObject) | ||
|
||
/** | ||
* FlPluginRegistrar: | ||
* | ||
* #FlPluginRegistrar is used when registering new plugins. | ||
*/ | ||
|
||
/** | ||
* fl_plugin_registrar_get_messenger: | ||
* @registrar: an #FlPluginRegistrar. | ||
* | ||
* Gets the messenger this plugin can communicate with. | ||
* | ||
* Returns: an #FlBinaryMessenger. | ||
*/ | ||
FlBinaryMessenger* fl_plugin_registrar_get_messenger( | ||
FlPluginRegistrar* registrar); | ||
|
||
/** | ||
* fl_plugin_registrar_get_view: | ||
* @registrar: an #FlPluginRegistrar. | ||
* | ||
* Get the view that Flutter is rendering with. | ||
* | ||
* Returns: (allow-none): an #FlView or %NULL if running in headless mode. | ||
*/ | ||
FlView* fl_plugin_registrar_get_view(FlPluginRegistrar* registrar); | ||
|
||
G_END_DECLS | ||
|
||
#endif // FLUTTER_SHELL_PLATFORM_LINUX_FL_PLUGIN_REGISTRAR_H_ |
60 changes: 60 additions & 0 deletions
60
shell/platform/linux/public/flutter_linux/fl_plugin_registry.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// 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_LINUX_FL_PLUGIN_REGISTRY_H_ | ||
#define FLUTTER_SHELL_PLATFORM_LINUX_FL_PLUGIN_REGISTRY_H_ | ||
|
||
#if !defined(__FLUTTER_LINUX_INSIDE__) && !defined(FLUTTER_LINUX_COMPILATION) | ||
#error "Only <flutter_linux/flutter_linux.h> can be included directly." | ||
#endif | ||
|
||
#include <glib-object.h> | ||
#include "fl_plugin_registrar.h" | ||
|
||
G_BEGIN_DECLS | ||
|
||
G_DECLARE_INTERFACE(FlPluginRegistry, | ||
fl_plugin_registry, | ||
FL, | ||
PLUGIN_REGISTRY, | ||
GObject) | ||
|
||
/** | ||
* FlPluginRegistry: | ||
* | ||
* #FlPluginRegistry vends #FlPluginRegistrar objects for named plugins. | ||
*/ | ||
|
||
struct _FlPluginRegistryInterface { | ||
GTypeInterface g_iface; | ||
|
||
/** | ||
* FlPluginRegistry::get_registrar_for_plugin: | ||
* @registry: an #FlPluginRegistry. | ||
* @name: plugin name. | ||
* | ||
* Gets the plugin registrar for the the plugin with @name. | ||
* | ||
* Returns: (transfer full): an #FlPluginRegistrar. | ||
*/ | ||
FlPluginRegistrar* (*get_registrar_for_plugin)(FlPluginRegistry* registry, | ||
const gchar* name); | ||
}; | ||
|
||
/** | ||
* fl_plugin_registry_get_registrar_for_plugin: | ||
* @registry: an #FlPluginRegistry. | ||
* @name: plugin name. | ||
* | ||
* Gets the plugin registrar for the the plugin with @name. | ||
* | ||
* Returns: (transfer full): an #FlPluginRegistrar. | ||
*/ | ||
FlPluginRegistrar* fl_plugin_registry_get_registrar_for_plugin( | ||
FlPluginRegistry* registry, | ||
const gchar* name); | ||
|
||
G_END_DECLS | ||
|
||
#endif // FLUTTER_SHELL_PLATFORM_LINUX_FL_PLUGIN_REGISTRY_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters