int32_t vrs_send_node_destroy(const uint8_t session_id, const uint8_t prio, const uint32_t node_id) { struct Generic_Cmd *node_destroy_cmd = v_node_destroy_create(node_id); return vc_send_command(session_id, prio, node_destroy_cmd); }
/** * \brief This function send Destroy_Node command to the all clients that * know about this node. * * This function only send Node_Destroy command. Own node destruction is done, * when all clients confirmed receiving of Node_Destroy command. */ static int vs_node_send_destroy(struct VSNode *node) { struct VSEntityFollower *node_follower; struct Generic_Cmd *node_destroy_cmd=NULL; int ret = 0; /* Has node any child? */ if(node->children_links.first != NULL) { v_print_log(VRS_PRINT_DEBUG_MSG, "node (id: %d) has children\n", node->id); goto end; } /* Send node_destroy to all clients, that knows about this node. These * clients received node_create command. */ node_follower = node->node_folls.first; while(node_follower!=NULL) { /* Node has to be in CREATED state */ if(node_follower->state == ENTITY_CREATED) { /* Create Destroy_Node command */ node_destroy_cmd = v_node_destroy_create(node->id); /* Push this command to the outgoing queue */ if ( node_destroy_cmd!= NULL && v_out_queue_push_tail(node_follower->node_sub->session->out_queue, node_follower->node_sub->prio, node_destroy_cmd) == 1) { node_follower->state = ENTITY_DELETING; ret = 1; } else { v_print_log(VRS_PRINT_DEBUG_MSG, "node_destroy (id: %d) wasn't added to the queue\n", node->id); } } else { v_print_log(VRS_PRINT_DEBUG_MSG, "Can't delete node %d, because it isn't in CREATED state\n"); } node_follower = node_follower->next; } node->state = ENTITY_DELETING; end: return ret; }
/** * \brief This function is called, when server receive ack command of packet * that contained node_create command sent to the client * * When this function is called, then we can be sure, that client knows about * the node. This node can be switched to the NODE_CREATED state for the * follower of this node */ int vs_handle_node_create_ack(struct VS_CTX *vs_ctx, struct VSession *vsession, struct Generic_Cmd *cmd) { VSNode *node; struct VSEntityFollower *node_follower; struct Node_Create_Ack_Cmd *node_create_ack = (struct Node_Create_Ack_Cmd*)cmd; int all_created = 1; /* Try to find node */ if((node = vs_node_find(vs_ctx, node_create_ack->node_id)) == NULL) { v_print_log(VRS_PRINT_DEBUG_MSG, "%s() node (id: %d) not found\n", __FUNCTION__, node_create_ack->node_id); return 0; } node_follower = node->node_folls.first; while(node_follower != NULL) { if(node_follower->node_sub->session->session_id == vsession->session_id) { if(node_follower->state == ENTITY_CREATING) { node_follower->state = ENTITY_CREATED; /* If the node is in state DELETING, then send to the client command * node_delete. The client knows about this node now and can receive * node_destroy command */ if(node->state == ENTITY_DELETING) { /* Create Destroy_Node command */ struct Generic_Cmd *node_destroy_cmd = v_node_destroy_create(node->id); /* Push this command to the outgoing queue */ if ( node_destroy_cmd != NULL && v_out_queue_push_tail(node_follower->node_sub->session->out_queue, node_follower->node_sub->prio, node_destroy_cmd) == 1) { node_follower->state = ENTITY_DELETING; } else { v_print_log(VRS_PRINT_DEBUG_MSG, "node_destroy (id: %d) wasn't added to the queue\n", node->id); } } } else { v_print_log(VRS_PRINT_DEBUG_MSG, "node %d isn't in CREATING state\n"); } } else { if(node_follower->state != ENTITY_CREATED) { all_created = 0; } } node_follower = node_follower->next; } /* When all followers know about this node, then change state of this node */ if(all_created == 1) { node->state = ENTITY_CREATED; } return 0; }