|
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 // streammap.h: defines COpenWfcStreamMap |
|
15 // |
|
16 // |
|
17 |
|
18 #ifndef STREAMMAP_H |
|
19 #define STREAMMAP_H |
|
20 |
|
21 #include <e32base.h> |
|
22 #include <e32std.h> //for RFastLock |
|
23 #include <e32hashtab.h> //for RHashMap |
|
24 #include <graphics/surfacemanager.h> |
|
25 |
|
26 #include <graphics/updateserverprovider.h> |
|
27 |
|
28 class CSurfaceStream; |
|
29 class TSurfaceId; |
|
30 class MSurfaceUpdateServerProvider; |
|
31 class CExtensionContainer; |
|
32 |
|
33 NONSHARABLE_CLASS(COpenWfcStreamMap): public CBase |
|
34 { |
|
35 public: |
|
36 /** |
|
37 * Returns a reference to the singleton instance. |
|
38 * |
|
39 * @return The pointer to the singleton instance |
|
40 */ |
|
41 IMPORT_C static COpenWfcStreamMap& InstanceL(); |
|
42 /** |
|
43 * Expands the array to accommodate a specified number of key-value pairs. |
|
44 * If the hash map already has enough space for the specified number of elements, no |
|
45 * action is taken. Any elements already in the map are retained. |
|
46 * |
|
47 * @param aExpand The number of key-value pairs for which space should be allocated. |
|
48 * @return KErrNone if the operation completed aInternalVersion. |
|
49 * @return KErrNoMemory if sufficient memory could not be allocated. |
|
50 */ |
|
51 IMPORT_C TInt Reserve(TInt aExpand); |
|
52 /** |
|
53 * Look up a specified TSurfaceId key in the associative array and return a pointer to the |
|
54 * corresponding to a native stream. The reference counter of the native stream is incremented by one. |
|
55 * |
|
56 * @param aSurfaceId The TSurfaceId key to look up |
|
57 * @return A pointer to the corresponding native stream, if the specified TSurfacId was found |
|
58 * NULL if the look up did not succeed |
|
59 */ |
|
60 CSurfaceStream* Find(const TSurfaceId& aSurfaceId); |
|
61 /** |
|
62 * Look up a specified TSurfaceId key in the associative array and return a pointer to the |
|
63 * corresponding to a native stream. The reference of the native stream is incremented by one. |
|
64 * If no native stream is found a new native stream instance is created. |
|
65 * |
|
66 * @param aSurfaceId The TSurfaceId key to look up |
|
67 * @return A pointer to the corresponding native stream, if the specified TSurfacId was found |
|
68 * NULL if the look up did not succeed |
|
69 */ |
|
70 CSurfaceStream* AcquireL(const TSurfaceId& aSurfaceId); |
|
71 /** |
|
72 * Query the number of elements stored in the stream hash map. |
|
73 * |
|
74 * @return The number of the key-value pairs stored |
|
75 */ |
|
76 IMPORT_C TInt Count(); |
|
77 |
|
78 public: |
|
79 |
|
80 /** |
|
81 * Register a screen number for surface update notifications. |
|
82 * |
|
83 * @param aScreenNum The screen for which we enable the notification mechanism |
|
84 * @param aPriority The priority associated with the screen |
|
85 * @param aPriority The internal version |
|
86 * @return KErrNone if operation is completed successfully |
|
87 */ |
|
88 TInt RegisterScreenNotifications(TInt aScreenNum, TInt aPriority,TInt aInternalVersion); |
|
89 |
|
90 /** |
|
91 * Retieves the screen updater associate with the specified screen |
|
92 * |
|
93 * @param aScreenNum The screen number |
|
94 * @return Pointer to screen updater id successful or NULL otherwise |
|
95 */ |
|
96 CExtensionContainer* RegisteredScreenNotifications(TInt aScreenNum); |
|
97 |
|
98 /** |
|
99 * Unregister the screen updater |
|
100 * |
|
101 * @param aScreenNum The screen number |
|
102 * @return KErrNone if operation is completed successfully |
|
103 */ |
|
104 TInt UnregisterScreenNotifications(TInt aScreenNum); |
|
105 |
|
106 /** |
|
107 * Returns a reference to the surface manager. |
|
108 * |
|
109 * @return A reference to the local SurfaceManager |
|
110 */ |
|
111 RSurfaceManager& SurfaceManager(); |
|
112 |
|
113 /** |
|
114 * Returns a pointer to the main heap |
|
115 * |
|
116 * @return A pointer to the main heap |
|
117 */ |
|
118 IMPORT_C RHeap* GetMainHeap(); |
|
119 |
|
120 /** |
|
121 * Sets the main heap |
|
122 */ |
|
123 void SetMainHeap(); |
|
124 |
|
125 protected: |
|
126 friend class CSurfaceStream; |
|
127 /** |
|
128 * Destroys the specified native stream IF the native stream reference counter is zero. |
|
129 * The counter reference of the native stream is tested prior its destruction and |
|
130 * if positive the destruction will not happen |
|
131 * |
|
132 * @param aStream The stream to be destroyed |
|
133 * @return KErrNone if the native stream is removed |
|
134 * KErrArgument if the parameter is invalid |
|
135 * KErrInUse if the stream has a owner |
|
136 * KErrNotFound if the TSurfaceId key was not found |
|
137 */ |
|
138 TInt LockDestroy(CSurfaceStream* aStream); |
|
139 /** |
|
140 * Constructor |
|
141 */ |
|
142 COpenWfcStreamMap(); |
|
143 /** |
|
144 * Destructor. |
|
145 */ |
|
146 ~COpenWfcStreamMap(); |
|
147 private: |
|
148 /** |
|
149 * Auxilliary private class to insure the release of a lock |
|
150 */ |
|
151 class Guard |
|
152 { |
|
153 public: |
|
154 Guard(RFastLock& aLock); |
|
155 ~Guard(); |
|
156 private: |
|
157 RFastLock& iLock; |
|
158 }; |
|
159 private: |
|
160 /** |
|
161 * Copy constructor |
|
162 */ |
|
163 COpenWfcStreamMap(const COpenWfcStreamMap&); |
|
164 /** |
|
165 * Assignment operator |
|
166 */ |
|
167 COpenWfcStreamMap& operator= (const COpenWfcStreamMap&); |
|
168 /** |
|
169 * Symbian constructor used with two stage construction pattern |
|
170 */ |
|
171 void ConstructL(); |
|
172 /** |
|
173 Forms a 32-bit hash value from a TSurfaceId. |
|
174 |
|
175 @param aHashKey The 64-bit key to be hashed. |
|
176 @return 32-bit hash value. |
|
177 */ |
|
178 static TUint32 HashFunction(const TSurfaceId& aHashKey); |
|
179 |
|
180 static TInt COpenWfcStreamMap::DeleteSingleton(TAny* aData); |
|
181 private: |
|
182 /** |
|
183 * Mutex used for controlling the access to the native streams map |
|
184 */ |
|
185 RFastLock iMutex; |
|
186 /** |
|
187 * Native stream map |
|
188 */ |
|
189 RHashMap<TSurfaceId, CSurfaceStream*> iMap; |
|
190 /** |
|
191 * Initial HashMap size |
|
192 */ |
|
193 static const TInt iInitialSize = 0; |
|
194 /** |
|
195 * Singleton instance placeholder |
|
196 */ |
|
197 static COpenWfcStreamMap* pInstance; |
|
198 /** |
|
199 * Surface manager |
|
200 */ |
|
201 RSurfaceManager iSurfaceManager; |
|
202 |
|
203 RHeap *iMainHeap; //< --This points to main thread's heap-- |
|
204 |
|
205 RHashMap<TInt32, CExtensionContainer*> iRegisteredUpdaters; //< Proxy objects for handing surface update notifications. |
|
206 |
|
207 MSurfaceUpdateServerProvider* iSurfUpdateServ; // Pointer to the surface update server |
|
208 }; |
|
209 |
|
210 #endif /* STREAMMAP_H */ |