| Flutter Linux Embedder |

event_stream_handler_functions.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_CLIENT_WRAPPER_INCLUDE_FLUTTER_EVENT_STREAM_HANDLER_FUNCTIONS_H_
6 #define FLUTTER_SHELL_PLATFORM_COMMON_CLIENT_WRAPPER_INCLUDE_FLUTTER_EVENT_STREAM_HANDLER_FUNCTIONS_H_
7
8 #include <memory>
9
10 #include "event_sink.h"
11 #include "event_stream_handler.h"
12
13 namespace flutter {
14
15 class EncodableValue;
16
17 // Handler types for each of the StreamHandler setup and teardown
18 // requests.
19 template <typename T>
20 using StreamHandlerListen =
21 std::function<std::unique_ptr<StreamHandlerError<T>>(
22 const T* arguments,
23 std::unique_ptr<EventSink<T>>&& events)>;
24
25 template <typename T>
26 using StreamHandlerCancel =
27 std::function<std::unique_ptr<StreamHandlerError<T>>(const T* arguments)>;
28
29 // An implementation of StreamHandler that pass calls through to
30 // provided function objects.
31 template <typename T = EncodableValue>
32 class StreamHandlerFunctions : public StreamHandler<T> {
33 public:
34 // Creates a handler object that calls the provided functions
35 // for the corresponding StreamHandler outcomes.
36 StreamHandlerFunctions(StreamHandlerListen<T> on_listen,
37 StreamHandlerCancel<T> on_cancel)
38 : on_listen_(on_listen), on_cancel_(on_cancel) {}
39
40 virtual ~StreamHandlerFunctions() = default;
41
42 // Prevent copying.
43 StreamHandlerFunctions(StreamHandlerFunctions const&) = delete;
44 StreamHandlerFunctions& operator=(StreamHandlerFunctions const&) = delete;
45
46 protected:
47 // |flutter::StreamHandler|
48 std::unique_ptr<StreamHandlerError<T>> OnListenInternal(
49 const T* arguments,
50 std::unique_ptr<EventSink<T>>&& events) override {
51 if (on_listen_) {
52 return on_listen_(arguments, std::move(events));
53 }
54
55 auto error = std::make_unique<StreamHandlerError<T>>(
56 "error", "No OnListen handler set", nullptr);
57 return std::move(error);
58 }
59
60 // |flutter::StreamHandler|
61 std::unique_ptr<StreamHandlerError<T>> OnCancelInternal(
62 const T* arguments) override {
63 if (on_cancel_) {
64 return on_cancel_(arguments);
65 }
66
67 auto error = std::make_unique<StreamHandlerError<T>>(
68 "error", "No OnCancel handler set", nullptr);
69 return std::move(error);
70 }
71
72 StreamHandlerListen<T> on_listen_;
73 StreamHandlerCancel<T> on_cancel_;
74 };
75
76 } // namespace flutter
77
78 #endif // FLUTTER_SHELL_PLATFORM_COMMON_CLIENT_WRAPPER_INCLUDE_FLUTTER_EVENT_STREAM_HANDLER_FUNCTIONS_H_
flutter::EventSink< T >
flutter::StreamHandlerFunctions
Definition: event_stream_handler_functions.h:32
flutter::StreamHandlerFunctions::~StreamHandlerFunctions
virtual ~StreamHandlerFunctions()=default
flutter::StreamHandlerFunctions::operator=
StreamHandlerFunctions & operator=(StreamHandlerFunctions const &)=delete
flutter::StreamHandlerFunctions::on_cancel_
StreamHandlerCancel< T > on_cancel_
Definition: event_stream_handler_functions.h:73
flutter::StreamHandlerFunctions::OnCancelInternal
std::unique_ptr< StreamHandlerError< T > > OnCancelInternal(const T *arguments) override
Definition: event_stream_handler_functions.h:61
flutter::StreamHandlerFunctions::on_listen_
StreamHandlerListen< T > on_listen_
Definition: event_stream_handler_functions.h:72
flutter::StreamHandlerFunctions::OnListenInternal
std::unique_ptr< StreamHandlerError< T > > OnListenInternal(const T *arguments, std::unique_ptr< EventSink< T >> &&events) override
Definition: event_stream_handler_functions.h:48
flutter::StreamHandlerFunctions::StreamHandlerFunctions
StreamHandlerFunctions(StreamHandlerFunctions const &)=delete
flutter::StreamHandlerFunctions::StreamHandlerFunctions
StreamHandlerFunctions(StreamHandlerListen< T > on_listen, StreamHandlerCancel< T > on_cancel)
Definition: event_stream_handler_functions.h:36
flutter::StreamHandler
Definition: event_stream_handler.h:38
event_sink.h
event_stream_handler.h
error
const uint8_t uint32_t uint32_t GError ** error
Definition: fl_pixel_buffer_texture_test.cc:40
flutter
Definition: accessibility_bridge.cc:14
flutter::StreamHandlerListen
std::function< std::unique_ptr< StreamHandlerError< T > >(const T *arguments, std::unique_ptr< EventSink< T > > &&events)> StreamHandlerListen
Definition: event_stream_handler_functions.h:23
flutter::StreamHandlerCancel
std::function< std::unique_ptr< StreamHandlerError< T > >(const T *arguments)> StreamHandlerCancel
Definition: event_stream_handler_functions.h:27