bluetoothengine/btnotif/btnotifsrv/src/btnotifsession.cpp
branchRCL_3
changeset 55 613943a21004
equal deleted inserted replaced
54:0ba996a9b75d 55:613943a21004
       
     1 /*
       
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: Session class for handling commands from clients.
       
    15 *
       
    16 */
       
    17 
       
    18 #include "btnotifsession.h"
       
    19 #include <btextnotifiers.h>
       
    20 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    21 #include <btextnotifierspartner.h>
       
    22 #endif
       
    23 #include "btnotifclientserver.h"
       
    24 #include "btnotifsettingstracker.h"
       
    25 #include "btnotifconnectiontracker.h"
       
    26 #include "btnotifdeviceselector.h"
       
    27 
       
    28 
       
    29 // ======== LOCAL FUNCTIONS ========
       
    30 
       
    31 // ---------------------------------------------------------------------------
       
    32 // Start the server.
       
    33 // ---------------------------------------------------------------------------
       
    34 //
       
    35 void LeaveIfNullL( const TAny* aPtr, TInt aLeaveCode )
       
    36     {
       
    37     if( aPtr == NULL )
       
    38         {
       
    39         User::Leave( aLeaveCode );
       
    40         }
       
    41     }
       
    42 
       
    43 // ======== MEMBER FUNCTIONS ========
       
    44 
       
    45 // ---------------------------------------------------------------------------
       
    46 // C++ default constructor
       
    47 // ---------------------------------------------------------------------------
       
    48 //
       
    49 CBTNotifSession::CBTNotifSession()
       
    50 :   CSession2()
       
    51     {
       
    52     }
       
    53 
       
    54 // ---------------------------------------------------------------------------
       
    55 // Symbian 2nd-phase constructor
       
    56 // ---------------------------------------------------------------------------
       
    57 //
       
    58 void CBTNotifSession::ConstructL()
       
    59     {
       
    60     }
       
    61 
       
    62 // ---------------------------------------------------------------------------
       
    63 // NewL.
       
    64 // ---------------------------------------------------------------------------
       
    65 //
       
    66 CBTNotifSession* CBTNotifSession::NewL()
       
    67     {
       
    68     CBTNotifSession* self = new( ELeave ) CBTNotifSession();
       
    69     CleanupStack::PushL( self );
       
    70     self->ConstructL();
       
    71     CleanupStack::Pop( self );
       
    72     return self;
       
    73     }
       
    74 
       
    75 
       
    76 // ---------------------------------------------------------------------------
       
    77 // Destructor
       
    78 // ---------------------------------------------------------------------------
       
    79 //
       
    80 CBTNotifSession::~CBTNotifSession()
       
    81     {
       
    82     // clients must complete the message they are responsible for
       
    83     // we do not complete any message here
       
    84     Server()->RemoveSession();
       
    85     }
       
    86 
       
    87 // ---------------------------------------------------------------------------
       
    88 // From class CSession2.
       
    89 // Receives a message from a client.
       
    90 // ---------------------------------------------------------------------------
       
    91 //
       
    92 void CBTNotifSession::ServiceL( const RMessage2& aMessage )
       
    93     {
       
    94     CBTNotifConnectionTracker* connTracker = Server()->ConnectionTracker();
       
    95     TInt opCode = aMessage.Function();
       
    96     TInt uid = aMessage.Int0();
       
    97     TInt err( KErrNotReady );
       
    98     switch(opCode){
       
    99         case EBTNotifCancelNotifier:
       
   100         case EBTNotifStartSyncNotifier:
       
   101         case EBTNotifStartAsyncNotifier:
       
   102         case EBTNotifUpdateNotifier:
       
   103             if( uid == KDeviceSelectionNotifierUid.iUid )
       
   104                 {
       
   105                 TRAP( err, {
       
   106                         CBTNotifDeviceSelector& selector = Server()->DeviceSelectorL();
       
   107                         selector.DispatchNotifierMessageL( aMessage ); }
       
   108                         );
       
   109                 if ( err )
       
   110                     {
       
   111                     aMessage.Complete( err );
       
   112                     }
       
   113                     // deviceselector takes the ownership of aMessage.
       
   114                 }
       
   115             else
       
   116                 {
       
   117                 // PIN/ SSP pairing notifiers from BT stack:
       
   118                 // ***** Note for implementers:
       
   119                 // message queue is not used for this notifier handling.
       
   120                 if ( uid == KBTManAuthNotifierUid.iUid ||
       
   121                      uid == KBTManPinNotifierUid.iUid ||
       
   122                      uid == KBTPinCodeEntryNotifierUid.iUid ||
       
   123                      uid == KBTNumericComparisonNotifierUid.iUid ||
       
   124                      uid == KBTPasskeyDisplayNotifierUid.iUid ||
       
   125                      uid == KBTUserConfirmationNotifierUid.iUid )
       
   126                     {
       
   127                     if( connTracker )
       
   128                         {
       
   129                          // Pass it to the connection tracker.
       
   130                          TRAP( err, 
       
   131                                  connTracker->HandleNotifierRequestL( aMessage ) );
       
   132                         }
       
   133                     if ( err )
       
   134                         {
       
   135                         // tracker not available, can't do this now.
       
   136                         aMessage.Complete( err );
       
   137                         }
       
   138                     }
       
   139                 }
       
   140             break;
       
   141         case EBTNotifPairDevice:
       
   142         case EBTNotifCancelPairDevice:
       
   143             // Pairing requests from clients:
       
   144             if ( connTracker )
       
   145                 {
       
   146                 TRAP( err, connTracker->HandleBondingRequestL( aMessage ) );
       
   147                 }
       
   148             if ( err )
       
   149                 {
       
   150                 // tracker not available, can't do this now.
       
   151                 aMessage.Complete( err );            
       
   152                 }
       
   153             break;
       
   154         default:
       
   155             aMessage.Complete( KErrNotSupported );
       
   156             break;
       
   157     }
       
   158 }
       
   159 
       
   160 
       
   161 // ---------------------------------------------------------------------------
       
   162 // From class CSession2.
       
   163 // Completes construction of the session.
       
   164 // ---------------------------------------------------------------------------
       
   165 //
       
   166 void CBTNotifSession::CreateL()
       
   167     {
       
   168     Server()->AddSession();
       
   169     }
       
   170