author | hgs |
Mon, 13 Sep 2010 15:16:07 +0100 | |
changeset 269 | d57b86b1867a |
parent 176 | af6ec97d9189 |
child 268 | 345b1ca54e88 |
permissions | -rw-r--r-- |
124 | 1 |
// Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 2 |
// All rights reserved. |
3 |
// This component and the accompanying materials are made available |
|
4 |
// under the terms of the License "Eclipse Public License v1.0" |
|
5 |
// which accompanies this distribution, and is available |
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 |
// |
|
8 |
// Initial Contributors: |
|
9 |
// Nokia Corporation - initial contribution. |
|
10 |
// |
|
11 |
// Contributors: |
|
12 |
// |
|
13 |
// Description: |
|
14 |
// Implements a Session of a Symbian OS server for the RUsbMassStorage API |
|
15 |
// |
|
16 |
// |
|
17 |
||
18 |
/** |
|
19 |
@file |
|
20 |
@internalTechnology |
|
21 |
*/ |
|
22 |
||
23 |
#include <e32base.h> |
|
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
24 |
|
0 | 25 |
#include "msctypes.h" |
26 |
#include "shared.h" |
|
27 |
#include "msgservice.h" |
|
28 |
#include "cusbhostmslogicalunit.h" |
|
29 |
#include "cusbhostmsdevice.h" |
|
30 |
#include "msdebug.h" |
|
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
31 |
#include "cusbhostmssession.h" |
0 | 32 |
#include "cusbhostmsdevicethread.h" |
33 |
#include "debug.h" |
|
34 |
||
35 |
/** |
|
36 |
Constructor |
|
37 |
*/ |
|
38 |
TDeviceHandler::TDeviceHandler(CUsbHostMsDevice& aDevice) |
|
39 |
: iDevice(aDevice) |
|
40 |
{ |
|
41 |
__MSFNLOG |
|
42 |
} |
|
43 |
||
44 |
||
45 |
/** |
|
46 |
Services messages directed to a device. Messages associated with a single |
|
47 |
Logical Unit contained by the device are forwarded to the Logical Unit |
|
48 |
Handler. |
|
49 |
||
50 |
@param aMessage |
|
51 |
*/ |
|
52 |
void TDeviceHandler::HandleMessageL(const RMessage2& aMessage) |
|
53 |
{ |
|
54 |
__MSFNLOG |
|
55 |
TLun lun = iDevice.GetAndSetLunL(aMessage); |
|
56 |
||
57 |
switch (aMessage.Function()) |
|
58 |
{ |
|
59 |
case EUsbHostMsSuspendLun: |
|
60 |
iDevice.SuspendLunL(lun); |
|
61 |
break; |
|
62 |
case EUsbHostMsUnRegisterLun: |
|
63 |
iDevice.RemoveLunL(lun); |
|
64 |
break; |
|
65 |
default: |
|
66 |
// Try Logical Unit Handler |
|
67 |
CUsbHostMsLogicalUnit& lu = iDevice.GetLuL(lun); |
|
68 |
TLogicalUnitHandler luHandler(lu); |
|
69 |
luHandler.HandleMessageL(aMessage); |
|
70 |
break; |
|
71 |
} |
|
72 |
} |
|
73 |
||
74 |
||
75 |
/** |
|
76 |
Constructor |
|
77 |
||
78 |
@param aLu Reference to the logical unit object |
|
79 |
*/ |
|
80 |
TLogicalUnitHandler::TLogicalUnitHandler(CUsbHostMsLogicalUnit& aLu) |
|
81 |
: iLu(aLu) |
|
82 |
{ |
|
83 |
__MSFNLOG |
|
84 |
} |
|
85 |
||
86 |
||
87 |
/** |
|
88 |
Services messages directed to a specific Logical Unit. Unrecognized messages |
|
89 |
will cause a PANIC. |
|
90 |
||
91 |
@param aMessage |
|
92 |
*/ |
|
93 |
void TLogicalUnitHandler::HandleMessageL(const RMessage2& aMessage) |
|
94 |
{ |
|
95 |
__MSFNLOG |
|
96 |
switch (aMessage.Function()) |
|
97 |
{ |
|
98 |
case EUsbHostMsNotifyChange: |
|
99 |
iLu.NotifyChange(aMessage); |
|
100 |
break; |
|
101 |
case EUsbHostMsCancelChangeNotifier: |
|
102 |
iLu.CancelChangeNotifierL(); |
|
103 |
break; |
|
104 |
case EUsbHostMsForceRemount: |
|
105 |
iLu.ForceCompleteNotifyChangeL(); |
|
106 |
break; |
|
107 |
case EUsbHostMsRead: |
|
108 |
iLu.ReadL(aMessage); |
|
109 |
break; |
|
110 |
case EUsbHostMsWrite: |
|
111 |
iLu.WriteL(aMessage); |
|
112 |
break; |
|
113 |
case EUsbHostMsErase: |
|
114 |
iLu.EraseL(aMessage); |
|
115 |
break; |
|
116 |
case EUsbHostMsCapacity: |
|
117 |
iLu.CapsL(aMessage); |
|
118 |
break; |
|
119 |
default: |
|
120 |
aMessage.Panic(KUsbHostMsSrvPncCat, EUsbMsPanicIllegalIPC); |
|
121 |
break; |
|
122 |
} |
|
123 |
} |
|
124 |
||
125 |
||
126 |
void CUsbHostMsDeviceThread::DoStartServerL(TAny* aPtr) |
|
127 |
{ |
|
128 |
__MSFNSLOG |
|
129 |
CActiveScheduler* s = new(ELeave) CActiveScheduler; |
|
130 |
CActiveScheduler::Install(s); |
|
131 |
||
132 |
CUsbHostMsDeviceThread* iThread = (CUsbHostMsDeviceThread*)aPtr; |
|
133 |
CActiveScheduler::Add(iThread); |
|
134 |
||
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
135 |
iThread->Start(); |
0 | 136 |
|
137 |
RThread::Rendezvous(KErrNone); |
|
138 |
||
139 |
// |
|
140 |
// Ready to run |
|
141 |
CActiveScheduler::Start(); |
|
142 |
||
143 |
// |
|
144 |
// Cleanup the scheduler |
|
145 |
delete s; |
|
146 |
} |
|
147 |
||
148 |
||
149 |
TInt CUsbHostMsDeviceThread::Entry(TAny* aPtr) |
|
150 |
{ |
|
151 |
__MSFNSLOG |
|
152 |
CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
153 |
if (!cleanup) |
|
154 |
{ |
|
155 |
return KErrNoMemory; |
|
156 |
} |
|
157 |
||
158 |
TRAPD(error, DoStartServerL(aPtr)); |
|
159 |
delete cleanup; |
|
160 |
return error; |
|
161 |
} |
|
162 |
||
163 |
||
164 |
void CUsbHostMsDeviceThread::RunL() |
|
165 |
{ |
|
166 |
__MSFNLOG |
|
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
167 |
|
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
168 |
// called on completion of MessageRequest() or Resume() |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
169 |
User::LeaveIfError(iStatus.Int()); |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
170 |
|
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
171 |
Lock(); |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
172 |
if (iUsbHostMsDevice) |
0 | 173 |
{ |
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
174 |
if (iUsbHostMsDevice->IsSuspended()) |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
175 |
{ |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
176 |
// request resume |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
177 |
Unlock(); |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
178 |
iUsbHostMsDevice->Resume(iStatus); |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
179 |
SetActive(); |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
180 |
return; |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
181 |
} |
0 | 182 |
} |
183 |
||
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
184 |
// process message queue |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
185 |
RMessage2 msg = iRMessage2[iDequeueIndex]; |
0 | 186 |
|
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
187 |
iDequeueIndex++; |
0 | 188 |
|
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
189 |
if(iDequeueIndex >= KMaxNumMessage) |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
190 |
iDequeueIndex = 0; |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
191 |
if(iQueueFull) |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
192 |
iQueueFull = EFalse; |
0 | 193 |
|
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
194 |
HandleMessage(msg); |
0 | 195 |
|
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
196 |
if ((iQueueIndex != iDequeueIndex) || iQueueFull) |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
197 |
{ |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
198 |
// self completion |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
199 |
TRequestStatus* status = &iStatus; |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
200 |
User::RequestComplete(status, KErrNone); |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
201 |
SetActive(); |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
202 |
} |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
203 |
else |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
204 |
{ |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
205 |
iUsbHostMsSession.MessageRequest(iStatus); |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
206 |
SetActive(); |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
207 |
} |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
208 |
Unlock(); |
0 | 209 |
} |
210 |
||
211 |
||
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
212 |
void CUsbHostMsDeviceThread::DoCancel() |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
213 |
{ |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
214 |
TRequestStatus* status = &iStatus; |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
215 |
User::RequestComplete(status, KErrCancel); |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
216 |
} |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
217 |
|
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
218 |
|
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
219 |
TInt CUsbHostMsDeviceThread::RunError(TInt aError) |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
220 |
{ |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
221 |
__HOSTPRINT1(_L(">> HOST RunError returning %d"), aError); |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
222 |
return KErrNone; |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
223 |
} |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
224 |
|
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
225 |
|
0 | 226 |
TInt CUsbHostMsDeviceThread::QueueMsg(const RMessage2& aMsg) |
227 |
{ |
|
228 |
__MSFNLOG |
|
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
229 |
|
0 | 230 |
if (iQueueFull) |
231 |
{ |
|
232 |
return KErrOverflow; |
|
233 |
} |
|
234 |
||
235 |
Lock(); |
|
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
236 |
|
0 | 237 |
iRMessage2[iQueueIndex] = aMsg; |
238 |
iQueueIndex++; |
|
239 |
||
240 |
if (iQueueIndex >= KMaxNumMessage) |
|
241 |
{ |
|
242 |
iQueueIndex = 0; |
|
243 |
} |
|
244 |
||
245 |
if (iQueueIndex == iDequeueIndex) |
|
246 |
{ |
|
247 |
iQueueFull = ETrue; |
|
248 |
} |
|
249 |
Unlock(); |
|
250 |
return KErrNone; |
|
251 |
} |
|
252 |
||
253 |
||
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
254 |
CUsbHostMsDeviceThread::CUsbHostMsDeviceThread(CUsbHostMsSession& aUsbHostMsSession, TUint aToken) |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
255 |
: CActive(EPriorityStandard), |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
256 |
iUsbHostMsSession(aUsbHostMsSession), |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
257 |
iQueueFull(EFalse) |
0 | 258 |
{ |
259 |
__MSFNLOG |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
260 |
TBuf<32> nameBuf; |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
261 |
nameBuf.Format(_L("Host Ms ThreadMutex%8x"), aToken); |
0 | 262 |
iMutex.CreateGlobal(nameBuf,EOwnerProcess); |
263 |
} |
|
264 |
||
265 |
CUsbHostMsDeviceThread::~CUsbHostMsDeviceThread() |
|
266 |
{ |
|
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
267 |
__MSFNLOG |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
268 |
Cancel(); |
0 | 269 |
iMutex.Close(); |
270 |
} |
|
271 |
||
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
272 |
CUsbHostMsDeviceThread* CUsbHostMsDeviceThread::NewL(CUsbHostMsSession& aUsbHostMsSession, TUint aToken) |
0 | 273 |
{ |
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
274 |
__MSFNSLOG |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
275 |
CUsbHostMsDeviceThread* r = new (ELeave) CUsbHostMsDeviceThread(aUsbHostMsSession, aToken); |
0 | 276 |
return r; |
277 |
} |
|
278 |
||
279 |
||
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
280 |
void CUsbHostMsDeviceThread::Start() |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
281 |
{ |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
282 |
iUsbHostMsSession.MessageRequest(iStatus); |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
283 |
SetActive(); |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
284 |
} |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
285 |
|
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
286 |
|
0 | 287 |
/** |
288 |
Handles the request (in the form of a message) received from the client |
|
289 |
@param aMessage The received message |
|
290 |
*/ |
|
291 |
void CUsbHostMsDeviceThread::HandleMessage(const RMessage2& aMessage) |
|
292 |
{ |
|
293 |
__MSFNLOG |
|
294 |
TInt ret = KErrNotReady; |
|
295 |
__HOSTPRINT2(_L(">> HOST DispatchMessageL Function=%d %d"), aMessage.Function(), aMessage.Int3()); |
|
296 |
switch (aMessage.Function()) |
|
297 |
{ |
|
298 |
case EUsbHostMsRegisterInterface: |
|
299 |
TRAP(ret, RegisterInterfaceL(aMessage)); |
|
300 |
break; |
|
301 |
case EUsbHostMsInitialiseInterface: |
|
302 |
TRAP(ret, InitialiseInterfaceL(aMessage)); |
|
303 |
// CUsbInterfaceHandler::GetMaxLun() completes asynchronously |
|
304 |
if (ret) |
|
305 |
{ |
|
306 |
// Error condition needs to be completed |
|
307 |
break; |
|
308 |
} |
|
309 |
return; |
|
310 |
case EUsbHostMsUnRegisterInterface: |
|
176 | 311 |
// Check whether all luns have got uninitialised. |
312 |
for(TInt i = 0, j = iUsbHostMsDevice->GetMaxLun(); i <= j; i++) |
|
313 |
TRAP_IGNORE(iUsbHostMsDevice->RemoveLunL(i)); |
|
0 | 314 |
TRAP(ret, UnRegisterInterfaceL(aMessage)); |
315 |
break; |
|
316 |
case EUsbHostMsRegisterLun: |
|
317 |
TRAP(ret, RegisterLogicalUnitL(aMessage)); |
|
318 |
break; |
|
319 |
case EUsbHostMsGetNumLun: |
|
320 |
TRAP(ret, GetNumLunL(aMessage)); |
|
321 |
break; |
|
322 |
case EUsbHostMsShutdown: |
|
323 |
ret = Shutdown(); |
|
324 |
break; |
|
325 |
default: |
|
326 |
// Try Device Handler and Logical Unit Handler |
|
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
327 |
__ASSERT_DEBUG(iUsbHostMsDevice, User::Invariant()); |
0 | 328 |
TDeviceHandler deviceHandler(*iUsbHostMsDevice); |
329 |
TRAP(ret, deviceHandler.HandleMessageL(aMessage)); |
|
330 |
break; |
|
331 |
} |
|
332 |
__HOSTPRINT1(_L(">> HOST returning %d"), ret); |
|
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
333 |
|
0 | 334 |
if (aMessage.Function() != EUsbHostMsNotifyChange) |
335 |
{ |
|
336 |
aMessage.Complete(ret); |
|
337 |
} |
|
338 |
} |
|
339 |
||
340 |
||
341 |
/** |
|
342 |
Client request to shut down the server |
|
343 |
||
344 |
return KErrNone |
|
345 |
*/ |
|
346 |
TInt CUsbHostMsDeviceThread::Shutdown() |
|
347 |
{ |
|
348 |
__MSFNLOG |
|
349 |
CActiveScheduler::Stop(); |
|
350 |
return KErrNone; |
|
351 |
} |
|
352 |
||
353 |
void CUsbHostMsDeviceThread::GetNumLunL(const RMessage2& aMessage) |
|
354 |
{ |
|
355 |
__MSFNLOG |
|
356 |
if (!iUsbHostMsDevice) |
|
357 |
{ |
|
358 |
User::Leave(KErrNotReady); |
|
359 |
} |
|
360 |
||
361 |
TUint32 maxLun = iUsbHostMsDevice->GetMaxLun() + 1; |
|
362 |
TPtrC8 pLun((TUint8*)&maxLun,sizeof(TUint32)); |
|
363 |
aMessage.WriteL(0,pLun); |
|
364 |
} |
|
365 |
||
366 |
||
367 |
void CUsbHostMsDeviceThread::RegisterInterfaceL(const RMessage2& aMessage) |
|
368 |
{ |
|
369 |
__MSFNLOG |
|
370 |
||
371 |
THostMassStorageConfig msDeviceConfig; |
|
372 |
TPtr8 ptr((TUint8*)&msDeviceConfig,sizeof(THostMassStorageConfig)); |
|
373 |
aMessage.ReadL(0, ptr); |
|
374 |
||
375 |
__HOSTPRINT1(_L("RegisterInterfaceL Token=%d "), msDeviceConfig.iInterfaceToken); |
|
376 |
||
377 |
iUsbHostMsDevice = CUsbHostMsDevice::NewL(msDeviceConfig); |
|
378 |
} |
|
379 |
||
380 |
||
381 |
void CUsbHostMsDeviceThread::InitialiseInterfaceL(const RMessage2& aMessage) |
|
382 |
{ |
|
383 |
__MSFNLOG |
|
384 |
if (!iUsbHostMsDevice) |
|
385 |
{ |
|
386 |
User::Leave(KErrNotReady); |
|
387 |
} |
|
388 |
||
389 |
TRAPD(err, iUsbHostMsDevice->InitialiseL(aMessage)); |
|
390 |
if (err != KErrNone) |
|
391 |
{ |
|
392 |
delete iUsbHostMsDevice; |
|
393 |
iUsbHostMsDevice = NULL; |
|
394 |
User::Leave(err); |
|
395 |
} |
|
396 |
} |
|
397 |
||
398 |
||
399 |
void CUsbHostMsDeviceThread::UnRegisterInterfaceL(const RMessage2& aMessage) |
|
400 |
{ |
|
401 |
__MSFNLOG |
|
402 |
if (!iUsbHostMsDevice) |
|
403 |
{ |
|
404 |
User::Leave(KErrNotReady); |
|
405 |
} |
|
406 |
||
407 |
TRAPD(err, iUsbHostMsDevice->UnInitialiseL()); |
|
408 |
delete iUsbHostMsDevice; |
|
409 |
iUsbHostMsDevice = NULL; |
|
410 |
User::LeaveIfError(err); |
|
411 |
} |
|
412 |
||
413 |
||
414 |
void CUsbHostMsDeviceThread::RegisterLogicalUnitL(const RMessage2& aMessage) |
|
415 |
{ |
|
416 |
if (!iUsbHostMsDevice) |
|
417 |
{ |
|
418 |
User::Leave(KErrNotReady); |
|
419 |
} |
|
420 |
||
421 |
TUint32 iLunId = aMessage.Int0() + 1; // Subssessions need a positive value to store in the handles. We represent Luns as LunId+1 |
|
422 |
TPtrC8 pLun((TUint8*)&iLunId, sizeof(TUint32)); |
|
423 |
aMessage.WriteL(3, pLun); |
|
424 |
iLunId -= 1; // We represent LunId in MSC from 0 to MaxLun-1 as represented in BOT |
|
124 | 425 |
__HOSTPRINT1(_L("RegisterLogicalUnitL LUN=%d "), iLunId); |
0 | 426 |
iUsbHostMsDevice->AddLunL(iLunId); |
427 |
iUsbHostMsDevice->InitLunL(iLunId); |
|
428 |
} |
|
429 |