Ejemplo n.º 1
0
LOCAL_D void SwitchToMainThread(RMutex& aMutex)
    {    
    RThread::Rendezvous(KErrNone);         
    aMutex.Wait();     
    aMutex.Signal();
    User::After(10);
    }
Ejemplo n.º 2
0
    bool wait(unsigned long time)
    {
        TInt err = KErrNone;
        if (time == ULONG_MAX) {
            // untimed wait, loop because RCondVar::Wait may return before the condition is triggered
            do {
                err = cond.Wait(mutex);
            } while (err == KErrNone && wakeups == 0);
        } else {
            unsigned long maxWait = KMaxTInt / 1000;
            QElapsedTimer waitTimer;
            do {
                waitTimer.start();
                unsigned long waitTime = qMin(maxWait, time);
                // wait at least 1ms, as 0 means no wait
                err = cond.TimedWait(mutex, qMax(1ul, waitTime) * 1000);
                // RCondVar::TimedWait may return before the condition is triggered, update the timeout with actual wait time
                time -= qMin((unsigned long)waitTimer.elapsed(), waitTime);
            } while ((err == KErrNone && wakeups == 0) || (err == KErrTimedOut && time > 0));
        }

        Q_ASSERT_X(waiters > 0, "QWaitCondition::wait", "internal error (waiters)");
        --waiters;
        if (err == KErrNone) {
            Q_ASSERT_X(wakeups > 0, "QWaitCondition::wait", "internal error (wakeups)");
            --wakeups;
        }

        mutex.Signal();

        if (err && err != KErrTimedOut)
            report_error(err, "QWaitCondition::wait()", "cv wait");
        return err == KErrNone;
    }
Ejemplo n.º 3
0
void TRecursiveMutex::Release()
{
    if (--iCount == 0)
    {
        iOwner = 0;
        iMutex.Signal();
    }
}
Ejemplo n.º 4
0
void Wait()
	{
	RMutex syncMutex;
	if(syncMutex.OpenGlobal(KSyncMutext)!=KErrNone)
		User::Invariant();
	syncMutex.Wait();
	syncMutex.Signal();
	syncMutex.Close();
	}
Ejemplo n.º 5
0
/* Unlock the mutex */
int SDL_mutexV(SDL_mutex *mutex)
{
	if ( mutex == NULL ) {
		SDL_SetError("Passed a NULL mutex");
		return -1;
	}
	RMutex rmutex;
    rmutex.SetHandle(mutex->handle);
	rmutex.Signal();
	return(0);
}
Ejemplo n.º 6
0
void LockLeave(void* Handle)
{
	lock_t *lock = (lock_t *)Handle;
    if (lock && --lock->Counter == 0)
    {
        lock->Thread = 0;
    	RMutex p;
	    p.SetHandle(lock->Handle);
	    p.Signal();
    }
}
Ejemplo n.º 7
0
/* Free the mutex */
void SDL_DestroyMutex(SDL_mutex *mutex)
{
	if ( mutex ) 
	{
    RMutex rmutex;
    rmutex.SetHandle(mutex->handle);
	rmutex.Signal();
	rmutex.Close();
	delete(mutex);
    mutex = NULL;
	}
}
Ejemplo n.º 8
0
TInt CCapabilityTestStep::StartServer()
	{
	TInt err = KErrNone;

    RMutex mutex;
    err = mutex.CreateGlobal(KSipServerStarterMutex);
    if (err != KErrNone)
        {
        err = mutex.OpenGlobal(KSipServerStarterMutex);
        if (err != KErrNone)
            {
            return err;
            }
        }
    mutex.Wait();
        {
        // Protected with a mutex
        TFindServer findServer(KSipServerName);
        TFullName name;
	    if (findServer.Next(name) == KErrNone)
            {
            mutex.Signal();
            mutex.Close();
            return KErrNone; // Server already running
            }

	    RSemaphore semaphore;
	    err = semaphore.CreateGlobal(KSipServerSemaphoreName,0);
	    if (err == KErrNone)
		    {
	        err = CreateServerProcess(semaphore);
	        semaphore.Close();
		    }
        }
    mutex.Signal();
    mutex.Close();

    return err;
	}
Ejemplo n.º 9
0
TInt CPARAM_MESS_NAMEStep::Exec_SendReceive()
	{
	_LIT(KEsockSessStartMutex,"KESSMTX"); //Keep the descriptor short
	RMutex mutex;
	TInt r;
	// Protect the openning of the session
	// with a mutex to stop thread collision
	FOREVER
		{
		r = mutex.CreateGlobal(KEsockSessStartMutex());
		if (r == KErrNone)
			break;
		if (r != KErrAlreadyExists)
			return r;
		r=mutex.OpenGlobal(KEsockSessStartMutex());
		if (r == KErrNone)
			break;
		if (r != KErrNotFound)
			return r;
		}
	mutex.Wait(); // the exclusion ensures the session is started atomically
	iResult_Server=CreateSession(SOCKET_SERVER_NAME,Version());
	// Because ESock is now loaded by the Comms Root Server which is generally started during
	// the boot this should commonly succeed; however for test code this is still a possibility
	// Hence here we try starting it; this is an atomic operation (and cheap if it's already started)
	if (iResult_Server==KErrNotFound)
		{
		r=StartC32();
		if (r==KErrNone || r==KErrAlreadyExists)
			{
			iResult_Server=CreateSession(SOCKET_SERVER_NAME,Version());
			}
		}
	mutex.Signal();
	mutex.Close();

	if (iResult_Server == KErrNone)
		{
		iSessionCreated = ETrue;

		const TInt test_id = dispatch_num<PARAM_MESS_VALUE>::result;

		iResult_SR = do_execute(Int2Type<test_id>());
		}
	else
		{
		iSessionCreated = EFalse;
		return 0;
		}
	return r;
	}
