34 G_DEFINE_TYPE(FlMethodChannel, fl_method_channel, G_TYPE_OBJECT)
40 FlBinaryMessengerResponseHandle* response_handle,
42 FlMethodChannel*
self = FL_METHOD_CHANNEL(
user_data);
44 if (self->method_call_handler ==
nullptr) {
48 g_autofree gchar* method =
nullptr;
50 g_autoptr(GError)
error =
nullptr;
53 g_warning(
"Failed to decode method call: %s",
error->message);
59 self->method_call_handler(
self,
method_call, self->method_call_handler_data);
66 g_autoptr(GTask) task = G_TASK(
user_data);
67 g_task_return_pointer(task, g_object_ref(result), g_object_unref);
72 g_autoptr(FlMethodChannel)
self = FL_METHOD_CHANNEL(
user_data);
74 self->channel_closed =
TRUE;
77 if (self->method_call_handler_destroy_notify !=
nullptr) {
78 self->method_call_handler_destroy_notify(self->method_call_handler_data);
80 self->method_call_handler =
nullptr;
81 self->method_call_handler_data =
nullptr;
82 self->method_call_handler_destroy_notify =
nullptr;
86 FlMethodChannel*
self = FL_METHOD_CHANNEL(
object);
92 g_clear_object(&self->messenger);
93 g_clear_pointer(&self->name, g_free);
94 g_clear_object(&self->codec);
96 if (self->method_call_handler_destroy_notify !=
nullptr) {
97 self->method_call_handler_destroy_notify(self->method_call_handler_data);
99 self->method_call_handler =
nullptr;
100 self->method_call_handler_data =
nullptr;
101 self->method_call_handler_destroy_notify =
nullptr;
103 G_OBJECT_CLASS(fl_method_channel_parent_class)->dispose(
object);
113 FlBinaryMessenger* messenger,
115 FlMethodCodec* codec) {
116 g_return_val_if_fail(FL_IS_BINARY_MESSENGER(messenger),
nullptr);
117 g_return_val_if_fail(name !=
nullptr,
nullptr);
118 g_return_val_if_fail(FL_IS_METHOD_CODEC(codec),
nullptr);
120 FlMethodChannel*
self =
121 FL_METHOD_CHANNEL(g_object_new(fl_method_channel_get_type(),
nullptr));
123 self->messenger = FL_BINARY_MESSENGER(g_object_ref(messenger));
124 self->name = g_strdup(name);
125 self->codec = FL_METHOD_CODEC(g_object_ref(codec));
128 self->messenger, self->name,
message_cb, g_object_ref(
self),
135 FlMethodChannel*
self,
136 FlMethodChannelMethodCallHandler handler,
138 GDestroyNotify destroy_notify) {
139 g_return_if_fail(FL_IS_METHOD_CHANNEL(
self));
142 if (self->channel_closed) {
143 if (handler !=
nullptr) {
145 "Attempted to set method call handler on a closed FlMethodChannel");
147 if (destroy_notify !=
nullptr) {
153 if (self->method_call_handler_destroy_notify !=
nullptr) {
154 self->method_call_handler_destroy_notify(self->method_call_handler_data);
157 self->method_call_handler = handler;
158 self->method_call_handler_data =
user_data;
159 self->method_call_handler_destroy_notify = destroy_notify;
163 FlMethodChannel*
self,
166 GCancellable* cancellable,
167 GAsyncReadyCallback callback,
169 g_return_if_fail(FL_IS_METHOD_CHANNEL(
self));
170 g_return_if_fail(method !=
nullptr);
172 g_autoptr(GTask) task =
173 callback !=
nullptr ? g_task_new(
self, cancellable, callback,
user_data)
176 g_autoptr(GError)
error =
nullptr;
177 g_autoptr(GBytes) message =
179 if (message ==
nullptr) {
180 if (task !=
nullptr) {
181 g_task_return_error(task, g_error_copy(
error));
187 self->messenger, self->name, message, cancellable,
189 g_steal_pointer(&task));
193 FlMethodChannel*
self,
194 GAsyncResult* result,
196 g_return_val_if_fail(FL_IS_METHOD_CHANNEL(
self),
nullptr);
197 g_return_val_if_fail(g_task_is_valid(result,
self),
nullptr);
199 GTask* task = G_TASK(result);
200 g_autoptr(GAsyncResult) r =
201 G_ASYNC_RESULT(g_task_propagate_pointer(task,
error));
206 g_autoptr(GBytes) response =
208 if (response ==
nullptr) {
216 FlMethodChannel*
self,
217 FlBinaryMessengerResponseHandle* response_handle,
218 FlMethodResponse* response,
220 g_return_val_if_fail(FL_IS_METHOD_CHANNEL(
self), FALSE);
221 g_return_val_if_fail(FL_IS_BINARY_MESSENGER_RESPONSE_HANDLE(response_handle),
223 g_return_val_if_fail(FL_IS_METHOD_RESPONSE(response), FALSE);
225 g_autoptr(GBytes) message =
227 if (message ==
nullptr) {
G_DEFINE_TYPE(FlBasicMessageChannelResponseHandle, fl_basic_message_channel_response_handle, G_TYPE_OBJECT) static void fl_basic_message_channel_response_handle_dispose(GObject *object)
G_MODULE_EXPORT GBytes * fl_binary_messenger_send_on_channel_finish(FlBinaryMessenger *self, GAsyncResult *result, GError **error)
G_MODULE_EXPORT void fl_binary_messenger_set_message_handler_on_channel(FlBinaryMessenger *self, const gchar *channel, FlBinaryMessengerMessageHandler handler, gpointer user_data, GDestroyNotify destroy_notify)
G_MODULE_EXPORT void fl_binary_messenger_send_on_channel(FlBinaryMessenger *self, const gchar *channel, GBytes *message, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
G_MODULE_EXPORT gboolean fl_binary_messenger_send_response(FlBinaryMessenger *self, FlBinaryMessengerResponseHandle *response_handle, GBytes *response, GError **error)
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
G_BEGIN_DECLS G_MODULE_EXPORT FlValue gpointer user_data
FlMethodCall * fl_method_call_new(const gchar *name, FlValue *args, FlMethodChannel *channel, FlBinaryMessengerResponseHandle *response_handle)
static void message_cb(FlBinaryMessenger *messenger, const gchar *channel, GBytes *message, FlBinaryMessengerResponseHandle *response_handle, gpointer user_data)
static void fl_method_channel_class_init(FlMethodChannelClass *klass)
static void fl_method_channel_init(FlMethodChannel *self)
G_MODULE_EXPORT void fl_method_channel_invoke_method(FlMethodChannel *self, const gchar *method, FlValue *args, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
static void message_response_cb(GObject *object, GAsyncResult *result, gpointer user_data)
G_MODULE_EXPORT FlMethodChannel * fl_method_channel_new(FlBinaryMessenger *messenger, const gchar *name, FlMethodCodec *codec)
gboolean fl_method_channel_respond(FlMethodChannel *self, FlBinaryMessengerResponseHandle *response_handle, FlMethodResponse *response, GError **error)
static void fl_method_channel_dispose(GObject *object)
static void channel_closed_cb(gpointer user_data)
G_MODULE_EXPORT FlMethodResponse * fl_method_channel_invoke_method_finish(FlMethodChannel *self, GAsyncResult *result, GError **error)
G_MODULE_EXPORT void fl_method_channel_set_method_call_handler(FlMethodChannel *self, FlMethodChannelMethodCallHandler handler, gpointer user_data, GDestroyNotify destroy_notify)
G_BEGIN_DECLS G_MODULE_EXPORT FlMethodCall * method_call
GBytes * fl_method_codec_encode_response(FlMethodCodec *self, FlMethodResponse *response, GError **error)
GBytes * fl_method_codec_encode_method_call(FlMethodCodec *self, const gchar *name, FlValue *args, GError **error)
gboolean fl_method_codec_decode_method_call(FlMethodCodec *self, GBytes *message, gchar **name, FlValue **args, GError **error)
FlMethodResponse * fl_method_codec_decode_response(FlMethodCodec *self, GBytes *message, GError **error)
const uint8_t uint32_t uint32_t GError ** error
typedefG_BEGIN_DECLS struct _FlValue FlValue
FlMethodChannelMethodCallHandler method_call_handler
FlBinaryMessenger * messenger
GDestroyNotify method_call_handler_destroy_notify
gpointer method_call_handler_data