agent_operation_handler(
service,
user_data,
- [fields, invocation](agent::connect_data const & d){
+ [object, invocation, fields](agent::connect_data const & d){
using ivi::settings::unique_ptr;
+ // Prepare to build a dictionary, i.e. an array of
+ // dictionary entries, "a{sv}".
+ GVariantBuilder builder;
+ g_variant_builder_init(&builder, G_VARIANT_TYPE_ARRAY);
+
+ bool error_occurred = false;
+ bool found_field = false;
+
// Extract requested mandatory and alternate fields.
GVariantIter * vi = nullptr;
g_variant_get(fields, "(a{sv})", &vi);
// Check if we were supplied the required field, and add
// it to the dictionary result.
auto const i = d.info.find(fname);
- if (i == d.info.end()) {
+ if (i != d.info.end()) {
+ // Note that the dictionary is of the form a{sv} so
+ // we wrap the dictionary string value in a variant.
+ g_variant_builder_add_value(
+ &builder,
+ g_variant_new_dict_entry(
+ g_variant_new_string(fname),
+ g_variant_new_variant(
+ g_variant_new_string(i->second.c_str()))));
+
+ /**
+ * @todo Is there any way to tell if an entry was
+ * added to the indefinite array being
+ * constructed through the glib GVariant builder
+ * interface? We can't get rid of this flag if
+ * that is the case.
+ */
+ found_field = true;
+ } else {
std::string err(
std::string("Required connection field \"")
+ fname
invocation,
"net.connman.Agent.Error.Canceled",
err.c_str());
- break; /// @todo Is this correct?
+
+ error_occurred = true;
+
+ return;
}
}
}
-
}
- });
- GVariant * dictionary = nullptr;
+ if (!error_occurred) {
+ GVariant * dictionary = nullptr;
- // The method return value will contain a dictionary of the
- // requested input fields.
- agent_complete_request_input(object, invocation, dictionary);
+ // We can't call g_variant_builder_end() if no children
+ // (dictionary entries) were added to the indefinite array
+ // being construction through the builder.
+ if (found_field)
+ dictionary = g_variant_builder_end(&builder);
+
+ // The method return value will contain a dictionary of the
+ // requested input fields.
+ agent_complete_request_input(object, invocation, dictionary);
+ }
+ });
return true;
}