usbengines/usbwatcher/src/tusbindicatorhandler.cpp
branchRCL_3
changeset 24 e02eb84a14d2
parent 4 7e15987c4500
equal deleted inserted replaced
23:25fce757be94 24:e02eb84a14d2
       
     1 /*
       
     2 * Copyright (c) 2009 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:  This implements TUsbIndicatorHandler class.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <e32std.h>
       
    20 #include <AknNotifySignature.h> // SAknNotifierPackage
       
    21 #include <avkon.hrh> //EAknIndicatorUSBConnection
       
    22 #include "tusbindicatorhandler.h"
       
    23 #include "debug.h"
       
    24 
       
    25 // ---------------------------------------------------------------------------
       
    26 // C++ Constructor 
       
    27 // ---------------------------------------------------------------------------
       
    28 //
       
    29 TUsbIndicatorHandler::TUsbIndicatorHandler() 
       
    30     : iDevStateB4Suspend( EUsbDeviceStateUndefined )
       
    31     , iUsbIndicator(EFalse)
       
    32     {
       
    33     }
       
    34 
       
    35 // ---------------------------------------------------------------------------
       
    36 // Change USB Indicator 
       
    37 // ---------------------------------------------------------------------------
       
    38 //
       
    39 void TUsbIndicatorHandler::HandleDeviceStateChange( TUsbDeviceState aStateOld, 
       
    40             TUsbDeviceState aStateNew )
       
    41     {
       
    42     LOG_FUNC
       
    43 
       
    44     LOG2( "USB device state changed: %d ==> %d", aStateOld, aStateNew );
       
    45     
       
    46     if ( EUsbDeviceStateConfigured == aStateNew ) // Entering configed state 
       
    47         {
       
    48         // filter out case of configed -> suspended -> configed
       
    49         if ( ( EUsbDeviceStateSuspended != aStateOld ) || 
       
    50              ( EUsbDeviceStateConfigured != iDevStateB4Suspend) )
       
    51             {
       
    52             ShowUsbIndicator( ETrue );
       
    53             }
       
    54         }
       
    55     else if ( EUsbDeviceStateSuspended == aStateNew )
       
    56     // If current state is suspend, we do not change the indicator, but save
       
    57     // the previous state
       
    58         {
       
    59         iDevStateB4Suspend = aStateOld;
       
    60         }
       
    61     else // New device state is not configured, nor suspended
       
    62         {
       
    63         // Hide USB indicator if previous state is either configured, or
       
    64         // suspended AND state before is not configured
       
    65         if( ( EUsbDeviceStateConfigured == aStateOld ) ||
       
    66             ( ( EUsbDeviceStateSuspended == aStateOld ) &&
       
    67               ( EUsbDeviceStateConfigured == iDevStateB4Suspend ) ) ) 
       
    68             {
       
    69             ShowUsbIndicator( EFalse );
       
    70             }
       
    71         } 
       
    72     }
       
    73     
       
    74 // ---------------------------------------------------------------------------
       
    75 // Show USB Indicator
       
    76 // ---------------------------------------------------------------------------
       
    77 //
       
    78 void TUsbIndicatorHandler::ShowUsbIndicator( TInt aUsbIndicatorState )
       
    79     {
       
    80     LOG_FUNC
       
    81     
       
    82     iUsbIndicator = aUsbIndicatorState;
       
    83     LOG1( "USB indicator state %d", aUsbIndicatorState );
       
    84     RNotifier notifier;
       
    85     TInt err = notifier.Connect();
       
    86     if ( KErrNone == err )
       
    87         {
       
    88         TPckgBuf< SAknNotifierPackage<SAknSmallIndicatorParams> > pckg;
       
    89         pckg().iParamData.iSmallIndicatorUid =
       
    90             TUid::Uid( EAknIndicatorUSBConnection );
       
    91         pckg().iParamData.iValue = aUsbIndicatorState ? 
       
    92             EAknIndicatorStateOn : EAknIndicatorStateOff ;
       
    93         notifier.StartNotifier( KAknSmallIndicatorUid, pckg );
       
    94         notifier.Close();
       
    95         }
       
    96     else
       
    97         {
       
    98         LOG1( "RNotifier::Connect error: %d", err );
       
    99         }
       
   100     }
       
   101 
       
   102 // End of file