bluetoothengine/btnotif/btnotifsrv/src/btnotifdeviceselector.cpp
author hgs
Mon, 17 May 2010 11:06:23 +0300
changeset 31 a0ea99b6fa53
parent 29 48ae3789ce00
child 40 997690c3397a
child 42 b72428996822
permissions -rw-r--r--
201019_1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
     1
/*
48ae3789ce00 201017_2
hgs
parents:
diff changeset
     2
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
48ae3789ce00 201017_2
hgs
parents:
diff changeset
     3
* All rights reserved.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
     4
* This component and the accompanying materials are made available
48ae3789ce00 201017_2
hgs
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
48ae3789ce00 201017_2
hgs
parents:
diff changeset
     6
* which accompanies this distribution, and is available
48ae3789ce00 201017_2
hgs
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
48ae3789ce00 201017_2
hgs
parents:
diff changeset
     8
*
48ae3789ce00 201017_2
hgs
parents:
diff changeset
     9
* Initial Contributors:
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    11
*
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    12
* Contributors:
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    13
*
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    14
* Description: 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    15
*
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    16
*/
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    17
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    18
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    19
#include <btextnotifiers.h>
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    20
#include <btservices/advancedevdiscoverer.h>
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    21
#include <btservices/btdevextension.h>
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    22
#include <hb/hbcore/hbdevicedialogsymbian.h>
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    23
#include <hb/hbcore/hbsymbianvariant.h>
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    24
#include "btnotifdeviceselector.h"
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    25
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    26
#include "btnotifserver.h"
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    27
#include "btnotificationmanager.h"
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    28
#include "btnotifclientserver.h"
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    30
// ======== MEMBER FUNCTIONS ========
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    31
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    32
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    33
// C++ default constructor
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    34
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    35
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    36
CBTNotifDeviceSelector::CBTNotifDeviceSelector( CBTNotifServer& aServer )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    37
:   iServer( aServer )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    38
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    39
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    40
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    41
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    42
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    43
// Symbian 2nd-phase constructor
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    44
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    45
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    46
void CBTNotifDeviceSelector::ConstructL()
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    47
    {
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    48
    iServer.DevRepository().AddObserverL(this);
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    49
    iDiscoverer = CAdvanceDevDiscoverer::NewL( iServer.DevRepository(), *this );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    50
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    51
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    52
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    53
// NewL.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    54
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    55
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    56
CBTNotifDeviceSelector* CBTNotifDeviceSelector::NewL( CBTNotifServer& aServer )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    57
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    58
    CBTNotifDeviceSelector* self = new( ELeave ) CBTNotifDeviceSelector( aServer );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    59
    CleanupStack::PushL( self );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    60
    self->ConstructL();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    61
    CleanupStack::Pop( self );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    62
    return self;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    63
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    64
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    65
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    66
// Destructor
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    67
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    68
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    69
CBTNotifDeviceSelector::~CBTNotifDeviceSelector()
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    70
    {
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    71
    iServer.DevRepository().RemoveObserver(this);
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    72
    if( iNotification )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    73
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    74
        // Clear the notification callback, we cannot receive them anymore.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    75
        iNotification->RemoveObserver();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    76
        iNotification->Close(); // Also dequeues the notification from the queue.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    77
        iNotification = NULL;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    78
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    79
    iDevices.ResetAndDestroy();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    80
    iDevices.Close();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    81
    delete iDiscoverer;
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    82
    
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    83
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    84
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    85
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    86
// Process a client message related to notifiers.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    87
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    88
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    89
void CBTNotifDeviceSelector::DispatchNotifierMessageL( const RMessage2& aMessage )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    90
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    91
    BOstraceFunctionEntryExt ( DUMMY_LIST, this, aMessage.Function() );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    92
    TInt opcode = aMessage.Function();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    93
    TInt uid = aMessage.Int0();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    94
    switch ( opcode ) 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    95
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    96
        case EBTNotifCancelNotifier:
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    97
            {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    98
            // We only accept a cancel message from the same session as the original
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    99
            // request (this is enforced by the RNotifier backend).
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   100
            TInt err( KErrNotFound );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   101
            if ( !iMessage.IsNull() && opcode == iMessage.Function() && 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   102
                    aMessage.Session() == iMessage.Session() )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   103
                {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   104
                iMessage.Complete( KErrCancel );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   105
                err = KErrNone;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   106
                }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   107
            aMessage.Complete( err );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   108
            break;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   109
            }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   110
        case EBTNotifUpdateNotifier:
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   111
            {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   112
            // not handling so far
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   113
            break;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   114
            }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   115
        case EBTNotifStartSyncNotifier:
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   116
            {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   117
            // synch version of device searching is not supported:
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   118
            aMessage.Complete( KErrNotSupported );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   119
            break;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   120
            }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   121
        case EBTNotifStartAsyncNotifier:
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   122
            {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   123
            if ( !iMessage.IsNull() )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   124
                {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   125
                aMessage.Complete( KErrServerBusy );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   126
                return;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   127
                }
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   128
            
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   129
            iLoadDevices = EFalse;
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   130
            if(iServer.DevRepository().IsInitialized())
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   131
                {
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   132
                iLoadDevices = ETrue;
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   133
                if(iServer.DevRepository().AllDevices().Count()==0)
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   134
                     {
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   135
                     PrepareNotificationL(TBluetoothDialogParams::EDeviceSearch, ENoResource);
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   136
                     iDevices.ResetAndDestroy();
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   137
                     iDiscoverer->DiscoverDeviceL();
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   138
                     }
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   139
                else
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   140
                     {
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   141
                     iDevices.ResetAndDestroy();
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   142
                     PrepareNotificationL(TBluetoothDialogParams::EMoreDevice, ENoResource);
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   143
                     LoadUsedDevicesL();
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   144
                     }
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   145
                }
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   146
            iMessage = aMessage;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   147
            break;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   148
            }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   149
        default:
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   150
            {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   151
            aMessage.Complete( KErrNotSupported );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   152
            }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   153
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   154
    BOstraceFunctionExit1( DUMMY_DEVLIST, this );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   155
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   156
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   157
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   158
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   159
// Cancels an outstanding client message related to notifiers.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   160
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   161
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   162
void CBTNotifDeviceSelector::CancelNotifierMessageL( const RMessage2& aMessage )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   163
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   164
    (void) aMessage;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   165
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   166
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   167
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   168
// From class MBTNotificationResult.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   169
// Handle a result from a user query.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   170
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   171
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   172
void CBTNotifDeviceSelector::MBRDataReceived( CHbSymbianVariantMap& aData )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   173
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   174
    TInt err = KErrCancel;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   175
    if(aData.Keys().MdcaPoint(0).Compare(_L("selectedindex"))==KErrNone)
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   176
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   177
        TInt val = *(static_cast<TInt*>(aData.Get(_L("selectedindex"))->Data()));
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   178
        BOstrace1( TRACE_DEBUG, TNAME_DEVLIST_2, "MBRDataReceived, val %d", val );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   179
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   180
        if ( !iMessage.IsNull() )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   181
            {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   182
           // TInt sel = val;// - TBluetoothDialogParams::EDialogExt;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   183
            TBTDeviceResponseParamsPckg devParams;    
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   184
            if (  val > -1 && val < iDevices.Count() )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   185
                {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   186
                devParams().SetDeviceAddress( iDevices[val]->Addr() );
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   187
                devParams().SetDeviceClass(iDevices[val]->Device().DeviceClass());
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   188
                devParams().SetDeviceName(iDevices[val]->Alias());
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   189
                err = iMessage.Write( EBTNotifSrvReplySlot, devParams );
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   190
                iNotification->Close(); // Also dequeues the notification from the queue.
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   191
                iNotification->RemoveObserver();
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   192
                iNotification = NULL;                
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   193
                }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   194
            iMessage.Complete( err );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   195
            }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   196
        iDiscoverer->CancelDiscovery();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   197
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   198
    else if(aData.Keys().MdcaPoint(0).Compare(_L("Stop"))==KErrNone)
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   199
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   200
         iDiscoverer->CancelDiscovery();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   201
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   202
    else if(aData.Keys().MdcaPoint(0).Compare(_L("Retry"))==KErrNone)
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   203
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   204
        iDiscoverer->CancelDiscovery();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   205
        iDevices.ResetAndDestroy();
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   206
        TRAP_IGNORE( iDiscoverer->DiscoverDeviceL() );
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   207
        
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   208
        }
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   209
    else if(aData.Keys().MdcaPoint(0).Compare(_L("MoreDevices"))==KErrNone)
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   210
        {
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   211
        iNotification->Close(); // Also dequeues the notification from the queue.
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   212
        iNotification->RemoveObserver();
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   213
        iNotification = NULL;
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   214
        iDevices.ResetAndDestroy();
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   215
        TRAP_IGNORE( {
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   216
        PrepareNotificationL(TBluetoothDialogParams::EDeviceSearch, ENoResource);
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   217
        iDiscoverer->DiscoverDeviceL(); } );
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   218
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   219
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   220
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   221
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   222
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   223
// From class MBTNotificationResult.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   224
// The notification is finished.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   225
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   226
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   227
void CBTNotifDeviceSelector::MBRNotificationClosed( TInt aError, const TDesC8& aData  )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   228
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   229
    (void) aError;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   230
    (void) aData;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   231
    iNotification->RemoveObserver();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   232
    iNotification = NULL;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   233
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   234
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   235
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   236
// HandleNextDiscoveryResultL
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   237
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   238
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   239
void CBTNotifDeviceSelector::HandleNextDiscoveryResultL( 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   240
        const TInquirySockAddr& aAddr, const TDesC& aName )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   241
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   242
    // Todo: look for this device in repository before creating it.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   243
    CBtDevExtension* devext = CBtDevExtension::NewLC( aAddr, aName );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   244
    iDevices.AppendL( devext );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   245
    CleanupStack::Pop( devext );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   246
    CHbSymbianVariantMap* map = iNotification->Data();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   247
    TBuf<8> keyStr;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   248
    CHbSymbianVariant* devEntry;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   249
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   250
    keyStr.Num( TBluetoothDialogParams::EDialogExt + iDevices.Count() - 1 );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   251
    devEntry = CHbSymbianVariant::NewL( (TAny*) &(devext->Alias()), 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   252
            CHbSymbianVariant::EDes );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   253
    map->Add( keyStr, devEntry );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   254
    iNotification->Update();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   255
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   256
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   257
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   258
// HandleDiscoveryCompleted
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   259
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   260
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   261
void CBTNotifDeviceSelector::HandleDiscoveryCompleted( TInt aErr )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   262
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   263
    (void) aErr;
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   264
    CHbSymbianVariantMap* map = iNotification->Data();
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   265
    TBuf<25> keyStr;
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   266
    
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   267
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   268
    //TODO compile fail here we need to send the discovery completed text to the dialog 
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   269
    keyStr.Copy(_L("Search Completed"));
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   270
    CHbSymbianVariant* devEntry( NULL );
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   271
    TRAP_IGNORE( devEntry = CHbSymbianVariant::NewL( (TAny*) &(keyStr), 
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   272
            CHbSymbianVariant::EDes ) );
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   273
    if ( devEntry )
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   274
        {
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   275
        map->Add( keyStr, devEntry );
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   276
        iNotification->Update();
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   277
        }
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   278
    else
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   279
        {
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   280
        // todo: Complete client request with error
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   281
        }
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   282
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   283
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   284
// From MBtDeviceRepositoryObserver
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   285
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   286
void CBTNotifDeviceSelector::RepositoryInitialized()
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   287
    {
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   288
    iRepositoryInitialized = ETrue;
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   289
    TInt err(KErrNone);
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   290
    if(!iLoadDevices)
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   291
        {
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   292
        iLoadDevices = ETrue;
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   293
        if(iServer.DevRepository().AllDevices().Count()==0)
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   294
             {
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   295
             iDevices.ResetAndDestroy();
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   296
             TRAP(err, {
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   297
             PrepareNotificationL(TBluetoothDialogParams::EDeviceSearch, ENoResource);
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   298
             iDiscoverer->DiscoverDeviceL(); } );
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   299
             }
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   300
        else
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   301
             {
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   302
             iDevices.ResetAndDestroy();
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   303
             TRAP( err, 
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   304
                     {PrepareNotificationL(
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   305
                             TBluetoothDialogParams::EMoreDevice, ENoResource);
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   306
                      LoadUsedDevicesL();
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   307
                     } );
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   308
             }
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   309
        }
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   310
    if ( err )
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   311
        {
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   312
        // todo: complete client request
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   313
        }
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   314
    }
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   315
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   316
void CBTNotifDeviceSelector::DeletedFromRegistry( const TBTDevAddr& aAddr )
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   317
    {
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   318
    (void) aAddr;
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   319
    }
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   320
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   321
void CBTNotifDeviceSelector::AddedToRegistry( const CBtDevExtension& aDev )
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   322
    {
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   323
    (void) aDev;
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   324
    }
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   325
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   326
void CBTNotifDeviceSelector::ChangedInRegistry( const CBtDevExtension& aDev, TUint aSimilarity  ) 
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   327
    {
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   328
    (void) aDev;
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   329
    (void) aSimilarity;
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   330
    }
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   331
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   332
void CBTNotifDeviceSelector::ServiceConnectionChanged(const CBtDevExtension& aDev, TBool aConnected )
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   333
    {
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   334
    (void) aDev;
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   335
    (void) aConnected;
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   336
    }
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   337
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   338
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   339
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   340
// Get and configure a notification.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   341
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   342
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   343
void CBTNotifDeviceSelector::PrepareNotificationL(
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   344
    TBluetoothDialogParams::TBTDialogType aType,
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   345
    TBTDialogResourceId aResourceId )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   346
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   347
    BOstraceFunctionEntry0( DUMMY_DEVLIST );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   348
    iNotification = iServer.NotificationManager()->GetNotification();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   349
    User::LeaveIfNull( iNotification ); // For OOM exception, leaves with KErrNoMemory
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   350
    iNotification->SetObserver( this );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   351
    iNotification->SetNotificationType( aType, aResourceId );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   352
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   353
    iServer.NotificationManager()->QueueNotificationL( iNotification,CBTNotificationManager::EPriorityHigh );
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   354
    BOstraceFunctionExit0( DUMMY_DEVLIST );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   355
    }
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   356
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   357
void CBTNotifDeviceSelector::LoadUsedDevicesL()
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   358
    {
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   359
    const RDevExtensionArray& devArray= iServer.DevRepository().AllDevices();
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   360
    for(TInt i=0; i< devArray.Count(); i++ )
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   361
        {
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   362
      const TTime& usedTime = devArray[i]->Device().Used();
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   363
        TTime monthBack;
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   364
        monthBack.HomeTime();
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   365
        monthBack -= TTimeIntervalDays(30);
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   366
        if(usedTime >= monthBack)
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   367
            {
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   368
            iDevices.AppendL( devArray[i]->CopyL() );
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   369
            CHbSymbianVariantMap* map = iNotification->Data();
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   370
            TBuf<8> keyStr;
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   371
            CHbSymbianVariant* devEntry;
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   372
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   373
            keyStr.Num( TBluetoothDialogParams::EDialogExt + iDevices.Count() - 1 );
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   374
            devEntry = CHbSymbianVariant::NewL( (TAny*) &(devArray[i]->Alias()), 
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   375
                    CHbSymbianVariant::EDes );
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   376
            map->Add( keyStr, devEntry );
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   377
            iNotification->Update();
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   378
            }
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   379
        }
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   380
    }