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