|
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 "idpinwatcher.h" |
|
25 #include <usb/usbshared.h> |
|
26 |
|
27 CIdPinWatcher* CIdPinWatcher::NewL(MOtgPropertiesObserver* aObserver) |
|
28 { |
|
29 CIdPinWatcher* self = new(ELeave) CIdPinWatcher(aObserver); |
|
30 CleanupStack::PushL(self); |
|
31 self->ConstructL(); |
|
32 CleanupStack::Pop(self); |
|
33 return self; |
|
34 } |
|
35 |
|
36 CIdPinWatcher::~CIdPinWatcher() |
|
37 { |
|
38 Cancel(); |
|
39 iIdPinProp.Close(); |
|
40 } |
|
41 |
|
42 CIdPinWatcher::CIdPinWatcher(MOtgPropertiesObserver* aObserver) |
|
43 : CActive(EPriorityStandard) |
|
44 , iObserver(aObserver), iIdPinValue(EFalse) |
|
45 { |
|
46 CActiveScheduler::Add(this); |
|
47 } |
|
48 |
|
49 void CIdPinWatcher::ConstructL() |
|
50 { |
|
51 User::LeaveIfError(iIdPinProp.Attach(KUidUsbManCategory, KUsbOtgIdPinPresentProperty)); |
|
52 iIdPinProp.Subscribe(iStatus); |
|
53 SetActive(); |
|
54 |
|
55 TInt err = iIdPinProp.Get(iIdPinValue); |
|
56 if (KErrNone != err) |
|
57 { |
|
58 iIdPinValue = EFalse; |
|
59 } |
|
60 } |
|
61 |
|
62 void CIdPinWatcher::DoCancel() |
|
63 { |
|
64 iIdPinProp.Cancel(); |
|
65 } |
|
66 |
|
67 void CIdPinWatcher::RunL() |
|
68 { |
|
69 iIdPinProp.Subscribe(iStatus); |
|
70 SetActive(); |
|
71 |
|
72 TInt err = iIdPinProp.Get(iIdPinValue); |
|
73 if (KErrNone == err) |
|
74 { |
|
75 iObserver->MpsoIdPinStateChanged(iIdPinValue); |
|
76 } |
|
77 else |
|
78 { |
|
79 iIdPinValue = EFalse; |
|
80 } |
|
81 } |
|
82 |
|
83 TInt CIdPinWatcher::IdPinValue() const |
|
84 { |
|
85 return iIdPinValue; |
|
86 } |