btobexprofiles/obexserviceman/plugins/src/bt/obexsmpasskey.cpp
branchRCL_3
changeset 56 9386f31cc85b
parent 55 613943a21004
child 61 269724087bed
equal deleted inserted replaced
55:613943a21004 56:9386f31cc85b
     1 /*
       
     2 * Copyright (c) 2002-2007 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:  Class to handle Obexpasskey queries
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "obexsmpasskey.h"
       
    22 #include <obex.h>
       
    23 #include <utf.h>
       
    24 #include "debug.h"
       
    25 
       
    26 
       
    27 CObexSMPasskey::CObexSMPasskey()
       
    28     : CActive(CActive::EPriorityStandard)
       
    29     {
       
    30     CActiveScheduler::Add(this);
       
    31     }
       
    32 
       
    33 CObexSMPasskey* CObexSMPasskey::NewL()
       
    34     {
       
    35     CObexSMPasskey* self = new (ELeave) CObexSMPasskey;
       
    36     return self;
       
    37     }
       
    38 
       
    39 CObexSMPasskey::~CObexSMPasskey()
       
    40     {
       
    41     Cancel();
       
    42     iNotif.Close();
       
    43     FLOG( _L( "[SRCS] CObexSMPasskey: ~CObexSMPasskey" ) );
       
    44     }
       
    45 
       
    46 void CObexSMPasskey::Cleanup()
       
    47     {
       
    48     iNotif.CancelNotifier( KBTObexPasskeyQueryNotifierUid );
       
    49     iNotif.Close();
       
    50     }
       
    51 
       
    52 // ---------------------------------------------------------
       
    53 // DoCancel()
       
    54 // Purpose: Cancels ObexPasskey notifier
       
    55 // Parameters:
       
    56 // Return value:
       
    57 // ---------------------------------------------------------
       
    58 //
       
    59 void CObexSMPasskey::DoCancel()
       
    60     {
       
    61     Cleanup();
       
    62     FLOG( _L( "[SRCS] CObexSMPasskey: DoCancel" ) );
       
    63     }
       
    64 
       
    65 // ---------------------------------------------------------
       
    66 // RunL()
       
    67 // Purpose: Handles ObexPasskey notifiers return value
       
    68 // Parameters:
       
    69 // Return value:
       
    70 // ---------------------------------------------------------
       
    71 //
       
    72 void CObexSMPasskey::RunL()
       
    73     {
       
    74     if ( iStatus.Int() != KErrNone )
       
    75         {
       
    76         FLOG( _L( "[SRCS] CObexSMPasskey: RunL::Cancel\t" ) );
       
    77         User::Leave(KErrCancel);
       
    78         }
       
    79     
       
    80     TBuf<KBTObexPasskeyMaxLength> tempResultBuffer;
       
    81     CnvUtfConverter::ConvertToUnicodeFromUtf8( tempResultBuffer, iObexPasskey() );
       
    82     iObexServer->UserPasswordL( tempResultBuffer );
       
    83     FLOG( _L( "[SRCS] CObexSMPasskey: RunL ObexPasskey returned\t" ) );
       
    84     
       
    85     Cleanup();
       
    86     }
       
    87 
       
    88 // ---------------------------------------------------------
       
    89 // RunError( TInt aError )
       
    90 // Purpose: Handle error cases
       
    91 // Parameters: TInt
       
    92 // Return value: error value
       
    93 // ---------------------------------------------------------
       
    94 //
       
    95 TInt CObexSMPasskey::RunError( TInt aError )
       
    96     {
       
    97     FTRACE(FPrint(_L("[SRCS] CObexSMPasskey: RunError: aError = %d"), aError));
       
    98     Cleanup();
       
    99     iObexServer->Error(aError); // Ensure that OBEX is kept informed of the problem.
       
   100     return KErrNone;
       
   101     }
       
   102 
       
   103 // ---------------------------------------------------------
       
   104 // StartPassKeyRequestL( CObexServer* aObexServer )
       
   105 // Purpose: Starts ObexPasskey notifier
       
   106 // Parameters: CObexServer*
       
   107 // Return value:
       
   108 // ---------------------------------------------------------
       
   109 //
       
   110 void CObexSMPasskey::StartPassKeyRequestL( CObexServer* aObexServer )
       
   111     {
       
   112     FLOG( _L( "[SRCS] CObexSMPasskey: StartPassKeyRequest" ) );
       
   113     User::LeaveIfError( iNotif.Connect() );
       
   114     TPtrC8 dummy( KNullDesC8 );
       
   115     // Starts notifier and gets the passkey for Obex
       
   116     iNotif.StartNotifierAndGetResponse( iStatus, KBTObexPasskeyQueryNotifierUid, dummy, iObexPasskey );
       
   117     iObexServer = aObexServer;
       
   118     SetActive();
       
   119     FLOG( _L( "[SRCS] CObexSMPasskey: SetActive" ) );
       
   120     }
       
   121 
       
   122 //  End of File