bearermanagement/S60MCPR/src/s60mpmrequests.cpp
branchRCL_3
changeset 13 68f0c7cd80ec
parent 0 5a93021fdf25
child 50 6a30cdd10231
equal deleted inserted replaced
12:ea6e024ea6f9 13:68f0c7cd80ec
    84 // CMPMPolicyRequests::CMPMPolicyRequests
    84 // CMPMPolicyRequests::CMPMPolicyRequests
    85 // -----------------------------------------------------------------------------
    85 // -----------------------------------------------------------------------------
    86 //
    86 //
    87 CMPMPolicyRequests::CMPMPolicyRequests() :
    87 CMPMPolicyRequests::CMPMPolicyRequests() :
    88                                     CActive( EPriorityStandard ),
    88                                     CActive( EPriorityStandard ),
    89                                     iCommitedToDeleteItself( EFalse )
    89                                     iCommitedToDeleteItself( EFalse ),
       
    90                                     iReconnectTimerRunning( EFalse ),
       
    91                                     iReconnectTimeout( KMPMInitialReconnectTimeout )
    90     {
    92     {
    91     S60MCPRLOGSTRING1( "S60MCPR::CMPMPolicyRequests<%x>::CMPMPolicyRequests()", this )
    93     S60MCPRLOGSTRING1( "S60MCPR::CMPMPolicyRequests<%x>::CMPMPolicyRequests()", this )
    92     CActiveScheduler::Add( this );
    94     CActiveScheduler::Add( this );
    93     iConnId = (TConnectionId)this;
    95     iConnId = (TConnectionId)this;
    94     }
    96     }
   127     if ( iMpm.Connected() )
   129     if ( iMpm.Connected() )
   128         {
   130         {
   129         S60MCPRLOGSTRING1( "S60MCPR::CMPMPolicyRequests<%x>::~CMPMPolicyRequests() closing MPM session", this )
   131         S60MCPRLOGSTRING1( "S60MCPR::CMPMPolicyRequests<%x>::~CMPMPolicyRequests() closing MPM session", this )
   130         iMpm.Close();
   132         iMpm.Close();
   131         }
   133         }
       
   134     
       
   135     if ( iReconnectTimerRunning )
       
   136         {
       
   137         Cancel();
       
   138         iReconnectTimer.Close();
       
   139         }
   132     }
   140     }
   133 
   141 
   134 // -----------------------------------------------------------------------------
   142 // -----------------------------------------------------------------------------
   135 // CMPMPolicyRequests::ConstructL
   143 // CMPMPolicyRequests::ConstructL
   136 // -----------------------------------------------------------------------------
   144 // -----------------------------------------------------------------------------
   456 // CMPMPolicyRequests::IssueRequest
   464 // CMPMPolicyRequests::IssueRequest
   457 // -----------------------------------------------------------------------------
   465 // -----------------------------------------------------------------------------
   458 //
   466 //
   459 void CMPMPolicyRequests::IssueRequest()
   467 void CMPMPolicyRequests::IssueRequest()
   460     {
   468     {
   461     //__ASSERT_ALWAYS(IsActive() || iPolicyRequests.Count() > 0,User::Panic(KNetMCprPanic, KPanicInvalidCActiveUsage));
       
   462 
       
   463     // If we have a pending request, back off.
   469     // If we have a pending request, back off.
   464     //
   470     //
   465     if ( IsActive() || iPolicyRequests.Count() == 0 )
   471     if ( IsActive() || iPolicyRequests.Count() == 0 )
   466         {
   472         {
   467         S60MCPRLOGSTRING1( "S60MCPR::CMPMPolicyRequests<%x>::IssueRequest() Unnecessary call, back off", this )
   473         S60MCPRLOGSTRING1( "S60MCPR::CMPMPolicyRequests<%x>::IssueRequest() Unnecessary call, back off", this )
   619 //
   625 //
   620 void CMPMPolicyRequests::RunL()
   626 void CMPMPolicyRequests::RunL()
   621     {
   627     {
   622     S60MCPRLOGSTRING2( "S60MCPR::CMPMPolicyRequests<%x>::RunL() iStatus %d", this, iStatus.Int() )
   628     S60MCPRLOGSTRING2( "S60MCPR::CMPMPolicyRequests<%x>::RunL() iStatus %d", this, iStatus.Int() )
   623 
   629 
   624     // If there's a request waiting and is now completed
   630     // At first, check if this is a timer activity
   625     //
   631     if ( iReconnectTimerRunning )
   626     if ( iPolicyRequests.Count() > 0 && !iCommitedToDeleteItself)
   632         {
   627         {
   633         // iMpm.Connect() failed at least once. Timeout has expired, try again.
       
   634 #ifdef _DEBUG    
       
   635         TBool isConnected = iMpm.Connected();
       
   636         __ASSERT_DEBUG( !isConnected,  User::Panic( KS60MCprPanic, KErrGeneral ) );
       
   637 #endif
       
   638         iReconnectTimerRunning = EFalse;
       
   639         iReconnectTimer.Close();
       
   640         iMpm.Connect( iStatus );
       
   641         SetActive();
       
   642         } 
       
   643     else if ( iPolicyRequests.Count() > 0 && !iCommitedToDeleteItself)
       
   644         {
       
   645         // there's a request waiting and is now completed
   628         S60MCPRLOGSTRING1( "S60MCPR::CMPMPolicyRequests<%x>::RunL() Standard processing", this )
   646         S60MCPRLOGSTRING1( "S60MCPR::CMPMPolicyRequests<%x>::RunL() Standard processing", this )
   629         PolicyRequest& policydata = iPolicyRequests[0];
   647         PolicyRequest& policydata = iPolicyRequests[0];
   630         // Process the response
   648         // Process the response
   631         //
   649         //
   632         switch ( policydata.iRequestType )
   650         switch ( policydata.iRequestType )
   633             {
   651             {
   634             case EPolicyRequestConnect:
   652             case EPolicyRequestConnect:
   635                 {
   653                 {
   636                 if ( iStatus.Int() != KErrNone )
   654                 if ( iStatus.Int() != KErrNone )
   637                     {
   655                     {
   638                     //-jl- MPM connection failed, set MPM connection required again.
   656                     // MPM connection failed, set MPM connection required again.
   639                     iMpm.Close();
   657                     iMpm.Close();
   640                     //-jl- Go to RunError
   658                     // Go to RunError
   641                     User::Leave( iStatus.Int() );
   659                     User::Leave( iStatus.Int() );
   642                     }
   660                     }
   643                 else
   661                 else
   644                     {
   662                     {
   645                     // Otherwise MPM ok and start listening for notifications
   663                     // Otherwise MPM ok and start listening for notifications
   753 // CMPMPolicyRequests::DoCancel
   771 // CMPMPolicyRequests::DoCancel
   754 // -----------------------------------------------------------------------------
   772 // -----------------------------------------------------------------------------
   755 //
   773 //
   756 void CMPMPolicyRequests::DoCancel()
   774 void CMPMPolicyRequests::DoCancel()
   757     {
   775     {
   758     // Not allowed! Cancel() may cause deadlock!
       
   759     _LIT( KPanicMsg, "CMPMPolicyRequests::DoCancel" );
   776     _LIT( KPanicMsg, "CMPMPolicyRequests::DoCancel" );
   760     User::Panic( KPanicMsg, KErrNotSupported );
   777     if ( iReconnectTimerRunning )
       
   778         {
       
   779         iReconnectTimer.Cancel();
       
   780         }
       
   781     else
       
   782         {
       
   783         // Not allowed! Cancel() may cause deadlock!
       
   784         User::Panic( KPanicMsg, KErrNotSupported );
       
   785         }
   761     }
   786     }
   762 
   787 
   763 
   788 
   764 // -----------------------------------------------------------------------------
   789 // -----------------------------------------------------------------------------
   765 // CMPMPolicyRequests::RunError
   790 // CMPMPolicyRequests::RunError
   767 //
   792 //
   768 TInt CMPMPolicyRequests::RunError( TInt aError )
   793 TInt CMPMPolicyRequests::RunError( TInt aError )
   769     {
   794     {
   770     S60MCPRLOGSTRING1( "S60MCPR::CMPMPolicyRequests<%x>::RunError()", this )
   795     S60MCPRLOGSTRING1( "S60MCPR::CMPMPolicyRequests<%x>::RunError()", this )
   771     // Connect has failed, cleanup and deliver errors
   796     // Connect has failed, cleanup and deliver errors
   772     TInt count = iPolicyRequests.Count();
   797     if ( aError != KErrServerBusy || iReconnectTimeout >= KMPMMaxReconnectTimeout )
   773     for ( TInt i = 0; i < count; i++ )
   798         {
   774         {
   799         TInt count = iPolicyRequests.Count();
   775         if ( iPolicyRequests[i].iUser )
   800         for ( TInt i = 0; i < count; i++ )
   776             {
   801             {
   777             S60MCPRLOGSTRING2( "S60MCPR::CMPMPolicyRequests<%x>::RunError() Sending error %d in PolicyResponse", this, aError )
   802             if ( iPolicyRequests[i].iUser )
   778             iPolicyRequests[i].iStatus = aError;
   803                 {
   779             iPolicyRequests[i].iUser->PolicyResponse( iPolicyRequests[i] );
   804                 S60MCPRLOGSTRING2( "S60MCPR::CMPMPolicyRequests<%x>::RunError() Sending error %d in PolicyResponse", this, aError )
   780             }
   805                 iPolicyRequests[i].iStatus = aError;
   781         
   806                 iPolicyRequests[i].iUser->PolicyResponse( iPolicyRequests[i] );
   782         // Delete prefs
   807                 }
   783         iPolicyRequests[i].Cleanup();
   808             
   784         }
   809             // Delete prefs
   785     iPolicyRequests.Reset();
   810             iPolicyRequests[i].Cleanup();
       
   811             }
       
   812         iPolicyRequests.Reset();
       
   813         }
       
   814     else
       
   815         {
       
   816         // KErrServerBusy received, try reconnecting after a brief pause
       
   817         iReconnectTimeout *= KMPMReconnectTimeoutMultiplier;
       
   818         TTimeIntervalMicroSeconds32 timeout( iReconnectTimeout );
       
   819         iReconnectTimer.CreateLocal();
       
   820         iReconnectTimer.After( iStatus, timeout );
       
   821         iReconnectTimerRunning = ETrue;
       
   822         SetActive();
       
   823         }
   786 
   824 
   787     return KErrNone;
   825     return KErrNone;
   788     }
   826     }
   789 
   827 
   790 
   828 
   883 
   921 
   884     // Submit it.
   922     // Submit it.
   885     IssueRequest();
   923     IssueRequest();
   886     }
   924     }
   887 
   925 
   888 
       
   889 // End of file
   926 // End of file