diff --git a/mesh/mesh.c b/mesh/mesh.c
index c610582..0f3c3c9 100644
--- a/mesh/mesh.c
+++ b/mesh/mesh.c
mesh_agent_remove(join_pending->agent);
- if (failed) {
- storage_remove_node_config(join_pending->node);
- node_free(join_pending->node);
- }
+ if (failed)
+ node_remove(join_pending->node);
l_free(join_pending);
join_pending = NULL;
static void setup_network_interface(struct l_dbus_interface *iface)
{
l_dbus_interface_method(iface, "Join", 0, join_network_call, "",
- "oay", "app", "uuid");
+ "oay", "app", "uuid");
l_dbus_interface_method(iface, "Cancel", 0, cancel_join_call, "", "");
l_dbus_interface_method(iface, "Attach", 0, attach_call,
- "oa(ya(qa{sv}))", "ot", "node", "configuration",
- "app", "token");
+ "oa(ya(qa{sv}))", "ot", "node",
+ "configuration", "app", "token");
/* TODO: Implement Leave method */
}
setup_network_interface,
NULL, false)) {
l_info("Unable to register %s interface",
- MESH_NETWORK_INTERFACE);
+ MESH_NETWORK_INTERFACE);
return false;
}
diff --git a/mesh/node.c b/mesh/node.c
index c815acf..6c5cd9c 100644
--- a/mesh/node.c
+++ b/mesh/node.c
const struct mesh_node *node = a;
const uint64_t *token = b;
const uint64_t tmp = l_get_u64(node->dev_key);
+
return *token == tmp;
}
return l_queue_find(nodes, match_device_uuid, uuid);
}
+struct mesh_node *node_find_by_token(uint64_t token)
+{
+ return l_queue_find(nodes, match_token, (void *) &token);
+}
+
uint8_t *node_uuid_get(struct mesh_node *node)
{
if (!node)
struct mesh_node *node = data;
/* Unregister io callbacks */
- if(node->net)
+ if (node->net)
mesh_net_detach(node->net);
mesh_net_free(node->net);
l_free(node->app_path);
l_free(node->owner);
+ if (node->disc_watch)
+ l_dbus_remove_watch(dbus_get_bus(), node->disc_watch);
+
if (node->path)
l_dbus_object_remove_interface(dbus_get_bus(), node->path,
MESH_NODE_INTERFACE);
l_free(node);
}
-void node_free(struct mesh_node *node)
+/*
+ * This function is called to free resources and remove the
+ * configuration files for the specified node.
+ */
+void node_remove(struct mesh_node *node)
{
if (!node)
return;
l_queue_remove(nodes, node);
+
+ if (node->cfg_file)
+ storage_remove_node_config(node);
+
free_node_resources(node);
}
return true;
}
-void node_cleanup(void *data)
+static void cleanup_node(void *data)
{
struct mesh_node *node = data;
struct mesh_net *net = node->net;
l_info("Saved final config to %s", node->cfg_file);
}
- if (node->disc_watch)
- l_dbus_remove_watch(dbus_get_bus(), node->disc_watch);
-
free_node_resources(node);
}
+/*
+ * This function is called to free resources and write the current
+ * sequence numbers to the configuration file for each known node.
+ */
void node_cleanup_all(void)
{
- l_queue_destroy(nodes, node_cleanup);
+ l_queue_destroy(nodes, cleanup_node);
l_dbus_unregister_interface(dbus_get_bus(), MESH_NODE_INTERFACE);
}
struct attach_obj_request *req;
struct mesh_node *node;
- l_debug("");
-
- node = l_queue_find(nodes, match_token, &token);
+ node = l_queue_find(nodes, match_token, (void *) &token);
if (!node)
return MESH_ERROR_NOT_FOUND;
diff --git a/mesh/node.h b/mesh/node.h
index ab09b14..ee1d4a6 100644
--- a/mesh/node.h
+++ b/mesh/node.h
struct mesh_agent *agent);
struct mesh_node *node_new(void);
-void node_free(struct mesh_node *node);
+void node_remove(struct mesh_node *node);
void node_join(const char *app_path, const char *sender, const uint8_t *uuid,
node_join_ready_func_t cb);
uint8_t *node_uuid_get(struct mesh_node *node);
struct mesh_net *node_get_net(struct mesh_node *node);
struct mesh_node *node_find_by_addr(uint16_t addr);
struct mesh_node *node_find_by_uuid(uint8_t uuid[16]);
+struct mesh_node *node_find_by_token(uint64_t token);
bool node_is_provisioned(struct mesh_node *node);
bool node_app_key_delete(struct mesh_net *net, uint16_t addr,
uint16_t net_idx, uint16_t idx);
void node_build_attach_reply(struct l_dbus_message *reply, uint64_t token);
void node_id_set(struct mesh_node *node, uint16_t node_id);
bool node_dbus_init(struct l_dbus *bus);
-void node_cleanup(void *node);
void node_cleanup_all(void);
void node_jconfig_set(struct mesh_node *node, void *jconfig);
void *node_jconfig_get(struct mesh_node *node);
diff --git a/mesh/storage.c b/mesh/storage.c
index 0b05823..e790373 100644
--- a/mesh/storage.c
+++ b/mesh/storage.c
uint8_t *uuid;
if (!node_init_from_storage(node, db_node)) {
- node_free(node);
+ node_remove(node);
return false;
}
node = node_new();
- node_jconfig_set(node, jnode);
- node_cfg_file_set(node, out_file);
- node_id_set(node, node_id);
-
result = parse_node(node, jnode);
if (!result) {
json_object_put(jnode);
- node_free(node);
+ node_remove(node);
}
+ node_jconfig_set(node, jnode);
+ node_cfg_file_set(node, out_file);
+ node_id_set(node, node_id);
+
done:
close(fd);
if (str)