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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // streammap.h: defines COpenWfcStreamMap
22 #include <e32std.h> //for RFastLock
23 #include <e32hashtab.h> //for RHashMap
24 #include <graphics/surfacemanager.h>
26 #include <graphics/updateserverprovider.h>
30 class MSurfaceUpdateServerProvider;
31 class CExtensionContainer;
33 NONSHARABLE_CLASS(COpenWfcStreamMap): public CBase
37 * Returns a reference to the singleton instance.
39 * @return The pointer to the singleton instance
41 IMPORT_C static COpenWfcStreamMap& InstanceL();
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.
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.
51 IMPORT_C TInt Reserve(TInt aExpand);
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.
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
60 CSurfaceStream* Find(const TSurfaceId& aSurfaceId);
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.
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
70 CSurfaceStream* AcquireL(const TSurfaceId& aSurfaceId);
72 * Query the number of elements stored in the stream hash map.
74 * @return The number of the key-value pairs stored
76 IMPORT_C TInt Count();
81 * Register a screen number for surface update notifications.
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
88 TInt RegisterScreenNotifications(TInt aScreenNum, TInt aPriority,TInt aInternalVersion);
91 * Retieves the screen updater associate with the specified screen
93 * @param aScreenNum The screen number
94 * @return Pointer to screen updater id successful or NULL otherwise
96 CExtensionContainer* RegisteredScreenNotifications(TInt aScreenNum);
99 * Unregister the screen updater
101 * @param aScreenNum The screen number
102 * @return KErrNone if operation is completed successfully
104 TInt UnregisterScreenNotifications(TInt aScreenNum);
107 * Returns a reference to the surface manager.
109 * @return A reference to the local SurfaceManager
111 RSurfaceManager& SurfaceManager();
114 * Returns a pointer to the main heap
116 * @return A pointer to the main heap
118 IMPORT_C RHeap* GetMainHeap();
126 friend class CSurfaceStream;
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
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
138 TInt LockDestroy(CSurfaceStream* aStream);
146 ~COpenWfcStreamMap();
149 * Auxilliary private class to insure the release of a lock
154 Guard(RFastLock& aLock);
163 COpenWfcStreamMap(const COpenWfcStreamMap&);
165 * Assignment operator
167 COpenWfcStreamMap& operator= (const COpenWfcStreamMap&);
169 * Symbian constructor used with two stage construction pattern
173 Forms a 32-bit hash value from a TSurfaceId.
175 @param aHashKey The 64-bit key to be hashed.
176 @return 32-bit hash value.
178 static TUint32 HashFunction(const TSurfaceId& aHashKey);
180 static TInt COpenWfcStreamMap::DeleteSingleton(TAny* aData);
183 * Mutex used for controlling the access to the native streams map
189 RHashMap<TSurfaceId, CSurfaceStream*> iMap;
191 * Initial HashMap size
193 static const TInt iInitialSize = 0;
195 * Singleton instance placeholder
197 static COpenWfcStreamMap* pInstance;
201 RSurfaceManager iSurfaceManager;
203 RHeap *iMainHeap; //< --This points to main thread's heap--
205 RHashMap<TInt32, CExtensionContainer*> iRegisteredUpdaters; //< Proxy objects for handing surface update notifications.
207 MSurfaceUpdateServerProvider* iSurfUpdateServ; // Pointer to the surface update server
210 #endif /* STREAMMAP_H */