}
base.generate_cparameters (m, decl_space, cparam_map, func, vdeclarator, carg_map, vcall, direction);
}
-}
-// vim:sw=8 noet
+ public string generate_async_callback_wrapper () {
+ string async_callback_wrapper_func = "_vala_g_async_ready_callback";
+
+ if (!add_wrapper (async_callback_wrapper_func)) {
+ return async_callback_wrapper_func;
+ }
+
+ var function = new CCodeFunction (async_callback_wrapper_func, "void");
+ function.modifiers = CCodeModifiers.STATIC;
+
+ function.add_parameter (new CCodeFormalParameter ("*source_object", "GObject"));
+ function.add_parameter (new CCodeFormalParameter ("*res", "GAsyncResult"));
+ function.add_parameter (new CCodeFormalParameter ("*user_data", "void"));
+
+ push_function (function);
+
+ var res_ref = new CCodeFunctionCall (new CCodeIdentifier ("g_object_ref"));
+ res_ref.add_argument (new CCodeIdentifier ("res"));
+
+ // store reference to async result of inner async function in out async result
+ var ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_simple_async_result_set_op_res_gpointer"));
+ ccall.add_argument (new CCodeIdentifier ("user_data"));
+ ccall.add_argument (res_ref);
+ ccall.add_argument (new CCodeIdentifier ("g_object_unref"));
+ ccode.add_expression (ccall);
+
+ // call user-provided callback
+ ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_simple_async_result_complete"));
+ ccall.add_argument (new CCodeIdentifier ("user_data"));
+ ccode.add_expression (ccall);
+
+ // free async result
+ ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_object_unref"));
+ ccall.add_argument (new CCodeIdentifier ("user_data"));
+ ccode.add_expression (ccall);
+
+ pop_function ();
+
+ cfile.add_function_declaration (function);
+ cfile.add_function (function);
+
+ return async_callback_wrapper_func;
+ }
+}
ccall.add_argument (timeout);
ccall.add_argument (new CCodeConstant ("NULL"));
ccall.add_argument (new CCodeConstant ("NULL"));
- ccall.add_argument (new CCodeIdentifier ("_callback_"));
- ccall.add_argument (new CCodeIdentifier ("_user_data_"));
+
+ // use wrapper as source_object wouldn't be correct otherwise
+ ccall.add_argument (new CCodeIdentifier (generate_async_callback_wrapper ()));
+ var res_wrapper = new CCodeFunctionCall (new CCodeIdentifier ("g_simple_async_result_new"));
+ res_wrapper.add_argument (new CCodeIdentifier ("self"));
+ res_wrapper.add_argument (new CCodeIdentifier ("_callback_"));
+ res_wrapper.add_argument (new CCodeIdentifier ("_user_data_"));
+ res_wrapper.add_argument (new CCodeConstant ("NULL"));
+ ccall.add_argument (res_wrapper);
+
ccode.add_expression (ccall);
}
} else {
var ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_dbus_connection_send_message_with_reply_finish"));
ccall.add_argument (connection);
- ccall.add_argument (new CCodeIdentifier ("_res_"));
+
+ // unwrap async result
+ var inner_res = new CCodeFunctionCall (new CCodeIdentifier ("g_simple_async_result_get_op_res_gpointer"));
+ inner_res.add_argument (new CCodeIdentifier ("_res_"));
+ ccall.add_argument (inner_res);
+
ccall.add_argument (new CCodeConstant ("error"));
ccode.add_expression (new CCodeAssignment (new CCodeIdentifier ("_reply_message"), ccall));
}