1 // Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies). |
1 // Copyright (c) 2000-2010 Nokia Corporation and/or its subsidiary(-ies). |
2 // All rights reserved. |
2 // All rights reserved. |
3 // This component and the accompanying materials are made available |
3 // This component and the accompanying materials are made available |
4 // under the terms of the License "Eclipse Public License v1.0" |
4 // under the terms of the License "Eclipse Public License v1.0" |
5 // which accompanies this distribution, and is available |
5 // which accompanies this distribution, and is available |
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
119 TChunkCreateInfo chunkInfo; |
118 TChunkCreateInfo chunkInfo; |
120 chunkInfo.iType = TChunkCreateInfo::ESharedKernelMultiple; |
119 chunkInfo.iType = TChunkCreateInfo::ESharedKernelMultiple; |
121 chunkInfo.iMaxSize = aTotalSize; |
120 chunkInfo.iMaxSize = aTotalSize; |
122 chunkInfo.iMapAttr = EMapAttrCachedMax; |
121 chunkInfo.iMapAttr = EMapAttrCachedMax; |
123 chunkInfo.iOwnsMemory = EFalse; |
122 chunkInfo.iOwnsMemory = EFalse; |
124 chunkInfo.iDestroyedDfc = &iCleanup; |
123 chunkInfo.iDestroyedDfc = NULL; |
125 |
124 |
126 TLinAddr chunkMem; |
125 TLinAddr chunkMem; |
127 r = Kern::ChunkCreate(chunkInfo, iChunk, chunkMem, iChunkMapAttr); |
126 r = Kern::ChunkCreate(chunkInfo, iChunk, chunkMem, iChunkMapAttr); |
128 iChunkMem = (TInt8*) chunkMem; |
127 iChunkMem = (TInt8*) chunkMem; |
129 if (r==KErrNone) |
128 if (r==KErrNone) |
136 |
135 |
137 // This method requests closing the chunk. |
136 // This method requests closing the chunk. |
138 // Note that nothing may happen immediately, as something else may have the chunk open. |
137 // Note that nothing may happen immediately, as something else may have the chunk open. |
139 void TUsbcScChunkInfo::Close() |
138 void TUsbcScChunkInfo::Close() |
140 { |
139 { |
141 Kern::ChunkClose(iChunk); |
140 __KTRACE_OPT(KUSB, Kern::Printf("TUsbcScChunkInfo::Close %d", iChunk->AccessCount())); |
|
141 |
|
142 if (Kern::ChunkClose(iChunk)) |
|
143 { |
|
144 __KTRACE_OPT(KUSB, Kern::Printf("TUsbcScChunkInfo::Close1")); |
|
145 ChunkCleanup(); |
|
146 __KTRACE_OPT(KUSB, Kern::Printf("TUsbcScChunkInfo::Close2")); |
|
147 } |
142 } |
148 } |
143 |
149 |
144 |
150 |
145 TInt TUsbcScChunkInfo::ChunkAlloc(TInt aOffset, TInt aSize) |
151 TInt TUsbcScChunkInfo::ChunkAlloc(TInt aOffset, TInt aSize) |
146 { |
152 { |
340 |
346 |
341 // Dont need to round here, as we will round it up on endpoint change. (configuration) |
347 // Dont need to round here, as we will round it up on endpoint change. (configuration) |
342 } |
348 } |
343 } |
349 } |
344 |
350 |
|
351 |
|
352 TBool TUsbcScBuffer::IsRequestPending() |
|
353 { |
|
354 return iStatusList.IsRequestPending(); |
|
355 } |
|
356 |
|
357 TBool TUsbcScStatusList::IsRequestPending() |
|
358 { |
|
359 return (iLength != 0); |
|
360 } |
|
361 |
|
362 |
|
363 |
345 /* |
364 /* |
346 TUsbcScBuffer::StartEndpoint |
365 TUsbcScBuffer::StartEndpoint |
347 |
366 |
348 This method sets the nessesary paramenters to the buffer, for use for a particular endpoint. |
367 This method sets the nessesary paramenters to the buffer, for use for a particular endpoint. |
349 |
368 |
878 Kern::RequestComplete(iClient, iElements[iHead].iStatus, KErrNone); |
897 Kern::RequestComplete(iClient, iElements[iHead].iStatus, KErrNone); |
879 |
898 |
880 iLength--; |
899 iLength--; |
881 iHead = ((iHead+1) & (iSize-1)); |
900 iHead = ((iHead+1) & (iSize-1)); |
882 } |
901 } |
|
902 |
|
903 |
|
904 void TUsbcScStatusList::SetClient(DThread& aThread) |
|
905 { |
|
906 iClient = &aThread; |
|
907 } |
|
908 |
883 |
909 |
884 // End TUsbcScStatusList |
910 // End TUsbcScStatusList |
885 |
911 |
886 /*****************************************************************************\ |
912 /*****************************************************************************\ |
887 * TRealizeInfo * |
913 * TRealizeInfo * |
1238 } |
1264 } |
1239 |
1265 |
1240 if (iRealizeCalled) |
1266 if (iRealizeCalled) |
1241 { |
1267 { |
1242 // Close Chunk |
1268 // Close Chunk |
|
1269 __KTRACE_OPT(KUSB, Kern::Printf("iChunkInfo->Close()")); |
1243 iChunkInfo->Close(); |
1270 iChunkInfo->Close(); |
1244 // ChunkInfo will delete itself with DFC, but the pointer here is no longer needed. |
1271 // ChunkInfo will delete itself with DFC, but the pointer here is no longer needed. |
1245 iChunkInfo=NULL; |
1272 iChunkInfo=NULL; |
1246 } |
1273 } |
1247 __KTRACE_OPT(KUSB, Kern::Printf("about to SafeClose")); |
1274 __KTRACE_OPT(KUSB, Kern::Printf("about to SafeClose")); |
1248 Kern::SafeClose((DObject*&)iClient, NULL); |
1275 Kern::SafeClose((DObject*&)iClient, NULL); |
|
1276 __KTRACE_OPT(KUSB, Kern::Printf("about to SafeClose1")); |
1249 } |
1277 } |
1250 |
1278 |
1251 |
1279 |
1252 // |
1280 // |
1253 // DoCreate - Create channel |
1281 // DoCreate - Create channel |
1324 m.Complete(KErrNone, EFalse); |
1352 m.Complete(KErrNone, EFalse); |
1325 return; |
1353 return; |
1326 } |
1354 } |
1327 |
1355 |
1328 TInt r; |
1356 TInt r; |
|
1357 |
|
1358 if (aMsg->Client() != iClient) |
|
1359 { |
|
1360 m.Complete(KErrAccessDenied, ETrue); |
|
1361 return; |
|
1362 } |
|
1363 |
1329 if (id < 0) |
1364 if (id < 0) |
1330 { |
1365 { |
1331 // DoRequest |
1366 // DoRequest |
1332 TRequestStatus* pS = (TRequestStatus*) m.Ptr0(); |
1367 TRequestStatus* pS = (TRequestStatus*) m.Ptr0(); |
1333 r = DoRequest(~id, pS, m.Ptr1(), m.Ptr2()); |
1368 r = DoRequest(~id, pS, m.Ptr1(), m.Ptr2()); |
2253 // Overriding DObject virtual |
2288 // Overriding DObject virtual |
2254 // |
2289 // |
2255 TInt DLddUsbcScChannel::RequestUserHandle(DThread* aThread, TOwnerType /*aType*/) |
2290 TInt DLddUsbcScChannel::RequestUserHandle(DThread* aThread, TOwnerType /*aType*/) |
2256 { |
2291 { |
2257 __KTRACE_OPT(KUSB, Kern::Printf("DLddUsbcScChannel::RequestUserHandle")); |
2292 __KTRACE_OPT(KUSB, Kern::Printf("DLddUsbcScChannel::RequestUserHandle")); |
2258 // The USB client LDD is not designed for a channel to be shared between |
2293 // The USB client LDD can share across process, but can't use simultanously. |
2259 // threads. It saves a pointer to the current thread when it is opened, and |
2294 // This mean if transfer the handle to another process, can't access this channel |
2260 // uses this to complete any asynchronous requests. |
2295 // in the origin process and any call to the channel will return with KErrAccessDenied. |
2261 // It is therefore not acceptable for the handle to be duplicated and used |
2296 // If there is async request scheduled, can't transfer channel handle to another process |
2262 // by another thread: |
2297 // and return KErrAccessDenied. |
2263 if (aThread == iClient) |
2298 if (aThread == iClient) |
2264 { |
2299 { |
2265 return KErrNone; |
2300 return KErrNone; |
2266 } |
2301 } |
2267 else |
2302 else |
2268 { |
2303 { |
2269 return KErrAccessDenied; |
2304 //check if async request has been called |
|
2305 for (TInt i = 1; i < KUsbcMaxRequests; i++) |
|
2306 { |
|
2307 if (iRequestStatus[i] != NULL) |
|
2308 { |
|
2309 return KErrAccessDenied; |
|
2310 } |
|
2311 } |
|
2312 |
|
2313 if (iBuffers) |
|
2314 { |
|
2315 for (TInt i=0; i<(iNumBuffers+2); i++) |
|
2316 { |
|
2317 if (iBuffers[i].IsRequestPending()) |
|
2318 { |
|
2319 return KErrAccessDenied; |
|
2320 } |
|
2321 } |
|
2322 } |
|
2323 |
|
2324 |
|
2325 Kern::SafeClose((DObject*&)iClient, NULL); |
|
2326 iClient = aThread; |
|
2327 iClient->Open(); |
|
2328 if (iBuffers) |
|
2329 { |
|
2330 for (TInt i=0; i<(iNumBuffers+2); i++) |
|
2331 { |
|
2332 iBuffers[i].iStatusList.SetClient(*iClient); |
|
2333 } |
|
2334 } |
|
2335 __KTRACE_OPT(KUSB, Kern::Printf("DLddUsbcScChannel::handle %d", iChunkInfo->iChunk->AccessCount())); |
|
2336 return KErrNone; |
2270 } |
2337 } |
2271 } |
2338 } |
2272 |
2339 |
2273 inline TInt DLddUsbcScChannel::GetRealEpForEpResource(TInt aEndpoint, TInt& aRealEp) |
2340 inline TInt DLddUsbcScChannel::GetRealEpForEpResource(TInt aEndpoint, TInt& aRealEp) |
2274 { |
2341 { |