Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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"
12
13namespace flutter {
14
15class EncodableValue;
16
17// Handler types for each of the StreamHandler setup and teardown
18// requests.
19template <typename T>
21 std::function<std::unique_ptr<StreamHandlerError<T>>(
22 const T* arguments,
23 std::unique_ptr<EventSink<T>>&& events)>;
24
25template <typename T>
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.
31template <typename T = EncodableValue>
33 public:
34 // Creates a handler object that calls the provided functions
35 // for the corresponding StreamHandler outcomes.
37 StreamHandlerCancel<T> on_cancel)
38 : on_listen_(on_listen), on_cancel_(on_cancel) {}
39
40 virtual ~StreamHandlerFunctions() = default;
41
42 // Prevent copying.
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
74};
75
76} // namespace flutter
77
78#endif // FLUTTER_SHELL_PLATFORM_COMMON_CLIENT_WRAPPER_INCLUDE_FLUTTER_EVENT_STREAM_HANDLER_FUNCTIONS_H_
std::unique_ptr< StreamHandlerError< T > > OnListenInternal(const T *arguments, std::unique_ptr< EventSink< T > > &&events) override
virtual ~StreamHandlerFunctions()=default
std::unique_ptr< StreamHandlerError< T > > OnCancelInternal(const T *arguments) override
StreamHandlerFunctions(StreamHandlerFunctions const &)=delete
StreamHandlerFunctions & operator=(StreamHandlerFunctions const &)=delete
StreamHandlerFunctions(StreamHandlerListen< T > on_listen, StreamHandlerCancel< T > on_cancel)
const uint8_t uint32_t uint32_t GError ** error
std::function< std::unique_ptr< StreamHandlerError< T > >(const T *arguments, std::unique_ptr< EventSink< T > > &&events)> StreamHandlerListen
std::function< std::unique_ptr< StreamHandlerError< T > >(const T *arguments)> StreamHandlerCancel
#define T