Ejemplo n.º 10
0
/* Free the mutex */
void SDL_DestroyMutex(SDL_mutex *mutex)
{
	if ( mutex ) 
	{
    RMutex rmutex;
    rmutex.SetHandle(mutex->handle);
    if(rmutex.IsHeld())
        {
	    rmutex.Signal();
        }
	rmutex.Close();
	EpocSdlEnv::RemoveCleanupItem(mutex);
	delete(mutex);
    mutex = NULL;
	}
}
Ejemplo n.º 11
0
// --------------------------------------------------------------------------------
// void DumpToFileL( TPtrC8 aBuffer )
// --------------------------------------------------------------------------------
void DumpToFileL( TPtrC8 aBuffer )
	{
	RFs fileSession;
	TInt pushed(0);
	if( fileSession.Connect() == KErrNone )
		{
		CleanupClosePushL(fileSession);
		pushed++;
		RFile file;
#ifdef __WINS__
		if( file.Open(fileSession, KNSmlDebugOutputName(), EFileShareAny|EFileWrite) == KErrNone )
#else
		HBufC* outputName = HBufC::NewLC( KNSmlDebugOutputName().Length()+1 );
		pushed++;
		TPtr namePtr = outputName->Des();
		TDriveInfo driveInfo;
		for ( TUint driveNumber = EDriveA; driveNumber <= EDriveZ; driveNumber++ ) 
			{
			fileSession.Drive( driveInfo, driveNumber );
			if ( KDriveAttRemovable & driveInfo.iDriveAtt ) 
				{
				// this is MMC
				namePtr.Insert( 0, KNSmlDebugDriveLetters().Mid( driveNumber, 1 ));
				namePtr.Insert( 1, KNSmlDebugOutputName() );
				break;
				}
			}
		if( file.Open(fileSession, *outputName, EFileShareAny|EFileWrite) == KErrNone )
#endif

			{
			CleanupClosePushL(file);
			TInt pos(0);
			file.Seek(ESeekEnd, pos);
			RMutex mutex;
			NSmlGrabMutexLC(mutex, KNSmlDebugMutexName());
			TInt result = file.Write(aBuffer);
			TInt result2 = file.Flush();
			mutex.Signal();
			CleanupStack::PopAndDestroy(2); // file, mutex
			User::LeaveIfError(result);
			User::LeaveIfError(result2);
			}
		CleanupStack::PopAndDestroy( pushed ); // fileSession and (for target) outputName
		}
	}
Ejemplo n.º 12
0
LOCAL_D void SwitchToWorkerThread(RMutex& aMutex, RThread& aThread, TBool aSignal, TBool aWait)
    {
    if (aSignal)
        {
        aMutex.Signal();             
        User::After(10);         
        }
        
    if (aWait)
        {            
        aMutex.Wait(); 
        }
        
    TRequestStatus status;            
    aThread.Rendezvous(status);         


    User::WaitForRequest(status);            
    }    
/**
Releases the mutex if leave occurs between wait and signal.
@internalTechnology
*/
void CTzLocalizationDbAccessor::ReleaseMutex(TAny *target)
{
	RMutex *mutex = static_cast<RMutex*> (target) ;	
	mutex->Signal() ;	
}
Ejemplo n.º 14
0
/**
  
   Application invoked as part of CommandLine tests
  
   @SYMPREQ 280 File Handle Support
  
   FunctionDesc Tests Environment slots . 
   Acquires a Mutex for log file access
   Invokes EnvironmentSlotsReaderL() which returns an CApaCommandLine Object
   Verifies the values returned by the GET APIs of CApaCommandLine object with those of predefined values
   Writes "Pass" to the logfile if verification passes else "Fail" is written.
  
 */
