Flutter Engine
fl_method_response.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_LINUX_FL_METHOD_RESPONSE_H_
6 #define FLUTTER_SHELL_PLATFORM_LINUX_FL_METHOD_RESPONSE_H_
7 
8 #if !defined(__FLUTTER_LINUX_INSIDE__) && !defined(FLUTTER_LINUX_COMPILATION)
9 #error "Only <flutter_linux/flutter_linux.h> can be included directly."
10 #endif
11 
12 #include <glib-object.h>
13 
14 #include "fl_value.h"
15 
16 G_BEGIN_DECLS
17 
18 /**
19  * FlMethodResponseError:
20  * @FL_METHOD_RESPONSE_ERROR_FAILED: Call failed due to an unspecified error.
21  * @FL_METHOD_RESPONSE_ERROR_REMOTE_ERROR: An error was returned by the other
22  * side of the channel.
23  * @FL_METHOD_RESPONSE_ERROR_NOT_IMPLEMENTED: The requested method is not
24  * implemented.
25  *
26  * Errors set by `fl_method_response_get_result` when the method call response
27  * is not #FlMethodSuccessResponse.
28  */
29 #define FL_METHOD_RESPONSE_ERROR fl_method_response_error_quark()
30 
31 typedef enum {
36 
37 GQuark fl_method_response_error_quark(void) G_GNUC_CONST;
38 
39 G_DECLARE_DERIVABLE_TYPE(FlMethodResponse,
40  fl_method_response,
41  FL,
42  METHOD_RESPONSE,
43  GObject)
44 
45 struct _FlMethodResponseClass {
46  GObjectClass parent_class;
47 };
48 
49 G_DECLARE_FINAL_TYPE(FlMethodSuccessResponse,
50  fl_method_success_response,
51  FL,
52  METHOD_SUCCESS_RESPONSE,
53  FlMethodResponse)
54 
55 G_DECLARE_FINAL_TYPE(FlMethodErrorResponse,
57  FL,
59  FlMethodResponse)
60 
61 G_DECLARE_FINAL_TYPE(FlMethodNotImplementedResponse,
63  FL,
64  METHOD_NOT_IMPLEMENTED_RESPONSE,
65  FlMethodResponse)
66 
67 /**
68  * FlMethodResponse:
69  *
70  * #FlMethodResponse contains the information returned when an #FlMethodChannel
71  * method call returns. If you expect the method call to be successful use
72  * fl_method_response_get_result(). If you want to handle error cases then you
73  * should use code like:
74  *
75  * |[<!-- language="C" -->
76  * if (FL_IS_METHOD_SUCCESS_RESPONSE (response)) {
77  * FlValue *result =
78  * fl_method_success_response_get_result(
79  * FL_METHOD_SUCCESS_RESPONSE (response));
80  * handle_result (result);
81  * } else if (FL_IS_METHOD_ERROR_RESPONSE (response)) {
82  * FlMethodErrorResponse *error_response =
83  * FL_METHOD_ERROR_RESPONSE (response);
84  * handle_error (fl_method_error_response_get_code (error_response),
85  * fl_method_error_response_get_message (error_response),
86  * fl_method_error_response_get_details (error_response));
87  * }
88  * else if (FL_IS_METHOD_ERROR_RESPONSE (response)) {
89  * handle_not_implemented ();
90  * }
91  * }
92  * ]|
93  */
94 
95 /**
96  * FlMethodSuccessResponse:
97  *
98  * #FlMethodSuccessResponse is the #FlMethodResponse returned when a method call
99  * has successfully completed. The result of the method call is obtained using
100  * `fl_method_success_response_get_result`.
101  */
102 
103 /**
104  * FlMethodErrorResponse:
105  *
106  * #FlMethodErrorResponse is the #FlMethodResponse returned when a method call
107  * results in an error. The error details are obtained using
108  * `fl_method_error_response_get_code`, `fl_method_error_response_get_message`
109  * and `fl_method_error_response_get_details`.
110  */
111 
112 /**
113  * FlMethodNotImplementedResponse:
114  *
115  * #FlMethodNotImplementedResponse is the #FlMethodResponse returned when a
116  * method call is not implemented.
117  */
118 
119 /**
120  * fl_method_response_get_result:
121  * @response: an #FlMethodResponse.
122  * @error: (allow-none): #GError location to store the error occurring, or %NULL
123  * to ignore.
124  *
125  * Gets the result of a method call, or an error if the response wasn't
126  * successful.
127  *
128  * Returns: an #FlValue or %NULL on error.
129  */
130 FlValue* fl_method_response_get_result(FlMethodResponse* response,
131  GError** error);
132 
133 /**
134  * fl_method_success_response_new:
135  * @result: (allow-none): the #FlValue returned by the method call or %NULL.
136  *
137  * Creates a response to a method call when that method has successfully
138  * completed.
139  *
140  * Returns: a new #FlMethodResponse.
141  */
142 FlMethodSuccessResponse* fl_method_success_response_new(FlValue* result);
143 
144 /**
145  * fl_method_success_response_get_result:
146  * @response: an #FlMethodSuccessResponse.
147  *
148  * Gets the result of the method call.
149  *
150  * Returns: an #FlValue.
151  */
153  FlMethodSuccessResponse* response);
154 
155 /**
156  * fl_method_error_response_new:
157  * @result: an #FlValue.
158  * @code: an error code.
159  * @message: (allow-none): an error message.
160  * @details: (allow-none): error details.
161  *
162  * Creates a response to a method call when that method has returned an error.
163  *
164  * Returns: a new #FlMethodErrorResponse.
165  */
166 FlMethodErrorResponse* fl_method_error_response_new(const gchar* code,
167  const gchar* message,
168  FlValue* details);
169 
170 /**
171  * fl_method_error_response_get_code:
172  * @response: an #FlMethodErrorResponse.
173  *
174  * Gets the error code reported.
175  *
176  * Returns: an error code.
177  */
178 const gchar* fl_method_error_response_get_code(FlMethodErrorResponse* response);
179 
180 /**
181  * fl_method_error_response_get_message:
182  * @response: an #FlMethodErrorResponse.
183  *
184  * Gets the error message reported.
185  *
186  * Returns: an error message or %NULL if no error message provided.
187  */
189  FlMethodErrorResponse* response);
190 
191 /**
192  * fl_method_error_response_get_details:
193  * @response: an #FlMethodErrorResponse.
194  *
195  * Gets the details provided with this error.
196  *
197  * Returns: an #FlValue or %NULL if no details provided.
198  */
199 FlValue* fl_method_error_response_get_details(FlMethodErrorResponse* response);
200 
201 /**
202  * fl_method_not_implemented_response_new:
203  *
204  * Creates a response to a method call when that method does not exist.
205  *
206  * Returns: a new #FlMethodNotImplementedResponse.
207  */
208 FlMethodNotImplementedResponse* fl_method_not_implemented_response_new();
209 
210 G_END_DECLS
211 
212 #endif // FLUTTER_SHELL_PLATFORM_LINUX_FL_METHOD_RESPONSE_H_
fl_method_not_implemented_response
FlMethodSuccessResponse * fl_method_success_response_new(FlValue *result)
FlValue * fl_method_success_response_get_result(FlMethodSuccessResponse *response)
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:39
METHOD_ERROR_RESPONSE
FlMethodResponse GError ** error
GQuark fl_method_response_error_quark(void) G_GNUC_CONST
G_MODULE_EXPORT const gchar * fl_method_error_response_get_message(FlMethodErrorResponse *self)
FlMethodResponseError
fl_method_error_response
G_DECLARE_DERIVABLE_TYPE(FlMethodResponse, fl_method_response, FL, METHOD_RESPONSE, GObject) struct _FlMethodResponseClass
G_MODULE_EXPORT const gchar * fl_method_error_response_get_code(FlMethodErrorResponse *self)
G_MODULE_EXPORT FlValue * fl_method_response_get_result(FlMethodResponse *self, GError **error)
G_MODULE_EXPORT FlMethodNotImplementedResponse * fl_method_not_implemented_response_new()
G_DECLARE_FINAL_TYPE(FlMethodSuccessResponse, fl_method_success_response, FL, METHOD_SUCCESS_RESPONSE, FlMethodResponse) G_DECLARE_FINAL_TYPE(FlMethodErrorResponse
G_MODULE_EXPORT FlValue * fl_method_error_response_get_details(FlMethodErrorResponse *self)
G_MODULE_EXPORT FlMethodErrorResponse * fl_method_error_response_new(const gchar *code, const gchar *message, FlValue *details)