bluetoothengine/bthid/bthidserver/src/bthidconnection.cpp
branchRCL_3
changeset 11 a42ed326b458
parent 0 f63038272f30
equal deleted inserted replaced
10:0707dd69d236 11:a42ed326b458
   101 
   101 
   102 void CBTHidConnection::SetConnID(TInt aConnID)
   102 void CBTHidConnection::SetConnID(TInt aConnID)
   103     {
   103     {
   104     // We shouldn't be trying to set the id for this connection
   104     // We shouldn't be trying to set the id for this connection
   105     // after it is connected.
   105     // after it is connected.
   106     __ASSERT_DEBUG(iConnectionState == ENotConnected || iConnectionState == EConnecting,
   106     __ASSERT_DEBUG(iConnectionState == ENotConnected || 
       
   107 	               iConnectionState == EConnecting   || 
       
   108 				   iConnectionState == EHIDInitConnecting ,
   107             User::Panic(KPanicBTConnection, ESocketsBadState));
   109             User::Panic(KPanicBTConnection, ESocketsBadState));
   108 
   110 
   109     iConnID = aConnID;
   111     iConnID = aConnID;
   110     }
   112     }
   111 
   113 
   212     {
   214     {
   213         TRACE_FUNC
   215         TRACE_FUNC
   214     (_L("[BTHID]\tCBTHidConnection::OfferControlSocket"));
   216     (_L("[BTHID]\tCBTHidConnection::OfferControlSocket"));
   215     if (aAddress == iDevice->iAddress)
   217     if (aAddress == iDevice->iAddress)
   216         {
   218         {
   217         __ASSERT_DEBUG((iConnectionState == ELinkLost) ||
   219         __ASSERT_DEBUG((iConnectionState == ELinkLost) || (iConnectionState == EHIDInitConnecting) ||
   218                 (iConnectionState == EHIDReconnecting),
   220                 (iConnectionState == EHIDReconnecting),
   219                 User::Panic(KPanicBTConnection, ESocketsBadState));
   221                 User::Panic(KPanicBTConnection, ESocketsBadState));
   220 
   222 
   221         // Take ownership of this socket
   223         // Take ownership of this socket
   222         delete iControlSocket;
   224         delete iControlSocket;
   223         iControlSocket = aSocket;
   225         iControlSocket = aSocket;
   224         aSocket = 0;
   226         aSocket = 0;
   225 
   227 
   226         // Mark that the HID Device is reconnecting to us.
   228         // Mark that the HID Device is reconnecting to us. Skip the state change if an initial connection from HID device. 
   227         ChangeState(EHIDReconnecting);
   229         if (iConnectionState != EHIDInitConnecting) 
       
   230             {
       
   231             ChangeState(EHIDReconnecting);
       
   232             }
   228         }
   233         }
   229     }
   234     }
   230 
   235 
   231 void CBTHidConnection::OfferInterruptSocket(const TBTDevAddr& aAddress,
   236 void CBTHidConnection::OfferInterruptSocket(const TBTDevAddr& aAddress,
   232         RSocket*& aSocket)
   237         RSocket*& aSocket)
   234         TRACE_FUNC
   239         TRACE_FUNC
   235     (_L("[BTHID]\tCBTHidConnection::OfferInterruptSocket"));
   240     (_L("[BTHID]\tCBTHidConnection::OfferInterruptSocket"));
   236 
   241 
   237     if (aAddress == iDevice->iAddress)
   242     if (aAddress == iDevice->iAddress)
   238         {
   243         {
   239         __ASSERT_DEBUG((iConnectionState == EHIDReconnecting), //||(iConnectionState == ELinkLost) ,
   244         __ASSERT_DEBUG((iConnectionState == EHIDReconnecting) ||(iConnectionState == EHIDInitConnecting) ,
   240                 User::Panic(KPanicBTConnection, ESocketsBadState));
   245                 User::Panic(KPanicBTConnection, ESocketsBadState));
   241 
   246 
   242         // Take ownership of this socket
   247         // Take ownership of this socket
   243         delete iInterruptSocket;
   248         delete iInterruptSocket;
   244         iInterruptSocket = aSocket;
   249         iInterruptSocket = aSocket;
   246         TRAPD(error, PrepareSocketsL());
   251         TRAPD(error, PrepareSocketsL());
   247 
   252 
   248         if (KErrNone == error)
   253         if (KErrNone == error)
   249             {
   254             {
   250             // Mark that we are now reconnected.
   255             // Mark that we are now reconnected.
   251 
   256             TBTConnectionState prevState = iConnectionState; 
   252             ChangeState(EConnected);
   257             ChangeState(EConnected);
   253 
   258 
   254             // Inform the observer that the connection has been restored.
   259             if (prevState == EHIDInitConnecting)
   255             iObserver.LinkRestored(iConnID);
   260                 {
   256 
   261                 // If this was an remote HID initial connection, start the SDP Search. 
       
   262                 iObserver.StartSDPSearch(iConnID);
       
   263                 }
       
   264             else
       
   265                 {
       
   266                 // Inform the observer that the connection has been restored.
       
   267                 iObserver.LinkRestored(iConnID);
       
   268                 }
   257             }
   269             }
   258         else
   270         else
   259             {
   271             {
   260             // Close the sockets as they can't be used
   272             // Close the sockets as they can't be used
   261             CloseChannels();
   273             CloseChannels();
   262             ChangeState(ELinkLost);
   274            
       
   275             if (iConnectionState == EHIDInitConnecting)
       
   276                 {
       
   277                  ChangeState(ENotConnected);
       
   278                 // If this was an remote HID initial connection inform the observer
       
   279                 iObserver.FirstTimeConnectionCompleteFromRemote(iConnID, error);
       
   280                 }
       
   281             else
       
   282                 {
       
   283                 ChangeState(ELinkLost);
       
   284                 }
   263             }
   285             }
   264         }
   286         }
   265     }
   287     }
   266 
   288 
   267 CBTHidDevice& CBTHidConnection::DeviceDetails()
   289 CBTHidDevice& CBTHidConnection::DeviceDetails()