00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "RioInterface.h"
00025 #include <stdio.h>
00026 #include <errno.h>
00027
00028 #ifdef WINDOWS
00029
00030 #include "stdafx.h"
00031 int sinalizacao = 0;
00032 int xtimes = 0;
00033 #else
00034 #include <strings.h>
00035 #include <string.h>
00036 #include <pthread.h>
00037 #include <netinet/in.h>
00038 #endif
00039
00040 #include "RioProxy.h"
00041 #include "RioError.h"
00042 #include "SessionManager.h"
00043 #include "StreamManager.h"
00044
00045
00046
00047 CRioStream::CRioStream()
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
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 }
00073
00074 CRioStream::~CRioStream()
00075 {
00076 #ifdef RIO_DEBUG1
00077 RioErr << "### [CRioStream - Destructor] Start" << endl;
00078 #endif
00079
00080 if( m_opened )
00081 Close();
00082
00083 #ifdef RIO_DEBUG1
00084 RioErr << "### [CRioStream - Destructor] Finish" << endl;
00085 #endif
00086 }
00087
00088
00089 RioResult CRioStream::Open( const RioStreamTraffic * Traffic,
00090 CRioSession* RioSession )
00091 {
00092 #ifdef RIO_DEBUG1
00093 RioErr << "### [CRioStream - Open] Start" << endl;
00094 #endif
00095
00096 RioSessionId SessionId;
00097
00098
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
00113 m_NetInterface = m_RioSession->m_NetInterface;
00114
00115
00116
00117
00118
00119 m_NetMgr->getmyaddrport( &m_myaddr, &m_myport );
00120
00121 m_TCPconnection = RioSession->m_TCPconnection;
00122
00123
00124
00125
00126
00127
00128
00129
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
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
00153 m_StreamManager = new CStreamManager( m_TCPconnection );
00154
00155 int maxrequests = 0;
00156
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 }
00185
00186
00187 RioResult CRioStream::Close()
00188 {
00189 #ifdef RIO_DEBUG1
00190 RioErr << "### [CRioStream - Close] Start" << endl;
00191 #endif
00192
00193
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
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 }
00214
00215
00216 int CRioStream::CancelExpect( int reqid )
00217 {
00218 #ifdef RIO_DEBUG1
00219 RioErr << "### [CRioStream - CancelExpect] Single" << endl;
00220 #endif
00221
00222
00223
00224
00225
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 }
00231
00232
00233
00234
00235
00236 RioResult CRioStream::MulticastRead( RioBlock block, int ObjectId ,
00237 int sendack, RioStreamType traffic )
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 }
00260
00261
00262
00263
00264 RioResult CRioStream::Read( RioRequest *Request, int ObjectId,
00265 RioStreamType traffic )
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 }
00292
00293
00294
00295
00296 RioResult CRioStream::Read( RioRequest *Request, int ObjectId, int sendack ,
00297 RioStreamType traffic, int ip, int port )
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 }
00324
00325
00326
00327 RioResult CRioStream::Write(RioRequest *Request, int ObjectId)
00328 {
00329 #ifdef RIO_DEBUG1
00330 RioErr << "### [CRioStream - Write] Single" << endl;
00331 #endif
00332
00333 return DataRequest(Request, ObjectId, WRITE );
00334 }
00335
00336
00337 bool CRioStream::SetMulticastSocket( unsigned short multicastport,
00338 char *multicast_addr,
00339 void *client_callback,
00340 BufferStream *buffer_stream ,
00341 int enable_join )
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 }
00369
00370
00371 void CRioStream::LeaveGroup( unsigned short multicastport )
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 }
00383
00384
00385 void CRioStream::LeaveAllGroups( void )
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 }
00397
00398
00399
00400
00401
00402
00403 RioResult CRioStream::MulticastDataRequest( RioBlock block, int ObjectId,
00404 RequestOperation ReqOp,
00405 int sendack, RioStreamType traffic,
00406 int ip, int port )
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
00467
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 }
00525
00526
00527 void CRioStream::Getmyaddr( int *my_address, int *my_port )
00528 {
00529 #ifdef RIO_DEBUG1
00530 RioErr << "### [CRioStream - Getmyaddr] Single" << endl;
00531 #endif
00532
00533
00534
00535
00536
00537 m_NetMgr->Getmyaddr( my_address, my_port );
00538 }
00539
00540
00541 RioTrafficType CRioStream::GetTrafficType()
00542 {
00543 #ifdef RIO_DEBUG1
00544 RioErr << "### [CRioStream - GetTrafficType] Single" << endl;
00545 #endif
00546
00547 return m_StreamType;
00548 }
00549
00550
00551 CRioSession *CRioStream::GetRioSession()
00552 {
00553 #ifdef RIO_DEBUG1
00554 RioErr << "### [CRioStream - GetRioSession] Single" << endl;
00555 #endif
00556
00557 return m_RioSession;
00558 }
00559
00560
00561
00562 RioResult CRioStream::DataRequest( RioRequest *Request, int ObjectId,
00563 RequestOperation ReqOp, int sendack ,
00564 RioStreamType traffic, int ip, int port )
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
00606 Request->Result = ERROR_CLIENT + ERROR_NOT_STARTED;
00607
00608 int reqid;
00609 int repbits = 0;
00610
00611
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
00632
00633
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
00686
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 }
00755
00756
00757
00758 RioResult CRioStream::DataRequest( RioRequest *Request, int ObjectId,
00759 RequestOperation ReqOp,
00760 RioStreamType traffic )
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
00801 Request->Result = ERROR_CLIENT + ERROR_NOT_STARTED;
00802
00803 int reqid = 0;
00804 int repbits = 0;
00805
00806
00807 Request->System = (void *)this;
00808
00809 if( traffic == UNICASTTRAFFIC )
00810 {
00811 if(ReqOp == READ)
00812 {
00813
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
00827
00828
00829
00830
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
00874
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 }
00944
00945
00946
00947 RioResult CRioStream::MaxRequests()
00948 {
00949 #ifdef RIO_DEBUG1
00950 RioErr << "### [CRioStream - MaxRequests] Single" << endl;
00951 #endif
00952
00953
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 }
00971
00972
00973 RioResult CRioStream::CanStart()
00974 {
00975 #ifdef RIO_DEBUG1
00976 RioErr << "### [CRioStream - CanStart] Single" << endl;
00977 #endif
00978
00979
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 }
00997
00998
00999
01000
01001
01002
01003
01004 void CRioStream::callback( void *parm, int result )
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 }
01021
01022
01023
01024 void CRioStream::MulticastCallBack(void *parm, int result)
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 }
01044
01045
01046 RioResult CRioStream::GetBlockSize(unsigned int* BlockSize)
01047 {
01048 #ifdef RIO_DEBUG1
01049 RioErr << "### [CRioStream - GetBlockSize] Single" << endl;
01050 #endif
01051
01052
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 }
01070
01071
01072 RioResult CRioStream::GetId(RioStreamId* Id)
01073 {
01074 #ifdef RIO_DEBUG1
01075 RioErr << "### [CRioStream - GetId] Single" << endl;
01076 #endif
01077
01078
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 }
01095
01096
01097 void CRioStream::FreeMembers()
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 }
01120
01121
01122 int CRioStream::FreeBlock( unsigned int block_id, RioStreamType traffic )
01123 {
01124 #ifdef RIO_DEBUG1
01125 RioErr << "### [CRioStream - FreeBlock] Single" << endl;
01126 #endif
01127
01128
01129
01130 return( m_NetMgr->FreeBlock( block_id, traffic ) );
01131 }
01132
01133 int CRioStream::FreePendentBlocks( bool useCache, int nBuffers )
01134 {
01135 #ifdef RIO_DEBUG1
01136 RioErr << "### [CRioStream - FreePendentBlocks] Single" << endl;
01137 #endif
01138
01139
01140
01141 return( m_NetMgr->FreePendentBlocks( useCache, nBuffers ) );
01142 }
01143
01144 bool CRioStream::thereAreFragments( RioBlock block )
01145 {
01146 #ifdef RIO_DEBUG1
01147 RioErr << "### [CRioStream - thereAreFragments] Single" << endl;
01148 #endif
01149
01150
01151
01152 return( m_NetMgr->thereAreFragments( block ) );
01153 }
01154
01155 #ifdef RIO_DEBUG2
01156 void CRioStream::printDebug( short debugCode, string message )
01157 {
01158 #ifdef RIO_DEBUG1
01159 RioErr << "### [CRioStream - printDebug] Start" << endl;
01160 #endif
01161
01162
01163
01164 m_NetMgr->printDebug( debugCode, message );
01165
01166 #ifdef RIO_DEBUG1
01167 RioErr << "### [CRioStream - printDebug] Finish" << endl;
01168 #endif
01169 }
01170 #endif