Flutter Engine
The Flutter 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_METHOD_RESULT_H_
6#define FLUTTER_SHELL_PLATFORM_COMMON_CLIENT_WRAPPER_INCLUDE_FLUTTER_METHOD_RESULT_H_
7
8#include <string>
9
10namespace flutter {
11
12class EncodableValue;
13
14// Encapsulates a result returned from a MethodCall. Only one method should be
15// called on any given instance.
16template <typename T = EncodableValue>
18 public:
19 MethodResult() = default;
20
21 virtual ~MethodResult() = default;
22
23 // Prevent copying.
24 MethodResult(MethodResult const&) = delete;
26
27 // Sends a success response, indicating that the call completed successfully
28 // with the given result.
30
31 // Sends a success response, indicating that the call completed successfully
32 // with no result.
33 void Success() { SuccessInternal(nullptr); }
34
35 // Sends an error response, indicating that the call was understood but
36 // handling failed in some way.
37 //
38 // error_code: A string error code describing the error.
39 // error_message: A user-readable error message.
40 // error_details: Arbitrary extra details about the error.
41 void Error(const std::string& error_code,
42 const std::string& error_message,
43 const T& error_details) {
44 ErrorInternal(error_code, error_message, &error_details);
45 }
46
47 // Sends an error response, indicating that the call was understood but
48 // handling failed in some way.
49 //
50 // error_code: A string error code describing the error.
51 // error_message: A user-readable error message (optional).
52 void Error(const std::string& error_code,
53 const std::string& error_message = "") {
54 ErrorInternal(error_code, error_message, nullptr);
55 }
56
57 // Sends a not-implemented response, indicating that the method either was not
58 // recognized, or has not been implemented.
60
61 protected:
62 // Implementation of the public interface, to be provided by subclasses.
63 virtual void SuccessInternal(const T* result) = 0;
64
65 // Implementation of the public interface, to be provided by subclasses.
66 virtual void ErrorInternal(const std::string& error_code,
67 const std::string& error_message,
68 const T* error_details) = 0;
69
70 // Implementation of the public interface, to be provided by subclasses.
71 virtual void NotImplementedInternal() = 0;
72};
73
74} // namespace flutter
75
76#endif // FLUTTER_SHELL_PLATFORM_COMMON_CLIENT_WRAPPER_INCLUDE_FLUTTER_METHOD_RESULT_H_
virtual void ErrorInternal(const std::string &error_code, const std::string &error_message, const T *error_details)=0
MethodResult & operator=(MethodResult const &)=delete
MethodResult(MethodResult const &)=delete
void Error(const std::string &error_code, const std::string &error_message, const T &error_details)
Definition: method_result.h:41
virtual void SuccessInternal(const T *result)=0
virtual void NotImplementedInternal()=0
void Success(const T &result)
Definition: method_result.h:29
void Error(const std::string &error_code, const std::string &error_message="")
Definition: method_result.h:52
virtual ~MethodResult()=default
GAsyncResult * result
#define T
Definition: precompiler.cc:65