connectivitylayer/isce/p2prouter_dll/src/p2prouter.cpp
changeset 9 8486d82aef45
parent 8 6295dc2169f3
equal deleted inserted replaced
8:6295dc2169f3 9:8486d82aef45
    89     iShChannelTableFastMutex = NULL;
    89     iShChannelTableFastMutex = NULL;
    90     // owning so deleting
    90     // owning so deleting
    91     for( TInt i( 0 ); i < EP2PAmountOfProtocols; i++ )
    91     for( TInt i( 0 ); i < EP2PAmountOfProtocols; i++ )
    92         {
    92         {
    93         MP2PRouterLinkIf* temp = iLinksArray[ i ];
    93         MP2PRouterLinkIf* temp = iLinksArray[ i ];
    94         temp->Release();
    94         if ( temp )
    95         temp = NULL;
    95             {
       
    96             temp->Release();
       
    97             temp = NULL;
       
    98             }
    96         iLinksArray[ i ] = NULL;
    99         iLinksArray[ i ] = NULL;
    97         }
   100         }
    98     delete []iLinksArray;
   101     delete []iLinksArray;
    99     delete []iP2PDfcQueList;
   102     delete []iP2PDfcQueList;
   100     iInitDfc->Cancel();
   103     
   101     delete iInitDfc;
   104     if ( iInitDfc )
   102     iInitDfc = NULL;
   105         {
   103     iTrxPrecentDfc->Cancel();
   106         iInitDfc->Cancel();//what about this
   104     delete iTrxPrecentDfc;
   107         delete iInitDfc;
   105     iTrxPrecentDfc = NULL;
   108         iInitDfc = NULL;
   106     iTrxNotPrecentDfc->Cancel();
   109         }
   107     delete iTrxNotPrecentDfc;
   110         
   108     iTrxNotPrecentDfc = NULL;
   111     if ( iTrxPrecentDfc )
       
   112         {
       
   113         iTrxPrecentDfc->Cancel();//what about this
       
   114         delete iTrxPrecentDfc;
       
   115         iTrxPrecentDfc = NULL;
       
   116         }
       
   117         
       
   118     if ( iTrxNotPrecentDfc )
       
   119         {
       
   120         iTrxNotPrecentDfc->Cancel();//what about this
       
   121         delete iTrxNotPrecentDfc;
       
   122         iTrxNotPrecentDfc = NULL;
       
   123         }
   109     C_TRACE( ( _T( "DP2PRouter::~DP2PRouter<" ) ) );
   124     C_TRACE( ( _T( "DP2PRouter::~DP2PRouter<" ) ) );
   110 
   125 
   111     }
   126     }
   112 
   127 
   113 // From MP2PLinkRouterIf start
   128 // From MP2PLinkRouterIf start
   159     }
   174     }
   160 
   175 
   161 // From MP2PLinkRouterIf end
   176 // From MP2PLinkRouterIf end
   162 
   177 
   163 // From MP2PChRouterIf start
   178 // From MP2PChRouterIf start
   164 void DP2PRouter::Open(
   179 void DP2PRouter::Connect(
   165         const TUint8 aProtocolId,
   180         const TUint8 aProtocolId,
   166         MP2PRouterChIf* aCallback
   181         MP2PRouterChIf* aCallback
   167         )
   182         )
   168     {
   183     {
   169 
   184 
   170     C_TRACE( ( _T( "DP2PRouter::Open %d>" ), aProtocolId ) );
   185     C_TRACE( ( _T( "DP2PRouter::Connect %d>" ), aProtocolId ) );
   171     // TODO :  assert to check always called in p2p extension thread context
   186     //  assert to check always called in p2p extension thread context
   172     ASSERT_RESET_ALWAYS( aCallback, EP2PRouterNullParam );
   187     ASSERT_RESET_ALWAYS( aCallback, EP2PRouterNullParam );
   173     ASSERT_RESET_ALWAYS( aProtocolId < EP2PAmountOfProtocols, ( EP2PRouterWrongParam2 | EDP2PRouterTraceId << KClassIdentifierShift ) );
   188     ASSERT_RESET_ALWAYS( aProtocolId < EP2PAmountOfProtocols, ( EP2PRouterWrongParam2 | EDP2PRouterTraceId << KClassIdentifierShift ) );
   174     ASSERT_RESET_ALWAYS( iLinksArray[ aProtocolId ], ( EP2PRouterWrongParam3 | EDP2PRouterTraceId << KClassIdentifierShift ) );
   189     ASSERT_RESET_ALWAYS( iLinksArray[ aProtocolId ], ( EP2PRouterWrongParam3 | EDP2PRouterTraceId << KClassIdentifierShift ) );
   175     if( iLinksArray[ aProtocolId ]->TrxPresent() )
   190     if( iLinksArray[ aProtocolId ]->TrxPresent() )
   176         {
   191         {
   177         C_TRACE( ( _T( "DP2PRouter::Open ok %d" ), aProtocolId ) );
   192         C_TRACE( ( _T( "DP2PRouter::Connect ok %d" ), aProtocolId ) );
   178         NKern::FMWait( iShChannelTableFastMutex );
   193         NKern::FMWait( iShChannelTableFastMutex );
   179         // Channel with the same protocol id is already opened or waiting to complete the opening.
   194         // Channel with the same protocol id is already opened or waiting to complete the opening.
   180         if( iShChannelTable[ aProtocolId ].iChannel || iShChannelTable[ aProtocolId ].iWaitingChannel )
   195         if( iShChannelTable[ aProtocolId ].iChannel || iShChannelTable[ aProtocolId ].iWaitingChannel )
   181             {
   196             {
   182             NKern::FMSignal( iShChannelTableFastMutex );
   197             NKern::FMSignal( iShChannelTableFastMutex );
   183             // If another channel tries to open already open channel.
   198             // If another channel tries to open already open channel.
   184             TRACE_WARNING( iShChannelTable[ aProtocolId ].iChannel == aCallback, (TUint8)aProtocolId );
   199             TRACE_WARNING( iShChannelTable[ aProtocolId ].iChannel == aCallback, (TUint8)aProtocolId );
   185             aCallback->EnqueChannelRequestCompleteDfc( EP2PAsyncOpen, KErrInUse );//TODO: synch user and kernel APIs return values
   200             aCallback->EnqueChannelRequestCompleteDfc( EP2PAsyncOpen, KErrInUse );// synch user and kernel APIs return values
   186             }
   201             }
   187         else
   202         else
   188             {
   203             {
   189             iShChannelTable[ aProtocolId ].iChannel = aCallback;
   204             iShChannelTable[ aProtocolId ].iChannel = aCallback;
   190             NKern::FMSignal( iShChannelTableFastMutex );
   205             NKern::FMSignal( iShChannelTableFastMutex );
   191             aCallback->EnqueChannelRequestCompleteDfc( EP2PAsyncOpen, KErrNone );
   206             aCallback->EnqueChannelRequestCompleteDfc( EP2PAsyncOpen, KErrNone );
   192             }
   207             }
   193         }
   208         }
   194     else
   209     else
   195         {
   210         {
   196         C_TRACE( ( _T( "DP2PRouter::Open pending %d" ), aProtocolId ) );
   211         C_TRACE( ( _T( "DP2PRouter::Connect pending %d" ), aProtocolId ) );
   197         ASSERT_RESET_ALWAYS( !iShChannelTable[ aProtocolId ].iWaitingChannel, EP2PRouterWrongRequest );
   212         ASSERT_RESET_ALWAYS( !iShChannelTable[ aProtocolId ].iWaitingChannel, EP2PRouterWrongRequest );
   198         NKern::FMWait( iShChannelTableFastMutex );
   213         NKern::FMWait( iShChannelTableFastMutex );
   199         iShChannelTable[ aProtocolId ].iWaitingChannel = aCallback;
   214         iShChannelTable[ aProtocolId ].iWaitingChannel = aCallback;
   200         NKern::FMSignal( iShChannelTableFastMutex );
   215         NKern::FMSignal( iShChannelTableFastMutex );
   201         }
   216         }
   202     C_TRACE( ( _T( "DP2PRouter::Open %d<" ), aProtocolId ) );
   217     C_TRACE( ( _T( "DP2PRouter::Connect %d<" ), aProtocolId ) );
   203 
   218 
   204     }
   219     }
   205 
   220 
   206 void DP2PRouter::Close(
   221 void DP2PRouter::Close(
   207         const TUint8 aProtocolId
   222         const TUint8 aProtocolId
   208         )
   223         )
   209     {
   224     {
   210 
   225 
   211     C_TRACE( ( _T( "DP2PRouter::Close %d>" ), aProtocolId ) );
   226     C_TRACE( ( _T( "DP2PRouter::Close %d>" ), aProtocolId ) );
   212     // TODO :  assert to check always called in p2p extension thread context
   227     //  assert to check always called in p2p extension thread context
   213     ASSERT_RESET_ALWAYS( aProtocolId < EP2PAmountOfProtocols, ( EP2PRouterWrongParam4 | EDP2PRouterTraceId << KClassIdentifierShift ) );
   228     ASSERT_RESET_ALWAYS( aProtocolId < EP2PAmountOfProtocols, ( EP2PRouterWrongParam4 | EDP2PRouterTraceId << KClassIdentifierShift ) );
   214     NKern::FMWait( iShChannelTableFastMutex );
   229     NKern::FMWait( iShChannelTableFastMutex );
   215     if( iShChannelTable[ aProtocolId ].iChannel || iShChannelTable[ aProtocolId ].iWaitingChannel )
   230     if( iShChannelTable[ aProtocolId ].iChannel || iShChannelTable[ aProtocolId ].iWaitingChannel )
   216         {
   231         {
   217         iShChannelTable[ aProtocolId ].iChannel = NULL;
   232         iShChannelTable[ aProtocolId ].iChannel = NULL;
   261         const TUint8 aProtocolId
   276         const TUint8 aProtocolId
   262         )
   277         )
   263     {
   278     {
   264 
   279 
   265     C_TRACE( ( _T( "DP2PRouter::Send 0x%x>" ), &aMessage ) );
   280     C_TRACE( ( _T( "DP2PRouter::Send 0x%x>" ), &aMessage ) );
   266     // TODO :  assert to check always called in p2p extension thread context
   281     //   assert to check always called in p2p extension thread context
   267     // Inside link array limits, if not programmer error.
   282     // Inside link array limits, if not programmer error.
   268     ASSERT_RESET_ALWAYS( aProtocolId < EP2PAmountOfProtocols, ( EP2PRouterWrongParam7 | EDP2PRouterTraceId << KClassIdentifierShift ) );
   283     ASSERT_RESET_ALWAYS( aProtocolId < EP2PAmountOfProtocols, ( EP2PRouterWrongParam7 | EDP2PRouterTraceId << KClassIdentifierShift ) );
   269     MP2PRouterLinkIf* link = iLinksArray[ aProtocolId ];
   284     MP2PRouterLinkIf* link = iLinksArray[ aProtocolId ];
   270     ASSERT_RESET_ALWAYS( link, ( EP2PRouterWrongParam8 | EDP2PRouterTraceId << KClassIdentifierShift ) );
   285     ASSERT_RESET_ALWAYS( link, ( EP2PRouterWrongParam8 | EDP2PRouterTraceId << KClassIdentifierShift ) );
   271     TInt sendResult( KErrNone );
   286     TInt sendResult( KErrNone );
   304     // Initialize channels
   319     // Initialize channels
   305     for( TInt i( 0 ); i < EP2PAmountOfProtocols; ++i )
   320     for( TInt i( 0 ); i < EP2PAmountOfProtocols; ++i )
   306         {
   321         {
   307         iShChannelTable[ i ].iChannel = NULL;
   322         iShChannelTable[ i ].iChannel = NULL;
   308         iShChannelTable[ i ].iWaitingChannel = NULL;
   323         iShChannelTable[ i ].iWaitingChannel = NULL;
   309         }
   324         iShChannelTable[ i ].iTrxConnectionStatus = EFalse;
   310     // TODO:do more clever way to create links.
   325         }
       
   326     // do more clever way to create links.
   311     // Configuration of links.
   327     // Configuration of links.
   312     iLinksArray[ EP2PRpc ] = MP2PRouterLinkIf::CreateLinkF( this, EP2PRpc, ETrxSharedMemory );
   328     iLinksArray[ EP2PRpc ] = MP2PRouterLinkIf::CreateLinkF( this, EP2PRpc, ETrxSharedMemory );
   313     iLinksArray[ EP2PTest ] = MP2PRouterLinkIf::CreateLinkF( this, EP2PTest, ETrxTest );
   329     iLinksArray[ EP2PTest ] = MP2PRouterLinkIf::CreateLinkF( this, EP2PTest, ETrxTest );
   314     iLinksArray[ EP2PTest2 ] = MP2PRouterLinkIf::CreateLinkF( this, EP2PTest2, ETrxTest );
   330     iLinksArray[ EP2PTest2 ] = MP2PRouterLinkIf::CreateLinkF( this, EP2PTest2, ETrxTest );
   315     iTrxPrecentDfc = new TDfc( TrxPrecentDfc, this, iP2PDfcQueList[ MP2PChRouterIf::EP2PDfcThread ], KDfcPriority );
   331     iTrxPrecentDfc = new TDfc( TrxPrecentDfc, this, iP2PDfcQueList[ MP2PChRouterIf::EP2PDfcThread ], KDfcPriority );
   343     // Notify all the protocols channel objects of the change of the presence.
   359     // Notify all the protocols channel objects of the change of the presence.
   344     for( TUint8 i( 0 ); i < EP2PAmountOfProtocols; i++ )
   360     for( TUint8 i( 0 ); i < EP2PAmountOfProtocols; i++ )
   345         {
   361         {
   346         TUint8 protocolId( i );
   362         TUint8 protocolId( i );
   347         C_TRACE( ( _T( "DP2PRouter::TrxPrecentDfc Trx present id=0x%x" ), protocolId ) );
   363         C_TRACE( ( _T( "DP2PRouter::TrxPrecentDfc Trx present id=0x%x" ), protocolId ) );
   348         NKern::FMWait( self.iShChannelTableFastMutex );
   364         if ( !self.iShChannelTable[ protocolId ].iTrxConnectionStatus &&
   349         MP2PRouterChIf* waitingChannel = self.iShChannelTable[ protocolId ].iWaitingChannel;
   365               self.ConnectionExist( protocolId ) )
   350         if( waitingChannel )
       
   351             {
   366             {
   352             self.iShChannelTable[ protocolId ].iChannel = waitingChannel;
   367             // Trx status changed
   353             NKern::FMSignal( self.iShChannelTableFastMutex );
   368             C_TRACE( ( _T( "DP2PRouter::TrxPrecentDfc Trx 0x%x present" ), protocolId ) );
   354             C_TRACE( ( _T( "DP2PRouter::TrxPrecentDfc channel open waiting %d>" ), protocolId ) );
   369             self.iShChannelTable[ protocolId ].iTrxConnectionStatus = ETrue;
   355             waitingChannel->EnqueChannelRequestCompleteDfc( EP2PAsyncOpen, KErrNone );
   370             NKern::FMWait( self.iShChannelTableFastMutex );
       
   371             MP2PRouterChIf* waitingChannel = self.iShChannelTable[ protocolId ].iWaitingChannel;
       
   372             if( waitingChannel )
       
   373                 {
       
   374                 self.iShChannelTable[ protocolId ].iChannel = waitingChannel;
       
   375                 NKern::FMSignal( self.iShChannelTableFastMutex );
       
   376                 C_TRACE( ( _T( "DP2PRouter::TrxPrecentDfc channel open waiting %d>" ), protocolId ) );
       
   377                 waitingChannel->EnqueChannelRequestCompleteDfc( EP2PAsyncOpen, KErrNone );
       
   378                 }
       
   379             else
       
   380                 {
       
   381                 // No need to inform presence, when connection is lost it is closed too and must be opened again.
       
   382                 NKern::FMSignal( self.iShChannelTableFastMutex );
       
   383                 C_TRACE( ( _T( "DP2PRouter::TrxPrecentDfc nothing waiting %d>" ), protocolId ) );
       
   384                 }
   356             }
   385             }
   357         else
   386         // No else: If trx status not changed no need to react
   358             {
       
   359             // No need to inform presence, when connection is lost it is closed too and must be opened again.
       
   360             NKern::FMSignal( self.iShChannelTableFastMutex );
       
   361             C_TRACE( ( _T( "DP2PRouter::TrxPrecentDfc nothing waiting %d>" ), protocolId ) );
       
   362             }
       
   363         }
   387         }
   364     C_TRACE( ( _T( "DP2PRouter::TrxPrecentDfc<" )) );
   388     C_TRACE( ( _T( "DP2PRouter::TrxPrecentDfc<" )) );
   365 
   389 
   366     }
   390     }
   367 
   391 
   374     DP2PRouter& self = *reinterpret_cast<DP2PRouter*>( aPtr );
   398     DP2PRouter& self = *reinterpret_cast<DP2PRouter*>( aPtr );
   375     // Notify all the protocols channel objects of the change of the presence.
   399     // Notify all the protocols channel objects of the change of the presence.
   376     for( TUint8 i( 0 ); i < EP2PAmountOfProtocols; i++ )
   400     for( TUint8 i( 0 ); i < EP2PAmountOfProtocols; i++ )
   377         {
   401         {
   378         TUint8 protocolId( i );
   402         TUint8 protocolId( i );
   379         C_TRACE( ( _T( "DP2PRouter::TrxNotPrecentDfc Trx lost id=0x%x" ), protocolId ) );
   403         if ( self.iShChannelTable[ protocolId ].iTrxConnectionStatus &&
   380         // Notifying channel that connection is lost and discard any received messages.
   404              !self.ConnectionExist( protocolId ) )
   381         NKern::FMWait( self.iShChannelTableFastMutex );
   405             {                
   382         MP2PRouterChIf* channel = self.iShChannelTable[ protocolId ].iChannel;
   406             C_TRACE( ( _T( "DP2PRouter::TrxNotPrecentDfc Trx lost id=0x%x" ), protocolId ) );
   383         if( channel )
   407             self.iShChannelTable[ protocolId ].iTrxConnectionStatus = EFalse;
   384             {
   408             // Notifying channel that connection is lost and discard any received messages.
   385             NKern::FMSignal( self.iShChannelTableFastMutex );
   409             NKern::FMWait( self.iShChannelTableFastMutex );
   386             C_TRACE( ( _T( "DP2PRouter::TrxNotPrecentDfc Trx lost channel found for id=0x%x" ), protocolId ) );
   410             MP2PRouterChIf* channel = self.iShChannelTable[ protocolId ].iChannel;
   387             channel->ConnectionLost();
   411             if( channel )
       
   412                 {
       
   413                 NKern::FMSignal( self.iShChannelTableFastMutex );
       
   414                 C_TRACE( ( _T( "DP2PRouter::TrxNotPrecentDfc Trx lost channel found for id=0x%x" ), protocolId ) );
       
   415                 channel->ConnectionLost();
       
   416                 }
       
   417             else
       
   418                 {
       
   419                 NKern::FMSignal( self.iShChannelTableFastMutex );
       
   420                 C_TRACE( ( _T( "DP2PRouter::TrxNotPrecentDfc Trx lost no channel found for id=0x%x" ), protocolId ) );
       
   421                 }         
   388             }
   422             }
   389         else
   423             // No else: If trx status not changed no need to react
   390             {
       
   391             NKern::FMSignal( self.iShChannelTableFastMutex );
       
   392             C_TRACE( ( _T( "DP2PRouter::TrxNotPrecentDfc Trx lost no channel found for id=0x%x" ), protocolId ) );
       
   393             }
       
   394         }
   424         }
   395     C_TRACE( ( _T( "DP2PRouter::TrxNotPrecentDfc<" )) );
   425     C_TRACE( ( _T( "DP2PRouter::TrxNotPrecentDfc<" )) );
   396 
   426 
   397     }
   427     }
   398 // privates end
   428 // privates end