/** * \brief This function is callback function for receiving of command Node_Owner */ static void cb_receive_node_owner(const uint8_t session_id, const uint32_t node_id, const uint16_t user_id) { printf("%s() session_id: %d, node_id: %d, user_id of new owner: %d\n", __FUNCTION__, session_id, node_id, user_id); if(node_id == my_test_node_id) { /* Try to delete "my" own node */ vrs_send_node_destroy(session_id, my_test_node_prio, node_id); } }
static void handle_signal(int sig) { if(sig == SIGINT) { if(ctx != NULL) { printf("%s() try to terminate connection: %d\n", __FUNCTION__, ctx->verse.session_id); /* Try to delete particle sender node */ vrs_send_node_destroy(ctx->verse.session_id, VRS_DEFAULT_PRIORITY, ctx->sender->sender_node->node_id); /* Terminate connection */ vrs_send_connect_terminate(ctx->verse.session_id); } else { exit(EXIT_FAILURE); } /* Reset signal handling to default behavior */ signal(SIGINT, SIG_DFL); } }
/** * \brief This function is callback function for receiving of node_create * command. It means, that this function is called, when verse_callback_update * is executed and there are any data in appropriate incoming queue. * * \param[in] session_id The ID of session with some verse server * \param[in] node_id The ID of new node * \param[in] parent_id The ID of parent node * \param[in] user_id The User ID of the owner of this node */ static void cb_receive_node_create(const uint8_t session_id, const uint32_t node_id, const uint32_t parent_id, const uint16_t user_id, const uint16_t custom_type) { printf("%s() session_id: %d, node_id: %d, parent_id: %d, user_id: %d, custom_type: %d\n", __FUNCTION__, session_id, node_id, parent_id, user_id, custom_type); /* Is node special node? */ if(node_id==VRS_ROOT_NODE_ID) { printf("\tRoot Node\n"); } else if(node_id==VRS_AVATAR_PARENT_NODE_ID) { printf("\tParent of Avatar Nodes\n"); /* Try to delete node, that could not be deleted */ vrs_send_node_destroy(session_id, VRS_DEFAULT_PRIORITY, node_id); } else if(node_id==VRS_USERS_PARENT_NODE_ID) { printf("\tParent of User Nodes\n"); /* Example of node subscribe command */ vrs_send_node_subscribe(session_id, VRS_DEFAULT_PRIORITY, node_id, 0, 0); } else if(node_id==VRS_SCENE_PARENT_NODE_ID) { printf("\tParent of Scene Nodes\n"); /* Example of node un-subscribe command */ vrs_send_node_unsubscribe(session_id, VRS_DEFAULT_PRIORITY, node_id, 0); } else if(node_id==VRS_ROOT_NODE_ID) { printf("\tUser Node of SuperUser\n"); } else if(parent_id==VRS_USERS_PARENT_NODE_ID) { printf("\tUser Node\n"); } else if(node_id==VRS_RESERVED_NODE_ID) { printf("\tReservered Node ID (should never be received by client from server)\n"); } else if(node_id>=VRS_FIRST_COMMON_NODE_ID) { printf("\tCommon Node\n"); } /* My Avatar Node */ if(node_id == my_avatar_id) { /* Client should subscribe to his avarat node to be able receive information * about nodes, that was created by this client */ printf("\tMy Avatar Node\n"); vrs_send_node_subscribe(session_id, VRS_DEFAULT_PRIORITY, node_id, 0, 0); /* Test of sending wrong node_perm command (client doesn't own this node) */ vrs_send_node_perm(session_id, VRS_DEFAULT_PRIORITY, node_id, my_user_id, VRS_PERM_NODE_READ | VRS_PERM_NODE_WRITE); } /* Who is owner of this node? */ if(my_user_id != -1 && my_user_id == user_id) { printf("\tNode owned by me\n"); } else if(user_id==VRS_SUPER_USER_UID) { printf("\tNode owned by super user (server)\n"); } else { printf("\tNode owned by someone else\n"); } /* Who created this node? */ if(my_avatar_id != -1 && my_avatar_id == parent_id) { printf("\tNode created from this client\n"); printf("\tParent of this node is my avatar node: %d\n", parent_id); } else { printf("\tNode created by somebody else\n"); printf("\tParent of this node is: %d\n", parent_id); } /* Example of subscribing to node created from this client */ if((my_user_id != -1 && my_user_id == user_id) && (my_avatar_id != -1 && my_avatar_id == parent_id)) { my_test_node_id = node_id; /* Test of subscribing to my own node */ vrs_send_node_subscribe(session_id, VRS_DEFAULT_PRIORITY, node_id, 0, 0); /* Test of changing priority of my node */ vrs_send_node_prio(session_id, VRS_DEFAULT_PRIORITY, node_id, my_test_node_prio); /* Test of changing parent of my node */ vrs_send_node_link(session_id, VRS_DEFAULT_PRIORITY, VRS_SCENE_PARENT_NODE_ID, node_id); /* Test of adding new node permission */ vrs_send_node_perm(session_id, VRS_DEFAULT_PRIORITY, node_id, 100, VRS_PERM_NODE_READ | VRS_PERM_NODE_WRITE); } }