|
1 // Copyright (c) 2010 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 // Client / server logging for Test Framework |
|
15 // NOTE : does NOT include secure API changes in EKA2 |
|
16 // |
|
17 // |
|
18 |
|
19 |
|
20 // Test system includes |
|
21 #include <testframework.h> |
|
22 |
|
23 /** |
|
24 * |
|
25 * Global : start a server |
|
26 * NOTE. Function is global static as only one server will ever run at any time |
|
27 * (there may be multiple client sessions) |
|
28 * |
|
29 * @return "TInt" |
|
30 * Error code (KErrNone if successful) |
|
31 * |
|
32 * @xxxx |
|
33 * |
|
34 */ |
|
35 GLDEF_C TInt StartServer() |
|
36 // Start the server process/thread which lives in an (EPOC)EXE object |
|
37 { |
|
38 const TUidType serverUid(KNullUid, KNullUid, KTestFrameworkServerUid3); |
|
39 |
|
40 |
|
41 // EPOC is easy, we just create a new server process. Simultaneous launching |
|
42 // of two such processes should be detected when the second one attempts to |
|
43 // create the server object, failing with KErrAlreadyExists. |
|
44 |
|
45 RProcess server; |
|
46 TInt r = server.Create(KTestFrameworkServerImg, KNullDesC, serverUid); |
|
47 |
|
48 if (r != KErrNone) |
|
49 return r; |
|
50 |
|
51 |
|
52 TRequestStatus rendezvous; |
|
53 server.Rendezvous(rendezvous); |
|
54 |
|
55 if (rendezvous!=KRequestPending) |
|
56 { |
|
57 server.Kill(0); |
|
58 } |
|
59 else |
|
60 { |
|
61 server.Resume(); |
|
62 } |
|
63 |
|
64 |
|
65 User::WaitForRequest(rendezvous); // wait for start or death |
|
66 |
|
67 // we can't use the 'exit reason' if the server panicked as this |
|
68 // is the panic 'reason' and may be '0' which cannot be distinguished |
|
69 // from KErrNone |
|
70 if (rendezvous!=KErrNone) |
|
71 { |
|
72 server.Close(); |
|
73 } |
|
74 |
|
75 // server started (at last). Cancel and consume the death-notification |
|
76 // before reporting success |
|
77 return rendezvous.Int(); |
|
78 } |
|
79 |
|
80 /** |
|
81 * |
|
82 * Constructor for RTestFrameworkClientSession |
|
83 * |
|
84 * @xxxx |
|
85 * |
|
86 */ |
|
87 RTestFrameworkClientSession::RTestFrameworkClientSession() |
|
88 { |
|
89 } |
|
90 |
|
91 /** |
|
92 * |
|
93 * Client session : connect to server. |
|
94 * Will start a new server session if no server exists |
|
95 * |
|
96 * @return "TInt" |
|
97 * Error code (KErrNone if connect successful) |
|
98 * |
|
99 * @xxxx |
|
100 * |
|
101 */ |
|
102 TInt RTestFrameworkClientSession::Connect() |
|
103 { |
|
104 // NOTE : this loop is ugly and can probably be rewritten to be more graceful |
|
105 const TInt KNumRetries = 2; |
|
106 |
|
107 TInt retry = KNumRetries; |
|
108 for (;;) |
|
109 { |
|
110 TInt r = CreateSession(KTestFrameworkServerName, TVersion(KTestFrameworkServerMajorVersionNumber, |
|
111 KTestFrameworkServerMinorVersionNumber, |
|
112 KTestFrameworkServerBuildVersionNumber)); |
|
113 if (r == KErrNone) |
|
114 { |
|
115 #ifdef __IPC_V2_PRESENT__ |
|
116 r = ShareAuto(); |
|
117 #else |
|
118 r = Share(RSessionBase::EAutoAttach); |
|
119 #endif |
|
120 if (r!=KErrNone) |
|
121 Close(); |
|
122 return r; |
|
123 } |
|
124 if (r != KErrNotFound && r != KErrServerTerminated) |
|
125 { |
|
126 return r; |
|
127 } |
|
128 if (--retry == 0) |
|
129 return r; |
|
130 r = StartServer(); |
|
131 if (r != KErrNone && r != KErrAlreadyExists) |
|
132 return r; |
|
133 } |
|
134 } |
|
135 |
|
136 /** |
|
137 * |
|
138 * Request creation of an input window. |
|
139 * NOTE. For initialisation of input console only - unlikely to |
|
140 * be required by user |
|
141 * |
|
142 * @param "TRectBuf& aAllocatedWindow" |
|
143 * Window dimensions |
|
144 * |
|
145 * @param "TRequestStatus& aReqStat" |
|
146 * Request status |
|
147 * |
|
148 * @xxxx |
|
149 * |
|
150 */ |
|
151 void RTestFrameworkClientSession::CreateInputWindow(TRectBuf& aAllocatedWindow, TRequestStatus& aReqStat) |
|
152 { |
|
153 SendReceiveResult(ECreateInputWindow, aAllocatedWindow, aReqStat); |
|
154 } |
|
155 |
|
156 /** |
|
157 * |
|
158 * Request window change notifications |
|
159 * NOTE. For initialisation of input console only - unlikely to |
|
160 * be required by user |
|
161 * |
|
162 * @param "TRectBuf& aNewWindow" |
|
163 * New window dimensions |
|
164 * |
|
165 * @param "TRequestStatus& aReqStat" |
|
166 * Request status |
|
167 * |
|
168 * @xxxx |
|
169 * |
|
170 */ |
|
171 void RTestFrameworkClientSession::NotifyIfWindowChange(TRectBuf& aNewWindow, TRequestStatus& aReqStat) |
|
172 { |
|
173 SendReceiveResult(ENotifyIfWindowChange, aNewWindow, aReqStat); |
|
174 } |
|
175 |
|
176 /** |
|
177 * |
|
178 * Cancel window change notifications |
|
179 * NOTE. For initialisation of input console only - unlikely to |
|
180 * be required by user |
|
181 * |
|
182 * @return "TInt" |
|
183 * SendReceive error code |
|
184 * |
|
185 * @xxxx |
|
186 * |
|
187 */ |
|
188 TInt RTestFrameworkClientSession::CancelNotifyIfWindowChange() |
|
189 { |
|
190 return SendReceive(ECancelNotifyIfWindowChange); |
|
191 } |
|
192 |
|
193 |
|
194 /** |
|
195 * |
|
196 * Open a log server session |
|
197 * |
|
198 * @param "const TDesC& aLogName" |
|
199 * The log name |
|
200 * |
|
201 * @param "TInt aLogMode" |
|
202 * The log mode (a bitmask of TTestFrameworkLogMode) |
|
203 * |
|
204 * @xxxx |
|
205 * |
|
206 */ |
|
207 void RTestFrameworkClientSession::OpenLog(const TDesC& aLogName, TInt aLogMode) |
|
208 { |
|
209 (void) SendReceive(EOpenLog, aLogName, aLogMode); |
|
210 } |
|
211 |
|
212 /** |
|
213 * |
|
214 * Write message string to log server session |
|
215 * |
|
216 * @param "const TDesC& aMsg" |
|
217 * The message string |
|
218 * |
|
219 * @param "TInt aLogMode" |
|
220 * The log mode (a bitmask of TTestFrameworkLogMode) |
|
221 * |
|
222 * @xxxx |
|
223 * |
|
224 */ |
|
225 void RTestFrameworkClientSession::WriteLog(const TDesC& aMsg, TInt aLogMode) |
|
226 { |
|
227 (void) SendReceive(EWriteLog, aMsg, aLogMode); |
|
228 } |
|
229 |
|
230 /** |
|
231 * |
|
232 * Send close log message to server |
|
233 * |
|
234 * @xxxx |
|
235 * |
|
236 */ |
|
237 void RTestFrameworkClientSession::CloseLog() |
|
238 { |
|
239 SendReceive(ECloseLog); |
|
240 } |
|
241 |
|
242 /** |
|
243 * |
|
244 * Retrieve log status from server |
|
245 * |
|
246 * @return "TInt" |
|
247 * The log status (a bitmask of TTestFrameworkLogMode) |
|
248 * |
|
249 * @xxxx |
|
250 * |
|
251 */ |
|
252 TInt RTestFrameworkClientSession::LogStatus() |
|
253 { |
|
254 TInt res = 0; |
|
255 TPckgBuf<TInt> pckg; |
|
256 TInt r = SendReceiveResult(ELogStatus, pckg); |
|
257 if (r != KErrNone) |
|
258 { |
|
259 // RTestFrameworkClientSession does not log - |
|
260 // we can however return 0 to indicate an error (no outputs) |
|
261 res = 0; |
|
262 } |
|
263 else |
|
264 res = pckg(); |
|
265 return res; |
|
266 } |