bluetoothengine/btnotif/src/BTNInqNotifier.cpp
changeset 0 f63038272f30
child 8 0707dd69d236
equal deleted inserted replaced
-1:000000000000 0:f63038272f30
       
     1 /*
       
     2 * Copyright (c) 2002 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:  Declares Bluetooth device inquiry notifier class.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <eikenv.h>          // Eikon environment
       
    21 
       
    22 #include "btninqnotifier.h"  // Own class definition
       
    23 #include "btNotifDebug.h"    // Debugging macros
       
    24 #include <StringLoader.h>    // Localisation stringloader
       
    25 #include <BTNotif.rsg>          // Own resources
       
    26     
       
    27 
       
    28 // ================= MEMBER FUNCTIONS =======================
       
    29 
       
    30 // ----------------------------------------------------------
       
    31 // CBTInqNotifier::NewL
       
    32 // Two-phased constructor.
       
    33 // ----------------------------------------------------------
       
    34 //
       
    35 CBTInqNotifier* CBTInqNotifier::NewL()
       
    36     {
       
    37     CBTInqNotifier* self=new (ELeave) CBTInqNotifier();
       
    38     CleanupStack::PushL(self);
       
    39     self->ConstructL();
       
    40     CleanupStack::Pop();
       
    41     return self;
       
    42     }
       
    43 
       
    44 // ----------------------------------------------------------
       
    45 // CBTInqNotifier::CBTInqNotifier
       
    46 // C++ default constructor can NOT contain any code, that
       
    47 // might leave.
       
    48 // ----------------------------------------------------------
       
    49 //
       
    50 CBTInqNotifier::CBTInqNotifier()
       
    51     {
       
    52     }
       
    53 
       
    54 // ----------------------------------------------------------
       
    55 // Destructor
       
    56 // ----------------------------------------------------------
       
    57 //
       
    58 CBTInqNotifier::~CBTInqNotifier()
       
    59     {
       
    60     FLOG(_L("[BTNOTIF]\t CBTInqNotifier::~CBTInqNotifier()"));
       
    61     delete iUi;
       
    62     FLOG(_L("[BTNOTIF]\t CBTInqNotifier::~CBTInqNotifier() completed"));
       
    63     }
       
    64 
       
    65 // ----------------------------------------------------------
       
    66 // CBTInqNotifier::RegisterL
       
    67 // ----------------------------------------------------------
       
    68 //
       
    69 CBTInqNotifier::TNotifierInfo CBTInqNotifier::RegisterL()
       
    70     {
       
    71     
       
    72     iInfo.iUid=KDeviceSelectionNotifierUid;
       
    73     iInfo.iChannel=KBTInquiryChannel;
       
    74     iInfo.iPriority=ENotifierPriorityVHigh; // User input level
       
    75     return iInfo;
       
    76     }
       
    77 
       
    78 // ----------------------------------------------------------
       
    79 // CBTInqNotifier::GetParamsL
       
    80 // Initialize parameters and launch device search.
       
    81 // ----------------------------------------------------------
       
    82 //
       
    83 void CBTInqNotifier::GetParamsL(const TDesC8& aBuffer, TInt aReplySlot, const RMessagePtr2& aMessage)
       
    84     {
       
    85     FLOG(_L("[BTNOTIF]\t CBTInqNotifier::GetParamsL()"));
       
    86 
       
    87     if( iUi || iReplySlot!=NULL || !iMessage.IsNull() )
       
    88         {
       
    89         aMessage.Complete(KErrInUse);
       
    90         return;
       
    91         }
       
    92 
       
    93     iMessage = aMessage;
       
    94     iReplySlot = aReplySlot;
       
    95     
       
    96     TBTDeviceClass cod;
       
    97     TBTDeviceSelectionParamsPckg pckg;
       
    98     pckg.Copy(aBuffer); 
       
    99 
       
   100     LaunchInquiryL(pckg().DeviceClass());
       
   101     
       
   102     FLOG(_L("[BTNOTIF]\t CBTInqNotifier::GetParamsL() completed "));
       
   103     }
       
   104 
       
   105 // ----------------------------------------------------------
       
   106 // CBTInqNotifier::NotifyDeviceSearchCompleted
       
   107 // Notified by InquiryUI, return to caller by completing message
       
   108 // ----------------------------------------------------------
       
   109 //
       
   110 void CBTInqNotifier::NotifyDeviceSearchCompleted(TInt aErr, const TBTDeviceResponseParams& aDevice)
       
   111     {
       
   112     FTRACE(FPrint( _L("[BTNOTIF]\t CBTInqNotifier::NotifyDeviceSearchCompleted aErr %d"), aErr ));
       
   113     CompleteMessage(TBTDeviceResponseParamsPckg( aDevice ), aErr);
       
   114     }
       
   115 
       
   116 // ----------------------------------------------------------
       
   117 // CBTInqNotifier::Cancel
       
   118 // Release all own resources (member variables)
       
   119 // ----------------------------------------------------------
       
   120 //
       
   121 void CBTInqNotifier::Cancel()
       
   122     {
       
   123     FLOG(_L("[BTNOTIF]\t CBTInqNotifier::Cancel()"));
       
   124     if( iUi )
       
   125         {
       
   126         iUi->Cancel();
       
   127         }
       
   128     CBTNotifierBase::Cancel();
       
   129     FLOG(_L("[BTNOTIF]\t CBTInqNotifier::Cancel() completed"));
       
   130     }
       
   131 
       
   132 // ----------------------------------------------------------
       
   133 // Ensure BT is ON; there are not too many connections; InqUi 
       
   134 // is launched successfully.
       
   135 // ----------------------------------------------------------
       
   136 //
       
   137 void CBTInqNotifier::LaunchInquiryL(const TBTDeviceClass& aDesiredDevice)
       
   138     {
       
   139     // Turn BT on if it is not yet.
       
   140     if ( !CheckAndSetPowerOnL() )
       
   141         {
       
   142         CompleteMessage(KErrGeneral);
       
   143         return;
       
   144         }
       
   145 
       
   146     TInt linkCount;
       
   147     User::LeaveIfError(RProperty::Get(KPropertyUidBluetoothCategory, 
       
   148             KPropertyKeyBluetoothGetPHYCount, linkCount));
       
   149     if ( linkCount > 6 )   //support only piconet
       
   150         {
       
   151         iNotifUiUtil->ShowInfoNoteL( R_BT_BUSY_NOTE, ECmdBTnotifUnavailable );
       
   152         User::Leave(KErrInUse);
       
   153         }
       
   154     
       
   155     // launch Inquiry UI
       
   156   
       
   157     iUi = new (ELeave) CBTInqUI( this, iNotifUiUtil, aDesiredDevice);
       
   158    
       
   159 
       
   160     iUi->ConstructL();
       
   161     }
       
   162 
       
   163 // End of File