bluetoothengine/btnotif/btnotifsrv/src/btnotifdeviceselector.cpp
changeset 42 b72428996822
parent 31 a0ea99b6fa53
child 47 9e2a905b887f
equal deleted inserted replaced
32:19bd632b5100 42:b72428996822
    24 #include "btnotifdeviceselector.h"
    24 #include "btnotifdeviceselector.h"
    25 
    25 
    26 #include "btnotifserver.h"
    26 #include "btnotifserver.h"
    27 #include "btnotificationmanager.h"
    27 #include "btnotificationmanager.h"
    28 #include "btnotifclientserver.h"
    28 #include "btnotifclientserver.h"
       
    29 // Key description length
       
    30 const TInt KMaxKeyDesCLength  = 20;
    29 
    31 
    30 // ======== MEMBER FUNCTIONS ========
    32 // ======== MEMBER FUNCTIONS ========
    31 
    33 
    32 // ---------------------------------------------------------------------------
    34 // ---------------------------------------------------------------------------
    33 // C++ default constructor
    35 // C++ default constructor
   185                 {
   187                 {
   186                 devParams().SetDeviceAddress( iDevices[val]->Addr() );
   188                 devParams().SetDeviceAddress( iDevices[val]->Addr() );
   187                 devParams().SetDeviceClass(iDevices[val]->Device().DeviceClass());
   189                 devParams().SetDeviceClass(iDevices[val]->Device().DeviceClass());
   188                 devParams().SetDeviceName(iDevices[val]->Alias());
   190                 devParams().SetDeviceName(iDevices[val]->Alias());
   189                 err = iMessage.Write( EBTNotifSrvReplySlot, devParams );
   191                 err = iMessage.Write( EBTNotifSrvReplySlot, devParams );
       
   192                 iNotification->RemoveObserver();
   190                 iNotification->Close(); // Also dequeues the notification from the queue.
   193                 iNotification->Close(); // Also dequeues the notification from the queue.
   191                 iNotification->RemoveObserver();
       
   192                 iNotification = NULL;                
   194                 iNotification = NULL;                
   193                 }
   195                 }
   194             iMessage.Complete( err );
   196             iMessage.Complete( err );
   195             }
   197             }
   196         iDiscoverer->CancelDiscovery();
   198         iDiscoverer->CancelDiscovery();
   206         TRAP_IGNORE( iDiscoverer->DiscoverDeviceL() );
   208         TRAP_IGNORE( iDiscoverer->DiscoverDeviceL() );
   207         
   209         
   208         }
   210         }
   209     else if(aData.Keys().MdcaPoint(0).Compare(_L("MoreDevices"))==KErrNone)
   211     else if(aData.Keys().MdcaPoint(0).Compare(_L("MoreDevices"))==KErrNone)
   210         {
   212         {
       
   213         iNotification->RemoveObserver();
   211         iNotification->Close(); // Also dequeues the notification from the queue.
   214         iNotification->Close(); // Also dequeues the notification from the queue.
   212         iNotification->RemoveObserver();
       
   213         iNotification = NULL;
   215         iNotification = NULL;
   214         iDevices.ResetAndDestroy();
   216         iDevices.ResetAndDestroy();
   215         TRAP_IGNORE( {
   217         TRAP_IGNORE( {
   216         PrepareNotificationL(TBluetoothDialogParams::EDeviceSearch, ENoResource);
   218         PrepareNotificationL(TBluetoothDialogParams::EDeviceSearch, ENoResource);
   217         iDiscoverer->DiscoverDeviceL(); } );
   219         iDiscoverer->DiscoverDeviceL(); } );
   241     {
   243     {
   242     // Todo: look for this device in repository before creating it.
   244     // Todo: look for this device in repository before creating it.
   243     CBtDevExtension* devext = CBtDevExtension::NewLC( aAddr, aName );
   245     CBtDevExtension* devext = CBtDevExtension::NewLC( aAddr, aName );
   244     iDevices.AppendL( devext );
   246     iDevices.AppendL( devext );
   245     CleanupStack::Pop( devext );
   247     CleanupStack::Pop( devext );
       
   248     
       
   249     if(iNotification)
       
   250         {// conditional check required as CAdvanceDevDiscoverer sends discovered devices at times
       
   251          // even after canceldiscovery is issued and notification is set to NULL
       
   252          // this causes EExcDataAbort
   246     CHbSymbianVariantMap* map = iNotification->Data();
   253     CHbSymbianVariantMap* map = iNotification->Data();
   247     TBuf<8> keyStr;
   254         TBuf<KMaxKeyDesCLength> keyStr;
   248     CHbSymbianVariant* devEntry;
   255     CHbSymbianVariant* devEntry;
   249 
   256 
   250     keyStr.Num( TBluetoothDialogParams::EDialogExt + iDevices.Count() - 1 );
   257     keyStr.Num( TBluetoothDialogParams::EDialogExt + iDevices.Count() - 1 );
   251     devEntry = CHbSymbianVariant::NewL( (TAny*) &(devext->Alias()), 
   258     devEntry = CHbSymbianVariant::NewL( (TAny*) &(devext->Alias()), 
   252             CHbSymbianVariant::EDes );
   259             CHbSymbianVariant::EDes );
   253     map->Add( keyStr, devEntry );
   260     map->Add( keyStr, devEntry );
   254     iNotification->Update();
   261     iNotification->Update();
       
   262         }
   255     }
   263     }
   256 
   264 
   257 // ---------------------------------------------------------------------------
   265 // ---------------------------------------------------------------------------
   258 // HandleDiscoveryCompleted
   266 // HandleDiscoveryCompleted
   259 // ---------------------------------------------------------------------------
   267 // ---------------------------------------------------------------------------
   260 //
   268 //
   261 void CBTNotifDeviceSelector::HandleDiscoveryCompleted( TInt aErr )
   269 void CBTNotifDeviceSelector::HandleDiscoveryCompleted( TInt aErr )
   262     {
   270     {
   263     (void) aErr;
   271     (void) aErr;
   264     CHbSymbianVariantMap* map = iNotification->Data();
   272     CHbSymbianVariantMap* map = iNotification->Data();
   265     TBuf<25> keyStr;
   273     TBuf<KMaxKeyDesCLength> keyStr;
   266     
   274     
   267 
   275 
   268     //TODO compile fail here we need to send the discovery completed text to the dialog 
   276     //TODO compile fail here we need to send the discovery completed text to the dialog 
       
   277     //TODO change the hardcoded string
   269     keyStr.Copy(_L("Search Completed"));
   278     keyStr.Copy(_L("Search Completed"));
   270     CHbSymbianVariant* devEntry( NULL );
   279     CHbSymbianVariant* devEntry( NULL );
   271     TRAP_IGNORE( devEntry = CHbSymbianVariant::NewL( (TAny*) &(keyStr), 
   280     TRAP_IGNORE( devEntry = CHbSymbianVariant::NewL( (TAny*) &(keyStr), 
   272             CHbSymbianVariant::EDes ) );
   281             CHbSymbianVariant::EDes ) );
   273     if ( devEntry )
   282     if ( devEntry )
   343 void CBTNotifDeviceSelector::PrepareNotificationL(
   352 void CBTNotifDeviceSelector::PrepareNotificationL(
   344     TBluetoothDialogParams::TBTDialogType aType,
   353     TBluetoothDialogParams::TBTDialogType aType,
   345     TBTDialogResourceId aResourceId )
   354     TBTDialogResourceId aResourceId )
   346     {
   355     {
   347     BOstraceFunctionEntry0( DUMMY_DEVLIST );
   356     BOstraceFunctionEntry0( DUMMY_DEVLIST );
       
   357     if(iNotification)
       
   358         {
       
   359         iNotification->RemoveObserver();
       
   360         iNotification = NULL;
       
   361         }
   348     iNotification = iServer.NotificationManager()->GetNotification();
   362     iNotification = iServer.NotificationManager()->GetNotification();
   349     User::LeaveIfNull( iNotification ); // For OOM exception, leaves with KErrNoMemory
   363     User::LeaveIfNull( iNotification ); // For OOM exception, leaves with KErrNoMemory
   350     iNotification->SetObserver( this );
   364     iNotification->SetObserver( this );
   351     iNotification->SetNotificationType( aType, aResourceId );
   365     iNotification->SetNotificationType( aType, aResourceId );
   352 
   366 
   365         monthBack -= TTimeIntervalDays(30);
   379         monthBack -= TTimeIntervalDays(30);
   366         if(usedTime >= monthBack)
   380         if(usedTime >= monthBack)
   367             {
   381             {
   368             iDevices.AppendL( devArray[i]->CopyL() );
   382             iDevices.AppendL( devArray[i]->CopyL() );
   369             CHbSymbianVariantMap* map = iNotification->Data();
   383             CHbSymbianVariantMap* map = iNotification->Data();
   370             TBuf<8> keyStr;
   384             TBuf<KMaxKeyDesCLength> keyStr;
   371             CHbSymbianVariant* devEntry;
   385             CHbSymbianVariant* devEntry;
   372 
   386 
   373             keyStr.Num( TBluetoothDialogParams::EDialogExt + iDevices.Count() - 1 );
   387             keyStr.Num( TBluetoothDialogParams::EDialogExt + iDevices.Count() - 1 );
   374             devEntry = CHbSymbianVariant::NewL( (TAny*) &(devArray[i]->Alias()), 
   388             devEntry = CHbSymbianVariant::NewL( (TAny*) &(devArray[i]->Alias()), 
   375                     CHbSymbianVariant::EDes );
   389                     CHbSymbianVariant::EDes );