// first try cached value
var result = b.add_temp_declaration (null, expression (@"get_cached_property (\"$dbus_name\")"));
b.open_if (expression (@"$result == null"));
+
+ b.open_try ();
b.add_expression (expression (@"$result = call_sync (\"org.freedesktop.DBus.Properties.Get\", new Variant (\"(ss)\", \"$dbus_iface_name\", \"$dbus_name\"), GLib.DBusCallFlags.NONE, $timeout, null)"));
+ b.add_catch_uncaught_error ();
+ b.close ();
+
b.add_expression (expression (@"$result.get (\"(v)\", out $result)"));
b.close ();
var iter = b.add_temp_declaration (null, expression ("arguments.iterator ()"));
- var call = (MethodCall) expression (@"object.$(m.name) ()");
- var finish_call = call;
+ MethodCall call;
+ MethodCall finish_call;
Method ready = null;
CodeBuilder ready_builder = null;
if (m.coroutine) {
+ call = (MethodCall) expression (@"object.$(m.name).begin ()");
wrapper_method (new VoidType (), "gdbus_server_async_ready " + m.get_full_name (), out ready);
ready.add_parameter (new Parameter ("source_object", data_type ("GLib.Object", false)));
ready.add_parameter (new Parameter ("res", data_type ("GLib.AsyncResult", false)));
ready_builder = new CodeBuilder.for_subroutine (ready);
finish_call = (MethodCall) expression (@"(($object_type) source_object).$(m.name).end (res)");
+ } else {
+ call = finish_call = (MethodCall) expression (@"object.$(m.name) ()");
}
var out_args = new string[0];
if (param.variable_type is ObjectType) {
type_name = param.variable_type.data_type.get_full_name ();
}
+
if (type_name == "GLib.Cancellable") {
call.add_argument (expression ("null"));
continue;
}
if (type_name == "GLib.BusName") {
+ call.add_argument (expression ("(GLib.BusName) invocation.get_sender ()"));
continue;
}
} else {
b.add_expression (finish_call);
}
- b.add_catch (data_type ("GLib.Error"), "e");
- b.add_expression (expression ("invocation.return_gerror (e)"));
+ b.add_catch_all ("_invocation_gerror_");
+ b.add_expression (expression ("invocation.return_gerror (_invocation_gerror_)"));
b.add_return ();
b.close ();
if (fd_list != null) {
b.add_expression (expression (@"$reply.set_unix_fd_list ($fd_list)"));
}
+ b.open_try ();
b.add_expression (expression (@"invocation.get_connection ().send_message ($reply, GLib.DBusSendMessageFlags.NONE, null)"));
+ b.add_catch_uncaught_error ();
+ b.close ();
if (m.coroutine) {
pop_builder ();
stmt.add_catch_clause (new CatchClause (error_type, variable_name, current_block, source_reference));
}
+ public void add_catch_all (string? variable_name) {
+ add_catch (data_type ("GLib.Error"), variable_name);
+ }
+
+ public void add_catch_uncaught_error () {
+ add_catch_all ("_uncaught_error_");
+ add_expression (expression ("GLib.critical (_uncaught_error_.message)"));
+ add_expression (expression ("GLib.critical (\"file %s: line %d: uncaught error: %s (%s, %d)\", GLib.Log.FILE, GLib.Log.LINE, _uncaught_error_.message, _uncaught_error_.domain.to_string(), _uncaught_error_.code)"));
+ }
+
public void add_statement (Statement statement) {
current_block.add_statement (statement);
}
current_block = top as Block;
} while (current_block == null);
}
+
+ /* Utilities for building the code */
+
+ public Expression expression (string str) {
+ return new Parser().parse_expression_string (str, source_reference);
+ }
+
+ // only qualified types, will slightly simplify the work of SymbolResolver
+ public static Symbol symbol_from_string (string symbol_string) {
+ Symbol sym = CodeContext.get().root;
+ foreach (unowned string s in symbol_string.split (".")) {
+ sym = sym.scope.lookup (s);
+ }
+ return sym;
+ }
+
+ // only qualified types, will slightly simplify the work of SymbolResolver
+ public static DataType data_type (string s, bool value_owned = true, bool nullable = false) {
+ DataType type = SemanticAnalyzer.get_data_type_for_symbol ((TypeSymbol) symbol_from_string (s));
+ type.value_owned = value_owned;
+ type.nullable = nullable;
+ return type;
+ }
}
return false;
}
- public Symbol symbol_from_string (string symbol_string) {
- Symbol sym = context.root;
- foreach (unowned string s in symbol_string.split (".")) {
- sym = sym.scope.lookup (s);
- }
- return sym;
+ public Symbol symbol_from_string (string s) {
+ return CodeBuilder.symbol_from_string (s);
}
- // only qualified types, will slightly simplify the work of SymbolResolver
public DataType data_type (string s, bool value_owned = true, bool nullable = false) {
- DataType type = SemanticAnalyzer.get_data_type_for_symbol ((TypeSymbol) symbol_from_string (s));
- type.value_owned = value_owned;
- type.nullable = nullable;
- return type;
+ return CodeBuilder.data_type (s, value_owned, nullable);
}
public Expression expression (string str) {
- return new Parser ().parse_expression_string (str, b.source_reference);
+ return b.expression (str);
}
public void check (CodeNode node) {
}
public override Symbol? get_member (string member_name) {
- var root_symbol = source_reference.file.context.root;
+ var root_symbol = CodeContext.get().root;
var gerror_symbol = root_symbol.scope.lookup ("GLib").scope.lookup ("Error");
return gerror_symbol.scope.lookup (member_name);
}