CommunicationTable Class Reference

#include <CommMulticastStream.h>

Public Member Functions

 CommunicationTable ()
 ------------------------------------------------------------------------ CommunicationTable Class This Class create a table that hold a thread ID and it current TCP socket connection.
CommunicationItemgetFirstItem ()
CommunicationItemgetLastItem ()
int insert (CommunicationItem *item)
int insertNullPid (int socket)
int changeSocketPid (int socket, int pid)
int removeSocket (int socket)
int searchPid (int defaultsocket, CommunicationItem **current, CommunicationItem **previous)
int searchSocket (int defaultsocket, CommunicationItem **current, CommunicationItem **previous)
ClientMode searchPidForMode (int pid)

Protected Member Functions

void setFirstItem (CommunicationItem *firstItem)
void setLastItem (CommunicationItem *lastItem)

Protected Attributes

CommunicationItemfirstItem
CommunicationItemlastItem

Detailed Description

Definition at line 148 of file CommMulticastStream.h.


Constructor & Destructor Documentation

CommunicationTable::CommunicationTable (  ) 

------------------------------------------------------------------------ CommunicationTable Class This Class create a table that hold a thread ID and it current TCP socket connection.

Definition at line 1660 of file CommMulticastStream.cpp.

01661 {
01662     #ifdef RIO_DEBUG1
01663     RioErr << "### [CommunicationTable - Constructor] Start" << endl;
01664     #endif
01665 
01666 //    maxSocket = 0;
01667     firstItem = NULL;
01668     lastItem  = NULL;
01669 
01670     #ifdef RIO_DEBUG1
01671     RioErr << "### [CommunicationTable - Constructor] Finish" << endl;
01672     #endif
01673 }


Member Function Documentation

int CommunicationTable::changeSocketPid ( int  socket,
int  pid 
)

Definition at line 1777 of file CommMulticastStream.cpp.

01778 {
01779     #ifdef RIO_DEBUG1
01780     RioErr << "### [CommunicationTable - changeSocketPid] Start" << endl;
01781     #endif
01782 
01783     int                result;
01784     CommunicationItem *current  = NULL;
01785     CommunicationItem *previous = NULL;
01786 
01787     result = searchSocket( socket, &current, &previous );
01788 
01789     if( result == RESULT_COMMUNICATION_SEARCH_FOUND )
01790     {
01791         current->setPid( pid );
01792 
01793         #ifdef RIO_DEBUG1
01794         RioErr << "### [CommunicationTable - insertNullPid] Finish 1" << endl;
01795         #endif
01796 
01797         return RESULT_COMMUNICATION_CHANGE_OK;
01798     }
01799 
01800     #ifdef RIO_DEBUG1
01801     RioErr << "### [CommunicationTable - insertNullPid] Finish 2" << endl;
01802     #endif
01803 
01804     return RESULT_COMMUNICATION_CHANGE_ERROR;
01805 }

CommunicationItem * CommunicationTable::getFirstItem (  ) 

Definition at line 2091 of file CommMulticastStream.cpp.

02092 {
02093     //#ifdef RIO_DEBUG1
02094     //RioErr << "### [CommunicationTable - getFirstItem] Single" << endl;
02095     //#endif
02096 
02097     return firstItem;
02098 }

CommunicationItem * CommunicationTable::getLastItem (  ) 

Definition at line 2100 of file CommMulticastStream.cpp.

02101 {
02102     //#ifdef RIO_DEBUG1
02103     //RioErr << "### [CommunicationTable - getLastItem] Single" << endl;
02104     //#endif
02105 
02106     return lastItem;
02107 }

int CommunicationTable::insert ( CommunicationItem item  ) 

Definition at line 1675 of file CommMulticastStream.cpp.

01676 {
01677     #ifdef RIO_DEBUG1
01678     RioErr << "### [CommunicationTable - insert] Start" << endl;
01679     #endif
01680 
01681     int                result;
01682     CommunicationItem *current;
01683     CommunicationItem *previous;
01684 
01685     if( item == NULL )
01686     {
01687         #ifdef RIO_DEBUG1
01688         RioErr << "### [CommunicationTable - insert] Finish 1" << endl;
01689         #endif
01690 
01691         return RESULT_COMMUNICATION_INSERT_ERROR;
01692     }
01693 
01694     current  = NULL;
01695     previous = NULL;
01696 
01697     result   = searchSocket( item->getSocket(), &current, &previous );
01698 
01699     if( result == RESULT_COMMUNICATION_SEARCH_EMPTY_LIST )
01700     {
01701         firstItem = item;
01702         lastItem  = item;
01703 
01704         #ifdef RIO_DEBUG1
01705         RioErr << "### [CommunicationTable - insert] Finish 2" << endl;
01706         #endif
01707 
01708         return RESULT_COMMUNICATION_INSERT_OK;
01709     }
01710 
01711     if( result == RESULT_COMMUNICATION_SEARCH_NOT_FOUND )
01712     {
01713         item->setNext( current );
01714         if( previous )
01715         {
01716             previous->setNext( item );
01717         }
01718         else
01719             firstItem = item;
01720 
01721 
01722         if( current == NULL )
01723         {
01724             lastItem = item;
01725         }
01726 
01727         #ifdef RIO_DEBUG1
01728         RioErr << "### [CommunicationTable - insert] Finish 3" << endl;
01729         #endif
01730 
01731         return RESULT_COMMUNICATION_INSERT_OK;
01732     }
01733 
01734     if( result == RESULT_COMMUNICATION_SEARCH_FOUND )
01735     {
01736         #ifdef RIO_DEBUG1
01737         RioErr << "### [CommunicationTable - insert] Finish 4" << endl;
01738         #endif
01739 
01740         return RESULT_COMMUNICATION_INSERT_ALREADY_EXIST;
01741     }
01742 
01743     #ifdef RIO_DEBUG1
01744     RioErr << "### [CommunicationTable - insert] Finish 5" << endl;
01745     #endif
01746 
01747     return RESULT_COMMUNICATION_INSERT_ERROR;
01748 }

