/** * \brief This function sends Node_Create command to the subscriber of parent * node. */ int vs_node_send_create(struct VSNodeSubscriber *node_subscriber, struct VSNode *node, struct VSNode *avatar_node) { struct Generic_Cmd *node_create_cmd = NULL; struct VSEntityFollower *node_follower; /* Check if this node is in created/creating state */ if(!(node->state == ENTITY_CREATING || node->state == ENTITY_CREATED)) { v_print_log(VRS_PRINT_DEBUG_MSG, "This node: %d is in %d state\n", node->id, node->state); return 0; } /* Check if this command, has not been already sent */ node_follower = node->node_folls.first; while(node_follower != NULL) { if(node_follower->node_sub->session->session_id == node_subscriber->session->session_id && (node_follower->state == ENTITY_CREATING || node_follower->state == ENTITY_CREATED)) { v_print_log(VRS_PRINT_DEBUG_MSG, "Client already knows about node: %d\n", node->id); return 0; } node_follower = node_follower->next; } if(avatar_node != NULL){ node_create_cmd = v_node_create_create(node->id, avatar_node->id, node->owner->user_id, node->type); } else { node_create_cmd = v_node_create_create(node->id, node->parent_link->parent->id, node->owner->user_id, node->type); } if ( node_create_cmd != NULL && v_out_queue_push_tail(node_subscriber->session->out_queue, node_subscriber->prio, node_create_cmd) == 1) { /* Add this session to the list of session, that knows about this * node. Server could send them node_destroy in the future. */ node_follower = (struct VSEntityFollower*)calloc(1, sizeof(struct VSEntityFollower)); node_follower->node_sub = node_subscriber; node_follower->state = ENTITY_CREATING; v_list_add_tail(&node->node_folls, node_follower); return 1; } return 0; }
int32_t vrs_send_node_create(const uint8_t session_id, const uint8_t prio, const uint16_t type) { int i, ret; /* This function is more complicated, because avatar ID and user ID are * stored in session */ if(vc_ctx == NULL) { v_print_log(VRS_PRINT_ERROR, "Basic callback functions were not set.\n"); return VRS_NO_CB_FUNC; } else { /* Go through all sessions ... */ for(i=0; i<vc_ctx->max_sessions; i++) { /* ... and try to find session with session_id */ if(vc_ctx->vsessions[i]!=NULL && vc_ctx->vsessions[i]->session_id==session_id) { struct Generic_Cmd *node_create_cmd = v_node_create_create(VRS_RESERVED_NODE_ID, vc_ctx->vsessions[i]->avatar_id, vc_ctx->vsessions[i]->user_id, type); assert(node_create_cmd != NULL); ret = v_out_queue_push_tail(vc_ctx->vsessions[i]->out_queue, OUT_QUEUE_LIMITS, prio, node_create_cmd); if(ret == 1) return VRS_SUCCESS; else return VRS_FAILURE; } } } v_print_log(VRS_PRINT_ERROR, "Session %d does not exist.\n", session_id); return VRS_FAILURE; }