| Flutter Linux Embedder |

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
10 namespace flutter {
11
12 class EncodableValue;
13
14 // Encapsulates a result returned from a MethodCall. Only one method should be
15 // called on any given instance.
16 template <typename T = EncodableValue>
17 class MethodResult {
18 public:
19 MethodResult() = default;
20
21 virtual ~MethodResult() = default;
22
23 // Prevent copying.
24 MethodResult(MethodResult const&) = delete;
25 MethodResult& operator=(MethodResult const&) = delete;
26
27 // Sends a success response, indicating that the call completed successfully
28 // with the given result.
29 void Success(const T& result) { SuccessInternal(&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.
59 void NotImplemented() { NotImplementedInternal(); }
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_
flutter::MethodResult::NotImplementedInternal
virtual void NotImplementedInternal()=0
flutter::MethodResult::SuccessInternal
virtual void SuccessInternal(const T *result)=0
flutter::MethodResult::Error
void Error(const std::string &error_code, const std::string &error_message="")
Definition: method_result.h:52
flutter::MethodResult::Error
void Error(const std::string &error_code, const std::string &error_message, const T &error_details)
Definition: method_result.h:41
flutter::MethodResult::Success
void Success()
Definition: method_result.h:33
flutter::MethodResult::MethodResult
MethodResult()=default
flutter
Definition: accessibility_bridge.cc:14
flutter::MethodResult::ErrorInternal
virtual void ErrorInternal(const std::string &error_code, const std::string &error_message, const T *error_details)=0
result
GAsyncResult * result
Definition: fl_text_input_handler.cc:106
flutter::MethodResult::Success
void Success(const T &result)
Definition: method_result.h:29
flutter::MethodResult
Definition: method_result.h:17
flutter::MethodResult::~MethodResult
virtual ~MethodResult()=default
flutter::MethodResult::operator=
MethodResult & operator=(MethodResult const &)=delete
flutter::MethodResult::NotImplemented
void NotImplemented()
Definition: method_result.h:59