/** * \brief This function do recursive setting new node priority */ static int vs_node_prio(struct VSession *vsession, struct VSNode *node, uint8 prio) { struct VSNodeSubscriber *node_subscriber; struct VSNode *child_node; struct VSLink *link; /* Is client subscribed to this node? */ node_subscriber = node->node_subs.first; while(node_subscriber != NULL) { if(node_subscriber->session->session_id == vsession->session_id) { break; } node_subscriber = node_subscriber->next; } /* If client is subscribed, then set up new priority */ if(node_subscriber != NULL) { node_subscriber->prio = prio; /* Do recursive subscribing to child nodes */ link = node->children_links.first; while(link != NULL) { child_node = link->child; vs_node_prio(vsession, child_node, prio); link = link->next; } } else { return 0; } return 1; }
/** * \brief This function handle Node_Priority command */ int vs_handle_node_prio(struct VS_CTX *vs_ctx, struct VSession *vsession, struct Generic_Cmd *node_prio) { struct VSNode *node; struct VSNodeSubscriber *node_subscriber; uint8 prio = UINT8(node_prio->data[0]); uint32 node_id = UINT32(node_prio->data[UINT8_SIZE]); /* Try to find node */ if((node = vs_node_find(vs_ctx, node_id)) == NULL) { v_print_log(VRS_PRINT_DEBUG_MSG, "%s() node (id: %d) not found\n", __FUNCTION__, node_id); return 0; } /* Node has to be created */ if(! (node->state == ENTITY_CREATED || node->state == ENTITY_CREATING)) { v_print_log(VRS_PRINT_DEBUG_MSG, "%s() node (id: %d) is not in NODE_CREATED state: %d\n", __FUNCTION__, node->id, node->state); return 0; } /* Is client subscribed to this node? */ node_subscriber = node->node_subs.first; while(node_subscriber != NULL) { if(node_subscriber->session->session_id == vsession->session_id) { break; } node_subscriber = node_subscriber->next; } /* When client is subscribed to this node, then change node priority */ if(node_subscriber != NULL) { node_subscriber->prio = prio; /* Change priority for this node and all child nodes */ vs_node_prio(vsession, node, prio); } else { v_print_log(VRS_PRINT_DEBUG_MSG, "%s() client not subscribed to this node (id: %d)\n", __FUNCTION__, node_id); return 0; } return 0; }