os/ossrv/genericservices/taskscheduler/Test/TSUtils/thelpers.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2004-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 //
    15 
    16 #include "Thelpers.h"
    17 
    18 // System includes
    19 #include <e32math.h>
    20 #include <f32file.h>
    21 
    22 _LIT(KPauseMessage,							"=== Pausing for %d seconds ===\n");
    23 
    24 //
    25 // Helper class for Scheduler Server test code
    26 //
    27 
    28 EXPORT_C TBool SchSvrHelpers::IsTimeTheSame(const TTime& aTime1, const TTime& aTime2)
    29 	{
    30 	// Just compares the time, not the date
    31 	TDateTime time1 = aTime1.DateTime();
    32 	TDateTime time2 = aTime2.DateTime();
    33 	return ((time1.Hour() == time2.Hour()) && (time1.Minute() == time2.Minute()) && (time1.Second() == time2.Second()));
    34 	}
    35 
    36 EXPORT_C TBool SchSvrHelpers::IsDateTheSame(const TTime& aTime1, const TTime& aTime2)
    37 	{
    38 	// Just compares the date not the time
    39 	TDateTime time1 = aTime1.DateTime();
    40 	TDateTime time2 = aTime2.DateTime();
    41 	return ((time1.Day() == time2.Day()) && (time1.Month() == time2.Month()) && (time1.Year() == time2.Year()));
    42 	}
    43 
    44 EXPORT_C TBool SchSvrHelpers::IsTaskInfoTheSame(const TTaskInfo& aTaskInfo1, const TTaskInfo& aTaskInfo2)
    45 	{
    46 	if	(	aTaskInfo1.iRepeat == aTaskInfo2.iRepeat	&& aTaskInfo1.iTaskId == aTaskInfo2.iTaskId
    47 		 &&	aTaskInfo1.iName == aTaskInfo2.iName		&& aTaskInfo1.iPriority == aTaskInfo2.iPriority)
    48 		 return ETrue;
    49 	return EFalse;
    50 	}
    51 
    52 EXPORT_C TBool SchSvrHelpers::IsItemRefTheSame(const TSchedulerItemRef& aItemRef1, const TSchedulerItemRef& aItemRef2)
    53 	{
    54 	if	(aItemRef1.iHandle == aItemRef2.iHandle && aItemRef1.iName == aItemRef2.iName)
    55 		return ETrue;
    56 	return EFalse;
    57 	}
    58 
    59 EXPORT_C TBool SchSvrHelpers::IsScheduleStateTheSame(const TScheduleState& aScheduleState1, const TScheduleState& aScheduleState2)
    60 	{
    61 	if	(	aScheduleState1.iDueTime == aScheduleState2.iDueTime	&& aScheduleState1.iPersists == aScheduleState2.iPersists
    62 		 &&	aScheduleState1.iName == aScheduleState2.iName			&& aScheduleState1.iEnabled == aScheduleState2.iEnabled)
    63 		 return ETrue;
    64 	return EFalse;
    65 	}
    66 
    67 EXPORT_C TScheduleEntryInfo SchSvrHelpers::RandomScheduleEntryInfo(TInt64& aSeed)
    68 	{
    69 	TScheduleEntryInfo entryInfo;
    70 	entryInfo.iIntervalType		= STATIC_CAST(TIntervalType, Rand(EHourly, EYearly, aSeed));
    71 	entryInfo.iStartTime		= TimeBasedOnOffset(Rand(0, 59, aSeed), Rand(0, 10, aSeed), Rand(0, 1, aSeed));
    72 	entryInfo.iInterval			= Rand(1, 100, aSeed);
    73 	entryInfo.iValidityPeriod	= Rand(1, 100, aSeed);
    74 	return entryInfo;
    75 	}
    76 
    77 EXPORT_C TScheduleEntryInfo SchSvrHelpers::ScheduleEntryInfo(TIntervalType aType, const TTime& aStartTime, TInt aInterval, TTimeIntervalMinutes aValidPeriod)
    78 	{
    79 	TScheduleEntryInfo info;
    80 	info.iIntervalType		= aType;
    81 	info.iStartTime			= aStartTime;
    82 	info.iInterval			= aInterval;
    83 	info.iValidityPeriod	= aValidPeriod;
    84 	return info;
    85 	}
    86 
    87 EXPORT_C TTaskInfo SchSvrHelpers::TaskInfo(const TDesC& aName, TInt aPriority, TInt aRepeat)
    88 	{
    89 	TName name(aName);
    90 	return TTaskInfo(0, name, aPriority, aRepeat); // zero the id for now (returned by server)
    91 	}
    92 
    93 // Generate a random number based upon a seed and a range
    94 EXPORT_C TInt SchSvrHelpers::Rand(const TInt aLow, const TInt aHigh, TInt64& aSeed)
    95 	{
    96 	TReal initialRand = (Math::FRand(aSeed) * (aHigh - aLow));
    97 	TInt32 rand;
    98 
    99 	// Round to 0 decimal places, ie. the nearest whole numer
   100 	Math::Round(initialRand, initialRand, 0);
   101 	Math::Int(rand, initialRand);
   102 
   103 	//aSeed = seed;
   104 	return (aLow + rand);
   105 	}
   106 
   107 // Pause execution for the specified number of seconds
   108 EXPORT_C void SchSvrHelpers::Pause(RTest& aTest, TInt aPauseAmount)
   109 	{
   110 	aTest.Printf(KPauseMessage, aPauseAmount);
   111 	User::After(KOneSecond * aPauseAmount); // default is 2 seconds
   112 	}
   113 
   114 // To be used by Hometime based schedules
   115 EXPORT_C TDateTime SchSvrHelpers::TimeBasedOnOffset(TInt aSeconds, TInt aMinutes, TInt aHours, TInt aDays, TInt aMonths, TInt aYears)
   116 	{
   117 	TTime now;
   118 	now.HomeTime();
   119 	now += TTimeIntervalSeconds(aSeconds);
   120 	now += TTimeIntervalMinutes(aMinutes);
   121 	now += TTimeIntervalHours(aHours);
   122 	now += TTimeIntervalDays(aDays);
   123 	now += TTimeIntervalMonths(aMonths);
   124 	now += TTimeIntervalYears(aYears);
   125 	return now.DateTime();
   126 	}
   127 
   128 // To be used by UTC time based schedules
   129 EXPORT_C TDateTime SchSvrHelpers::UtcTimeBasedOnOffset(TInt aSeconds, TInt aMinutes, TInt aHours, TInt aDays, TInt aMonths, TInt aYears)
   130 	{
   131 	TTime now;
   132 	now.UniversalTime();
   133 	now += TTimeIntervalSeconds(aSeconds);
   134 	now += TTimeIntervalMinutes(aMinutes);
   135 	now += TTimeIntervalHours(aHours);
   136 	now += TTimeIntervalDays(aDays);
   137 	now += TTimeIntervalMonths(aMonths);
   138 	now += TTimeIntervalYears(aYears);
   139 	return now.DateTime();
   140 	}
   141 	
   142 // Check task file left
   143 // It creates a separate process to do this as file to access in in private
   144 // data cage which requires all files capability 
   145 EXPORT_C TInt SchSvrHelpers::CheckTaskFilesL()
   146 	{
   147 	_LIT(KTaskFileChecker, "TTaskFileChecker");
   148 	TRequestStatus stat;
   149 	RProcess p;
   150 	User::LeaveIfError(p.Create(KTaskFileChecker, KNullDesC));
   151 	// Asynchronous logon: completes when process terminates with process exit code
   152 	p.Logon(stat);
   153 	p.Resume();
   154 
   155 	User::WaitForRequest(stat);
   156 	TInt exitReason = p.ExitReason();
   157 	p.Close();
   158 	
   159 	// return exit reasons as checking result
   160 	return exitReason;
   161 	}	
   162 	
   163 	
   164 // Create task files for testing
   165 // It creates a separate process to do this as file to access in in private
   166 // data cage which requires all files capability 
   167 EXPORT_C TInt SchSvrHelpers::CreateTaskFilesL()
   168 	{
   169 	_LIT(KTaskFileCreator, "TTaskFileCreator");
   170 	TRequestStatus stat;
   171 	RProcess p;
   172 	User::LeaveIfError(p.Create(KTaskFileCreator, KNullDesC));
   173 	// Asynchronous logon: completes when process terminates with process exit code
   174 	p.Logon(stat);
   175 	p.Resume();
   176 
   177 	User::WaitForRequest(stat);
   178 	TInt exitReason = p.ExitReason();
   179 	p.Close();
   180 	
   181 	// return exit reasons as checking result
   182 	return exitReason;
   183 	}	
   184 	
   185 // Start Task Scheduler
   186 // It creates a separate process to do this as need to set appropriate SID
   187 // to enable task scheduler to be started 
   188 EXPORT_C TInt SchSvrHelpers::LaunchTaskSchedulerL()
   189 	{
   190 	_LIT(KTaskSchedulerLauncher, "TTaskSchedulerLauncher");
   191 	TRequestStatus stat;
   192 	RProcess p;
   193 	User::LeaveIfError(p.Create(KTaskSchedulerLauncher, KNullDesC));
   194 	// Asynchronous logon: completes when process terminates with process exit code
   195 	p.Logon(stat);
   196 	p.Resume();
   197 
   198 	User::WaitForRequest(stat);
   199 	TInt exitReason = p.ExitReason();
   200 	p.Close();
   201 	
   202 	// return exit reasons as checking result
   203 	return exitReason;
   204 	}	
   205 
   206 
   207 //
   208 // PREQ234 support //
   209 
   210 EXPORT_C TBool SchSvrHelpers::IsTimeTheSame(const TTsTime& aTime1, const TTsTime& aTime2)
   211 	{
   212 	// Just compares the time, not the date
   213 	TBool ret = EFalse;
   214 	
   215 	if (aTime1.IsUtc() && aTime2.IsUtc())
   216 		{
   217 		TDateTime time1 = aTime1.GetUtcTime().DateTime();
   218 		TDateTime time2 = aTime2.GetUtcTime().DateTime();
   219 		ret = ((time1.Hour() == time2.Hour()) && (time1.Minute() == time2.Minute()) && (time1.Second() == time2.Second()));
   220 		}
   221 	if (!aTime1.IsUtc() && !aTime2.IsUtc())
   222 		{
   223 		TDateTime time1 = aTime1.GetLocalTime().DateTime();
   224 		TDateTime time2 = aTime2.GetLocalTime().DateTime();
   225 		ret = ((time1.Hour() == time2.Hour()) && (time1.Minute() == time2.Minute()) && (time1.Second() == time2.Second()));
   226 		}
   227 
   228 	return ret;
   229 	}
   230 
   231 EXPORT_C TBool SchSvrHelpers::IsTimeTheSameNoSeconds(const TTsTime& aTime1, const TTsTime& aTime2)
   232 	{
   233 	// Just compares the time up to hours and minutes
   234 	TBool ret = EFalse;
   235 	
   236 	if (aTime1.IsUtc() && aTime2.IsUtc())
   237 		{
   238 		TDateTime time1 = aTime1.GetUtcTime().DateTime();
   239 		TDateTime time2 = aTime2.GetUtcTime().DateTime();
   240 		ret = ((time1.Hour() == time2.Hour()) && (time1.Minute() == time2.Minute()));
   241 		}
   242 	if (!aTime1.IsUtc() && !aTime2.IsUtc())
   243 		{
   244 		TDateTime time1 = aTime1.GetLocalTime().DateTime();
   245 		TDateTime time2 = aTime2.GetLocalTime().DateTime();
   246 		ret = ((time1.Hour() == time2.Hour()) && (time1.Minute() == time2.Minute()));
   247 		}
   248 	return ret;
   249 	}
   250 
   251 EXPORT_C TBool SchSvrHelpers::IsDateTheSame(const TTsTime& aTime1, const TTsTime& aTime2)
   252 	{
   253 	// Just compares the date not the time
   254 	TBool ret = EFalse;
   255 	
   256 	if (aTime1.IsUtc() && aTime2.IsUtc())
   257 		{
   258 		TDateTime time1 = aTime1.GetUtcTime().DateTime();
   259 		TDateTime time2 = aTime2.GetUtcTime().DateTime();
   260 		ret = ((time1.Day() == time2.Day()) && (time1.Month() == time2.Month()) && (time1.Year() == time2.Year()));
   261 		}
   262 	if (!aTime1.IsUtc() && !aTime2.IsUtc())
   263 		{
   264 		TDateTime time1 = aTime1.GetLocalTime().DateTime();
   265 		TDateTime time2 = aTime2.GetLocalTime().DateTime();
   266 		ret = ((time1.Day() == time2.Day()) && (time1.Month() == time2.Month()) && (time1.Year() == time2.Year()));
   267 		}
   268 
   269 	return ret;
   270 	}
   271 
   272 EXPORT_C TBool SchSvrHelpers::IsScheduleStateTheSame(const TScheduleState2& aScheduleState1, const TScheduleState2& aScheduleState2)
   273 	{
   274 	if (aScheduleState1.DueTime().IsUtc() && aScheduleState2.DueTime().IsUtc())
   275 		{
   276 		TTime dueTime1 = aScheduleState1.DueTime().GetUtcTime();
   277 		TTime dueTime2 = aScheduleState2.DueTime().GetUtcTime();
   278 		
   279 		if (aScheduleState1.Persists() == aScheduleState2.Persists()	&&	aScheduleState1.Name() == aScheduleState2.Name()
   280 		&& 	aScheduleState1.Enabled() == aScheduleState2.Enabled()		&&	dueTime1 == dueTime2)
   281 			return ETrue;
   282 		}
   283 
   284 	if (!aScheduleState1.DueTime().IsUtc() && !aScheduleState2.DueTime().IsUtc())
   285 		{
   286 		TTime dueTime1 = aScheduleState1.DueTime().GetLocalTime();
   287 		TTime dueTime2 = aScheduleState2.DueTime().GetLocalTime();
   288 		
   289 		if (aScheduleState1.Persists() == aScheduleState2.Persists()	&&	aScheduleState1.Name() == aScheduleState2.Name()
   290 		&& 	aScheduleState1.Enabled() == aScheduleState2.Enabled()		&&	dueTime1 == dueTime2)
   291 			return ETrue;
   292 		}	
   293 	
   294 	return EFalse;
   295 	}
   296 
   297 EXPORT_C TScheduleEntryInfo2 SchSvrHelpers::RandomScheduleEntryInfoHometime(TInt64& aSeed)
   298 	{
   299 	TScheduleEntryInfo2 entryInfo;
   300 	entryInfo.SetIntervalType(STATIC_CAST(TIntervalType, Rand(EHourly, EYearly, aSeed)));
   301 	entryInfo.SetStartTime(TTsTime (TTime(TimeBasedOnOffset(Rand(0, 59, aSeed), Rand(0, 10, aSeed), Rand(0, 1, aSeed))), ETrue));
   302 	entryInfo.SetInterval(Rand(1, 100, aSeed));
   303 	entryInfo.SetValidityPeriod(Rand(1, 100, aSeed));
   304 	return entryInfo;
   305 	}
   306 
   307 EXPORT_C TScheduleEntryInfo2 SchSvrHelpers::RandomScheduleEntryInfoUtc(TInt64& aSeed)
   308 	{
   309 	TScheduleEntryInfo2 entryInfo;
   310 	entryInfo.SetIntervalType(STATIC_CAST(TIntervalType, Rand(EHourly, EYearly, aSeed)));
   311 	entryInfo.SetStartTime(TTsTime(TTime(TimeBasedOnOffset(Rand(0, 59, aSeed), Rand(0, 10, aSeed), Rand(0, 1, aSeed))), ETrue));
   312 	entryInfo.SetInterval(Rand(1, 100, aSeed));
   313 	entryInfo.SetValidityPeriod(Rand(1, 100, aSeed));
   314 	return entryInfo;
   315 	}
   316 
   317 EXPORT_C TScheduleEntryInfo2 SchSvrHelpers::ScheduleEntryInfo(TIntervalType aType, const TTsTime& aStartTime, TInt aInterval, TTimeIntervalMinutes aValidPeriod)
   318 	{
   319 	TScheduleEntryInfo2 info (aStartTime, aType, aInterval, aValidPeriod);
   320 	return info;
   321 	}
   322 
   323 // Pause execution for the specified number of seconds
   324 EXPORT_C void SchSvrHelpers::Pause(TInt aPauseAmount)
   325 	{
   326 	//aTest.Printf(KPauseMessage, aPauseAmount);
   327 	User::After(KOneSecond * aPauseAmount); // default is 2 seconds
   328 	}
   329 
   330 // PREQ234 support //
   331 //
   332 
   333 EXPORT_C void SchSvrHelpers::DeleteAllSchedulesL(RScheduler& aScheduler)
   334 	{
   335 	// First fetch task references so that we can delete all the tasks.
   336 	CArrayFixFlat<TSchedulerItemRef>* refs = new (ELeave) CArrayFixFlat<TSchedulerItemRef>(3);
   337 	CleanupStack::PushL(refs);
   338 
   339 	{
   340 	User::LeaveIfError(aScheduler.GetTaskRefsL(*refs, EAllSchedules, EAllTasks));
   341 	const TInt count = refs->Count();
   342 	// Delete all tasks
   343 	for(TInt i=0; i<count; ++i)
   344 		{
   345 		const TSchedulerItemRef& ref = refs->At(i);
   346 		User::LeaveIfError(aScheduler.DeleteTask(ref.iHandle));
   347 		}
   348 	}
   349 	refs->Reset();
   350 	{
   351 	User::LeaveIfError(aScheduler.GetScheduleRefsL(*refs, EAllSchedules));
   352 	// Delete all schedules
   353 	const TInt count = refs->Count();
   354 	for(TInt i=0; i<count; ++i)
   355 		{
   356 		const TSchedulerItemRef& ref = refs->At(i);
   357 		User::LeaveIfError(aScheduler.DeleteSchedule(ref.iHandle));
   358 		}
   359 	}
   360 	CleanupStack::PopAndDestroy(refs);
   361 	}
   362 
   363 // Deletes the task scheduler persisted files.
   364 // It creates a separate process to do this as file to delete in in private
   365 // data cage which requires all files capability which we don't want to 
   366 // grant to all test exes.
   367 EXPORT_C void SchSvrHelpers::DeleteScheduleFilesL()
   368 	{
   369 	_LIT(KScheduleDeleter, "TScheduleDeleter");
   370 	TRequestStatus stat;
   371 	RProcess p;
   372 	User::LeaveIfError(p.Create(KScheduleDeleter, KNullDesC));
   373 	// Asynchronous logon: completes when process terminates with process exit code
   374 	p.Logon(stat);
   375 	p.Resume();
   376 
   377 	User::WaitForRequest(stat);
   378 	TInt exitReason = p.ExitReason();
   379 	p.Close();
   380 	User::LeaveIfError(exitReason);
   381 	}
   382 	
   383 // registers the client exe, leaving if it is not found 
   384 EXPORT_C TInt SchSvrHelpers::RegisterClientL(RScheduler& aScheduler)
   385 	{
   386 	TFileName filename;
   387 	filename = _L("MinimalTaskHandler");
   388 
   389 	return aScheduler.Register(filename, 27);
   390 	}
   391 	
   392 // registers the panicing client exe
   393 EXPORT_C TInt SchSvrHelpers::RegisterPanicingClient(RScheduler& aScheduler)
   394 	{
   395 	TFileName filename;
   396 	filename = _L("FaultyMinimalTaskHandler");
   397 
   398 	return aScheduler.Register(filename, 27);
   399 	}
   400 	
   401 // registers the a non existent exe
   402 EXPORT_C TInt SchSvrHelpers::RegisterNonExistentClient(RScheduler& aScheduler)
   403 	{
   404 	TFileName filename;
   405 	filename = _L("NonExistentClient");
   406 
   407 	return aScheduler.Register(filename, 27);
   408 	}
   409 	
   410 // Sets the system time to the given local time
   411 // It creates a separate process to do this, 
   412 // as this requires WDD capability which we don't want to grant to all test exes.
   413 EXPORT_C TInt SchSvrHelpers::SetHomeTimeL(const TTime& aLocalTime)
   414 	{
   415 	
   416 	_LIT(KSetHomeTime, "TSetHomeTime");
   417 	_LIT(KTimeFormat, "%F%Y%M%D:%H%T%S.%*C6");
   418 	
   419 	RProcess p;	
   420 	TRequestStatus stat;
   421 	TBuf<128> bufLocalTime;	
   422 	
   423 	aLocalTime.FormatL(bufLocalTime, KTimeFormat);
   424 	
   425 	User::LeaveIfError(p.Create(KSetHomeTime, bufLocalTime));
   426 	
   427 	// Asynchronous logon: completes when process terminates with process exit code
   428 	p.Logon(stat);
   429 	p.Resume();
   430 
   431 	User::WaitForRequest(stat);
   432 	TInt exitReason = p.ExitReason();
   433 	p.Close();
   434 	return (exitReason);
   435 	}
   436 
   437 	
   438 // Sets the UTC time to a specified time value
   439 // It creates a separate process to do this, 
   440 // as this requires WDD capability which we don't want to grant to all test exes.
   441 EXPORT_C TInt SchSvrHelpers::SetUTCTimeL(const TTime& aUTCTime)
   442 	{
   443 	_LIT(KSetUTCTime, "TSetUTCTime");
   444 	_LIT(KTimeFormat, "%F%Y%M%D:%H%T%S.%*C6");
   445 	
   446 	RProcess p;	
   447 	TRequestStatus stat;
   448 	TBuf<128> bufUTCTime;	
   449 	
   450 	aUTCTime.FormatL(bufUTCTime, KTimeFormat);	
   451 
   452 	User::LeaveIfError(p.Create(KSetUTCTime, bufUTCTime));
   453 		
   454 	// Asynchronous logon: completes when process terminates with process exit code
   455 	p.Logon(stat);
   456 	p.Resume();
   457 
   458 	User::WaitForRequest(stat);
   459 	TInt exitReason = p.ExitReason();	
   460 	p.Close();	
   461 	return (exitReason);
   462 	}
   463 
   464 //This function is used in the test code to kill SCHSVR or MinimalTaskHandler
   465 //processes (or some other) when they leftover and may cause OOM conditions.
   466 // It creates a separate process to do this as killing a process requires
   467 // PwrMgmt capability which we don't want to grant to all test exes.
   468 EXPORT_C TInt CleanupHelpers::KillProcess(const TDesC& aProcessName)
   469 	{
   470 	_LIT(KProcessKiller, "TProcessKiller");
   471 	TRequestStatus stat;
   472 	RProcess p;
   473 	TInt result = p.Create(KProcessKiller, aProcessName);
   474 	
   475 	if(result == KErrNone)
   476 		{
   477 		// Asynchronous logon: completes when process terminates with process exit code
   478 		p.Logon(stat);
   479 		p.Resume();
   480 
   481 		User::WaitForRequest(stat);
   482 		result = p.ExitReason();
   483 		p.Close();			
   484 		}
   485 
   486 	return result;
   487 	}
   488 
   489 //Call this method before "TheTest(error == KErrNone);" statement.
   490 //Otherwise if the error code is not KErrNone and the check fails, your 
   491 //cleanup code never gets called - probably you will have low memory condition on the 
   492 //test hardware and the rest of SCHSVR unit tests will fail sometimes and it will be very 
   493 //hard to find out what is going on there.
   494 EXPORT_C void CleanupHelpers::TestCleanupL()
   495 	{
   496 	// 5 second delay to clean up any launched processes 
   497 	// left over by the test
   498 	RDebug::Print(KPauseMessage, 5);
   499 	User::After(5 * KOneSecond); 
   500 
   501 	_LIT(KLogServerName, "SCHEXE");
   502 	
   503 	TInt err = CleanupHelpers::KillProcess(KLogServerName);
   504 	//dont leave if the process was not found, or if it is already dead
   505 	//but do leave if some other error occured
   506 	if((err != KErrNotFound)&&(err != KErrDied))
   507 		{
   508 		User::LeaveIfError(err);	
   509 		}
   510 	}
   511 	
   512 
   513 //
   514 //class STaskSemaphore
   515 
   516 _LIT(KSchSemaphoreName, "SCHMinimalTaskHandler");
   517 
   518 EXPORT_C void STaskSemaphore::CreateL()
   519 	{
   520 	//create semaphore and set it to 0
   521 	User::LeaveIfError(iSemaphore.CreateGlobal(KSchSemaphoreName,0));
   522 	}
   523 
   524 EXPORT_C void STaskSemaphore::WaitL()
   525 	{
   526 	RSemaphore sem;
   527 	User::LeaveIfError(sem.OpenGlobal(KSchSemaphoreName));
   528 	sem.Wait();
   529 	sem.Close();		
   530 	}
   531 
   532 EXPORT_C TInt STaskSemaphore::WaitL(TInt aTimeout)
   533 	{
   534 	RSemaphore sem;
   535 	User::LeaveIfError(sem.OpenGlobal(KSchSemaphoreName));
   536 	TInt r = sem.Wait(aTimeout);
   537 	sem.Close();		
   538 	return r;
   539 	}
   540 
   541 EXPORT_C void STaskSemaphore::Close()
   542 	{
   543 	iSemaphore.Close();
   544 	}
   545 	
   546 	
   547