[vala/gdbus: 3/8] D-Bus: Use lowlevel message API for methods in GDBus servers



commit 76ff4a60be78f2d171b62acdd0843bb610ddd4ba
Author: Jürg Billeter <j bitron ch>
Date:   Tue Oct 19 08:49:47 2010 +0200

    D-Bus: Use lowlevel message API for methods in GDBus servers
    
    This will be required for file descriptor passing.

 codegen/valagdbusservermodule.vala |   50 ++++++++++++++++++++++++++---------
 1 files changed, 37 insertions(+), 13 deletions(-)
---
diff --git a/codegen/valagdbusservermodule.vala b/codegen/valagdbusservermodule.vala
index 05156ca..4aab777 100644
--- a/codegen/valagdbusservermodule.vala
+++ b/codegen/valagdbusservermodule.vala
@@ -72,6 +72,9 @@ public class Vala.GDBusServerModule : GDBusClientModule {
 			ccode.add_declaration ("GDBusMethodInvocation *", new CCodeVariableDeclarator ("invocation", new CCodeIdentifier ("_user_data_")));
 		}
 
+		var connection = new CCodeFunctionCall (new CCodeIdentifier ("g_dbus_method_invocation_get_connection"));
+		connection.add_argument (new CCodeIdentifier ("invocation"));
+
 		bool no_reply = is_dbus_no_reply (m);
 
 		if (!m.coroutine || ready) {
@@ -189,8 +192,12 @@ public class Vala.GDBusServerModule : GDBusClientModule {
 			if (m.get_error_types ().size > 0) {
 				ccode.open_if (new CCodeIdentifier ("error"));
 
+				// g_dbus_method_invocation_return_gerror consumes reference
+				var ref_invocation = new CCodeFunctionCall (new CCodeIdentifier ("g_object_ref"));
+				ref_invocation.add_argument (new CCodeIdentifier ("invocation"));
+
 				var return_error = new CCodeFunctionCall (new CCodeIdentifier ("g_dbus_method_invocation_return_gerror"));
-				return_error.add_argument (new CCodeIdentifier ("invocation"));
+				return_error.add_argument (ref_invocation);
 				return_error.add_argument (new CCodeIdentifier ("error"));
 				ccode.add_expression (return_error);
 
@@ -199,6 +206,15 @@ public class Vala.GDBusServerModule : GDBusClientModule {
 				ccode.close ();
 			}
 
+			ccode.add_declaration ("GDBusMessage*", new CCodeVariableDeclarator ("_reply_message"));
+
+			var message_expr = new CCodeFunctionCall (new CCodeIdentifier ("g_dbus_method_invocation_get_message"));
+			message_expr.add_argument (new CCodeIdentifier ("invocation"));
+
+			ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_dbus_message_new_method_reply"));
+			ccall.add_argument (message_expr);
+			ccode.add_expression (new CCodeAssignment (new CCodeIdentifier ("_reply_message"), ccall));
+
 			ccode.add_declaration ("GVariant*", new CCodeVariableDeclarator ("_reply"));
 			ccode.add_declaration ("GVariantBuilder", new CCodeVariableDeclarator ("_reply_builder"));
 
@@ -277,6 +293,11 @@ public class Vala.GDBusServerModule : GDBusClientModule {
 			var builder_end = new CCodeFunctionCall (new CCodeIdentifier ("g_variant_builder_end"));
 			builder_end.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier ("_reply_builder")));
 			ccode.add_expression (new CCodeAssignment (new CCodeIdentifier ("_reply"), builder_end));
+
+			var set_body = new CCodeFunctionCall (new CCodeIdentifier ("g_dbus_message_set_body"));
+			set_body.add_argument (new CCodeIdentifier ("_reply_message"));
+			set_body.add_argument (new CCodeIdentifier ("_reply"));
+			ccode.add_expression (set_body);
 		} else {
 			ccode.add_expression (ccall);
 		}
@@ -299,25 +320,24 @@ public class Vala.GDBusServerModule : GDBusClientModule {
 			}
 		}
 
-		if (no_reply) {
-			var return_value = new CCodeFunctionCall (new CCodeIdentifier ("g_object_unref"));
-			return_value.add_argument (new CCodeIdentifier ("invocation"));
-			ccode.add_expression (return_value);
-		} else if (!m.coroutine || ready) {
-			var return_value = new CCodeFunctionCall (new CCodeIdentifier ("g_dbus_method_invocation_return_value"));
-			return_value.add_argument (new CCodeIdentifier ("invocation"));
-			return_value.add_argument (new CCodeIdentifier ("_reply"));
+		if (!no_reply && (!m.coroutine || ready)) {
+			var return_value = new CCodeFunctionCall (new CCodeIdentifier ("g_dbus_connection_send_message"));
+			return_value.add_argument (connection);
+			return_value.add_argument (new CCodeIdentifier ("_reply_message"));
+			return_value.add_argument (new CCodeConstant ("G_DBUS_SEND_MESSAGE_FLAGS_NONE"));
+			return_value.add_argument (new CCodeConstant ("NULL"));
+			return_value.add_argument (new CCodeConstant ("NULL"));
 			ccode.add_expression (return_value);
 
 			if (ready) {
 				var unref_call = new CCodeFunctionCall (new CCodeIdentifier ("g_object_unref"));
 				unref_call.add_argument (new CCodeIdentifier ("invocation"));
 				ccode.add_expression (unref_call);
-
-				unref_call = new CCodeFunctionCall (new CCodeIdentifier ("g_variant_unref"));
-				unref_call.add_argument (new CCodeIdentifier ("_reply"));
-				ccode.add_expression (unref_call);
 			}
+
+			var unref_call = new CCodeFunctionCall (new CCodeIdentifier ("g_object_unref"));
+			unref_call.add_argument (new CCodeIdentifier ("_reply_message"));
+			ccode.add_expression (unref_call);
 		}
 
 		pop_function ();
@@ -586,6 +606,10 @@ public class Vala.GDBusServerModule : GDBusClientModule {
 
 		ccode.close ();
 
+		var ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_object_unref"));
+		ccall.add_argument (new CCodeIdentifier ("invocation"));
+		ccode.add_expression (ccall);
+
 		pop_function ();
 
 		cfile.add_function_declaration (cfunc);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]