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/cpp/incoming_message_dispatcher.h"
6 
7 namespace flutter {
8 
11  : messenger_(messenger) {}
12 
14 
15 /// @note Procedure doesn't copy all closures.
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  // Find the handler for the channel; if there isn't one, report the failure.
23  if (callbacks_.find(channel) == callbacks_.end()) {
25  nullptr, 0);
26  return;
27  }
28  auto& callback_info = callbacks_[channel];
29  FlutterDesktopMessageCallback message_callback = callback_info.first;
30 
31  // Process the call, handling input blocking if requested.
32  bool block_input = input_blocking_channels_.count(channel) > 0;
33  if (block_input) {
34  input_block_cb();
35  }
36  message_callback(messenger_, &message, callback_info.second);
37  if (block_input) {
38  input_unblock_cb();
39  }
40 }
41 
43  const std::string& channel,
45  void* user_data) {
46  if (!callback) {
47  callbacks_.erase(channel);
48  return;
49  }
50  callbacks_[channel] = std::make_pair(callback, user_data);
51 }
52 
54  const std::string& channel) {
55  input_blocking_channels_.insert(channel);
56 }
57 
58 } // namespace flutter
IncomingMessageDispatcher(FlutterDesktopMessengerRef messenger)
void SetMessageCallback(const std::string &channel, FlutterDesktopMessageCallback callback, void *user_data)
void HandleMessage(const FlutterDesktopMessage &message, const std::function< void(void)> &input_block_cb=[] {}, const std::function< void(void)> &input_unblock_cb=[] {})
Dart_NativeFunction function
Definition: fuchsia.cc:51
const FlutterDesktopMessageResponseHandle * response_handle
void EnableInputBlockingForChannel(const std::string &channel)
void FlutterDesktopMessengerSendResponse(FlutterDesktopMessengerRef messenger, const FlutterDesktopMessageResponseHandle *handle, const uint8_t *data, size_t data_length)
G_BEGIN_DECLS FlMethodCall gpointer user_data
void(* FlutterDesktopMessageCallback)(FlutterDesktopMessengerRef, const FlutterDesktopMessage *, void *)