mtpfws/mtpfw/src/cmtpconnection.cpp
changeset 38 48c22c726cf9
parent 22 a5c0bb5018eb
child 47 63cf70d3ecd8
equal deleted inserted replaced
33:883e91c086aa 38:48c22c726cf9
    80 CMTPConnection::~CMTPConnection()
    80 CMTPConnection::~CMTPConnection()
    81     {
    81     {
    82     __FLOG(_L8("~CMTPConnection - Entry"));
    82     __FLOG(_L8("~CMTPConnection - Entry"));
    83     CloseAllSessions();
    83     CloseAllSessions();
    84     
    84     
    85     // Remove any events not associated 
    85 	//remove all events
    86     // with a session
    86     DequeueAllEvents();
    87     TSglQueIter<CMTPEventLink> iter(iEventQ);
    87 	
    88     iter.SetToFirst();
       
    89     CMTPEventLink* link = NULL;
       
    90     
       
    91     while ((link = iter++) != NULL)
       
    92     	{
       
    93     	delete link;
       
    94     	}
       
    95     
       
    96     iSessions.ResetAndDestroy();
    88     iSessions.ResetAndDestroy();
       
    89     
       
    90     if (iTransportConnection != NULL)
       
    91         {
       
    92         iTransportConnection->Unbind(*this);
       
    93         }
       
    94     
    97     //close the property
    95     //close the property
    98     iProperty.Close();
    96     iProperty.Close();
    99     // delete the ‘name?property
    97     // delete the ‘name?property
   100     RProcess process;
    98     RProcess process;
   101     RProperty::Delete(process.SecureId(), EMTPConnStateKey);
    99     RProperty::Delete(process.SecureId(), EMTPConnStateKey);
   355         if (ActiveSessions() == 0 || currentState == EStateErrorShutdown)
   353         if (ActiveSessions() == 0 || currentState == EStateErrorShutdown)
   356             {
   354             {
   357             CompleteCloseConnection();
   355             CompleteCloseConnection();
   358             ret = ETrue;
   356             ret = ETrue;
   359             }
   357             }
   360         
   358           
   361         SetState(EStateShutdown);
   359         SetState(EStateShutdown);
   362         PublishConnState(EDisconnectedFromHost);   
   360         PublishConnState(EDisconnectedFromHost);   
   363         }
   361         }
   364     
   362     
   365     __FLOG(_L8("ConnectionSuspended - Exit"));
   363     __FLOG(_L8("ConnectionSuspended - Exit"));
   370     {
   368     {
   371     __FLOG(_L8("CompleteCloseConnection - Entry"));
   369     __FLOG(_L8("CompleteCloseConnection - Entry"));
   372     
   370     
   373     CloseAllSessions();
   371     CloseAllSessions();
   374     iSessions.Reset();
   372     iSessions.Reset();
   375 	if (iTransportConnection != NULL)
       
   376 		{
       
   377 		iTransportConnection->Unbind(*this);
       
   378 		}
       
   379     
   373     
   380     //notify ConnectionMgr and corresponding transports of completion of connection close
   374     //notify ConnectionMgr and corresponding transports of completion of connection close
   381     iSingletons.ConnectionMgr().ConnectionCloseComplete(iConnectionId);    
   375     iSingletons.ConnectionMgr().ConnectionCloseComplete(iConnectionId);    
   382     iSingletons.Close();
   376     iSingletons.Close();
   383 
   377 
   403         Create the null session object which owns the transaction state for 
   397         Create the null session object which owns the transaction state for 
   404         transaction occuring outside a session (i.e. with SessionID == 0x00000000)
   398         transaction occuring outside a session (i.e. with SessionID == 0x00000000)
   405         */
   399         */
   406         SessionOpenedL(KMTPSessionNone);            
   400         SessionOpenedL(KMTPSessionNone);            
   407         
   401         
       
   402         if (iTransportConnection != NULL)
       
   403             {
       
   404             iTransportConnection->Unbind(*this);
       
   405             }
   408         iTransportConnection = &aTransportConnection;
   406         iTransportConnection = &aTransportConnection;
   409         iTransportConnection->BindL(*this); 
   407         iTransportConnection->BindL(*this);
   410         SetState(EStateOpen); 
   408         SetState(EStateOpen); 
   411          
   409          
   412         }
   410         }
   413     
   411     
   414     __FLOG(_L8("ConnectionResumed - Exit"));
   412     __FLOG(_L8("ConnectionResumed - Exit"));
   659         }
   657         }
   660     // Dequeue first since the code below might leave.
   658     // Dequeue first since the code below might leave.
   661     DequeueEvent(iEventQ.First());       
   659     DequeueEvent(iEventQ.First());       
   662    	if (iPendingEventCount > 0)
   660    	if (iPendingEventCount > 0)
   663    		{
   661    		{
   664    		// Forward the event to the transport connection layer.
   662 		if (NULL != iTransportConnection)
   665    		__FLOG(_L8("Sending queued event"));
   663 			{
   666  	    iTransportConnection->SendEventL(iEventQ.First()->iEvent);
   664 			// Forward the event to the transport connection layer.
       
   665 			__FLOG(_L8("Sending queued event"));
       
   666 			iTransportConnection->SendEventL(iEventQ.First()->iEvent);
       
   667 			}
       
   668 		else
       
   669 			{
       
   670 			DequeueAllEvents();
       
   671 			}
   667    		}
   672    		}
   668     
   673     
   669     __FLOG(_L8("SendEventCompleteL - Exit"));
   674     __FLOG(_L8("SendEventCompleteL - Exit"));
   670     }
   675     }
   671 
   676 
   705 CMTPConnection::CMTPConnection(TUint aConnectionId, MMTPTransportConnection& aTransportConnection) :
   710 CMTPConnection::CMTPConnection(TUint aConnectionId, MMTPTransportConnection& aTransportConnection) :
   706     iConnectionId(aConnectionId),
   711     iConnectionId(aConnectionId),
   707     iEventQ(_FOFF(CMTPEventLink, iLink)),
   712     iEventQ(_FOFF(CMTPEventLink, iLink)),
   708     iTransportConnection(&aTransportConnection)
   713     iTransportConnection(&aTransportConnection)
   709     {
   714     {
   710     
   715     iTransportConnection->BindL(*this);
   711     }
   716     }
   712     
   717     
   713 /**
   718 /**
   714 Second phase constructor.
   719 Second phase constructor.
   715 @leave One of the system wide error code, if a processing failure occurs.
   720 @leave One of the system wide error code, if a processing failure occurs.
  1038 		}
  1043 		}
  1039     
  1044     
  1040     __FLOG(_L8("RemoveEventsForSession - Exit"));
  1045     __FLOG(_L8("RemoveEventsForSession - Exit"));
  1041 	}
  1046 	}
  1042 
  1047 
       
  1048 void CMTPConnection::DequeueAllEvents()
       
  1049 	{
       
  1050 	TSglQueIter<CMTPEventLink> iter(iEventQ);
       
  1051     iter.SetToFirst();
       
  1052     CMTPEventLink* link = NULL;
       
  1053     
       
  1054     while ((link = iter++) != NULL)
       
  1055     	{
       
  1056     	delete link;
       
  1057     	}
       
  1058 	iPendingEventCount = 0;
       
  1059 	}
       
  1060 	
  1043 void CMTPConnection::DequeueEvent(CMTPEventLink* aLink)
  1061 void CMTPConnection::DequeueEvent(CMTPEventLink* aLink)
  1044 	{
  1062 	{
  1045 	iEventQ.Remove(*aLink);
  1063 	iEventQ.Remove(*aLink);
  1046 	delete aLink;
  1064 	delete aLink;
  1047 	--iPendingEventCount;	
  1065 	--iPendingEventCount;