Flutter Engine
The Flutter Engine
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
7namespace flutter {
8
11 : messenger_(messenger) {}
12
14
15/// @note Procedure doesn't copy all closures.
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
44 const std::string& channel,
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
55 const std::string& channel) {
56 input_blocking_channels_.insert(channel);
57}
58
59} // namespace flutter
void HandleMessage(const FlutterDesktopMessage &message, const std::function< void(void)> &input_block_cb=[] {}, const std::function< void(void)> &input_unblock_cb=[] {})
IncomingMessageDispatcher(FlutterDesktopMessengerRef messenger)
void EnableInputBlockingForChannel(const std::string &channel)
void SetMessageCallback(const std::string &channel, FlutterDesktopMessageCallback callback, void *user_data)
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
void(* FlutterDesktopMessageCallback)(FlutterDesktopMessengerRef, const FlutterDesktopMessage *, void *)
Dart_NativeFunction function
Definition: fuchsia.cc:51
Win32Message message
void FlutterDesktopMessengerSendResponse(FlutterDesktopMessengerRef messenger, const FlutterDesktopMessageResponseHandle *handle, const uint8_t *data, size_t data_length)
void * user_data