void testEnvironmentSlotsL()
	{

	TPtrC appName;
	TPtrC docName;
	TApaCommand command = EApaCommandOpen;
	TBool testResult = PASS;
	
		
	//Get the Mutex to access the log file
	RMutex fileAccess;
	fileAccess.OpenGlobal(KTLogFileAccess);
	fileAccess.Wait();
			
	/** Invoke EnvironmenstSlotsReaderL() function which would constuct the CApaCommandLine class object
	from the environment slots and return the pointer to that object */
	//CApaCommandLine* cmdLine = CApaCommandLine::EnvironmentSlotsReaderL(); 
	
	//Method CApaCommandLine::EnvironmentSlotsReaderL has been implemented in a different fashion
	CApaCommandLine* cmdLine;
	CApaCommandLine::GetCommandLineFromProcessEnvironment(cmdLine);

	CleanupStack::PushL(cmdLine);
    				
    appName.Set(KTAppName);
	docName.Set(KTDocName);
	
	RFs fSession;
	fSession.Connect();
	RFile logFile;
	TBufC<KMaxFilePath> testFilePath(KFilePath);
	
	//Open the Log file in Write Mode			
	User::LeaveIfError(logFile.Replace(fSession,testFilePath,EFileWrite));
		
	// Compare the values returned by GET APIs with pre defined values	
	TESTCOND(appName,cmdLine->ExecutableName());
	
	if(appName != cmdLine->ExecutableName())
	{
		logFile.Write(KTFail);
		logFile.Write(KTApp);
	}
		
	TESTCOND(docName,cmdLine->DocumentName());
	if(docName != cmdLine->DocumentName())
	{
		logFile.Write(KTFail);
		logFile.Write(KTDoc);
	}
	
    TESTCOND(command,cmdLine->Command());
	
	if(command != cmdLine->Command())
	{
		logFile.Write(KTFail);
		logFile.Write(KTCommand);
	}
	          
    if(testResult == PASS)
    	{
    	logFile.Write(KTPass);
    	}
  
    	
    //Close the file and the file session
    logFile.Close();
    fSession.Close();
    
    //Signal the Mutex
    fileAccess.Signal();  
    CleanupStack::PopAndDestroy(cmdLine); 

	}
Ejemplo n.º 15
0
void LockLeave(void* Handle)
{
	RMutex p;
	p.SetHandle((int)Handle);
	p.Signal();
}
Ejemplo n.º 16
0
// -----------------------------------------------------------------------------
// InitServerL
// Initialises the SatServer.
// -----------------------------------------------------------------------------
//
LOCAL_C void InitServerL()
    {
    LOG( SIMPLE, "SATSERVER: InitServerL calling" )

    RMutex serverStartMutex;
    TInt createErr( serverStartMutex.CreateGlobal( KSatServerMtx ) );
    if ( createErr )
        {
        TInt openErr( serverStartMutex.OpenGlobal( KSatServerMtx ) );
        User::LeaveIfError( openErr );
        LOG( SIMPLE, "SATSERVER:   Opened SATSERVERMTX" )
        }

    LOG( SIMPLE, "SATSERVER:   Asking ownership of SATSERVERMTX" )
    serverStartMutex.Wait();
    LOG( SIMPLE, "SATSERVER:   Got ownership of SATSERVERMTX" )

    // create server - if one of this name does not already exist
    TFindServer findSatServer( KSatServerName );
    TFullName pathName;

    // Search for the server.
    if ( KErrNone != findSatServer.Next( pathName ) )
        {
        // We don't already exist.
        // Start scheduler and server.
        CSatSScheduler* scheduler = new ( ELeave ) CSatSScheduler;
        __ASSERT_ALWAYS( scheduler !=
            NULL, PanicServer( ESatSMainSchedulerError ) );

        CleanupStack::PushL( scheduler );
        CActiveScheduler::Install( scheduler );

        // Rename the thread.
        User::RenameThread( KSatServerName );

        // Create the server and connect to external interfaces.
        CSatSServer* server = CreateSatServerL();
        CleanupStack::PushL( server );

        // The scheduler needs access to the server instance.
        //lint -e{613} scheduler cannot be null, due assertion in creation.
        scheduler->SetServer( server );

        // Call Rendezvous to improve startup time
        RProcess::Rendezvous( KErrNone );

        LOG( SIMPLE,
            "SATSERVER:   Releasing ownership of SATSERVERMTX, Starting.." )
        serverStartMutex.Signal();

        // start fielding requests from clients
        CActiveScheduler::Start();

        // finished when the scheduler stops
        CleanupStack::PopAndDestroy( KInitServerPop ); // scheduler, server
        }
    else
        {
        LOG( SIMPLE,
            "SATSERVER:   Releasing ownership of SATSERVERMTX, Already started" )
        serverStartMutex.Signal();
        }
    serverStartMutex.Close();
    LOG( SIMPLE, "SATSERVER: InitServerL exiting" )
    }
