From 0bdea44b72d68068ff2d21774cfe9afd0bcea8ce Mon Sep 17 00:00:00 2001 From: Anupam Roy Date: Thu, 20 Aug 2020 21:04:50 +0530 Subject: [PATCH] mesh: Add api to release node dbus resources Currently, there is no way to release the node and attach it back without disconnection of dbus client. It is possible that dbus client is owner of multiple mesh nodes and it intends to stop using one or multiple nodes & re-attach them back without disconnecting from dbus. This patch introduces a Release API through which dbus client can request to release the node's dbus resources. dbus client can attach the node after releasing it at any point of time. Change-Id: I9ffb2588f1c1dc5d2ccbe45ab5c447ed916c593f Signed-off-by: Anupam Roy --- doc/mesh-api.txt | 12 ++++++++++++ mesh/mesh.c | 28 ++++++++++++++++++++++++++++ mesh/node.c | 16 ++++++++++++++++ mesh/node.h | 3 +++ 4 files changed, 59 insertions(+) diff --git a/doc/mesh-api.txt b/doc/mesh-api.txt index 24cface..e71cf78 100644 --- a/doc/mesh-api.txt +++ b/doc/mesh-api.txt @@ -127,6 +127,18 @@ Methods: PossibleErrors: org.bluez.mesh.Error.InvalidArguments + void Release(uint64 token) + + This removes the dbus resources of the mesh node + identified by the 64-bit token parameter. The token parameter + has been obtained as a result of successful Join() method call. + The mesh node whose dbus resources are removed can be attached back to + network by Attach() call. + + PossibleErrors: + org.bluez.mesh.Error.InvalidArguments, + org.bluez.mesh.Error.NotFound + void CreateNetwork(object app_root, array{byte}[16] uuid) This is the first method that an application calls to become diff --git a/mesh/mesh.c b/mesh/mesh.c index c1eeeaa..c744ddf 100644 --- a/mesh/mesh.c +++ b/mesh/mesh.c @@ -665,6 +665,29 @@ static struct l_dbus_message *leave_call(struct l_dbus *dbus, return l_dbus_message_new_method_return(msg); } +#ifdef TIZEN_FEATURE_BLUEZ_MODIFY +static struct l_dbus_message *release_call(struct l_dbus *dbus, + struct l_dbus_message *msg, + void *user_data) +{ + uint64_t token; + struct mesh_node *node; + + l_debug("Release"); + + if (!l_dbus_message_get_arguments(msg, "t", &token)) + return dbus_error(msg, MESH_ERROR_INVALID_ARGS, NULL); + + node = node_find_by_token(token); + + if (!node) + return dbus_error(msg, MESH_ERROR_NOT_FOUND, NULL); + + node_release_resources(node); + return l_dbus_message_new_method_return(msg); +} +#endif + static void create_join_complete_reply_cb(struct l_dbus_message *message, void *user_data) { @@ -848,6 +871,11 @@ static void setup_network_interface(struct l_dbus_interface *iface) l_dbus_interface_method(iface, "Leave", 0, leave_call, "", "t", "token"); +#ifdef TIZEN_FEATURE_BLUEZ_MODIFY + l_dbus_interface_method(iface, "Release", 0, release_call, "", "t", + "token"); +#endif + l_dbus_interface_method(iface, "CreateNetwork", 0, create_network_call, "", "oay", "app", "uuid"); diff --git a/mesh/node.c b/mesh/node.c index 66b9c41..cd3dd78 100644 --- a/mesh/node.c +++ b/mesh/node.c @@ -340,6 +340,22 @@ static void free_node_resources(void *data) l_free(node); } +#ifdef TIZEN_FEATURE_BLUEZ_MODIFY +/* + * This function is called to free resources + */ +void node_release_resources(struct mesh_node *node) +{ + if (!node) + return; + + /* Free dynamic resources */ + free_node_dbus_resources(node); + + l_debug("Node DBUS Resources are removed"); +} +#endif + /* * This function is called to free resources and remove the * configuration files for the specified node. diff --git a/mesh/node.h b/mesh/node.h index 290681e..7a51205 100644 --- a/mesh/node.h +++ b/mesh/node.h @@ -31,6 +31,9 @@ typedef void (*node_join_ready_func_t) (struct mesh_node *node, struct mesh_agent *agent); void node_remove(struct mesh_node *node); +#ifdef TIZEN_FEATURE_BLUEZ_MODIFY +void node_release_resources(struct mesh_node *node); +#endif void node_join(const char *app_root, const char *sender, const uint8_t *uuid, node_join_ready_func_t cb); uint8_t *node_uuid_get(struct mesh_node *node); -- 2.7.4