author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Wed, 18 Aug 2010 10:48:20 +0300 | |
changeset 75 | 809df41c314e |
parent 56 | f45583a69686 |
permissions | -rw-r--r-- |
35 | 1 |
/* |
56
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
2 |
* Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies). |
35 | 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: Blink/show Usb indicator notifier implementation |
|
15 |
* |
|
16 |
*/ |
|
17 |
||
18 |
#include <usbuinotif.h> |
|
56
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
19 |
#include <hb/hbcore/hbindicatorsymbian.h> |
35 | 20 |
|
21 |
#include "cusbindicatornotifier.h" |
|
22 |
#include "cusbstate.h" |
|
23 |
#include "definitions.h" |
|
24 |
||
25 |
#include "debug.h" |
|
26 |
#include "panic.h" |
|
27 |
||
28 |
// ======== MEMBER FUNCTIONS ======== |
|
29 |
||
30 |
// ----------------------------------------------------------------------------- |
|
31 |
// Two-phased constructor. |
|
32 |
// ----------------------------------------------------------------------------- |
|
33 |
// |
|
34 |
CUsbIndicatorNotifier* CUsbIndicatorNotifier::NewL( |
|
35 |
CUsbNotifManager& aNotifManager, CUsbOtgWatcher& aOtgWatcher) |
|
36 |
{ |
|
37 |
LOG_FUNC |
|
38 |
||
39 |
CUsbIndicatorNotifier* self = new (ELeave) CUsbIndicatorNotifier( |
|
40 |
aNotifManager, aOtgWatcher); |
|
41 |
CleanupStack::PushL(self); |
|
42 |
self->ConstructL(); |
|
43 |
CleanupStack::Pop(self); |
|
44 |
return self; |
|
45 |
} |
|
46 |
||
47 |
// --------------------------------------------------------------------------- |
|
48 |
// Destructor |
|
49 |
// --------------------------------------------------------------------------- |
|
50 |
// |
|
51 |
CUsbIndicatorNotifier::~CUsbIndicatorNotifier() |
|
52 |
{ |
|
53 |
LOG_FUNC |
|
54 |
||
55 |
Close(); |
|
56 |
||
57 |
if (iOtgWatcher.VBusObserver()) |
|
58 |
{ |
|
59 |
TRAP_IGNORE(iOtgWatcher.VBusObserver()->UnsubscribeL(*this)); |
|
60 |
} |
|
61 |
||
62 |
// Unsubscribe from otg watcher states change notifications |
|
63 |
TRAP_IGNORE(iOtgWatcher.UnsubscribeL(*this)); |
|
56
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
64 |
|
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
65 |
delete iUsbConnectingIndicator; |
35 | 66 |
} |
67 |
||
68 |
// --------------------------------------------------------------------------- |
|
69 |
// C++ constructor |
|
70 |
// --------------------------------------------------------------------------- |
|
71 |
// |
|
72 |
CUsbIndicatorNotifier::CUsbIndicatorNotifier(CUsbNotifManager& aNotifManager, |
|
73 |
CUsbOtgWatcher& aOtgWatcher) : |
|
75
809df41c314e
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
74 |
iOtgWatcher(aOtgWatcher) |
35 | 75 |
{ |
76 |
LOG_FUNC |
|
56
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
77 |
|
35 | 78 |
} |
79 |
||
80 |
// --------------------------------------------------------------------------- |
|
81 |
// Second-phase constructor |
|
82 |
// --------------------------------------------------------------------------- |
|
83 |
// |
|
84 |
void CUsbIndicatorNotifier::ConstructL() |
|
85 |
{ |
|
86 |
LOG_FUNC |
|
87 |
||
56
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
88 |
iUsbConnectingIndicator = CHbIndicatorSymbian::NewL(); |
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
89 |
|
35 | 90 |
// Subscribe for VBus change notifications |
91 |
iOtgWatcher.VBusObserver()->SubscribeL(*this); |
|
92 |
||
93 |
// Subscribe for otg watcher states change notifications |
|
94 |
iOtgWatcher.SubscribeL(*this); |
|
95 |
||
75
809df41c314e
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
96 |
iConnectingIndicatorOn = EFalse; |
809df41c314e
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
97 |
|
35 | 98 |
// check here for condition to set usb indicator |
56
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
99 |
SetIndicator(); |
75
809df41c314e
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
100 |
|
35 | 101 |
} |
102 |
||
103 |
||
104 |
// --------------------------------------------------------------------------- |
|
105 |
// From CUsbNotifier |
|
106 |
// --------------------------------------------------------------------------- |
|
107 |
// |
|
108 |
void CUsbIndicatorNotifier::Close() |
|
109 |
{ |
|
110 |
LOG_FUNC |
|
111 |
||
75
809df41c314e
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
112 |
ToggleConnectingIndicator( EFalse ); |
35 | 113 |
} |
114 |
||
115 |
// --------------------------------------------------------------------------- |
|
116 |
// Set USB indicator On or Off |
|
117 |
// --------------------------------------------------------------------------- |
|
118 |
// |
|
75
809df41c314e
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
119 |
void CUsbIndicatorNotifier::ToggleConnectingIndicator(TBool aEnable) |
35 | 120 |
{ |
75
809df41c314e
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
121 |
LOG1( "toggle connecting indicator = %d" , aEnable); |
56
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
122 |
|
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
123 |
TBool success = ETrue; |
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
124 |
|
75
809df41c314e
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
125 |
if (aEnable && !iConnectingIndicatorOn) |
56
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
126 |
{ |
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
127 |
success = iUsbConnectingIndicator->Activate(KUsbConnectingIndicator); |
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
128 |
LOG1( "calling CHbIndicatorSymbian::Activate(), returned %d", success); |
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
129 |
if (success) |
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
130 |
{ |
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
131 |
iConnectingIndicatorOn = ETrue; |
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
132 |
} |
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
133 |
|
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
134 |
} |
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
135 |
|
75
809df41c314e
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
136 |
if (!aEnable && iConnectingIndicatorOn) |
56
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
137 |
{ |
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
138 |
success = iUsbConnectingIndicator->Deactivate(KUsbConnectingIndicator); |
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
139 |
if (success) |
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
140 |
{ |
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
141 |
iConnectingIndicatorOn = EFalse; |
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
142 |
} |
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
143 |
LOG1( "calling CHbIndicatorSymbian::Deactivate(), returned %d", success); |
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
144 |
} |
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
145 |
|
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
146 |
// if success became false loading the indicator failed, log the error |
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
147 |
if (!success) |
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
148 |
{ |
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
149 |
TInt error = iUsbConnectingIndicator->Error(); |
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
150 |
LOG1( "indicator error is %d", error); |
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
151 |
} |
35 | 152 |
} |
56
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
153 |
|
35 | 154 |
// --------------------------------------------------------------------------- |
155 |
// |
|
156 |
// --------------------------------------------------------------------------- |
|
157 |
// |
|
158 |
void CUsbIndicatorNotifier::OtgWatcherStateChangedL(TUsbStateIds aState) |
|
159 |
{ |
|
75
809df41c314e
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
160 |
LOG_FUNC |
56
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
161 |
SetIndicator(); |
35 | 162 |
} |
163 |
||
164 |
// --------------------------------------------------------------------------- |
|
165 |
// |
|
166 |
// --------------------------------------------------------------------------- |
|
167 |
// |
|
168 |
void CUsbIndicatorNotifier::VBusDownL() |
|
169 |
{ |
|
75
809df41c314e
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
170 |
LOG_FUNC |
56
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
171 |
SetIndicator(); |
35 | 172 |
} |
173 |
||
174 |
// --------------------------------------------------------------------------- |
|
175 |
// |
|
176 |
// --------------------------------------------------------------------------- |
|
177 |
// |
|
178 |
void CUsbIndicatorNotifier::VBusUpL() |
|
179 |
{ |
|
75
809df41c314e
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
180 |
LOG_FUNC |
56
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
181 |
SetIndicator(); |
35 | 182 |
} |
183 |
||
184 |
// --------------------------------------------------------------------------- |
|
185 |
// |
|
186 |
// --------------------------------------------------------------------------- |
|
187 |
// |
|
188 |
void CUsbIndicatorNotifier::VBusObserverErrorL(TInt aError) |
|
189 |
{ |
|
75
809df41c314e
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
190 |
LOG_FUNC |
35 | 191 |
// do nothing |
192 |
} |
|
193 |
||
194 |
// --------------------------------------------------------------------------- |
|
195 |
// |
|
196 |
// --------------------------------------------------------------------------- |
|
197 |
// |
|
56
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
198 |
void CUsbIndicatorNotifier::SetIndicator() |
35 | 199 |
{ |
75
809df41c314e
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
200 |
LOG_FUNC |
35 | 201 |
if (!(iOtgWatcher.IsDeviceA()) || iOtgWatcher.CurrentHostState()->Id() == EUsbStateHostAPeripheral) |
202 |
{ |
|
203 |
// if B or peripheral, than other party (usbwatcher) takes care of usb indicator |
|
204 |
// in combined usbwatcher (if role swap allowed) one class has to manage usb indicator |
|
205 |
return; |
|
206 |
} |
|
207 |
||
75
809df41c314e
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
208 |
// if VBus up and we are not host -> show connecting indicator |
35 | 209 |
if ((iOtgWatcher.VBusObserver()->VBus() == CUsbVBusObserver::EVBusUp) |
210 |
&& (iOtgWatcher.CurrentHostState()->Id() != EUsbStateHostAHost)) |
|
211 |
{ |
|
75
809df41c314e
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
212 |
ToggleConnectingIndicator( ETrue ); |
35 | 213 |
} |
214 |
else |
|
215 |
// Otherwise do not show indicator |
|
216 |
{ |
|
75
809df41c314e
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
56
diff
changeset
|
217 |
ToggleConnectingIndicator( EFalse ); |
35 | 218 |
} |
219 |
} |
|
220 |
||
221 |
// End of file |