connectivitylayer/isce/p2prouter_dll/src/p2puserchannel.cpp
changeset 9 8486d82aef45
parent 5 8ccc39f9d787
equal deleted inserted replaced
8:6295dc2169f3 9:8486d82aef45
    25 #include "memapi.h"                 // MemApi
    25 #include "memapi.h"                 // MemApi
    26 #include "p2pdefs.h"                // For EP2PAmountOfProtocols
    26 #include "p2pdefs.h"                // For EP2PAmountOfProtocols
    27 
    27 
    28 enum TP2PUserChannelFaults
    28 enum TP2PUserChannelFaults
    29     {
    29     {
    30     EP2PUserChannelMemAllocFail = 0x00,
    30     EP2PUserChannelMemAllocFail = 0x01,
    31     EP2PUserChannelMemAllocFail1,
    31     EP2PUserChannelMemAllocFail1,
    32     EP2PUserChannelMemAllocFail2,
    32     EP2PUserChannelMemAllocFail2,
       
    33     EP2PUserChannelMemAllocFail3,
       
    34     EP2PUserChannelMemAllocFail4,
    33     EP2PUserChannelWrongRequest,
    35     EP2PUserChannelWrongRequest,
    34     EP2PUserChannelWrongRequest1,
    36     EP2PUserChannelWrongRequest1,
    35     EP2PUserChannelWrongRequest2,
    37     EP2PUserChannelWrongRequest2,
    36     EP2PUserChannelWrongRequest3,
    38     EP2PUserChannelWrongRequest3,
    37     EP2PUserChannelWrongRequest4,
    39     EP2PUserChannelWrongRequest4,
    67     EP2PUserChannelReqQueueOutOfSync5,
    69     EP2PUserChannelReqQueueOutOfSync5,
    68     EP2PUserChannelReqQueueOutOfSync6,
    70     EP2PUserChannelReqQueueOutOfSync6,
    69     EP2PUserChannelReqQueueOutOfSync7,
    71     EP2PUserChannelReqQueueOutOfSync7,
    70     EP2PUserChannelReqQueueOverTheLimits,
    72     EP2PUserChannelReqQueueOverTheLimits,
    71     EP2PUserChannelReqQueueOverTheLimits2,
    73     EP2PUserChannelReqQueueOverTheLimits2,
       
    74     EP2PUserChannelReqQueueOverTheLimits3,
    72     EP2PUserChannelReqQueueWrongRequest,
    75     EP2PUserChannelReqQueueWrongRequest,
    73     EP2PUserChannelReqQueueWrongRequest2,
    76     EP2PUserChannelReqQueueWrongRequest2,
    74     EP2PUserChannelReqQueueMemoryAllocFailure,
    77     EP2PUserChannelReqQueueMemoryAllocFailure,
    75     EP2PUserChannelReqQueueCommon,
    78     EP2PUserChannelReqQueueCommon,
    76     };
    79     };
   186 
   189 
   187     C_TRACE( ( _T( "DP2PUserChannel::DoCreate 0x%x 0x%x 0x%x>" ), this, iShP2PProtocolId, anInfo ) );
   190     C_TRACE( ( _T( "DP2PUserChannel::DoCreate 0x%x 0x%x 0x%x>" ), this, iShP2PProtocolId, anInfo ) );
   188     if( !Kern::CurrentThreadHasCapability( ECapabilityCommDD, __PLATSEC_DIAGNOSTIC_STRING( "Check by: P2PRouter" ) ) ) return KErrPermissionDenied;  
   191     if( !Kern::CurrentThreadHasCapability( ECapabilityCommDD, __PLATSEC_DIAGNOSTIC_STRING( "Check by: P2PRouter" ) ) ) return KErrPermissionDenied;  
   189     TRACE_ASSERT_INFO( anInfo, EP2PUserChannelProtocolIdNotSpecified );
   192     TRACE_ASSERT_INFO( anInfo, EP2PUserChannelProtocolIdNotSpecified );
   190     // Check for channel number inside anInfo.
   193     // Check for channel number inside anInfo.
   191     TRACE_ASSERT_INFO( anInfo->Length() > 0, ( EP2PUserChannelOverTheArrayLimits | EDP2PUserChannelTraceId << KClassIdentifierShift ) );
   194     TUint8* buffer = reinterpret_cast<TUint8*>( Kern::Alloc( 1 ) );
   192     if( !anInfo || anInfo->Length() == 0 ) return KErrNotSupported;
   195     
   193     TUint8 protocolId = static_cast<TUint8>( ( *anInfo )[ 0 ] );
   196     
       
   197     TPtr8* bufferPtr = new TPtr8( buffer, 1 );    
       
   198     ASSERT_RESET_ALWAYS( bufferPtr && buffer, EP2PUserChannelMemAllocFail3 | EDP2PUserChannelTraceId << KClassIdentifierShift );
       
   199     
       
   200     ASSERT_RESET_ALWAYS( KErrNone == Kern::ThreadDesRead( iThread, anInfo, *bufferPtr, 0, KChunkShiftBy0 ), EP2PUserChannelMemAllocFail4 | EDP2PUserChannelTraceId << KClassIdentifierShift );
       
   201     ASSERT_RESET_ALWAYS( bufferPtr->Length() > 0 , EP2PUserChannelReqQueueOverTheLimits3 | EDP2PUserChannelTraceId << KClassIdentifierShift);
       
   202     
       
   203     TUint8 protocolId = static_cast<TUint8>( ( *bufferPtr )[ 0 ] );
       
   204 
   194     TRACE_ASSERT_INFO( ( protocolId < EP2PAmountOfProtocols ), ( EP2PUserChannelWrongParam | EDP2PUserChannelTraceId << KClassIdentifierShift ) );
   205     TRACE_ASSERT_INFO( ( protocolId < EP2PAmountOfProtocols ), ( EP2PUserChannelWrongParam | EDP2PUserChannelTraceId << KClassIdentifierShift ) );
   195     if( protocolId >= EP2PAmountOfProtocols ) return KErrNotSupported;
   206     if( protocolId >= EP2PAmountOfProtocols ) return KErrNotSupported;
   196     TInt err( Kern::MutexWait( *iShP2PProtocolIdMutex ) );
   207     TInt err( Kern::MutexWait( *iShP2PProtocolIdMutex ) );
   197     ASSERT_RESET_ALWAYS( ( KErrNone == err ), ( EP2PUserChannelMutexWaitFailed | EDP2PUserChannelTraceId << KClassIdentifierShift ) );
   208     ASSERT_RESET_ALWAYS( ( KErrNone == err ), ( EP2PUserChannelMutexWaitFailed | EDP2PUserChannelTraceId << KClassIdentifierShift ) );
   198     // If channel is already used for some protocol.
   209     // If channel is already used for some protocol.
   445     {
   456     {
   446 
   457 
   447     C_TRACE( ( _T( "DP2PUserChannel::CompleteChReqDfc>" ) ) );
   458     C_TRACE( ( _T( "DP2PUserChannel::CompleteChReqDfc>" ) ) );
   448     // Make sure that user side is accessed only by ldd DFCThread.
   459     // Make sure that user side is accessed only by ldd DFCThread.
   449     ASSERT_THREAD_CONTEXT_ALWAYS( ( EP2PIUserChannelfNotThreadContext2 | EDP2PUserChannelTraceId << KClassIdentifierShift ) );
   460     ASSERT_THREAD_CONTEXT_ALWAYS( ( EP2PIUserChannelfNotThreadContext2 | EDP2PUserChannelTraceId << KClassIdentifierShift ) );
   450     //TODO    ASSERT_DFCTHREAD_INLDD();
   461     //    ASSERT_DFCTHREAD_INLDD();
   451     DP2PUserChannel* chPtr = reinterpret_cast<DP2PUserChannel*>( aPtr );
   462     DP2PUserChannel* chPtr = reinterpret_cast<DP2PUserChannel*>( aPtr );
   452     C_TRACE( ( _T( "DP2PUserChannel::CompleteChReqDfc 0x%x 0x%x" ), chPtr, chPtr->iShP2PProtocolId ) );
   463     C_TRACE( ( _T( "DP2PUserChannel::CompleteChReqDfc 0x%x 0x%x" ), chPtr, chPtr->iShP2PProtocolId ) );
   453     TP2PReq requ = chPtr->iP2PReqQueue->Get();
   464     TP2PReq requ = chPtr->iP2PReqQueue->Get();
   454     if( EP2PAsyncOpen == requ.iRequest )
   465     if( EP2PAsyncOpen == requ.iRequest )
   455         {
   466         {
   476 void DP2PUserChannel::EmptyRxQueueDfc(
   487 void DP2PUserChannel::EmptyRxQueueDfc(
   477         TAny* aPtr // Pointer to self
   488         TAny* aPtr // Pointer to self
   478         )
   489         )
   479     {
   490     {
   480 
   491 
   481 // TODO    ASSERT_DFCTHREAD_INLDD();
   492 //     ASSERT_DFCTHREAD_INLDD();
   482     DP2PUserChannel& chTmp = *reinterpret_cast<DP2PUserChannel*>( aPtr );
   493     DP2PUserChannel& chTmp = *reinterpret_cast<DP2PUserChannel*>( aPtr );
   483     C_TRACE( ( _T( "DP2PUserChannel::EmptyRxQueueDfc 0x%x 0x%x>" ), &chTmp, chTmp.iShP2PProtocolId ) );
   494     C_TRACE( ( _T( "DP2PUserChannel::EmptyRxQueueDfc 0x%x 0x%x>" ), &chTmp, chTmp.iShP2PProtocolId ) );
   484     if( ( chTmp.iP2PReqQueue->GetReq( EP2PAsyncReceive ) ) && ( chTmp.iRx->Count() > 0 ) )
   495     if( ( chTmp.iP2PReqQueue->GetReq( EP2PAsyncReceive ) ) && ( chTmp.iRx->Count() > 0 ) )
   485         {
   496         {
   486         TDes8& tmpDes = chTmp.iRx->Get();
   497         TDes8& tmpDes = chTmp.iRx->Get();
   552             {
   563             {
   553             case EP2PAsyncOpen:
   564             case EP2PAsyncOpen:
   554                 {
   565                 {
   555                 C_TRACE( ( _T( "DP2PUserChannel::HandleAsyncRequest 0x%x 0x%x EP2PAsyncOpen" ), this, iShP2PProtocolId ) );
   566                 C_TRACE( ( _T( "DP2PUserChannel::HandleAsyncRequest 0x%x 0x%x EP2PAsyncOpen" ), this, iShP2PProtocolId ) );
   556                 // Set open to pending to router, router completes it when the interconnection to other point is ready.
   567                 // Set open to pending to router, router completes it when the interconnection to other point is ready.
   557                 iRouterIf->Open( ~iShP2PProtocolId, this );
   568                 iRouterIf->Connect( ~iShP2PProtocolId, this );
   558                 break;
   569                 break;
   559                 }
   570                 }
   560             case EP2PAsyncReceive:
   571             case EP2PAsyncReceive:
   561                 {
   572                 {
   562                 iReceiveBufPtr = reinterpret_cast<TAny*>( tablePtr[ KSecondParam ] );
   573                 iReceiveBufPtr = reinterpret_cast<TAny*>( tablePtr[ KSecondParam ] );