Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp11793432ybi; Thu, 25 Jul 2019 23:36:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqy5EyvHeLMDEK9NmsjwNYl2qXAjBEUAe43TorjVXa2dcoNkUbmcKJ1GJzP3gWtSioC++xH1 X-Received: by 2002:a17:902:9a04:: with SMTP id v4mr91965451plp.95.1564123010127; Thu, 25 Jul 2019 23:36:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564123010; cv=none; d=google.com; s=arc-20160816; b=x5KJp/m2F68uJs5wEZGXO4Y8hAS4aKIce91rQb3C/QWxegiCb9+9QsE76nQq/FfImT /P5BuTnyu0p6oLya0/QdpCWb1rDJFOkKIBvgXxNkWWRe2Ygu0a9+k6nEwC2RJX4a0/R+ OaJIm6ggPEo8MMu907E7fD8/49ZEfyWvyJSLnLJBFhC3NluMzHFFwF3MWNv5PgM3lu5p 6ZvQ7VAjwUSn82t6ENgsI5gC88Xf4AJ4yZYJIo/kXRZR6QZTT+ENJ2oQBTy0OURQZBdv F3cX5JSw/28g4uGGvKbDXeDDpr3m/n38xoBt/GW0w6xZ04qIqYe0mMmj17BX8g/LcPFG ueug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=KqLn8+bE/vEKaDQwLsUmWvs20QwlNFeyMYxnmAqou2s=; b=lhPdO+5VWPTjeIwNuFONSC1IkWkwCvLxGi4a2N5V5zle2bIxVF8OxH/WCwKKjcrsJp fyyvzGoCLiPiFTgc52S1oFkpKuE3+RTxqFnZrtm+vllJDqIQ++ZSX/OSj69A9AfbdKfR zSjIXkvVzgHpV6xSz07kKKvciEsdGpa/M3uM+VrB1pGK2FIUvhwL5dQFDuCHVO37/tSB 4Fj3erFnKQmxTMRxUS0cIoCNhdHOOF/h3R8rVbA62OCawZ80N/2vAQv3cg9YYHD6BNio /emt6bmFF86UfMd23ZFIJ2OxnQuReF6mZ/18m+N+rd8Mc0eaZWM2hSUFNIQrl4mNjFfW OswA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@silvair-com.20150623.gappssmtp.com header.s=20150623 header.b=G3MtroM5; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o3si15782321plb.238.2019.07.25.23.36.21; Thu, 25 Jul 2019 23:36:50 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@silvair-com.20150623.gappssmtp.com header.s=20150623 header.b=G3MtroM5; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725953AbfGZGgQ (ORCPT + 99 others); Fri, 26 Jul 2019 02:36:16 -0400 Received: from mail-lf1-f42.google.com ([209.85.167.42]:33677 "EHLO mail-lf1-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725903AbfGZGgQ (ORCPT ); Fri, 26 Jul 2019 02:36:16 -0400 Received: by mail-lf1-f42.google.com with SMTP id x3so36380184lfc.0 for ; Thu, 25 Jul 2019 23:36:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=silvair-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=KqLn8+bE/vEKaDQwLsUmWvs20QwlNFeyMYxnmAqou2s=; b=G3MtroM5LejJOVC5CyMoLxuqvWEbTCUbqE7lbb/mUpxDALXq8sJSmJgeO1e9vmkj49 G7LY9xszRULbPHgtJGCqKKNWBBV9wqPTDHNEHjDt8iKNG44VPdbFrBPoxy8comNYl3Kg q4A9Iu10PKkHB4XPC2ieT27vd/KGHMoUHqdmdsKNNQKH4ovnoObg+HZmedPCu2HQ3f7N xNAq/nxMKHooVUozVELEk5gw5K9AMCIzlgCy76N1j9zXVsaGXphStUi2T5/vuEwb4r8u oMnzUzUtyVwNOu/vIL3ts8pbWaLI5fQhBcUPu1vdbbCrT0t/5TEmoGW+73/cs2kWPJNq bLcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=KqLn8+bE/vEKaDQwLsUmWvs20QwlNFeyMYxnmAqou2s=; b=t5o+H5J1KnNcI/vcREmzMPRCKlFw7qlkRGiBr/Y1PnC26yjoN1/DWmLlpUl9EFMhC1 EriJEImtpV0Ml9AXvkmOUCcNp4ogEqiomMQf5E5dJ4SlImwEiR6G29RXk8jLDakjjkFH NeU7cRcHMmkS8X0lX5uzdNw7MfifstHSqbDxrUv5w3GYbn/+1G21lZDwoj+FZlqRD5eD IH1FuiRCVmNZzYT+nYfqAHun0fazehQM4jJ/D8u0Gt02ybBtjT5hvVb+TVXHI3SqaIcR PvjCVReIirGFiP37bOaRmrD+U1YBKeocet69hkgBfKmzwEM6drZ0Ul0QnZI2LwZPdEal 769Q== X-Gm-Message-State: APjAAAU4WBxTJmZpL7pHJYA/Y17d80bcqySlUgRgrAhvuodF314ThPsq iNNkpuTTRwJ0OaEkLupTlEFQydxQ8N0= X-Received: by 2002:ac2:5c1d:: with SMTP id r29mr39885894lfp.72.1564122974134; Thu, 25 Jul 2019 23:36:14 -0700 (PDT) Received: from mlowasrzechonek2133.silvair.lan ([217.153.94.18]) by smtp.gmail.com with ESMTPSA id d15sm8039109lfq.76.2019.07.25.23.36.13 for (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 25 Jul 2019 23:36:13 -0700 (PDT) From: =?UTF-8?q?Micha=C5=82=20Lowas-Rzechonek?= To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ v6 1/5] mesh: Convert void pointers to anonymous unions in managed_obj_request Date: Fri, 26 Jul 2019 08:36:02 +0200 Message-Id: <20190726063606.19359-2-michal.lowas-rzechonek@silvair.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190726063606.19359-1-michal.lowas-rzechonek@silvair.com> References: <20190726063606.19359-1-michal.lowas-rzechonek@silvair.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org --- mesh/node.c | 75 +++++++++++++++++++++++++---------------------------- 1 file changed, 35 insertions(+), 40 deletions(-) diff --git a/mesh/node.c b/mesh/node.c index ceb46e4df..e51913edf 100644 --- a/mesh/node.c +++ b/mesh/node.c @@ -58,9 +58,11 @@ #define DEFAULT_CRPL 10 #define DEFAULT_SEQUENCE_NUMBER 0 -#define REQUEST_TYPE_JOIN 0 -#define REQUEST_TYPE_ATTACH 1 -#define REQUEST_TYPE_CREATE 2 +enum request_type { + REQUEST_TYPE_JOIN, + REQUEST_TYPE_ATTACH, + REQUEST_TYPE_CREATE, +}; struct node_element { char *path; @@ -110,10 +112,16 @@ struct mesh_node { }; struct managed_obj_request { - void *data; - void *cb; - void *user_data; - uint8_t type; + union { + const uint8_t *uuid; + struct mesh_node *node; + }; + union { + node_ready_func_t ready_cb; + node_join_ready_func_t join_ready_cb; + }; + struct l_dbus_message *pending_msg; + enum request_type type; }; static struct l_queue *nodes; @@ -1571,7 +1579,7 @@ static void get_managed_objects_cb(struct l_dbus_message *msg, void *user_data) node = l_new(struct mesh_node, 1); node->elements = l_queue_new(); } else { - node = req->data; + node = req->node; } num_ele = 0; @@ -1642,8 +1650,6 @@ static void get_managed_objects_cb(struct l_dbus_message *msg, void *user_data) } if (req->type == REQUEST_TYPE_ATTACH) { - node_ready_func_t cb = req->cb; - if (num_ele != node->num_ele) goto fail; @@ -1652,7 +1658,7 @@ static void get_managed_objects_cb(struct l_dbus_message *msg, void *user_data) node->disc_watch = l_dbus_add_disconnect_watch(bus, node->owner, app_disc_cb, node, NULL); - cb(req->user_data, MESH_ERROR_NONE, node); + req->ready_cb(req->pending_msg, MESH_ERROR_NONE, node); } else goto fail; @@ -1665,8 +1671,6 @@ static void get_managed_objects_cb(struct l_dbus_message *msg, void *user_data) init_storage_dir(node); } else if (req->type == REQUEST_TYPE_JOIN) { - node_join_ready_func_t cb = req->cb; - if (!agent) { l_error("Interface %s not found", MESH_PROVISION_AGENT_INTERFACE); @@ -1675,22 +1679,20 @@ static void get_managed_objects_cb(struct l_dbus_message *msg, void *user_data) node->num_ele = num_ele; set_defaults(node); - memcpy(node->uuid, req->data, 16); + memcpy(node->uuid, req->uuid, 16); if (!create_node_config(node, node->uuid)) goto fail; - cb(node, agent); - + req->join_ready_cb(node, agent); } else { /* Callback for create node request */ - node_ready_func_t cb = req->cb; struct keyring_net_key net_key; uint8_t dev_key[16]; node->num_ele = num_ele; set_defaults(node); - memcpy(node->uuid, req->data, 16); + memcpy(node->uuid, req->uuid, 16); if (!create_node_config(node, node->uuid)) goto fail; @@ -1717,7 +1719,7 @@ static void get_managed_objects_cb(struct l_dbus_message *msg, void *user_data) if (!keyring_put_net_key(node, PRIMARY_NET_IDX, &net_key)) goto fail; - cb(req->user_data, MESH_ERROR_NONE, node); + req->ready_cb(req->pending_msg, MESH_ERROR_NONE, node); } return; @@ -1726,26 +1728,19 @@ fail: mesh_agent_remove(agent); if (!is_new) { - /* Handle failed Attach request */ - node_ready_func_t cb = req->cb; - free_node_dbus_resources(node); - cb(req->user_data, MESH_ERROR_FAILED, node); + req->ready_cb(req->pending_msg, MESH_ERROR_FAILED, node); } else { /* Handle failed Join and Create requests */ if (node) node_remove(node); - if (req->type == REQUEST_TYPE_JOIN) { - node_join_ready_func_t cb = req->cb; - - cb(NULL, NULL); - } else { - node_ready_func_t cb = req->cb; - - cb(req->user_data, MESH_ERROR_FAILED, NULL); - } + if (req->type == REQUEST_TYPE_JOIN) + req->join_ready_cb(NULL, NULL); + else + req->ready_cb(req->pending_msg, MESH_ERROR_FAILED, + NULL); } } @@ -1770,9 +1765,9 @@ int node_attach(const char *app_path, const char *sender, uint64_t token, node->owner = l_strdup(sender); req = l_new(struct managed_obj_request, 1); - req->data = node; - req->cb = cb; - req->user_data = user_data; + req->node = node; + req->ready_cb = cb; + req->pending_msg = user_data; req->type = REQUEST_TYPE_ATTACH; l_dbus_method_call(dbus_get_bus(), sender, app_path, @@ -1794,8 +1789,8 @@ void node_join(const char *app_path, const char *sender, const uint8_t *uuid, l_debug(""); req = l_new(struct managed_obj_request, 1); - req->data = (void *) uuid; - req->cb = cb; + req->uuid = uuid; + req->join_ready_cb = cb; req->type = REQUEST_TYPE_JOIN; l_dbus_method_call(dbus_get_bus(), sender, app_path, @@ -1813,9 +1808,9 @@ void node_create(const char *app_path, const char *sender, const uint8_t *uuid, l_debug(""); req = l_new(struct managed_obj_request, 1); - req->data = (void *) uuid; - req->cb = cb; - req->user_data = user_data; + req->uuid = uuid; + req->ready_cb = cb; + req->pending_msg = user_data; req->type = REQUEST_TYPE_CREATE; l_dbus_method_call(dbus_get_bus(), sender, app_path, -- 2.19.1