bluetoothengine/btnotif/btnotifsrv/src/bluetoothnotification.cpp
author hgs
Wed, 05 May 2010 09:56:48 +0300
changeset 30 df7a93ede42e
parent 29 48ae3789ce00
child 31 a0ea99b6fa53
permissions -rw-r--r--
201017_3
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
* ============================================================================
48ae3789ce00 201017_2
hgs
parents:
diff changeset
     3
*  Name        : bluetoothnotification.cpp
48ae3789ce00 201017_2
hgs
parents:
diff changeset
     4
*  Part of     : bluetoothengine / btnotif
48ae3789ce00 201017_2
hgs
parents:
diff changeset
     5
*  Description : Class for managing an actual user notification or query.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
     6
*                It hides UI framework-specifics in a private class.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
     7
*
48ae3789ce00 201017_2
hgs
parents:
diff changeset
     8
*  Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies).
48ae3789ce00 201017_2
hgs
parents:
diff changeset
     9
*  All rights reserved.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    10
*  This component and the accompanying materials are made available
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    11
*  under the terms of "Eclipse Public License v1.0"
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    12
*  which accompanies this distribution, and is available
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    13
*  at the URL "http://www.eclipse.org/legal/epl-v10.html".
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    14
*
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    15
*  Initial Contributors:
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    16
*  Nokia Corporation - initial contribution.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    17
*
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    18
*  Contributors:
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    19
*  Nokia Corporation
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    20
* ============================================================================
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    21
* Template version: 4.1
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    22
*/
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    23
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    24
#include "bluetoothnotification.h"
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    25
#include <hb/hbcore/hbsymbianvariant.h>
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    26
#include "btnotificationmanager.h"
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    27
#include "btnotifserver.h"
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    28
#include "bluetoothtrace.h"
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    29
#include <utf.h>  // for debugging
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    30
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    31
/**  Identifier of Bluetooth device dialog plug-in. */
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    32
_LIT( KBTDevDialogId, "com.nokia.hb.btdevicedialog/1.0" );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    33
/**  Key name of result. */
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    34
_LIT( KBTDevDialogResult, "result" );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    35
_LIT( KBTDevDialogInput, "input" );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    36
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    37
// ======== MEMBER FUNCTIONS ========
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    38
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    39
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    40
// C++ default constructor
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    41
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    42
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    43
CBluetoothNotification::CBluetoothNotification( CBTNotificationManager* aManager )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    44
:   iManager( aManager )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    45
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    46
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    47
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    48
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    49
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    50
// Symbian 2nd-phase constructor
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    51
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    52
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    53
void CBluetoothNotification::ConstructL()
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    54
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    55
    iNotificationData = CHbSymbianVariantMap::NewL();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    56
    iDialog = CHbDeviceDialogSymbian::NewL();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    57
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    58
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    59
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    60
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    61
// NewL.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    62
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    63
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    64
CBluetoothNotification* CBluetoothNotification::NewL( 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    65
    CBTNotificationManager* aManager )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    66
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    67
	BOstraceFunctionEntry0( DUMMY_DEVLIST );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    68
    CBluetoothNotification* self = new( ELeave ) CBluetoothNotification( aManager );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    69
    CleanupStack::PushL( self );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    70
    self->ConstructL();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    71
    CleanupStack::Pop( self );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    72
	BOstraceFunctionExit0( DUMMY_DEVLIST );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    73
    return self;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    74
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    75
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    76
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    77
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    78
// Destructor
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    79
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    80
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    81
CBluetoothNotification::~CBluetoothNotification()
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    82
{
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    83
    BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    84
    delete iDialog;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    85
    delete iNotificationData;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    86
    delete iReturnData;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    87
	BOstraceFunctionExit1( DUMMY_DEVLIST, this )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    88
}
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    89
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    90
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    91
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    92
// Resets the notification, clean all the internals.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    93
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    94
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    95
void CBluetoothNotification::Reset()
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    96
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    97
	BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    98
    iType = TBluetoothDialogParams::EInvalidDialog;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    99
    iResourceId = ENoResource;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   100
    iObserver = NULL;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   101
    iDialog->Cancel();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   102
    iDialog->SetObserver( NULL );   // Not interested in a callback anymore.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   103
    delete iNotificationData;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   104
    iNotificationData = NULL;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   105
    iNotificationData = CHbSymbianVariantMap::NewL();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   106
    delete iReturnData;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   107
    iReturnData = NULL;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   108
    iReturnData = CHbSymbianVariantMap::NewL();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   109
    BOstraceFunctionExit1( DUMMY_DEVLIST, this );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   110
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   111
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   112
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   113
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   114
// Sets the data to be shown to the user.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   115
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   116
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   117
TInt CBluetoothNotification::SetData( TInt aDataType, const TDesC& aData )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   118
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   119
    TRAPD( err, SetDataL( aDataType, aData ) );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   120
    return (int) err;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   121
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   122
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   123
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   124
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   125
// Sets the data to be shown to the user.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   126
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   127
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   128
TInt CBluetoothNotification::SetData( TInt aDataType, TInt aData )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   129
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   130
    TRAPD( err, SetDataL( aDataType, aData ) );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   131
    return (int) err;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   132
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   133
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   134
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   135
// Updates the data to be shown to the user.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   136
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   137
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   138
TInt CBluetoothNotification::Update( const TDesC& aData )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   139
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   140
    BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   141
    (void) aData;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   142
    int ret = iDialog->Update( *iNotificationData );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   143
    delete iNotificationData;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   144
    iNotificationData = NULL;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   145
    iNotificationData = CHbSymbianVariantMap::NewL();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   146
    BOstraceFunctionExit1( DUMMY_DEVLIST, this );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   147
    return ret;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   148
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   149
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   150
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   151
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   152
// Show the notification, which means that it is added to the queue.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   153
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   154
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   155
TInt CBluetoothNotification::Show()
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   156
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   157
	BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   158
    TRAPD( err, SetDataL( TBluetoothDialogParams::EDialogType, iType ) );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   159
    if( !err )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   160
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   161
        TRAP( err, SetDataL( TBluetoothDialogParams::EResource, iResourceId ) );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   162
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   163
    delete iReturnData;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   164
    iReturnData = NULL;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   165
    if( !err )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   166
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   167
        TRAP( err, iReturnData = CHbSymbianVariantMap::NewL() );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   168
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   169
    if( !err )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   170
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   171
        err = iDialog->Show( KBTDevDialogId(), *iNotificationData, this );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   172
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   173
    delete iNotificationData;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   174
    iNotificationData = NULL;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   175
    iNotificationData = CHbSymbianVariantMap::NewL();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   176
    
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   177
    const TInt KPluginErr = CHbDeviceDialogSymbian::EPluginErrors + 1;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   178
    if( err == KPluginErr )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   179
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   180
        err = KErrNotFound;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   181
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   182
	BOstraceFunctionExitExt( DUMMY_DEVLIST, this, err );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   183
    return err;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   184
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   185
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   186
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   187
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   188
// Stop showing the notification.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   189
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   190
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   191
TInt CBluetoothNotification::Close()
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   192
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   193
    BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   194
    iDialog->Cancel();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   195
    iManager->ReleaseNotification( this );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   196
	BOstraceFunctionExit1( DUMMY_DEVLIST, this );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   197
    return KErrNone;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   198
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   199
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   200
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   201
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   202
// Sets the data to be shown to the user.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   203
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   204
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   205
void CBluetoothNotification::SetDataL( TInt aType, const TDesC& aData )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   206
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   207
    BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, aType );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   208
    TBuf16<6> key;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   209
    TInt err = 0;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   210
    CHbSymbianVariant* value = NULL;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   211
    switch( aType )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   212
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   213
        case TBluetoothDialogParams::EAddress:
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   214
        case TBluetoothDeviceDialog::EDeviceName:
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   215
        case TBluetoothDeviceDialog::EAdditionalDesc:
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   216
        case TBluetoothDialogParams::EDialogTitle:
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   217
            key.Num(aType);
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   218
            value = CHbSymbianVariant::NewL( (TAny*) &aData, CHbSymbianVariant::EDes );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   219
			BtTraceBlock( 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   220
                    TBuf<32> buf;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   221
                    switch (aType) {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   222
                        case TBluetoothDialogParams::EAddress:
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   223
                            _LIT(KAddress,"EAddress");
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   224
                            buf.Append(KAddress); 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   225
                            break;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   226
                        case TBluetoothDeviceDialog::EDeviceName:
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   227
                            _LIT(KDeviceName,"EDeviceName");
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   228
                            buf.Append(KDeviceName); 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   229
                            break;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   230
                        case TBluetoothDeviceDialog::EAdditionalDesc:
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   231
                            _LIT(KAdditionalDesc,"EAdditionalDesc");
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   232
                            buf.Append(KAdditionalDesc); 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   233
                            break;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   234
                    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   235
                    TPtrC p(buf);
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   236
                    TPtrC16 *ptr = (TPtrC16 *)value->Data();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   237
                    BOstraceExt2( TRACE_DEBUG, DUMMY_DEVLIST, "SetData [%S] = [%S]", &p, ptr);
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   238
                    );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   239
            err = iNotificationData->Add( key, value );   // Takes ownership of value
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   240
            if ( err )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   241
                {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   242
                // Note: need a proper exception handling. 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   243
                // NOTIF_NOTHANDLED( err )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   244
                }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   245
            break;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   246
        case TBluetoothDialogParams::EResource:
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   247
        case TBluetoothDeviceDialog::EDeviceClass:
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   248
        case TBluetoothDeviceDialog::EAdditionalInt:
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   249
            PanicServer( EBTNotifPanicBadArgument );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   250
            break;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   251
        case TBluetoothDialogParams::ENoParams:
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   252
        case TBluetoothDeviceDialog::ENoParams:
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   253
        default:
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   254
            break;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   255
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   256
		BOstraceFunctionExit1( DUMMY_DEVLIST, this );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   257
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   258
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   259
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   260
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   261
// Sets the data to be shown to the user.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   262
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   263
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   264
void CBluetoothNotification::SetDataL( TInt aType, TInt aData )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   265
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   266
    BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, aType );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   267
    TBuf<6> key;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   268
    TInt err = 0;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   269
    CHbSymbianVariant* value = NULL;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   270
    switch( aType )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   271
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   272
        case TBluetoothDialogParams::EDialogType:
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   273
        case TBluetoothDialogParams::EResource:
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   274
        case TBluetoothDialogParams::EDialogTitle:
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   275
        case TBluetoothDeviceDialog::EDeviceClass:
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   276
        case TBluetoothDeviceDialog::EAdditionalInt:
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   277
            key.Num(aType);
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   278
            value = CHbSymbianVariant::NewL( (TAny*) &aData, CHbSymbianVariant::EInt );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   279
			BtTraceBlock( 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   280
                    TBuf<32> buf;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   281
                    switch (aType) {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   282
                        case TBluetoothDialogParams::EDialogType:
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   283
                            buf = _L("EDialogType"); 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   284
                            break;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   285
                        case TBluetoothDialogParams::EResource:
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   286
                            buf = _L("EResource");
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   287
                            break;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   288
                        case TBluetoothDeviceDialog::EDeviceClass:
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   289
                            buf = _L("EDeviceClass");
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   290
                            break;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   291
                        case TBluetoothDeviceDialog::EAdditionalInt:
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   292
                            buf = _L("EAdditionalInt");
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   293
                            break;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   294
                    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   295
                    TPtrC p(buf);
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   296
                    TInt *intPtr = (TInt *)value->Data();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   297
                    BOstraceExt2( TRACE_DEBUG, DUMMY_DEVLIST, "SetData [%S] = [%d]", &p, *intPtr);
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   298
                    );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   299
			err = iNotificationData->Add( key, value );   // Takes ownership of value
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   300
	         if ( err )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   301
	             {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   302
                 // need a proper exception handling.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   303
                 //NOTIF_NOTHANDLED( !err )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   304
	             }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   305
            
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   306
            break;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   307
        case TBluetoothDialogParams::EAddress:
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   308
        case TBluetoothDeviceDialog::EDeviceName:
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   309
            PanicServer( EBTNotifPanicBadArgument );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   310
            break;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   311
        case TBluetoothDialogParams::ENoParams:
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   312
        case TBluetoothDeviceDialog::ENoParams:
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   313
        default:
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   314
            break;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   315
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   316
		BOstraceFunctionExit1( DUMMY_DEVLIST, this );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   317
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   318
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   319
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   320
// From class MHbDeviceDialogObserver.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   321
// Callback called when data is received from a device dialog.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   322
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   323
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   324
void CBluetoothNotification::DataReceived( CHbSymbianVariantMap& aData )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   325
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   326
    BOstraceFunctionEntry1( DUMMY_DEVLIST, this );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   327
    BtTraceBlock( debugHbSymbianVariantMap(aData); );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   328
    for( TInt i = 0; i < aData.Keys().MdcaCount(); i++ )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   329
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   330
        TPtrC key( aData.Keys().MdcaPoint( i ).Ptr(), aData.Keys().MdcaPoint( i ).Length() );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   331
        const CHbSymbianVariant* valueRef = aData.Get( key );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   332
        CHbSymbianVariant* value = CHbSymbianVariant::NewL( valueRef->Data(), valueRef->Type() );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   333
        TInt err = iReturnData->Add( key, value );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   334
        NOTIF_NOTHANDLED( !err )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   335
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   336
    iObserver->MBRDataReceived( aData );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   337
    BOstraceFunctionExit1( DUMMY_DEVLIST, this );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   338
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   339
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   340
#ifdef BLUETOOTHTRACE_ENABLED
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   341
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   342
void CBluetoothNotification::debugHbSymbianVariantMap( CHbSymbianVariantMap& aData)
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   343
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   344
    for( TInt i = 0; i < aData.Keys().MdcaCount(); i++ )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   345
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   346
        TBuf<128> buf;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   347
        TPtrC key( aData.Keys().MdcaPoint( i ).Ptr(), aData.Keys().MdcaPoint( i ).Length() );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   348
        buf = key;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   349
        buf.Append(_L(" = "));
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   350
        const CHbSymbianVariant* value = aData.Get( key );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   351
        TBuf<16> nbr;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   352
        TBuf<32> newBuf;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   353
        switch (value->Type()) {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   354
            case CHbSymbianVariant::EInt :
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   355
                buf.Append(_L("[EInt] ")); 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   356
                nbr.Num(*((TInt*)value->Data()));
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   357
                buf.Append(nbr);
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   358
                break;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   359
            case  CHbSymbianVariant::EBool :
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   360
                buf.Append(_L("[EBool] ")); 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   361
                buf.Append(*((TBool*)value->Data()) ? _L("True") : _L("False"));
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   362
                break;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   363
            case CHbSymbianVariant::EUint :
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   364
                buf.Append( _L("[EUint] ")); 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   365
                nbr.Num(*((TUint*)value->Data()));
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   366
                buf.Append(nbr);
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   367
                break;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   368
            case CHbSymbianVariant::EReal  :
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   369
                buf.Append(_L("[EReal] ")); 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   370
                nbr.Num(*((TReal*)value->Data()));
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   371
                buf.Append(nbr);
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   372
                break;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   373
            case CHbSymbianVariant::EDes :  // TDesC
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   374
                buf.Append(_L("[EDes] ")); 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   375
                buf.Append(*((TPtrC16 *)value->Data()));
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   376
                break;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   377
            case CHbSymbianVariant::EBinary :  // TDesC8
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   378
                buf.Append(_L("[EBinary] ")); 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   379
                // the following function caused problems when converting this function to 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   380
                // a trace function in bluetoothtrace.h
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   381
                CnvUtfConverter::ConvertToUnicodeFromUtf8(newBuf,*((TPtrC8 *)value->Data()) );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   382
                buf.Append(newBuf);
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   383
                break;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   384
            case CHbSymbianVariant::EChar  : // a TChar
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   385
                buf.Append(_L("[EChar] ")); 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   386
                buf.Append(*((TChar *)value->Data()));
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   387
                break;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   388
            case CHbSymbianVariant::ERect  : // a TRect
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   389
            case CHbSymbianVariant::EPoint : // a TPoint
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   390
            case CHbSymbianVariant::ESize  : // a TSize
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   391
            case CHbSymbianVariant::EDesArray : //  a MDesCArray
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   392
                break;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   393
            default:
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   394
                break;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   395
            }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   396
        TPtrC p(buf);
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   397
        BOstraceExt1( TRACE_DEBUG, DUMMY_DEVLIST, "HbSymbianVariantMap [%S]", &p);
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   398
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   399
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   400
#endif // BLUETOOTHTRACE_ENABLED
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   401
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   402
// From class MHbDeviceDialogObserver.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   403
// Callback called when a device dialog is closed.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   404
// ---------------------------------------------------------------------------
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   405
//
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   406
void CBluetoothNotification::DeviceDialogClosed( TInt aCompletionCode )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   407
    {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   408
    BOstraceFunctionEntryExt( DUMMY_DEVLIST, this, aCompletionCode );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   409
    TPckg<TBool> result( EFalse );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   410
    TPtrC8 resultPtr( result );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   411
    const CHbSymbianVariant* value = iReturnData->Get( KBTDevDialogResult );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   412
    if( value && value->IsValid() )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   413
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   414
        result() = *value->Value<TBool>();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   415
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   416
    RBuf8 resultBuf;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   417
    value = iReturnData->Get( KBTDevDialogInput );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   418
    if( value && value->IsValid() )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   419
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   420
        HBufC8* data = value->Value<HBufC8>();
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   421
        if( !resultBuf.Create( data->Length() + result.Length() ) )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   422
            {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   423
            resultBuf = *data;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   424
            resultBuf.Insert( 0, result );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   425
            resultPtr.Set( resultBuf );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   426
            }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   427
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   428
    if( iObserver )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   429
        {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   430
        if( aCompletionCode == CHbDeviceDialogSymbian::ECancelledError )
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   431
            {
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   432
            aCompletionCode = KErrCancel;
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   433
            }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   434
        iObserver->MBRNotificationClosed( aCompletionCode, resultPtr );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   435
        }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   436
    iManager->ReleaseNotification( this );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   437
    // Note that we might get deleted after releasing ourselves.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   438
    BOstraceFunctionExit1( DUMMY_DEVLIST, this );
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   439
    }
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   440