Ejemplo n.º 17
0
// --------------------------------------------------------------------------------
// void doNSmlDebugDumpL( void* aData, TInt aLength, TText8* aFile, TInt aLine, const TText8* aMsg )
// --------------------------------------------------------------------------------
void doNSmlDebugDumpL( void* aData, TInt aLength, TText8* aFile, TInt aLine, const TText8* aMsg )
	{
	TInt pushed(0);
	HBufC8* pDateBuffer8 = HBufC8::NewLC(64);
	pushed++;
	TPtr8 dateBuffer8 = pDateBuffer8->Des();
	HBufC8* pTimeBuffer8 = HBufC8::NewLC(64);
	pushed++;
	TPtr8 timeBuffer8 = pTimeBuffer8->Des();
	NSmlGetDateAndTimeL(dateBuffer8, timeBuffer8);
	TPtrC8 data(REINTERPRET_CAST(TUint8*, aData), aLength);
	TPtrC8 fileName(aFile);
	HBufC8* buffer8 = HBufC8::NewLC(KBufferSize);
	pushed++;
	TPtr8 ptrBuffer8 = buffer8->Des();
	TPtrC8 msg(aMsg);
	if( !msg.Length() )
		{
#if !defined(__SML_DEVELOPER_DEBUG__)
		ptrBuffer8.Format(_L8("[%S %S File: %S Line: %d Length: %d]\r\n"), &dateBuffer8, &timeBuffer8, &fileName, aLine, aLength);
#else
		ptrBuffer8.Format(_L8("[%S %S Length: %d]\r\n"), &dateBuffer8, &timeBuffer8, aLength);
#endif
		}
	else
		{
#if !defined(__SML_DEVELOPER_DEBUG__)
		ptrBuffer8.Format(_L8("[%S %S File: %S Line: %d Length: %d] %S\r\n"), &dateBuffer8, &timeBuffer8, &fileName, aLine, aLength, &msg);
#else
		ptrBuffer8.Format(_L8("[%S %S Length: %d] %S\r\n"), &dateBuffer8, &timeBuffer8, aLength, &msg);
#endif
		}
	// Now we're ready to write into file
	RFs fileSession;
	if( fileSession.Connect() == KErrNone )
		{
		CleanupClosePushL(fileSession);
		pushed++;
		RFile file;
#ifdef __WINS__
		if( file.Open(fileSession, KNSmlDebugDumpName(), EFileShareAny|EFileWrite) == KErrNone )
#else
		HBufC* outputDumpName = HBufC::NewLC( KNSmlDebugDumpName().Length()+1 );
		pushed++;
		TPtr nameDumpPtr = outputDumpName->Des();
		TDriveInfo driveInfo;
		for ( TUint driveNumber = EDriveA; driveNumber <= EDriveZ; driveNumber++ ) 
			{
			fileSession.Drive( driveInfo, driveNumber );
			if ( KDriveAttRemovable & driveInfo.iDriveAtt ) 
				{
				// this is MMC
				nameDumpPtr.Insert( 0, KNSmlDebugDriveLetters().Mid( driveNumber, 1 ));
				nameDumpPtr.Insert( 1, KNSmlDebugDumpName() );
				break;
				}
			}
		if( file.Open(fileSession, *outputDumpName, EFileShareAny|EFileWrite) == KErrNone )
#endif

			{
			CleanupClosePushL(file);
			TInt pos(0);
			file.Seek(ESeekEnd, pos);
			RMutex mutex;
			NSmlGrabMutexLC(mutex, KNSmlDebugMutexNameDump());
			TInt result1 = file.Write(ptrBuffer8);
			TInt result2 = file.Write(data);
			TInt result3 = file.Write(_L8("\r\n\r\n"));
			TInt result4 = file.Flush();
			mutex.Signal();
			CleanupStack::PopAndDestroy(2); // file, mutex
			User::LeaveIfError(result1);
			User::LeaveIfError(result2);
			User::LeaveIfError(result3);
			User::LeaveIfError(result4);
			}
		}
	CleanupStack::PopAndDestroy( pushed ); // buffer8, pDateBuffer8, pTimeBuffer8
	}
