f_tee.cpp 1.5 KB
//
//  Created by Arnaud Blanchard on 22/12/15.
//  Copyright ETIS 2015. All rights reserved.
//
#include "blc_channel.h"
#include "blc_program.h"
#include <unistd.h>

int main(int argc, char **argv){
	blc_channel input, output1, output2;
	char const  *output_name1, *output_name2, *input_name;

	blc_program_set_description("Duplicate a channel");
	blc_program_add_parameter(&input_name, "blc_channel-in", 1, "input channel to split", NULL);
    blc_program_add_parameter(&output_name1, "blc_channel-out", 1, "first copy of input", NULL);
    blc_program_add_parameter(&output_name2, "blc_channel-out", 1, "second_copy of input", NULL);

    blc_program_init(&argc, &argv, blc_quit);

	input.open(input_name, BLC_CHANNEL_READ);
	blc_loop_try_add_waiting_semaphore(input.sem_new_data);
	blc_loop_try_add_posting_semaphore(input.sem_ack_data);

    
    output1.create_or_open(output_name1, BLC_CHANNEL_WRITE, input.type, input.format, input.dims_nb, input.dims);
   
    output2.create_or_open(output_name2, BLC_CHANNEL_WRITE, input.type, input.format, input.dims_nb, input.dims);
    
	
	BLC_COMMAND_LOOP(0){
        if (output1.sem_ack_data) sem_wait(output1.sem_ack_data);
        memcpy(output1.data, input.data, output1.size);
        if (output1.sem_new_data) sem_post(output1.sem_new_data);
        
            
        if (output2.sem_ack_data) sem_wait(output2.sem_ack_data);
        memcpy(output2.data, input.data, output2.size);
        if (output2.sem_new_data) sem_post(output2.sem_new_data);

    }
	return EXIT_SUCCESS;
}