|
1 // Copyright (c) 2004-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 #include <e32math.h> |
|
17 #include "messagingtestutility.h" |
|
18 |
|
19 const TUid KServerUid3={0x1020427D}; |
|
20 |
|
21 |
|
22 |
|
23 static TInt StartServer() |
|
24 // |
|
25 // Start the server process. Simultaneous launching |
|
26 // of two such processes should be detected when the second one attempts to |
|
27 // create the server object, failing with KErrAlreadyExists. |
|
28 // |
|
29 { |
|
30 const TUidType serverUid(KNullUid,KNullUid,KServerUid3); |
|
31 TInt r=KErrNone; |
|
32 RProcess server; |
|
33 r=server.Create(KTestServerImg,KNullDesC,serverUid); |
|
34 |
|
35 |
|
36 if (r!=KErrNone) |
|
37 return r; |
|
38 TRequestStatus stat; |
|
39 server.Rendezvous(stat); |
|
40 if (stat!=KRequestPending) |
|
41 server.Kill(0); // abort startup |
|
42 else |
|
43 server.Resume(); // logon OK - start the server |
|
44 User::WaitForRequest(stat); // wait for start or death |
|
45 server.Close(); |
|
46 return stat.Int(); |
|
47 } |
|
48 |
|
49 |
|
50 EXPORT_C TInt RMessagingTestUtilityServer::Connect() |
|
51 // |
|
52 // Connect to the server, attempting to start it if necessary |
|
53 // |
|
54 { |
|
55 TInt retry=2; |
|
56 for (;;) |
|
57 { |
|
58 TInt r=CreateSession(KTestServerName,TVersion(0,0,0),1); |
|
59 if (r!=KErrNotFound && r!=KErrServerTerminated) |
|
60 return r; |
|
61 if (--retry==0) |
|
62 return r; |
|
63 r=StartServer(); |
|
64 if (r!=KErrNone && r!=KErrAlreadyExists) |
|
65 return r; |
|
66 } |
|
67 } |
|
68 |
|
69 |
|
70 EXPORT_C TInt RMessagingTestUtilityServer::DeleteMessageStore(const TMsvId aMsvId) |
|
71 // |
|
72 // Delete an entry in the Message Server index. |
|
73 // |
|
74 { |
|
75 |
|
76 TPckgBuf<TMsvId> msvId(aMsvId); |
|
77 TIpcArgs args(&msvId); |
|
78 |
|
79 TInt ret = SendReceive(EDeleteMessageStore, args); |
|
80 |
|
81 return ret; |
|
82 } |
|
83 |
|
84 EXPORT_C TInt RMessagingTestUtilityServer::KillProcess(const TProcessId aProcessId) |
|
85 // |
|
86 // Kill a (non protected) process. |
|
87 // |
|
88 { |
|
89 TPckgBuf<TProcessId> procIdBuf(aProcessId); |
|
90 TIpcArgs args(&procIdBuf); |
|
91 |
|
92 TInt ret = SendReceive(EKillProcess, args); |
|
93 |
|
94 return ret; |
|
95 } |
|
96 |
|
97 EXPORT_C TInt RMessagingTestUtilityServer::CopyFile(const TDesC& aSrc, const TDesC& aDest) |
|
98 // |
|
99 // Copy a file regardless of data caging. |
|
100 // |
|
101 { |
|
102 |
|
103 TIpcArgs args(&aSrc,&aDest); |
|
104 |
|
105 TInt ret = SendReceive(ECopyFile, args); |
|
106 |
|
107 return ret; |
|
108 } |
|
109 |
|
110 EXPORT_C TInt RMessagingTestUtilityServer::DeleteFile(const TDesC& aPath) |
|
111 // |
|
112 // Delete a file regardless of data caging. |
|
113 // |
|
114 { |
|
115 |
|
116 TIpcArgs args(&aPath); |
|
117 |
|
118 TInt ret = SendReceive(EDeleteFile, args); |
|
119 |
|
120 return ret; |
|
121 } |
|
122 |
|
123 EXPORT_C TInt RMessagingTestUtilityServer::MkDir(const TDesC& aPath) |
|
124 // |
|
125 // Create a directory regardless of data caging. |
|
126 // |
|
127 { |
|
128 |
|
129 TIpcArgs args(&aPath); |
|
130 |
|
131 TInt ret = SendReceive(EMkDir, args); |
|
132 |
|
133 return ret; |
|
134 } |
|
135 |
|
136 EXPORT_C TInt RMessagingTestUtilityServer::RmDir(const TDesC& aPath) |
|
137 // |
|
138 // Remove a directory regardless of data caging. |
|
139 // |
|
140 { |
|
141 |
|
142 TIpcArgs args(&aPath); |
|
143 |
|
144 TInt ret = SendReceive(ERmDir, args); |
|
145 |
|
146 return ret; |
|
147 } |
|
148 |
|
149 // |
|
150 |
|
151 CDirDerived* CDirDerived::NewL() |
|
152 { |
|
153 CDir* dir = CDir::NewL(); |
|
154 CDirDerived* self = static_cast<CDirDerived*>(dir); |
|
155 |
|
156 return self; |
|
157 } |
|
158 |
|
159 void CDirDerived::AddL(const TEntry& aEntry) |
|
160 { |
|
161 this->CDir::AddL(aEntry); |
|
162 } |
|
163 |
|
164 EXPORT_C TInt RMessagingTestUtilityServer::GetDirL(const TDesC& aPath, const TUint aEntryAttMask, const TUint aEntrySortKey, CDir*& aDir) |
|
165 // |
|
166 // Obtain directory information regardless of data caging. |
|
167 // Caller is responsible for deleting CDir object as with RFs::GetDir(). |
|
168 // |
|
169 { |
|
170 TPckgBuf<TUint> entryAttMask(aEntryAttMask); |
|
171 TPckgBuf<TUint> entrySortKey(aEntrySortKey); |
|
172 |
|
173 TIpcArgs args1(&aPath, &entryAttMask, &entrySortKey); |
|
174 |
|
175 TInt ret = SendReceive(EGetDir, args1); //Create CDir object on the server. |
|
176 |
|
177 TPckgBuf<TUint> countBuf; |
|
178 TIpcArgs args2(&countBuf); |
|
179 |
|
180 ret = SendReceive(EGetDirCount, args2); //Get the number of dir entries. |
|
181 |
|
182 TUint count = countBuf(); |
|
183 |
|
184 |
|
185 CDirDerived* dirDerived = CDirDerived::NewL(); //Construct a new CDir from CDirDerived. |
|
186 |
|
187 TPckgBuf<TEntry> entryBuf; |
|
188 |
|
189 for (TUint i=0; i<count; i++) |
|
190 { |
|
191 TPckgBuf<TInt> indexBuf(i); |
|
192 TIpcArgs args3(&indexBuf, &entryBuf); |
|
193 |
|
194 ret = SendReceive(EGetDirEntry, args3); //Get each dir entry from the server. |
|
195 |
|
196 TEntry entry = entryBuf(); |
|
197 |
|
198 dirDerived->AddL(entry); //Add each entry to the client's CDir object. |
|
199 } |
|
200 |
|
201 aDir = dirDerived; //Return pointer to client's CDir object. |
|
202 |
|
203 TInt c2 = aDir->Count(); |
|
204 |
|
205 return KErrNone; |
|
206 } |
|
207 |
|
208 EXPORT_C TBool RMessagingTestUtilityServer::FileExists(const TDesC& aFileName) |
|
209 // |
|
210 // Check for a file's existence regardless of data caging. |
|
211 // |
|
212 { |
|
213 TIpcArgs args(&aFileName); |
|
214 |
|
215 TInt ret = SendReceive(EFileExists, args); |
|
216 |
|
217 return ret; |
|
218 } |
|
219 |
|
220 //EOF |