int CommunicationTable::insertNullPid ( int  socket  ) 

Definition at line 1750 of file CommMulticastStream.cpp.

01751 {
01752     #ifdef RIO_DEBUG1
01753     RioErr << "### [CommunicationTable - insertNullPid] Start" << endl;
01754     #endif
01755 
01756     int                result;
01757     CommunicationItem *current  = NULL;
01758     CommunicationItem *previous = NULL;
01759 
01760     result = searchSocket( socket, &current, &previous );
01761 
01762     if( result == RESULT_COMMUNICATION_SEARCH_EMPTY_LIST ||
01763         result == RESULT_COMMUNICATION_SEARCH_NOT_FOUND
01764       )
01765     {
01766         CommunicationItem *item = new CommunicationItem( 0, socket );
01767         insert( item );
01768     }
01769 
01770     #ifdef RIO_DEBUG1
01771     RioErr << "### [CommunicationTable - insertNullPid] Finish 1" << endl;
01772     #endif
01773 
01774     return RESULT_COMMUNICATION_INSERT_ERROR;
01775 }

int CommunicationTable::removeSocket ( int  socket  ) 

Definition at line 1869 of file CommMulticastStream.cpp.

01870 {
01871     #ifdef RIO_DEBUG1
01872     RioErr << "### [CommunicationTable - removeSocket] Start" << endl;
01873     #endif
01874 
01875     int                result;
01876     CommunicationItem *current  = NULL;
01877     CommunicationItem *previous = NULL;
01878 
01879     result = searchSocket( socket, &current, &previous );
01880 
01881     if( result == RESULT_COMMUNICATION_SEARCH_NOT_FOUND )
01882     {
01883         #ifdef RIO_DEBUG1
01884         RioErr << "### [CommunicationTable - removeSocket] Finish 1" << endl;
01885         #endif
01886 
01887         return RESULT_COMMUNICATION_REMOVE_NOT_FOUND;
01888     }
01889 
01890     if( result == RESULT_COMMUNICATION_SEARCH_FOUND )
01891     {
01892         if( previous == NULL )
01893             firstItem = current->getNext();
01894         else
01895             previous->setNext( current->getNext() );
01896 
01897         if( current->getNext() == NULL )
01898             lastItem = previous;
01899 
01900         //A linha abaixo � s� pra tentar evitar um problema que o
01901         //valgrind detectou.
01902         current->setNext( NULL );
01903         delete( current );
01904     }
01905 
01906     #ifdef RIO_DEBUG1
01907     RioErr << "### [CommunicationTable - removeSocket] Finish 2" << endl;
01908     #endif
01909 
01910     return RESULT_COMMUNICATION_REMOVE_ERROR;
01911 }

int CommunicationTable::searchPid ( int  defaultsocket,
CommunicationItem **  current,
CommunicationItem **  previous 
)

Definition at line 1941 of file CommMulticastStream.cpp.

01943 {
01944     #ifdef RIO_DEBUG1
01945     RioErr << "### [CommunicationTable - searchPid] Start" << endl;
01946     #endif
01947 
01948     if( current == NULL || previous == NULL )
01949     {
01950         #ifdef RIO_DEBUG1
01951         RioErr << "### [CommunicationTable - searchPid] Finish 1" << endl;
01952         #endif
01953 
01954         return RESULT_COMMUNICATION_SEARCH_NULL_REFERENCE;
01955     }
01956 
01957     bool               found       = false;
01958     CommunicationItem *aux         = this->firstItem;
01959     CommunicationItem *auxPrevious = NULL;
01960 
01961     if( aux == NULL )
01962     {
01963         #ifdef RIO_DEBUG1
01964         RioErr << "### [CommunicationTable - searchPid] Finish 2" << endl;
01965         #endif
01966 
01967         return RESULT_COMMUNICATION_SEARCH_EMPTY_LIST;
01968     }
01969 
01970     while( aux != NULL && !found )
01971     {
01972         if( pid == aux->getPid() )
01973         {
01974             found = true;
01975         }
01976         else
01977         {
01978             auxPrevious = aux;
01979             aux = aux->getNext();
01980         }
01981     }
01982 
01983     *previous = auxPrevious;
01984     *current  = aux;
01985 
01986     if( aux == NULL )
01987     {
01988         #ifdef RIO_DEBUG1
01989         RioErr << "### [CommunicationTable - searchPid] Finish 3" << endl;
01990         #endif
01991 
01992         return RESULT_COMMUNICATION_SEARCH_NOT_FOUND;
01993     }
01994 
01995     #ifdef RIO_DEBUG1
01996     RioErr << "### [CommunicationTable - searchPid] Finish 4" << endl;
01997     #endif
01998 
01999     return RESULT_COMMUNICATION_SEARCH_FOUND;
02000 }

