52
|
1 |
/*
|
|
2 |
* Copyright (c) 2009-2010 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: This implements TUsbIndicatorHandler class.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include <e32std.h>
|
|
19 |
#include <hbindicatorsymbian.h>
|
|
20 |
#include <hbsymbianvariant.h>
|
|
21 |
#include <usbman.h>
|
|
22 |
#include "debug.h"
|
|
23 |
#include "cusbindicatorhandler.h"
|
|
24 |
|
|
25 |
|
|
26 |
// ---------------------------------------------------------------------------
|
|
27 |
// C++ Constructor
|
|
28 |
// ---------------------------------------------------------------------------
|
|
29 |
//
|
|
30 |
|
|
31 |
CUsbIndicatorHandler::CUsbIndicatorHandler()
|
|
32 |
{
|
|
33 |
// No implementation required
|
|
34 |
}
|
|
35 |
|
|
36 |
CUsbIndicatorHandler::~CUsbIndicatorHandler()
|
|
37 |
{
|
|
38 |
delete iSymbianIndicator;
|
|
39 |
|
|
40 |
}
|
|
41 |
|
|
42 |
CUsbIndicatorHandler* CUsbIndicatorHandler::NewLC()
|
|
43 |
{
|
|
44 |
CUsbIndicatorHandler* self = new (ELeave) CUsbIndicatorHandler();
|
|
45 |
CleanupStack::PushL(self);
|
|
46 |
self->ConstructL();
|
|
47 |
return self;
|
|
48 |
}
|
|
49 |
|
|
50 |
CUsbIndicatorHandler* CUsbIndicatorHandler::NewL()
|
|
51 |
{
|
|
52 |
CUsbIndicatorHandler* self = CUsbIndicatorHandler::NewLC();
|
|
53 |
CleanupStack::Pop(); // self;
|
|
54 |
return self;
|
|
55 |
}
|
|
56 |
|
|
57 |
void CUsbIndicatorHandler::ConstructL()
|
|
58 |
{
|
|
59 |
LOG_FUNC
|
|
60 |
|
|
61 |
iDevStateB4Suspend = EUsbDeviceStateUndefined;
|
|
62 |
iSymbianIndicator = CHbIndicatorSymbian::NewL();
|
|
63 |
}
|
|
64 |
|
|
65 |
// ---------------------------------------------------------------------------
|
|
66 |
// Change USB Indicator
|
|
67 |
// ---------------------------------------------------------------------------
|
|
68 |
//
|
|
69 |
void CUsbIndicatorHandler::HandleDeviceStateChangeL( TUsbDeviceState aStateOld,
|
|
70 |
TUsbDeviceState aStateNew, TInt aPersonality )
|
|
71 |
{
|
|
72 |
LOG_FUNC
|
|
73 |
|
|
74 |
LOG2( "USB device state changed: %d ==> %d", aStateOld, aStateNew );
|
|
75 |
|
|
76 |
if ( EUsbDeviceStateAddress == aStateNew ) // Entering addressed state
|
|
77 |
{
|
|
78 |
// going down configured -> addressed
|
|
79 |
if( ( EUsbDeviceStateConfigured == aStateOld ) ||
|
|
80 |
( ( EUsbDeviceStateSuspended == aStateOld ) &&
|
|
81 |
( EUsbDeviceStateConfigured == iDevStateB4Suspend ) ) )
|
|
82 |
{
|
|
83 |
ShowUsbConnectedIndicatorL( EFalse, aPersonality );
|
|
84 |
}
|
|
85 |
|
|
86 |
// connecting indicator will be shown when addressed state is entered going up or down
|
|
87 |
// note that when disconnecting the cable (no need to show connecting indicator)
|
|
88 |
// the state change is CONFIGURED => SUSPENDED => POWERED => UNDEFINED
|
|
89 |
// filter out case of addressed -> suspended -> addressed
|
|
90 |
if ( ( EUsbDeviceStateSuspended != aStateOld ) ||
|
|
91 |
( EUsbDeviceStateAddress != iDevStateB4Suspend) )
|
|
92 |
{
|
|
93 |
ShowUsbAddressedIndicator( ETrue );
|
|
94 |
}
|
|
95 |
}
|
|
96 |
|
|
97 |
else if ( EUsbDeviceStateConfigured == aStateNew ) // Entering configured state
|
|
98 |
{
|
|
99 |
// filter out case of configed -> suspended -> configed
|
|
100 |
if ( ( EUsbDeviceStateSuspended != aStateOld ) ||
|
|
101 |
( EUsbDeviceStateConfigured != iDevStateB4Suspend) )
|
|
102 |
{
|
|
103 |
ShowUsbAddressedIndicator( EFalse );
|
|
104 |
ShowUsbConnectedIndicatorL( ETrue, aPersonality );
|
|
105 |
}
|
|
106 |
}
|
|
107 |
|
|
108 |
else if ( EUsbDeviceStateUndefined == aStateNew ) // Entering undefined
|
|
109 |
{
|
|
110 |
ShowUsbAddressedIndicator( EFalse );
|
|
111 |
ShowUsbConnectedIndicatorL( EFalse, aPersonality );
|
|
112 |
}
|
|
113 |
|
|
114 |
|
|
115 |
else if ( EUsbDeviceStateSuspended == aStateNew )
|
|
116 |
// If current state is suspend, we do not change the indicator, but save
|
|
117 |
// the previous state
|
|
118 |
{
|
|
119 |
iDevStateB4Suspend = aStateOld;
|
|
120 |
}
|
|
121 |
else // New device state is not configured, nor suspended, nor addressed
|
|
122 |
{
|
|
123 |
ShowUsbConnectedIndicatorL( EFalse, aPersonality );
|
|
124 |
}
|
|
125 |
|
|
126 |
}
|
|
127 |
|
|
128 |
// ---------------------------------------------------------------------------
|
|
129 |
// Show USB Indicator
|
|
130 |
// ---------------------------------------------------------------------------
|
|
131 |
//
|
|
132 |
void CUsbIndicatorHandler::ShowUsbConnectedIndicatorL( TBool aActivate, TInt aPersonality )
|
|
133 |
{
|
|
134 |
LOG_FUNC
|
|
135 |
TBool success = EFalse;
|
|
136 |
_LIT(KUsbIndicator, "com.nokia.hb.indicator.usb.device.connected/1.0");
|
|
137 |
|
|
138 |
if (aActivate)
|
|
139 |
{
|
|
140 |
RUsb usbman;
|
|
141 |
User::LeaveIfError(usbman.Connect());
|
|
142 |
CleanupClosePushL(usbman);
|
|
143 |
HBufC* description = NULL;
|
|
144 |
User::LeaveIfError(usbman.GetDescription(aPersonality,
|
|
145 |
description));
|
|
146 |
CleanupStack::PopAndDestroy(&usbman);
|
|
147 |
CleanupStack::PushL(description);
|
|
148 |
CHbSymbianVariant* parameters = CHbSymbianVariant::NewL(description, CHbSymbianVariant::EDes);
|
|
149 |
CleanupStack::PopAndDestroy(description);
|
|
150 |
success = iSymbianIndicator->Activate(KUsbIndicator, parameters);
|
|
151 |
LOG1( "calling CHbIndicatorSymbian::Activate(), returned %d", success);
|
|
152 |
if (!success)
|
|
153 |
{
|
|
154 |
TInt indicatorerror = iSymbianIndicator->Error();
|
|
155 |
LOG1( "activating the indicator failed with %d", indicatorerror);
|
|
156 |
}
|
|
157 |
else
|
|
158 |
{
|
|
159 |
iConnectedIndicatorActive = ETrue;
|
|
160 |
}
|
|
161 |
delete parameters;
|
|
162 |
}
|
|
163 |
else if (iConnectedIndicatorActive)
|
|
164 |
{
|
|
165 |
success = iSymbianIndicator->Deactivate(KUsbIndicator);
|
|
166 |
LOG1( "calling CHbIndicatorSymbian::Deactivate(), returned %d", success);
|
|
167 |
if (success)
|
|
168 |
{
|
|
169 |
iConnectedIndicatorActive = EFalse;
|
|
170 |
}
|
|
171 |
LOG( "calling CHbIndicatorSymbian::Deactivate()");
|
|
172 |
}
|
|
173 |
|
|
174 |
}
|
|
175 |
|
|
176 |
void CUsbIndicatorHandler::ShowUsbAddressedIndicator( TBool aActivate )
|
|
177 |
{
|
|
178 |
LOG_FUNC
|
|
179 |
TBool success = EFalse;
|
|
180 |
_LIT(KUsbIndicator, "com.nokia.hb.indicator.usb.device.inprogress/1.0");
|
|
181 |
if (aActivate)
|
|
182 |
{
|
|
183 |
success = iSymbianIndicator->Activate(KUsbIndicator);
|
|
184 |
LOG1( "calling CHbIndicatorSymbian::Activate(), returned %d", success);
|
|
185 |
if (!success)
|
|
186 |
{
|
|
187 |
TInt indicatorerror = iSymbianIndicator->Error();
|
|
188 |
LOG1( "activating the indicator failed with %d", indicatorerror);
|
|
189 |
}
|
|
190 |
else
|
|
191 |
{
|
|
192 |
iAddressedIndicatorActive = ETrue;
|
|
193 |
}
|
|
194 |
}
|
|
195 |
else if (iAddressedIndicatorActive)
|
|
196 |
{
|
|
197 |
success = iSymbianIndicator->Deactivate(KUsbIndicator);
|
|
198 |
LOG1( "calling CHbIndicatorSymbian::Deactivate(), returned %d", success);
|
|
199 |
if (success)
|
|
200 |
{
|
|
201 |
iAddressedIndicatorActive = EFalse;
|
|
202 |
}
|
|
203 |
LOG( "calling CHbIndicatorSymbian::Deactivate()");
|
|
204 |
}
|
|
205 |
}
|
|
206 |
|
|
207 |
|
|
208 |
|
|
209 |
// End of file
|