author | hgs |
Wed, 22 Sep 2010 10:53:45 +0100 | |
changeset 271 | dc268b18d709 |
parent 176 | af6ec97d9189 |
child 294 | 039a3e647356 |
child 297 | b2826f67641f |
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 |
{ |
271 | 176 |
|
177 |
RMessage2 msg = iRMessage2[iDequeueIndex]; |
|
178 |
if (msg.Function() != EUsbHostMsSuspendLun) |
|
179 |
{ |
|
180 |
// request resume |
|
181 |
Unlock(); |
|
182 |
iUsbHostMsDevice->Resume(iStatus); |
|
183 |
SetActive(); |
|
184 |
return; |
|
185 |
} |
|
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
186 |
} |
0 | 187 |
} |
188 |
||
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
189 |
// process message queue |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
190 |
RMessage2 msg = iRMessage2[iDequeueIndex]; |
0 | 191 |
|
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
192 |
iDequeueIndex++; |
0 | 193 |
|
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
194 |
if(iDequeueIndex >= KMaxNumMessage) |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
195 |
iDequeueIndex = 0; |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
196 |
if(iQueueFull) |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
197 |
iQueueFull = EFalse; |
0 | 198 |
|
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
199 |
HandleMessage(msg); |
0 | 200 |
|
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
201 |
if ((iQueueIndex != iDequeueIndex) || iQueueFull) |
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 |
// self completion |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
204 |
TRequestStatus* status = &iStatus; |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
205 |
User::RequestComplete(status, KErrNone); |
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 |
else |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
209 |
{ |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
210 |
iUsbHostMsSession.MessageRequest(iStatus); |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
211 |
SetActive(); |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
212 |
} |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
213 |
Unlock(); |
0 | 214 |
} |
215 |
||
216 |
||
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
217 |
void CUsbHostMsDeviceThread::DoCancel() |
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 |
TRequestStatus* status = &iStatus; |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
220 |
User::RequestComplete(status, KErrCancel); |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
221 |
} |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
222 |
|
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 |
TInt CUsbHostMsDeviceThread::RunError(TInt aError) |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
225 |
{ |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
226 |
__HOSTPRINT1(_L(">> HOST RunError returning %d"), aError); |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
227 |
return KErrNone; |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
228 |
} |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
229 |
|
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
230 |
|
0 | 231 |
TInt CUsbHostMsDeviceThread::QueueMsg(const RMessage2& aMsg) |
232 |
{ |
|
233 |
__MSFNLOG |
|
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
234 |
|
0 | 235 |
if (iQueueFull) |
236 |
{ |
|
237 |
return KErrOverflow; |
|
238 |
} |
|
239 |
||
240 |
Lock(); |
|
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
241 |
|
0 | 242 |
iRMessage2[iQueueIndex] = aMsg; |
243 |
iQueueIndex++; |
|
244 |
||
245 |
if (iQueueIndex >= KMaxNumMessage) |
|
246 |
{ |
|
247 |
iQueueIndex = 0; |
|
248 |
} |
|
249 |
||
250 |
if (iQueueIndex == iDequeueIndex) |
|
251 |
{ |
|
252 |
iQueueFull = ETrue; |
|
253 |
} |
|
254 |
Unlock(); |
|
255 |
return KErrNone; |
|
256 |
} |
|
257 |
||
258 |
||
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
259 |
CUsbHostMsDeviceThread::CUsbHostMsDeviceThread(CUsbHostMsSession& aUsbHostMsSession, TUint aToken) |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
260 |
: CActive(EPriorityStandard), |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
261 |
iUsbHostMsSession(aUsbHostMsSession), |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
262 |
iQueueFull(EFalse) |
0 | 263 |
{ |
264 |
__MSFNLOG |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
265 |
TBuf<32> nameBuf; |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
266 |
nameBuf.Format(_L("Host Ms ThreadMutex%8x"), aToken); |
0 | 267 |
iMutex.CreateGlobal(nameBuf,EOwnerProcess); |
268 |
} |
|
269 |
||
270 |
CUsbHostMsDeviceThread::~CUsbHostMsDeviceThread() |
|
271 |
{ |
|
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
272 |
__MSFNLOG |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
273 |
Cancel(); |
0 | 274 |
iMutex.Close(); |
275 |
} |
|
276 |
||
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
277 |
CUsbHostMsDeviceThread* CUsbHostMsDeviceThread::NewL(CUsbHostMsSession& aUsbHostMsSession, TUint aToken) |
0 | 278 |
{ |
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
279 |
__MSFNSLOG |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
280 |
CUsbHostMsDeviceThread* r = new (ELeave) CUsbHostMsDeviceThread(aUsbHostMsSession, aToken); |
0 | 281 |
return r; |
282 |
} |
|
283 |
||
284 |
||
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
285 |
void CUsbHostMsDeviceThread::Start() |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
286 |
{ |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
287 |
iUsbHostMsSession.MessageRequest(iStatus); |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
288 |
SetActive(); |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
289 |
} |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
290 |
|
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
291 |
|
0 | 292 |
/** |
293 |
Handles the request (in the form of a message) received from the client |
|
294 |
@param aMessage The received message |
|
295 |
*/ |
|
296 |
void CUsbHostMsDeviceThread::HandleMessage(const RMessage2& aMessage) |
|
297 |
{ |
|
298 |
__MSFNLOG |
|
299 |
TInt ret = KErrNotReady; |
|
300 |
__HOSTPRINT2(_L(">> HOST DispatchMessageL Function=%d %d"), aMessage.Function(), aMessage.Int3()); |
|
301 |
switch (aMessage.Function()) |
|
302 |
{ |
|
303 |
case EUsbHostMsRegisterInterface: |
|
304 |
TRAP(ret, RegisterInterfaceL(aMessage)); |
|
305 |
break; |
|
306 |
case EUsbHostMsInitialiseInterface: |
|
307 |
TRAP(ret, InitialiseInterfaceL(aMessage)); |
|
308 |
// CUsbInterfaceHandler::GetMaxLun() completes asynchronously |
|
309 |
if (ret) |
|
310 |
{ |
|
311 |
// Error condition needs to be completed |
|
312 |
break; |
|
313 |
} |
|
314 |
return; |
|
315 |
case EUsbHostMsUnRegisterInterface: |
|
176 | 316 |
// Check whether all luns have got uninitialised. |
271 | 317 |
if (iUsbHostMsDevice) |
318 |
{ |
|
319 |
for(TInt i = 0, j = iUsbHostMsDevice->GetMaxLun(); i <= j; i++) |
|
320 |
TRAP_IGNORE(iUsbHostMsDevice->RemoveLunL(i)); |
|
321 |
} |
|
0 | 322 |
TRAP(ret, UnRegisterInterfaceL(aMessage)); |
323 |
break; |
|
324 |
case EUsbHostMsRegisterLun: |
|
325 |
TRAP(ret, RegisterLogicalUnitL(aMessage)); |
|
326 |
break; |
|
327 |
case EUsbHostMsGetNumLun: |
|
328 |
TRAP(ret, GetNumLunL(aMessage)); |
|
329 |
break; |
|
330 |
case EUsbHostMsShutdown: |
|
331 |
ret = Shutdown(); |
|
332 |
break; |
|
333 |
default: |
|
334 |
// 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
|
335 |
__ASSERT_DEBUG(iUsbHostMsDevice, User::Invariant()); |
0 | 336 |
TDeviceHandler deviceHandler(*iUsbHostMsDevice); |
337 |
TRAP(ret, deviceHandler.HandleMessageL(aMessage)); |
|
338 |
break; |
|
339 |
} |
|
340 |
__HOSTPRINT1(_L(">> HOST returning %d"), ret); |
|
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
341 |
|
0 | 342 |
if (aMessage.Function() != EUsbHostMsNotifyChange) |
343 |
{ |
|
344 |
aMessage.Complete(ret); |
|
345 |
} |
|
346 |
} |
|
347 |
||
348 |
||
349 |
/** |
|
350 |
Client request to shut down the server |
|
351 |
||
352 |
return KErrNone |
|
353 |
*/ |
|
354 |
TInt CUsbHostMsDeviceThread::Shutdown() |
|
355 |
{ |
|
356 |
__MSFNLOG |
|
357 |
CActiveScheduler::Stop(); |
|
358 |
return KErrNone; |
|
359 |
} |
|
360 |
||
361 |
void CUsbHostMsDeviceThread::GetNumLunL(const RMessage2& aMessage) |
|
362 |
{ |
|
363 |
__MSFNLOG |
|
364 |
if (!iUsbHostMsDevice) |
|
365 |
{ |
|
366 |
User::Leave(KErrNotReady); |
|
367 |
} |
|
368 |
||
369 |
TUint32 maxLun = iUsbHostMsDevice->GetMaxLun() + 1; |
|
370 |
TPtrC8 pLun((TUint8*)&maxLun,sizeof(TUint32)); |
|
371 |
aMessage.WriteL(0,pLun); |
|
372 |
} |
|
373 |
||
374 |
||
375 |
void CUsbHostMsDeviceThread::RegisterInterfaceL(const RMessage2& aMessage) |
|
376 |
{ |
|
377 |
__MSFNLOG |
|
378 |
||
379 |
THostMassStorageConfig msDeviceConfig; |
|
380 |
TPtr8 ptr((TUint8*)&msDeviceConfig,sizeof(THostMassStorageConfig)); |
|
381 |
aMessage.ReadL(0, ptr); |
|
382 |
||
383 |
__HOSTPRINT1(_L("RegisterInterfaceL Token=%d "), msDeviceConfig.iInterfaceToken); |
|
384 |
||
385 |
iUsbHostMsDevice = CUsbHostMsDevice::NewL(msDeviceConfig); |
|
386 |
} |
|
387 |
||
388 |
||
389 |
void CUsbHostMsDeviceThread::InitialiseInterfaceL(const RMessage2& aMessage) |
|
390 |
{ |
|
391 |
__MSFNLOG |
|
392 |
if (!iUsbHostMsDevice) |
|
393 |
{ |
|
394 |
User::Leave(KErrNotReady); |
|
395 |
} |
|
396 |
||
397 |
TRAPD(err, iUsbHostMsDevice->InitialiseL(aMessage)); |
|
398 |
if (err != KErrNone) |
|
399 |
{ |
|
400 |
delete iUsbHostMsDevice; |
|
401 |
iUsbHostMsDevice = NULL; |
|
402 |
User::Leave(err); |
|
403 |
} |
|
404 |
} |
|
405 |
||
406 |
||
407 |
void CUsbHostMsDeviceThread::UnRegisterInterfaceL(const RMessage2& aMessage) |
|
408 |
{ |
|
409 |
__MSFNLOG |
|
410 |
if (!iUsbHostMsDevice) |
|
411 |
{ |
|
412 |
User::Leave(KErrNotReady); |
|
413 |
} |
|
414 |
||
415 |
TRAPD(err, iUsbHostMsDevice->UnInitialiseL()); |
|
416 |
delete iUsbHostMsDevice; |
|
417 |
iUsbHostMsDevice = NULL; |
|
418 |
User::LeaveIfError(err); |
|
419 |
} |
|
420 |
||
421 |
||
422 |
void CUsbHostMsDeviceThread::RegisterLogicalUnitL(const RMessage2& aMessage) |
|
423 |
{ |
|
424 |
if (!iUsbHostMsDevice) |
|
425 |
{ |
|
426 |
User::Leave(KErrNotReady); |
|
427 |
} |
|
428 |
||
429 |
TUint32 iLunId = aMessage.Int0() + 1; // Subssessions need a positive value to store in the handles. We represent Luns as LunId+1 |
|
430 |
TPtrC8 pLun((TUint8*)&iLunId, sizeof(TUint32)); |
|
431 |
aMessage.WriteL(3, pLun); |
|
432 |
iLunId -= 1; // We represent LunId in MSC from 0 to MaxLun-1 as represented in BOT |
|
124 | 433 |
__HOSTPRINT1(_L("RegisterLogicalUnitL LUN=%d "), iLunId); |
0 | 434 |
iUsbHostMsDevice->AddLunL(iLunId); |
435 |
iUsbHostMsDevice->InitLunL(iLunId); |
|
436 |
} |
|
437 |