From patchwork Tue Aug 20 10:39:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vlad Pruteanu X-Patchwork-Id: 821417 Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2082.outbound.protection.outlook.com [40.107.22.82]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C7776158A18 for ; Tue, 20 Aug 2024 10:43:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.22.82 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724150602; cv=fail; b=UxWzjyT2zOBdhYDKeKorGY9gQt6kJ5hrHLoo19MQGCtigsSkRCTXtEESxScSoQyZXrtcYZVr0IvTX6Tf+KhuOUAEN+Bt2RGGQ3FOl8DP/3ijJcw5BeyvNMye9er9quyQYaku6bojwZQ15NlHqtfi7ZqT+NURcfy41ZImBtvEfuw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724150602; c=relaxed/simple; bh=ITK6I+aiC9pnfqvRCBWZJjnpDjD+OyfZCUy6BaHu4Do=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=EnvAzGiwHao9IuSBa996c+JxKKEidDc2Vy30WhQdFoAFBvAlqKNyZrRLlDYcXsjc6//fpXjWLSFledck7p3z5OP4X3Zz3dzWNbX04km3W0YW/E5owKQ+m3j2m7PQxuZafJxYHcVvtrdEBCcvGVkI8by9n2W1U4PYB4uSk6JFoz8= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b=UPx8IV7c; arc=fail smtp.client-ip=40.107.22.82 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b="UPx8IV7c" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=qkKxc4lA3KX63XdP/8gP4e2APsl40FMp1cWb5dBePYF3DbXmoccvCbJ97SuQzrQxM9v24IM1PAuNmt7R5h7pEAr6T4PnaBSSn6hHBGLkuB9GlCTBk25Z3h67seA0zqxAnvioqyvIMXXJDKxm1u06pdMY/gwRIrnGZ9hTNPEpA2bqvICqbpylOFxF6oDVe4MuzW9zSC9Z6st0QRa099dGl+G/I5yRTnPSk2AVdSaRC0EYfI8pR+NdkTIRZO8TgeYKiaP7c87PtldD0PjUxW/9c1bwhLnBO6EUPLyLqGLeTTpgHolzTUyZChhqLgR1OjF4PlPXO8VhAW+Ct0YBi/i+sQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=WLHtQfZ5kLUXv4cohNM77E6vGC1rveLTAZncRyHE7gk=; b=r5Ta7q0Al5+sXLHVzBPEu+irYvKav6hy6J3+xQWd+MXbMj1HP1Fn/aptWTkHqxh1DkertNXaisFhn4cmk+bETmliLMJZNrPwonYbaBNs5zPDS9Wc1SYsygvLBM6EeaxFUdB4JtKkwEmwVV3+TLU5SAmo7CEuz9PPaRaXvG+3fVSyA5gZYCqwFJ8gKTrBw5hF6F9gCLCNn7v6wGg0OHl3TEuTHmG8hlFA/L8eBcjHCqxHuN/BCN8d1NVtu4wBo2vQHoROf3f2laPLrJTc6agOduuIJb5RDL7HpQn+gogxTzlW9dP1lkf7v31eFCQIgxLpQfviIbsG/EYFQygjxqsA5Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=WLHtQfZ5kLUXv4cohNM77E6vGC1rveLTAZncRyHE7gk=; b=UPx8IV7chn21GhFYYYeluJIu9Bory1IIJ0NEc1wt4AzyG2SVqFQJJb5V9gGWuzl2elLwYKmW9kw0XO6shewRSEjFm97u8l96yPsAyQZ1RGDhHqn6nTSiEDhrKshemTBn7cpFuSjuzyj1cayFYiys76AcwfOc3abdCwD8Y8zVAj04wULQVFGZ2c5iqrPbVq2mQ0gQGxXnpVqK50zunChmBpSbz0+W1kmxts84QL+tl/AxbylR+vInHY4TodSlvNOxQa/7bLCe6AtE+BQN7D2wZRFqaBQg5BU4OkGeyTafFIW6A6Dti9dGWdhVWI0U86CBWHRIPV7rCA+vX4LbJoXeCQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from GV1PR04MB9088.eurprd04.prod.outlook.com (2603:10a6:150:23::20) by PAXPR04MB9641.eurprd04.prod.outlook.com (2603:10a6:102:23f::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.18; Tue, 20 Aug 2024 10:43:16 +0000 Received: from GV1PR04MB9088.eurprd04.prod.outlook.com ([fe80::8775:dba3:39ac:3277]) by GV1PR04MB9088.eurprd04.prod.outlook.com ([fe80::8775:dba3:39ac:3277%3]) with mapi id 15.20.7897.014; Tue, 20 Aug 2024 10:43:16 +0000 From: Vlad Pruteanu To: linux-bluetooth@vger.kernel.org Cc: mihai-octavian.urzica@nxp.com, iulia.tanasescu@nxp.com, andrei.istodorescu@nxp.com, luiz.dentz@gmail.com, Vlad Pruteanu Subject: [PATCH BlueZ 3/8] gdbus: Add g_dbus_proxy_set_property_dict Date: Tue, 20 Aug 2024 13:39:13 +0300 Message-Id: <20240820103918.24246-4-vlad.pruteanu@nxp.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240820103918.24246-1-vlad.pruteanu@nxp.com> References: <20240820103918.24246-1-vlad.pruteanu@nxp.com> X-ClientProxiedBy: MI0P293CA0011.ITAP293.PROD.OUTLOOK.COM (2603:10a6:290:44::11) To GV1PR04MB9088.eurprd04.prod.outlook.com (2603:10a6:150:23::20) Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: GV1PR04MB9088:EE_|PAXPR04MB9641:EE_ X-MS-Office365-Filtering-Correlation-Id: cafd1f41-2359-418b-906c-08dcc104e5ee X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|366016|52116014|1800799024|376014|38350700014; X-Microsoft-Antispam-Message-Info: VR/oRZQ1kZQN4PsRsN1ORvTraLUksDHaSbUjRGVzhX9mJiemyd02UHjw2s6ousdvo5/nHD7N1apidM1CRfG0Ek/O90O6T48G/z6euQscHojsgB9Naj5C1tgw2rpefbUx4SAVQhAgNUmovl0StHmrvkeaLltAxw0ct8Yc5D1TqEeUBjRa7KihJxyJi03pUEisddw1CvuXrUYGAbJ3M2/R8Y0/q3nYVYIdPsWao68V+Y5ZR6RRODEwZTiVn+Z1jW6/08t9FPDAjPnA40hwuOpcxRyBkod9JAqf3pjdFNKT1135ZrTEnYZ9kGEwQPoJ8+5tTtso55xwcwXBqbYysTLYm5zhgTH0utX0rUiybq06DSer7h6SqMDth03P5HyV7SJliNXEgbtIUBXqbP2ZGRZZFkJJa1SWjUWtRAnpbJmAzG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MB9088.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(366016)(52116014)(1800799024)(376014)(38350700014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: kmvgLJenjUB1FzWqutx3dnGQ/dhcjpYcTgjp9vIn0qnH9GXYhGwU48xOjRjKUP56vdzIdaR9AAWVJxf0csMVzkZzjpu7dbcBeThqpmHhj1378z4jJan+rxrlk/pnluWTwaT/4a/V/vpdSNA3gGQRqL6srnjBSc44lQnrxLwyYWOFWxB1xZKyz1zVlYVvQ5aMbF4Iyk8Ums4XBJ7CVIMweOoAs6GTpgH/3G5667Ujngu1c7kVMZNsZHVpnfF2DE96V4mfegaNxUCk0R/7lcQdYtg92hYPqpGulMxM/KhC4eCqWPojfSM0WtgEFyG0rz0fCu5vbxLoWSGm3gTd9D+YOmKBlHoUa3tGuZHiD8L96nRs2/rdlX6BzT0G8TgmcNp2slEULcHSvTAHItb5og30SbwOqcXv2Vu1YR3dCaMqZIA32AV7uv93F0uScOGun0GoyOvXrNEYv2DelD7D/GM9Hwqi+CJaKnEskAzuEIaSY0HcYYM36x52x5o9fDU7W6VNTZdY76CKHtXAnfQnsoY+3mijeDZru9sMFG+HszOynNW5M8+RjFj8CZA8qdqiLNjisiLJekv9u8PgnyfzIGeXgzDT1pLwPkjQl0LwbdNKOh0xd3ARHkqLXyOZ+o/uHSDEhitBxLxd+QzJj7CtGT011DQGERDQjswcuHOyO/RsXycb0CDiyg5cbUFSiEFawWXFpB4F43QKdkXfH+/meTk6qmTSGfuLHAxLT8m5uCz7zeHEi9ngnV4QHCKL2XnoSGGxTCkhXxBJhPKmpamaHgswvJSbuvsToLX4/qhbsIzpi61HJKXtlEppacmCLq/VZ70q8pW83UYpv47n/3G7ZdjMYDSojt4H9NwtFEvYr8ZUzzjB3DC2BKTLltVjaBORKkfLOK0qQabqHOh1ULY8M5xRVPX8Xz58ST2PvEPmjGD+BBuIgYRTM3hVw7xODqFNKR05PsyWjeCJk6C4Zjr3EyS5MFxNmzZkBgavB2BbsRfxTI32pM6dCrBecuwfcEhmA5Gqov5TFgB+02gsEiL4I4OQuof3UzrIqpb2iAug6atjbKbtx374q1+QaFGDxDkB2inVkEyhHTMuhurpfq0+175FmODJoA4FbWToW8dl8l3yKKbObHpOibOfmqf3gMbC1WT7z2GIRoXO4C+hptlBfm4MiO2gC0JhG/KgNMvhl4Tuk3rnukdGBJbqly014aVSfaE+zRurQHgFr/+5l+A9IwgvLLJMmK0Wvu2/R2ILAJpZD7lCk2NeSNa224XTXe/mZ2LEyEgA2Pw1nSwCalNbcqCRvUMUtAixVd3bhV4WzIqFIyi8uGU4I7bH2C/FpyJ8XdlaWey/ebV8fHMnfLdqVD5+kRdUU0AuShyYNl0NKgtQxo6kpgN1OSPyUBt7qaGQCMLVoDaQAP/B/FKcm6c6OGXFvqm+TnIvew1ZwRKBlxlAyMkax4kiVnIGF26+8AKQAHy0cIbL69amHRXbURkWsaDffUsp7yw9eBdTSC8iOJLi3OxR3Hn4OWGx37yB+7IyHhBl5DfQFTQvRQC63CsSohtgnlvSoPxSCcron9YNcJmAtyGapD2Mdh60LeKocN4N5QVV X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: cafd1f41-2359-418b-906c-08dcc104e5ee X-MS-Exchange-CrossTenant-AuthSource: GV1PR04MB9088.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Aug 2024 10:43:16.2877 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: RLyYYrmjzWPlmqDUERRuYpTTS4TPb+ZGZNUpoQmSrRNfXlNFTO+Y27guUDfuCEjI5fRNs6SDHiK5lRkiwiFgRg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR04MB9641 This adds a new gdbus function to allow for the setting of a dictionary type property - a{sv}. It received the name of the property, the name of the entry to be set from the dictionary, it's type and value. These values are passed as a dict entry, to the set method associated with the property. There, it must be parsed and the appropriate entry updated. --- gdbus/client.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++ gdbus/gdbus.h | 6 ++++ 2 files changed, 92 insertions(+) diff --git a/gdbus/client.c b/gdbus/client.c index 3b7faa4e4..980f8fc0f 100644 --- a/gdbus/client.c +++ b/gdbus/client.c @@ -4,6 +4,7 @@ * D-Bus helper library * * Copyright (C) 2004-2011 Marcel Holtmann + * Copyright 2024 NXP * * */ @@ -184,6 +185,33 @@ void g_dbus_dict_append_entry(DBusMessageIter *dict, dict_append_basic(dict, DBUS_TYPE_STRING, &key, type, val); } +static void append_dict_variant(DBusMessageIter *iter, char *entry, int type, + void *val) +{ + DBusMessageIter variant, dict; + + dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT, + DBUS_TYPE_ARRAY_AS_STRING + DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING + DBUS_TYPE_STRING_AS_STRING + DBUS_TYPE_VARIANT_AS_STRING + DBUS_DICT_ENTRY_END_CHAR_AS_STRING, + &variant); + + dbus_message_iter_open_container(&variant, DBUS_TYPE_ARRAY, + DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING + DBUS_TYPE_STRING_AS_STRING + DBUS_TYPE_VARIANT_AS_STRING + DBUS_DICT_ENTRY_END_CHAR_AS_STRING, + &dict); + + g_dbus_dict_append_entry(&dict, entry, type, val); + + dbus_message_iter_close_container(&variant, &dict); + + dbus_message_iter_close_container(iter, &variant); +} + void g_dbus_dict_append_basic_array(DBusMessageIter *dict, int key_type, const void *key, int type, void *val, int n_elements) @@ -885,6 +913,64 @@ gboolean g_dbus_proxy_set_property_basic(GDBusProxy *proxy, return TRUE; } +gboolean g_dbus_proxy_set_property_dict(GDBusProxy *proxy, + const char *name, char *entry, int type, + const void *value, GDBusResultFunction function, + void *user_data, GDBusDestroyFunction destroy) +{ + struct set_property_data *data; + GDBusClient *client; + DBusMessage *msg; + DBusMessageIter iter; + DBusPendingCall *call; + + if (proxy == NULL || name == NULL || value == NULL) + return FALSE; + + if (dbus_type_is_basic(type) == FALSE) + return FALSE; + + client = proxy->client; + if (client == NULL) + return FALSE; + + data = g_try_new0(struct set_property_data, 1); + if (data == NULL) + return FALSE; + + data->function = function; + data->user_data = user_data; + data->destroy = destroy; + + msg = dbus_message_new_method_call(client->service_name, + proxy->obj_path, DBUS_INTERFACE_PROPERTIES, "Set"); + if (msg == NULL) { + g_free(data); + return FALSE; + } + + dbus_message_iter_init_append(msg, &iter); + dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, + &proxy->interface); + dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &name); + + append_dict_variant(&iter, entry, type, &value); + + if (g_dbus_send_message_with_reply(client->dbus_conn, msg, + &call, -1) == FALSE) { + dbus_message_unref(msg); + g_free(data); + return FALSE; + } + + dbus_pending_call_set_notify(call, set_property_reply, data, g_free); + dbus_pending_call_unref(call); + + dbus_message_unref(msg); + + return TRUE; +} + gboolean g_dbus_proxy_set_property_array(GDBusProxy *proxy, const char *name, int type, const void *value, size_t size, GDBusResultFunction function, diff --git a/gdbus/gdbus.h b/gdbus/gdbus.h index 6fe09b743..4aaf73b62 100644 --- a/gdbus/gdbus.h +++ b/gdbus/gdbus.h @@ -4,6 +4,7 @@ * D-Bus helper library * * Copyright (C) 2004-2011 Marcel Holtmann + * Copyright 2024 NXP * * */ @@ -362,6 +363,11 @@ gboolean g_dbus_proxy_set_property_basic(GDBusProxy *proxy, GDBusResultFunction function, void *user_data, GDBusDestroyFunction destroy); +gboolean g_dbus_proxy_set_property_dict(GDBusProxy *proxy, + const char *name, char *entry, int type, + const void *value, GDBusResultFunction function, + void *user_data, GDBusDestroyFunction destroy); + gboolean g_dbus_proxy_set_property_array(GDBusProxy *proxy, const char *name, int type, const void *value, size_t size, GDBusResultFunction function,