23 #ifdef TEST_SURFACE_UPDATE |
23 #ifdef TEST_SURFACE_UPDATE |
24 #include "surfaceupdatetest.h" |
24 #include "surfaceupdatetest.h" |
25 #endif |
25 #endif |
26 |
26 |
27 |
27 |
|
28 |
28 const TUint KDefaultHeapSize=0x10000; |
29 const TUint KDefaultHeapSize=0x10000; |
29 |
30 |
30 void *gProvider = NULL; |
|
31 RFastLock gProviderFastLock; |
|
32 |
31 |
33 /** |
32 /** |
34 The server maintains session with the clients. |
33 The server maintains session with the clients. |
35 It starts during the initialization of the Content update receiver thread. |
34 It starts during the initialization of the Content update receiver thread. |
36 */ |
35 */ |
350 */ |
349 */ |
351 CUpdateReceiverNotificationBatch* CSurfaceUpdateSession::UpdateReceiverNotificationBatchL() |
350 CUpdateReceiverNotificationBatch* CSurfaceUpdateSession::UpdateReceiverNotificationBatchL() |
352 { |
351 { |
353 TInt numElement = iUpdateReceiverNotificationBatches.Count(); |
352 TInt numElement = iUpdateReceiverNotificationBatches.Count(); |
354 CUpdateReceiverNotificationBatch* notifier = NULL; |
353 CUpdateReceiverNotificationBatch* notifier = NULL; |
355 CSurfaceUpdateServer* server = (CSurfaceUpdateServer*) Server(); |
|
356 for(TInt index = 0; index < numElement; index++) |
354 for(TInt index = 0; index < numElement; index++) |
357 { |
355 { |
358 notifier = iUpdateReceiverNotificationBatches[index]; |
356 notifier = iUpdateReceiverNotificationBatches[index]; |
359 if(notifier->iType == EUpdateSrvReusable) |
357 if(notifier->iType == EUpdateSrvReusable) |
360 { |
358 { |
361 __ASSERT_ALWAYS(notifier->iMsg.IsNull(), CSurfaceUpdateServer::PanicServer(EUpdateServPanicDataIntegrity)); |
359 __ASSERT_ALWAYS(notifier->iMsg.IsNull(), CSurfaceUpdateServer::PanicServer(EUpdateServPanicDataIntegrity)); |
362 notifier->SetNumUpdateReceivers(server->NumUpdateReceivers()); |
|
363 if(numElement > index + 1) |
360 if(numElement > index + 1) |
364 { |
361 { |
365 //to improve a search, append the element to the end of the array |
362 //to improve a search, append the element to the end of the array |
366 iUpdateReceiverNotificationBatches.Remove(index); |
363 iUpdateReceiverNotificationBatches.Remove(index); |
367 iUpdateReceiverNotificationBatches.AppendL(notifier); |
364 iUpdateReceiverNotificationBatches.AppendL(notifier); |
368 } |
365 } |
369 return notifier; |
366 return notifier; |
370 } |
367 } |
371 } |
368 } |
372 |
369 |
|
370 CSurfaceUpdateServer* server = (CSurfaceUpdateServer*) Server(); |
373 notifier = new (ELeave) CUpdateReceiverNotificationBatch(this, server->NumUpdateReceivers()); |
371 notifier = new (ELeave) CUpdateReceiverNotificationBatch(this, server->NumUpdateReceivers()); |
374 CleanupStack::PushL(notifier); |
372 CleanupStack::PushL(notifier); |
375 iUpdateReceiverNotificationBatches.AppendL(notifier); |
373 iUpdateReceiverNotificationBatches.AppendL(notifier); |
376 CleanupStack::Pop(); |
374 CleanupStack::Pop(); |
377 |
375 |
883 (static_cast<CSurfaceUpdateServer*> (server))-> iNumberPendingNotification++; |
881 (static_cast<CSurfaceUpdateServer*> (server))-> iNumberPendingNotification++; |
884 } |
882 } |
885 } |
883 } |
886 #endif |
884 #endif |
887 |
885 |
888 |
|
889 /** |
|
890 Set number of UpdateReceivers - called when update receivers are added/removed. |
|
891 |
|
892 @param aNumUpdateReceivers - new number of update receivers for the batch. |
|
893 */ |
|
894 void CUpdateReceiverNotificationBatch::SetNumUpdateReceivers(TInt aNumUpdateReceivers) |
|
895 { |
|
896 __ASSERT_DEBUG(aNumUpdateReceivers >= 0 && aNumUpdateReceivers < 1000 /* arbitrary "large" limit */, |
|
897 CSurfaceUpdateServer::PanicServer(EUpdateServPanicDataIntegrity)); |
|
898 __ASSERT_DEBUG(iType == EUpdateSrvReusable, |
|
899 CSurfaceUpdateServer::PanicServer(EUpdateServPanicDataIntegrity)); |
|
900 iNumUpdateReceivers = aNumUpdateReceivers; |
|
901 } |
|
902 /** |
886 /** |
903 |
887 |
904 The class will be used by composition receiver |
888 The class will be used by composition receiver |
905 */ |
889 */ |
906 CSurfaceUpdateServerProvider* CSurfaceUpdateServerProvider::NewL(CActive::TPriority aPriority, CSurfaceUpdateServer* aServer) |
890 CSurfaceUpdateServerProvider* CSurfaceUpdateServerProvider::NewL(CActive::TPriority aPriority, CSurfaceUpdateServer* aServer) |
969 #ifdef TEST_SURFACE_UPDATE |
953 #ifdef TEST_SURFACE_UPDATE |
970 RThread thread; |
954 RThread thread; |
971 |
955 |
972 if(thread.Open(iThreadId) == KErrNone) |
956 if(thread.Open(iThreadId) == KErrNone) |
973 { |
957 { |
974 TInt err = gProviderFastLock.CreateLocal(); |
|
975 __ASSERT_ALWAYS(err == KErrNone || err == KErrAlreadyExists, CSurfaceUpdateServer::PanicServer(EUpdateServPanicGlobalFastLock)); |
|
976 |
|
977 gProviderFastLock.Wait(); |
|
978 gProvider = NULL; |
|
979 if (iServer) |
958 if (iServer) |
980 { |
959 { |
981 while((static_cast<CSurfaceUpdateServer*> (iServer))-> iNumberPendingNotification) |
960 while((static_cast<CSurfaceUpdateServer*> (iServer))-> iNumberPendingNotification) |
982 User::After(TTimeIntervalMicroSeconds32(1000)); |
961 User::After(TTimeIntervalMicroSeconds32(1000)); |
983 } |
962 } |
1038 @return KErrNone if an operation is successful, any other system error codes otherwise |
1017 @return KErrNone if an operation is successful, any other system error codes otherwise |
1039 */ |
1018 */ |
1040 EXPORT_C TInt StartSurfaceUpdateServer(MSurfaceUpdateServerProvider*& aSurfaceUpdateServerProvider) |
1019 EXPORT_C TInt StartSurfaceUpdateServer(MSurfaceUpdateServerProvider*& aSurfaceUpdateServerProvider) |
1041 { |
1020 { |
1042 #ifndef TEST_SURFACE_UPDATE |
1021 #ifndef TEST_SURFACE_UPDATE |
1043 TPtrC serverName(KSurfaceUpdateServerName); |
1022 TPtrC serverName(KSurfaceUpdateServerName); |
1044 #else |
1023 #else |
1045 TPtrC serverName(KTestSurfaceUpdateServerName); |
1024 TPtrC serverName(KTestSurfaceUpdateServerName); |
1046 #endif |
1025 #endif |
1047 //locking |
1026 TAny *provider = Dll::Tls(); |
1048 TInt err = gProviderFastLock.CreateLocal(); |
|
1049 |
|
1050 if (err != KErrNone && err != KErrAlreadyExists) |
|
1051 { |
|
1052 return err; |
|
1053 } |
|
1054 |
|
1055 gProviderFastLock.Wait(); |
|
1056 |
|
1057 TAny *provider = gProvider; |
|
1058 if(provider) |
1027 if(provider) |
1059 { |
1028 { |
1060 aSurfaceUpdateServerProvider = static_cast <MSurfaceUpdateServerProvider*> (provider); |
1029 aSurfaceUpdateServerProvider = static_cast <MSurfaceUpdateServerProvider*> (provider); |
1061 gProviderFastLock.Signal(); |
|
1062 return KErrNone; |
1030 return KErrNone; |
1063 } |
1031 } |
1064 TFullName name; |
1032 TFullName name; |
1065 RThread serverThread; |
1033 RThread serverThread; |
1066 TInt res = KErrAlreadyExists; |
1034 TInt res = KErrAlreadyExists; |
1073 TBuf<32> buf; |
1041 TBuf<32> buf; |
1074 tm.UniversalTime(); |
1042 tm.UniversalTime(); |
1075 TRAP(res, tm.FormatL(buf, _L("_%H%T%S%C"))); |
1043 TRAP(res, tm.FormatL(buf, _L("_%H%T%S%C"))); |
1076 if(res != KErrNone) |
1044 if(res != KErrNone) |
1077 { |
1045 { |
1078 gProviderFastLock.Signal(); |
|
1079 return res; |
1046 return res; |
1080 } |
1047 } |
1081 TBuf<128> threadName(serverName); |
1048 TBuf<128> threadName(serverName); |
1082 threadName.Append(buf); //guarantee uniqueness of the thread name |
1049 threadName.Append(buf); //guarantee uniqueness of the thread name |
1083 // Create the thread for the server. |
1050 // Create the thread for the server. |
1097 serverThread.SetPriority(priority); // The same as the priority of the creating thread |
1064 serverThread.SetPriority(priority); // The same as the priority of the creating thread |
1098 serverThread.Rendezvous(rendezvousStatus); |
1065 serverThread.Rendezvous(rendezvousStatus); |
1099 serverThread.Resume(); |
1066 serverThread.Resume(); |
1100 User::WaitForRequest(rendezvousStatus); |
1067 User::WaitForRequest(rendezvousStatus); |
1101 res = rendezvousStatus.Int(); |
1068 res = rendezvousStatus.Int(); |
1102 gProvider = aSurfaceUpdateServerProvider; |
1069 Dll::SetTls(aSurfaceUpdateServerProvider); |
1103 } |
1070 } |
1104 // The thread has not been created - clearly there's been a problem. |
1071 // The thread has not been created - clearly there's been a problem. |
1105 else |
1072 else |
1106 { |
1073 { |
1107 serverThread.Close(); |
1074 serverThread.Close(); |
1108 } |
1075 } |
1109 } |
1076 } |
1110 gProviderFastLock.Signal(); |
|
1111 return res; |
1077 return res; |
1112 } |
1078 } |