ClientMode CommunicationTable::searchPidForMode ( int  pid  ) 

Definition at line 1913 of file CommMulticastStream.cpp.

01914 {
01915     #ifdef RIO_DEBUG1
01916     RioErr << "### [CommunicationTable - searchPidForMode] Start" << endl;
01917     #endif
01918 
01919     int                result;
01920     CommunicationItem *current  = NULL;
01921     CommunicationItem *previous = NULL;
01922 
01923     result   = searchPid( pid, &current, &previous );
01924 
01925     if( result != RESULT_COMMUNICATION_SEARCH_FOUND )
01926     {
01927         #ifdef RIO_DEBUG1
01928         RioErr << "### [CommunicationTable - searchPidForMode] Finish 1" << endl;
01929         #endif
01930 
01931         return UNAVAILABLE;
01932     }
01933 
01934     #ifdef RIO_DEBUG1
01935     RioErr << "### [CommunicationTable - searchPidForMode] Finish 2" << endl;
01936     #endif
01937 
01938     return current->getMode();
01939 }

int CommunicationTable::searchSocket ( int  defaultsocket,
CommunicationItem **  current,
CommunicationItem **  previous 
)

Definition at line 2002 of file CommMulticastStream.cpp.

02004 {
02005     #ifdef RIO_DEBUG1
02006     RioErr << "### [CommunicationTable - searchSocket] Start" << endl;
02007     #endif
02008 
02009     if( current == NULL || previous == NULL )
02010     {
02011         #ifdef RIO_DEBUG1
02012         RioErr << "### [CommunicationTable - searchSocket] Finish 1" << endl;
02013         #endif
02014 
02015         return RESULT_COMMUNICATION_SEARCH_NULL_REFERENCE;
02016     }
02017 
02018     bool               found       = false;
02019     CommunicationItem *aux         = this->firstItem;
02020     CommunicationItem *auxPrevious = NULL;
02021 
02022     if( aux == NULL )
02023     {
02024         #ifdef RIO_DEBUG1
02025         RioErr << "### [CommunicationTable - searchSocket] Finish 2" << endl;
02026         #endif
02027 
02028         return RESULT_COMMUNICATION_SEARCH_EMPTY_LIST;
02029     }
02030 
02031     while( aux != NULL && !found )
02032     {
02033         if( socket > aux->getSocket() )
02034         {
02035             auxPrevious = aux;
02036             aux = aux->getNext();
02037         }
02038         else
02039         {
02040             found = true;
02041         }
02042     }
02043 
02044     *previous = auxPrevious;
02045     *current  = aux;
02046 
02047     if( aux == NULL )
02048     {
02049         #ifdef RIO_DEBUG1
02050         RioErr << "### [CommunicationTable - searchSocket] Finish 3" << endl;
02051         #endif
02052 
02053         return RESULT_COMMUNICATION_SEARCH_NOT_FOUND;
02054     }
02055 
02056     if( socket < aux->getSocket() )
02057     {
02058         #ifdef RIO_DEBUG1
02059         RioErr << "### [CommunicationTable - searchSocket] Finish 4" << endl;
02060         #endif
02061 
02062         return RESULT_COMMUNICATION_SEARCH_NOT_FOUND;
02063     }
02064 
02065     #ifdef RIO_DEBUG1
02066     RioErr << "### [CommunicationTable - searchSocket] Finish 6" << endl;
02067     #endif
02068 
02069     return RESULT_COMMUNICATION_SEARCH_FOUND;
02070 }

void CommunicationTable::setFirstItem ( CommunicationItem firstItem  )  [protected]

Definition at line 2073 of file CommMulticastStream.cpp.

02074 {
02075     #ifdef RIO_DEBUG1
02076     RioErr << "### [CommunicationTable - setFirstItem] Single" << endl;
02077     #endif
02078 
02079     this->firstItem = firstItem;
02080 }

void CommunicationTable::setLastItem ( CommunicationItem lastItem  )  [protected]

Definition at line 2082 of file CommMulticastStream.cpp.

02083 {
02084     #ifdef RIO_DEBUG1
02085     RioErr << "### [CommunicationTable - setLastItem] Single" << endl;
02086     #endif
02087 
02088     this->lastItem = lastItem;
02089 }


Field Documentation

Definition at line 151 of file CommMulticastStream.h.

Definition at line 152 of file CommMulticastStream.h.


The documentation for this class was generated from the following files:
Generated on Wed Jul 4 16:03:32 2012 for RIO by  doxygen 1.6.3