Commit 514a3a96331bc16258cfbcc373eaf87bdc549397

Authored by Arnaud Blanchard
1 parent d3a1a460

Set ouptus as options

Showing 1 changed file with 21 additions and 21 deletions
@@ -7,36 +7,36 @@ @@ -7,36 +7,36 @@
7 #include <unistd.h> 7 #include <unistd.h>
8 8
9 int main(int argc, char **argv){ 9 int main(int argc, char **argv){
10 - blc_channel input, output1, output2;  
11 - char const *output_name1, *output_name2, *input_name; 10 + blc_channel input, output1, output2;
  11 + char const *output_name1, *output_name2, *input_name;
12 12
13 - blc_program_set_description("Duplicate a channel");  
14 - blc_program_add_parameter(&input_name, "blc_channel-in", 1, "input channel to split", NULL);  
15 - blc_program_add_parameter(&output_name1, "blc_channel-out", 1, "first copy of input", NULL);  
16 - blc_program_add_parameter(&output_name2, "blc_channel-out", 1, "second_copy of input", NULL); 13 + blc_program_set_description("Duplicate a channel");
  14 + blc_program_add_option(&output_name1,'1', "output1", "blc_channel-out", "first copy of input", NULL);
  15 + blc_program_add_option(&output_name2, '2', "output2", "blc_channel-out", "second_copy of input", NULL);
  16 + blc_program_add_parameter(&input_name, "blc_channel-in", 1, "input channel to split", NULL);
17 17
18 blc_program_init(&argc, &argv, blc_quit); 18 blc_program_init(&argc, &argv, blc_quit);
19 19
20 - input.open(input_name, BLC_CHANNEL_READ);  
21 - blc_loop_try_add_waiting_semaphore(input.sem_new_data);  
22 - blc_loop_try_add_posting_semaphore(input.sem_ack_data); 20 + if (output_name1==NULL) EXIT_ON_ERROR("You need option -1 <name of output channel>");
  21 + if (output_name2==NULL) EXIT_ON_ERROR("You need option -2 <name of output channel>");
23 22
  23 + input.open(input_name, BLC_CHANNEL_READ);
  24 + blc_loop_try_add_waiting_semaphore(input.sem_new_data);
  25 + blc_loop_try_add_posting_semaphore(input.sem_ack_data);
24 26
  27 +
25 output1.create_or_open(output_name1, BLC_CHANNEL_WRITE, input.type, input.format, input.dims_nb, input.dims); 28 output1.create_or_open(output_name1, BLC_CHANNEL_WRITE, input.type, input.format, input.dims_nb, input.dims);
26 -  
27 output2.create_or_open(output_name2, BLC_CHANNEL_WRITE, input.type, input.format, input.dims_nb, input.dims); 29 output2.create_or_open(output_name2, BLC_CHANNEL_WRITE, input.type, input.format, input.dims_nb, input.dims);
28 30
29 31
30 - BLC_COMMAND_LOOP(0){  
31 - if (output1.sem_ack_data) sem_wait(output1.sem_ack_data);  
32 - memcpy(output1.data, input.data, output1.size);  
33 - if (output1.sem_new_data) sem_post(output1.sem_new_data);  
34 -  
35 -  
36 - if (output2.sem_ack_data) sem_wait(output2.sem_ack_data);  
37 - memcpy(output2.data, input.data, output2.size);  
38 - if (output2.sem_new_data) sem_post(output2.sem_new_data);  
39 - 32 + BLC_COMMAND_LOOP(0){
  33 + if (output1.sem_ack_data) sem_wait(output1.sem_ack_data);
  34 + memcpy(output1.data, input.data, output1.size);
  35 + if (output1.sem_new_data) sem_post(output1.sem_new_data);
  36 +
  37 + if (output2.sem_ack_data) sem_wait(output2.sem_ack_data);
  38 + memcpy(output2.data, input.data, output2.size);
  39 + if (output2.sem_new_data) sem_post(output2.sem_new_data);
40 } 40 }
41 - return EXIT_SUCCESS; 41 + return EXIT_SUCCESS;
42 } 42 }