| Flutter Linux Embedder |

incoming_message_dispatcher.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/common/incoming_message_dispatcher.h"
6
7 namespace flutter {
8
9 IncomingMessageDispatcher::IncomingMessageDispatcher(
10 FlutterDesktopMessengerRef messenger)
11 : messenger_(messenger) {}
12
13 IncomingMessageDispatcher::~IncomingMessageDispatcher() = default;
14
15 /// @note Procedure doesn't copy all closures.
16 void IncomingMessageDispatcher::HandleMessage(
17 const FlutterDesktopMessage& message,
18 const std::function<void(void)>& input_block_cb,
19 const std::function<void(void)>& input_unblock_cb) {
20 std::string channel(message.channel);
21
22 auto callback_iterator = callbacks_.find(channel);
23 // Find the handler for the channel; if there isn't one, report the failure.
24 if (callback_iterator == callbacks_.end()) {
25 FlutterDesktopMessengerSendResponse(messenger_, message.response_handle,
26 nullptr, 0);
27 return;
28 }
29 auto& callback_info = callback_iterator->second;
30 const FlutterDesktopMessageCallback& message_callback = callback_info.first;
31
32 // Process the call, handling input blocking if requested.
33 bool block_input = input_blocking_channels_.count(channel) > 0;
34 if (block_input) {
35 input_block_cb();
36 }
37 message_callback(messenger_, &message, callback_info.second);
38 if (block_input) {
39 input_unblock_cb();
40 }
41 }
42
43 void IncomingMessageDispatcher::SetMessageCallback(
44 const std::string& channel,
45 FlutterDesktopMessageCallback callback,
46 void* user_data) {
47 if (!callback) {
48 callbacks_.erase(channel);
49 return;
50 }
51 callbacks_[channel] = std::make_pair(callback, user_data);
52 }
53
54 void IncomingMessageDispatcher::EnableInputBlockingForChannel(
55 const std::string& channel) {
56 input_blocking_channels_.insert(channel);
57 }
58
59 } // namespace flutter
user_data
FlKeyEvent uint64_t FlKeyResponderAsyncCallback gpointer user_data
Definition: fl_key_channel_responder.cc:121
flutter::IncomingMessageDispatcher::HandleMessage
void HandleMessage(const FlutterDesktopMessage &message, const std::function< void(void)> &input_block_cb=[] {}, const std::function< void(void)> &input_unblock_cb=[] {})
Definition: incoming_message_dispatcher.cc:16
flutter::IncomingMessageDispatcher::~IncomingMessageDispatcher
virtual ~IncomingMessageDispatcher()
FlutterDesktopMessengerSendResponse
FLUTTER_EXPORT void FlutterDesktopMessengerSendResponse(FlutterDesktopMessengerRef messenger, const FlutterDesktopMessageResponseHandle *handle, const uint8_t *data, size_t data_length)
flutter
Definition: accessibility_bridge.cc:14
flutter::IncomingMessageDispatcher::SetMessageCallback
void SetMessageCallback(const std::string &channel, FlutterDesktopMessageCallback callback, void *user_data)
Definition: incoming_message_dispatcher.cc:43
FlutterDesktopMessengerRef
struct FlutterDesktopMessenger * FlutterDesktopMessengerRef
Definition: flutter_messenger.h:19
flutter::IncomingMessageDispatcher::IncomingMessageDispatcher
IncomingMessageDispatcher(FlutterDesktopMessengerRef messenger)
Definition: incoming_message_dispatcher.cc:9
FlutterDesktopMessage
Definition: flutter_messenger.h:31
FlutterDesktopMessage::channel
const char * channel
Definition: flutter_messenger.h:35
flutter::IncomingMessageDispatcher::EnableInputBlockingForChannel
void EnableInputBlockingForChannel(const std::string &channel)
Definition: incoming_message_dispatcher.cc:54
incoming_message_dispatcher.h
callback
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
Definition: fl_key_channel_responder.cc:120
FlutterDesktopMessage::response_handle
const FlutterDesktopMessageResponseHandle * response_handle
Definition: flutter_messenger.h:42
FlutterDesktopMessageCallback
void(* FlutterDesktopMessageCallback)(FlutterDesktopMessengerRef, const FlutterDesktopMessage *, void *)
Definition: flutter_messenger.h:49