|
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 <e32debug.h> |
|
24 #include <sysmonclisess.h> |
|
25 //#include "ssmstartupproperties.h" |
|
26 #include <startupproperties.h> |
|
27 #include "ssmtestprocgoodsession.h" |
|
28 #include "ssmtestprocgood.h" |
|
29 #include "ssmtestapps.h" |
|
30 |
|
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 //Signalling the start of the application |
|
82 RSemaphore sem; |
|
83 TInt err = sem.OpenGlobal(KStartProcSignalSemaphore); |
|
84 RDebug::Print(_L("KStartProcSignalSemaphore Opened with %d"), err); |
|
85 |
|
86 if(err == KErrNone) |
|
87 { |
|
88 sem.Signal(); |
|
89 sem.Close(); |
|
90 } |
|
91 |
|
92 CActiveScheduler::Start(); |
|
93 |
|
94 CleanupStack::PopAndDestroy(2); |
|
95 } |
|
96 |
|
97 TInt E32Main() |
|
98 { |
|
99 __UHEAP_MARK; |
|
100 |
|
101 CTrapCleanup* cleanup=CTrapCleanup::New(); |
|
102 TInt r=KErrNoMemory; |
|
103 if (cleanup) |
|
104 { |
|
105 TRAP(r,RunL()); |
|
106 delete cleanup; |
|
107 } |
|
108 |
|
109 __UHEAP_MARKEND; |
|
110 return r; |
|
111 } |
|
112 |
|
113 // |
|
114 // Server |
|
115 // |
|
116 |
|
117 CTestServerGood::CTestServerGood() : CServer2(0) |
|
118 { |
|
119 } |
|
120 |
|
121 CTestServerGood::~CTestServerGood() |
|
122 { |
|
123 } |
|
124 |
|
125 CServer2* CTestServerGood::NewLC() |
|
126 { |
|
127 CTestServerGood * self=new(ELeave) CTestServerGood; |
|
128 CleanupStack::PushL(self); |
|
129 self->ConstructL(); |
|
130 return self; |
|
131 } |
|
132 |
|
133 void CTestServerGood::ConstructL() |
|
134 { |
|
135 StartL(KTestProcGood); |
|
136 } |
|
137 |
|
138 static CStartupProperties* StartupPropertiesLC(TInt aRecoveryMethod) |
|
139 { |
|
140 CStartupProperties* prop = CStartupProperties::NewLC(KTestProcGood, KLaunchServerCommandLineOption); |
|
141 prop->SetMonitored(ETrue); |
|
142 prop->SetStartMethod(EWaitForStart); |
|
143 prop->SetRecoveryParams((TRecoveryMethod)aRecoveryMethod, 0); |
|
144 prop->SetNoOfRetries(1); |
|
145 prop->SetTimeout(0); |
|
146 return prop; |
|
147 } |
|
148 |
|
149 void CTestServerGoodSession::ServiceL(const RMessage2& aMessage) |
|
150 { |
|
151 TInt err = KErrNone; |
|
152 switch (aMessage.Function()) |
|
153 { |
|
154 case EMonitorSelf: |
|
155 { |
|
156 RSysMonSession sysmons; |
|
157 sysmons.OpenL(); |
|
158 CleanupClosePushL(sysmons); |
|
159 CStartupProperties* prop = StartupPropertiesLC(aMessage.Int0()); |
|
160 TRAP(err, sysmons.MonitorSelfL(*prop)); |
|
161 CleanupStack::PopAndDestroy(prop); |
|
162 CleanupStack::PopAndDestroy(&sysmons); |
|
163 break; |
|
164 } |
|
165 case ECancelMonitor: |
|
166 { |
|
167 RSysMonSession sysmons; |
|
168 sysmons.OpenL(); |
|
169 CleanupClosePushL(sysmons); |
|
170 TRAP(err, sysmons.CancelMonitorSelfL()); |
|
171 CleanupStack::PopAndDestroy(&sysmons); |
|
172 break; |
|
173 } |
|
174 case EShutDown: |
|
175 CActiveScheduler::Stop(); |
|
176 break; |
|
177 default: |
|
178 break; |
|
179 } |
|
180 aMessage.Complete(err); |
|
181 } |
|
182 |
|
183 // |
|
184 // Session |
|
185 // |
|
186 |
|
187 CSession2* CTestServerGood::NewSessionL(const TVersion&,const RMessage2&) const |
|
188 { |
|
189 return new(ELeave) CTestServerGoodSession(); |
|
190 } |
|
191 |