35
|
1 |
/*
|
|
2 |
* Copyright (c) 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: Blink/show Usb indicator notifier implementation
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include <AknSmallIndicator.h>
|
|
19 |
#include <avkon.hrh>
|
|
20 |
#include <usbuinotif.h>
|
|
21 |
|
|
22 |
#include "cusbindicatornotifier.h"
|
|
23 |
#include "cusbstate.h"
|
|
24 |
#include "definitions.h"
|
|
25 |
|
|
26 |
#include "debug.h"
|
|
27 |
#include "panic.h"
|
|
28 |
|
|
29 |
// ======== MEMBER FUNCTIONS ========
|
|
30 |
|
|
31 |
// -----------------------------------------------------------------------------
|
|
32 |
// Two-phased constructor.
|
|
33 |
// -----------------------------------------------------------------------------
|
|
34 |
//
|
|
35 |
CUsbIndicatorNotifier* CUsbIndicatorNotifier::NewL(
|
|
36 |
CUsbNotifManager& aNotifManager, CUsbOtgWatcher& aOtgWatcher)
|
|
37 |
{
|
|
38 |
LOG_FUNC
|
|
39 |
|
|
40 |
CUsbIndicatorNotifier* self = new (ELeave) CUsbIndicatorNotifier(
|
|
41 |
aNotifManager, aOtgWatcher);
|
|
42 |
CleanupStack::PushL(self);
|
|
43 |
self->ConstructL();
|
|
44 |
CleanupStack::Pop(self);
|
|
45 |
return self;
|
|
46 |
}
|
|
47 |
|
|
48 |
// ---------------------------------------------------------------------------
|
|
49 |
// Destructor
|
|
50 |
// ---------------------------------------------------------------------------
|
|
51 |
//
|
|
52 |
CUsbIndicatorNotifier::~CUsbIndicatorNotifier()
|
|
53 |
{
|
|
54 |
LOG_FUNC
|
|
55 |
|
|
56 |
Close();
|
|
57 |
|
|
58 |
if (iOtgWatcher.VBusObserver())
|
|
59 |
{
|
|
60 |
TRAP_IGNORE(iOtgWatcher.VBusObserver()->UnsubscribeL(*this));
|
|
61 |
}
|
|
62 |
|
|
63 |
// Unsubscribe from otg watcher states change notifications
|
|
64 |
TRAP_IGNORE(iOtgWatcher.UnsubscribeL(*this));
|
|
65 |
}
|
|
66 |
|
|
67 |
// ---------------------------------------------------------------------------
|
|
68 |
// C++ constructor
|
|
69 |
// ---------------------------------------------------------------------------
|
|
70 |
//
|
|
71 |
CUsbIndicatorNotifier::CUsbIndicatorNotifier(CUsbNotifManager& aNotifManager,
|
|
72 |
CUsbOtgWatcher& aOtgWatcher) :
|
|
73 |
CUsbNotifier(aNotifManager, KUsbUiNotifOtgIndicator, NULL), iOtgWatcher(
|
|
74 |
aOtgWatcher)
|
|
75 |
{
|
|
76 |
LOG_FUNC
|
|
77 |
|
|
78 |
//To be changed to EAknIndicatorStateAnimate and remove iIconBlinkingTimer
|
|
79 |
//when AVKON implements animation form of usb indicator.
|
|
80 |
iIndicatorState = EAknIndicatorStateOn;
|
|
81 |
}
|
|
82 |
|
|
83 |
// ---------------------------------------------------------------------------
|
|
84 |
// Second-phase constructor
|
|
85 |
// ---------------------------------------------------------------------------
|
|
86 |
//
|
|
87 |
void CUsbIndicatorNotifier::ConstructL()
|
|
88 |
{
|
|
89 |
LOG_FUNC
|
|
90 |
|
|
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
|
|
98 |
SetIndicatorL();
|
|
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 |
//
|
|
107 |
void CUsbIndicatorNotifier::ShowStaticL(TBool aVisible)
|
|
108 |
{
|
|
109 |
LOG_FUNC
|
|
110 |
|
|
111 |
LOG1("aVisible = %d" , aVisible);
|
|
112 |
|
|
113 |
SetIndicatorStateL(aVisible
|
|
114 |
? EAknIndicatorStateOn
|
|
115 |
: EAknIndicatorStateOff);
|
|
116 |
}
|
|
117 |
|
|
118 |
// ---------------------------------------------------------------------------
|
|
119 |
//
|
|
120 |
// ---------------------------------------------------------------------------
|
|
121 |
//
|
|
122 |
void CUsbIndicatorNotifier::BlinkL()
|
|
123 |
{
|
|
124 |
LOG_FUNC
|
|
125 |
|
|
126 |
SetIndicatorStateL( EAknIndicatorStateAnimate );
|
|
127 |
}
|
|
128 |
|
|
129 |
// ---------------------------------------------------------------------------
|
|
130 |
// From base class CUsbNotifier
|
|
131 |
// ---------------------------------------------------------------------------
|
|
132 |
//
|
|
133 |
void CUsbIndicatorNotifier::ShowL()
|
|
134 |
{
|
|
135 |
LOG_FUNC
|
|
136 |
|
|
137 |
ShowStaticL(ETrue);
|
|
138 |
}
|
|
139 |
|
|
140 |
// ---------------------------------------------------------------------------
|
|
141 |
// From CUsbNotifier
|
|
142 |
// ---------------------------------------------------------------------------
|
|
143 |
//
|
|
144 |
void CUsbIndicatorNotifier::Close()
|
|
145 |
{
|
|
146 |
LOG_FUNC
|
|
147 |
|
|
148 |
TRAP_IGNORE( ShowStaticL(EFalse) );
|
|
149 |
}
|
|
150 |
|
|
151 |
// ---------------------------------------------------------------------------
|
|
152 |
// Set USB indicator On or Off
|
|
153 |
// ---------------------------------------------------------------------------
|
|
154 |
//
|
|
155 |
void CUsbIndicatorNotifier::SetIndicatorStateL(const TInt aState)
|
|
156 |
{
|
|
157 |
|
|
158 |
LOG1( "USB indicator State = %d" , aState);
|
|
159 |
|
|
160 |
CAknSmallIndicator* indicator = CAknSmallIndicator::NewLC(TUid::Uid(
|
|
161 |
EAknIndicatorUSBConnection));
|
|
162 |
indicator->SetIndicatorStateL(aState);
|
|
163 |
CleanupStack::PopAndDestroy(indicator); //indicator
|
|
164 |
}
|
|
165 |
|
|
166 |
// ---------------------------------------------------------------------------
|
|
167 |
//
|
|
168 |
// ---------------------------------------------------------------------------
|
|
169 |
//
|
|
170 |
void CUsbIndicatorNotifier::OtgWatcherStateChangedL(TUsbStateIds aState)
|
|
171 |
{
|
|
172 |
SetIndicatorL();
|
|
173 |
}
|
|
174 |
|
|
175 |
// ---------------------------------------------------------------------------
|
|
176 |
//
|
|
177 |
// ---------------------------------------------------------------------------
|
|
178 |
//
|
|
179 |
void CUsbIndicatorNotifier::VBusDownL()
|
|
180 |
{
|
|
181 |
SetIndicatorL();
|
|
182 |
}
|
|
183 |
|
|
184 |
// ---------------------------------------------------------------------------
|
|
185 |
//
|
|
186 |
// ---------------------------------------------------------------------------
|
|
187 |
//
|
|
188 |
void CUsbIndicatorNotifier::VBusUpL()
|
|
189 |
{
|
|
190 |
SetIndicatorL();
|
|
191 |
}
|
|
192 |
|
|
193 |
// ---------------------------------------------------------------------------
|
|
194 |
//
|
|
195 |
// ---------------------------------------------------------------------------
|
|
196 |
//
|
|
197 |
void CUsbIndicatorNotifier::VBusObserverErrorL(TInt aError)
|
|
198 |
{
|
|
199 |
// do nothing
|
|
200 |
}
|
|
201 |
|
|
202 |
// ---------------------------------------------------------------------------
|
|
203 |
//
|
|
204 |
// ---------------------------------------------------------------------------
|
|
205 |
//
|
|
206 |
void CUsbIndicatorNotifier::SetIndicatorL()
|
|
207 |
{
|
|
208 |
if (!(iOtgWatcher.IsDeviceA()) || iOtgWatcher.CurrentHostState()->Id() == EUsbStateHostAPeripheral)
|
|
209 |
{
|
|
210 |
// if B or peripheral, than other party (usbwatcher) takes care of usb indicator
|
|
211 |
// in combined usbwatcher (if role swap allowed) one class has to manage usb indicator
|
|
212 |
return;
|
|
213 |
}
|
|
214 |
|
|
215 |
// if VBus Up and we are host -> show indicator
|
|
216 |
if ((iOtgWatcher.VBusObserver()->VBus() == CUsbVBusObserver::EVBusUp)
|
|
217 |
&& (iOtgWatcher.CurrentHostState()->Id() == EUsbStateHostAHost))
|
|
218 |
{
|
|
219 |
ShowStaticL(ETrue);
|
|
220 |
}
|
|
221 |
// if VBus up and we are not host -> Blink indicator
|
|
222 |
else if ((iOtgWatcher.VBusObserver()->VBus() == CUsbVBusObserver::EVBusUp)
|
|
223 |
&& (iOtgWatcher.CurrentHostState()->Id() != EUsbStateHostAHost))
|
|
224 |
{
|
|
225 |
BlinkL();
|
|
226 |
}
|
|
227 |
else
|
|
228 |
// Otherwise do not show indicator
|
|
229 |
{
|
|
230 |
ShowStaticL(EFalse);
|
|
231 |
}
|
|
232 |
}
|
|
233 |
|
|
234 |
// End of file
|