|
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: Asynchronous allocation from the system shared buffer pool |
|
14 // |
|
15 |
|
16 #ifndef __SYSTEMSHAREDASYNCALLOC_H__ |
|
17 #define __SYSTEMSHAREDASYNCALLOC_H__ |
|
18 |
|
19 #include <es_commsbuf.h> |
|
20 #include <elements/rworkerlock.h> |
|
21 |
|
22 /** |
|
23 Notifies the asyncronous request completion or error |
|
24 |
|
25 @internalTechnology |
|
26 */ |
|
27 class MAsyncAllocNotifier |
|
28 { |
|
29 public: |
|
30 virtual void OnCompletion() =0; |
|
31 virtual void OnError(TInt aError) =0; |
|
32 }; |
|
33 |
|
34 class CSystemSharedBufPool; |
|
35 |
|
36 /** |
|
37 Asynchronous allocation from the single system shared pool |
|
38 |
|
39 @internalTechnology |
|
40 |
|
41 */ |
|
42 NONSHARABLE_CLASS(CSystemSharedPoolAsyncAlloc) : public CActive |
|
43 { |
|
44 friend class CSystemSharedAsyncAlloc; |
|
45 public: |
|
46 CSystemSharedPoolAsyncAlloc(CSystemSharedBufPool& aPool, MAsyncAllocNotifier& aNotifer); |
|
47 ~CSystemSharedPoolAsyncAlloc(); |
|
48 |
|
49 void Activate(TInt aFreeBufs); |
|
50 void Deactivate(); |
|
51 private: |
|
52 // From CActive |
|
53 void RunL(); |
|
54 TInt RunError(TInt aError); |
|
55 void DoCancel(); |
|
56 |
|
57 private: |
|
58 CSystemSharedBufPool& iPool; |
|
59 MAsyncAllocNotifier& iNotifier; |
|
60 }; |
|
61 |
|
62 class CSystemSharedBufPool; |
|
63 /** |
|
64 Manages the asynchronous allocation from the system shared pools. |
|
65 @internalTechnology |
|
66 |
|
67 */ |
|
68 NONSHARABLE_CLASS(CSystemSharedAsyncAlloc) : public CActive, public MAsyncAllocNotifier |
|
69 { |
|
70 enum TAsyncRequestState |
|
71 { |
|
72 EMakeRequest = 0, |
|
73 ECancelRequest, |
|
74 }; |
|
75 |
|
76 public: |
|
77 static CSystemSharedAsyncAlloc* New(const RPointerArray<CSystemSharedBufPool>& aPools); |
|
78 ~CSystemSharedAsyncAlloc(); |
|
79 void StartRequest(CCommsBufAsyncRequest& aRequest); |
|
80 void CancelRequest(CCommsBufAsyncRequest& aRequest); |
|
81 |
|
82 private: |
|
83 CSystemSharedAsyncAlloc(); |
|
84 TInt Construct(const RPointerArray<CSystemSharedBufPool>& aPools); |
|
85 void MakePoolAsyncRequest(); |
|
86 void MakePoolRequest(); |
|
87 void CancelPoolAsyncRequest(); |
|
88 void CancelAllPoolRequest(); |
|
89 |
|
90 void ActivateSelf(); |
|
91 void CompleteSelf(); |
|
92 void CancelSelf(); |
|
93 |
|
94 // From MAsyncAllocNotifier |
|
95 virtual void OnCompletion(); |
|
96 virtual void OnError(TInt aError); |
|
97 |
|
98 // From CActive |
|
99 void RunL(); |
|
100 void DoCancel(); |
|
101 |
|
102 void CompleteAsyncAllocs(); |
|
103 |
|
104 |
|
105 private: |
|
106 RPointerArray<CSystemSharedPoolAsyncAlloc> iAsyncAllocPools; |
|
107 TAsyncRequestState iRequestState; |
|
108 RThread iOwnerThread; |
|
109 TBool iSignalled; |
|
110 RWorkerLock iAsynAllocLock; |
|
111 TDblQue<CCommsBufAsyncRequest> iAllocsPending; |
|
112 }; |
|
113 |
|
114 #endif // __SYSTEMSHAREDASYNCALLOC_H__ |