]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
D-Bus: Require gio-unix only when using file descriptor passing
authorJürg Billeter <j@bitron.ch>
Fri, 22 Oct 2010 11:06:25 +0000 (13:06 +0200)
committerJürg Billeter <j@bitron.ch>
Sat, 23 Oct 2010 16:11:47 +0000 (18:11 +0200)
codegen/valagdbusclientmodule.vala
codegen/valagdbusmodule.vala
codegen/valagdbusservermodule.vala

index 95eb641f2adff9716017b0c0a9d7d9138f774490..27cda2583c0c1ce3f29a3612cd5a1df24a5270f4 100644 (file)
@@ -415,11 +415,15 @@ public class Vala.GDBusClientModule : GDBusModule {
        }
 
        void generate_marshalling (Method m, CallType call_type, string? iface_name, string? method_name) {
-               cfile.add_include ("gio/gunixfdlist.h");
 
                var connection = new CCodeFunctionCall (new CCodeIdentifier ("g_dbus_proxy_get_connection"));
                connection.add_argument (new CCodeIdentifier ("self"));
 
+               bool uses_fd = dbus_method_uses_file_descriptor (m);
+               if (uses_fd) {
+                       cfile.add_include ("gio/gunixfdlist.h");
+               }
+
                if (call_type != CallType.FINISH) {
                        var destination = new CCodeFunctionCall (new CCodeIdentifier ("g_dbus_proxy_get_name"));
                        destination.add_argument (new CCodeIdentifier ("self"));
@@ -464,8 +468,10 @@ public class Vala.GDBusClientModule : GDBusModule {
                        builder_init.add_argument (new CCodeIdentifier ("G_VARIANT_TYPE_TUPLE"));
                        ccode.add_expression (builder_init);
 
-                       ccode.add_declaration ("GUnixFDList", new CCodeVariableDeclarator ("*_fd_list"));
-                       ccode.add_expression (new CCodeAssignment (new CCodeIdentifier ("_fd_list"), new CCodeFunctionCall (new CCodeIdentifier ("g_unix_fd_list_new"))));
+                       if (uses_fd) {
+                               ccode.add_declaration ("GUnixFDList", new CCodeVariableDeclarator ("*_fd_list"));
+                               ccode.add_expression (new CCodeAssignment (new CCodeIdentifier ("_fd_list"), new CCodeFunctionCall (new CCodeIdentifier ("g_unix_fd_list_new"))));
+                       }
 
                        CCodeExpression cancellable = new CCodeConstant ("NULL");
 
@@ -494,14 +500,16 @@ public class Vala.GDBusClientModule : GDBusModule {
                        set_body.add_argument (new CCodeIdentifier ("_arguments"));
                        ccode.add_expression (set_body);
 
-                       ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_dbus_message_set_unix_fd_list"));
-                       ccall.add_argument (new CCodeIdentifier ("_message"));
-                       ccall.add_argument (new CCodeIdentifier ("_fd_list"));
-                       ccode.add_expression (ccall);
+                       if (uses_fd) {
+                               ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_dbus_message_set_unix_fd_list"));
+                               ccall.add_argument (new CCodeIdentifier ("_message"));
+                               ccall.add_argument (new CCodeIdentifier ("_fd_list"));
+                               ccode.add_expression (ccall);
 
-                       ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_object_unref"));
-                       ccall.add_argument (new CCodeIdentifier ("_fd_list"));
-                       ccode.add_expression (ccall);
+                               ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_object_unref"));
+                               ccall.add_argument (new CCodeIdentifier ("_fd_list"));
+                               ccode.add_expression (ccall);
+                       }
 
                        // send D-Bus message
 
@@ -590,7 +598,9 @@ public class Vala.GDBusClientModule : GDBusModule {
 
                        bool has_result = !(m.return_type is VoidType);
 
-                       ccode.add_declaration ("gint", new CCodeVariableDeclarator.zero ("_fd_index", new CCodeConstant ("0")));
+                       if (uses_fd) {
+                               ccode.add_declaration ("gint", new CCodeVariableDeclarator.zero ("_fd_index", new CCodeConstant ("0")));
+                       }
 
                        foreach (FormalParameter param in m.get_parameters ()) {
                                if (param.direction == ParameterDirection.OUT) {
index 71050178ba6b743c9a6ac3e4bfd3a42f5e8f08ad..6667771667e126069cd6e14c2ef2a4dc8901836a 100644 (file)
@@ -111,6 +111,32 @@ public class Vala.GDBusModule : GVariantModule {
                cfile.add_function (cquark_fun);
        }
 
+       bool is_file_descriptor (DataType type) {
+               if (type is ObjectType) {
+                       if (type.data_type.get_full_name () == "GLib.UnixInputStream" ||
+                           type.data_type.get_full_name () == "GLib.UnixOutputStream" ||
+                           type.data_type.get_full_name () == "GLib.Socket") {
+                               return true;
+                       }
+               }
+
+               return false;
+       }
+
+       public bool dbus_method_uses_file_descriptor (Method method) {
+               foreach (FormalParameter param in method.get_parameters ()) {
+                       if (is_file_descriptor (param.variable_type)) {
+                               return true;
+                       }
+               }
+
+               if (is_file_descriptor (method.return_type)) {
+                       return true;
+               }
+
+               return false;
+       }
+
        CCodeExpression? get_file_descriptor (DataType type, CCodeExpression expr) {
                if (type is ObjectType) {
                        if (type.data_type.get_full_name () == "GLib.UnixInputStream") {
index 9cb79c3e411112aa0992c3b6c0888dd2f73eb34f..9f8813b3ed068e363ee5d827fa367fee6f4155f8 100644 (file)
@@ -74,8 +74,6 @@ public class Vala.GDBusServerModule : GDBusClientModule {
 
                push_function (function);
 
-               cfile.add_include ("gio/gunixfdlist.h");
-
                if (ready) {
                        ccode.add_declaration ("GDBusMethodInvocation *", new CCodeVariableDeclarator ("invocation", new CCodeIdentifier ("_user_data_")));
                }
@@ -84,6 +82,10 @@ public class Vala.GDBusServerModule : GDBusClientModule {
                connection.add_argument (new CCodeIdentifier ("invocation"));
 
                bool no_reply = is_dbus_no_reply (m);
+               bool uses_fd = dbus_method_uses_file_descriptor (m);
+               if (uses_fd) {
+                       cfile.add_include ("gio/gunixfdlist.h");
+               }
 
                if (!m.coroutine || ready) {
                        ccode.add_declaration ("GError*", new CCodeVariableDeclarator ("error", new CCodeConstant ("NULL")));
@@ -109,7 +111,9 @@ public class Vala.GDBusServerModule : GDBusClientModule {
                }
 
                if (!ready) {
-                       ccode.add_declaration ("gint", new CCodeVariableDeclarator.zero ("_fd_index", new CCodeConstant ("0")));
+                       if (uses_fd) {
+                               ccode.add_declaration ("gint", new CCodeVariableDeclarator.zero ("_fd_index", new CCodeConstant ("0")));
+                       }
 
                        foreach (FormalParameter param in m.get_parameters ()) {
                                if (param.direction != ParameterDirection.IN) {
@@ -245,8 +249,10 @@ public class Vala.GDBusServerModule : GDBusClientModule {
                        builder_init.add_argument (new CCodeIdentifier ("G_VARIANT_TYPE_TUPLE"));
                        ccode.add_expression (builder_init);
 
-                       ccode.add_declaration ("GUnixFDList", new CCodeVariableDeclarator ("*_fd_list"));
-                       ccode.add_expression (new CCodeAssignment (new CCodeIdentifier ("_fd_list"), new CCodeFunctionCall (new CCodeIdentifier ("g_unix_fd_list_new"))));
+                       if (uses_fd) {
+                               ccode.add_declaration ("GUnixFDList", new CCodeVariableDeclarator ("*_fd_list"));
+                               ccode.add_expression (new CCodeAssignment (new CCodeIdentifier ("_fd_list"), new CCodeFunctionCall (new CCodeIdentifier ("g_unix_fd_list_new"))));
+                       }
 
                        foreach (FormalParameter param in m.get_parameters ()) {
                                if (param.direction != ParameterDirection.OUT) {
@@ -324,14 +330,16 @@ public class Vala.GDBusServerModule : GDBusClientModule {
                        set_body.add_argument (new CCodeIdentifier ("_reply"));
                        ccode.add_expression (set_body);
 
-                       ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_dbus_message_set_unix_fd_list"));
-                       ccall.add_argument (new CCodeIdentifier ("_reply_message"));
-                       ccall.add_argument (new CCodeIdentifier ("_fd_list"));
-                       ccode.add_expression (ccall);
+                       if (uses_fd) {
+                               ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_dbus_message_set_unix_fd_list"));
+                               ccall.add_argument (new CCodeIdentifier ("_reply_message"));
+                               ccall.add_argument (new CCodeIdentifier ("_fd_list"));
+                               ccode.add_expression (ccall);
 
-                       ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_object_unref"));
-                       ccall.add_argument (new CCodeIdentifier ("_fd_list"));
-                       ccode.add_expression (ccall);
+                               ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_object_unref"));
+                               ccall.add_argument (new CCodeIdentifier ("_fd_list"));
+                               ccode.add_expression (ccall);
+                       }
                } else {
                        ccode.add_expression (ccall);
                }