bluetoothengine/btnotif/src/BTNInquiAO.cpp
branchRCL_3
changeset 35 95674584745d
parent 20 2f88a7d66f50
equal deleted inserted replaced
21:53b7818cd282 35:95674584745d
    64         {
    64         {
    65         action = KHostResInquiry + KHostResEir + KHostResIgnoreCache;
    65         action = KHostResInquiry + KHostResEir + KHostResIgnoreCache;
    66         }
    66         }
    67     else
    67     else
    68         {
    68         {
    69         if( iIndex < iDevsWithoutName.Count() )
    69         TInt firstPartialNameDevIndex;
    70             {
    70         if (HaveDevsWithPartialName(firstPartialNameDevIndex))
       
    71             {
       
    72             FTRACE(FPrint(_L("[BTNOTIF]\t CBTInqUI::IssueRequestL() looking up device index %d (have partial name already)"), firstPartialNameDevIndex));
       
    73 
    71             action = KHostResName + KHostResIgnoreCache;
    74             action = KHostResName + KHostResIgnoreCache;
    72             TInquirySockAddr& sa = TInquirySockAddr::Cast( iDevsWithoutName[iIndex].iAddr );
    75             TInquirySockAddr sa;
       
    76             sa.SetBTAddr(iLastSeenDevicesArray->At(firstPartialNameDevIndex)->BDAddr());
       
    77             iInquirySockAddr.SetBTAddr( sa.BTAddr() );            
       
    78             }
       
    79         else if( iCurrentlyResolvingUnnamedDeviceIndex < iDevsWithoutName.Count() )
       
    80             {
       
    81             FTRACE(FPrint(_L("[BTNOTIF]\t CBTInqUI::IssueRequestL() looking up device index %d (currently anonymous)"), iCurrentlyResolvingUnnamedDeviceIndex));
       
    82 
       
    83             action = KHostResName + KHostResIgnoreCache;
       
    84             TInquirySockAddr& sa = TInquirySockAddr::Cast( iDevsWithoutName[iCurrentlyResolvingUnnamedDeviceIndex].iAddr );
    73             iInquirySockAddr.SetBTAddr( sa.BTAddr() );            
    85             iInquirySockAddr.SetBTAddr( sa.BTAddr() );            
    74             }
    86             }
    75         }
    87         }
    76     if (action)
    88     if (action)
    77         {
    89         {
    82         }
    94         }
    83     else
    95     else
    84         {
    96         {
    85         FLOG(_L("[BTNOTIF]\t CBTInqUI::RunL() All name inquiries complete ."));
    97         FLOG(_L("[BTNOTIF]\t CBTInqUI::RunL() All name inquiries complete ."));
    86         iPageForName = EFalse;
    98         iPageForName = EFalse;
    87         iIndex = 0;
    99         iCurrentlyResolvingUnnamedDeviceIndex = 0;
    88         InquiryComplete( KErrNone );
   100         InquiryComplete( KErrNone );
    89         }
   101         }
    90     FLOG(_L("[BTNOTIF]\t CBTInqUI::IssueRequestL() completed"));
   102     FLOG(_L("[BTNOTIF]\t CBTInqUI::IssueRequestL() completed"));
    91     }
   103     }
    92 
   104 
    99 void CBTInqUI::RequestCompletedL( CBTNotifActive* aActive, TInt aId, TInt aStatus )
   111 void CBTInqUI::RequestCompletedL( CBTNotifActive* aActive, TInt aId, TInt aStatus )
   100     {
   112     {
   101     FTRACE(FPrint(_L("[BTNOTIF]\t CBTInqUI::RequestCompletedL() status: %d >>"), aStatus ));
   113     FTRACE(FPrint(_L("[BTNOTIF]\t CBTInqUI::RequestCompletedL() status: %d >>"), aStatus ));
   102     ASSERT( aId == KBTNotifInquiryNotifierReq);
   114     ASSERT( aId == KBTNotifInquiryNotifierReq);
   103     (void) aActive;
   115     (void) aActive;
   104     
   116 
       
   117     TInt firstPartialNameDevIndex = -1;
       
   118     const TBool haveDevsWithPartialName = HaveDevsWithPartialName(firstPartialNameDevIndex);
       
   119 
   105     if( aStatus == KErrNone )
   120     if( aStatus == KErrNone )
   106         {
   121         {
   107         if( iPageForName )
   122         if( iPageForName )
   108             {
   123             {
   109             HandleFoundNameL();
   124             FLOG(_L("[BTNOTIF]\t CBTInqUI::RequestCompletedL() in name request state."));
   110             iIndex++;
   125 
       
   126             if (haveDevsWithPartialName)
       
   127                 {
       
   128                 // We resolve names in chronological order so it must be the first device
       
   129                 // with an incomplete name we can find on the last seen list.
       
   130                 HandleUpdatedNameL(firstPartialNameDevIndex);
       
   131                 }
       
   132             else
       
   133                 {
       
   134                 // Must be the current index in iDevsWithoutName.
       
   135                 HandleFoundNameL();
       
   136                 iCurrentlyResolvingUnnamedDeviceIndex++;
       
   137                 }
   111             IssueRequestL();
   138             IssueRequestL();
   112             }
   139             }
   113         else
   140         else
   114             {
   141             {
   115             HandleInquiryDeviceL();
   142             HandleInquiryDeviceL();
   118             }
   145             }
   119         }
   146         }
   120     else if( aStatus == (KHCIErrorBase - EPageTimedOut) && iPageForName )
   147     else if( aStatus == (KHCIErrorBase - EPageTimedOut) && iPageForName )
   121         {
   148         {
   122         FLOG(_L("[BTNOTIF]\t CBTInqUI::RequestCompletedL() HCI:EPageTimeOut, page next one."));
   149         FLOG(_L("[BTNOTIF]\t CBTInqUI::RequestCompletedL() HCI:EPageTimeOut, page next one."));
   123         iIndex++;
   150         if (haveDevsWithPartialName)
       
   151             {
       
   152             // A device with incomplete name has probably gone out of range. Just removing
       
   153             // it from the UI may be a bit confusing, so let's just update its RSSI indicator
       
   154             // to minimum.
       
   155             PageTimeoutOnDeviceWithPartialNameL(firstPartialNameDevIndex);
       
   156             }
       
   157         else
       
   158             {
       
   159             iCurrentlyResolvingUnnamedDeviceIndex++;            
       
   160             }
   124         IssueRequestL();
   161         IssueRequestL();
   125         }
   162         }
   126     else
   163     else
   127         {
   164         {
   128         if( !iPageForName && iDevsWithoutName.Count()>0 )
   165         if( !iPageForName && (iDevsWithoutName.Count() > 0 || haveDevsWithPartialName) )
   129             {
   166             {
   130             FTRACE(FPrint(_L("[BTNOTIF]\t CBTInqUI::RequestCompletedL() nameless devices %d, paging for name."), 
   167             FTRACE(FPrint(_L("[BTNOTIF]\t CBTInqUI::RequestCompletedL() have devs with incomplete name = %d, nameless devices %d, paging for name."), 
   131                     iDevsWithoutName.Count() ));
   168                     haveDevsWithPartialName, iDevsWithoutName.Count() ));
   132             iIndex = 0;
   169             iCurrentlyResolvingUnnamedDeviceIndex = 0;
   133             iPageForName = ETrue;
   170             iPageForName = ETrue;
   134             IssueRequestL();
   171             IssueRequestL();
   135             }
   172             }
   136         else
   173         else
   137             {
   174             {
   186     TBuf<12> devAddrString;
   223     TBuf<12> devAddrString;
   187     sa.BTAddr().GetReadable(devAddrString);
   224     sa.BTAddr().GetReadable(devAddrString);
   188     FTRACE(FPrint(_L("[BTNOTIF]\t BT Address: %S"), &devAddrString));
   225     FTRACE(FPrint(_L("[BTNOTIF]\t BT Address: %S"), &devAddrString));
   189 #endif
   226 #endif
   190         TBTDeviceName devName;
   227         TBTDeviceName devName;
   191         TBool nameGotten = CheckEirDeviceName( iEntry, devName );
   228         TBool isNameComplete(EFalse);
   192         FTRACE(FPrint(_L("[BTNOTIF]\t CBTInqUI::HandleInquiryDeviceL() EIR device name? %d, %S"), nameGotten, &devName ));
   229         TBool nameGotten = CheckEirDeviceName( iEntry, devName, isNameComplete );
       
   230         FTRACE(FPrint(_L("[BTNOTIF]\t CBTInqUI::HandleInquiryDeviceL() EIR device name? %d, %S, complete = %d"), nameGotten, &devName, isNameComplete ));
   193         if( nameGotten )
   231         if( nameGotten )
   194             {
   232             {
   195             DeviceAvailableL( iEntry(), devName );
   233             DeviceAvailableL( iEntry(), devName, isNameComplete );
   196             }
   234             }
   197         else
   235         else
   198             {
   236             {
   199             iDevsWithoutName.Append( iEntry() );
   237             iDevsWithoutName.AppendL( iEntry() );
   200             }
   238             }
   201         }
   239         }
   202     }
   240     }
   203 
   241 
   204 // ----------------------------------------------------------
   242 // ----------------------------------------------------------
   215     FTRACE(FPrint(_L("[BTNOTIF]\t CBTInqUI::HandleFoundNameL() BT Address: %S"), &devAddrString));
   253     FTRACE(FPrint(_L("[BTNOTIF]\t CBTInqUI::HandleFoundNameL() BT Address: %S"), &devAddrString));
   216 #endif
   254 #endif
   217     if( iEntry().iName != KNullDesC )
   255     if( iEntry().iName != KNullDesC )
   218         {
   256         {
   219         FTRACE(FPrint(_L("[BTNOTIF]\t CBTInqUI::HandleFoundNameL() Name found: %S"), &(iEntry().iName) ));
   257         FTRACE(FPrint(_L("[BTNOTIF]\t CBTInqUI::HandleFoundNameL() Name found: %S"), &(iEntry().iName) ));
   220 
   258         DeviceAvailableL( iDevsWithoutName[iCurrentlyResolvingUnnamedDeviceIndex], iEntry().iName, ETrue );
   221         DeviceAvailableL( iDevsWithoutName[iIndex], iEntry().iName );
   259         }
   222         }
   260 
   223     
       
   224     FLOG(_L("[BTNOTIF]\t CBTInqUI::HandleFoundNameL() Complete"));
   261     FLOG(_L("[BTNOTIF]\t CBTInqUI::HandleFoundNameL() Complete"));
   225     }
   262     }
       
   263 
       
   264 void CBTInqUI::HandleUpdatedNameL(TInt aLastSeenIndex)
       
   265     {
       
   266 #ifdef _DEBUG
       
   267     TBuf<12> devAddrString;
       
   268     TInquirySockAddr& sa = TInquirySockAddr::Cast( iEntry().iAddr );
       
   269     sa.BTAddr().GetReadable(devAddrString);
       
   270     FTRACE(FPrint(_L("[BTNOTIF]\t CBTInqUI::HandleUpdatedNameL() BT Address: %S"), &devAddrString));
       
   271 #endif
       
   272     iLastSeenDevicesNameComplete[aLastSeenIndex] = ETrue;
       
   273     if( iEntry().iName != KNullDesC )
       
   274         {
       
   275         DeviceNameUpdatedL(iEntry(), aLastSeenIndex);
       
   276         }
       
   277 
       
   278     FTRACE(FPrint(_L("[BTNOTIF]\t CBTInqUI::HandleUpdatedNameL() Complete")));
       
   279     }
       
   280 
   226 
   281 
   227 // ----------------------------------------------------------
   282 // ----------------------------------------------------------
   228 // CBTInqUI::CheckEirDeviceName
   283 // CBTInqUI::CheckEirDeviceName
   229 // Check if the retrieved the device info contains device name.  
   284 // Check if the retrieved the device info contains device name.  
   230 // ----------------------------------------------------------
   285 // ----------------------------------------------------------
   231 //
   286 //
   232 TBool CBTInqUI::CheckEirDeviceName( TNameEntry& aEntry, TBTDeviceName& aName )
   287 TBool CBTInqUI::CheckEirDeviceName( TNameEntry& aEntry, TBTDeviceName& aName, TBool& aIsComplete )
   233     {
   288     {
   234     TBluetoothNameRecordWrapper eir( aEntry() );
   289     TBluetoothNameRecordWrapper eir( aEntry() );
   235     TInt length = eir.GetDeviceNameLength();
   290     TInt length = eir.GetDeviceNameLength();
   236     
   291 
   237     TBool isComplete( EFalse );
       
   238     TInt err( KErrNone );
   292     TInt err( KErrNone );
   239         
   293 
   240     if( length > 0 )
   294     if( length > 0 )
   241         {            
   295         {            
   242         err = eir.GetDeviceName( aName, isComplete);
   296         err = eir.GetDeviceName( aName, aIsComplete);
   243         return (!err);
   297         return (!err);
   244         }
   298         }
   245     return EFalse;
   299     return EFalse;
   246     }
   300     }
   247 // End of File
   301 // End of File