| Flutter Linux Embedder |

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
8 namespace flutter {
9
10 class EncodableValue;
11
12 // Event callback. Events to be sent to Flutter application
13 // act as clients of this interface for sending events.
14 template <typename T = EncodableValue>
15 class 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.
45 void EndOfStream() { EndOfStreamInternal(); }
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_
flutter::EventSink
Definition: event_sink.h:15
flutter::EventSink::EndOfStreamInternal
virtual void EndOfStreamInternal()=0
flutter::EventSink::Error
void Error(const std::string &error_code, const std::string &error_message="")
Definition: event_sink.h:38
flutter::EventSink::EventSink
EventSink()=default
flutter::EventSink::ErrorInternal
virtual void ErrorInternal(const std::string &error_code, const std::string &error_message, const T *error_details)=0
flutter::EventSink::~EventSink
virtual ~EventSink()=default
flutter::EventSink::Success
void Success()
Definition: event_sink.h:28
flutter::EventSink::Error
void Error(const std::string &error_code, const std::string &error_message, const T &error_details)
Definition: event_sink.h:31
flutter::EventSink::SuccessInternal
virtual void SuccessInternal(const T *event=nullptr)=0
flutter::EventSink::EventSink
EventSink(EventSink const &)=delete
flutter::EventSink::Success
void Success(const T &event)
Definition: event_sink.h:25
flutter::EventSink::EndOfStream
void EndOfStream()
Definition: event_sink.h:45
flutter::EventSink::operator=
EventSink & operator=(EventSink const &)=delete
flutter
Definition: accessibility_bridge.cc:14