voicerecorder/UtilsSrc/VRUSBStateHanlder.cpp
branchRCL_3
changeset 25 c6bafb5162d8
equal deleted inserted replaced
24:072a5fa0c63b 25:c6bafb5162d8
       
     1 /*
       
     2 * Copyright (c) 2002-2006 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: 
       
    15 *     CVRUSBStateHanlder implementation
       
    16 *
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 // INCLUDES
       
    22 #include <e32cmn.h>
       
    23 #include <usbpersonalityids.h>
       
    24 #include <e32property.h> 
       
    25 #include <UsbWatcherInternalPSKeys.h>
       
    26 #include <usbpersonalityids.h>
       
    27 
       
    28 #include <AknWaitDialog.h>
       
    29 #include <eikenv.h> 
       
    30 
       
    31 #include "VRUSBStateHanlder.h"
       
    32 #include "CVRRecView.h"
       
    33 
       
    34 CVRUSBStateHanlder::CVRUSBStateHanlder(MVRUSBStateObserver* aObserver) :
       
    35     CActive(EPriorityStandard), // Standard priority
       
    36             iObserver(aObserver),
       
    37             iConnectionStatus(EStateUninitialized)
       
    38     {
       
    39     }
       
    40 
       
    41 EXPORT_C CVRUSBStateHanlder* CVRUSBStateHanlder::NewL(
       
    42         MVRUSBStateObserver* aObserver)
       
    43     {
       
    44     CVRUSBStateHanlder* self = new (ELeave) CVRUSBStateHanlder(aObserver);
       
    45     CleanupStack::PushL(self);
       
    46     self->ConstructL();
       
    47     CleanupStack::Pop(); // self;
       
    48     return self;
       
    49     }
       
    50 
       
    51 void CVRUSBStateHanlder::ConstructL()
       
    52     {
       
    53 #ifdef DUMMY_USB_TESTING 
       
    54     User::LeaveIfError(iTimer.CreateLocal()); // Initialize timer
       
    55 #else
       
    56     iProperty.Attach(KPSUidUsbWatcher, KUsbWatcherSelectedPersonality);
       
    57 #endif
       
    58     CActiveScheduler::Add(this); // Add to scheduler    
       
    59     StartL();
       
    60     }
       
    61 
       
    62 CVRUSBStateHanlder::~CVRUSBStateHanlder()
       
    63     {
       
    64     Cancel(); // Cancel any request, if outstanding
       
    65 #ifdef DUMMY_USB_TESTING   
       
    66     iTimer.Close();
       
    67 #else      
       
    68     iProperty.Close();
       
    69 #endif     
       
    70     }
       
    71 
       
    72 void CVRUSBStateHanlder::DoCancel()
       
    73     {
       
    74 #ifdef DUMMY_USB_TESTING   
       
    75     iTimer.Cancel();
       
    76 #else      
       
    77     iProperty.Cancel();
       
    78 #endif  
       
    79 
       
    80     }
       
    81 
       
    82 void CVRUSBStateHanlder::StartL()
       
    83     {
       
    84     Cancel(); // Cancel any request, just to be sure
       
    85 #ifdef DUMMY_USB_TESTING
       
    86     iTimer.After(iStatus, 10000000); // Set for later
       
    87     SetActive(); // Tell scheduler a request is active   
       
    88 #else   
       
    89     SetActive();
       
    90     iProperty.Subscribe(iStatus);
       
    91 #endif
       
    92     }
       
    93 
       
    94 void CVRUSBStateHanlder::RunL()
       
    95     {
       
    96 #ifdef DUMMY_USB_TESTING
       
    97     CDummyUSBState::HandleUSBEventL();
       
    98 #else
       
    99     StartL();
       
   100 #endif
       
   101     
       
   102  
       
   103     TBool isUsbActive (IsUsbActive());
       
   104     
       
   105     if (isUsbActive)
       
   106         {
       
   107         if(iConnectionStatus != EStateConnected)
       
   108             {
       
   109             iObserver->HandleUsbPlugInL();
       
   110             iConnectionStatus = EStateConnected;
       
   111             }
       
   112         }
       
   113     else
       
   114         {
       
   115         if(iConnectionStatus != EStateDisConnected)
       
   116             {
       
   117             iObserver->HandleUsbPlugOutL();
       
   118             iConnectionStatus = EStateDisConnected;
       
   119             } 
       
   120         }
       
   121 
       
   122 #ifdef DUMMY_USB_TESTING    
       
   123     //    iStatus = KRequestPending;
       
   124     SetActive(); // Tell scheduler a request is active    
       
   125     iTimer.After(iStatus, 10000000); // Set for later
       
   126 
       
   127     
       
   128 #endif
       
   129 
       
   130 
       
   131     }
       
   132 
       
   133 TInt CVRUSBStateHanlder::RunError(TInt aError)
       
   134     {
       
   135     return aError;
       
   136     }
       
   137 
       
   138 EXPORT_C TBool CVRUSBStateHanlder::IsUsbActive()
       
   139     {
       
   140 #ifdef DUMMY_USB_TESTING
       
   141     //dummy
       
   142     return CDummyUSBState::IsUSBActive();
       
   143 #else
       
   144 
       
   145     TInt usbState;
       
   146     TInt err = RProperty::Get(KPSUidUsbWatcher,
       
   147             KUsbWatcherSelectedPersonality, usbState);
       
   148 
       
   149     if (KErrNone == err && KUsbPersonalityIdMS == usbState)
       
   150         {
       
   151         return true;
       
   152         }
       
   153     else
       
   154         {
       
   155         return false;
       
   156         }
       
   157 #endif
       
   158     }
       
   159