alc_session.c

Go to the documentation of this file.
00001 
00034 #include <stdlib.h>
00035 #include <stdio.h>
00036 #include <memory.h>
00037 #include <string.h>
00038 #include <assert.h>
00039 #include <math.h>
00040 
00041 #ifdef _MSC_VER
00042 #include <process.h>
00043 #else
00044 #include <pthread.h>
00045 #endif
00046 
00047 #include <sys/timeb.h>
00048 
00049 #include "alc_session.h"
00050 #include "mad_rlc.h"
00051 #include "alc_rx.h"
00052 #include "alc_tx.h"
00053 #include "transport.h"
00054 #include "alc_channel.h"
00055 
00060 #define ABSOLUTE_PATH 1
00061 
00062 struct alc_session *alc_session_list[MAX_ALC_SESSIONS]; 
00063 int nb_alc_session = 0; 
00069 #ifdef _MSC_VER
00070 RTL_CRITICAL_SECTION session_variables_semaphore;
00071 #else
00072 pthread_mutex_t session_variables_semaphore = PTHREAD_MUTEX_INITIALIZER;
00073 #endif
00074 
00080 void lock_session() {
00081 #ifdef _MSC_VER
00082   EnterCriticalSection(&session_variables_semaphore);
00083 #else
00084   pthread_mutex_lock(&session_variables_semaphore);
00085 #endif
00086 }
00087 
00093 void unlock_session() {
00094 #ifdef _MSC_VER
00095   LeaveCriticalSection(&session_variables_semaphore);
00096 #else
00097   pthread_mutex_unlock(&session_variables_semaphore);
00098 #endif
00099 }
00100 
00101 int open_alc_session(alc_arguments_t *a) {
00102 
00103   alc_session_t *s;
00104   int i;
00105   int retval;
00106   struct timeb timeb_current_time;
00107   
00108 #if ABSOLUTE_PATH
00109   char fullpath[MAX_PATH_LENGTH];
00110 #endif
00111 
00112   lock_session();
00113   
00114   if(!lib_init) {
00115     alc_init();
00116     /* alc session list initialization */
00117     memset(alc_session_list, 0, MAX_ALC_SESSIONS * sizeof(alc_session_t*));
00118   }
00119   
00120   if(nb_alc_session >= MAX_ALC_SESSIONS) {
00121     /* Could not create new alc session */
00122     printf("Could not create new alc session: too many sessions!\n");
00123     unlock_session();
00124     return -1;
00125   }
00126   
00127   if (!(s = (alc_session_t*)calloc(1, sizeof(alc_session_t)))) {
00128     printf("Could not alloc memory for alc session!\n");
00129     unlock_session();
00130     return -1;
00131   }
00132 
00133   memset(s, 0, sizeof(alc_session_t));
00134 
00135   s->mode = a->mode;
00136   s->tsi = a->tsi;
00137   s->state = SActive;
00138   s->addr_family = a->addr_family;
00139   s->addr_type = a->addr_type;
00140   s->cc_id = a->cc_id;
00141   
00142   if(s->cc_id == RLC) {
00143     retval = init_mad_rlc(s);
00144     
00145     if(retval < 0) {
00146       unlock_session();
00147       return retval;
00148     }
00149   }
00150   
00151   s->rx_memory_mode = a->rx_memory_mode;
00152   s->verbosity = a->verbosity;
00153   s->starttime = a->start_time;
00154   s->stoptime = a->stop_time;
00155   s->simul_losses = a->simul_losses;
00156   s->loss_ratio1 = a->loss_ratio1;
00157   s->loss_ratio2 = a->loss_ratio2;
00158   
00159   if(s->mode == SENDER) {
00160 
00161     ftime(&timeb_current_time);
00162         s->ftimestarttime = timeb_current_time.time+timeb_current_time.millitm/1000.0;
00163 
00164     memcpy(s->base_dir, a->base_dir, strlen(a->base_dir));
00165     
00166     s->nb_channel = 0;
00167     s->max_channel = a->nb_channel;
00168     s->def_fec_ratio = a->fec_ratio; 
00169     s->sent_bytes = 0;
00170     s->obj_sent_bytes = 0;
00171     s->last_print_tx_percent = 0;
00172     s->a_flag = 0;
00173     s->fdt_instance_id = 0; /*uplimit 16777215;*/
00174     s->def_ttl = a->ttl;
00175     s->def_fec_enc_id = a->fec_enc_id;
00176     s->def_fec_inst_id = a->fec_inst_id;
00177     s->def_max_sblen = a->max_sb_len;
00178     s->def_eslen = a->es_len;
00179     s->use_fec_oti_ext_hdr = a->use_fec_oti_ext_hdr;
00180     s->def_tx_rate = a->tx_rate;
00181     s->tx_queue_begin = NULL;
00182     s->tx_queue_end = NULL;
00183     s->tx_queue_size = 0;
00184     s->first_unit_in_loop = TRUE;
00185     s->nb_ready_channel = 0;
00186     s->nb_sending_channel = 0;
00187     s->half_word = a->half_word;
00188     s->encode_content = a->encode_content;
00189     s->optimize_tx_rate =  a->optimize_tx_rate;
00190     s->calculate_session_size = a->calculate_session_size;
00191 
00192     if(((s->cc_id == RLC) || ((s->cc_id == Null) && (s->max_channel != 1)))) {
00193 
00194       /**** Start tx_thread ****/
00195       
00196 #ifdef _MSC_VER
00197       s->handle_tx_thread = (HANDLE)_beginthreadex(NULL, 0, (void*)tx_thread, (void*)s, 0, &s->tx_thread_id);
00198 
00199       if(s->handle_tx_thread == NULL) {
00200         perror("open_alc_session: _beginthread");
00201         unlock_session();
00202         return -1;
00203       }
00204 #else
00205       if(pthread_create(&s->tx_thread_id, NULL, tx_thread, (void*)s) != 0) {
00206         perror("open_alc_session: pthread_create");
00207         unlock_session();
00208         return -1;
00209       }
00210 #endif
00211     }
00212   }
00213   
00214   if(s->mode == RECEIVER) {
00215     
00216 #ifdef SSM
00217     s->ssm = a->use_ssm;
00218 #endif
00219 
00220 #if ABSOLUTE_PATH    
00221 #ifdef _MSC_VER
00222     memset(fullpath, 0, MAX_PATH_LENGTH);
00223     
00224     if(_fullpath(fullpath, a->base_dir, MAX_PATH_LENGTH) != NULL) {
00225       memcpy(s->base_dir, fullpath, strlen(fullpath));
00226     }
00227     else {
00228       memcpy(s->base_dir, a->base_dir, strlen(a->base_dir));
00229     }
00230 #else
00231     memset(fullpath, 0, MAX_PATH_LENGTH);
00232     
00233     if(a->base_dir[0] != '/') {
00234       
00235       if(getcwd(fullpath, MAX_PATH_LENGTH) != NULL) {
00236         memcpy(s->base_dir, fullpath, strlen(fullpath));
00237         strcat(s->base_dir, "/");
00238         strcat(s->base_dir, a->base_dir);
00239       }
00240       else {
00241         memcpy(s->base_dir, a->base_dir, strlen(a->base_dir));
00242       }
00243     }
00244     else {
00245       memcpy(s->base_dir, a->base_dir, strlen(a->base_dir));
00246     }
00247 #endif
00248 #else
00249          memcpy(s->base_dir, a->base_dir, strlen(a->base_dir));
00250 #endif
00251 
00252     s->nb_channel = 0;
00253     s->max_channel = a->nb_channel;
00254     s->obj_list = NULL;
00255     s->fdt_list = NULL;
00256     s->wanted_obj_list = NULL;
00257     s->rx_fdt_instance_list = NULL;
00258     s->accept_expired_fdt_inst = a->accept_expired_fdt_inst;
00259     
00260     memset(s->src_addr, 0, 40);
00261     
00262     if(a->src_addr != NULL) {
00263       memcpy(s->src_addr, a->src_addr, strlen(a->src_addr));
00264     }
00265     
00266     /* Create receiving thread */
00267     
00268 #ifdef _MSC_VER
00269     s->handle_rx_thread =
00270       (HANDLE)_beginthreadex(NULL, 0, (void*)rx_thread, (void*)s, 0, &s->rx_thread_id);
00271     
00272     if(s->handle_rx_thread == NULL) {
00273       perror("open_alc_session: _beginthread");
00274       unlock_session();
00275       return -1;
00276     }
00277 #else
00278     if(pthread_create(&s->rx_thread_id, NULL, rx_thread, (void*)s) != 0) {
00279       perror("open_alc_session: pthread_create");
00280       unlock_session();
00281       return -1;
00282     }
00283 #endif
00284     
00285   }
00286   
00287   for(i = 0; i < MAX_ALC_SESSIONS; i++) {
00288     if(alc_session_list[i] == NULL) {
00289       s->s_id = i;
00290       alc_session_list[s->s_id] = s;
00291       break;
00292     }
00293   }
00294   
00295   nb_alc_session++;
00296   
00297   unlock_session();
00298   return s->s_id;
00299 }
00300 
00301 void close_alc_session(int s_id) {
00302 
00303   int i;
00304   wanted_obj_t *next_want;
00305   wanted_obj_t *want;
00306   rx_fdt_instance_t *next_instance;
00307   rx_fdt_instance_t *instance;
00308   
00309   tx_queue_t *next_pkt;
00310   tx_queue_t *pkt;
00311   
00312   trans_obj_t *to;
00313   
00314   alc_session_t *s;
00315 
00316 #ifdef USE_RETRIEVE_UNIT
00317   trans_unit_container_t *tmp;
00318   trans_unit_container_t *to_delete;
00319 #endif
00320 
00321 #ifdef LINUX
00322   int join_retval;
00323 #endif
00324 
00325   /* Wait for open thread. */
00326 #ifdef _MSC_VER
00327   if(alc_session_list[s_id]->handle_rx_thread != NULL) {
00328         WaitForSingleObject(alc_session_list[s_id]->handle_rx_thread, INFINITE);
00329         CloseHandle(alc_session_list[s_id]->handle_rx_thread);
00330         alc_session_list[s_id]->handle_rx_thread = NULL;
00331   }
00332 #else
00333   if(alc_session_list[s_id]->rx_thread_id != 0) {   
00334      join_retval = pthread_join(alc_session_list[s_id]->rx_thread_id, NULL);
00335      assert(join_retval == 0);
00336      pthread_detach(alc_session_list[s_id]->rx_thread_id);
00337      alc_session_list[s_id]->rx_thread_id = 0;
00338   }
00339 #endif
00340 
00341   lock_session();
00342   s = alc_session_list[s_id];
00343   s->state = SClosed;  
00344 
00345   for(i = 0; i < s->max_channel; i++) {
00346     
00347     if(s->ch_list[i] != NULL) {
00348       close_alc_channel(s->ch_list[i], s);
00349     }
00350   }
00351 
00352 #ifdef USE_RETRIEVE_UNIT
00353         tmp = s->unit_pool;
00354 
00355         while(tmp != NULL ) {
00356                 to_delete = tmp;
00357                 tmp = tmp->next;
00358                 free(to_delete->u.data);
00359                 free(to_delete);
00360         }
00361 
00362         s->unit_pool = NULL;
00363 #endif
00364 
00365   /* Closing, free all uncompleted objects, uncompleted fdt instances and wanted obj list */
00366   
00367   to = s->obj_list;
00368   
00369   while(to != NULL) {
00370     free_object(to, s, 1);
00371     to = s->obj_list;
00372   }
00373   
00374   to = s->fdt_list;
00375   
00376   while(to != NULL) {
00377     free_object(to, s, 0);
00378     to = s->fdt_list;
00379   }
00380   
00381   want = s->wanted_obj_list;
00382   
00383   while(want != NULL) {
00384     next_want = want->next;
00385     free(want);
00386     want = next_want;
00387   }     
00388   
00389   instance = s->rx_fdt_instance_list;
00390   
00391   while(instance != NULL) {
00392     next_instance = instance->next;
00393     free(instance);
00394     instance = next_instance;
00395   }
00396     
00397   if(s->cc_id == RLC) {
00398     close_mad_rlc(s);
00399   }
00400   
00401   pkt = s->tx_queue_begin;
00402   
00403   while(pkt != NULL) {
00404     next_pkt = pkt->next;
00405     free(pkt->data);
00406     free(pkt);
00407     pkt = next_pkt;
00408   }
00409   
00410   free(s);
00411   alc_session_list[s_id] = NULL;
00412   nb_alc_session--;
00413   unlock_session();
00414 }
00415 
00416 alc_session_t* get_alc_session(int s_id) {
00417 
00418   alc_session_t* alc_session;
00419 
00420   lock_session();
00421   assert (alc_session_list != NULL);
00422   assert (s_id >= 0);
00423   assert (s_id < MAX_ALC_SESSIONS);
00424   alc_session = alc_session_list[s_id];
00425 
00426   unlock_session();
00427 
00428   return alc_session;
00429 }
00430 
00431 
00432 int add_alc_channel(int s_id, const char *port, const char *addr, const char *intface, const char *intface_name) {
00433         
00434   alc_channel_t *ch;
00435   alc_session_t *s;
00436   int ret;
00437 
00438   lock_session();
00439   ch = NULL;
00440   s = alc_session_list[s_id];
00441 
00442   if(s->nb_channel >= s->max_channel) {
00443     /* Could not add new alc channel to alc session */
00444     printf("Could not create new alc channel: Max number of channels already used!\n");
00445     unlock_session();
00446     return -1;
00447   }
00448 
00449   ret = open_alc_channel(ch, s, port, addr, intface, intface_name, s->def_tx_rate);
00450   unlock_session();
00451 
00452   return ret;
00453 }
00454 
00455 void remove_alc_channels(int s_id) {
00456 
00457   alc_session_t *s;
00458   alc_channel_t *ch;
00459   int i;
00460 
00461   lock_session();
00462   s = alc_session_list[s_id];
00463 
00464   for(i = 0; i < s->max_channel; i++) {
00465 
00466     if(s->ch_list[i] != NULL) {
00467       ch = s->ch_list[i];
00468       close_alc_channel(ch, s);
00469     }
00470   }
00471 
00472   unlock_session();
00473 }
00474 
00475 trans_obj_t* get_session_obj_list(int s_id) {
00476 
00477   trans_obj_t* obj_list;
00478 
00479   lock_session();
00480   obj_list = alc_session_list[s_id]->obj_list;
00481   unlock_session();
00482 
00483   return obj_list;
00484 }
00485 
00486 trans_obj_t* get_session_fdt_list(int s_id) {
00487 
00488   trans_obj_t* fdt_list;
00489 
00490   lock_session();
00491   fdt_list = alc_session_list[s_id]->fdt_list;
00492   unlock_session();
00493 
00494   return fdt_list;
00495 }
00496 
00497 wanted_obj_t* get_session_wanted_obj_list(int s_id) {
00498 
00499   wanted_obj_t* wanted_obj_list;
00500 
00501   lock_session();
00502   wanted_obj_list = alc_session_list[s_id]->wanted_obj_list;
00503   unlock_session();
00504 
00505   return wanted_obj_list;
00506 }
00507 
00508 int get_session_state(int s_id) {
00509   int state;
00510 
00511   lock_session();
00512 
00513   if(alc_session_list[s_id] == NULL) {
00514     unlock_session();
00515     return -1;
00516   }
00517 
00518   state = alc_session_list[s_id]->state;
00519   unlock_session();
00520   return state;
00521 }
00522 
00523 void set_session_state(int s_id, enum alc_session_states state) {
00524   lock_session();
00525   alc_session_list[s_id]->state = state;
00526   unlock_session();
00527 }
00528 
00529 void set_all_sessions_state(enum alc_session_states state) {
00530 
00531   int i;
00532   lock_session();
00533 
00534   for(i = 0; i < MAX_ALC_SESSIONS; i++)
00535     {
00536       if(alc_session_list[i] != NULL)
00537         {
00538           alc_session_list[i]->state = state;
00539         }
00540     }
00541   unlock_session();
00542 }
00543 
00544 int get_session_a_flag_usage(int s_id) {
00545 
00546   int flag;
00547   lock_session();
00548   flag = alc_session_list[s_id]->a_flag;
00549   unlock_session();
00550 
00551   return flag;
00552 }
00553 
00554 void set_session_a_flag_usage(int s_id) {
00555 
00556   lock_session();
00557   alc_session_list[s_id]->a_flag = 1;
00558   unlock_session();
00559 }
00560 
00561 unsigned int get_fdt_instance_id(int s_id) {
00562 
00563   int instance_id;
00564 
00565   lock_session();
00566   instance_id = alc_session_list[s_id]->fdt_instance_id;
00567   unlock_session();
00568 
00569   return instance_id;
00570 }
00571 
00572 void set_fdt_instance_id(int s_id, unsigned int instance_id) {
00573   lock_session();
00574   alc_session_list[s_id]->fdt_instance_id =  (instance_id & 0x00FFFFFF);
00575   unlock_session();
00576 }
00577 
00578 void set_fdt_instance_parsed(int s_id) {
00579   lock_session();
00580   alc_session_list[s_id]->waiting_fdt_instance = FALSE;
00581   unlock_session();
00582 }
00583 
00584 unsigned long long get_session_sent_bytes(int s_id) {
00585   unsigned long long byte_sent;
00586 
00587   lock_session();
00588   byte_sent = alc_session_list[s_id]->sent_bytes;
00589   unlock_session();
00590 
00591   return byte_sent;
00592 }
00593 
00594 void set_session_sent_bytes(int s_id, unsigned long long sent_bytes) {
00595 
00596   lock_session();
00597   alc_session_list[s_id]->sent_bytes = sent_bytes;
00598   unlock_session();
00599 }
00600 
00601 void add_session_sent_bytes(int s_id, unsigned int sent_bytes) {
00602 
00603   lock_session();
00604   alc_session_list[s_id]->sent_bytes += sent_bytes;
00605   unlock_session();
00606 }
00607 
00608 unsigned long long get_object_sent_bytes(int s_id) {
00609   unsigned long long byte_sent;
00610 
00611   lock_session();
00612   byte_sent = alc_session_list[s_id]->obj_sent_bytes;
00613   unlock_session();
00614 
00615   return byte_sent;
00616 }
00617 
00618  void set_object_sent_bytes(int s_id, unsigned long long sent_bytes) {
00619 
00620    lock_session();
00621    alc_session_list[s_id]->obj_sent_bytes = sent_bytes;
00622    unlock_session();
00623  }
00624 
00625 void add_object_sent_bytes(int s_id, unsigned int sent_bytes) {
00626 
00627   lock_session();
00628   alc_session_list[s_id]->obj_sent_bytes += sent_bytes;
00629   unlock_session();
00630 }
00631 
00632 double get_object_last_print_tx_percent(int s_id) {                                                                                                                   
00633   double tx_percent;
00634 
00635   lock_session();
00636   tx_percent = alc_session_list[s_id]->last_print_tx_percent;
00637   unlock_session();
00638 
00639   return tx_percent;
00640 }
00641                                                                                                                                           
00642 void set_object_last_print_tx_percent(int s_id, double last_print_tx_percent) {                                                                                  
00643   lock_session();
00644   alc_session_list[s_id]->last_print_tx_percent = last_print_tx_percent;
00645   unlock_session();
00646 }
00647 
00648 void set_session_tx_toi(int s_id, unsigned long long toi) {
00649 
00650   lock_session();
00651   alc_session_list[s_id]->tx_toi = toi;
00652   unlock_session();
00653 }
00654 
00655 unsigned long long get_session_tx_toi(int s_id) {
00656 
00657   unsigned long long tx_toi;
00658 
00659   lock_session();
00660   tx_toi = alc_session_list[s_id]->tx_toi;
00661   unlock_session();
00662 
00663   return tx_toi;
00664 }
00665 
00666 void update_session_tx_rate(int s_id, int base_tx_rate) {
00667         alc_session_t *s;
00668         alc_channel_t *ch;
00669         int i;
00670 
00671         lock_session();
00672         s = alc_session_list[s_id];
00673         
00674         for(i = 0; i < s->max_channel; i++) {
00675                 if(s->ch_list[i] != NULL) {
00676                         ch = s->ch_list[i];
00677 
00678                         if(ch->ch_id == 0) {
00679                                 ch->tx_rate = base_tx_rate;
00680                                 ch->nb_tx_units = 1;
00681                         }
00682                         else {
00683                                 ch->tx_rate = base_tx_rate * (int)pow(2.0, (double)(ch->ch_id - 1));
00684                                 ch->nb_tx_units = (int)pow(2.0, (double)(ch->ch_id - 1));
00685                         }
00686                         printf("new rate [channel: %i]: %i\n", ch->ch_id, ch->tx_rate);
00687                 }
00688         }
00689         unlock_session();
00690 }
00691 
00692 wanted_obj_t* get_wanted_object(alc_session_t *s, unsigned long long toi) {
00693 
00694         wanted_obj_t *tmp;
00695 
00696         lock_session();
00697 
00698         tmp = s->wanted_obj_list;
00699 
00700         while(tmp != NULL) {
00701                 if(tmp->toi == toi) {
00702                   unlock_session();
00703                   return tmp;
00704                 }
00705                 tmp = tmp->next;
00706         }
00707 
00708         unlock_session();
00709         return NULL;
00710 }
00711 
00712 int set_wanted_object(int s_id, unsigned long long toi,
00713                       unsigned long long transfer_len,
00714                       unsigned short es_len, unsigned int max_sb_len, int fec_inst_id,
00715                       short fec_enc_id, unsigned short max_nb_of_es,
00716                       unsigned char content_enc_algo, unsigned char finite_field,
00717                           unsigned char nb_of_es_per_group) {
00718         
00719   alc_session_t *s;
00720   wanted_obj_t *wanted_obj;
00721   wanted_obj_t *tmp;
00722   
00723   lock_session();
00724    
00725   s = alc_session_list[s_id];
00726   tmp = s->wanted_obj_list;
00727   
00728   if(tmp == NULL) {
00729     
00730     if (!(wanted_obj = (wanted_obj_t*)calloc(1, sizeof(wanted_obj_t)))) {
00731       printf("Could not alloc memory for wanted object!\n");
00732       unlock_session();
00733       return -1;
00734     }
00735     
00736     wanted_obj->toi = toi;
00737     wanted_obj->transfer_len = transfer_len;
00738     wanted_obj->es_len = es_len;
00739     wanted_obj->max_sb_len = max_sb_len;
00740     wanted_obj->fec_inst_id = fec_inst_id;
00741     wanted_obj->fec_enc_id = fec_enc_id;
00742     wanted_obj->max_nb_of_es = max_nb_of_es;
00743     wanted_obj->content_enc_algo = content_enc_algo;
00744         wanted_obj->finite_field = finite_field;
00745         wanted_obj->nb_of_es_per_group = nb_of_es_per_group;
00746 
00747     wanted_obj->prev = NULL;
00748     wanted_obj->next = NULL;
00749 
00750     s->wanted_obj_list = wanted_obj;
00751   }
00752   else {
00753     for(;; tmp = tmp->next) {
00754       if(tmp->toi == toi) {
00755         break;
00756       }
00757       else if(tmp->next == NULL) {
00758         
00759         if (!(wanted_obj = (wanted_obj_t*)calloc(1, sizeof(wanted_obj_t)))) {
00760           printf("Could not alloc memory for wanted object!\n");
00761           unlock_session();
00762           return -1;
00763         }
00764         
00765         wanted_obj->toi = toi;
00766         wanted_obj->transfer_len = transfer_len;
00767         wanted_obj->es_len = es_len;
00768         wanted_obj->max_sb_len = max_sb_len;
00769         wanted_obj->fec_inst_id = fec_inst_id;
00770         wanted_obj->fec_enc_id = fec_enc_id;
00771         wanted_obj->max_nb_of_es = max_nb_of_es;
00772         wanted_obj->content_enc_algo = content_enc_algo;
00773         wanted_obj->finite_field = finite_field;
00774         wanted_obj->nb_of_es_per_group = nb_of_es_per_group;
00775         
00776         tmp->next = wanted_obj;
00777         wanted_obj->prev = tmp;
00778         wanted_obj->next = NULL;
00779 
00780         break;
00781       }
00782     }
00783   }
00784   
00785   unlock_session();
00786   return 0;
00787 }
00788 
00789 void remove_wanted_object(int s_id, unsigned long long toi) {
00790 
00791         alc_session_t *s;       
00792         wanted_obj_t *next_want;
00793         wanted_obj_t *want;
00794         
00795         lock_session();
00796 
00797         s = alc_session_list[s_id];
00798         next_want = s->wanted_obj_list;
00799 
00800         while(next_want != NULL) {
00801                 
00802                 want = next_want;
00803                   
00804                 if(want->toi == toi) {
00805                         
00806                         if(want->next != NULL) {
00807                                         want->next->prev = want->prev;
00808                         }
00809                         if(want->prev != NULL) {
00810                                         want->prev->next = want->next;
00811                         }
00812                         if(want == s->wanted_obj_list) {
00813                                         s->wanted_obj_list = want->next;
00814                         }
00815               
00816                         free(want);
00817                         break;
00818                 }
00819                 next_want = want->next;
00820         }
00821 
00822         unlock_session();
00823 }
00824                                                                                                                                               
00825 BOOL is_received_instance(alc_session_t *s, unsigned int fdt_instance_id) {
00826                                                                                                                                               
00827         BOOL retval = FALSE;
00828         rx_fdt_instance_t *list = s->rx_fdt_instance_list;
00829                                                                                                                                               
00830         while(list != NULL) {
00831                 if(list->fdt_instance_id == fdt_instance_id) {
00832                         retval = TRUE;
00833                         break;
00834                 }
00835                 list = list->next;
00836         }
00837                                                                                                                                               
00838         return retval;
00839 }
00840 
00841 int set_received_instance(alc_session_t *s, unsigned int fdt_instance_id) {
00842  
00843         rx_fdt_instance_t *rx_fdt_instance;
00844         rx_fdt_instance_t *list;
00845         
00846         lock_session();
00847 
00848         list = s->rx_fdt_instance_list;
00849                                                                                                                                               
00850         if(list == NULL) {
00851                                                                                                                                               
00852                 if (!(rx_fdt_instance = (rx_fdt_instance_t*)calloc(1, sizeof(rx_fdt_instance_t)))) {
00853                         printf("Could not alloc memory for rx_fdt_instance!\n");
00854                         unlock_session();
00855                         return -1;
00856                 }
00857 
00858                 rx_fdt_instance->fdt_instance_id = fdt_instance_id;
00859                 rx_fdt_instance->prev = NULL;
00860                 rx_fdt_instance->next = NULL;
00861         
00862                         s->rx_fdt_instance_list = rx_fdt_instance;
00863         }
00864         else {
00865                 for(;; list = list->next) {
00866                         if(list->fdt_instance_id == fdt_instance_id) {
00867                                 break;
00868                         }
00869                         else if(list->next == NULL) {
00870               
00871                                                           if (!(rx_fdt_instance = (rx_fdt_instance_t*)calloc(1, sizeof(rx_fdt_instance_t)))) {
00872                                                                 printf("Could not alloc memory for rx_fdt_instance!\n");
00873                                                                 unlock_session();
00874                                                                 return -1;
00875                                                           }
00876                           
00877                                                           rx_fdt_instance->fdt_instance_id = fdt_instance_id;
00878                                                           
00879                                                           list->next = rx_fdt_instance;
00880                                                           rx_fdt_instance->prev = list;
00881                                                           rx_fdt_instance->next = NULL;
00882 
00883                                                           break;
00884                         }
00885                 }
00886         }
00887         
00888         unlock_session();
00889         return 0;
00890 }
00891 
00892 char* get_session_basedir(int s_id) {
00893 
00894   alc_session_t *s;
00895   char* base_dir;
00896 
00897   lock_session();
00898 
00899   s = alc_session_list[s_id];
00900   base_dir = s->base_dir;
00901 
00902   unlock_session();
00903 
00904   return base_dir;
00905 }
00906 
00907 void initialize_session_handler() {
00908 #ifdef _MSC_VER
00909   InitializeCriticalSection(&session_variables_semaphore);
00910 #else
00911 #endif
00912 }
00913 
00914 void release_session_handler() {
00915 #ifdef _MSC_VER
00916   DeleteCriticalSection(&session_variables_semaphore);
00917 #else
00918 #endif
00919 }

Generated on Fri Mar 9 19:59:51 2007 for MAD-FCL by  doxygen 1.5.0