Flutter Windows Embedder
incoming_message_dispatcher.h
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 #ifndef FLUTTER_SHELL_PLATFORM_COMMON_INCOMING_MESSAGE_DISPATCHER_H_
6 #define FLUTTER_SHELL_PLATFORM_COMMON_INCOMING_MESSAGE_DISPATCHER_H_
7 
8 #include <functional>
9 #include <map>
10 #include <set>
11 #include <string>
12 #include <utility>
13 
15 
16 namespace flutter {
17 
18 // Manages per-channel registration of callbacks for handling messages from the
19 // Flutter engine, and dispatching incoming messages to those handlers.
21  public:
22  // Creates a new IncomingMessageDispatcher. |messenger| must remain valid as
23  // long as this object exists.
25 
27 
28  // Prevent copying.
31  delete;
32 
33  // Routes |message| to the registered handler for its channel, if any.
34  //
35  // If input blocking has been enabled on that channel, wraps the call to the
36  // handler with calls to the given callbacks to block and then unblock input.
37  //
38  // If no handler is registered for the message's channel, sends a
39  // NotImplemented response to the engine.
40  void HandleMessage(
42  const std::function<void(void)>& input_block_cb = [] {},
43  const std::function<void(void)>& input_unblock_cb = [] {});
44 
45  // Registers a message callback for incoming messages from the Flutter
46  // side on the specified channel. |callback| will be called with the message
47  // and |user_data| any time a message arrives on that channel.
48  //
49  // Replaces any existing callback. Pass a null callback to unregister the
50  // existing callback.
51  void SetMessageCallback(const std::string& channel,
53  void* user_data);
54 
55  // Enables input blocking on the given channel name.
56  //
57  // If set, then the parent window should disable input callbacks
58  // while waiting for the handler for messages on that channel to run.
59  void EnableInputBlockingForChannel(const std::string& channel);
60 
61  private:
62  // Handle for interacting with the C messaging API.
63  FlutterDesktopMessengerRef messenger_;
64 
65  // A map from channel names to the FlutterDesktopMessageCallback that should
66  // be called for incoming messages on that channel, along with the void* user
67  // data to pass to it.
68  std::map<std::string, std::pair<FlutterDesktopMessageCallback, void*>>
69  callbacks_;
70 
71  // Channel names for which input blocking should be enabled during the call to
72  // that channel's handler.
73  std::set<std::string> input_blocking_channels_;
74 };
75 
76 } // namespace flutter
77 
78 #endif // FLUTTER_SHELL_PLATFORM_COMMON_INCOMING_MESSAGE_DISPATCHER_H_
flutter::IncomingMessageDispatcher::operator=
IncomingMessageDispatcher & operator=(IncomingMessageDispatcher const &)=delete
flutter::IncomingMessageDispatcher
Definition: incoming_message_dispatcher.h:20
user_data
void * user_data
Definition: flutter_windows_view_unittests.cc:52
flutter_messenger.h
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()
flutter
Definition: accessibility_bridge_windows.cc:11
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
message
Win32Message message
Definition: keyboard_unittests.cc:137
flutter::IncomingMessageDispatcher::EnableInputBlockingForChannel
void EnableInputBlockingForChannel(const std::string &channel)
Definition: incoming_message_dispatcher.cc:54
FlutterDesktopMessageCallback
void(* FlutterDesktopMessageCallback)(FlutterDesktopMessengerRef, const FlutterDesktopMessage *, void *)
Definition: flutter_messenger.h:49
callback
FlutterDesktopBinaryReply callback
Definition: flutter_windows_view_unittests.cc:51