35
|
1 |
/*
|
|
2 |
* Copyright (c) 2008 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: Implementation
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include <usbman.h>
|
|
19 |
#include <d32usbdi_errors.h>
|
|
20 |
#include <d32otgdi_errors.h>
|
|
21 |
|
|
22 |
#include "cusbmessagenotificationobserver.h"
|
|
23 |
|
|
24 |
#include "definitions.h"
|
|
25 |
#include "debug.h"
|
|
26 |
#include "panic.h"
|
|
27 |
|
|
28 |
// ---------------------------------------------------------------------------
|
|
29 |
//
|
|
30 |
// ---------------------------------------------------------------------------
|
|
31 |
//
|
|
32 |
CUsbMessageNotificationObserver::CUsbMessageNotificationObserver(RUsb* aUsb) :
|
|
33 |
CActive(EPriorityStandard), iUsb(aUsb)
|
|
34 |
{
|
|
35 |
CActiveScheduler::Add(this);
|
|
36 |
}
|
|
37 |
|
|
38 |
// ---------------------------------------------------------------------------
|
|
39 |
//
|
|
40 |
// ---------------------------------------------------------------------------
|
|
41 |
//
|
|
42 |
void CUsbMessageNotificationObserver::ConstructL()
|
|
43 |
{
|
|
44 |
LOG_FUNC
|
|
45 |
|
|
46 |
}
|
|
47 |
|
|
48 |
// ---------------------------------------------------------------------------
|
|
49 |
//
|
|
50 |
// ---------------------------------------------------------------------------
|
|
51 |
//
|
|
52 |
CUsbMessageNotificationObserver* CUsbMessageNotificationObserver::NewL(
|
|
53 |
RUsb* aUsb)
|
|
54 |
{
|
|
55 |
LOG_FUNC
|
|
56 |
|
|
57 |
CUsbMessageNotificationObserver* self =
|
|
58 |
new (ELeave) CUsbMessageNotificationObserver(aUsb);
|
|
59 |
CleanupStack::PushL(self);
|
|
60 |
self->ConstructL();
|
|
61 |
CleanupStack::Pop(self);
|
|
62 |
return self;
|
|
63 |
}
|
|
64 |
|
|
65 |
// ---------------------------------------------------------------------------
|
|
66 |
//
|
|
67 |
// ---------------------------------------------------------------------------
|
|
68 |
//
|
|
69 |
CUsbMessageNotificationObserver::~CUsbMessageNotificationObserver()
|
|
70 |
{
|
|
71 |
LOG_FUNC
|
|
72 |
|
|
73 |
Cancel();
|
|
74 |
|
|
75 |
iObservers.Close();
|
|
76 |
|
|
77 |
}
|
|
78 |
|
|
79 |
// ---------------------------------------------------------------------------
|
|
80 |
//
|
|
81 |
// ---------------------------------------------------------------------------
|
|
82 |
//
|
|
83 |
void CUsbMessageNotificationObserver::SubscribeL(
|
|
84 |
MUsbMessageNotificationObserver& aObserver)
|
|
85 |
{
|
|
86 |
LOG_FUNC
|
|
87 |
|
|
88 |
// check if the same observer already exist in a list
|
|
89 |
if (KErrNotFound != iObservers.Find(&aObserver))
|
|
90 |
{
|
|
91 |
LOG("Observer already exists");
|
|
92 |
PANIC( EObserverAlreadyExists);
|
|
93 |
return;
|
|
94 |
}
|
|
95 |
iObservers.AppendL(&aObserver);
|
|
96 |
|
|
97 |
if (KFirst == iObservers.Count()) // first item
|
|
98 |
{
|
|
99 |
iUsb->MessageNotification(iStatus, iMessage);
|
|
100 |
SetActive();
|
|
101 |
}
|
|
102 |
}
|
|
103 |
|
|
104 |
// ---------------------------------------------------------------------------
|
|
105 |
//
|
|
106 |
// ---------------------------------------------------------------------------
|
|
107 |
//
|
|
108 |
void CUsbMessageNotificationObserver::UnsubscribeL(
|
|
109 |
MUsbMessageNotificationObserver& aObserver)
|
|
110 |
{
|
|
111 |
LOG_FUNC
|
|
112 |
|
|
113 |
TInt i(iObservers.Find(&aObserver));
|
|
114 |
if (KErrNotFound == i)
|
|
115 |
{
|
|
116 |
LOG("Observer not found" )
|
|
117 |
PANIC( ECanNotFindMessageNotificationObserver);
|
|
118 |
return;
|
|
119 |
}
|
|
120 |
|
|
121 |
iObservers.Remove(i);
|
|
122 |
|
|
123 |
if (0 == iObservers.Count()) // no items
|
|
124 |
{
|
|
125 |
// cancel pending request
|
|
126 |
Cancel();
|
|
127 |
}
|
|
128 |
}
|
|
129 |
|
|
130 |
// ---------------------------------------------------------------------------
|
|
131 |
//
|
|
132 |
// ---------------------------------------------------------------------------
|
|
133 |
//
|
|
134 |
void CUsbMessageNotificationObserver::RunL()
|
|
135 |
{
|
|
136 |
// Log the event
|
|
137 |
LOG1( "Message notification observer iMessage = %d" , iMessage);
|
|
138 |
|
|
139 |
// if error occured, tell to Observers
|
|
140 |
if (KErrNone != iStatus.Int())
|
|
141 |
{
|
|
142 |
for (TInt i(0); i < iObservers.Count(); ++i)
|
|
143 |
{
|
|
144 |
iObservers[i]->MessageNotificationErrorL(iStatus.Int());
|
|
145 |
}
|
|
146 |
return;
|
|
147 |
}
|
|
148 |
|
|
149 |
TInt message(iMessage);
|
|
150 |
|
|
151 |
// re-issue request first
|
|
152 |
iUsb->MessageNotification(iStatus, iMessage);
|
|
153 |
SetActive();
|
|
154 |
|
|
155 |
// then process property change
|
|
156 |
switch (message)
|
|
157 |
{
|
|
158 |
case KErrUsbBadHubPosition:
|
|
159 |
{
|
|
160 |
LOG("HubBadPosition" );
|
|
161 |
|
|
162 |
for (TInt i(0); i < iObservers.Count(); ++i)
|
|
163 |
{
|
|
164 |
iObservers[i]->BadHubPositionL();
|
|
165 |
}
|
|
166 |
break;
|
|
167 |
}
|
|
168 |
case KErrUsbOtgVbusError:
|
|
169 |
{
|
|
170 |
LOG( "VBusError");
|
|
171 |
|
|
172 |
for (TInt i(0); i < iObservers.Count(); ++i)
|
|
173 |
{
|
|
174 |
iObservers[i]->VBusErrorL();
|
|
175 |
}
|
|
176 |
break;
|
|
177 |
}
|
|
178 |
case KUsbMessageSrpReceived:
|
|
179 |
{
|
|
180 |
LOG("SRP received" );
|
|
181 |
|
|
182 |
for (TInt i(0); i < iObservers.Count(); ++i)
|
|
183 |
{
|
|
184 |
iObservers[i]->SrpReceivedL();
|
|
185 |
}
|
|
186 |
break;
|
|
187 |
}
|
|
188 |
case KUsbMessageRequestSession:
|
|
189 |
{
|
|
190 |
LOG("Session requested" );
|
|
191 |
|
|
192 |
for (TInt i(0); i < iObservers.Count(); ++i)
|
|
193 |
{
|
|
194 |
iObservers[i]->SessionRequestedL();
|
|
195 |
}
|
|
196 |
break;
|
|
197 |
}
|
|
198 |
// notify states with other messages
|
|
199 |
default:
|
|
200 |
{
|
|
201 |
|
|
202 |
for (TInt i(0); i < iObservers.Count(); ++i)
|
|
203 |
{
|
|
204 |
iObservers[i]->MessageNotificationReceivedL(message);
|
|
205 |
}
|
|
206 |
break;
|
|
207 |
}
|
|
208 |
|
|
209 |
}
|
|
210 |
|
|
211 |
}
|
|
212 |
|
|
213 |
// ---------------------------------------------------------------------------
|
|
214 |
//
|
|
215 |
// ---------------------------------------------------------------------------
|
|
216 |
//
|
|
217 |
void CUsbMessageNotificationObserver::DoCancel()
|
|
218 |
{
|
|
219 |
iUsb->MessageNotificationCancel();
|
|
220 |
}
|
|
221 |
|
|
222 |
// ---------------------------------------------------------------------------
|
|
223 |
//
|
|
224 |
// ---------------------------------------------------------------------------
|
|
225 |
//
|
|
226 |
TInt CUsbMessageNotificationObserver::RunError(TInt aError)
|
|
227 |
{
|
|
228 |
LOG_FUNC
|
|
229 |
|
|
230 |
LOG1( "aError = %d" , aError);
|
|
231 |
|
|
232 |
// try to recover and continue
|
|
233 |
return KErrNone;
|
|
234 |
|
|
235 |
}
|
|
236 |
|