src/sessionset.c

00001 /*
00002   The oRTP library is an RTP (Realtime Transport Protocol - rfc1889) stack.
00003   Copyright (C) 2001  Simon MORLAT simon.morlat@linphone.org
00004 
00005   This library is free software; you can redistribute it and/or
00006   modify it under the terms of the GNU Lesser General Public
00007   License as published by the Free Software Foundation; either
00008   version 2.1 of the License, or (at your option) any later version.
00009 
00010   This library is distributed in the hope that it will be useful,
00011   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013   Lesser General Public License for more details.
00014 
00015   You should have received a copy of the GNU Lesser General Public
00016   License along with this library; if not, write to the Free Software
00017   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 */
00019 
00020 #include <ortp/ortp.h>
00021 #include <ortp/sessionset.h>
00022 #include "scheduler.h"
00023 
00024 
00030 SessionSet * session_set_new()
00031 {
00032         SessionSet *set=(SessionSet *) ortp_malloc(sizeof(SessionSet));
00033         session_set_init(set);
00034         return set;
00035 }
00036 
00037 
00043 void session_set_destroy(SessionSet *set)
00044 {
00045         ortp_free(set);
00046 }
00047 
00048 int session_set_and(SessionSet *sched_set, int maxs, SessionSet *user_set, SessionSet *result_set)
00049 {
00050         uint32_t *mask1,*mask2,*mask3;
00051         int i=0;
00052         int j,ret=0;
00053         mask1=(uint32_t*)(void*)&sched_set->rtpset;
00054         mask2=(uint32_t*)(void*)&user_set->rtpset;
00055         mask3=(uint32_t*)(void*)&result_set->rtpset;
00056         while(i<maxs+1){
00057                 *mask3=(*mask1) & (*mask2);     /* computes the AND between the two masks*/
00058                 /* and unset the sessions that have been found from the sched_set */
00059                 *mask1=(*mask1) & (~(*mask3));
00060                 if ((*mask3)!=0){
00061                         for (j=0;j<32;j++){
00062                                 if ( ((*mask3)>>j) & 1){
00063                                         ret++;
00064                                 }
00065                         }
00066                 }
00067                 i+=32;
00068                 mask1++;
00069                 mask2++;
00070                 mask3++;
00071         }
00072         //printf("session_set_and: ret=%i\n",ret);
00073         return ret;
00074 }
00075 
00098 int session_set_select(SessionSet *recvs, SessionSet *sends, SessionSet *errors)
00099 {
00100         int ret=0,bits;
00101         SessionSet temp;
00102         RtpScheduler *sched=ortp_get_scheduler();
00103         
00104         /*lock the scheduler to not read the masks while they are being modified by the scheduler*/
00105         rtp_scheduler_lock(sched);
00106         
00107         while(1){
00108                 /* computes the SessionSet intersection (in the other words mask intersection) between
00109                 the mask given by the user and scheduler masks */
00110                 if (recvs!=NULL){
00111                         session_set_init(&temp);
00112                         bits=session_set_and(&sched->r_sessions,sched->all_max,recvs,&temp);
00113                         if (bits>0){
00114                                 ret+=bits;
00115                                 /* copy the result set in the given user set */
00116                                 session_set_copy(recvs,&temp);
00117                         }
00118                 }
00119                 if (sends!=NULL){
00120                         session_set_init(&temp);
00121                         bits=session_set_and(&sched->w_sessions,sched->all_max,sends,&temp);
00122                         if (bits>0){
00123                                 ret+=bits;
00124                                 /* copy the result set in the given user set */
00125                                 session_set_copy(sends,&temp);
00126                         }
00127                 }
00128                 if (errors!=NULL){
00129                         session_set_init(&temp);
00130                         bits=session_set_and(&sched->e_sessions,sched->all_max,errors,&temp);
00131                         if (bits>0){
00132                                 ret+=bits;
00133                                 /* copy the result set in the given user set */
00134                                 session_set_copy(errors,&temp);
00135                         }
00136                 }
00137                 if (ret>0){
00138                         /* there are set file descriptors, return immediately */
00139                         //printf("There are %i sessions set, returning.\n",ret);
00140                         rtp_scheduler_unlock(sched);
00141                         return ret;
00142                 }
00143                 //printf("There are %i sessions set.\n",ret);
00144                 /* else we wait until the next loop of the scheduler*/
00145                 ortp_cond_wait(&sched->unblock_select_cond,&sched->lock);
00146         }
00147 
00148         return -1;
00149 }
00150 

Generated on Thu Feb 14 16:10:59 2008 for oRTP by  doxygen 1.5.4