int32_t vrs_send_taggroup_create(const uint8_t session_id, const uint8_t prio, const uint32_t node_id, const uint16_t type) { struct Generic_Cmd *taggroup_create_cmd = v_taggroup_create_create(node_id, -1, type); return vc_send_command(session_id, prio, taggroup_create_cmd); }
/** * \brief This function sends TagGroupCreate command to the client * * \param[in] *node_subscriber * \param[in] *node * \param[in] *tg * * \return This function return 1, when command was successfully created and * pushed to outgoing queue. When some error occur (already subscribed to * tag group, out of memory, etc.) then 0 is returned. When outgoing queue is * empty, then -1 is returned. */ int vs_taggroup_send_create(struct VSNodeSubscriber *node_subscriber, struct VSNode *node, struct VSTagGroup *tg) { struct VSession *vsession = node_subscriber->session; struct Generic_Cmd *taggroup_create_cmd; struct VSEntityFollower *taggroup_follower; /* Check if this tag group is in created/creating state */ if(!(tg->state == ENTITY_CREATING || tg->state == ENTITY_CREATED)) { v_print_log(VRS_PRINT_DEBUG_MSG, "This tag group: %d in node: %d is in %d state\n", tg->id, node->id, tg->state); return 0; } /* Check if this command, has not been already sent */ taggroup_follower = tg->tg_folls.first; while(taggroup_follower != NULL) { if(taggroup_follower->node_sub->session->session_id == vsession->session_id ) { v_print_log(VRS_PRINT_DEBUG_MSG, "Client already knows about this TagGroup: %d\n", tg->id); return 0; } taggroup_follower = taggroup_follower->next; } /* Create TagGroup create command */ taggroup_create_cmd = v_taggroup_create_create(node->id, tg->id, tg->custom_type); /* Put this command to the outgoing queue */ if(taggroup_create_cmd == NULL) { return 0; } if(v_out_queue_push_tail(vsession->out_queue, 0, node_subscriber->prio, taggroup_create_cmd) == 0) { return -1; } else { /* Add this session to the list of session, that knows about this * taggroup. Server could send them taggroup_destroy in the future. */ taggroup_follower = (struct VSEntityFollower*)calloc(1, sizeof(struct VSEntityFollower)); taggroup_follower->node_sub = node_subscriber; taggroup_follower->state = ENTITY_CREATING; v_list_add_tail(&tg->tg_folls, taggroup_follower); return 1; } return 0; }