Ejemplo n.º 18
0
void TestKill()
	{
	RTestProcess process;
	RTestProcess process2;
	TRequestStatus logonStatus;
	TRequestStatus logonStatus2;

	process2.Create(0,ETestProcessNull);
	process2.Logon(logonStatus2);

	// Test RProcess::Kill()

	test.Start(_L("Test killing an un-resumed process created by us"));
	process.Create(0,ETestProcessNull);
	process.Logon(logonStatus);
	process.Kill(999);
	User::WaitForRequest(logonStatus);
	test(process.ExitType()==EExitKill);
	test(logonStatus==999);
	CLOSE_AND_WAIT(process);

	test.Next(_L("Try killing un-resumed process not created by self"));
	process.Create(~(1u<<ECapabilityPowerMgmt),ETestProcessKill,process2.Id());
	process.Logon(logonStatus);
	process.Resume();
	User::WaitForRequest(logonStatus);
	test(process.ExitType()==EExitPanic); // Process should have got a Platform Security panic
	test(logonStatus==EPlatformSecurityTrap);
	test(logonStatus2==KRequestPending); // the process should still be alive
	CLOSE_AND_WAIT(process);

	test.Next(_L("Test a process killing itself"));
	process.Create(0,ETestProcessKillSelf);
	process.Logon(logonStatus);
	process.Resume();
	User::WaitForRequest(logonStatus);
	test(process.ExitType()==EExitKill);
	test(logonStatus==999);
	CLOSE_AND_WAIT(process);

	test.Next(_L("Try killing running process"));
	process.Create(~(1u<<ECapabilityPowerMgmt),ETestProcessKill,RProcess().Id());
	process.Logon(logonStatus);
	process.Resume();
	User::WaitForRequest(logonStatus);
	test(process.ExitType()==EExitPanic); // Process should have got a Platform Security panic
	test(logonStatus==EPlatformSecurityTrap);
	CLOSE_AND_WAIT(process);

	// Test RProcess::Teminate()

	test.Next(_L("Test terminating an un-resumed process created by us"));
	process.Create(0,ETestProcessNull);
	process.Logon(logonStatus);
	process.Terminate(999);
	User::WaitForRequest(logonStatus);
	test(process.ExitType()==EExitTerminate);
	test(logonStatus==999);
	CLOSE_AND_WAIT(process);

	test.Next(_L("Try terminating un-resumed process not created by self"));
	process.Create(~(1u<<ECapabilityPowerMgmt),ETestProcessTerminate,process2.Id());
	process.Logon(logonStatus);
	process.Resume();
	User::WaitForRequest(logonStatus);
	test(process.ExitType()==EExitPanic); // Process should have got a Platform Security panic
	test(logonStatus==EPlatformSecurityTrap);
	test(logonStatus2==KRequestPending); // the process should still be alive
	CLOSE_AND_WAIT(process);

	test.Next(_L("Test a process terminating itself"));
	process.Create(0,ETestProcessTerminateSelf);
	process.Logon(logonStatus);
	process.Resume();
	User::WaitForRequest(logonStatus);
	test(process.ExitType()==EExitTerminate);
	test(logonStatus==999);
	CLOSE_AND_WAIT(process);

	test.Next(_L("Try terminating running process"));
	process.Create(~(1u<<ECapabilityPowerMgmt),ETestProcessTerminate,RProcess().Id());
	process.Logon(logonStatus);
	process.Resume();
	User::WaitForRequest(logonStatus);
	test(process.ExitType()==EExitPanic); // Process should have got a Platform Security panic
	test(logonStatus==EPlatformSecurityTrap);
	CLOSE_AND_WAIT(process);

	// Test RProcess::Panic()

	test.Next(_L("Test panicking an un-resumed process created by us"));
	process.Create(0,ETestProcessNull);
	process.Logon(logonStatus);
	process.Panic(KTestPanicCategory,999);
	User::WaitForRequest(logonStatus);
	test(process.ExitType()==EExitPanic);
	test(logonStatus==999);
	CLOSE_AND_WAIT(process);

	test.Next(_L("Try panicking un-resumed process not created by self"));
	process.Create(~(1u<<ECapabilityPowerMgmt),ETestProcessPanic,process2.Id());
	process.Logon(logonStatus);
	process.Resume();
	User::WaitForRequest(logonStatus);
	test(process.ExitType()==EExitPanic); // Process should have got a Platform Security panic
	test(logonStatus==EPlatformSecurityTrap);
	test(logonStatus2==KRequestPending); // the process should still be alive
	CLOSE_AND_WAIT(process);

	test.Next(_L("Test a process panicking itself"));
	process.Create(0,ETestProcessPanicSelf);
	process.Logon(logonStatus);
	process.Resume();
	User::WaitForRequest(logonStatus);
	test(process.ExitType()==EExitPanic);
	test(logonStatus==999);
	CLOSE_AND_WAIT(process);

	test.Next(_L("Try panicking running process"));
	process.Create(~(1u<<ECapabilityPowerMgmt),ETestProcessPanic,RProcess().Id());
	process.Logon(logonStatus);
	process.Resume();
	User::WaitForRequest(logonStatus);
	test(process.ExitType()==EExitPanic); // Process should have got a Platform Security panic
	test(logonStatus==EPlatformSecurityTrap);
	CLOSE_AND_WAIT(process);

	// 

	test(logonStatus2==KRequestPending); // the process should still be alive
	process2.Resume();
	User::WaitForRequest(logonStatus2);
	test(logonStatus2==KErrNone);
	CLOSE_AND_WAIT(process2);

	// Checks with ECapabilityPowerMgmt

	test.Next(_L("Test kill running process ECapabilityPowerMgmt"));
	process2.Create(0,ETestProcessNull);
	process2.Logon(logonStatus2);
	process.Create((1<<ECapabilityPowerMgmt),ETestProcessKill,process2.Id());
	process.Logon(logonStatus);
	SyncMutex.Wait();
	process2.Resume();
	process.Resume();
	User::WaitForRequest(logonStatus);
	test(process.ExitType()==EExitKill);
	test(logonStatus==0);
	CLOSE_AND_WAIT(process);
	User::WaitForRequest(logonStatus2);
	test(process2.ExitType()==EExitKill);
	test(logonStatus2==999);
	process2.Close();
	SyncMutex.Signal();

	test.Next(_L("Test terminating running process ECapabilityPowerMgmt"));
	process2.Create(0,ETestProcessNull);
	process2.Logon(logonStatus2);
	process.Create((1<<ECapabilityPowerMgmt),ETestProcessTerminate,process2.Id());
	process.Logon(logonStatus);
	SyncMutex.Wait();
	process2.Resume();
	process.Resume();
	User::WaitForRequest(logonStatus);
	test(process.ExitType()==EExitKill);
	test(logonStatus==0);
	CLOSE_AND_WAIT(process);
	User::WaitForRequest(logonStatus2);
	test(process2.ExitType()==EExitTerminate);
	test(logonStatus2==999);
	CLOSE_AND_WAIT(process2);
	SyncMutex.Signal();

	test.Next(_L("Test panicking running process ECapabilityPowerMgmt"));
	process2.Create(0,ETestProcessNull);
	process2.Logon(logonStatus2);
	process.Create((1<<ECapabilityPowerMgmt),ETestProcessPanic,process2.Id());
	process.Logon(logonStatus);
	SyncMutex.Wait();
	process2.Resume();
	process.Resume();
	User::WaitForRequest(logonStatus);
	test(process.ExitType()==EExitKill);
	test(logonStatus==0);
	CLOSE_AND_WAIT(process);
	User::WaitForRequest(logonStatus2);
	test(process2.ExitType()==EExitPanic);
	test(logonStatus2==999);
	CLOSE_AND_WAIT(process2);
	SyncMutex.Signal();

	//

	test.End();
	}
