Update contrib.
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.cpp: creates and maintaines the association between native stream and a TSurfaceId
18 #include "streammap.h"
19 #include <graphics/updateserverprovider.h>
20 #include <graphics/surfacemanager.h>
21 #include <e32property.h>
24 #include "openwfcpanic.h"
25 #include "surfacestream.h"
26 #include "contentupdateproxy.h"
28 static const TInt KOpenWfcInteropCleanupKey = 0x10286FC5;
30 COpenWfcStreamMap* COpenWfcStreamMap::pInstance = NULL;
32 TUint32 COpenWfcStreamMap::HashFunction(const TSurfaceId& aHashKey)
34 TPckgC<TSurfaceId> pckg(aHashKey);
35 return DefaultHash::Des8(pckg);
38 EXPORT_C COpenWfcStreamMap& COpenWfcStreamMap::InstanceL()
40 // would have been nice to try to protect this area with a mutex, however,
41 // the preliminary analyses show we can guarantee the safe creation of the mutex
42 // by invoking InstanceL() from the place the CGce instances are created
43 // If necessary, in future, the code can be expanded by using a named mutex.
46 COpenWfcStreamMap* newInstance = new(ELeave)COpenWfcStreamMap();
47 CleanupStack::PushL(newInstance);
48 newInstance->ConstructL();
49 CleanupStack::Pop(newInstance);
50 pInstance=newInstance;
55 CSurfaceStream* COpenWfcStreamMap::Find(const TSurfaceId& aSurfaceId)
58 CSurfaceStream** ns = iMap.Find(aSurfaceId);
59 // used if statement to ease debug help
62 (*ns)->AddReference();
68 CSurfaceStream* COpenWfcStreamMap::AcquireL(const TSurfaceId& aSurfaceId)
70 Guard* pGuard = new(ELeave) Guard(iMutex);
71 User::LeaveIfNull(pGuard);
72 CleanupDeletePushL(pGuard);
74 CSurfaceStream** ns = NULL;
75 CSurfaceStream* ret = NULL;
76 ns = iMap.Find(aSurfaceId);
79 WFCI_ASSERT_DEBUG((*ns), EOwfPanicInvalidHasMap); // should have never happened
84 ret = CSurfaceStream::NewLC(aSurfaceId);
85 User::LeaveIfError(iMap.Insert(aSurfaceId, ret));
89 CleanupStack::PopAndDestroy(pGuard);
93 EXPORT_C TInt COpenWfcStreamMap::Count()
96 TInt count = iMap.Count();
100 EXPORT_C RSurfaceManager& COpenWfcStreamMap::SurfaceManager()
102 WFCI_ASSERT_DEBUG(iSurfaceManager, EOwfPanicInvalidHasMap);
103 return *iSurfaceManager;
106 TInt COpenWfcStreamMap::LockDestroy(CSurfaceStream* aStream)
112 if (aStream->RemainingReference())
114 const TSurfaceId& surfaceId = aStream->SurfaceId();
115 CSurfaceStream** ns = iMap.Find(surfaceId);
116 // used if statement to ease debug help
117 if (ns && ((*ns) == aStream))
119 TInt ret = iMap.Remove(surfaceId);
127 else // RemainingReference
139 COpenWfcStreamMap::COpenWfcStreamMap():
140 iMap(THashFunction32<TSurfaceId>(COpenWfcStreamMap::HashFunction), TIdentityRelation<TSurfaceId>()),
141 iSurfaceManager(NULL),
142 iRegisteredUpdaters()
146 TInt COpenWfcStreamMap::DeleteSingleton(TAny* aData)
148 * aData A pointer to the heap registered for this callback
151 // Blank the property for this callback
154 TCallBack cb(NULL, NULL);
155 TPckgC<TCallBack> cbPckg(cb);
156 prop.Set(TUid::Uid(t.SecureId().iId), KOpenWfcInteropCleanupKey, cbPckg);
160 if (aData == &User::Heap())
169 COpenWfcStreamMap::~COpenWfcStreamMap()
173 THashMapIter<TSurfaceId, CSurfaceStream*> iter(iMap);
174 const TSurfaceId* nextKey = iter.NextKey();
175 CSurfaceStream* const* ns = NULL;
178 ns = iter.CurrentValue();
183 nextKey = iter.NextKey();
189 iSurfaceManager->Close();
190 delete iSurfaceManager;
191 iSurfaceManager = NULL;
197 THashMapIter<TInt32, CExtensionContainer*> iter(iRegisteredUpdaters);
198 const TInt32* nextKey = iter.NextKey();
199 CExtensionContainer* const* extensionContainer = NULL;
202 extensionContainer = iter.CurrentValue();
203 if (extensionContainer && *extensionContainer)
205 delete (*extensionContainer);
207 nextKey = iter.NextKey();
210 iRegisteredUpdaters.Close();
213 void COpenWfcStreamMap::ConstructL()
215 User::LeaveIfError(iMutex.CreateLocal());
216 iMap.Reserve(iInitialSize);
217 TSurfaceId surface = TSurfaceId::CreateNullId();
218 User::LeaveIfError(iMap.Insert(surface, NULL));
220 iSurfaceManager = new(ELeave) RSurfaceManager();
221 User::LeaveIfError(iSurfaceManager->Open());
223 TUidType uidType = process.Type();
224 const TInt32 KWservUid = 268450592;
225 const TUid& uid1 = uidType[2];
227 if(uid1.iUid == KWservUid) //only wserv process can start the server
229 StartSurfaceUpdateServer(iSurfUpdateServ);
232 // Register the cleanup function in a property defined by WServ
234 TUid category = {t.SecureId().iId};
236 TCallBack cb(DeleteSingleton, &User::Heap());
237 TPckgC<TCallBack> cbPckg(cb);
239 // If the property cannot be set the assumption is that the cleanup is not needed
240 (void) prop.Set(category, KOpenWfcInteropCleanupKey, cbPckg);
244 // StreamMap is constructed from main thread
248 COpenWfcStreamMap::Guard::Guard(RFastLock& aLock):
254 COpenWfcStreamMap::Guard::~Guard()
259 EXPORT_C RHeap* COpenWfcStreamMap::GetMainHeap()
264 void COpenWfcStreamMap::SetMainHeap()
266 iMainHeap = &User::Heap();
269 TInt COpenWfcStreamMap::RegisterScreenNotifications(TInt aScreenNum, TInt aPriority,TInt aInternalVersion)
271 COpenWfcStreamMap* pInstance = NULL;
272 TRAPD(err,pInstance = &COpenWfcStreamMap::InstanceL());
278 if (iRegisteredUpdaters.Find(aScreenNum)!= NULL)
280 return KErrAlreadyExists;
283 CExtensionContainer* updateProxy = NULL;
284 TRAP(err, updateProxy = CContentUpdateProxy::NewL(aScreenNum, pInstance,aInternalVersion,aPriority));
290 if ((err = iRegisteredUpdaters.Insert(aScreenNum, updateProxy)) != KErrNone)
296 if (!pInstance->iSurfUpdateServ)
298 return KErrNotReady; //For testing purposes the backend proxy still exists.
300 err = iSurfUpdateServ->Register(aScreenNum, updateProxy, aPriority);
304 iRegisteredUpdaters.Remove(aScreenNum);
309 CExtensionContainer* COpenWfcStreamMap::RegisteredScreenNotifications(TInt aScreenNum)
311 return *iRegisteredUpdaters.Find(aScreenNum);
314 TInt COpenWfcStreamMap::UnregisterScreenNotifications(TInt aScreenNum)
317 CExtensionContainer** backend = iRegisteredUpdaters.Find(aScreenNum);
321 iRegisteredUpdaters.Remove(aScreenNum);
324 err = iSurfUpdateServ->Register(aScreenNum, NULL, 0);