mtpfws/mtpfw/src/cmtpconnection.cpp
branchRCL_3
changeset 1 f8e15b44d440
parent 0 d0791faffa3f
child 2 4843bb5893b6
equal deleted inserted replaced
0:d0791faffa3f 1:f8e15b44d440
   104     RProcess process;
   104     RProcess process;
   105     RProperty::Delete(process.SecureId(), EMTPConnStateKey);
   105     RProperty::Delete(process.SecureId(), EMTPConnStateKey);
   106     __FLOG(_L8("~CMTPConnection - Exit"));
   106     __FLOG(_L8("~CMTPConnection - Exit"));
   107 	__FLOG_CLOSE;
   107 	__FLOG_CLOSE;
   108     }
   108     }
   109 
       
   110 /**
       
   111 Unbinds the Transport Connection
       
   112 */    
       
   113 void CMTPConnection::Unbind(MMTPTransportConnection& /*aConnection*/)
       
   114 	{
       
   115 	iTransportConnection = NULL;
       
   116 	}
       
   117 
   109 
   118 /**
   110 /**
   119 Initiates MTP transaction data phase processing for initiator-to-responder
   111 Initiates MTP transaction data phase processing for initiator-to-responder
   120 data flows. This method should only be invoked when the MTP transaction phase 
   112 data flows. This method should only be invoked when the MTP transaction phase 
   121 state is ERequestPhase. This is an asynchronous method.
   113 state is ERequestPhase. This is an asynchronous method.
   349 
   341 
   350 /*
   342 /*
   351  * Signals the connection is suspended, the connection state is set to EStateShutdown which 
   343  * Signals the connection is suspended, the connection state is set to EStateShutdown which 
   352  * means that all the current transaction will not be able to send/receive any data via the
   344  * means that all the current transaction will not be able to send/receive any data via the
   353  * connection
   345  * connection
       
   346  * @return ETrue - there is an active transaction currently, and Connection will suspend when it finishes
       
   347  * EFalse - No active transaction, connection suspends immediately.
   354  */
   348  */
   355 void CMTPConnection::ConnectionSuspended()
   349 TBool CMTPConnection::ConnectionSuspended()
   356     {
   350     {
   357     __FLOG(_L8("ConnectionSuspended - Entry"));
   351     __FLOG(_L8("ConnectionSuspended - Entry"));
   358     
   352     
       
   353     TBool ret = EFalse;
   359     TUint currentState = State();
   354     TUint currentState = State();
   360     if (currentState!=EStateShutdown && currentState!=EStateErrorShutdown)
   355     if (currentState != EStateShutdown)
   361         {
   356         {
       
   357         if (ActiveSessions() == 0 || currentState == EStateErrorShutdown)
       
   358             {
       
   359             CompleteCloseConnection();
       
   360             ret = ETrue;
       
   361             }
       
   362         
   362         SetState(EStateShutdown);
   363         SetState(EStateShutdown);
   363         
       
   364         if (iTransportConnection != NULL)
       
   365             {
       
   366             iTransportConnection->Unbind(*this);
       
   367             iTransportConnection = NULL;
       
   368             }
       
   369         PublishConnState(EDisconnectedFromHost);   
   364         PublishConnState(EDisconnectedFromHost);   
   370     
       
   371         if (ActiveSessions() == 0)
       
   372             {
       
   373             CloseAllSessions();
       
   374             iSessions.Reset();
       
   375             iSingletons.Close();
       
   376             }
       
   377         else 
       
   378             {
       
   379             //some session may be in data or response phase, complete them and set transaction phase to ECompletingPhase.
       
   380             const TUint count(iSessions.Count());
       
   381             for (TUint i(0); (i < count); i++)
       
   382                 {
       
   383                 if (iSessions[i]->TransactionPhase() & (EDataIToRPhase|EDataRToIPhase|EResponsePhase))
       
   384                     {
       
   385                     iSessions[i]->SetTransactionPhase(ECompletingPhase);
       
   386                     iSessions[i]->CompletePendingRequest(KErrCancel);
       
   387                     }
       
   388                 }
       
   389             }
       
   390         }
   365         }
   391     
   366     
   392     __FLOG(_L8("ConnectionSuspended - Exit"));
   367     __FLOG(_L8("ConnectionSuspended - Exit"));
       
   368     return ret;
       
   369     }
       
   370 
       
   371 void CMTPConnection::CompleteCloseConnection()
       
   372     {
       
   373     __FLOG(_L8("CompleteCloseConnection - Entry"));
       
   374     
       
   375     CloseAllSessions();
       
   376     iSessions.Reset();
       
   377     
       
   378     //notify ConnectionMgr and corresponding transports of completion of connection close
       
   379     iSingletons.ConnectionMgr().ConnectionCloseComplete(iConnectionId);    
       
   380     iSingletons.Close();
       
   381 
       
   382     __FLOG(_L8("CompleteCloseConnection - Exit"));
   393     }
   383     }
   394 
   384 
   395 /*
   385 /*
   396  * Signals that the connection is resumed to EStateOpen state which means that data providers
   386  * Signals that the connection is resumed to EStateOpen state which means that data providers
   397  * can receive requests from host again.
   387  * can receive requests from host again.
   437     CMTPSession& session(SessionL(aRequest, TMTPTypeRequest::ERequestSessionID));    
   427     CMTPSession& session(SessionL(aRequest, TMTPTypeRequest::ERequestSessionID));    
   438 
   428 
   439     if (ValidFrameworkRequest(&session, KValidPhases, NULL))
   429     if (ValidFrameworkRequest(&session, KValidPhases, NULL))
   440         {
   430         {
   441         session.SetTransactionPhase(EIdlePhase);
   431         session.SetTransactionPhase(EIdlePhase);
   442         if (State() == EStateShutdown)
   432         
   443             {
   433         if (State() == EStateShutdown && ActiveSessions() == 0)
   444             if (ActiveSessions() == 0)
   434             {     
   445                 {        
   435             CompleteCloseConnection();
   446                 CloseAllSessions();
   436             }
   447                 iSessions.Reset();
   437         
   448                 iSingletons.Close();
   438         if (iTransportConnection != NULL)
   449                 
       
   450                 // Move the log here because ShutdownComplete will delete this object.
       
   451                 __FLOG(_L8("TransactionCompleteL - Exit"));
       
   452                 }
       
   453             }
       
   454         else
       
   455             {
   439             {
   456             iTransportConnection->TransactionCompleteL(aRequest);
   440             iTransportConnection->TransactionCompleteL(aRequest);
   457             __FLOG(_L8("TransactionCompleteL - Exit"));
   441             }
   458             }
   442         }
   459         }
   443     __FLOG(_L8("TransactionCompleteL - Exit"));
   460     }
   444     }
   461     
   445     
   462 TUint CMTPConnection::ConnectionId() const
   446 TUint CMTPConnection::ConnectionId() const
   463     {
   447     {
   464     return iConnectionId;
   448     return iConnectionId;
   698     	session.CompletePendingRequest(aErr);
   682     	session.CompletePendingRequest(aErr);
   699 		}
   683 		}
   700     __FLOG(_L8("SendResponseCompleteL - Exit"));
   684     __FLOG(_L8("SendResponseCompleteL - Exit"));
   701     }
   685     }
   702 
   686 
       
   687 void CMTPConnection::Unbind(MMTPTransportConnection& /*aConnection*/)
       
   688     {
       
   689     iTransportConnection = NULL;
       
   690     }
       
   691 
   703    
   692    
   704 TMTPTransactionPhase CMTPConnection::TransactionPhaseL(TUint32 aMTPId) const
   693 TMTPTransactionPhase CMTPConnection::TransactionPhaseL(TUint32 aMTPId) const
   705     {
   694     {
   706     TInt idx(iSessions.FindInOrder(aMTPId, SessionOrder));
   695     TInt idx(iSessions.FindInOrder(aMTPId, SessionOrder));
   707     User::LeaveIfError(idx);
   696     User::LeaveIfError(idx);