Ejemplo n.º 19
0
void TestSetPriority()
	{
	RTestProcess process;
	RTestProcess process2;
	TProcessPriority priority;
	TRequestStatus rendezvousStatus;
	TRequestStatus logonStatus;

	test.Start(_L("Test changing our own process priority"));
	priority = process.Priority();
	process.SetPriority(EPriorityLow);
	test(process.Priority()==EPriorityLow);
	process.SetPriority(EPriorityBackground);
	test(process.Priority()==EPriorityBackground);
	process.SetPriority(EPriorityForeground);
	test(process.Priority()==EPriorityForeground);
	process.SetPriority(priority);

	test.Next(_L("Test changing unresumed process priority (which we created)"));
	process.Create(0,ETestProcessNull);
	priority = process.Priority();
	process.SetPriority(EPriorityLow);
	test(process.Priority()==EPriorityLow);
	process.SetPriority(EPriorityBackground);
	test(process.Priority()==EPriorityBackground);
	process.SetPriority(EPriorityForeground);
	test(process.Priority()==EPriorityForeground);
	process.SetPriority(priority);
	process.Kill(0);
	CLOSE_AND_WAIT(process);

	test.Next(_L("Try other process changing the priority of our created process"));
	process2.Create(0,ETestProcessNull);
	process.Create(~0u,ETestProcessPriority,process2.Id());
	process.Logon(logonStatus);
	process.Resume();
	User::WaitForRequest(logonStatus);
	test(logonStatus==KErrNone);
	CLOSE_AND_WAIT(process);
	process2.Kill(0);
	CLOSE_AND_WAIT(process2);

	test.Next(_L("Try changing other process's priority (no priority-control enabled)"));
	process.Create(~0u,ETestProcessPriorityControlOff);
	process.Rendezvous(rendezvousStatus);
	process.Logon(logonStatus);
	SyncMutex.Wait();
	process.Resume();
	User::WaitForRequest(rendezvousStatus); // Process has started
	priority = process.Priority();
	TInt result = process.SetPriority(EPriorityLow);
	test(result == KErrPermissionDenied);
	test(process.Priority()==priority); // priority shouldn't have changed
	process.SetPriority(EPriorityBackground);
	test(result == KErrPermissionDenied);
	test(process.Priority()==priority); // priority shouldn't have changed
	process.SetPriority(EPriorityForeground);
	test(result == KErrPermissionDenied);
	test(process.Priority()==priority); // priority shouldn't have changed
	test(logonStatus==KRequestPending); // wait for process to end
	SyncMutex.Signal();
	User::WaitForRequest(logonStatus);
	CLOSE_AND_WAIT(process);

	test.Next(_L("Try changing other process's priority (priority-control enabled)"));
	process.Create(~0u,ETestProcessPriorityControlOn);
	process.Rendezvous(rendezvousStatus);
	process.Logon(logonStatus);
	SyncMutex.Wait();
	process.Resume();
	User::WaitForRequest(rendezvousStatus); // Process has started
	priority = process.Priority();
	result = process.SetPriority(EPriorityForeground);
	test(result == KErrNone);
	test(process.Priority()==EPriorityForeground);
	result = process.SetPriority(EPriorityBackground);
	test(result == KErrNone);
	test(process.Priority()==EPriorityBackground);
	result = process.SetPriority(EPriorityForeground);
	test(result == KErrNone);
	test(process.Priority()==EPriorityForeground);
	result = process.SetPriority(EPriorityLow);
	test(result == KErrPermissionDenied);
	test(process.Priority()==EPriorityForeground); // should still be foreground priority
	result = process.SetPriority(EPriorityHigh);
	test(result == KErrNone);
	test(process.Priority()==EPriorityHigh);
	result = process.SetPriority(priority);
	test(result == KErrNone);
	test(logonStatus==KRequestPending); // wait for process to end
	SyncMutex.Signal();
	User::WaitForRequest(logonStatus);
	CLOSE_AND_WAIT(process);

	test.Next(_L("Try changing other process's priority (priority-control enabled and low priority)"));
	process.Create(~0u,ETestProcessPriorityControlOnAndLowPriority);
	process.Rendezvous(rendezvousStatus);
	process.Logon(logonStatus);
	SyncMutex.Wait();
	process.Resume();
	User::WaitForRequest(rendezvousStatus); // Process has started
	test(process.Priority()==EPriorityLow);
	result = process.SetPriority(EPriorityForeground);
	test(result == KErrPermissionDenied);
	test(process.Priority()==EPriorityLow);
	result = process.SetPriority(EPriorityBackground);
	test(result == KErrPermissionDenied);
	test(process.Priority()==EPriorityLow);
	result = process.SetPriority(EPriorityForeground);
	test(result == KErrPermissionDenied);
	test(process.Priority()==EPriorityLow);
	result = process.SetPriority(EPriorityLow);
	test(result == KErrPermissionDenied);
	test(process.Priority()==EPriorityLow);
	result = process.SetPriority(EPriorityHigh);
	test(result == KErrPermissionDenied);
	test(process.Priority()==EPriorityLow);
	test(logonStatus==KRequestPending); // wait for process to end
	SyncMutex.Signal();
	User::WaitForRequest(logonStatus);
	CLOSE_AND_WAIT(process);

	test.End();
	}
