|
1 // Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "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 // |
|
15 |
|
16 #include "es_commsbuf_internal.h" |
|
17 #include <comms-infras/commsbufpondop.h> |
|
18 #include "commsbufasyncreqinternal.h" |
|
19 #include "commsbufpondintf.h" |
|
20 |
|
21 EXPORT_C CCommsBufAsyncRequest::CCommsBufAsyncRequest(TCommsBufAllocator& aAllocator) |
|
22 :iAllocator(aAllocator) |
|
23 { |
|
24 iLink.iPrev = &iLink; |
|
25 iLink.iNext = &iLink; |
|
26 } |
|
27 |
|
28 EXPORT_C CCommsBufAsyncRequest::~CCommsBufAsyncRequest() |
|
29 { |
|
30 |
|
31 } |
|
32 |
|
33 void CCommsBufAsyncRequest::Alloc(RCommsBufChain& aChain, TInt aSize, TInt aMinSize, TInt aMaxSize, TRequestStatus& aStatus) |
|
34 { |
|
35 iSize = aSize; |
|
36 iMinSize = aMinSize; |
|
37 iMaxSize = aMaxSize; |
|
38 iChain = &aChain; |
|
39 iStatusPtr = &aStatus; |
|
40 *iStatusPtr = KRequestPending; |
|
41 // Try to satify the request syncronously |
|
42 TInt err = aChain.Alloc(iSize, iAllocator); |
|
43 if (err==KErrNone) |
|
44 { |
|
45 #ifdef __CFLOG_ACTIVE |
|
46 __CFLOG_2(KSubsysMBufMgr, KSubsysMBufMgrAsyncAlloc, _L8("RMBufAsyncRequest %x:\tAlloc(aLength %d) request satisfied immediately"), this, aLength); |
|
47 #endif |
|
48 User::RequestComplete(iStatusPtr, KErrNone); |
|
49 return; |
|
50 } |
|
51 |
|
52 // Sync alloc failed, so setup the async alloc request |
|
53 TThreadId id = RThread().Id(); |
|
54 TInt ret = iThread.Open(id); |
|
55 if(ret == KErrNone) |
|
56 { |
|
57 #ifdef __CFLOG_ACTIVE |
|
58 __CFLOG_2(KSubsysMBufMgr, KSubsysMBufMgrAsyncAlloc, _L8("RCommsBufAsyncRequest %x:\tAlloc(aLength %d) starting request"), this, aSize); |
|
59 #endif |
|
60 iAllocator.iPond.StartRequest(*this); |
|
61 } |
|
62 else |
|
63 { |
|
64 #ifdef __CFLOG_ACTIVE |
|
65 __CFLOG_3(KSubsysMBufMgr, KSubsysMBufMgrAsyncAlloc, _L8("RCommsBufAsyncRequest %x:\tAlloc(aLength %d) failed with %d"), this, aSize, ret); |
|
66 #endif |
|
67 } |
|
68 } |
|
69 |
|
70 void CCommsBufAsyncRequest::Cancel() |
|
71 { |
|
72 iAllocator.iPond.CancelRequest(*this); |
|
73 } |
|
74 |
|
75 EXPORT_C void CCommsBufAsyncRequest::Complete(TInt aCode) |
|
76 { |
|
77 #ifdef __CFLOG_ACTIVE |
|
78 __CFLOG_2(KSubsysMBufMgr, KSubsysMBufMgrAsyncAlloc, _L8("RCommsBufAsyncRequest %x:\tComplete(aCode %d)"), this, aCode); |
|
79 #endif |
|
80 iLink.Deque(); |
|
81 if (aCode==KErrNone) |
|
82 { |
|
83 // In future we may have another smarter way of doing this. |
|
84 // Currently RCommsBufQ is internal |
|
85 RCommsBufChain chain(iBufQ.First()); |
|
86 iChain->Assign(chain); |
|
87 iBufQ.Init(); |
|
88 } |
|
89 else |
|
90 { |
|
91 iBufQ.Free(); |
|
92 } |
|
93 |
|
94 iThread.RequestComplete(iStatusPtr, aCode); |
|
95 iThread.Close(); |
|
96 } |
|
97 |