Flutter Engine
fl_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 "flutter/shell/platform/linux/public/flutter_linux/fl_plugin_registrar.h"
6 #include "flutter/shell/platform/linux/fl_plugin_registrar_private.h"
7 
8 #include <gmodule.h>
9 
11  GObject parent_instance;
12 
13  // View that plugin is controlling.
14  FlView* view;
15 
16  // Messenger to communicate on.
17  FlBinaryMessenger* messenger;
18 };
19 
20 // Added here to stop the compiler from optimising this function away.
21 G_MODULE_EXPORT GType fl_plugin_registrar_get_type();
22 
23 G_DEFINE_TYPE(FlPluginRegistrar, fl_plugin_registrar, G_TYPE_OBJECT)
24 
25 static void view_weak_notify_cb(gpointer user_data,
26  GObject* where_the_object_was) {
27  FlPluginRegistrar* self = FL_PLUGIN_REGISTRAR(user_data);
28  self->view = nullptr;
29 }
30 
31 static void fl_plugin_registrar_dispose(GObject* object) {
32  FlPluginRegistrar* self = FL_PLUGIN_REGISTRAR(object);
33 
34  if (self->view != nullptr) {
35  g_object_weak_unref(G_OBJECT(self->view), view_weak_notify_cb, self);
36  self->view = nullptr;
37  }
38 
39  g_clear_object(&self->messenger);
40 
41  G_OBJECT_CLASS(fl_plugin_registrar_parent_class)->dispose(object);
42 }
43 
44 static void fl_plugin_registrar_class_init(FlPluginRegistrarClass* klass) {
45  G_OBJECT_CLASS(klass)->dispose = fl_plugin_registrar_dispose;
46 }
47 
48 static void fl_plugin_registrar_init(FlPluginRegistrar* self) {}
49 
50 FlPluginRegistrar* fl_plugin_registrar_new(FlView* view,
51  FlBinaryMessenger* messenger) {
52  g_return_val_if_fail(view == nullptr || FL_IS_VIEW(view), nullptr);
53  g_return_val_if_fail(FL_IS_BINARY_MESSENGER(messenger), nullptr);
54 
55  FlPluginRegistrar* self = FL_PLUGIN_REGISTRAR(
56  g_object_new(fl_plugin_registrar_get_type(), nullptr));
57 
58  self->view = view;
59  if (view != nullptr)
60  g_object_weak_ref(G_OBJECT(view), view_weak_notify_cb, self);
61  self->messenger = FL_BINARY_MESSENGER(g_object_ref(messenger));
62 
63  return self;
64 }
65 
66 G_MODULE_EXPORT FlBinaryMessenger* fl_plugin_registrar_get_messenger(
67  FlPluginRegistrar* self) {
68  g_return_val_if_fail(FL_IS_PLUGIN_REGISTRAR(self), nullptr);
69 
70  return self->messenger;
71 }
72 
73 G_MODULE_EXPORT FlView* fl_plugin_registrar_get_view(FlPluginRegistrar* self) {
74  g_return_val_if_fail(FL_IS_PLUGIN_REGISTRAR(self), nullptr);
75 
76  return self->view;
77 }
FlPluginRegistrar * fl_plugin_registrar_new(FlView *view, FlBinaryMessenger *messenger)
FlBinaryMessenger * messenger
static void fl_plugin_registrar_init(FlPluginRegistrar *self)
G_BEGIN_DECLS FlValue gpointer user_data
static void fl_plugin_registrar_dispose(GObject *object)
G_MODULE_EXPORT FlBinaryMessenger * fl_plugin_registrar_get_messenger(FlPluginRegistrar *self)
G_MODULE_EXPORT FlView * fl_plugin_registrar_get_view(FlPluginRegistrar *self)
static void view_weak_notify_cb(gpointer user_data, GObject *where_the_object_was)
G_DEFINE_TYPE(FlBasicMessageChannelResponseHandle, fl_basic_message_channel_response_handle, G_TYPE_OBJECT) static void fl_basic_message_channel_response_handle_dispose(GObject *object)
static void fl_plugin_registrar_class_init(FlPluginRegistrarClass *klass)
G_MODULE_EXPORT GType fl_plugin_registrar_get_type()