|
1 /* |
|
2 * Copyright (c) 2008-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: |
|
15 * Talks directly to the USB Logical Device Driver (LDD) and |
|
16 * watches any state changes |
|
17 * |
|
18 */ |
|
19 |
|
20 /** |
|
21 @file |
|
22 */ |
|
23 |
|
24 #include "vbuswatcher.h" |
|
25 #include <usb/usbshared.h> |
|
26 |
|
27 CVBusWatcher* CVBusWatcher::NewL(MOtgPropertiesObserver* aObserver) |
|
28 { |
|
29 CVBusWatcher* self = new(ELeave) CVBusWatcher(aObserver); |
|
30 CleanupStack::PushL(self); |
|
31 self->ConstructL(); |
|
32 CleanupStack::Pop(self); |
|
33 return self; |
|
34 } |
|
35 |
|
36 CVBusWatcher::~CVBusWatcher() |
|
37 { |
|
38 Cancel(); |
|
39 iVBusProp.Close(); |
|
40 } |
|
41 |
|
42 CVBusWatcher::CVBusWatcher(MOtgPropertiesObserver* aObserver) |
|
43 : CActive(EPriorityStandard) |
|
44 , iObserver(aObserver), iVBusState(EFalse) |
|
45 { |
|
46 CActiveScheduler::Add(this); |
|
47 } |
|
48 |
|
49 void CVBusWatcher::ConstructL() |
|
50 { |
|
51 User::LeaveIfError(iVBusProp.Attach(KUidUsbManCategory, KUsbOtgVBusPoweredProperty)); |
|
52 iVBusProp.Subscribe(iStatus); |
|
53 SetActive(); |
|
54 |
|
55 TInt err = iVBusProp.Get(iVBusState); |
|
56 if (KErrNone != err) |
|
57 { |
|
58 #ifndef __WINS__ |
|
59 iVBusState = EFalse; |
|
60 #else |
|
61 iVBusState = ETrue; |
|
62 #endif |
|
63 } |
|
64 } |
|
65 |
|
66 void CVBusWatcher::DoCancel() |
|
67 { |
|
68 iVBusProp.Cancel(); |
|
69 } |
|
70 |
|
71 void CVBusWatcher::RunL() |
|
72 { |
|
73 iVBusProp.Subscribe(iStatus); |
|
74 SetActive(); |
|
75 |
|
76 TInt err = iVBusProp.Get(iVBusState); |
|
77 if (KErrNone == err) |
|
78 { |
|
79 iObserver->MpsoVBusStateChanged(iVBusState); |
|
80 } |
|
81 else |
|
82 { |
|
83 #ifndef __WINS__ |
|
84 iVBusState = EFalse; |
|
85 #else |
|
86 iVBusState = ETrue; |
|
87 #endif |
|
88 iObserver->MpsoVBusStateChanged(iVBusState); |
|
89 } |
|
90 } |
|
91 |
|
92 TInt CVBusWatcher::VBusState() const |
|
93 { |
|
94 return iVBusState; |
|
95 } |