43 G_DEFINE_TYPE(FlEventChannel, fl_event_channel, G_TYPE_OBJECT)
49 FlEventChannelHandler handler;
51 handler =
self->listen_handler;
53 handler =
self->cancel_handler;
55 g_autofree gchar* message =
56 g_strdup_printf(
"Unknown event channel request '%s'", name);
61 if (handler ==
nullptr) {
65 return handler(
self,
args, self->handler_data);
72 FlBinaryMessengerResponseHandle* response_handle,
74 FlEventChannel*
self = FL_EVENT_CHANNEL(
user_data);
76 g_autofree gchar* name =
nullptr;
77 g_autoptr(GError)
error =
nullptr;
81 g_warning(
"Failed to decode message on event channel %s: %s", self->name,
88 g_autoptr(FlMethodErrorResponse) response =
91 g_autoptr(GBytes) data =
nullptr;
92 if (response ==
nullptr) {
93 g_autoptr(GError) codec_error =
nullptr;
96 if (data ==
nullptr) {
97 g_warning(
"Failed to encode event channel %s success response: %s",
98 self->name, codec_error->message);
101 g_autoptr(GError) codec_error =
nullptr;
106 if (data ==
nullptr) {
107 g_warning(
"Failed to encode event channel %s error response: %s",
108 self->name, codec_error->message);
114 g_warning(
"Failed to send event channel response: %s",
error->message);
120 if (self->handler_data_destroy_notify !=
nullptr) {
121 self->handler_data_destroy_notify(self->handler_data);
123 self->listen_handler =
nullptr;
124 self->cancel_handler =
nullptr;
125 self->handler_data =
nullptr;
126 self->handler_data_destroy_notify =
nullptr;
131 g_autoptr(FlEventChannel)
self = FL_EVENT_CHANNEL(
user_data);
132 self->channel_closed =
TRUE;
137 FlEventChannel*
self = FL_EVENT_CHANNEL(
object);
139 if (!self->channel_closed) {
141 self->messenger, self->name,
nullptr,
nullptr,
nullptr);
144 g_clear_object(&self->messenger);
145 g_clear_pointer(&self->name, g_free);
146 g_clear_object(&self->codec);
150 G_OBJECT_CLASS(fl_event_channel_parent_class)->dispose(
object);
160 FlBinaryMessenger* messenger,
162 FlMethodCodec* codec) {
163 g_return_val_if_fail(FL_IS_BINARY_MESSENGER(messenger),
nullptr);
164 g_return_val_if_fail(name !=
nullptr,
nullptr);
165 g_return_val_if_fail(FL_IS_METHOD_CODEC(codec),
nullptr);
167 FlEventChannel*
self =
168 FL_EVENT_CHANNEL(g_object_new(fl_event_channel_get_type(),
nullptr));
170 self->messenger = FL_BINARY_MESSENGER(g_object_ref(messenger));
171 self->name = g_strdup(name);
172 self->codec = FL_METHOD_CODEC(g_object_ref(codec));
175 self->messenger, self->name,
message_cb, g_object_ref(
self),
182 FlEventChannel*
self,
183 FlEventChannelHandler listen_handler,
184 FlEventChannelHandler cancel_handler,
186 GDestroyNotify destroy_notify) {
187 g_return_if_fail(FL_IS_EVENT_CHANNEL(
self));
190 self->listen_handler = listen_handler;
191 self->cancel_handler = cancel_handler;
193 self->handler_data_destroy_notify = destroy_notify;
198 GCancellable* cancellable,
200 g_return_val_if_fail(FL_IS_EVENT_CHANNEL(
self), FALSE);
201 g_return_val_if_fail(
event !=
nullptr, FALSE);
203 g_autoptr(GBytes) data =
205 if (data ==
nullptr) {
210 cancellable,
nullptr,
nullptr);
217 const gchar* message,
219 GCancellable* cancellable,
221 g_return_val_if_fail(FL_IS_EVENT_CHANNEL(
self), FALSE);
222 g_return_val_if_fail(code !=
nullptr, FALSE);
223 g_return_val_if_fail(message !=
nullptr, FALSE);
226 self->codec, code, message, details,
error);
227 if (data ==
nullptr) {
232 cancellable,
nullptr,
nullptr);
238 FlEventChannel*
self,
239 GCancellable* cancellable,
241 g_return_val_if_fail(FL_IS_EVENT_CHANNEL(
self), FALSE);
243 cancellable,
nullptr,
nullptr);