#include <RioInterface.h>
Public Member Functions | |
CRioStream () | |
~CRioStream () | |
RioResult | Open (const RioStreamTraffic *Traffic, CRioSession *RioSession) |
RioResult | Close () |
RioResult | MaxRequests () |
RioResult | CanStart () |
bool | SetMulticastSocket (unsigned short multicastport, char *multicast_addr, void *callback=0, BufferStream *buffer_stream=0, int enable_join=1) |
void | LeaveGroup (unsigned short multicastport) |
void | LeaveAllGroups (void) |
int | FreeBlock (unsigned int block_id, RioStreamType traffic) |
int | FreePendentBlocks (bool useCache, int nBuffers) |
bool | thereAreFragments (RioBlock block) |
void | Getmyaddr (int *my_address, int *my_port) |
RioTrafficType | GetTrafficType () |
CRioSession * | GetRioSession () |
Static Public Member Functions | |
static void | MulticastCallBack (void *parm, int result) |
Private Member Functions | |
RioResult | Read (RioRequest *Request, int ObjectId, RioStreamType traffic=UNICASTTRAFFIC) |
RioResult | Read (RioRequest *Request, int ObjectId, int sendack, RioStreamType traffic, int ip, int port) |
RioResult | Write (RioRequest *Request, int ObjectId) |
RioResult | MulticastRead (RioBlock block, int ObjectId, int sendack, RioStreamType traffic) |
RioResult | MulticastDataRequest (RioBlock block, int ObjectId, RequestOperation ReqOp, int sendack, RioStreamType traffic, int ip, int port) |
int | CancelExpect (int reqid) |
RioResult | DataRequest (RioRequest *Request, int ObjectId, RequestOperation, RioStreamType traffic=UNICASTTRAFFIC) |
RioResult | DataRequest (RioRequest *Request, int ObjectId, RequestOperation, int sendack, RioStreamType traffic, int ip, int port) |
RioResult | GetBlockSize (unsigned int *BlockSize) |
RioResult | GetId (RioStreamId *Id) |
void | FreeMembers () |
Static Private Member Functions | |
static void | callback (void *parm, int result) |
Private Attributes | |
void * | client_callback |
bool | m_opened |
RioStreamId | m_StreamId |
RioTrafficType | m_StreamType |
unsigned int | m_BlockSize |
int | m_myaddr |
int | m_myport |
CRioSession * | m_RioSession |
NetMgr * | m_NetMgr |
CStreamManager * | m_StreamManager |
CRouter * | m_Router |
CRioTCP * | m_TCPconnection |
CNetInterface * | m_NetInterface |
Friends | |
class | CRioObject |
Definition at line 411 of file RioInterface.h.
CRioStream::CRioStream | ( | ) |
Definition at line 47 of file RioStream.cpp.
00048 { 00049 #ifdef RIO_DEBUG1 00050 RioErr << "### [CRioStream - Constructor] Start" << endl; 00051 #endif 00052 00053 client_callback = NULL; 00054 m_opened = false; 00055 m_StreamId.Version = -1; 00056 m_StreamId.Index = -1; 00057 m_StreamType = RIO_TRAFFIC_INVALID; 00058 m_BlockSize = 0; 00059 m_myaddr = 0; 00060 m_myport = 0; 00061 m_RioSession = NULL; 00062 m_NetMgr = NULL; 00063 // Ponteiro para a nova classe de gerenciamento de rede. 00064 m_NetInterface = NULL; 00065 m_StreamManager = NULL; 00066 m_Router = NULL; 00067 m_TCPconnection = 0; 00068 00069 #ifdef RIO_DEBUG1 00070 RioErr << "### [CRioStream - Constructor] Finish" << endl; 00071 #endif 00072 }
CRioStream::~CRioStream | ( | ) |
Definition at line 74 of file RioStream.cpp.
void CRioStream::callback | ( | void * | parm, | |
int | result | |||
) | [static, private] |
Definition at line 1004 of file RioStream.cpp.
01005 { 01006 #ifdef RIO_DEBUG1 01007 RioErr << "### [CRioStream - callback] Start" << endl; 01008 #endif 01009 01010 RioRequest *Request = ( RioRequest * )parm; 01011 01012 Request->Result = result; 01013 Request->Status = RIO_REQUEST_COMPLETED; 01014 01015 (*Request->CallBackFunction)(Request); 01016 01017 #ifdef RIO_DEBUG1 01018 RioErr << "### [CRioStream - callback] Finish" << endl; 01019 #endif 01020 }
int CRioStream::CancelExpect | ( | int | reqid | ) | [private] |
Definition at line 216 of file RioStream.cpp.
00217 { 00218 #ifdef RIO_DEBUG1 00219 RioErr << "### [CRioStream - CancelExpect] Single" << endl; 00220 #endif 00221 00222 // Dependendo do tipo do stream (e de o objeto da classe CNetInterface ter 00223 // sido criado - isso nao ocorre no multicast), chamamos ou a funcao da 00224 // NetMgr (nos casos do tempo real) ou a funcao da classe CNetInterface 00225 // (no caso de tempo nao real). 00226 if( ( m_NetInterface != NULL ) && ( m_StreamType == RIO_TRAFFIC_NRT ) ) 00227 return m_NetInterface->CancelExpect( reqid, -1 ); 00228 else 00229 return m_NetMgr->CancelExpect( reqid, -1 ); 00230 }
RioResult CRioStream::CanStart | ( | void | ) |
Definition at line 973 of file RioStream.cpp.
00974 { 00975 #ifdef RIO_DEBUG1 00976 RioErr << "### [CRioStream - CanStart] Single" << endl; 00977 #endif 00978 00979 // Check if we are connected 00980 if( !m_opened ) 00981 { 00982 #ifdef RIO_DEBUG1 00983 RioErr << "### [CRioStream - CanStart] Finish1" << endl; 00984 #endif 00985 00986 return ERROR_RIOSTREAM + ERROR_STREAM_NOT_OPENED; 00987 } 00988 else 00989 { 00990 #ifdef RIO_DEBUG1 00991 RioErr << "### [CRioStream - CanStart] Finish2" << endl; 00992 #endif 00993 00994 return (m_StreamManager->CanStart(m_StreamId)); 00995 } 00996 }
RioResult CRioStream::Close | ( | void | ) |
Definition at line 187 of file RioStream.cpp.
00188 { 00189 #ifdef RIO_DEBUG1 00190 RioErr << "### [CRioStream - Close] Start" << endl; 00191 #endif 00192 00193 // Check if stream is opened 00194 if(!m_opened) 00195 { 00196 #ifdef RIO_DEBUG1 00197 RioErr << "### [CRioStream - Close] Finish1" << endl; 00198 #endif 00199 00200 return ERROR_RIOSTREAM + ERROR_STREAM_NOT_OPENED; 00201 } 00202 00203 // Free memory for class member variables 00204 FreeMembers(); 00205 00206 m_opened = false; 00207 00208 #ifdef RIO_DEBUG1 00209 RioErr << "### [CRioStream - Close] Finish2" << endl; 00210 #endif 00211 00212 return S_OK; 00213 }
RioResult CRioStream::DataRequest | ( | RioRequest * | Request, | |
int | ObjectId, | |||
RequestOperation | ReqOp, | |||
int | sendack, | |||
RioStreamType | traffic, | |||
int | ip, | |||
int | port | |||
) | [private] |
Definition at line 562 of file RioStream.cpp.
00565 { 00566 #ifdef RIO_DEBUG1 00567 RioErr << "### [CRioStream - DataRequest1] Start" << endl; 00568 #endif 00569 00570 char *Parameter = (char*) malloc( MaxTCPDataSize*sizeof(char) ); 00571 char *Result; 00572 unsigned int ParameterSize; 00573 unsigned int ResultSize; 00574 HRESULT status; 00575 00576 if( Parameter == NULL ) 00577 { 00578 RioErr << "malloc error DataRequest:" << strerror(errno) << endl; 00579 00580 #ifdef RIO_DEBUG1 00581 RioErr << "### [CRioStream - DataRequest1] Finish1" << endl; 00582 #endif 00583 00584 free( Parameter ); 00585 00586 return ERROR_RIOPROXY + ERROR_MEMORY; 00587 } 00588 00589 memset( Parameter, 0, MaxTCPDataSize*sizeof( char ) ); 00590 00591 if( Request->Status == RIO_REQUEST_PENDING ) 00592 { 00593 RioErr << "[RioStream] ERROR: Status RIO_REQUEST_PENDING" << endl; 00594 00595 free( Parameter ); 00596 00597 #ifdef RIO_DEBUG1 00598 RioErr << "### [CRioStream - DataRequest1] Finish2" << endl; 00599 #endif 00600 00601 return ERROR_CLIENT + ERROR_STARTED; 00602 } 00603 00604 Request->Status = RIO_REQUEST_PENDING; 00605 // looking at Result before the request is complete is a client error! 00606 Request->Result = ERROR_CLIENT + ERROR_NOT_STARTED; 00607 00608 int reqid; 00609 int repbits = 0; 00610 00611 // ### need to pass both "this" and Request to callback... 00612 Request->System = (void *)this; 00613 00614 if( traffic == UNICASTTRAFFIC ) 00615 { 00616 if( ReqOp == READ ) 00617 { 00618 if( ( m_NetInterface != NULL ) && 00619 ( m_StreamType == RIO_TRAFFIC_NRT ) ) 00620 reqid = m_NetInterface->ExpectBlock( (char *) Request->Buffer, 00621 Request->Size, callback, 00622 ( void * ) Request, 00623 sendack ); 00624 else 00625 reqid = m_NetMgr->ExpectBlock( (char *) Request->Buffer, 00626 Request->Size, callback, 00627 ( void * ) Request, sendack ); 00628 } 00629 else 00630 { 00631 // A operacao de escrita sempre e em tempo nao real. Portanto, basta 00632 // verificar se m_NetInterface e NULL e usa-la em caso contrario 00633 // (m_NetInterface sera NULL se estivermos usando a PL). 00634 if( m_NetInterface != NULL ) 00635 reqid = m_NetInterface->ExpectTellId( (char *) Request->Buffer, 00636 Request->Size, callback, 00637 ( void * ) Request ); 00638 else 00639 reqid = m_NetMgr->ExpectTellId( (char *) Request->Buffer, 00640 Request->Size, callback, 00641 ( void * ) Request ); 00642 } 00643 00644 Request->reqid = reqid; 00645 00646 #ifdef RIO_DEBUG2 00647 RioErr << "[CRioStream] reqid "<< reqid << " � relativo ao bloco " 00648 << Request->Block << endl; 00649 #endif 00650 } 00651 else 00652 { 00653 reqid = ( int )Request->reqid; 00654 } 00655 00656 ParameterSize = 2*MAX_LONG_STRING_SIZE + 2*MAX_LONG_STRING_SIZE + 00657 MAX_SHORT_STRING_SIZE + MAX_SHORT_STRING_SIZE + 00658 MAX_LONG_STRING_SIZE + MAX_LONG_STRING_SIZE + 00659 2*(MAX_SHORT_STRING_SIZE+MAX_ULONG_STRING_SIZE); 00660 00661 if( ParameterSize > (unsigned int) MaxTCPDataSize ) 00662 { 00663 free( Parameter ); 00664 free( Result ); 00665 00666 #ifdef RIO_DEBUG1 00667 RioErr << "### [CRioStream - DataRequest1] Finish3" << endl; 00668 #endif 00669 00670 return ERROR_RIOPROXY + ERROR_CALL_MESSAGE_OVERFLOW; 00671 } 00672 00673 int offset = 0; 00674 00675 SetLong( Parameter, ntohl(reqid), &offset ); 00676 SetLong( Parameter, ntohl(ip), &offset ); 00677 SetLong( Parameter, ObjectId, &offset ); 00678 SetLong( Parameter, Request->Block, &offset ); 00679 SetLong( Parameter, repbits, &offset ); 00680 SetShort( Parameter, (short)port, &offset ); 00681 SetShort( Parameter, (short) ReqOp, &offset ); 00682 SetLong( Parameter, traffic, &offset ); 00683 00684 00685 // Update Parameter size to actual size 00686 // (previously was maximum possible size) 00687 ParameterSize = offset; 00688 00689 #ifdef RIO_DEBUG2 00690 RioErr << "[CRioStream] Chamando call para pedido de bloco " 00691 << Request->Block << endl; 00692 #endif 00693 00694 status = m_TCPconnection->Call( RioClassRouter, 00695 RioMethodRouterDataRequest, 00696 ParameterSize, 00697 Parameter, 00698 &ResultSize, 00699 &Result ); 00700 00701 if( FAILED( status ) ) 00702 { 00703 #ifdef RIO_DEBUG2 00704 RioErr << "[RioStream] Failed to call block " << Request->Block 00705 << "(" << GetErrorDescription( status ) << ")" << endl; 00706 #endif 00707 00708 if( ( unsigned int ) status == ( ERROR_RIOTCP + ERROR_MEMORY ) ) 00709 status = ERROR_RIOPROXY + ERROR_MEMORY; 00710 if( Result != NULL ) 00711 free( Result ); 00712 free( Parameter ); 00713 00714 #ifdef RIO_DEBUG1 00715 RioErr << "### [CRioStream - DataRequest1] Finish4" << endl; 00716 #endif 00717 00718 return status; 00719 } 00720 #ifdef RIO_DEBUG2 00721 else 00722 { 00723 RioErr << "[RioStream] DataRequest1 - Foi pedido o bloco " 00724 << Request->Block; 00725 if( traffic == MULTICASTTRAFFIC ) 00726 RioErr << " multicast." << endl; 00727 else 00728 RioErr << " unicast." << endl; 00729 } 00730 #endif 00731 00732 offset = 0; 00733 if( !GetLong( Result, ResultSize, &status, &offset ) ) 00734 { 00735 00736 free( Parameter ); 00737 free( Result ); 00738 00739 #ifdef RIO_DEBUG1 00740 RioErr << "### [CRioStream - DataRequest1] Finish5" << endl; 00741 #endif 00742 00743 return ERROR_RIOPROXY + ERROR_MESSAGE_DATA_FORMAT; 00744 } 00745 00746 free( Parameter ); 00747 free( Result ); 00748 00749 #ifdef RIO_DEBUG1 00750 RioErr << "### [CRioStream - DataRequest1] Finish6" << endl; 00751 #endif 00752 00753 return status; 00754 }
RioResult CRioStream::DataRequest | ( | RioRequest * | Request, | |
int | ObjectId, | |||
RequestOperation | ReqOp, | |||
RioStreamType | traffic = UNICASTTRAFFIC | |||
) | [private] |
Definition at line 758 of file RioStream.cpp.
00761 { 00762 #ifdef RIO_DEBUG1 00763 RioErr << "### [CRioStream - DataRequest2] Start" << endl; 00764 #endif 00765 00766 char *Parameter = (char*) malloc( MaxTCPDataSize*sizeof(char) ); 00767 char *Result; 00768 unsigned int ParameterSize; 00769 unsigned int ResultSize; 00770 HRESULT status; 00771 00772 if( Parameter == NULL ) 00773 { 00774 RioErr << "malloc error DataRequest:" << strerror(errno) << endl; 00775 00776 #ifdef RIO_DEBUG1 00777 RioErr << "### [CRioStream - DataRequest2] Finish1" << endl; 00778 #endif 00779 00780 free( Parameter ); 00781 00782 return ERROR_RIOPROXY + ERROR_MEMORY; 00783 } 00784 00785 memset( Parameter, 0, MaxTCPDataSize*sizeof( char ) ); 00786 00787 if(Request->Status == RIO_REQUEST_PENDING) 00788 { 00789 free( Parameter ); 00790 00791 #ifdef RIO_DEBUG1 00792 RioErr << "### [CRioStream - DataRequest2] Finish2" << endl; 00793 #endif 00794 00795 return ERROR_CLIENT + ERROR_STARTED; 00796 } 00797 00798 Request->Status = RIO_REQUEST_PENDING; 00799 00800 // looking at Result before the request is complete is a client error! 00801 Request->Result = ERROR_CLIENT + ERROR_NOT_STARTED; 00802 00803 int reqid = 0; 00804 int repbits = 0; 00805 00806 // ### need to pass both "this" and Request to callback... 00807 Request->System = (void *)this; 00808 00809 if( traffic == UNICASTTRAFFIC ) 00810 { 00811 if(ReqOp == READ) 00812 { 00813 //ExpectBlock abaixo chama d_neti->ExpectData 00814 if( ( m_NetInterface != NULL ) && 00815 ( m_StreamType == RIO_TRAFFIC_NRT ) ) 00816 reqid = m_NetInterface->ExpectBlock( (char *) Request->Buffer, 00817 Request->Size, callback, 00818 ( void * ) Request ); 00819 else 00820 reqid = m_NetMgr->ExpectBlock( (char *) Request->Buffer, 00821 Request->Size, callback, 00822 ( void * ) Request ); 00823 } 00824 else 00825 { 00826 //ExpectTellId abaixo chama d_neti->ExpectCmd 00827 00828 // A operacao de escrita sempre e em tempo nao real. Portanto, basta 00829 // verificar se m_NetInterface e NULL e usa-la em caso contrario 00830 // (m_NetInterface sera NULL se estivermos usando a PL). 00831 if( m_NetInterface != NULL ) 00832 reqid = m_NetInterface->ExpectTellId( (char *) Request->Buffer, 00833 Request->Size, callback, 00834 ( void * ) Request ); 00835 else 00836 reqid = m_NetMgr->ExpectTellId( (char *) Request->Buffer, 00837 Request->Size, callback, 00838 ( void * ) Request ); 00839 } 00840 00841 Request->reqid = reqid; 00842 } 00843 00844 ParameterSize = 2*MAX_LONG_STRING_SIZE + 00845 2*MAX_LONG_STRING_SIZE + 00846 MAX_LONG_STRING_SIZE + 00847 2*MAX_SHORT_STRING_SIZE + 00848 MAX_LONG_STRING_SIZE + 00849 2*(MAX_SHORT_STRING_SIZE+MAX_ULONG_STRING_SIZE); 00850 00851 if( ParameterSize > (unsigned int) MaxTCPDataSize ) 00852 { 00853 free( Parameter ); 00854 00855 #ifdef RIO_DEBUG1 00856 RioErr << "### [CRioStream - DataRequest2] Finish3" << endl; 00857 #endif 00858 00859 return ERROR_RIOPROXY + ERROR_CALL_MESSAGE_OVERFLOW; 00860 } 00861 00862 int offset = 0; 00863 00864 SetLong(Parameter, ntohl(reqid), &offset); 00865 SetLong(Parameter, ntohl(m_myaddr), &offset); 00866 SetLong(Parameter, ObjectId, &offset); 00867 SetLong(Parameter, Request->Block, &offset); 00868 SetLong(Parameter, repbits, &offset); 00869 SetShort(Parameter, ntohs((short) m_myport), &offset); 00870 SetShort(Parameter, (short) ReqOp, &offset); 00871 SetShort(Parameter, (short) traffic, &offset); 00872 00873 // Update Parameter size to actual size 00874 // (previously was maximum possible size) 00875 ParameterSize = offset; 00876 00877 #ifdef RIO_DEBUG2 00878 RioErr << "[CRioStream] Pedido de bloco - Call() " << endl; 00879 #endif 00880 00881 status = m_TCPconnection->Call(RioClassRouter, 00882 RioMethodRouterDataRequest, 00883 ParameterSize, 00884 Parameter, 00885 &ResultSize, 00886 &Result); 00887 00888 if(FAILED (status)) 00889 { 00890 #ifdef RIO_DEBUG2 00891 RioErr << "[CRioStream] Failed call() " << endl; 00892 #endif 00893 00894 if( ( unsigned int ) status == ( ERROR_RIOTCP + ERROR_MEMORY ) ) 00895 status = ERROR_RIOPROXY + ERROR_MEMORY; 00896 if( Result != NULL ) 00897 free( Result ); 00898 free( Parameter ); 00899 00900 #ifdef RIO_DEBUG1 00901 RioErr << "### [CRioStream - DataRequest2] Finish4" << endl; 00902 #endif 00903 00904 return status; 00905 } 00906 #ifdef RIO_DEBUG2 00907 else 00908 { 00909 RioErr << "[RioStream] DataRequest2 - Foi pedido o bloco " 00910 << Request->Block; 00911 if( traffic == MULTICASTTRAFFIC ) 00912 RioErr << " multicast." << endl; 00913 else 00914 RioErr << " unicast." << endl; 00915 } 00916 #endif 00917 00918 #ifdef RIO_DEBUG2 00919 RioErr << "[CRioStream] retorno do pedido de bloco " << endl; 00920 #endif 00921 00922 offset = 0; 00923 if(!GetLong(Result,ResultSize,&status,&offset)) 00924 { 00925 free( Parameter ); 00926 free( Result ); 00927 00928 #ifdef RIO_DEBUG1 00929 RioErr << "### [CRioStream - DataRequest2] Finish5" << endl; 00930 #endif 00931 00932 return ERROR_RIOPROXY + ERROR_MESSAGE_DATA_FORMAT; 00933 } 00934 00935 free( Parameter ); 00936 free( Result ); 00937 00938 #ifdef RIO_DEBUG1 00939 RioErr << "### [CRioStream - DataRequest2] Finish6" << endl; 00940 #endif 00941 00942 return status; 00943 }
int CRioStream::FreeBlock | ( | unsigned int | block_id, | |
RioStreamType | traffic | |||
) |
Definition at line 1122 of file RioStream.cpp.
void CRioStream::FreeMembers | ( | ) | [private] |
Definition at line 1097 of file RioStream.cpp.
01098 { 01099 #ifdef RIO_DEBUG1 01100 RioErr << "### [CRioStream - FreeMembers] Start" << endl; 01101 #endif 01102 01103 if(m_StreamId.Index != -1) 01104 { 01105 m_StreamManager->Close(m_StreamId); 01106 } 01107 01108 if( m_StreamManager !=0 ) 01109 { 01110 delete m_StreamManager; 01111 m_StreamManager = 0; 01112 } 01113 01114 m_StreamType = RIO_TRAFFIC_INVALID; 01115 01116 #ifdef RIO_DEBUG1 01117 RioErr << "### [CRioStream - FreeMembers] Finish" << endl; 01118 #endif 01119 }
int CRioStream::FreePendentBlocks | ( | bool | useCache, | |
int | nBuffers | |||
) |
Definition at line 1133 of file RioStream.cpp.
01134 { 01135 #ifdef RIO_DEBUG1 01136 RioErr << "### [CRioStream - FreePendentBlocks] Single" << endl; 01137 #endif 01138 01139 // Eu nao alterei esta chamada porque ela e usada somente pela copia em 01140 // tempo real. 01141 return( m_NetMgr->FreePendentBlocks( useCache, nBuffers ) ); 01142 }
RioResult CRioStream::GetBlockSize | ( | unsigned int * | BlockSize | ) | [private] |
Definition at line 1046 of file RioStream.cpp.
01047 { 01048 #ifdef RIO_DEBUG1 01049 RioErr << "### [CRioStream - GetBlockSize] Single" << endl; 01050 #endif 01051 01052 // Check if we are connected 01053 if( !m_opened ) 01054 { 01055 #ifdef RIO_DEBUG1 01056 RioErr << "### [CRioStream - GetBlockSize] Finish1" << endl; 01057 #endif 01058 01059 return ERROR_RIOSTREAM + ERROR_STREAM_NOT_OPENED; 01060 } 01061 01062 *BlockSize = m_BlockSize; 01063 01064 #ifdef RIO_DEBUG1 01065 RioErr << "### [CRioStream - GetBlockSize] Finish2" << endl; 01066 #endif 01067 01068 return S_OK; 01069 }
RioResult CRioStream::GetId | ( | RioStreamId * | Id | ) | [private] |
Definition at line 1072 of file RioStream.cpp.
01073 { 01074 #ifdef RIO_DEBUG1 01075 RioErr << "### [CRioStream - GetId] Single" << endl; 01076 #endif 01077 01078 // Check if we are connected 01079 if( !m_opened ) 01080 { 01081 #ifdef RIO_DEBUG1 01082 RioErr << "### [CRioStream - GetId] Finish1" << endl; 01083 #endif 01084 01085 return ERROR_RIOSTREAM + ERROR_STREAM_NOT_OPENED; 01086 } 01087 01088 *Id = m_StreamId; 01089 #ifdef RIO_DEBUG1 01090 RioErr << "### [CRioStream - GetId] Finish2" << endl; 01091 #endif 01092 01093 return S_OK; 01094 }
void CRioStream::Getmyaddr | ( | int * | my_address, | |
int * | my_port | |||
) |
Definition at line 527 of file RioStream.cpp.
00528 { 00529 #ifdef RIO_DEBUG1 00530 RioErr << "### [CRioStream - Getmyaddr] Single" << endl; 00531 #endif 00532 00533 // Eu nao alterei esta chamada porque ela retorna o IP do cliente associado 00534 // ao servidor de despacho, e porque estamos, temporariamente enquanto a 00535 // classe NetMgr ainda e usada (para as copias em tempo real e o multicast), 00536 // o IP associado a ela do cliente e o que esta sendo passado ao servidor. 00537 m_NetMgr->Getmyaddr( my_address, my_port ); 00538 }
CRioSession * CRioStream::GetRioSession | ( | ) |
Definition at line 551 of file RioStream.cpp.
00552 { 00553 #ifdef RIO_DEBUG1 00554 RioErr << "### [CRioStream - GetRioSession] Single" << endl; 00555 #endif 00556 00557 return m_RioSession; 00558 }
RioTrafficType CRioStream::GetTrafficType | ( | ) |
Definition at line 541 of file RioStream.cpp.
00542 { 00543 #ifdef RIO_DEBUG1 00544 RioErr << "### [CRioStream - GetTrafficType] Single" << endl; 00545 #endif 00546 00547 return m_StreamType; 00548 }
void CRioStream::LeaveAllGroups | ( | void | ) |
Definition at line 385 of file RioStream.cpp.
00386 { 00387 #ifdef RIO_DEBUG1 00388 RioErr << "### [CRioStream - LeaveAllGroups] Start" << endl; 00389 #endif 00390 00391 m_NetMgr->LeaveAllGroups(); 00392 00393 #ifdef RIO_DEBUG1 00394 RioErr << "### [CRioStream - LeaveAllGroups] Finish" << endl; 00395 #endif 00396 }
void CRioStream::LeaveGroup | ( | unsigned short | multicastport | ) |
Definition at line 371 of file RioStream.cpp.
00372 { 00373 #ifdef RIO_DEBUG1 00374 RioErr << "### [CRioStream - LeaveGroup] Start" << endl; 00375 #endif 00376 00377 m_NetMgr->LeaveGroup( multicastport ); 00378 00379 #ifdef RIO_DEBUG1 00380 RioErr << "### [CRioStream - LeaveGroup] Finish" << endl; 00381 #endif 00382 }
RioResult CRioStream::MaxRequests | ( | ) |
Definition at line 947 of file RioStream.cpp.
00948 { 00949 #ifdef RIO_DEBUG1 00950 RioErr << "### [CRioStream - MaxRequests] Single" << endl; 00951 #endif 00952 00953 // Check if we are connected 00954 if( !m_opened ) 00955 { 00956 #ifdef RIO_DEBUG1 00957 RioErr << "### [CRioStream - MaxRequests] Finish1" << endl; 00958 #endif 00959 00960 return ERROR_RIOSTREAM + ERROR_MAX_STREAM_REQUESTS; 00961 } 00962 else 00963 { 00964 #ifdef RIO_DEBUG1 00965 RioErr << "### [CRioStream - MaxRequests] Finish2" << endl; 00966 #endif 00967 00968 return (m_StreamManager->MaxRequests(m_StreamId)); 00969 } 00970 }
void CRioStream::MulticastCallBack | ( | void * | parm, | |
int | result | |||
) | [static] |
Definition at line 1024 of file RioStream.cpp.
01025 { 01026 #ifdef RIO_DEBUG1 01027 RioErr << "### [CRioStream - MulticastCallBack] Start" << endl; 01028 #endif 01029 01030 RioCallBackTransport *callback = ( RioCallBackTransport * ) parm; 01031 01032 #ifdef RIO_DEBUG2 01033 RioErr << "[CRioStream - MulticastCallBack] Chegada de bloco: " 01034 << callback->block << endl; 01035 #endif 01036 01037 callback_t client_callback = callback->main_callback; 01038 (*client_callback)( parm, result ); 01039 01040 #ifdef RIO_DEBUG1 01041 RioErr << "### [CRioStream - MulticastCallBack] Finish" << endl; 01042 #endif 01043 }
RioResult CRioStream::MulticastDataRequest | ( | RioBlock | block, | |
int | ObjectId, | |||
RequestOperation | ReqOp, | |||
int | sendack, | |||
RioStreamType | traffic, | |||
int | ip, | |||
int | port | |||
) | [private] |
Definition at line 403 of file RioStream.cpp.
00407 { 00408 #ifdef RIO_DEBUG1 00409 RioErr << "### [CRioStream - MulticastDataRequest] Start" << endl; 00410 #endif 00411 00412 char *Parameter = (char*) malloc( MaxTCPDataSize*sizeof(char) ); 00413 char *Result; 00414 unsigned int ParameterSize; 00415 unsigned int ResultSize; 00416 HRESULT status; 00417 00418 if( Parameter == NULL ) 00419 { 00420 RioErr << "malloc error MulticastDataRequest:" << strerror(errno) << endl; 00421 00422 #ifdef RIO_DEBUG1 00423 RioErr << "### [CRioStream - MulticastDataRequest] Finish1" << endl; 00424 #endif 00425 00426 free( Parameter ); 00427 00428 return ERROR_RIOPROXY + ERROR_MEMORY; 00429 } 00430 00431 memset( Parameter, 0, MaxTCPDataSize*sizeof( char ) ); 00432 00433 int reqid = 0; 00434 int repbits = 0; 00435 00436 ParameterSize = 2*MAX_LONG_STRING_SIZE + 00437 2*MAX_LONG_STRING_SIZE + 00438 MAX_SHORT_STRING_SIZE + 00439 MAX_SHORT_STRING_SIZE + 00440 MAX_LONG_STRING_SIZE + 00441 MAX_LONG_STRING_SIZE + 00442 2*(MAX_SHORT_STRING_SIZE+MAX_ULONG_STRING_SIZE); 00443 00444 if( ParameterSize > (unsigned int) MaxTCPDataSize ) 00445 { 00446 free( Parameter ); 00447 00448 #ifdef RIO_DEBUG1 00449 RioErr << "### [CRioStream - MulticastDataRequest] Finish2" << endl; 00450 #endif 00451 00452 return ERROR_RIOPROXY + ERROR_CALL_MESSAGE_OVERFLOW; 00453 } 00454 00455 int offset = 0; 00456 00457 SetLong(Parameter, ntohl(reqid), &offset); 00458 SetLong(Parameter, ntohl(ip), &offset); 00459 SetLong(Parameter, ObjectId, &offset); 00460 SetLong(Parameter, block, &offset); 00461 SetLong(Parameter, repbits, &offset); 00462 SetShort(Parameter, ntohs((short) port), &offset); 00463 SetShort(Parameter, (short) ReqOp, &offset); 00464 SetShort(Parameter, (short) traffic, &offset); 00465 00466 // Update Parameter size to actual size 00467 // (previously was maximum possible size) 00468 ParameterSize = offset; 00469 00470 status = m_TCPconnection->Call( RioClassRouter, 00471 RioMethodRouterDataRequest, 00472 ParameterSize, 00473 Parameter, 00474 &ResultSize, 00475 &Result ); 00476 00477 if( FAILED( status ) ) 00478 { 00479 RioErr << "[RioStream] Failed to call block " << block << "(" 00480 << GetErrorDescription( status ) << ")" << endl; 00481 00482 if( ( unsigned int ) status == ( ERROR_RIOTCP + ERROR_MEMORY ) ) 00483 status = ERROR_RIOPROXY + ERROR_MEMORY; 00484 if( Result != NULL ) 00485 free( Result ); 00486 free( Parameter ); 00487 00488 #ifdef RIO_DEBUG1 00489 RioErr << "### [CRioStream - MulticastDataRequest] Finish3" << endl; 00490 #endif 00491 00492 return status; 00493 } 00494 #ifdef RIO_DEBUG2 00495 else 00496 { 00497 RioErr << "[RioStream] MulticastDataRequest - Foi pedido o bloco " 00498 << block << endl; 00499 } 00500 #endif 00501 00502 offset = 0; 00503 00504 if(!GetLong(Result,ResultSize,&status,&offset)) 00505 { 00506 free( Parameter ); 00507 free( Result ); 00508 00509 #ifdef RIO_DEBUG1 00510 RioErr << "### [CRioStream - MulticastDataRequest] Finish4" << endl; 00511 #endif 00512 00513 return ERROR_RIOPROXY + ERROR_MESSAGE_DATA_FORMAT; 00514 } 00515 00516 free( Parameter ); 00517 free( Result ); 00518 00519 #ifdef RIO_DEBUG1 00520 RioErr << "### [CRioStream - MulticastDataRequest] Finish5" << endl; 00521 #endif 00522 00523 return status; 00524 }
RioResult CRioStream::MulticastRead | ( | RioBlock | block, | |
int | ObjectId, | |||
int | sendack, | |||
RioStreamType | traffic | |||
) | [private] |
Definition at line 236 of file RioStream.cpp.
00238 { 00239 #ifdef RIO_DEBUG1 00240 RioErr << "### [CRioStream - MulticastRead] Start" << endl; 00241 #endif 00242 00243 RioResult status = 0; 00244 00245 status = MulticastDataRequest( block, ObjectId, READ, sendack, 00246 traffic, 0, 0 ); 00247 00248 #ifdef RIO_DEBUG_EMUL 00249 if( FAILED( status ) ) 00250 RioErr << "[RioStream MulticastRead] Falha no pedido de bloco " 00251 << block << "(" << GetErrorDescription( status ) << ")" << endl; 00252 #endif 00253 00254 #ifdef RIO_DEBUG1 00255 RioErr << "### [CRioStream - MulticastRead] Finish" << endl; 00256 #endif 00257 00258 return( status ); 00259 }
RioResult CRioStream::Open | ( | const RioStreamTraffic * | Traffic, | |
CRioSession * | RioSession | |||
) |
Definition at line 89 of file RioStream.cpp.
00091 { 00092 #ifdef RIO_DEBUG1 00093 RioErr << "### [CRioStream - Open] Start" << endl; 00094 #endif 00095 00096 RioSessionId SessionId; 00097 00098 // Check if stream is not already opened 00099 if( m_opened ) 00100 { 00101 #ifdef RIO_DEBUG1 00102 RioErr << "### [CRioStream - Open] Finish1" << endl; 00103 #endif 00104 00105 return ERROR_RIOSTREAM + ERROR_STREAM_ALREADY_OPENED; 00106 } 00107 00108 m_RioSession = RioSession; 00109 00110 m_NetMgr = m_RioSession->m_NetMgr; 00111 00112 // Obtem o ponteiro para a classe de gerenciamento de rede. 00113 m_NetInterface = m_RioSession->m_NetInterface; 00114 00115 // Eu nao alterei esta chamada porque ela retorna o IP do cliente associado 00116 // ao servidor de despacho, e porque estamos, temporariamente enquanto a 00117 // classe NetMgr ainda e usada (para as copias em tempo real e o multicast), 00118 // o IP associado a ela do cliente e o que esta sendo passado ao servidor. 00119 m_NetMgr->getmyaddrport( &m_myaddr, &m_myport ); 00120 00121 m_TCPconnection = RioSession->m_TCPconnection; 00122 //### Don't open NetMgr here so that streams share socket/port. 00123 00124 //### preallocate some number of NetBuf here 00125 //### need NetMgr to keep track of preallocated buffer count 00126 // so that pool is sum of all streams? 00127 00128 // Get SessionId from RioSession interface 00129 // A Session must have been previously opened for success 00130 HRESULT hResult; 00131 hResult = RioSession->GetId( &SessionId ); 00132 if( FAILED( hResult ) ) 00133 { 00134 #ifdef RIO_DEBUG1 00135 RioErr << "### [CRioStream - Open] Finish2" << endl; 00136 #endif 00137 00138 return hResult; 00139 } 00140 00141 // Get block size 00142 hResult = RioSession->GetBlockSize( &m_BlockSize ); 00143 if( FAILED( hResult ) ) 00144 { 00145 #ifdef RIO_DEBUG1 00146 RioErr << "### [CRioStream - Open] Finish3" << endl; 00147 #endif 00148 00149 return hResult; 00150 } 00151 00152 // Create Stream Manager Proxy 00153 m_StreamManager = new CStreamManager( m_TCPconnection ); 00154 00155 int maxrequests = 0; 00156 // Open new Stream 00157 hResult = m_RioSession->m_SessionManager->OpenStream ( SessionId, 00158 Traffic, 00159 &m_StreamId, 00160 &maxrequests ); 00161 00162 if( FAILED( hResult ) ) 00163 { 00164 m_StreamId.Version = -1; 00165 m_StreamId.Index = -1; 00166 FreeMembers(); 00167 RioErr << " RioStream - Error opening stream... " << endl; 00168 00169 #ifdef RIO_DEBUG1 00170 RioErr << "### [CRioStream - Open] Finish4" << endl; 00171 #endif 00172 00173 return hResult; 00174 } 00175 00176 m_StreamType = Traffic->Type; 00177 m_opened = true; 00178 00179 #ifdef RIO_DEBUG1 00180 RioErr << "### [CRioStream - Open] Finish5" << endl; 00181 #endif 00182 00183 return S_OK; 00184 }
RioResult CRioStream::Read | ( | RioRequest * | Request, | |
int | ObjectId, | |||
int | sendack, | |||
RioStreamType | traffic, | |||
int | ip, | |||
int | port | |||
) | [private] |
Definition at line 296 of file RioStream.cpp.
00298 { 00299 #ifdef RIO_DEBUG1 00300 RioErr << "### [CRioStream - Read2] Start" << endl; 00301 #endif 00302 00303 RioResult status = 0; 00304 00305 #ifdef RIO_DEBUG2 00306 RioErr << "[RioStream] 2 Fazendo pedido do bloco " 00307 << Request->Block << endl; 00308 #endif 00309 00310 status = DataRequest( Request, ObjectId, READ, sendack, traffic, ip, port ); 00311 00312 #ifdef RIO_DEBUG_EMUL 00313 if( FAILED( status ) ) 00314 RioErr << "[RioStream Read] Falha no pedido de bloco: " 00315 << GetErrorDescription( status ) << endl; 00316 #endif 00317 00318 #ifdef RIO_DEBUG1 00319 RioErr << "### [CRioStream - Read2] Finish" << endl; 00320 #endif 00321 00322 return( status ); 00323 }
RioResult CRioStream::Read | ( | RioRequest * | Request, | |
int | ObjectId, | |||
RioStreamType | traffic = UNICASTTRAFFIC | |||
) | [private] |
Definition at line 264 of file RioStream.cpp.
00266 { 00267 #ifdef RIO_DEBUG1 00268 RioErr << "### [CRioStream - Read1] Start" << endl; 00269 #endif 00270 00271 RioResult status = 0; 00272 00273 #ifdef RIO_DEBUG2 00274 RioErr << "[RioStream] 1 Fazendo pedido do bloco " 00275 << Request->Block << endl; 00276 #endif 00277 00278 status = DataRequest( Request, ObjectId, READ, traffic ); 00279 00280 #ifdef RIO_DEBUG_EMUL 00281 if( FAILED( status ) ) 00282 RioErr << "[RioStream Read] Falha no pedido de bloco " 00283 << Request->Block << "(" << GetErrorDescription( status ) << ")" << endl; 00284 #endif 00285 00286 #ifdef RIO_DEBUG1 00287 RioErr << "### [CRioStream - Read1] Finish" << endl; 00288 #endif 00289 00290 return( status ); 00291 }
bool CRioStream::SetMulticastSocket | ( | unsigned short | multicastport, | |
char * | multicast_addr, | |||
void * | callback = 0 , |
|||
BufferStream * | buffer_stream = 0 , |
|||
int | enable_join = 1 | |||
) |
Definition at line 337 of file RioStream.cpp.
00342 { 00343 #ifdef RIO_DEBUG1 00344 RioErr << "### [CRioStream - SetMulticastSocket] Start" << endl; 00345 #endif 00346 00347 bool rc = true; 00348 RioCallBackTransport *callback_transport = 00349 (RioCallBackTransport*) client_callback; 00350 00351 if( client_callback ) 00352 { 00353 callback_transport->stream = (void *) this; 00354 callback_transport->callback = MulticastCallBack; 00355 } 00356 00357 rc = m_NetMgr->SetMulticastSocket( multicastport, 00358 multicast_addr, 00359 callback_transport, 00360 buffer_stream, 00361 enable_join ); 00362 00363 #ifdef RIO_DEBUG1 00364 RioErr << "### [CRioStream - SetMulticastSocket] Finish" << endl; 00365 #endif 00366 00367 return rc; 00368 }
bool CRioStream::thereAreFragments | ( | RioBlock | block | ) |
Definition at line 1144 of file RioStream.cpp.
01145 { 01146 #ifdef RIO_DEBUG1 01147 RioErr << "### [CRioStream - thereAreFragments] Single" << endl; 01148 #endif 01149 01150 // Eu nao alterei esta chamada porque ela e usada somente pela copia em 01151 // tempo real. 01152 return( m_NetMgr->thereAreFragments( block ) ); 01153 }
RioResult CRioStream::Write | ( | RioRequest * | Request, | |
int | ObjectId | |||
) | [private] |
Definition at line 327 of file RioStream.cpp.
00328 { 00329 #ifdef RIO_DEBUG1 00330 RioErr << "### [CRioStream - Write] Single" << endl; 00331 #endif 00332 00333 return DataRequest(Request, ObjectId, WRITE ); 00334 }
friend class CRioObject [friend] |
Definition at line 491 of file RioInterface.h.
void* CRioStream::client_callback [private] |
Definition at line 443 of file RioInterface.h.
unsigned int CRioStream::m_BlockSize [private] |
Definition at line 447 of file RioInterface.h.
int CRioStream::m_myaddr [private] |
Definition at line 448 of file RioInterface.h.
int CRioStream::m_myport [private] |
Definition at line 449 of file RioInterface.h.
CNetInterface* CRioStream::m_NetInterface [private] |
Definition at line 456 of file RioInterface.h.
NetMgr* CRioStream::m_NetMgr [private] |
Definition at line 451 of file RioInterface.h.
bool CRioStream::m_opened [private] |
Definition at line 444 of file RioInterface.h.
CRioSession* CRioStream::m_RioSession [private] |
Definition at line 450 of file RioInterface.h.
CRouter* CRioStream::m_Router [private] |
Definition at line 453 of file RioInterface.h.
RioStreamId CRioStream::m_StreamId [private] |
Definition at line 445 of file RioInterface.h.
CStreamManager* CRioStream::m_StreamManager [private] |
Definition at line 452 of file RioInterface.h.
RioTrafficType CRioStream::m_StreamType [private] |
Definition at line 446 of file RioInterface.h.
CRioTCP* CRioStream::m_TCPconnection [private] |
Definition at line 454 of file RioInterface.h.