usbmgmt/usbmgrtest/t_usb_charging/src/usbstatewatcher.cpp
changeset 54 320d509f1a12
child 59 bbdce6bffaad
equal deleted inserted replaced
51:eaaed528d5fd 54:320d509f1a12
       
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of the License "Symbian Foundation License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include "usbstatewatcher.h"
       
    17 #include <e32cmn.h>
       
    18 #include "testmanager.h"
       
    19 #include "OstTraceDefinitions.h"
       
    20 #ifdef OST_TRACE_COMPILER_IN_USE
       
    21 #include "usbstatewatcherTraces.h"
       
    22 #endif
       
    23 
       
    24 
       
    25 CUsbStateWatcher* CUsbStateWatcher::NewL(CUsbChargingArmTest& aUsbChargingArm)
       
    26     {
       
    27     OstTraceFunctionEntry0( CUSBSTATEWATCHER_NEWL_ENTRY );
       
    28     CUsbStateWatcher* self = new(ELeave) CUsbStateWatcher(aUsbChargingArm);
       
    29     CleanupStack::PushL(self);
       
    30     self->ConstructL();
       
    31     CleanupStack::Pop(self);
       
    32     OstTraceFunctionExit0( CUSBSTATEWATCHER_NEWL_EXIT );
       
    33     return self;
       
    34     }
       
    35 
       
    36 CUsbStateWatcher::~CUsbStateWatcher()
       
    37     {
       
    38     OstTraceFunctionEntry0( CUSBSTATEWATCHER_CUSBSTATEWATCHER_ENTRY );
       
    39     Cancel();
       
    40     OstTraceFunctionExit0( CUSBSTATEWATCHER_CUSBSTATEWATCHER_EXIT );
       
    41     }
       
    42 
       
    43 CUsbStateWatcher::CUsbStateWatcher(CUsbChargingArmTest& aUsbChargingArm)
       
    44     : CActive(EPriorityStandard)
       
    45     , iUsbChargingArm(aUsbChargingArm)
       
    46     {
       
    47     OstTraceFunctionEntry0( DUP1_CUSBSTATEWATCHER_CUSBSTATEWATCHER_ENTRY );
       
    48     CActiveScheduler::Add(this);
       
    49     OstTraceFunctionExit0( DUP1_CUSBSTATEWATCHER_CUSBSTATEWATCHER_EXIT );
       
    50     }
       
    51 
       
    52 void CUsbStateWatcher::ConstructL()
       
    53     {
       
    54     OstTraceFunctionEntry0( CUSBSTATEWATCHER_CONSTRUCTL_ENTRY );
       
    55     GetAndShowDeviceStateL();
       
    56     OstTraceFunctionExit0( CUSBSTATEWATCHER_CONSTRUCTL_EXIT );
       
    57     }
       
    58 
       
    59 void CUsbStateWatcher::DoCancel()
       
    60     {
       
    61     OstTraceFunctionEntry0( CUSBSTATEWATCHER_DOCANCEL_ENTRY );
       
    62     iUsbChargingArm.Usb().DeviceStateNotificationCancel();
       
    63     OstTraceFunctionExit0( CUSBSTATEWATCHER_DOCANCEL_EXIT );
       
    64     }
       
    65 
       
    66 void CUsbStateWatcher::RunL()
       
    67     {
       
    68     OstTraceFunctionEntry0( CUSBSTATEWATCHER_RUNL_ENTRY );
       
    69     GetAndShowDeviceStateL();
       
    70     OstTraceFunctionExit0( CUSBSTATEWATCHER_RUNL_EXIT );
       
    71     }
       
    72 
       
    73 void CUsbStateWatcher::GetAndShowDeviceStateL()
       
    74     {
       
    75     OstTraceFunctionEntry0( CUSBSTATEWATCHER_GETANDSHOWDEVICESTATEL_ENTRY );
       
    76     TUsbDeviceState deviceState;
       
    77     User::LeaveIfError(iUsbChargingArm.Usb().GetDeviceState(deviceState));
       
    78     if(deviceState != iDeviceState)
       
    79         {
       
    80         deviceState = iDeviceState;
       
    81         }
       
    82     iUsbChargingArm.ShowUsbDeviceState(deviceState);  
       
    83     
       
    84     iUsbChargingArm.Usb().DeviceStateNotification(0xffffffff, iDeviceState, iStatus);
       
    85     SetActive();    
       
    86     OstTraceFunctionExit0( CUSBSTATEWATCHER_GETANDSHOWDEVICESTATEL_EXIT );
       
    87     }
       
    88