mtpfws/mtpfw/src/cmtpconnection.cpp
changeset 49 c20dd21d1eb4
parent 37 d9d8313203af
equal deleted inserted replaced
41:2c19c7cf5550 49:c20dd21d1eb4
    33 
    33 
    34 #ifdef MTP_CAPTURE_TEST_DATA
    34 #ifdef MTP_CAPTURE_TEST_DATA
    35 #include "cmtprequestlogger.h"
    35 #include "cmtprequestlogger.h"
    36 #endif
    36 #endif
    37 
    37 
       
    38 #include "mtpdebug.h"
       
    39 #include "OstTraceDefinitions.h"
       
    40 #ifdef OST_TRACE_COMPILER_IN_USE
       
    41 #include "cmtpconnectionTraces.h"
       
    42 #endif
       
    43 
    38 #define UNUSED_VAR(a) (a) = (a)
    44 #define UNUSED_VAR(a) (a) = (a)
    39 
       
    40 __FLOG_STMT(_LIT8(KComponent,"MTPConnection");)
       
    41 
    45 
    42 /**
    46 /**
    43 CMTPConnection panics
    47 CMTPConnection panics
    44 */
    48 */
    45 _LIT(KMTPPanicCategory, "CMTPConnection");
    49 _LIT(KMTPPanicCategory, "CMTPConnection");
    77 /**
    81 /**
    78 Destructor.
    82 Destructor.
    79 */
    83 */
    80 CMTPConnection::~CMTPConnection()
    84 CMTPConnection::~CMTPConnection()
    81     {
    85     {
    82     __FLOG(_L8("~CMTPConnection - Entry"));
    86     OstTraceFunctionEntry0( CMTPCONNECTION_CMTPCONNECTION_DES_ENTRY );
    83     CloseAllSessions();
    87     CloseAllSessions();
    84     
    88     
    85 	//remove all events
    89 	//remove all events
    86     DequeueAllEvents();
    90     DequeueAllEvents();
    87 	
    91 	
    95     //close the property
    99     //close the property
    96     iProperty.Close();
   100     iProperty.Close();
    97     // delete the ‘name?property
   101     // delete the ‘name?property
    98     RProcess process;
   102     RProcess process;
    99     RProperty::Delete(process.SecureId(), EMTPConnStateKey);
   103     RProperty::Delete(process.SecureId(), EMTPConnStateKey);
   100     __FLOG(_L8("~CMTPConnection - Exit"));
   104     OstTraceFunctionExit0( CMTPCONNECTION_CMTPCONNECTION_DES_EXIT );
   101 	__FLOG_CLOSE;
       
   102     }
   105     }
   103 
   106 
   104 /**
   107 /**
   105 Initiates MTP transaction data phase processing for initiator-to-responder
   108 Initiates MTP transaction data phase processing for initiator-to-responder
   106 data flows. This method should only be invoked when the MTP transaction phase 
   109 data flows. This method should only be invoked when the MTP transaction phase 
   114 connection.
   117 connection.
   115 @panic CMTPConnection 2 If the MTP transaction phase is invalid.
   118 @panic CMTPConnection 2 If the MTP transaction phase is invalid.
   116 */
   119 */
   117 void CMTPConnection::ReceiveDataL(MMTPType& aData, const TMTPTypeRequest& aRequest, TRequestStatus& aStatus)
   120 void CMTPConnection::ReceiveDataL(MMTPType& aData, const TMTPTypeRequest& aRequest, TRequestStatus& aStatus)
   118     {   
   121     {   
   119     __FLOG(_L8("ReceiveDataL - Entry"));
   122     OstTraceFunctionEntry0( CMTPCONNECTION_RECEIVEDATAL_ENTRY );
       
   123     
   120     iDataReceiveResult = KErrNone;
   124     iDataReceiveResult = KErrNone;
   121     const TUint KValidPhases(ERequestPhase);
   125     const TUint KValidPhases(ERequestPhase);
   122     CMTPSession& session(SessionL(aRequest, TMTPTypeRequest::ERequestSessionID));
   126     CMTPSession& session(SessionL(aRequest, TMTPTypeRequest::ERequestSessionID));
   123     
   127     
   124     if (ValidFrameworkRequest(&session, KValidPhases, &aStatus))
   128     if (ValidFrameworkRequest(&session, KValidPhases, &aStatus))
   130             ValidateAndPublishConnState(session, State());
   134             ValidateAndPublishConnState(session, State());
   131             }
   135             }
   132         
   136         
   133         iTransportConnection->ReceiveDataL(aData, aRequest);      
   137         iTransportConnection->ReceiveDataL(aData, aRequest);      
   134         }
   138         }
   135     __FLOG(_L8("ReceiveDataL - Exit"));
   139     OstTraceFunctionExit0( CMTPCONNECTION_RECEIVEDATAL_EXIT );
   136     }
   140     }
   137 
   141 
   138 /**
   142 /**
   139 Initiates MTP transaction data phase processing for responder-to-initiator
   143 Initiates MTP transaction data phase processing for responder-to-initiator
   140 data flows. This method should only be invoked when the MTP transaction phase
   144 data flows. This method should only be invoked when the MTP transaction phase
   148 connection.
   152 connection.
   149 @panic CMTPConnection 2 If the MTP transaction phase is invalid.
   153 @panic CMTPConnection 2 If the MTP transaction phase is invalid.
   150 */
   154 */
   151 void CMTPConnection::SendDataL(const MMTPType& aData, const TMTPTypeRequest& aRequest, TRequestStatus& aStatus)
   155 void CMTPConnection::SendDataL(const MMTPType& aData, const TMTPTypeRequest& aRequest, TRequestStatus& aStatus)
   152     {
   156     {
   153     __FLOG(_L8("SendDataL - Entry"));
   157     OstTraceFunctionEntry0( CMTPCONNECTION_SENDDATAL_ENTRY );
   154 #ifdef MTP_CAPTURE_TEST_DATA
   158 #ifdef MTP_CAPTURE_TEST_DATA
   155     iRequestLogger->WriteDataPhaseL(aData, EDataRToIPhase);
   159     iRequestLogger->WriteDataPhaseL(aData, EDataRToIPhase);
   156 #endif
   160 #endif
   157 
   161 
   158     const TUint KValidPhases(ERequestPhase);
   162     const TUint KValidPhases(ERequestPhase);
   168             //publish the connection state info to the subscriber.
   172             //publish the connection state info to the subscriber.
   169             ValidateAndPublishConnState(session, State());
   173             ValidateAndPublishConnState(session, State());
   170             }
   174             }
   171         iTransportConnection->SendDataL(aData, aRequest);
   175         iTransportConnection->SendDataL(aData, aRequest);
   172         }
   176         }
   173     __FLOG(_L8("SendDataL - Exit"));
   177     OstTraceFunctionExit0( CMTPCONNECTION_SENDDATAL_EXIT );
   174     }
   178     }
   175 
   179 
   176 /**
   180 /**
   177 Sends an MTP event dataset.
   181 Sends an MTP event dataset.
   178 @param aEvent The MTP event dataset source.
   182 @param aEvent The MTP event dataset source.
   179 @leave KErrNotFound If the MTP event dataset specifies an invalid SessionID.
   183 @leave KErrNotFound If the MTP event dataset specifies an invalid SessionID.
   180 */
   184 */
   181 void CMTPConnection::SendEventL(const TMTPTypeEvent& aEvent)
   185 void CMTPConnection::SendEventL(const TMTPTypeEvent& aEvent)
   182     {
   186     {
   183     __FLOG(_L8("SendEventL - Entry"));
   187     OstTraceFunctionEntry0( CMTPCONNECTION_SENDEVENTL_ENTRY );
   184     const TUint KValidPhases(EIdlePhase | ERequestPhase | EDataIToRPhase| EDataRToIPhase | EResponsePhase | ECompletingPhase);
   188     const TUint KValidPhases(EIdlePhase | ERequestPhase | EDataIToRPhase| EDataRToIPhase | EResponsePhase | ECompletingPhase);
   185     if (ValidFrameworkRequest(NULL, KValidPhases, NULL))
   189     if (ValidFrameworkRequest(NULL, KValidPhases, NULL))
   186         {
   190         {
   187         // Validate the SessionID
   191         // Validate the SessionID
   188         TUint32 sessionId(aEvent.Uint32(TMTPTypeEvent::EEventSessionID));
   192         TUint32 sessionId(aEvent.Uint32(TMTPTypeEvent::EEventSessionID));
   189         if (sessionId != KMTPSessionAll)
   193         if (sessionId != KMTPSessionAll)
   190             {
   194             {
   191             User::LeaveIfError(iSessions.FindInOrder(sessionId, SessionOrder));
   195             TInt ret = iSessions.FindInOrder(sessionId, SessionOrder);
       
   196             LEAVEIFERROR(ret, 
       
   197                     OstTrace1(TRACE_ERROR, CMTPCONNECTION_SENDEVENTL, "can't find according to session_id %d", sessionId));
   192             }
   198             }
   193             
   199             
   194 
   200 
   195 		EnqueueEvent(new (ELeave) CMTPEventLink(aEvent));
   201 		EnqueueEvent(new (ELeave) CMTPEventLink(aEvent));
   196 		if (iPendingEventCount == 1)
   202 		if (iPendingEventCount == 1)
   197 			{
   203 			{
   198 			// Forward the event to the transport connection layer.
   204 			// Forward the event to the transport connection layer.
   199 			iTransportConnection->SendEventL(iEventQ.First()->iEvent);			
   205 			iTransportConnection->SendEventL(iEventQ.First()->iEvent);			
   200 			}
   206 			}
   201         }
   207         }
   202     __FLOG(_L8("SendEventL - Exit"));
   208     OstTraceFunctionExit0( CMTPCONNECTION_SENDEVENTL_EXIT );
   203     }
   209     }
   204 
   210 
   205 /**
   211 /**
   206 Initiates MTP transaction response phase processing. This method should only 
   212 Initiates MTP transaction response phase processing. This method should only 
   207 be invoked when the MTP transaction phase state is either ERequestPhase, or 
   213 be invoked when the MTP transaction phase state is either ERequestPhase, or 
   217 connection.
   223 connection.
   218 @panic CMTPConnection 2 If the MTP transaction phase is invalid.
   224 @panic CMTPConnection 2 If the MTP transaction phase is invalid.
   219 */
   225 */
   220 void CMTPConnection::SendResponseL(const TMTPTypeResponse& aResponse, const TMTPTypeRequest& aRequest, TRequestStatus& aStatus)
   226 void CMTPConnection::SendResponseL(const TMTPTypeResponse& aResponse, const TMTPTypeRequest& aRequest, TRequestStatus& aStatus)
   221     {
   227     {
   222     __FLOG(_L8("SendResponseL - Entry"));
   228     OstTraceFunctionEntry0( CMTPCONNECTION_SENDRESPONSEL_ENTRY );
   223 #ifdef MTP_CAPTURE_TEST_DATA
   229 #ifdef MTP_CAPTURE_TEST_DATA
   224     // Running under debug capture mode save this request off to disk.
   230     // Running under debug capture mode save this request off to disk.
   225     iRequestLogger->LogResponseL(aResponse);
   231     iRequestLogger->LogResponseL(aResponse);
   226 #endif
   232 #endif
   227     
   233     
   237             Request/Response mismatch by the originating data provider plug-in. 
   243             Request/Response mismatch by the originating data provider plug-in. 
   238             Fail the transport connection to avoid leaving the current 
   244             Fail the transport connection to avoid leaving the current 
   239             transaction irrecoverably hanging.
   245             transaction irrecoverably hanging.
   240             */
   246             */
   241             UnrecoverableMTPError();
   247             UnrecoverableMTPError();
   242             User::Leave(KErrArgument);                
   248             OstTrace0(TRACE_ERROR, CMTPCONNECTION_SENDRESPONSEL, "Request/Response mismatch");
       
   249             User::Leave(KErrArgument);   
   243             }
   250             }
   244 
   251 
   245         if (session.TransactionPhase() == ERequestPhase)
   252         if (session.TransactionPhase() == ERequestPhase)
   246             {
   253             {
   247             // Transaction has no data phase.
   254             // Transaction has no data phase.
   250             
   257             
   251         session.SetRequestPending(aStatus);
   258         session.SetRequestPending(aStatus);
   252         
   259         
   253         iTransportConnection->SendResponseL(aResponse, aRequest);
   260         iTransportConnection->SendResponseL(aResponse, aRequest);
   254         }
   261         }
   255     __FLOG(_L8("SendResponseL - Exit"));
   262     OstTraceFunctionExit0( CMTPCONNECTION_SENDRESPONSEL_EXIT );
   256     }
   263     }
   257 
   264 
   258 /**
   265 /**
   259 Deletes the session object assigned to the specified session and notifies all 
   266 Deletes the session object assigned to the specified session and notifies all 
   260 loaded data providers.
   267 loaded data providers.
   265 @leave One of the system wide error codes, if a general processing failure 
   272 @leave One of the system wide error codes, if a general processing failure 
   266 occurs.
   273 occurs.
   267 */
   274 */
   268 EXPORT_C void CMTPConnection::SessionClosedL(TUint32 aMTPId)
   275 EXPORT_C void CMTPConnection::SessionClosedL(TUint32 aMTPId)
   269     {
   276     {
   270     __FLOG(_L8("SessionClosedL - Entry"));
   277     OstTraceFunctionEntry0( CMTPCONNECTION_SESSIONCLOSEDL_ENTRY );
   271     if(0x0FFFFFFF != aMTPId)
   278     if(0x0FFFFFFF != aMTPId)
   272     	{
   279     	{
   273     	TInt idx(iSessions.FindInOrder(aMTPId, SessionOrder));
   280     	TInt idx(iSessions.FindInOrder(aMTPId, SessionOrder));
   274 	    __ASSERT_DEBUG((idx != KErrNotFound), Panic(EMTPPanicInvalidSession));
   281 	    __ASSERT_DEBUG((idx != KErrNotFound), Panic(EMTPPanicInvalidSession));
   275 	    CloseSession(idx);
   282 	    CloseSession(idx);
   286 		    	SessionClosedL(id);	
   293 		    	SessionClosedL(id);	
   287 		    	}
   294 		    	}
   288 		    session = NULL;
   295 		    session = NULL;
   289 		    }
   296 		    }
   290 	    }
   297 	    }
   291     __FLOG(_L8("SessionClosedL - Exit"));
   298     OstTraceFunctionExit0( CMTPCONNECTION_SESSIONCLOSEDL_EXIT );
   292     }
   299     }
   293 
   300 
   294 /**
   301 /**
   295 Creates a new session object for the specified session and notifies all loaded
   302 Creates a new session object for the specified session and notifies all loaded
   296 data providers. The session is known by two identifiers:
   303 data providers. The session is known by two identifiers:
   309 @leave One of the system wide error codes, if a general processing failure 
   316 @leave One of the system wide error codes, if a general processing failure 
   310 occurs.
   317 occurs.
   311 */
   318 */
   312 EXPORT_C void CMTPConnection::SessionOpenedL(TUint32 aMTPId)
   319 EXPORT_C void CMTPConnection::SessionOpenedL(TUint32 aMTPId)
   313     {
   320     {
   314     __FLOG(_L8("SessionOpenedL - Entry"));
   321     OstTraceFunctionEntry0( CMTPCONNECTION_SESSIONOPENEDL_ENTRY );
   315     // Validate the SessionID
   322     // Validate the SessionID
   316     if (SessionWithMTPIdExists(aMTPId))
   323     if (SessionWithMTPIdExists(aMTPId))
   317         {
   324         {
   318         User::Leave(KErrAlreadyExists);            
   325         OstTrace1(TRACE_ERROR, CMTPCONNECTION_SESSIONOPENEDL, "session %d alreay exist", aMTPId);
       
   326         User::Leave(KErrAlreadyExists);   
   319         }
   327         }
   320     
   328     
   321     // Create a new session object
   329     // Create a new session object
   322     CMTPSession* session = CMTPSession::NewLC(aMTPId, aMTPId);
   330     CMTPSession* session = CMTPSession::NewLC(aMTPId, aMTPId);
   323     session->SetTransactionPhase(EIdlePhase);
   331     session->SetTransactionPhase(EIdlePhase);
   330         // OpenSession Command coming and now it is really connected to host.
   338         // OpenSession Command coming and now it is really connected to host.
   331         PublishConnState(EConnectedToHost);
   339         PublishConnState(EConnectedToHost);
   332         TMTPNotificationParamsSessionChange params = {aMTPId, *this};
   340         TMTPNotificationParamsSessionChange params = {aMTPId, *this};
   333         iSingletons.DpController().NotifyDataProvidersL(EMTPSessionOpened, &params);
   341         iSingletons.DpController().NotifyDataProvidersL(EMTPSessionOpened, &params);
   334         }
   342         }
   335     __FLOG(_L8("SessionOpenedL - Exit"));
   343     OstTraceFunctionExit0( CMTPCONNECTION_SESSIONOPENEDL_EXIT );
   336     }
   344     }
   337 
   345 
   338 /*
   346 /*
   339  * Signals the connection is suspended, the connection state is set to EStateShutdown which 
   347  * Signals the connection is suspended, the connection state is set to EStateShutdown which 
   340  * means that all the current transaction will not be able to send/receive any data via the
   348  * means that all the current transaction will not be able to send/receive any data via the
   342  * @return ETrue - there is an active transaction currently, and Connection will suspend when it finishes
   350  * @return ETrue - there is an active transaction currently, and Connection will suspend when it finishes
   343  * EFalse - No active transaction, connection suspends immediately.
   351  * EFalse - No active transaction, connection suspends immediately.
   344  */
   352  */
   345 TBool CMTPConnection::ConnectionSuspended()
   353 TBool CMTPConnection::ConnectionSuspended()
   346     {
   354     {
   347     __FLOG(_L8("ConnectionSuspended - Entry"));
   355     OstTraceFunctionEntry0( CMTPCONNECTION_CONNECTIONSUSPENDED_ENTRY );
   348     
   356     
   349     TBool ret = EFalse;
   357     TBool ret = EFalse;
   350     TUint currentState = State();
   358     TUint currentState = State();
   351     if (currentState != EStateShutdown)
   359     if (currentState != EStateShutdown)
   352         {
   360         {
   358           
   366           
   359         SetState(EStateShutdown);
   367         SetState(EStateShutdown);
   360         PublishConnState(EDisconnectedFromHost);   
   368         PublishConnState(EDisconnectedFromHost);   
   361         }
   369         }
   362     
   370     
   363     __FLOG(_L8("ConnectionSuspended - Exit"));
   371     OstTraceFunctionExit0( CMTPCONNECTION_CONNECTIONSUSPENDED_EXIT );
   364     return ret;
   372     return ret;
   365     }
   373     }
   366 
   374 
   367 void CMTPConnection::CompleteCloseConnection()
   375 void CMTPConnection::CompleteCloseConnection()
   368     {
   376     {
   369     __FLOG(_L8("CompleteCloseConnection - Entry"));
   377     OstTraceFunctionEntry0( CMTPCONNECTION_COMPLETECLOSECONNECTION_ENTRY );
   370     
   378     
   371     CloseAllSessions();
   379     CloseAllSessions();
   372     iSessions.Reset();
   380     iSessions.Reset();
   373     
   381     
   374     //notify ConnectionMgr and corresponding transports of completion of connection close
   382     //notify ConnectionMgr and corresponding transports of completion of connection close
   375     iSingletons.ConnectionMgr().ConnectionCloseComplete(iConnectionId);    
   383     iSingletons.ConnectionMgr().ConnectionCloseComplete(iConnectionId);    
   376     iSingletons.Close();
   384     iSingletons.Close();
   377 
   385 
   378     __FLOG(_L8("CompleteCloseConnection - Exit"));
   386     OstTraceFunctionExit0( CMTPCONNECTION_COMPLETECLOSECONNECTION_EXIT );
   379     }
   387     }
   380 
   388 
   381 /*
   389 /*
   382  * Signals that the connection is resumed to EStateOpen state which means that data providers
   390  * Signals that the connection is resumed to EStateOpen state which means that data providers
   383  * can receive requests from host again.
   391  * can receive requests from host again.
   384  * @aTransportConnection The new transport connection object
   392  * @aTransportConnection The new transport connection object
   385  * @leave One of the system wide error codes, if a processing failure occurs.
   393  * @leave One of the system wide error codes, if a processing failure occurs.
   386  */
   394  */
   387 void CMTPConnection::ConnectionResumedL(MMTPTransportConnection& aTransportConnection)
   395 void CMTPConnection::ConnectionResumedL(MMTPTransportConnection& aTransportConnection)
   388     {
   396     {
   389     __FLOG(_L8("ConnectionResumed - Entry"));
   397     OstTraceFunctionEntry0( CMTPCONNECTION_CONNECTIONRESUMEDL_ENTRY );
   390     
   398     
   391     TUint currentState = State();
   399     TUint currentState = State();
   392     if (currentState != EStateOpen && currentState != EStateErrorRecovery)
   400     if (currentState != EStateOpen && currentState != EStateErrorRecovery)
   393         {
   401         {
   394         iSingletons.OpenL();
   402         iSingletons.OpenL();
   407         iTransportConnection->BindL(*this);
   415         iTransportConnection->BindL(*this);
   408         SetState(EStateOpen); 
   416         SetState(EStateOpen); 
   409          
   417          
   410         }
   418         }
   411     
   419     
   412     __FLOG(_L8("ConnectionResumed - Exit"));
   420     OstTraceFunctionExit0( CMTPCONNECTION_CONNECTIONRESUMEDL_EXIT );
   413     }
   421     }
   414 
   422 
   415 /**
   423 /**
   416 Signals the completion of the current transaction processing sequence. This
   424 Signals the completion of the current transaction processing sequence. This
   417 method should only be invoked when the MTP transaction phase state is 
   425 method should only be invoked when the MTP transaction phase state is 
   420 @leave KErrNotFound If the MTP request dataset specifies an invalid SessionID.
   428 @leave KErrNotFound If the MTP request dataset specifies an invalid SessionID.
   421 @panic CMTPConnection 2 If the MTP transaction phase is invalid.
   429 @panic CMTPConnection 2 If the MTP transaction phase is invalid.
   422 */
   430 */
   423 void CMTPConnection::TransactionCompleteL(const TMTPTypeRequest& aRequest)
   431 void CMTPConnection::TransactionCompleteL(const TMTPTypeRequest& aRequest)
   424     {
   432     {
   425     __FLOG(_L8("TransactionCompleteL - Entry"));
   433     OstTraceFunctionEntry0( CMTPCONNECTION_TRANSACTIONCOMPLETEL_ENTRY );
       
   434 
   426     const TUint KValidPhases(ECompletingPhase);
   435     const TUint KValidPhases(ECompletingPhase);
   427     CMTPSession& session(SessionL(aRequest, TMTPTypeRequest::ERequestSessionID));    
   436     CMTPSession& session(SessionL(aRequest, TMTPTypeRequest::ERequestSessionID));    
   428 
   437 
   429     if (ValidFrameworkRequest(&session, KValidPhases, NULL))
   438     if (ValidFrameworkRequest(&session, KValidPhases, NULL))
   430         {
   439         {
   438         if (State() == EStateShutdown && ActiveSessions() == 0)
   447         if (State() == EStateShutdown && ActiveSessions() == 0)
   439             {     
   448             {     
   440             CompleteCloseConnection();
   449             CompleteCloseConnection();
   441             }
   450             }
   442         }
   451         }
   443     __FLOG(_L8("TransactionCompleteL - Exit"));
   452 
       
   453     OstTraceFunctionExit0( CMTPCONNECTION_TRANSACTIONCOMPLETEL_EXIT );
   444     }
   454     }
   445     
   455     
   446 TUint CMTPConnection::ConnectionId() const
   456 TUint CMTPConnection::ConnectionId() const
   447     {
   457     {
   448     return iConnectionId;
   458     return iConnectionId;
   459     }
   469     }
   460 
   470 
   461 MMTPSession& CMTPConnection::SessionWithMTPIdL(TUint32 aMTPId) const
   471 MMTPSession& CMTPConnection::SessionWithMTPIdL(TUint32 aMTPId) const
   462     {
   472     {
   463     TInt idx(iSessions.FindInOrder(aMTPId, SessionOrder));
   473     TInt idx(iSessions.FindInOrder(aMTPId, SessionOrder));
   464     User::LeaveIfError(idx);
   474     LEAVEIFERROR(idx, 
       
   475             OstTrace1(TRACE_ERROR, CMTPCONNECTION_SESSIONWITHMTPIDL, "can't find according to session_id %d", aMTPId));
   465     return *iSessions[idx];
   476     return *iSessions[idx];
   466     }
   477     }
   467     
   478     
   468 TBool CMTPConnection::SessionWithUniqueIdExists(TUint32 aUniqueId) const
   479 TBool CMTPConnection::SessionWithUniqueIdExists(TUint32 aUniqueId) const
   469     {
   480     {
   475     return SessionWithMTPIdL(aUniqueId);
   486     return SessionWithMTPIdL(aUniqueId);
   476     }
   487     }
   477     
   488     
   478 void CMTPConnection::ReceivedEventL(const TMTPTypeEvent& aEvent)
   489 void CMTPConnection::ReceivedEventL(const TMTPTypeEvent& aEvent)
   479     {  
   490     {  
   480     __FLOG(_L8("ReceivedEventL - Entry"));
   491     OstTraceFunctionEntry0( CMTPCONNECTION_RECEIVEDEVENTL_ENTRY );
       
   492 
   481     TInt idx(KErrNotFound);
   493     TInt idx(KErrNotFound);
   482     
   494     
   483     // Validate the SessionID.
   495     // Validate the SessionID.
   484     TUint32 sessionId(aEvent.Uint32(TMTPTypeEvent::EEventSessionID));
   496     TUint32 sessionId(aEvent.Uint32(TMTPTypeEvent::EEventSessionID));
   485     if (sessionId != KMTPSessionAll)
   497     if (sessionId != KMTPSessionAll)
   486         {
   498         {
   487         idx = iSessions.FindInOrder(sessionId, SessionOrder);
   499         idx = iSessions.FindInOrder(sessionId, SessionOrder);
   488         User::LeaveIfError(idx);
   500         LEAVEIFERROR(idx, 
       
   501                 OstTrace1(TRACE_ERROR, CMTPCONNECTION_RECEIVEDEVENTL, "can't find according to session_id %d", sessionId));
   489         }
   502         }
   490        
   503        
   491     // Check that this event is valid.
   504     // Check that this event is valid.
   492     CMTPSession& session(*iSessions[idx]);
   505     CMTPSession& session(*iSessions[idx]);
   493 
   506 
   499     	{
   512     	{
   500     	session.StorePendingEventL(aEvent);
   513     	session.StorePendingEventL(aEvent);
   501     	}
   514     	}
   502     else
   515     else
   503     	{
   516     	{
   504 	   	if (request.Uint32(TMTPTypeRequest::ERequestTransactionID) > 
   517         TUint32 requestTransactionId = request.Uint32(TMTPTypeRequest::ERequestTransactionID);
   505 	    	aEvent.Uint32(TMTPTypeEvent::EEventTransactionID) )
   518         TUint32 eventTransactionId = aEvent.Uint32(TMTPTypeEvent::EEventTransactionID); 
       
   519 	   	if (eventTransactionId > requestTransactionId)
   506 	        {
   520 	        {
   507 	        // Event to be queued for future use, we can only queue one event at a time
   521 	        // Event to be queued for future use, we can only queue one event at a time
   508 	        session.StorePendingEventL(aEvent);
   522 	        session.StorePendingEventL(aEvent);
   509 	        }
   523 	        }
   510 	        
   524 	   	else if (eventTransactionId == requestTransactionId)
   511 	    if (request.Uint32(TMTPTypeRequest::ERequestTransactionID) == 
       
   512 	         aEvent.Uint32(TMTPTypeEvent::EEventTransactionID) )
       
   513 	        {     
   525 	        {     
   514 	        // Event is valid	     
   526 	        // Event is valid	     
   515 	        // Perform transport layer processing.
   527 	        // Perform transport layer processing.
   516 	        if (aEvent.Uint16(TMTPTypeEvent::EEventCode) == EMTPEventCodeCancelTransaction)
   528 	        if (aEvent.Uint16(TMTPTypeEvent::EEventCode) == EMTPEventCodeCancelTransaction)
   517 	            {
   529 	            {
   527 	                {
   539 	                {
   528 	                InitiateTransactionCancelL(idx);
   540 	                InitiateTransactionCancelL(idx);
   529 	                }
   541 	                }
   530 	            }
   542 	            }
   531 	        
   543 	        
   532 	         // Forward the event to the DP framework layer.
   544 	        // Forward the event to the DP framework layer.
   533 	        iSingletons.Router().ProcessEventL(aEvent, *this); 
   545 	        iSingletons.Router().ProcessEventL(aEvent, *this); 
   534 	        }
   546 	        }
       
   547 	   	
       
   548 	   	//discard the event if the event transaction id < requestion transaction id
       
   549 	   	
   535     	}	
   550     	}	
   536     __FLOG(_L8("ReceivedEventL - Exit"));
   551 
       
   552     OstTraceFunctionExit0( CMTPCONNECTION_RECEIVEDEVENTL_EXIT );
   537     }
   553     }
   538 
   554 
   539 void CMTPConnection::ReceivedRequestL(const TMTPTypeRequest& aRequest)
   555 void CMTPConnection::ReceivedRequestL(const TMTPTypeRequest& aRequest)
   540     {  
   556     {  
   541     __FLOG(_L8("ReceivedRequestL - Entry"));
   557     OstTraceFunctionEntry0( CMTPCONNECTION_RECEIVEDREQUESTL_ENTRY );
       
   558     
   542 #ifdef MTP_CAPTURE_TEST_DATA
   559 #ifdef MTP_CAPTURE_TEST_DATA
   543     // Running under debug capture mode save this request off to disk.
   560     // Running under debug capture mode save this request off to disk.
   544     iRequestLogger->LogRequestL(aRequest);
   561     iRequestLogger->LogRequestL(aRequest);
   545 #endif
   562 #endif
   546 
   563 
   572             // Forward the request to the DP framework layer.
   589             // Forward the request to the DP framework layer.
   573             TRAPD(err,iSingletons.Router().ProcessRequestL(session.ActiveRequestL(), *this));   
   590             TRAPD(err,iSingletons.Router().ProcessRequestL(session.ActiveRequestL(), *this));   
   574             if(err!=KErrNone)
   591             if(err!=KErrNone)
   575                 {
   592                 {
   576                 session.SetTransactionPhase(EIdlePhase);
   593                 session.SetTransactionPhase(EIdlePhase);
       
   594                 OstTrace1(TRACE_ERROR, CMTPCONNECTION_RECEIVEDREQUESTL, "router process request error! error code %d", err);
   577                 User::Leave(err);
   595                 User::Leave(err);
   578                 }
   596                 }
   579             }
   597             }
   580         }
   598         }
   581     __FLOG(_L8("ReceivedRequestL - Exit"));
   599     OstTraceFunctionExit0( CMTPCONNECTION_RECEIVEDREQUESTL_EXIT );
   582     }
   600     }
   583 
   601 
   584 #ifdef MTP_CAPTURE_TEST_DATA
   602 #ifdef MTP_CAPTURE_TEST_DATA
   585 void CMTPConnection::ReceiveDataCompleteL(TInt aErr, const MMTPType& aData, const TMTPTypeRequest& aRequest)
   603 void CMTPConnection::ReceiveDataCompleteL(TInt aErr, const MMTPType& aData, const TMTPTypeRequest& aRequest)
   586 #else
   604 #else
   587 void CMTPConnection::ReceiveDataCompleteL(TInt aErr, const MMTPType& aData, const TMTPTypeRequest& aRequest)
   605 void CMTPConnection::ReceiveDataCompleteL(TInt aErr, const MMTPType& aData, const TMTPTypeRequest& aRequest)
   588 #endif
   606 #endif
   589     {
   607     {
   590     __FLOG(_L8("ReceiveDataCompleteL - Entry"));    
   608     OstTraceFunctionEntry0( CMTPCONNECTION_RECEIVEDATACOMPLETEL_ENTRY );
       
   609     
   591     CMTPSession& session(SessionL(aRequest, TMTPTypeRequest::ERequestSessionID)); 
   610     CMTPSession& session(SessionL(aRequest, TMTPTypeRequest::ERequestSessionID)); 
   592     __ASSERT_DEBUG((session.TransactionPhase() == EDataIToRPhase), Panic(EMTPPanicInvalidState));
   611     __ASSERT_DEBUG((session.TransactionPhase() == EDataIToRPhase), Panic(EMTPPanicInvalidState));
   593     
   612     
   594 	if(EMTPTypeFile == aData.Type())
   613 	if(EMTPTypeFile == aData.Type())
   595 	{
   614 	{
   602 #endif
   621 #endif
   603     
   622     
   604 	session.SetTransactionPhase(EResponsePhase);
   623 	session.SetTransactionPhase(EResponsePhase);
   605 	iDataReceiveResult = aErr;
   624 	iDataReceiveResult = aErr;
   606 	session.CompletePendingRequest(aErr);
   625 	session.CompletePendingRequest(aErr);
   607     
   626 	OstTraceFunctionExit0( CMTPCONNECTION_RECEIVEDATACOMPLETEL_EXIT );
   608     __FLOG(_L8("ReceiveDataCompleteL - Exit"));
       
   609     }
   627     }
   610 
   628 
   611 void CMTPConnection::SendDataCompleteL(TInt aErr, const MMTPType& aData, const TMTPTypeRequest& aRequest)
   629 void CMTPConnection::SendDataCompleteL(TInt aErr, const MMTPType& aData, const TMTPTypeRequest& aRequest)
   612     {
   630     {
   613     __FLOG(_L8("SendDataCompleteL - Entry"));  
   631     OstTraceFunctionEntry0( CMTPCONNECTION_SENDDATACOMPLETEL_ENTRY );   
   614     CMTPSession& session(SessionL(aRequest, TMTPTypeRequest::ERequestSessionID)); 
   632     CMTPSession& session(SessionL(aRequest, TMTPTypeRequest::ERequestSessionID)); 
   615     __ASSERT_DEBUG((session.TransactionPhase() == EDataRToIPhase), Panic(EMTPPanicInvalidState));
   633     __ASSERT_DEBUG((session.TransactionPhase() == EDataRToIPhase), Panic(EMTPPanicInvalidState));
   616 
   634 
   617     session.SetTransactionPhase(EResponsePhase);
   635     session.SetTransactionPhase(EResponsePhase);
   618    
   636    
   623         PublishConnState(EConnectedToHost);
   641         PublishConnState(EConnectedToHost);
   624         }
   642         }
   625     
   643     
   626     session.CompletePendingRequest(aErr);
   644     session.CompletePendingRequest(aErr);
   627     
   645     
   628     __FLOG(_L8("SendDataCompleteL - Exit"));
   646     OstTraceFunctionExit0( CMTPCONNECTION_SENDDATACOMPLETEL_EXIT );
   629     }
   647     }
   630 
   648 
   631 void CMTPConnection::SendEventCompleteL(TInt aErr, const TMTPTypeEvent& aEvent)
   649 void CMTPConnection::SendEventCompleteL(TInt aErr, const TMTPTypeEvent& aEvent)
   632     {
   650     {
   633     __FLOG(_L8("SendEventCompleteL - Entry"));
   651     OstTraceFunctionEntry0( CMTPCONNECTION_SENDEVENTCOMPLETEL_ENTRY );
   634 
   652 
   635     
   653     
   636     if (aErr != KErrNone)
   654     if (aErr != KErrNone)
   637         {
   655         {
   638         UnrecoverableMTPError();            
   656         UnrecoverableMTPError();            
   660    	if (iPendingEventCount > 0)
   678    	if (iPendingEventCount > 0)
   661    		{
   679    		{
   662 		if (NULL != iTransportConnection)
   680 		if (NULL != iTransportConnection)
   663 			{
   681 			{
   664 			// Forward the event to the transport connection layer.
   682 			// Forward the event to the transport connection layer.
   665 			__FLOG(_L8("Sending queued event"));
   683 			OstTrace0( TRACE_NORMAL, CMTPCONNECTION_SENDEVENTCOMPLETEL, "Sending queued event");
   666 			iTransportConnection->SendEventL(iEventQ.First()->iEvent);
   684 			iTransportConnection->SendEventL(iEventQ.First()->iEvent);
   667 			}
   685 			}
   668 		else
   686 		else
   669 			{
   687 			{
   670 			DequeueAllEvents();
   688 			DequeueAllEvents();
   671 			}
   689 			}
   672    		}
   690    		}
   673     
   691     
   674     __FLOG(_L8("SendEventCompleteL - Exit"));
   692     OstTraceFunctionExit0( CMTPCONNECTION_SENDEVENTCOMPLETEL_EXIT );
   675     }
   693     }
   676 
   694 
   677 void CMTPConnection::SendResponseCompleteL(TInt aErr, const TMTPTypeResponse& /*aResponse*/, const TMTPTypeRequest& aRequest)
   695 void CMTPConnection::SendResponseCompleteL(TInt aErr, const TMTPTypeResponse& /*aResponse*/, const TMTPTypeRequest& aRequest)
   678     {   
   696     {   
   679     __FLOG(_L8("SendResponseCompleteL - Entry"));
   697     OstTraceFunctionEntry0( CMTPCONNECTION_SENDRESPONSECOMPLETEL_ENTRY );
       
   698     
   680 	if(iState == EStateErrorRecovery)
   699 	if(iState == EStateErrorRecovery)
   681 		{
   700 		{
   682 		MTPErrorRecoveryComplete();	    
   701 		MTPErrorRecoveryComplete();	    
   683 		iTransportConnection->TransactionCompleteL(aRequest);
   702 		iTransportConnection->TransactionCompleteL(aRequest);
   684 		}
   703 		}
   686         CMTPSession& session(SessionL(aRequest, TMTPTypeRequest::ERequestSessionID)); 
   705         CMTPSession& session(SessionL(aRequest, TMTPTypeRequest::ERequestSessionID)); 
   687 	    __ASSERT_DEBUG((session.TransactionPhase() == EResponsePhase), Panic(EMTPPanicInvalidState));
   706 	    __ASSERT_DEBUG((session.TransactionPhase() == EResponsePhase), Panic(EMTPPanicInvalidState));
   688     	session.SetTransactionPhase(ECompletingPhase);
   707     	session.SetTransactionPhase(ECompletingPhase);
   689     	session.CompletePendingRequest(aErr);
   708     	session.CompletePendingRequest(aErr);
   690 		}
   709 		}
   691     __FLOG(_L8("SendResponseCompleteL - Exit"));
   710     OstTraceFunctionExit0( CMTPCONNECTION_SENDRESPONSECOMPLETEL_EXIT );
   692     }
   711     }
   693 
   712 
   694 void CMTPConnection::Unbind(MMTPTransportConnection& /*aConnection*/)
   713 void CMTPConnection::Unbind(MMTPTransportConnection& /*aConnection*/)
   695     {
   714     {
   696     iTransportConnection = NULL;
   715     iTransportConnection = NULL;
   698 
   717 
   699    
   718    
   700 TMTPTransactionPhase CMTPConnection::TransactionPhaseL(TUint32 aMTPId) const
   719 TMTPTransactionPhase CMTPConnection::TransactionPhaseL(TUint32 aMTPId) const
   701     {
   720     {
   702     TInt idx(iSessions.FindInOrder(aMTPId, SessionOrder));
   721     TInt idx(iSessions.FindInOrder(aMTPId, SessionOrder));
   703     User::LeaveIfError(idx);
   722     LEAVEIFERROR(idx, 
       
   723             OstTrace1(TRACE_ERROR, CMTPCONNECTION_TRANSACTIONPHASEL, "can't find according to session_id %d", aMTPId));
   704     return iSessions[idx]->TransactionPhase();
   724     return iSessions[idx]->TransactionPhase();
   705     }
   725     }
   706 
   726 
   707 /**
   727 /**
   708 Constructor.
   728 Constructor.
   719 Second phase constructor.
   739 Second phase constructor.
   720 @leave One of the system wide error code, if a processing failure occurs.
   740 @leave One of the system wide error code, if a processing failure occurs.
   721 */
   741 */
   722 void CMTPConnection::ConstructL()
   742 void CMTPConnection::ConstructL()
   723     {
   743     {
   724 	__FLOG_OPEN(KMTPSubsystem, KComponent);
   744     OstTraceFunctionEntry0( CMTPCONNECTION_CONSTRUCTL_ENTRY );   
   725     __FLOG(_L8("ConstructL - Entry"));
       
   726     //define the property for publishing connection state.
   745     //define the property for publishing connection state.
   727     DefineConnStatePropertyL();
   746     DefineConnStatePropertyL();
   728     PublishConnState(EDisconnectedFromHost);  
   747     PublishConnState(EDisconnectedFromHost);  
   729 #ifdef MTP_CAPTURE_TEST_DATA
   748 #ifdef MTP_CAPTURE_TEST_DATA
   730     // Running under debug capture mode save this request off to disk.
   749     // Running under debug capture mode save this request off to disk.
   731     iRequestLogger = CMTPRequestLogger::NewL();
   750     iRequestLogger = CMTPRequestLogger::NewL();
   732 #endif
   751 #endif
   733     __FLOG(_L8("ConstructL - Exit"));
   752     OstTraceFunctionExit0( CMTPCONNECTION_CONSTRUCTL_EXIT );
   734     }
   753     }
   735     
   754     
   736 /**
   755 /**
   737 Initiates an MTP connection level protocol error recovery sequence. This 
   756 Initiates an MTP connection level protocol error recovery sequence. This 
   738 sequence is invoked when a recoverable protocol error is detected that cannot 
   757 sequence is invoked when a recoverable protocol error is detected that cannot 
   748 @leave One of the system wide error codes, if a processing failure occurs.
   767 @leave One of the system wide error codes, if a processing failure occurs.
   749 @see MTPErrorRecoveryComplete
   768 @see MTPErrorRecoveryComplete
   750 */
   769 */
   751 void CMTPConnection::InitiateMTPErrorRecoveryL(const TMTPTypeRequest& aRequest, TUint16 aResponseCode)
   770 void CMTPConnection::InitiateMTPErrorRecoveryL(const TMTPTypeRequest& aRequest, TUint16 aResponseCode)
   752     {
   771     {
   753     __FLOG(_L8("InitiateMTPErrorRecoveryL - Entry"));
   772     OstTraceFunctionEntry0( CMTPCONNECTION_INITIATEMTPERRORRECOVERYL_ENTRY );   
   754     // Populate error response.
   773     // Populate error response.
   755     iResponse.Reset();
   774     iResponse.Reset();
   756     iResponse.SetUint16(TMTPTypeResponse::EResponseCode, aResponseCode);
   775     iResponse.SetUint16(TMTPTypeResponse::EResponseCode, aResponseCode);
   757     iResponse.SetUint32(TMTPTypeResponse::EResponseSessionID, aRequest.Uint32(TMTPTypeRequest::ERequestSessionID));
   776     iResponse.SetUint32(TMTPTypeResponse::EResponseSessionID, aRequest.Uint32(TMTPTypeRequest::ERequestSessionID));
   758     iResponse.SetUint32(TMTPTypeResponse::EResponseTransactionID, aRequest.Uint32(TMTPTypeRequest::ERequestTransactionID));
   777     iResponse.SetUint32(TMTPTypeResponse::EResponseTransactionID, aRequest.Uint32(TMTPTypeRequest::ERequestTransactionID));
   759     
   778     
   760     // Set the connection state pending completion, and send the response.
   779     // Set the connection state pending completion, and send the response.
   761     SetState(EStateErrorRecovery);
   780     SetState(EStateErrorRecovery);
   762     iTransportConnection->SendResponseL(iResponse, aRequest);
   781     iTransportConnection->SendResponseL(iResponse, aRequest);
   763     __FLOG(_L8("InitiateMTPErrorRecoveryL - Exit"));
   782     OstTraceFunctionExit0( CMTPCONNECTION_INITIATEMTPERRORRECOVERYL_EXIT );
   764     }
   783     }
   765     
   784     
   766 /**
   785 /**
   767 Concludes an MTP connection level protocol error recovery sequence.
   786 Concludes an MTP connection level protocol error recovery sequence.
   768 @see InitiateMTPErrorRecoveryL
   787 @see InitiateMTPErrorRecoveryL
   769 */
   788 */
   770 void CMTPConnection::MTPErrorRecoveryComplete()
   789 void CMTPConnection::MTPErrorRecoveryComplete()
   771     {
   790     {
   772     __FLOG(_L8("MTPErrorRecoveryComplete - Entry"));
   791     OstTraceFunctionEntry0( CMTPCONNECTION_MTPERRORRECOVERYCOMPLETE_ENTRY ); 
   773     SetState(EStateOpen);
   792     SetState(EStateOpen);
   774     PublishConnState(EConnectedToHost);	
   793     PublishConnState(EConnectedToHost);	
   775     __FLOG(_L8("MTPErrorRecoveryComplete - Exit"));
   794     OstTraceFunctionExit0( CMTPCONNECTION_MTPERRORRECOVERYCOMPLETE_EXIT );
   776     }
   795     }
   777     
   796     
   778 /**
   797 /**
   779 Forces the immediate shutdown of the MTP connection. This is invoked when a 
   798 Forces the immediate shutdown of the MTP connection. This is invoked when a 
   780 protocol error is detected that cannot be recovered from, e.g. if an attempt
   799 protocol error is detected that cannot be recovered from, e.g. if an attempt
   781 is detected to initiate an MTP transaction before a previous transaction has 
   800 is detected to initiate an MTP transaction before a previous transaction has 
   782 concluded.
   801 concluded.
   783 */
   802 */
   784 void CMTPConnection::UnrecoverableMTPError()
   803 void CMTPConnection::UnrecoverableMTPError()
   785     {
   804     {
   786     __FLOG(_L8("UnrecoverableMTPError - Entry"));
   805     OstTraceFunctionEntry0( CMTPCONNECTION_UNRECOVERABLEMTPERROR_ENTRY ); 
   787     SetState(EStateErrorShutdown);
   806     SetState(EStateErrorShutdown);
   788     PublishConnState(EDisconnectedFromHost);		
   807     PublishConnState(EDisconnectedFromHost);		
   789     iTransportConnection->CloseConnection();
   808     iTransportConnection->CloseConnection();
   790     __FLOG(_L8("UnrecoverableMTPError - Exit"));
   809     OstTraceFunctionExit0( CMTPCONNECTION_UNRECOVERABLEMTPERROR_EXIT );
   791     }
   810     }
   792 
   811 
   793 /**
   812 /**
   794 Signals the MTP connection transport to terminate any in-progress data phase 
   813 Signals the MTP connection transport to terminate any in-progress data phase 
   795 processing on the specified session.
   814 processing on the specified session.
   796 @param aidx The sessions table index of the required session.
   815 @param aidx The sessions table index of the required session.
   797 @leave One of the system wide error codes, if a processing failure occurs.
   816 @leave One of the system wide error codes, if a processing failure occurs.
   798 */
   817 */
   799 void CMTPConnection::InitiateTransactionCancelL(TInt aIdx)
   818 void CMTPConnection::InitiateTransactionCancelL(TInt aIdx)
   800     {    
   819     {    
   801     __FLOG(_L8("InitiateTransactionCancelL - Entry"));
   820     OstTraceFunctionEntry0( CMTPCONNECTION_INITIATETRANSACTIONCANCELL_ENTRY );   
   802     // Initiate transport connection level termination of the active data phase.
   821     // Initiate transport connection level termination of the active data phase.
   803     CMTPSession& session(*iSessions[aIdx]);
   822     CMTPSession& session(*iSessions[aIdx]);
   804     
   823     
   805     switch (session.TransactionPhase())
   824     switch (session.TransactionPhase())
   806         {
   825         {
   816     case EResponsePhase:
   835     case EResponsePhase:
   817     case EDataRToIPhase:
   836     case EDataRToIPhase:
   818         iTransportConnection->SendDataCancelL(session.ActiveRequestL());
   837         iTransportConnection->SendDataCancelL(session.ActiveRequestL());
   819         break;
   838         break;
   820         }
   839         }
   821     __FLOG(_L8("InitiateTransactionCancelL - Exit"));
   840     OstTraceFunctionExit0( CMTPCONNECTION_INITIATETRANSACTIONCANCELL_EXIT );
   822     }
   841     }
   823 
   842 
   824 /**
   843 /**
   825 Provides a count of the number of sessions with transactions in-progress.
   844 Provides a count of the number of sessions with transactions in-progress.
   826 */
   845 */
   827 TUint CMTPConnection::ActiveSessions() const
   846 TUint CMTPConnection::ActiveSessions() const
   828     {
   847     {
   829     __FLOG(_L8("ActiveSessions - Entry"));
   848     OstTraceFunctionEntry0( CMTPCONNECTION_ACTIVESESSIONS_ENTRY );   
   830     TUint active(0);
   849     TUint active(0);
   831     const TUint count(iSessions.Count());
   850     const TUint count(iSessions.Count());
   832     for (TUint i(0); (i < count); i++)
   851     for (TUint i(0); (i < count); i++)
   833         {
   852         {
   834         if (iSessions[i]->TransactionPhase() > EIdlePhase)
   853         if (iSessions[i]->TransactionPhase() > EIdlePhase)
   835             {
   854             {
   836             active++;
   855             active++;
   837             }
   856             }
   838         }
   857         }
   839     __FLOG_VA((_L8("Active sessions = %d"), active));
   858     OstTrace1( TRACE_NORMAL, CMTPCONNECTION_ACTIVESESSIONS, "Active sessions = %d", active );  
   840     __FLOG(_L8("ActiveSessions - Exit"));
   859     OstTraceFunctionExit0( CMTPCONNECTION_ACTIVESESSIONS_EXIT );
   841     return active;
   860     return active;
   842     }
   861     }
   843 
   862 
   844 /**
   863 /**
   845 Closes all sessions which have been opened on the connection.
   864 Closes all sessions which have been opened on the connection.
   846 */
   865 */
   847 void CMTPConnection::CloseAllSessions()
   866 void CMTPConnection::CloseAllSessions()
   848     {
   867     {
   849     __FLOG(_L8("CloseAllSessions - Entry"));
   868     OstTraceFunctionEntry0( CMTPCONNECTION_CLOSEALLSESSIONS_ENTRY );
   850 	
   869 	
   851     TInt count = iSessions.Count();
   870     TInt count = iSessions.Count();
   852     __FLOG_VA((_L8("Sessions number to be closed = %d"), count));   
   871     OstTrace1( TRACE_NORMAL, CMTPCONNECTION_CLOSEALLSESSIONS, "Sessions number to be closed = %d", count );
   853 	for (TInt i(count - 1); i>=0; i--)
   872 	for (TInt i(count - 1); i>=0; i--)
   854 		{
   873 		{
   855 		CloseSession(i);
   874 		CloseSession(i);
   856 		}
   875 		}
   857 	
   876 	
   858     __FLOG(_L8("CloseAllSessions - Exit"));
   877     OstTraceFunctionExit0( CMTPCONNECTION_CLOSEALLSESSIONS_EXIT );
   859     }
   878     }
   860 
   879 
   861 /**
   880 /**
   862 Closes the sessions with the specified session index.
   881 Closes the sessions with the specified session index.
   863 @param aIdx The session index.
   882 @param aIdx The session index.
   864 */
   883 */
   865 void CMTPConnection::CloseSession(TUint aIdx)
   884 void CMTPConnection::CloseSession(TUint aIdx)
   866     {
   885     {
   867     __FLOG(_L8("CloseSession - Entry"));
   886     OstTraceFunctionEntry0( CMTPCONNECTION_CLOSESESSION_ENTRY );
   868     
   887     
   869     __FLOG_VA((_L8("Session index to be closed = %d"), aIdx));    
   888     OstTrace1(TRACE_NORMAL, CMTPCONNECTION_CLOSESESSION, "Session index to be closed = %d", aIdx);
   870     CMTPSession* session(iSessions[aIdx]);
   889     CMTPSession* session(iSessions[aIdx]);
   871         
   890         
   872     TUint id(session->SessionMTPId());
   891     TUint id(session->SessionMTPId());
   873     if (id != KMTPSessionNone)
   892     if (id != KMTPSessionNone)
   874         {
   893         {
   883     
   902     
   884     // Delete the session object.
   903     // Delete the session object.
   885     iSessions.Remove(aIdx);
   904     iSessions.Remove(aIdx);
   886     delete session;
   905     delete session;
   887     
   906     
   888     __FLOG(_L8("CloseSession - Exit"));
   907     OstTraceFunctionExit0( CMTPCONNECTION_CLOSESESSION_EXIT );
   889     }
   908     }
   890     
   909     
   891 /**
   910 /**
   892 Provides a reference to the session with the MTP connection assigned identifier
   911 Provides a reference to the session with the MTP connection assigned identifier
   893 specified in the supplied MTP dataset. 
   912 specified in the supplied MTP dataset. 
   936 Get the data receive result.
   955 Get the data receive result.
   937 @return the data recevice result.
   956 @return the data recevice result.
   938 */
   957 */
   939 EXPORT_C TInt CMTPConnection::GetDataReceiveResult() const
   958 EXPORT_C TInt CMTPConnection::GetDataReceiveResult() const
   940 	{
   959 	{
   941 	__FLOG(_L8("GetDataReceiveResult - Entry"));
   960     OstTraceFunctionEntry0( CMTPCONNECTION_GETDATARECEIVERESULT_ENTRY );
   942     __FLOG_VA((_L8("Data receive result = %d"), iDataReceiveResult));
   961     OstTrace1( TRACE_NORMAL, CMTPCONNECTION_GETDATARECEIVERESULT, "Data receive result = %d", iDataReceiveResult);
   943     __FLOG(_L8("GetDataReceiveResult - Exit"));
   962     OstTraceFunctionExit0( CMTPCONNECTION_GETDATARECEIVERESULT_EXIT );
   944     return iDataReceiveResult;
   963     return iDataReceiveResult;
   945 	}
   964 	}
   946     
   965     
   947 /**
   966 /**
   948 Sets the MTP connection state variable.
   967 Sets the MTP connection state variable.
   949 @param aState The new MTP connection state value.
   968 @param aState The new MTP connection state value.
   950 */
   969 */
   951 void CMTPConnection::SetState(TUint aState)
   970 void CMTPConnection::SetState(TUint aState)
   952     {
   971     {
   953     __FLOG(_L8("SetState - Entry"));
   972     OstTraceFunctionEntry0( CMTPCONNECTION_SETSTATE_ENTRY );   
   954     __FLOG_VA((_L8("Setting state = %d"), aState));
   973     OstTrace1( TRACE_NORMAL, CMTPCONNECTION_SETSTATE, "CMTPConnection::SetState;aState=%d", aState );
   955     iState = aState;
   974     iState = aState;
   956     __FLOG(_L8("SetState - Exit"));
   975     OstTraceFunctionExit0( CMTPCONNECTION_SETSTATE_EXIT );
   957     }
   976     }
   958   
   977   
   959     
   978     
   960 /**
   979 /**
   961 Provide the current MTP connection state.
   980 Provide the current MTP connection state.
   962 @return The current MTP connection state.
   981 @return The current MTP connection state.
   963 */
   982 */
   964 TUint CMTPConnection::State() const
   983 TUint CMTPConnection::State() const
   965     {
   984     {
   966     __FLOG(_L8("State - Entry"));
   985     OstTraceFunctionEntry0( CMTPCONNECTION_STATE_ENTRY );    
   967     __FLOG_VA((_L8("State = %d"), iState));
   986     OstTrace1( TRACE_NORMAL, CMTPCONNECTION_STATE, "State = %d", iState);
   968     __FLOG(_L8("State - Exit"));
   987     OstTraceFunctionExit0( CMTPCONNECTION_STATE_EXIT );
   969     return iState;        
   988     return iState;        
   970     }
   989     }
   971     
   990     
   972 /**
   991 /**
   973 Performs common validation processing for requests initiated from the data 
   992 Performs common validation processing for requests initiated from the data 
   984 connection.
  1003 connection.
   985 @panic CMTPConnection 2 If the MTP transaction phase is invalid.
  1004 @panic CMTPConnection 2 If the MTP transaction phase is invalid.
   986 */
  1005 */
   987 TBool CMTPConnection::ValidFrameworkRequest(CMTPSession* aSession, TUint aValidPhases, TRequestStatus* aStatus)
  1006 TBool CMTPConnection::ValidFrameworkRequest(CMTPSession* aSession, TUint aValidPhases, TRequestStatus* aStatus)
   988     {
  1007     {
   989     __FLOG(_L8("ValidFrameworkRequest - Entry"));
  1008     OstTraceFunctionEntry0( CMTPCONNECTION_VALIDFRAMEWORKREQUEST_ENTRY );
   990     __ASSERT_ALWAYS((!aSession || (aSession->TransactionPhase() & aValidPhases)), Panic(EMTPPanicInvalidState));
  1009     __ASSERT_ALWAYS((!aSession || (aSession->TransactionPhase() & aValidPhases)), Panic(EMTPPanicInvalidState));
   991     __ASSERT_ALWAYS((!aStatus || (!aSession->RequestPending())), Panic(EMTPPanicBusy));
  1010     __ASSERT_ALWAYS((!aStatus || (!aSession->RequestPending())), Panic(EMTPPanicBusy));
   992     
  1011     
   993     TBool ret(ETrue);
  1012     TBool ret(ETrue);
   994     switch (State())
  1013     switch (State())
  1020             ret = EFalse;
  1039             ret = EFalse;
  1021             }
  1040             }
  1022         break;
  1041         break;
  1023         }
  1042         }
  1024         
  1043         
  1025     __FLOG(_L8("ValidFrameworkRequest - Exit"));
  1044     OstTraceFunctionExit0( CMTPCONNECTION_VALIDFRAMEWORKREQUEST_EXIT );
  1026     return ret;
  1045     return ret;
  1027     }
  1046     }
  1028 
  1047 
  1029 void CMTPConnection::RemoveEventsForSession(TUint32 aMTPId)
  1048 void CMTPConnection::RemoveEventsForSession(TUint32 aMTPId)
  1030 	{
  1049 	{
  1031     __FLOG(_L8("RemoveEventsForSession - Entry"));
  1050     OstTraceFunctionEntry0( CMTPCONNECTION_REMOVEEVENTSFORSESSION_ENTRY );
  1032     
  1051     
  1033     TSglQueIter<CMTPEventLink> iter(iEventQ);
  1052     TSglQueIter<CMTPEventLink> iter(iEventQ);
  1034     iter.SetToFirst();
  1053     iter.SetToFirst();
  1035     CMTPEventLink* link = NULL;
  1054     CMTPEventLink* link = NULL;
  1036     
  1055     
  1040 			{
  1059 			{
  1041 			DequeueEvent(link);
  1060 			DequeueEvent(link);
  1042 			}
  1061 			}
  1043 		}
  1062 		}
  1044     
  1063     
  1045     __FLOG(_L8("RemoveEventsForSession - Exit"));
  1064 	OstTraceFunctionExit0( CMTPCONNECTION_REMOVEEVENTSFORSESSION_EXIT );
  1046 	}
  1065 	}
  1047 
  1066 
  1048 void CMTPConnection::DequeueAllEvents()
  1067 void CMTPConnection::DequeueAllEvents()
  1049 	{
  1068 	{
  1050 	TSglQueIter<CMTPEventLink> iter(iEventQ);
  1069 	TSglQueIter<CMTPEventLink> iter(iEventQ);
  1080   * This method define and attach the property for publishing connection state 
  1099   * This method define and attach the property for publishing connection state 
  1081   *  events.
  1100   *  events.
  1082   */
  1101   */
  1083 void CMTPConnection::DefineConnStatePropertyL()
  1102 void CMTPConnection::DefineConnStatePropertyL()
  1084 	{
  1103 	{
  1085 	
  1104 	OstTraceFunctionEntry0( CMTPCONNECTION_DEFINECONNSTATEPROPERTYL_ENTRY );	
  1086 	 __FLOG(_L8("DefineConnStatePropertyL - Entry"));
       
  1087 	 RProcess process;
  1105 	 RProcess process;
  1088 	 TUid tSid = process.SecureId();	
  1106 	 TUid tSid = process.SecureId();	
  1089 	//Property can read by anyone who subscribe for it.
  1107 	//Property can read by anyone who subscribe for it.
  1090 	_LIT_SECURITY_POLICY_PASS(KAllowReadAll);
  1108 	_LIT_SECURITY_POLICY_PASS(KAllowReadAll);
  1091 	_LIT_SECURITY_POLICY_S0(KAllowWrite, (TSecureId )KMTPPublishConnStateCat);
  1109 	_LIT_SECURITY_POLICY_S0(KAllowWrite, (TSecureId )KMTPPublishConnStateCat);
  1092 	
  1110 	
  1093 	TInt error = RProperty::Define(tSid, EMTPConnStateKey, RProperty::EInt, KAllowReadAll, KAllowReadAll);	
  1111 	TInt error = RProperty::Define(tSid, EMTPConnStateKey, RProperty::EInt, KAllowReadAll, KAllowReadAll);	
  1094 	if (KErrAlreadyExists != error)
  1112 	if (KErrAlreadyExists != error)
  1095 		{
  1113 		{
  1096 		User::LeaveIfError(error);
  1114         LEAVEIFERROR(error, OstTrace1(TRACE_ERROR, CMTPCONNECTION_DEFINECONNSTATEPROPERTYL, "property define error! error code %d", error));
  1097 		}
  1115 		}
  1098 	User::LeaveIfError(iProperty.Attach(tSid, EMTPConnStateKey, EOwnerThread));
  1116 	LEAVEIFERROR(iProperty.Attach(tSid, EMTPConnStateKey, EOwnerThread), 
  1099 	__FLOG(_L8("DefineConnStatePropertyL - Exit"));
  1117 	        OstTrace0(TRACE_ERROR, DUP1_CMTPCONNECTION_DEFINECONNSTATEPROPERTYL, "property attach error"));
       
  1118 	OstTraceFunctionExit0( CMTPCONNECTION_DEFINECONNSTATEPROPERTYL_EXIT );
  1100 	}
  1119 	}
  1101 
  1120 
  1102 /**
  1121 /**
  1103   * This method is to publish various connection state. 
  1122   * This method is to publish various connection state. 
  1104   */
  1123   */
  1105 void CMTPConnection::PublishConnState(TMTPConnStateType aConnState)	
  1124 void CMTPConnection::PublishConnState(TMTPConnStateType aConnState)	
  1106 	{
  1125 	{  
  1107 	__FLOG_VA((_L8("PublishConnState - Entry \n publishing state = %d"), (TInt)aConnState));
  1126     OstTraceFunctionEntry0( CMTPCONNECTION_PUBLISHCONNSTATE_ENTRY);
       
  1127 	OstTrace1( TRACE_NORMAL, CMTPCONNECTION_PUBLISHCONNSTATE, "publishing state = %d", (TInt)aConnState );
       
  1128 	
  1108 	RProcess process;    
  1129 	RProcess process;    
  1109 	TInt error = iProperty.Set(process.SecureId(), EMTPConnStateKey, (TInt)aConnState);		
  1130 	TInt error = iProperty.Set(process.SecureId(), EMTPConnStateKey, (TInt)aConnState);		
  1110 	 __ASSERT_DEBUG((error == KErrNone), Panic(EMTPPanicPublishEvent));;
  1131 	 __ASSERT_DEBUG((error == KErrNone), Panic(EMTPPanicPublishEvent));;
  1111 	__FLOG(_L8("PublishConnState - Exit"));
  1132 	 OstTraceFunctionExit0( CMTPCONNECTION_PUBLISHCONNSTATE_EXIT);
  1112 	}
  1133 	}
  1113 
  1134 
  1114 /**
  1135 /**
  1115   * This method is used to publish the events based on the TransactionPhase.
  1136   * This method is used to publish the events based on the TransactionPhase.
  1116   * 
  1137   * 
  1117   */
  1138   */
  1118 void CMTPConnection::ValidateAndPublishConnState(CMTPSession& aSession, TInt aState)
  1139 void CMTPConnection::ValidateAndPublishConnState(CMTPSession& aSession, TInt aState)
  1119 	{	
  1140 	{	
  1120     	__FLOG_VA((_L8("ValidateAndPublishConnState - Entry \n publishing state = %d"), aState));
  1141     OstTraceFunctionEntry0(CMTPCONNECTION_VALIDATEANDPUBLISHCONNSTATE_ENTRY);
  1121 
  1142     OstTrace1( TRACE_NORMAL, CMTPCONNECTION_VALIDATEANDPUBLISHCONNSTATE, "publishing state = %d", aState );
       
  1143     	
  1122 	TMTPConnStateType conState = EConnectedToHost;
  1144 	TMTPConnStateType conState = EConnectedToHost;
  1123 	switch((TStates)aState)
  1145 	switch((TStates)aState)
  1124 		{
  1146 		{
  1125 		  case EStateOpen:
  1147 		  case EStateOpen:
  1126 		  	{
  1148 		  	{
  1156 		  default:
  1178 		  default:
  1157 		  	conState = EConnectedToHost;
  1179 		  	conState = EConnectedToHost;
  1158 		  break;
  1180 		  break;
  1159 		}
  1181 		}
  1160 	PublishConnState(conState);
  1182 	PublishConnState(conState);
  1161 	__FLOG(_L8("ValidateAndPublishConnStateL - Exit"));
  1183 	OstTraceFunctionExit0(CMTPCONNECTION_VALIDATEANDPUBLISHCONNSTATE_EXIT);
  1162 	}
  1184 	}
  1163 
  1185 
  1164 void CMTPConnection::DisconnectionNotifyL()
  1186 void CMTPConnection::DisconnectionNotifyL()
  1165 	{
  1187 	{
  1166 	iSingletons.DpController().NotifyDataProvidersL(EMTPDisconnected,this);	
  1188 	iSingletons.DpController().NotifyDataProvidersL(EMTPDisconnected,this);