bluetoothengine/btui/devmodel/src/btpairedmodel.cpp
branchRCL_3
changeset 72 4b59561a31c0
parent 56 9386f31cc85b
equal deleted inserted replaced
64:1934667b0e2b 72:4b59561a31c0
    57     {
    57     {
    58 	TRACE_FUNC_ENTRY    
    58 	TRACE_FUNC_ENTRY    
    59 	
    59 	
    60     delete iConnMan;
    60     delete iConnMan;
    61     delete iPairingDevice;
    61     delete iPairingDevice;
       
    62     delete iDisconnectDevice;
    62     delete iLinks;
    63     delete iLinks;
    63     delete iBtEngSettings;
    64     delete iBtEngSettings;
    64     iSocketServ.Close();    
    65     iSocketServ.Close();    
    65     
    66     
    66     TRACE_FUNC_EXIT    
    67     TRACE_FUNC_EXIT    
   129     // disconnect device to be unpaired, or blocked
   130     // disconnect device to be unpaired, or blocked
   130     if((aDevice.iOperation == EOpBlock || aDevice.iOperation == EOpUnpair ))
   131     if((aDevice.iOperation == EOpBlock || aDevice.iOperation == EOpUnpair ))
   131     	{    	
   132     	{    	
   132     	if( iState != EDisconnectBeforeOperationState)
   133     	if( iState != EDisconnectBeforeOperationState)
   133     		{
   134     		{
   134     			// disconnect by CBTEngConnMan if connected that way.
   135             TInt code = KErrNone;
   135     			if (aDevice.iStatus & static_cast<TInt>(EStatusBtuiConnected ) )
   136             iState=EDisconnectBeforeOperationState;
   136     				{
   137             __ASSERT_DEBUG(iDisconnectDevice == NULL,PANIC(EBTPanicClassMemberVariableNotNull));
   137     				TInt code=KErrNone;
   138             iDisconnectDevice = new TBTDevice(aDevice);   				
   138 		    		TRAPD(err,
   139 
   139 		    		iState=EDisconnectBeforeOperationState;
   140             if( iDisconnectDevice )
   140 			    		iDisconnectDevice=new(ELeave) TBTDevice(aDevice);
   141                 {
   141 			    		code=iConnMan->Disconnect(aDevice.iAddr,EBTDiscImmediate);    				
   142                 // disconnect by CBTEngConnMan if connected that way.
   142 			    		);
   143                 if ( aDevice.iStatus & static_cast<TInt>(EStatusBtuiConnected ) )
   143 					// if the return code is KErrNone then there will be
   144                     {
   144 					// a callback. However if it fails, there will not be any.
   145                     code = iConnMan->Disconnect(aDevice.iAddr,EBTDiscImmediate);    				
   145 					// So the execution will go on inside this method, if there was an error.
   146                     }
   146 					if(err == KErrNone && code==KErrNone )
   147                 else // try disconnecting from the link layer
   147 						{
   148                     {
   148 						return KErrNone;
   149                     code = iLinks->Disconnect(aDevice.iAddr);
   149 						}
   150                     }
   150 						
   151                 }
   151     				}
   152             else 
   152     			else // try disconnecting from the link layer
   153                 {
   153     				{
   154                 code = KErrNoMemory;
   154     				TInt code=KErrNone;
   155                 }
   155     				TRAPD(err,
   156             // if the return code is KErrNone then there will be
   156 					iState=EDisconnectBeforeOperationState;
   157             // a callback. However if it fails, there will not be any.
   157 						iDisconnectDevice=new(ELeave) TBTDevice(aDevice);
   158             // So the execution will go on inside this method, if there was an error.
   158 						code=iLinks->Disconnect(aDevice.iAddr);
   159             if( code == KErrNone )
   159 						);
   160                 {
   160 					// if the return code is KErrNone then there will be
   161                 return code;
   161 					// a callback. However if it fails, there will not be any.
   162                 }
   162 					// So the execution will go on inside this method, if there was an error.
   163             else
   163 					if(err == KErrNone && code==KErrNone )
   164                 {
   164 						{
   165                 // Reset the state if error happened
   165 						return KErrNone;
   166                 TRACE_INFO((_L("[BTUI] CBTPairedModel::DoChangeDeviceL disconnect error = %d, operation %d"), code, aDevice.iOperation));
   166 						}
   167                 delete iDisconnectDevice;
   167     				}
   168                 iDisconnectDevice = NULL;
   168     		}
   169                 iState = EIdleState; 
   169    		else    
   170                 }
   170 			iState=EIdleState;
   171             }
   171     
       
   172     	}
   172     	}
       
   173     else
       
   174         {
       
   175         iState=EIdleState;
       
   176         }
   173     	
   177     	
   174     if(	aDevice.iOperation ==EOpPair)
   178     if(	aDevice.iOperation ==EOpPair)
   175     	{
   179     	{
   176     	DoPairDeviceL();
   180     	DoPairDeviceL();
   177     	TRACE_FUNC_EXIT 
   181     	TRACE_FUNC_EXIT 
   178     	return KErrNone;    	
   182     	return KErrNone;    	
   179     	}
   183     	}
   180     
   184     
   181     TInt err = CBTDevModelBase::DoChangeDeviceL(aDevice);
   185     TInt err = CBTDevModelBase::DoChangeDeviceL(aDevice);
   182     if(iDisconnectDevice!= NULL)
   186        
   183     	{
       
   184     	delete iDisconnectDevice;
       
   185     	iDisconnectDevice=NULL;
       
   186     	}
       
   187     
       
   188     if (err != KErrNone)
   187     if (err != KErrNone)
   189         {      
   188         {      
   190         TBTDevAddr addr;
   189         TBTDevAddr addr;
   191         if(aDevice.iAddr == KNullAddress )
   190         if(aDevice.iAddr == KNullAddress )
   192         	{        	        	
   191         	{        	        	
   205                 err = iConnMan->Connect(addr, aDevice.iDeviceClass);
   204                 err = iConnMan->Connect(addr, aDevice.iDeviceClass);
   206                 break;
   205                 break;
   207             	}
   206             	}
   208             case EOpDisconnect:
   207             case EOpDisconnect:
   209             	{
   208             	{
       
   209                 __ASSERT_DEBUG(iDisconnectDevice == NULL,PANIC(EBTPanicClassMemberVariableNotNull));
   210             	iDisconnectDevice=new(ELeave) TBTDevice(aDevice);            		            		           	
   210             	iDisconnectDevice=new(ELeave) TBTDevice(aDevice);            		            		           	
   211 				if (aDevice.iStatus & static_cast<TInt>(EStatusBtuiConnected ) )            	
   211 				if (aDevice.iStatus & static_cast<TInt>(EStatusBtuiConnected ) )            	
   212 					{
   212 					{
   213 					err = iConnMan->Disconnect(addr, EBTDiscImmediate);	
   213 					err = iConnMan->Disconnect(addr, EBTDiscImmediate);	
   214 					}
   214 					}
   215 				else
   215 				else
   216 					{
   216 					{
   217 					err=iLinks->Disconnect(aDevice.iAddr);
   217 					err=iLinks->Disconnect(aDevice.iAddr);
   218 					}
   218 					}
   219                 
   219                 // Reset the state if error happened
       
   220 				if( err )
       
   221 				    {
       
   222                     TRACE_INFO((_L("[BTUI] CBTPairedModel::DoChangeDeviceL disconnect error = %d, operation %d"), err, aDevice.iOperation));
       
   223                     delete iDisconnectDevice;
       
   224                     iDisconnectDevice = NULL;
       
   225                     iState = EIdleState;
       
   226 				    }
   220                 break;
   227                 break;
   221             	}
   228             	}
   222             default:
   229             default:
   223             	User::Leave(err);
   230             	User::Leave(err);
   224                 break;
   231                 break;