Ejemplo n.º 20
0
void CLogFileControl::WriteXml(const TDesC8 &aDes)
/**
 * @param aDes - send a aDes string in xml format to a log file
 */
	{
/*--------- Maintaince Warning:  -----------------------------------
******* the fomat of below is sensible from client original format.  
******* Any change should match actual string formated from client. 
******* Double check the code on client side 

* The current assumtion of format:
* First string values are seperated by sign " - " and extra pair of fields are
* seperated from main log message  by long unusual string "LogFieldsRequiredBeingAddedToAboveLogMessage"
* The \t used to seperate field name and field value and \r\n used to seperate
* each other from those pairs of field
* \t\t\t\t\t\t is used to end of whole string
--------------------------------------------------------------------------------*/
		_LIT8(KxmlHeader,"<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\r\n<LOGFILE>");
		//The order of variables:
		// time 		- aTime
		// Severity 	- aSeverity
		// Thread 		- aThread
		// Filename 	- aFilename
		// Linenumber 	- aLinenumber
		// Text 		- aText
		
		// Start of string retrive/deformating 
		HBufC8* pBuf1 = HBufC8::New(KMaxLoggerLineLength*2); //(aDes.Length()+200);
		if(!pBuf1)
			{
			return; // no memory 
			}
		TPtr8 aPtr(pBuf1->Des());  // used for searching
		TPtr8 alogbuf(pBuf1->Des());  //used for final log
		aPtr.Append(aDes);
		TPtrC8 SearchBuf;
		TInt aCount[8]; 
		aCount[0]=0;
		TInt posI(0);

        // retrive log message:
		// Retrive common part of log message:
		TInt i=0;
		for(i=1; i<6; i++)
			{
			SearchBuf.Set(aPtr.Mid(posI));
			aCount[i]=SearchBuf.Find(KSeperation8)+posI;
			posI=aCount[i]+3;
			if(aCount[i]<aCount[i-1])	
                {
                delete pBuf1;
                return; // wrong format string from client
                }
			}
		// seperating common log message and extra log fields will be easy for future maintaince.
		TLogField8* alogField = new TLogField8[6];  // the common part of log message for both 
								  					// with and without extra log fields
		if(!alogField) 
            {
            delete pBuf1;
            return; // no memory
            }

		TLogField8* extralogField=NULL; // only applied to extra log fields

		TInt alength=0;  // a length of array of extra log fields

		alogField[0].iLogTag8.Copy(_L8("TIME"));
		alogField[1].iLogTag8.Copy(_L8("SEVERITY"));
		alogField[2].iLogTag8.Copy(_L8("THREAD"));
		alogField[3].iLogTag8.Copy(_L8("FILENAME"));
		alogField[4].iLogTag8.Copy(_L8("LINENUMBER"));
		alogField[5].iLogTag8.Copy(_L8("TEXT"));
			
		alogField[0].iLogValue8.Copy(aPtr.Mid(aCount[0],aCount[1]-aCount[0]));
		for(i=1; i<5; i++)
			{
			alogField[i].iLogValue8.Copy(aPtr.Mid(aCount[i]+3,aCount[i+1]-aCount[i]-3));				
			}

		SearchBuf.Set(aPtr.Mid(posI));
		aCount[6]=SearchBuf.Find(_L8("LogFieldsRequiredBeingAddedToAboveLogMessage"))+posI; 
		if(aCount[6]<posI)  // no addtional fields. Find return value is KErrNotFound or >0
			{
			alogField[5].iLogValue8.Copy(aPtr.Mid(aCount[5]+3,aDes.Length()-aCount[5]-5));
			}
		else
            {
			alogField[5].iLogValue8.Copy(aPtr.Mid(aCount[5]+3,aCount[6]-aCount[5]-5));
			posI=aCount[6]+45;  //45 is from the length of long string and a tab
			SearchBuf.Set(aPtr.Mid(posI));
			aCount[7]=SearchBuf.Find(_L8("\r\n"))+posI;
			TLex8 lex(aPtr.Mid(posI,aCount[7]-posI));  // get the length
			TInt err=lex.Val(alength); 
			if (err)
                alength=0; // ignor the extra log fields. Let the log go

			// Retrive the extra log fields
			extralogField = new TLogField8[alength];
			if(!extralogField)
                {
                delete pBuf1; 
                return; // no memory
                }
			for(TInt i=0; i<alength; i++)
				{
				aCount[6]=aCount[7]+2;
				SearchBuf.Set(aPtr.Mid(aCount[6]));
				aCount[7]=SearchBuf.Find(_L8("\t"))+aCount[6];
				extralogField[i].iLogTag8.Copy(aPtr.Mid(aCount[6],aCount[7]-aCount[6]));
				aCount[6]=aCount[7]+1;
				SearchBuf.Set(aPtr.Mid(aCount[6]));
				aCount[7]=SearchBuf.Find(_L8("\r\n"))+aCount[6];
				extralogField[i].iLogValue8.Copy(aPtr.Mid(aCount[6],aCount[7]-aCount[6]));
				}
            }
		// Start to organize an XML format:
		TInt afileSize;
		_LIT(KLogMutex, "LoggingServerMutex");
		RMutex mutex;
		TInt r = mutex.CreateGlobal(KLogMutex);
		if(r==KErrAlreadyExists)
			r = mutex.OpenGlobal(KLogMutex);  
		
		if(!r)
            mutex.Wait(); // If still failed, let logging go without bother the mutex.
		iLogFile.Size(afileSize);
		if(afileSize<12) // 12 is from charters of "\r\n</LOGFILE>" 
					//It shoud happened once at the beginning of the file
					// such as overwrite mode
            {
			afileSize=12; // used for lock position
			alogbuf.Copy(KxmlHeader);
			}
		alogbuf.Append(_L8("\r\n<MESSAGE>\r\n"));
		for(TInt i=0; i<6; i++)
			{
			alogbuf.Append(_L8("  <"));
			alogbuf.Append(alogField[i].iLogTag8);
			alogbuf.Append(_L8(">"));
			alogbuf.Append(alogField[i].iLogValue8);
			alogbuf.Append(_L8("</"));
			alogbuf.Append(alogField[i].iLogTag8);
			alogbuf.Append(_L8(">\r\n"));				
			}
		for(TInt i=0; i<alength; i++)  
			{
			alogbuf.Append(_L8("  <"));
			alogbuf.Append(extralogField[i].iLogTag8);
			alogbuf.Append(_L8(">"));
			alogbuf.Append(extralogField[i].iLogValue8);
			alogbuf.Append(_L8("</"));
			alogbuf.Append(extralogField[i].iLogTag8);
			alogbuf.Append(_L8(">\r\n"));				
			}
		
		alogbuf.Append(_L8("</MESSAGE>"));
		alogbuf.Append(_L8("\r\n</LOGFILE>"));
		
		iLogFile.Write(afileSize-12, alogbuf,iStatus);
													
		if(!r)	
			{
			mutex.Signal();
			mutex.Close();				
			} 

		if(extralogField)
            delete[] extralogField;

		delete[] alogField;	
		delete pBuf1;
	}
