[vala] GAsync: Implement the finish function
- From: Jürg Billeter <juergbi src gnome org>
- To: svn-commits-list gnome org
- Subject: [vala] GAsync: Implement the finish function
- Date: Sat, 4 Jul 2009 19:20:18 +0000 (UTC)
commit 37b6eec64dba1bb08bd731d858039c4ca9e030f8
Author: Didier 'Ptitjes <ptitjes free fr>
Date: Sun May 31 04:37:33 2009 +0200
GAsync: Implement the finish function
The finish function returns the values stored in the closure as out
parameters and method return value.
Signed-off-by: Didier 'Ptitjes <ptitjes free fr>
codegen/valagasyncmodule.vala | 35 +++++++++++++++++++++++++++++++++++
1 files changed, 35 insertions(+), 0 deletions(-)
---
diff --git a/codegen/valagasyncmodule.vala b/codegen/valagasyncmodule.vala
index f2ab75d..438cbab 100644
--- a/codegen/valagasyncmodule.vala
+++ b/codegen/valagasyncmodule.vala
@@ -220,12 +220,47 @@ internal class Vala.GAsyncModule : GSignalModule {
CCodeFunction generate_finish_function (Method m) {
+ string dataname = Symbol.lower_case_to_camel_case (m.get_cname ()) + "Data";
+
var finishfunc = new CCodeFunction (m.get_real_cname () + "_finish");
var cparam_map = new HashMap<int,CCodeFormalParameter> (direct_hash, direct_equal);
var finishblock = new CCodeBlock ();
+ var return_type = m.return_type;
+ if (!(return_type is VoidType)) {
+ var cdecl = new CCodeDeclaration (m.return_type.get_cname ());
+ cdecl.add_declarator (new CCodeVariableDeclarator ("result"));
+ finishblock.add_statement (cdecl);
+ }
+
+ var datadecl = new CCodeDeclaration (dataname + "*");
+ datadecl.add_declarator (new CCodeVariableDeclarator ("data"));
+ finishblock.add_statement (datadecl);
+
+ var simple_async_result_cast = new CCodeFunctionCall (new CCodeIdentifier ("G_SIMPLE_ASYNC_RESULT"));
+ simple_async_result_cast.add_argument (new CCodeIdentifier ("res"));
+
+ var ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_simple_async_result_get_op_res_gpointer"));
+ ccall.add_argument (simple_async_result_cast);
+ finishblock.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeIdentifier ("data"), ccall)));
+
+ foreach (FormalParameter param in m.get_parameters ()) {
+ if (param.direction != ParameterDirection.IN) {
+ finishblock.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, new CCodeIdentifier (param.name)), new CCodeMemberAccess.pointer (new CCodeIdentifier ("data"), get_variable_cname (param.name)))));
+ finishblock.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeMemberAccess.pointer (new CCodeIdentifier ("data"), get_variable_cname (param.name)), new CCodeConstant ("NULL"))));
+ }
+ }
+
+ if (!(return_type is VoidType)) {
+ finishblock.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeIdentifier ("result"), new CCodeMemberAccess.pointer (new CCodeIdentifier ("data"), "result"))));
+ if (!(return_type is ValueType) || return_type.nullable) {
+ finishblock.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeMemberAccess.pointer (new CCodeIdentifier ("data"), "result"), new CCodeConstant ("NULL"))));
+ }
+ finishblock.add_statement (new CCodeReturnStatement (new CCodeIdentifier ("result")));
+ }
+
cparam_map.set (get_param_pos (0.1), new CCodeFormalParameter ("res", "GAsyncResult*"));
generate_cparameters (m, source_declarations, cparam_map, finishfunc, null, null, null, 2);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]