|
1 // Copyright (c) 2006-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 */ |
|
19 |
|
20 #include <e32math.h> |
|
21 #include <messagingtestutility2.h> |
|
22 |
|
23 const TUid KServerUid3={0x102857AB}; |
|
24 |
|
25 |
|
26 /** |
|
27 Start the server process. Simultaneous launching |
|
28 of two such processes should be detected when the second one attempts to |
|
29 create the server object, failing with KErrAlreadyExists. |
|
30 */ |
|
31 static TInt StartServer() |
|
32 { |
|
33 const TUidType serverUid(KNullUid,KNullUid,KServerUid3); |
|
34 TInt r = KErrNone; |
|
35 RProcess server; |
|
36 r = server.Create(KTestServerImg,KNullDesC,serverUid); |
|
37 |
|
38 if (r != KErrNone) |
|
39 { |
|
40 return r; |
|
41 } |
|
42 TRequestStatus stat; |
|
43 server.Rendezvous(stat); |
|
44 if (stat != KRequestPending) |
|
45 { |
|
46 server.Kill(0); // abort startup |
|
47 } |
|
48 else |
|
49 { |
|
50 server.Resume(); // logon OK - start the server |
|
51 } |
|
52 User::WaitForRequest(stat); // wait for start or death |
|
53 server.Close(); |
|
54 return stat.Int(); |
|
55 } |
|
56 |
|
57 |
|
58 /** |
|
59 Connect to the server, attempting to start it if necessary |
|
60 */ |
|
61 EXPORT_C TInt RMessagingTestUtilityServer2::Connect() |
|
62 { |
|
63 TInt retry = 2; |
|
64 for (;;) |
|
65 { |
|
66 TInt r=CreateSession(KTestServerName, TVersion(0, 0, 0), 1); |
|
67 if (r != KErrNotFound && r != KErrServerTerminated) |
|
68 { |
|
69 return r; |
|
70 } |
|
71 if (--retry == 0) |
|
72 { |
|
73 return r; |
|
74 } |
|
75 r = StartServer(); |
|
76 if (r != KErrNone && r != KErrAlreadyExists) |
|
77 { |
|
78 return r; |
|
79 } |
|
80 } |
|
81 } |
|
82 |
|
83 |
|
84 /** |
|
85 Delete an entry in the Message Server index. |
|
86 */ |
|
87 EXPORT_C TInt RMessagingTestUtilityServer2::DeleteMessageStore(const TMsvId aMsvId) |
|
88 { |
|
89 TPckgBuf<TMsvId> msvId(aMsvId); |
|
90 TIpcArgs args(&msvId); |
|
91 |
|
92 TInt ret = SendReceive(EDeleteMessageStore, args); |
|
93 |
|
94 return ret; |
|
95 } |
|
96 |
|
97 |
|
98 /** |
|
99 Kill a (non protected) process. |
|
100 */ |
|
101 EXPORT_C TInt RMessagingTestUtilityServer2::KillProcess(const TProcessId aProcessId) |
|
102 { |
|
103 TPckgBuf<TProcessId> procIdBuf(aProcessId); |
|
104 TIpcArgs args(&procIdBuf); |
|
105 |
|
106 TInt ret = SendReceive(EKillProcess, args); |
|
107 |
|
108 return ret; |
|
109 } |
|
110 |
|
111 |
|
112 /** |
|
113 Copy a file regardless of data caging. |
|
114 */ |
|
115 EXPORT_C TInt RMessagingTestUtilityServer2::CopyFile(const TDesC& aSrc, const TDesC& aDest) |
|
116 { |
|
117 TIpcArgs args(&aSrc,&aDest); |
|
118 |
|
119 TInt ret = SendReceive(ECopyFile, args); |
|
120 |
|
121 return ret; |
|
122 } |
|
123 |
|
124 |
|
125 /** |
|
126 Delete a file regardless of data caging. |
|
127 */ |
|
128 EXPORT_C TInt RMessagingTestUtilityServer2::DeleteFile(const TDesC& aPath) |
|
129 { |
|
130 TIpcArgs args(&aPath); |
|
131 |
|
132 TInt ret = SendReceive(EDeleteFile, args); |
|
133 |
|
134 return ret; |
|
135 } |
|
136 |
|
137 |
|
138 /** |
|
139 Create a directory regardless of data caging. |
|
140 */ |
|
141 EXPORT_C TInt RMessagingTestUtilityServer2::MkDir(const TDesC& aPath) |
|
142 { |
|
143 TIpcArgs args(&aPath); |
|
144 |
|
145 TInt ret = SendReceive(EMkDir, args); |
|
146 |
|
147 return ret; |
|
148 } |
|
149 |
|
150 |
|
151 /** |
|
152 Remove a directory regardless of data caging. |
|
153 */ |
|
154 EXPORT_C TInt RMessagingTestUtilityServer2::RmDir(const TDesC& aPath) |
|
155 { |
|
156 TIpcArgs args(&aPath); |
|
157 |
|
158 TInt ret = SendReceive(ERmDir, args); |
|
159 |
|
160 return ret; |
|
161 } |
|
162 |
|
163 |
|
164 /** |
|
165 NewL() |
|
166 Allocates and constructs a directory object. |
|
167 |
|
168 @leave KErrNoMemory |
|
169 @return |
|
170 Returns pointer to an object of CDirDerived |
|
171 */ |
|
172 CDirDerived* CDirDerived::NewL() |
|
173 { |
|
174 CDir* dir = CDir::NewL(); |
|
175 CDirDerived* self = static_cast<CDirDerived*>(dir); |
|
176 |
|
177 return self; |
|
178 } |
|
179 |
|
180 /** |
|
181 AddL() |
|
182 Adds the specified entry to the directory. |
|
183 |
|
184 @param aEntry |
|
185 */ |
|
186 void CDirDerived::AddL(const TEntry& aEntry) |
|
187 { |
|
188 this->CDir::AddL(aEntry); |
|
189 } |
|
190 |
|
191 |
|
192 /** |
|
193 Obtain directory information regardless of data caging. |
|
194 Caller is responsible for deleting CDir object as with RFs::GetDir(). |
|
195 */ |
|
196 EXPORT_C TInt RMessagingTestUtilityServer2::GetDirL(const TDesC& aPath, const TUint aEntryAttMask, const TUint aEntrySortKey, CDir*& aDir) |
|
197 { |
|
198 TPckgBuf<TUint> entryAttMask(aEntryAttMask); |
|
199 TPckgBuf<TUint> entrySortKey(aEntrySortKey); |
|
200 |
|
201 TIpcArgs args1(&aPath, &entryAttMask, &entrySortKey); |
|
202 |
|
203 TInt ret = SendReceive(EGetDir, args1); //Create CDir object on the server. |
|
204 |
|
205 TPckgBuf<TUint> countBuf; |
|
206 TIpcArgs args2(&countBuf); |
|
207 |
|
208 ret = SendReceive(EGetDirCount, args2); //Get the number of dir entries. |
|
209 |
|
210 TUint count = countBuf(); |
|
211 |
|
212 |
|
213 CDirDerived* dirDerived = CDirDerived::NewL(); //Construct a new CDir from CDirDerived. |
|
214 |
|
215 TPckgBuf<TEntry> entryBuf; |
|
216 |
|
217 for (TUint i=0; i<count; i++) |
|
218 { |
|
219 TPckgBuf<TInt> indexBuf(i); |
|
220 TIpcArgs args3(&indexBuf, &entryBuf); |
|
221 |
|
222 ret = SendReceive(EGetDirEntry, args3); //Get each dir entry from the server. |
|
223 |
|
224 TEntry entry = entryBuf(); |
|
225 |
|
226 dirDerived->AddL(entry); //Add each entry to the client's CDir object. |
|
227 } |
|
228 |
|
229 aDir = dirDerived; //Return pointer to client's CDir object. |
|
230 |
|
231 TInt c2 = aDir->Count(); |
|
232 |
|
233 return KErrNone; |
|
234 } |
|
235 |
|
236 |
|
237 /** |
|
238 Check for a file's existence regardless of data caging. |
|
239 */ |
|
240 EXPORT_C TBool RMessagingTestUtilityServer2::FileExists(const TDesC& aFileName) |
|
241 { |
|
242 TIpcArgs args(&aFileName); |
|
243 |
|
244 TInt ret = SendReceive(EFileExists, args); |
|
245 |
|
246 return ret; |
|
247 } |
|
248 |
|
249 |
|
250 /** |
|
251 Initialise event handler. |
|
252 */ |
|
253 EXPORT_C TInt RMessagingTestUtilityServer2::EventHandlerInit() |
|
254 { |
|
255 |
|
256 TInt ret = SendReceive(EEventHandlerInit); |
|
257 |
|
258 return ret; |
|
259 } |
|
260 |
|
261 |
|
262 /** |
|
263 Add event handler. |
|
264 */ |
|
265 EXPORT_C TInt RMessagingTestUtilityServer2::EventHandlerAdd(const TDesC& aFlag, const TDesC& aCall) |
|
266 { |
|
267 TIpcArgs args(&aFlag, &aCall); |
|
268 |
|
269 TInt ret = SendReceive(EEventHandlerAdd, args); |
|
270 |
|
271 return ret; |
|
272 } |
|
273 |
|
274 |
|
275 /** |
|
276 Check event handler. |
|
277 */ |
|
278 EXPORT_C TInt RMessagingTestUtilityServer2::EventHandlerCheck() |
|
279 { |
|
280 TInt ret = SendReceive(EEventHandlerCheck); |
|
281 |
|
282 return ret; |
|
283 } |
|
284 |
|
285 |
|
286 /** |
|
287 Mount a drive regardless of data caging. |
|
288 */ |
|
289 EXPORT_C TInt RMessagingTestUtilityServer2::MountDrive(TInt aDrive) |
|
290 { |
|
291 TIpcArgs args(&aDrive); |
|
292 TInt ret = SendReceive(EMount, args); |
|
293 return ret; |
|
294 } |
|
295 |
|
296 /** |
|
297 Dismount a drive regardless of data caging. |
|
298 */ |
|
299 EXPORT_C TInt RMessagingTestUtilityServer2::UnMountDrive(TInt aDrive) |
|
300 { |
|
301 TIpcArgs args(&aDrive); |
|
302 TInt ret = SendReceive(EUnMount, args); |
|
303 return ret; |
|
304 } |