Flutter Engine
The Flutter Engine
event_sink.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_SINK_H_
6#define FLUTTER_SHELL_PLATFORM_COMMON_CLIENT_WRAPPER_INCLUDE_FLUTTER_EVENT_SINK_H_
7
8namespace flutter {
9
10class EncodableValue;
11
12// Event callback. Events to be sent to Flutter application
13// act as clients of this interface for sending events.
14template <typename T = EncodableValue>
15class EventSink {
16 public:
17 EventSink() = default;
18 virtual ~EventSink() = default;
19
20 // Prevent copying.
21 EventSink(EventSink const&) = delete;
22 EventSink& operator=(EventSink const&) = delete;
23
24 // Consumes a successful event
25 void Success(const T& event) { SuccessInternal(&event); }
26
27 // Consumes a successful event.
28 void Success() { SuccessInternal(nullptr); }
29
30 // Consumes an error event.
31 void Error(const std::string& error_code,
32 const std::string& error_message,
33 const T& error_details) {
34 ErrorInternal(error_code, error_message, &error_details);
35 }
36
37 // Consumes an error event.
38 void Error(const std::string& error_code,
39 const std::string& error_message = "") {
40 ErrorInternal(error_code, error_message, nullptr);
41 }
42
43 // Consumes end of stream. Ensuing calls to Success() or
44 // Error(), if any, are ignored.
46
47 protected:
48 // Implementation of the public interface, to be provided by subclasses.
49 virtual void SuccessInternal(const T* event = nullptr) = 0;
50
51 // Implementation of the public interface, to be provided by subclasses.
52 virtual void ErrorInternal(const std::string& error_code,
53 const std::string& error_message,
54 const T* error_details) = 0;
55
56 // Implementation of the public interface, to be provided by subclasses.
57 virtual void EndOfStreamInternal() = 0;
58};
59
60} // namespace flutter
61
62#endif // FLUTTER_SHELL_PLATFORM_COMMON_CLIENT_WRAPPER_INCLUDE_FLUTTER_EVENT_SINK_H_
virtual void EndOfStreamInternal()=0
EventSink & operator=(EventSink const &)=delete
void Error(const std::string &error_code, const std::string &error_message="")
Definition: event_sink.h:38
virtual void ErrorInternal(const std::string &error_code, const std::string &error_message, const T *error_details)=0
virtual ~EventSink()=default
void Error(const std::string &error_code, const std::string &error_message, const T &error_details)
Definition: event_sink.h:31
virtual void SuccessInternal(const T *event=nullptr)=0
EventSink(EventSink const &)=delete
void Success(const T &event)
Definition: event_sink.h:25
FlKeyEvent * event
#define T
Definition: precompiler.cc:65