From: Jürg Billeter Date: Sat, 27 Mar 2010 07:36:00 +0000 (+0100) Subject: D-Bus: Support [DBus (timeout = ...)] attribute in static clients X-Git-Tag: 0.8.0~27 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c7214e116aa05c3e2ae8e4af134a78186fb5deef;p=thirdparty%2Fvala.git D-Bus: Support [DBus (timeout = ...)] attribute in static clients The attribute can be applied to D-Bus methods, properties, and parent declarations. The timeout is specified in milliseconds. --- diff --git a/codegen/valadbusclientmodule.vala b/codegen/valadbusclientmodule.vala index 18c78f80e..38093848a 100644 --- a/codegen/valadbusclientmodule.vala +++ b/codegen/valadbusclientmodule.vala @@ -44,6 +44,19 @@ internal class Vala.DBusClientModule : DBusModule { } } + public CCodeConstant get_dbus_timeout (Symbol symbol) { + int timeout = -1; + + var dbus = symbol.get_attribute ("DBus"); + if (dbus != null && dbus.has_argument ("timeout")) { + timeout = dbus.get_integer ("timeout"); + } else if (symbol.parent_symbol != null) { + return get_dbus_timeout (symbol.parent_symbol); + } + + return new CCodeConstant (timeout.to_string ()); + } + bool has_dbus_error (List error_types) { foreach (DataType error_type in error_types) { if (((ErrorType) error_type).error_domain.get_full_name () == "DBus.Error") { @@ -1304,7 +1317,7 @@ internal class Vala.DBusClientModule : DBusModule { var ccall = new CCodeFunctionCall (new CCodeIdentifier ("dbus_connection_send_with_reply_and_block")); ccall.add_argument (connection); ccall.add_argument (new CCodeIdentifier ("_message")); - ccall.add_argument (new CCodeConstant ("-1")); + ccall.add_argument (get_dbus_timeout (m)); ccall.add_argument (dbus_error); block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeIdentifier ("_reply"), ccall))); @@ -1802,7 +1815,7 @@ internal class Vala.DBusClientModule : DBusModule { var ccall = new CCodeFunctionCall (new CCodeIdentifier ("dbus_connection_send_with_reply_and_block")); ccall.add_argument (connection); ccall.add_argument (new CCodeIdentifier ("_message")); - ccall.add_argument (new CCodeConstant ("-1")); + ccall.add_argument (get_dbus_timeout (m)); ccall.add_argument (dbus_error); block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeIdentifier ("_reply"), ccall))); @@ -1976,7 +1989,7 @@ internal class Vala.DBusClientModule : DBusModule { ccall.add_argument (connection); ccall.add_argument (new CCodeIdentifier ("_message")); ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier ("_pending"))); - ccall.add_argument (new CCodeConstant ("-1")); + ccall.add_argument (get_dbus_timeout (m)); block.add_statement (new CCodeExpressionStatement (ccall)); var conn_unref = new CCodeFunctionCall (new CCodeIdentifier ("dbus_g_connection_unref")); @@ -2450,7 +2463,7 @@ internal class Vala.DBusClientModule : DBusModule { var ccall = new CCodeFunctionCall (new CCodeIdentifier ("dbus_connection_send_with_reply_and_block")); ccall.add_argument (connection); ccall.add_argument (new CCodeIdentifier ("_message")); - ccall.add_argument (new CCodeConstant ("-1")); + ccall.add_argument (get_dbus_timeout (prop)); ccall.add_argument (dbus_error); block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeIdentifier ("_reply"), ccall))); @@ -2603,7 +2616,7 @@ internal class Vala.DBusClientModule : DBusModule { var ccall = new CCodeFunctionCall (new CCodeIdentifier ("dbus_connection_send_with_reply_and_block")); ccall.add_argument (connection); ccall.add_argument (new CCodeIdentifier ("_message")); - ccall.add_argument (new CCodeConstant ("-1")); + ccall.add_argument (get_dbus_timeout (prop)); ccall.add_argument (dbus_error); block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeIdentifier ("_reply"), ccall))); diff --git a/codegen/valadbusmodule.vala b/codegen/valadbusmodule.vala index 83ff555d0..0a3a10c43 100644 --- a/codegen/valadbusmodule.vala +++ b/codegen/valadbusmodule.vala @@ -81,7 +81,7 @@ internal class Vala.DBusModule : GAsyncModule { public string get_dbus_name_for_member (Symbol symbol) { var dbus = symbol.get_attribute ("DBus"); - if (dbus != null) { + if (dbus != null && dbus.has_argument ("name")) { return dbus.get_string ("name"); }