author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Wed, 23 Jun 2010 19:20:39 +0300 | |
changeset 56 | f45583a69686 |
parent 35 | 9d8b04ca6939 |
child 63 | ef2686f7597e |
child 75 | 809df41c314e |
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) : |
|
74 |
CUsbNotifier(aNotifManager, KUsbUiNotifOtgIndicator, NULL), iOtgWatcher( |
|
75 |
aOtgWatcher) |
|
76 |
{ |
|
77 |
LOG_FUNC |
|
56
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
78 |
|
35 | 79 |
} |
80 |
||
81 |
// --------------------------------------------------------------------------- |
|
82 |
// Second-phase constructor |
|
83 |
// --------------------------------------------------------------------------- |
|
84 |
// |
|
85 |
void CUsbIndicatorNotifier::ConstructL() |
|
86 |
{ |
|
87 |
LOG_FUNC |
|
88 |
||
56
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
89 |
iUsbConnectingIndicator = CHbIndicatorSymbian::NewL(); |
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
90 |
|
35 | 91 |
// Subscribe for VBus change notifications |
92 |
iOtgWatcher.VBusObserver()->SubscribeL(*this); |
|
93 |
||
94 |
// Subscribe for otg watcher states change notifications |
|
95 |
iOtgWatcher.SubscribeL(*this); |
|
96 |
||
97 |
// 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
|
98 |
SetIndicator(); |
35 | 99 |
} |
100 |
||
101 |
// --------------------------------------------------------------------------- |
|
102 |
// Show/hide static icon of the indicator. |
|
103 |
// If the indicator is blinking, stop blinking it and show/hide the static |
|
104 |
// form of the indicator. |
|
105 |
// --------------------------------------------------------------------------- |
|
106 |
// |
|
56
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
107 |
void CUsbIndicatorNotifier::ShowStatic(TBool aVisible) |
35 | 108 |
{ |
109 |
LOG_FUNC |
|
110 |
||
111 |
LOG1("aVisible = %d" , aVisible); |
|
112 |
||
56
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
113 |
SetIndicatorState(aVisible |
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
114 |
? EIndicatorStateOn |
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
115 |
: EIndicatorStateOff); |
35 | 116 |
} |
117 |
||
118 |
// --------------------------------------------------------------------------- |
|
119 |
// |
|
120 |
// --------------------------------------------------------------------------- |
|
121 |
// |
|
56
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
122 |
void CUsbIndicatorNotifier::Blink() |
35 | 123 |
{ |
124 |
LOG_FUNC |
|
125 |
||
56
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
126 |
SetIndicatorState( EIndicatorConnecting ); |
35 | 127 |
} |
128 |
||
129 |
// --------------------------------------------------------------------------- |
|
130 |
// From base class CUsbNotifier |
|
131 |
// --------------------------------------------------------------------------- |
|
132 |
// |
|
133 |
void CUsbIndicatorNotifier::ShowL() |
|
134 |
{ |
|
135 |
LOG_FUNC |
|
136 |
||
56
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
137 |
ShowStatic(ETrue); |
35 | 138 |
} |
139 |
||
140 |
// --------------------------------------------------------------------------- |
|
141 |
// From CUsbNotifier |
|
142 |
// --------------------------------------------------------------------------- |
|
143 |
// |
|
144 |
void CUsbIndicatorNotifier::Close() |
|
145 |
{ |
|
146 |
LOG_FUNC |
|
147 |
||
56
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
148 |
ShowStatic(EFalse); |
35 | 149 |
} |
150 |
||
151 |
// --------------------------------------------------------------------------- |
|
152 |
// Set USB indicator On or Off |
|
153 |
// --------------------------------------------------------------------------- |
|
154 |
// |
|
56
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
155 |
void CUsbIndicatorNotifier::SetIndicatorState(const TInt aState) |
35 | 156 |
{ |
157 |
LOG1( "USB indicator State = %d" , aState); |
|
56
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
158 |
|
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
159 |
TBool success = ETrue; |
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
160 |
|
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
161 |
if ((aState == EIndicatorConnecting) && !iConnectingIndicatorOn) |
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
162 |
{ |
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
163 |
success = iUsbConnectingIndicator->Activate(KUsbConnectingIndicator); |
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
164 |
LOG1( "calling CHbIndicatorSymbian::Activate(), returned %d", success); |
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
165 |
if (success) |
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
166 |
{ |
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
167 |
iConnectingIndicatorOn = ETrue; |
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
168 |
} |
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
169 |
|
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
170 |
} |
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
171 |
|
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
172 |
if ((aState != EIndicatorConnecting) && iConnectingIndicatorOn) |
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
173 |
{ |
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
174 |
success = iUsbConnectingIndicator->Deactivate(KUsbConnectingIndicator); |
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
175 |
if (success) |
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
176 |
{ |
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
177 |
iConnectingIndicatorOn = EFalse; |
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
178 |
} |
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
179 |
LOG1( "calling CHbIndicatorSymbian::Deactivate(), returned %d", success); |
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
180 |
} |
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
181 |
|
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
182 |
// 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
|
183 |
if (!success) |
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
184 |
{ |
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
185 |
TInt error = iUsbConnectingIndicator->Error(); |
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
186 |
LOG1( "indicator error is %d", error); |
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
187 |
} |
35 | 188 |
} |
56
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
189 |
|
35 | 190 |
// --------------------------------------------------------------------------- |
191 |
// |
|
192 |
// --------------------------------------------------------------------------- |
|
193 |
// |
|
194 |
void CUsbIndicatorNotifier::OtgWatcherStateChangedL(TUsbStateIds aState) |
|
195 |
{ |
|
56
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
196 |
SetIndicator(); |
35 | 197 |
} |
198 |
||
199 |
// --------------------------------------------------------------------------- |
|
200 |
// |
|
201 |
// --------------------------------------------------------------------------- |
|
202 |
// |
|
203 |
void CUsbIndicatorNotifier::VBusDownL() |
|
204 |
{ |
|
56
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
205 |
SetIndicator(); |
35 | 206 |
} |
207 |
||
208 |
// --------------------------------------------------------------------------- |
|
209 |
// |
|
210 |
// --------------------------------------------------------------------------- |
|
211 |
// |
|
212 |
void CUsbIndicatorNotifier::VBusUpL() |
|
213 |
{ |
|
56
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
214 |
SetIndicator(); |
35 | 215 |
} |
216 |
||
217 |
// --------------------------------------------------------------------------- |
|
218 |
// |
|
219 |
// --------------------------------------------------------------------------- |
|
220 |
// |
|
221 |
void CUsbIndicatorNotifier::VBusObserverErrorL(TInt aError) |
|
222 |
{ |
|
223 |
// do nothing |
|
224 |
} |
|
225 |
||
226 |
// --------------------------------------------------------------------------- |
|
227 |
// |
|
228 |
// --------------------------------------------------------------------------- |
|
229 |
// |
|
56
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
230 |
void CUsbIndicatorNotifier::SetIndicator() |
35 | 231 |
{ |
232 |
if (!(iOtgWatcher.IsDeviceA()) || iOtgWatcher.CurrentHostState()->Id() == EUsbStateHostAPeripheral) |
|
233 |
{ |
|
234 |
// if B or peripheral, than other party (usbwatcher) takes care of usb indicator |
|
235 |
// in combined usbwatcher (if role swap allowed) one class has to manage usb indicator |
|
236 |
return; |
|
237 |
} |
|
238 |
||
239 |
// if VBus Up and we are host -> show indicator |
|
240 |
if ((iOtgWatcher.VBusObserver()->VBus() == CUsbVBusObserver::EVBusUp) |
|
241 |
&& (iOtgWatcher.CurrentHostState()->Id() == EUsbStateHostAHost)) |
|
242 |
{ |
|
56
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
243 |
ShowStatic(ETrue); |
35 | 244 |
} |
245 |
// if VBus up and we are not host -> Blink indicator |
|
246 |
else if ((iOtgWatcher.VBusObserver()->VBus() == CUsbVBusObserver::EVBusUp) |
|
247 |
&& (iOtgWatcher.CurrentHostState()->Id() != EUsbStateHostAHost)) |
|
248 |
{ |
|
56
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
249 |
Blink(); |
35 | 250 |
} |
251 |
else |
|
252 |
// Otherwise do not show indicator |
|
253 |
{ |
|
56
f45583a69686
Revision: 201023
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
254 |
ShowStatic(EFalse); |
35 | 255 |
} |
256 |
} |
|
257 |
||
258 |
// End of file |