|
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 // |
|
15 |
|
16 /** |
|
17 @file |
|
18 @test |
|
19 @internalComponent - Internal Symbian test code |
|
20 */ |
|
21 |
|
22 #include <e32base.h> |
|
23 #include <sysmonclisess.h> |
|
24 #include <startupproperties.h> |
|
25 #include "testprocgoodsession.h" |
|
26 #include "testprocgood.h" |
|
27 #include "testapps.h" |
|
28 |
|
29 // |
|
30 // Launch code |
|
31 // |
|
32 |
|
33 /** Check if a aSwitch was given in the commandline when starting this process */ |
|
34 static TBool CmdLineOptionL(const TDesC& aSwitch) |
|
35 { |
|
36 const TInt KMaxCommandLength = 256; |
|
37 TBuf<KMaxCommandLength> commandLine; |
|
38 if(User::CommandLineLength() > commandLine.MaxLength()) |
|
39 User::Leave(KErrTooBig); |
|
40 |
|
41 User::CommandLine(commandLine); |
|
42 |
|
43 TLex flagLex(commandLine); |
|
44 while(!flagLex.Eos()) |
|
45 { |
|
46 TPtrC token(flagLex.NextToken()); |
|
47 if(token == aSwitch) |
|
48 { |
|
49 return ETrue; |
|
50 } |
|
51 } |
|
52 return EFalse; |
|
53 } |
|
54 |
|
55 static void RunL() |
|
56 { |
|
57 User::LeaveIfError(RThread::RenameMe(KTestProcGood)); |
|
58 |
|
59 CActiveScheduler* s=new(ELeave) CActiveScheduler; |
|
60 CleanupStack::PushL(s); |
|
61 CActiveScheduler::Install(s); |
|
62 |
|
63 if(CmdLineOptionL(KLaunchServerCommandLineOption)) |
|
64 { |
|
65 CTestServerGood::NewLC(); |
|
66 } |
|
67 |
|
68 if(!CmdLineOptionL(KTestProcGoodNoRendevouz)) |
|
69 { |
|
70 RProcess::Rendezvous(KErrNone); |
|
71 } |
|
72 |
|
73 if(CmdLineOptionL(KFailAfterRendevouzCommandLineOption)) |
|
74 { |
|
75 User::Leave(KErrAbort); |
|
76 } |
|
77 |
|
78 CActiveScheduler::Start(); |
|
79 |
|
80 CleanupStack::PopAndDestroy(2); |
|
81 } |
|
82 |
|
83 TInt E32Main() |
|
84 { |
|
85 __UHEAP_MARK; |
|
86 |
|
87 CTrapCleanup* cleanup=CTrapCleanup::New(); |
|
88 TInt r=KErrNoMemory; |
|
89 if (cleanup) |
|
90 { |
|
91 TRAP(r,RunL()); |
|
92 delete cleanup; |
|
93 } |
|
94 |
|
95 __UHEAP_MARKEND; |
|
96 return r; |
|
97 } |
|
98 |
|
99 // |
|
100 // Server |
|
101 // |
|
102 |
|
103 CTestServerGood::CTestServerGood() : CServer2(0) |
|
104 { |
|
105 } |
|
106 |
|
107 CTestServerGood::~CTestServerGood() |
|
108 { |
|
109 } |
|
110 |
|
111 CServer2* CTestServerGood::NewLC() |
|
112 { |
|
113 CTestServerGood * self=new(ELeave) CTestServerGood; |
|
114 CleanupStack::PushL(self); |
|
115 self->ConstructL(); |
|
116 return self; |
|
117 } |
|
118 |
|
119 void CTestServerGood::ConstructL() |
|
120 { |
|
121 StartL(KTestProcGood); |
|
122 } |
|
123 |
|
124 static CStartupProperties* StartupPropertiesLC(TInt aRecoveryMethod) |
|
125 { |
|
126 CStartupProperties* prop = CStartupProperties::NewLC(KTestProcGood, KLaunchServerCommandLineOption); |
|
127 prop->SetMonitored(ETrue); |
|
128 prop->SetStartMethod(EWaitForStart); |
|
129 prop->SetRecoveryParams((TRecoveryMethod)aRecoveryMethod, 0); |
|
130 prop->SetNoOfRetries(1); |
|
131 prop->SetTimeout(0); |
|
132 return prop; |
|
133 } |
|
134 |
|
135 void CTestServerGoodSession::ServiceL(const RMessage2& aMessage) |
|
136 { |
|
137 TInt err = KErrNone; |
|
138 switch (aMessage.Function()) |
|
139 { |
|
140 case EMonitorSelf: |
|
141 { |
|
142 RSysMonSession sysmons; |
|
143 sysmons.OpenL(); |
|
144 CleanupClosePushL(sysmons); |
|
145 CStartupProperties* prop = StartupPropertiesLC(aMessage.Int0()); |
|
146 TRAP(err, sysmons.MonitorSelfL(*prop)); |
|
147 CleanupStack::PopAndDestroy(prop); |
|
148 CleanupStack::PopAndDestroy(&sysmons); |
|
149 break; |
|
150 } |
|
151 case ECancelMonitor: |
|
152 { |
|
153 RSysMonSession sysmons; |
|
154 sysmons.OpenL(); |
|
155 CleanupClosePushL(sysmons); |
|
156 TRAP(err, sysmons.CancelMonitorSelfL()); |
|
157 CleanupStack::PopAndDestroy(&sysmons); |
|
158 break; |
|
159 } |
|
160 case EShutDown: |
|
161 CActiveScheduler::Stop(); |
|
162 break; |
|
163 default: |
|
164 break; |
|
165 } |
|
166 aMessage.Complete(err); |
|
167 } |
|
168 |
|
169 // |
|
170 // Session |
|
171 // |
|
172 |
|
173 CSession2* CTestServerGood::NewSessionL(const TVersion&,const RMessage2&) const |
|
174 { |
|
175 return new(ELeave) CTestServerGoodSession(); |
|
176 } |
|
177 |