systemhealthmanagement/systemhealthmgr/test/testprocgood/shmatestprocgood.cpp
changeset 0 4e1aa6a622a0
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     1 // Copyright (c) 2007-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 // testprocgood.cpp
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20  @test
       
    21  @internalComponent - Internal Symbian test code
       
    22 */
       
    23 
       
    24 #include <e32base.h>
       
    25 #include <sysmonclisess.h>
       
    26 #include <startupproperties.h>
       
    27 #include <ssm/ssmstartupproperties.h>
       
    28 #include "testprocgoodsession.h"
       
    29 #include "shmatestprocgood.h"
       
    30 #include "testapps.h"
       
    31 
       
    32 //
       
    33 // Launch code
       
    34 //
       
    35 
       
    36 /** Check if a aSwitch was given in the commandline when starting this process */
       
    37 static TBool CmdLineOptionL(const TDesC& aSwitch)
       
    38 	{
       
    39 	const TInt KMaxCommandLength = 256;
       
    40 	TBuf<KMaxCommandLength> commandLine;
       
    41 	if(User::CommandLineLength() > commandLine.MaxLength())
       
    42 		User::Leave(KErrTooBig);
       
    43 	
       
    44 	User::CommandLine(commandLine);
       
    45 	
       
    46 	TLex flagLex(commandLine);
       
    47 	while(!flagLex.Eos())
       
    48 		{
       
    49 		TPtrC token(flagLex.NextToken());
       
    50 		if(token == aSwitch)
       
    51 			{
       
    52 			return ETrue;
       
    53 			}
       
    54 		}
       
    55 	return EFalse;
       
    56 	}
       
    57 
       
    58 static void RunL()
       
    59 	{
       
    60 	User::LeaveIfError(RThread::RenameMe(KTestProcGood));
       
    61 
       
    62 	CActiveScheduler* s=new(ELeave) CActiveScheduler;
       
    63 	CleanupStack::PushL(s);
       
    64 	CActiveScheduler::Install(s);
       
    65 	
       
    66 	if(CmdLineOptionL(KLaunchServerCommandLineOption))
       
    67 		{
       
    68 		CTestServerGood::NewLC();
       
    69 		}
       
    70 		
       
    71 	if(!CmdLineOptionL(KTestProcGoodNoRendevouz))
       
    72 		{
       
    73 		RProcess::Rendezvous(KErrNone);
       
    74 		}
       
    75 
       
    76 	if(CmdLineOptionL(KFailAfterRendevouzCommandLineOption))
       
    77 		{
       
    78 		User::Leave(KErrAbort);
       
    79 		}
       
    80 		
       
    81 	_LIT(KTestGoodProcPanic, "Panic");
       
    82 	if(CmdLineOptionL(KPanicCommandLineOption1))
       
    83 		{
       
    84 		User::Panic(KTestGoodProcPanic, KProcPanic);
       
    85 		}
       
    86 
       
    87 	if(CmdLineOptionL(KPanicCommandLineOption2))
       
    88 		{
       
    89 		User::Panic(KTestGoodProcPanic, KErrNone);
       
    90 		}
       
    91 	
       
    92 	RSemaphore sem;
       
    93 	TInt err = sem.OpenGlobal(KStartShmaTestProcGood);
       
    94 	if(err == KErrNone)
       
    95 		{
       
    96 		sem.Signal();
       
    97 		sem.Close();
       
    98 		}
       
    99 	
       
   100 	CActiveScheduler::Start();
       
   101 
       
   102 	CleanupStack::PopAndDestroy(2);
       
   103 	}
       
   104 
       
   105 TInt E32Main()
       
   106 	{
       
   107 	__UHEAP_MARK;
       
   108 
       
   109 	CTrapCleanup* cleanup=CTrapCleanup::New();
       
   110 	TInt r=KErrNoMemory;
       
   111 	if (cleanup)
       
   112 		{
       
   113 		TRAP(r,RunL());
       
   114 		delete cleanup;
       
   115 		}
       
   116 
       
   117 	__UHEAP_MARKEND;
       
   118 	return r;
       
   119 	} //lint -e714 Suppress 'not referenced'
       
   120 
       
   121 //
       
   122 // Server
       
   123 //
       
   124 
       
   125 CTestServerGood::CTestServerGood() : CServer2(0)
       
   126 	{
       
   127 	}
       
   128 	
       
   129 CTestServerGood::~CTestServerGood()
       
   130 	{
       
   131 	}
       
   132 
       
   133 CServer2* CTestServerGood::NewLC()
       
   134 	{
       
   135 	CTestServerGood * self=new(ELeave) CTestServerGood;
       
   136 	CleanupStack::PushL(self);
       
   137 	self->ConstructL();
       
   138 	return self;
       
   139 	}
       
   140 
       
   141 void CTestServerGood::ConstructL()
       
   142 	{
       
   143 	StartL(KTestProcGood);
       
   144 	
       
   145 	//Signalling the start of the application
       
   146 	}
       
   147 
       
   148 static CStartupProperties* StartupPropertiesLC(TInt aRecoveryMethod)	
       
   149 	{
       
   150 	CStartupProperties* prop = CStartupProperties::NewLC(KTestProcGood, KLaunchServerCommandLineOption);
       
   151 	prop->SetMonitored(ETrue);
       
   152 	prop->SetStartMethod(EWaitForStart);	
       
   153 	prop->SetRecoveryParams((TRecoveryMethod)aRecoveryMethod, 0);
       
   154 	prop->SetNoOfRetries(1);
       
   155 	prop->SetTimeout(0);
       
   156 	return prop;
       
   157 	}
       
   158 static CSsmStartupProperties*  SsmStartupPropertiesLC(TInt aRecoveryMethod)
       
   159 	{
       
   160 	CSsmStartupProperties* prop = CSsmStartupProperties::NewLC(KTestProcGood, KLaunchServerCommandLineOption);
       
   161 	prop->SetExecutionBehaviour(ESsmWaitForSignal);	
       
   162 	TSsmMonitorInfo monitorInfo;
       
   163 	monitorInfo.iRestartPolicy = (TSsmRecoveryMethod)aRecoveryMethod;
       
   164 	monitorInfo.iRestartMode = 0;
       
   165 	monitorInfo.iTimeout = 0;
       
   166 	monitorInfo.iRetries = 1;
       
   167 	prop->SetMonitorInfoL(monitorInfo);
       
   168 	return prop;
       
   169 	}
       
   170 
       
   171 void CTestServerGoodSession::ServiceL(const RMessage2& aMessage)
       
   172 	{
       
   173 	TInt err = KErrNone;
       
   174 	switch (aMessage.Function())
       
   175 		{
       
   176 		case EMonitorSelfWithStartupProp:
       
   177 			{
       
   178 			RSysMonSession sysmons;
       
   179 			sysmons.OpenL();
       
   180 			CleanupClosePushL(sysmons);
       
   181 			CStartupProperties* prop = StartupPropertiesLC(aMessage.Int0());
       
   182 			TRAP(err, sysmons.MonitorSelfL(*prop));
       
   183 			CleanupStack::PopAndDestroy(prop);
       
   184 			CleanupStack::PopAndDestroy(&sysmons);
       
   185 			break;
       
   186 			}
       
   187 		case EMonitorSelfWithSsmStartupProp:
       
   188 			{
       
   189 			RSysMonSession sysmons;
       
   190 			sysmons.OpenL();
       
   191 			CleanupClosePushL(sysmons);
       
   192 			CSsmStartupProperties* prop = SsmStartupPropertiesLC(aMessage.Int0());
       
   193 			TRAP(err, sysmons.MonitorSelfL(*prop));
       
   194 			CleanupStack::PopAndDestroy(prop);
       
   195 			CleanupStack::PopAndDestroy(&sysmons);
       
   196 			break;
       
   197 			}
       
   198 		case ECancelMonitor:
       
   199 			{
       
   200 			RSysMonSession sysmons;
       
   201 			sysmons.OpenL();
       
   202 			CleanupClosePushL(sysmons);
       
   203 			TRAP(err, sysmons.CancelMonitorSelfL());
       
   204 			CleanupStack::PopAndDestroy(&sysmons);
       
   205 			break;
       
   206 			}
       
   207 		case EShutDown:
       
   208 			CActiveScheduler::Stop();
       
   209 			break;
       
   210 		default:
       
   211 			break;
       
   212 		}
       
   213 	aMessage.Complete(err);
       
   214 	}
       
   215 	
       
   216 //
       
   217 // Session
       
   218 //
       
   219 	
       
   220 CSession2* CTestServerGood::NewSessionL(const TVersion&,const RMessage2&) const
       
   221 	{
       
   222 	return new(ELeave) CTestServerGoodSession();
       
   223 	}
       
   224