Ejemplo n.º 21
0
// ---------------------------------------------------------
// TInt RSCPClient::Connect()
// Creates a new session, and starts the server, if required.
// 
// Status : Approved
// ---------------------------------------------------------
//
EXPORT_C TInt RSCPClient::Connect()
    {
    Dprint( (_L("--> RSCPClient::Connect()") ));
    
    // Use a mutex-object so that two processes cannot start the server at the same time
    RMutex startMutex;
    
    TRAPD( errf, FeatureManager::InitializeLibL() );
	if( errf != KErrNone )
		{
		return errf;
		}
		if(FeatureManager::FeatureSupported(KFeatureIdSapDeviceLockEnhancements))
		{
			isFlagEnabled = ETrue;
		}
		else
		{
			isFlagEnabled = EFalse;
		}
		FeatureManager::UnInitializeLib();
    TInt mRet = startMutex.OpenGlobal( KSCPServerName );
    if ( mRet == KErrNotFound )
        {
        mRet = startMutex.CreateGlobal( KSCPServerName );
        }
        
    if ( mRet != KErrNone )
        {        
        return mRet;
        }
    
    // Acquire the mutex
    startMutex.Wait();
    
    TInt retry = KSCPConnectRetries;
    TInt r;
    for (;;)
        {        
        r = CreateSession( KSCPServerName, Version(), KDefaultMessageSlots );
        
        if ( ( r != KErrNotFound ) && ( r != KErrServerTerminated  ) )
            {
            break;
            }
        
        if ( --retry == 0 )
            {
            break;
            }
      
        r = StartServer();
        
        if ( ( r != KErrNone ) && ( r != KErrAlreadyExists ) )
            {
            break;   
            }
        }
    
    Dprint( (_L("<-- RSCPClient::Connect(), exiting: %d"), r ));
    
    // Release the mutex
    startMutex.Signal();
    startMutex.Close();

    return r;
    }