Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
engine_method_result.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_ENGINE_METHOD_RESULT_H_
6#define FLUTTER_SHELL_PLATFORM_COMMON_CLIENT_WRAPPER_INCLUDE_FLUTTER_ENGINE_METHOD_RESULT_H_
7
8#include <memory>
9#include <string>
10#include <vector>
11
12#include "binary_messenger.h"
13#include "method_codec.h"
14#include "method_result.h"
15
16namespace flutter {
17
18namespace internal {
19// Manages the one-time sending of response data. This is an internal helper
20// class for EngineMethodResult, separated out since the implementation doesn't
21// vary based on the template type.
23 public:
24 explicit ReplyManager(BinaryReply reply_handler_);
26
27 // Prevent copying.
28 ReplyManager(ReplyManager const&) = delete;
30
31 // Sends the given response data (which must either be nullptr, which
32 // indicates an unhandled method, or a response serialized with |codec_|) to
33 // the engine.
34 void SendResponseData(const std::vector<uint8_t>* data);
35
36 private:
37 BinaryReply reply_handler_;
38};
39} // namespace internal
40
41// Implemention of MethodResult that sends a response to the Flutter engine
42// exactly once, encoded using a given codec.
43template <typename T>
45 public:
46 // Creates a result object that will send results to |reply_handler|, encoded
47 // using |codec|. The |codec| pointer must remain valid for as long as this
48 // object exists.
49 EngineMethodResult(BinaryReply reply_handler, const MethodCodec<T>* codec)
50 : reply_manager_(
51 std::make_unique<internal::ReplyManager>(std::move(reply_handler))),
52 codec_(codec) {}
53
55
56 protected:
57 // |flutter::MethodResult|
58 void SuccessInternal(const T* result) override {
59 std::unique_ptr<std::vector<uint8_t>> data =
60 codec_->EncodeSuccessEnvelope(result);
61 reply_manager_->SendResponseData(data.get());
62 }
63
64 // |flutter::MethodResult|
65 void ErrorInternal(const std::string& error_code,
66 const std::string& error_message,
67 const T* error_details) override {
68 std::unique_ptr<std::vector<uint8_t>> data =
69 codec_->EncodeErrorEnvelope(error_code, error_message, error_details);
70 reply_manager_->SendResponseData(data.get());
71 }
72
73 // |flutter::MethodResult|
74 void NotImplementedInternal() override {
75 reply_manager_->SendResponseData(nullptr);
76 }
77
78 private:
79 std::unique_ptr<internal::ReplyManager> reply_manager_;
80
81 const MethodCodec<T>* codec_;
82};
83
84} // namespace flutter
85
86#endif // FLUTTER_SHELL_PLATFORM_COMMON_CLIENT_WRAPPER_INCLUDE_FLUTTER_ENGINE_METHOD_RESULT_H_
void SuccessInternal(const T *result) override
void ErrorInternal(const std::string &error_code, const std::string &error_message, const T *error_details) override
EngineMethodResult(BinaryReply reply_handler, const MethodCodec< T > *codec)
ReplyManager(ReplyManager const &)=delete
void SendResponseData(const std::vector< uint8_t > *data)
ReplyManager & operator=(ReplyManager const &)=delete
GAsyncResult * result
std::function< void(const uint8_t *reply, size_t reply_size)> BinaryReply
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
Definition switches.h:41
Definition ref_ptr.h:256
#define T