|
1 /* |
|
2 * Copyright (c) 2007 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: Watches USB states |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "cusbstatewatcher.h" |
|
20 #include "debug.h" |
|
21 |
|
22 // --------------------------------------------------------------------------- |
|
23 // Two-phase construction |
|
24 // --------------------------------------------------------------------------- |
|
25 // |
|
26 CUsbStateWatcher* CUsbStateWatcher::NewL(CUsbDevCon& aObserver, RDevUsbcClient& aLdd) |
|
27 { |
|
28 |
|
29 FLOG( _L( "[USBDEVCON]\tCUsbStateWatcher::NewL" ) ); |
|
30 |
|
31 CUsbStateWatcher* self = new (ELeave) CUsbStateWatcher(aObserver, aLdd); |
|
32 CleanupStack::PushL(self); |
|
33 self->ConstructL(); |
|
34 CleanupStack::Pop(self); |
|
35 return self; |
|
36 } |
|
37 |
|
38 // --------------------------------------------------------------------------- |
|
39 // Default construction |
|
40 // --------------------------------------------------------------------------- |
|
41 // |
|
42 CUsbStateWatcher::CUsbStateWatcher(CUsbDevCon& aObserver, RDevUsbcClient& aLdd) : |
|
43 CActive(EPriorityMore), |
|
44 iState(EUsbcNoState), |
|
45 iObserver(aObserver), |
|
46 iLdd(aLdd) |
|
47 |
|
48 { |
|
49 CActiveScheduler::Add(this); |
|
50 } |
|
51 |
|
52 // --------------------------------------------------------------------------- |
|
53 // Two-phase construction |
|
54 // --------------------------------------------------------------------------- |
|
55 // |
|
56 void CUsbStateWatcher::ConstructL() |
|
57 { |
|
58 } |
|
59 |
|
60 // --------------------------------------------------------------------------- |
|
61 // Destruction |
|
62 // --------------------------------------------------------------------------- |
|
63 // |
|
64 CUsbStateWatcher::~CUsbStateWatcher() |
|
65 { |
|
66 Cancel(); |
|
67 } |
|
68 |
|
69 // --------------------------------------------------------------------------- |
|
70 // Cancellation |
|
71 // --------------------------------------------------------------------------- |
|
72 // |
|
73 void CUsbStateWatcher::DoCancel() |
|
74 { |
|
75 iLdd.AlternateDeviceStatusNotifyCancel(); |
|
76 } |
|
77 |
|
78 // ---------------------------------------------------------------------------- |
|
79 // Standard active object error function. |
|
80 // ---------------------------------------------------------------------------- |
|
81 // |
|
82 TInt CUsbStateWatcher::RunError( TInt /*aError*/ ) |
|
83 { |
|
84 return KErrNone; |
|
85 } |
|
86 |
|
87 // --------------------------------------------------------------------------- |
|
88 // USB state has changed |
|
89 // --------------------------------------------------------------------------- |
|
90 // |
|
91 void CUsbStateWatcher::RunL() |
|
92 { |
|
93 if (!(iState & KUsbAlternateSetting)) |
|
94 { |
|
95 iObserver.ActAccordinglyToUsbStateL(TUsbcDeviceState(iState)); |
|
96 } |
|
97 else |
|
98 { |
|
99 // Alternate interface setting changed to iDeviceState & ~KUsbAlternateSetting |
|
100 } |
|
101 } |
|
102 |
|
103 // --------------------------------------------------------------------------- |
|
104 // Start listening to USB state changes |
|
105 // --------------------------------------------------------------------------- |
|
106 // |
|
107 void CUsbStateWatcher::Activate() |
|
108 { |
|
109 |
|
110 FLOG( _L( "[USBDEVCON]\tCUsbStateWatcher::Activate" ) ); |
|
111 |
|
112 if(IsActive()) |
|
113 { |
|
114 return; |
|
115 } |
|
116 |
|
117 iLdd.AlternateDeviceStatusNotify(iStatus, iState); |
|
118 SetActive(); |
|
119 FLOG( _L( "[USBDEVCON]\tCUsbStateWatcher::Activate end" ) ); |
|
120 |
|
121 } |
|
122 |
|
123 |