Beispiel #1
0
/**
 * \brief This function adds TagDestroy command to the queue of the session
 */
int vs_tag_send_destroy(struct VSNode *node,
                        struct VSTagGroup *tg,
                        struct VSTag *tag)
{
    struct VSEntityFollower *tag_follower;
    struct Generic_Cmd *tag_destroy_cmd;
    int ret = 0;

    tag_follower = tag->tag_folls.first;
    while(tag_follower != NULL) {
        /* Client can receive tag_destroy command only in situation, when
         * this client already received tag_create command */
        if(tag_follower->state == ENTITY_CREATED) {
            tag_destroy_cmd = v_tag_destroy_create(node->id, tg->id, tag->id);

            if( tag_destroy_cmd != NULL &&
                    (v_out_queue_push_tail(tag_follower->node_sub->session->out_queue,
                                           0,
                                           tag_follower->node_sub->prio,
                                           tag_destroy_cmd) == 1)) {
                tag_follower->state = ENTITY_DELETING;
                ret = 1;
            } else {
                v_print_log(VRS_PRINT_DEBUG_MSG, "Tag_Destroy (node_id: %d, taggroup_id: %d, tag_id: %d) wasn't added to the queue\n",
                            node->id, tg->id, tag->id);
            }
        }
        tag_follower = tag_follower->next;
    }

    tag->state = ENTITY_DELETING;

    return ret;
}
Beispiel #2
0
int32_t vrs_send_tag_destroy(const uint8_t session_id,
		const uint8_t prio,
		const uint32_t node_id,
		const uint16_t taggroup_id,
		const uint16_t tag_id)
{
	struct Generic_Cmd *tag_destroy_cmd = v_tag_destroy_create(node_id, taggroup_id, tag_id);
	return vc_send_command(session_id, prio, tag_destroy_cmd);
}
Beispiel #3
0
/**
 * \brief This function tries to handle Tag_Create command.
 *
 * This function change state of follower from CREATING to CREATED
 * and it sends value to this client.
 */
int vs_handle_tag_create_ack(struct VS_CTX *vs_ctx,
                             struct VSession *vsession,
                             struct Generic_Cmd *cmd)
{
    struct VSNode				*node;
    struct VSTagGroup			*tg;
    struct VSTag				*tag;
    struct VSEntityFollower		*tag_follower;
    struct Tag_Create_Ack_Cmd	*tag_create_ack = (struct Tag_Create_Ack_Cmd*)cmd;
    uint32						node_id = tag_create_ack->node_id;
    uint16						taggroup_id = tag_create_ack->taggroup_id;
    uint16						tag_id = tag_create_ack->tag_id;
    int							all_created = 1, tag_found = 0, ret = 0;

    /* 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;
    }

    pthread_mutex_lock(&node->mutex);

    /* Try to find TagGroup */
    if( (tg = vs_taggroup_find(node, taggroup_id)) == NULL) {
        v_print_log(VRS_PRINT_DEBUG_MSG, "%s() tag_group (id: %d) in node (id: %d) not found\n",
                    __FUNCTION__, taggroup_id, node_id);
        goto end;
    }

    /* Try to find Tag */
    if ( (tag = vs_tag_find(tg, tag_id)) == NULL) {
        v_print_log(VRS_PRINT_DEBUG_MSG, "%s() tag (id: %d) in tag_group (id: %d), node (id: %d) not found\n",
                    __FUNCTION__, tag_id, taggroup_id, node_id);
        goto end;
    }

    /* Try to find tag follower that generated this fake command */
    tag_follower = tag->tag_folls.first;
    while(tag_follower != NULL) {
        if(tag_follower->node_sub->session->session_id == vsession->session_id) {
            tag_found = 1;
            /* When tag contain value, then send this value to the client */
            if( (tag->flag & TAG_INITIALIZED) && (tag_follower->state != ENTITY_CREATED)) {
                ret = vs_tag_send_set(tag_follower->node_sub->session, tag_follower->node_sub->prio, node, tg, tag);
            }
            tag_follower->state = ENTITY_CREATED;

            /* When this tag has been destroyed during sending tag_create
             * command, then send tag_destroy command now */
            if(tag->state == ENTITY_DELETING) {
                struct Generic_Cmd *tag_destroy_cmd = v_tag_destroy_create(node->id, tg->id, tag->id);

                if( tag_destroy_cmd != NULL &&
                        (v_out_queue_push_tail(tag_follower->node_sub->session->out_queue,
                                               0,
                                               tag_follower->node_sub->prio,
                                               tag_destroy_cmd) == 1))
                {
                    tag_follower->state = ENTITY_DELETING;
                } else {
                    v_print_log(VRS_PRINT_DEBUG_MSG,
                                "Tag_Destroy (node_id: %d, taggroup_id: %d, tag_id: %d) wasn't added to the queue\n",
                                node->id, tg->id, tag->id);
                    ret = 0;
                }
            }
        } else if(tag_follower->state != ENTITY_CREATED) {
            all_created = 0;
        }
        tag_follower = tag_follower->next;
    }

    /* When all clients knows about this tag, then switch tag to state CREATED */
    if(all_created == 1) {
        tag->state = ENTITY_CREATED;
    }

    if(tag_found == 0) {
        v_print_log(VRS_PRINT_DEBUG_MSG,
                    "%s() tag_follower of tag (id: %d) in tag_group (id: %d) in node (id: %d) not found\n",
                    __FUNCTION__, tag_id, tg->id, node->id);
    } else {
        ret = 1;
    }

end:

    pthread_mutex_unlock(&node->mutex);

    return ret;
}