}
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"));
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");
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
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) {
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") {
push_function (function);
- cfile.add_include ("gio/gunixfdlist.h");
-
if (ready) {
ccode.add_declaration ("GDBusMethodInvocation *", new CCodeVariableDeclarator ("invocation", new CCodeIdentifier ("_user_data_")));
}
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")));
}
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) {
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) {
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);
}