display.c

Go to the documentation of this file.
00001 
00033 #include <stdio.h>
00034 #include <string.h>
00035 
00036 #ifdef _MSC_VER
00037 #define _WINSOCKAPI_   /* Prevent inclusion of winsock.h in windows.h */
00038 #include <windows.h>
00039 #include <process.h>
00040 #else
00041 #include <unistd.h>
00042 #endif
00043 
00044 #include "fdt.h"
00045 #include "flute.h"
00046 #include "../alclib/alc_session.h"
00047 #include "../alclib/transport.h"
00048 #include "../alclib/alc_rx.h"
00049 
00057 void print_sender_info(flute_sender_t *sender) {
00058 
00059   alc_session_t *s;
00060   file_t *next_file;
00061   file_t *file;
00062   
00063   s = get_alc_session(sender->s_id);
00064 
00065 #ifdef _MSC_VER
00066   system("cls");
00067 #else
00068   printf("\e[H\e[J");
00069 #endif
00070 
00071   if(s->cc_id == 0 && s->nb_channel == 1) { 
00072     printf("%-7s%-7s%-13s%-52s\n\n", "TOI", "Tx[%]", "Size[B]", "File");
00073   }
00074   else {
00075     printf("%-7s%-13s%-59s\n\n", "TOI", "Size[B]", "File");
00076   }
00077   
00078   next_file = sender->fdt->file_list;
00079 
00080   while(next_file != NULL) {
00081     file = next_file;
00082     
00083 #ifdef _MSC_VER
00084     printf("%-7I64u", file->toi);
00085 #else 
00086     printf("%-7llu", file->toi);
00087 #endif
00088 
00089     if(s->cc_id == 0 && s->nb_channel == 1) {
00090     
00091       if(get_session_tx_toi(sender->s_id) == file->toi) {
00092       
00093         printf("%-7.2f", (double)((double)100 *
00094                                   ((double)(long long)get_object_sent_bytes(sender->s_id)/(double)(long long)file->content_len)));
00095       }
00096       else {
00097         printf("%-7.s", "");
00098       }
00099     }
00100       
00101 #ifdef _MSC_VER
00102     printf("%-13I64u",  file->content_len);
00103 #else
00104     printf("%-13llu",  file->content_len);
00105 #endif
00106     
00107     if(s->cc_id == 0 && s->nb_channel == 1) {
00108       printf("%-52s\n",  file->location);
00109     }
00110     else {
00111       printf("%-59s\n",  file->location);
00112     }
00113     
00114     fflush(stdout);
00115     
00116     next_file = file->next;
00117   }
00118 }
00119 
00127 void print_receiver_info(flute_receiver_t *receiver) {
00128 
00129   trans_obj_t *trans_obj;
00130   alc_session_t *s;
00131   
00132   file_t *next_file;
00133   file_t *file;
00134 
00135   char tmp[17];
00136   
00137   s = get_alc_session(receiver->s_id);
00138 
00139 #ifdef _MSC_VER
00140   system("cls");
00141 #else
00142   printf("\e[H\e[J");
00143 #endif
00144 
00145   printf("%-7s%-7s%-16s%-13s%-36s\n\n", "TOI", "Rx[%]", "Blocks",  "Size[B]", "File");
00146 
00147   next_file = receiver->fdt->file_list;
00148 
00149   while(next_file != NULL) {
00150     file = next_file;
00151 
00152 #ifdef _MSC_VER
00153     printf("%-7I64u", file->toi);
00154 #else
00155     printf("%-7llu", file->toi);
00156 #endif
00157 
00158     trans_obj = object_exist(file->toi, s, 1);
00159     
00160     if(trans_obj != NULL) {
00161 
00162       printf("%-7.2f", (double)((double)100 *
00163                                 ((double)(long long)trans_obj->rx_bytes/(double)(long long)trans_obj->len)));
00164       
00165       memset(tmp, 0, 17);
00166       sprintf(tmp, "%u/%u", trans_obj->nb_of_ready_blocks, trans_obj->bs->N);
00167       printf("%-16s", tmp);
00168     }
00169     else if(file->status == 2) {
00170        printf("%-7s%-16s", "100", "");
00171     }
00172     else {
00173       printf("%-7s%-16s", "", "");
00174     }
00175        
00176 #ifdef _MSC_VER
00177     printf("%-13I64u",  file->content_len);
00178 #else
00179     printf("%-13llu",  file->content_len);
00180 #endif
00181 
00182     printf("%-36s\n",  file->location);
00183     fflush(stdout);
00184     
00185     next_file = file->next;
00186   }
00187 }
00188 
00189 void* sender_file_table_output_thread(void *a) {
00190 
00191   flute_sender_t *sender;
00192 
00193   sender = (flute_sender_t*)a;
00194 
00195   while(get_session_state(sender->s_id) == SActive || get_session_state(sender->s_id) == SPaused) {
00196 
00197     if(sender->fdt != NULL) {
00198       print_sender_info(sender);
00199     }
00200 
00201 #ifdef _MSC_VER
00202     Sleep(1000);
00203 #else
00204     sleep(1);
00205 #endif
00206   }
00207 
00208 #ifdef _MSC_VER
00209   _endthread();
00210 #else
00211   pthread_exit(0);
00212 #endif
00213 
00214   return NULL;
00215 }
00216 
00217 void* receiver_file_table_output_thread(void *a) {
00218 
00219   flute_receiver_t *receiver;
00220 
00221   receiver = (flute_receiver_t*)a;
00222   
00223   while(get_session_state(receiver->s_id) == SActive ||
00224                 get_session_state(receiver->s_id) == SAFlagReceived) {
00225 
00226     if(receiver->fdt != NULL) { 
00227       print_receiver_info(receiver);
00228     }
00229 
00230 #ifdef _MSC_VER
00231     Sleep(1000);
00232 #else
00233     sleep(1);
00234 #endif
00235   }
00236 
00237 #ifdef _MSC_VER
00238   _endthread();
00239 #else
00240   pthread_exit(0);
00241 #endif
00242 
00243   return NULL;
00244 }

Generated on Fri Mar 9 20:08:51 2007 for MAD-FCL by  doxygen 1.5.0