williamr@4: // Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). williamr@4: // All rights reserved. williamr@4: // This component and the accompanying materials are made available williamr@4: // under the terms of "Eclipse Public License v1.0" williamr@4: // which accompanies this distribution, and is available williamr@4: // at the URL "http://www.eclipse.org/legal/epl-v10.html". williamr@4: // williamr@4: // Initial Contributors: williamr@4: // Nokia Corporation - initial contribution. williamr@4: // williamr@4: // Contributors: williamr@4: // williamr@4: // Description: williamr@4: // streammap.h: defines COpenWfcStreamMap williamr@4: // williamr@4: // williamr@4: williamr@4: #ifndef STREAMMAP_H williamr@4: #define STREAMMAP_H williamr@4: williamr@4: #include williamr@4: #include //for RFastLock williamr@4: #include //for RHashMap williamr@4: #include williamr@4: williamr@4: #include williamr@4: williamr@4: class CSurfaceStream; williamr@4: class TSurfaceId; williamr@4: class MSurfaceUpdateServerProvider; williamr@4: class CExtensionContainer; williamr@4: williamr@4: NONSHARABLE_CLASS(COpenWfcStreamMap): public CBase williamr@4: { williamr@4: public: williamr@4: /** williamr@4: * Returns a reference to the singleton instance. williamr@4: * williamr@4: * @return The pointer to the singleton instance williamr@4: */ williamr@4: IMPORT_C static COpenWfcStreamMap& InstanceL(); williamr@4: /** williamr@4: * Expands the array to accommodate a specified number of key-value pairs. williamr@4: * If the hash map already has enough space for the specified number of elements, no williamr@4: * action is taken. Any elements already in the map are retained. williamr@4: * williamr@4: * @param aExpand The number of key-value pairs for which space should be allocated. williamr@4: * @return KErrNone if the operation completed aInternalVersion. williamr@4: * @return KErrNoMemory if sufficient memory could not be allocated. williamr@4: */ williamr@4: IMPORT_C TInt Reserve(TInt aExpand); williamr@4: /** williamr@4: * Look up a specified TSurfaceId key in the associative array and return a pointer to the williamr@4: * corresponding to a native stream. The reference counter of the native stream is incremented by one. williamr@4: * williamr@4: * @param aSurfaceId The TSurfaceId key to look up williamr@4: * @return A pointer to the corresponding native stream, if the specified TSurfacId was found williamr@4: * NULL if the look up did not succeed williamr@4: */ williamr@4: CSurfaceStream* Find(const TSurfaceId& aSurfaceId); williamr@4: /** williamr@4: * Look up a specified TSurfaceId key in the associative array and return a pointer to the williamr@4: * corresponding to a native stream. The reference of the native stream is incremented by one. williamr@4: * If no native stream is found a new native stream instance is created. williamr@4: * williamr@4: * @param aSurfaceId The TSurfaceId key to look up williamr@4: * @return A pointer to the corresponding native stream, if the specified TSurfacId was found williamr@4: * NULL if the look up did not succeed williamr@4: */ williamr@4: CSurfaceStream* AcquireL(const TSurfaceId& aSurfaceId); williamr@4: /** williamr@4: * Query the number of elements stored in the stream hash map. williamr@4: * williamr@4: * @return The number of the key-value pairs stored williamr@4: */ williamr@4: IMPORT_C TInt Count(); williamr@4: williamr@4: public: williamr@4: williamr@4: /** williamr@4: * Register a screen number for surface update notifications. williamr@4: * williamr@4: * @param aScreenNum The screen for which we enable the notification mechanism williamr@4: * @param aPriority The priority associated with the screen williamr@4: * @param aPriority The internal version williamr@4: * @return KErrNone if operation is completed successfully williamr@4: */ williamr@4: TInt RegisterScreenNotifications(TInt aScreenNum, TInt aPriority,TInt aInternalVersion); williamr@4: williamr@4: /** williamr@4: * Retieves the screen updater associate with the specified screen williamr@4: * williamr@4: * @param aScreenNum The screen number williamr@4: * @return Pointer to screen updater id successful or NULL otherwise williamr@4: */ williamr@4: CExtensionContainer* RegisteredScreenNotifications(TInt aScreenNum); williamr@4: williamr@4: /** williamr@4: * Unregister the screen updater williamr@4: * williamr@4: * @param aScreenNum The screen number williamr@4: * @return KErrNone if operation is completed successfully williamr@4: */ williamr@4: TInt UnregisterScreenNotifications(TInt aScreenNum); williamr@4: williamr@4: /** williamr@4: * Returns a reference to the surface manager. williamr@4: * williamr@4: * @return A reference to the local SurfaceManager williamr@4: */ williamr@4: RSurfaceManager& SurfaceManager(); williamr@4: williamr@4: /** williamr@4: * Returns a pointer to the main heap williamr@4: * williamr@4: * @return A pointer to the main heap williamr@4: */ williamr@4: IMPORT_C RHeap* GetMainHeap(); williamr@4: williamr@4: /** williamr@4: * Sets the main heap williamr@4: */ williamr@4: void SetMainHeap(); williamr@4: williamr@4: protected: williamr@4: friend class CSurfaceStream; williamr@4: /** williamr@4: * Destroys the specified native stream IF the native stream reference counter is zero. williamr@4: * The counter reference of the native stream is tested prior its destruction and williamr@4: * if positive the destruction will not happen williamr@4: * williamr@4: * @param aStream The stream to be destroyed williamr@4: * @return KErrNone if the native stream is removed williamr@4: * KErrArgument if the parameter is invalid williamr@4: * KErrInUse if the stream has a owner williamr@4: * KErrNotFound if the TSurfaceId key was not found williamr@4: */ williamr@4: TInt LockDestroy(CSurfaceStream* aStream); williamr@4: /** williamr@4: * Constructor williamr@4: */ williamr@4: COpenWfcStreamMap(); williamr@4: /** williamr@4: * Destructor. williamr@4: */ williamr@4: ~COpenWfcStreamMap(); williamr@4: private: williamr@4: /** williamr@4: * Auxilliary private class to insure the release of a lock williamr@4: */ williamr@4: class Guard williamr@4: { williamr@4: public: williamr@4: Guard(RFastLock& aLock); williamr@4: ~Guard(); williamr@4: private: williamr@4: RFastLock& iLock; williamr@4: }; williamr@4: private: williamr@4: /** williamr@4: * Copy constructor williamr@4: */ williamr@4: COpenWfcStreamMap(const COpenWfcStreamMap&); williamr@4: /** williamr@4: * Assignment operator williamr@4: */ williamr@4: COpenWfcStreamMap& operator= (const COpenWfcStreamMap&); williamr@4: /** williamr@4: * Symbian constructor used with two stage construction pattern williamr@4: */ williamr@4: void ConstructL(); williamr@4: /** williamr@4: Forms a 32-bit hash value from a TSurfaceId. williamr@4: williamr@4: @param aHashKey The 64-bit key to be hashed. williamr@4: @return 32-bit hash value. williamr@4: */ williamr@4: static TUint32 HashFunction(const TSurfaceId& aHashKey); williamr@4: williamr@4: static TInt COpenWfcStreamMap::DeleteSingleton(TAny* aData); williamr@4: private: williamr@4: /** williamr@4: * Mutex used for controlling the access to the native streams map williamr@4: */ williamr@4: RFastLock iMutex; williamr@4: /** williamr@4: * Native stream map williamr@4: */ williamr@4: RHashMap iMap; williamr@4: /** williamr@4: * Initial HashMap size williamr@4: */ williamr@4: static const TInt iInitialSize = 0; williamr@4: /** williamr@4: * Singleton instance placeholder williamr@4: */ williamr@4: static COpenWfcStreamMap* pInstance; williamr@4: /** williamr@4: * Surface manager williamr@4: */ williamr@4: RSurfaceManager iSurfaceManager; williamr@4: williamr@4: RHeap *iMainHeap; //< --This points to main thread's heap-- williamr@4: williamr@4: RHashMap iRegisteredUpdaters; //< Proxy objects for handing surface update notifications. williamr@4: williamr@4: MSurfaceUpdateServerProvider* iSurfUpdateServ; // Pointer to the surface update server williamr@4: }; williamr@4: williamr@4: #endif /* STREAMMAP_H */