1 /* |
|
2 * Copyright (c) 2002-2004 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Client side implementation of Remote Storage FW API |
|
15 * : for control functions such as mounting and unmounting. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "rsfwcommon.h" |
|
22 #include "rsfwcontrol.h" |
|
23 |
|
24 |
|
25 // CONSTANTS |
|
26 |
|
27 #ifdef __WINS__ |
|
28 const TUint KServerMinHeapSize = 0x1000; // 4K |
|
29 const TUint KServerMaxHeapSize = 0x100000; // 64K |
|
30 #endif |
|
31 |
|
32 // ============================ MEMBER FUNCTIONS ============================== |
|
33 |
|
34 // ---------------------------------------------------------------------------- |
|
35 // RRsfwControl::RRsfwControl |
|
36 // C++ default constructor can NOT contain any code, that |
|
37 // might leave. |
|
38 // ---------------------------------------------------------------------------- |
|
39 // |
|
40 EXPORT_C RRsfwControl::RRsfwControl() : RSessionBase() |
|
41 { |
|
42 } |
|
43 |
|
44 // ---------------------------------------------------------------------------- |
|
45 // RRRsfwControl::Connect |
|
46 // Connects to the framework by starting the server if neccessary and creating |
|
47 // a session. |
|
48 // (other items were commented in a header). |
|
49 // ---------------------------------------------------------------------------- |
|
50 // |
|
51 EXPORT_C TInt RRsfwControl::Connect() |
|
52 { |
|
53 const TInt KTryCount = 3; |
|
54 |
|
55 TInt err; |
|
56 TBool retry; |
|
57 TInt i = KTryCount; |
|
58 do |
|
59 { |
|
60 err = StartServer(KRfeServerName); |
|
61 if (err == KErrNone) |
|
62 { |
|
63 err = CreateSession(KRfeServerName, |
|
64 Version(), |
|
65 KDefaultMessageSlots); |
|
66 } |
|
67 retry = ((err == KErrNotFound) || (err == KErrServerTerminated)); |
|
68 } while (retry && (++i <= KTryCount)); |
|
69 |
|
70 return err; |
|
71 } |
|
72 |
|
73 // ---------------------------------------------------------------------------- |
|
74 // RRsfwControl::Version |
|
75 // Returns the version of Remote File Engine |
|
76 // (other items were commented in a header). |
|
77 // ---------------------------------------------------------------------------- |
|
78 // |
|
79 EXPORT_C TVersion RRsfwControl::Version() |
|
80 { |
|
81 return(TVersion(KRfeMajorVersionNumber, |
|
82 KRfeMinorVersionNumber, |
|
83 KRfeBuildVersionNumber)); |
|
84 } |
|
85 |
|
86 // ---------------------------------------------------------------------------- |
|
87 // RRsfwControl::Mount |
|
88 // ---------------------------------------------------------------------------- |
|
89 // |
|
90 EXPORT_C TInt RRsfwControl::Mount(TInt aDriveLetter) |
|
91 { |
|
92 TIpcArgs args; |
|
93 args.Set(0, aDriveLetter); |
|
94 return SendRequest(EMountByDriveLetter, args); |
|
95 } |
|
96 |
|
97 // ---------------------------------------------------------------------------- |
|
98 // RRsfwControl::Mount |
|
99 // ---------------------------------------------------------------------------- |
|
100 // |
|
101 EXPORT_C TInt RRsfwControl::Mount(const TRsfwMountConfig& aMountConfig) |
|
102 { |
|
103 TPckg<TRsfwMountConfig> pckgMountConfig(aMountConfig); |
|
104 return SendRequest(EMount, TIpcArgs(&pckgMountConfig)); |
|
105 } |
|
106 |
|
107 // ---------------------------------------------------------------------------- |
|
108 // RRsfwControl::Mount |
|
109 // ---------------------------------------------------------------------------- |
|
110 // |
|
111 EXPORT_C TInt RRsfwControl::MountBlind(TInt aDriveLetter) |
|
112 { |
|
113 iArgs.Set(0, aDriveLetter); |
|
114 return Send(EMountByDriveLetter, iArgs); |
|
115 } |
|
116 |
|
117 // ---------------------------------------------------------------------------- |
|
118 // RRsfwControl::Mount |
|
119 // ---------------------------------------------------------------------------- |
|
120 // |
|
121 EXPORT_C void RRsfwControl::Mount(const TRsfwMountConfig& aMountConfig, |
|
122 TRequestStatus& aStatus) |
|
123 { |
|
124 aStatus = KRequestPending; |
|
125 iPckgBufMountConfig = aMountConfig; |
|
126 SendRequest(EMount, TIpcArgs(&iPckgBufMountConfig), aStatus); |
|
127 } |
|
128 |
|
129 // ---------------------------------------------------------------------------- |
|
130 // RRsfwControl::DismountByVolumeId |
|
131 // ---------------------------------------------------------------------------- |
|
132 // |
|
133 EXPORT_C TInt RRsfwControl::DismountByVolumeId(TInt aVolumeId) |
|
134 { |
|
135 return SendRequest(EDismountByVolumeId, TIpcArgs(aVolumeId)); |
|
136 } |
|
137 |
|
138 // ---------------------------------------------------------------------------- |
|
139 // RRsfwControl::DismountByDriveLetter |
|
140 // ---------------------------------------------------------------------------- |
|
141 // |
|
142 EXPORT_C TInt RRsfwControl::DismountByDriveLetter(TChar aDriveLetter) |
|
143 { |
|
144 aDriveLetter.UpperCase(); |
|
145 return SendRequest(EDismountByDriveLetter, TIpcArgs(aDriveLetter)); |
|
146 } |
|
147 |
|
148 |
|
149 // ---------------------------------------------------------------------------- |
|
150 // RRsfwControl::GetMountInfo |
|
151 // ---------------------------------------------------------------------------- |
|
152 // |
|
153 EXPORT_C TInt RRsfwControl::GetMountInfo(const TChar& aDriveLetter, |
|
154 TRsfwMountInfo& aMountInfo) |
|
155 { |
|
156 TPckg<TRsfwMountInfo> pckgMountInfo(aMountInfo); |
|
157 SendRequest(EGetMountInfo, TIpcArgs(aDriveLetter, &pckgMountInfo)); |
|
158 TInt err; |
|
159 if (aMountInfo.iMountConfig.iUri.Length()) |
|
160 { |
|
161 err = KErrNone; |
|
162 } |
|
163 else |
|
164 { |
|
165 err = KErrNotFound; |
|
166 } |
|
167 return err; |
|
168 } |
|
169 |
|
170 // ---------------------------------------------------------------------------- |
|
171 // RRsfwControl::SetMountConnectionState |
|
172 // ---------------------------------------------------------------------------- |
|
173 // |
|
174 EXPORT_C TInt RRsfwControl::SetMountConnectionState(const TChar& aDriveLetter, |
|
175 TUint aState) |
|
176 { |
|
177 // send a blind request |
|
178 return Send(ESetMountConnectionState, |
|
179 TIpcArgs(aDriveLetter, |
|
180 aState)); |
|
181 } |
|
182 |
|
183 // ---------------------------------------------------------------------------- |
|
184 // RRsfwControl::RefreshDirectoryL |
|
185 // ---------------------------------------------------------------------------- |
|
186 // |
|
187 EXPORT_C TInt RRsfwControl::RefreshDirectory(const TDesC& aPath) |
|
188 { |
|
189 return(SendRequest(EDirRefresh, TIpcArgs(&aPath))); |
|
190 } |
|
191 |
|
192 // ---------------------------------------------------------------------------- |
|
193 // RRsfwControl::CancelAllRemoteTransfers |
|
194 // ---------------------------------------------------------------------------- |
|
195 // |
|
196 EXPORT_C TInt RRsfwControl::CancelRemoteTransfer(const TDesC& aFile) |
|
197 { |
|
198 // server must be running in order to successfully cancel anything |
|
199 return(SendReceive(ECancelAll, TIpcArgs(&aFile))); |
|
200 } |
|
201 |
|
202 |
|
203 // ---------------------------------------------------------------------------- |
|
204 // RRsfwControl::StartServer |
|
205 // Starts the Remote File Engine if it is not running, uses semaphore to |
|
206 // synchronize startup. |
|
207 // (other items were commented in a header). |
|
208 // ---------------------------------------------------------------------------- |
|
209 // |
|
210 TInt RRsfwControl::StartServer(const TDesC& aServerName) |
|
211 { |
|
212 TInt err; |
|
213 |
|
214 TFindServer findRfe(aServerName); |
|
215 TFullName name; |
|
216 |
|
217 err = findRfe.Next(name); |
|
218 if (err == KErrNone) |
|
219 { |
|
220 // Server already running |
|
221 return KErrNone; |
|
222 } |
|
223 |
|
224 RSemaphore semaphore; |
|
225 err = semaphore.CreateGlobal(KRfeSemaphoreName, 0); |
|
226 if (err != KErrNone) |
|
227 { |
|
228 return err; |
|
229 } |
|
230 |
|
231 err = CreateServerProcess(aServerName); |
|
232 if (err != KErrNone) |
|
233 { |
|
234 semaphore.Close(); |
|
235 return err; |
|
236 } |
|
237 semaphore.Wait(); |
|
238 semaphore.Close(); |
|
239 |
|
240 return KErrNone; |
|
241 } |
|
242 |
|
243 // ---------------------------------------------------------------------------- |
|
244 // RRRsfwControl::CreateServerProcess |
|
245 // Starts the Remote File Engine using name to find the binary |
|
246 // (other items were commented in a header). |
|
247 // ---------------------------------------------------------------------------- |
|
248 // |
|
249 TInt RRsfwControl::CreateServerProcess(const TDesC& aServerName) |
|
250 { |
|
251 TInt err; |
|
252 |
|
253 // just load anything that matches with the name |
|
254 const TUidType serverUid(KNullUid, KNullUid, KNullUid); |
|
255 |
|
256 RProcess server; |
|
257 |
|
258 _LIT(KStartCommand, ""); |
|
259 err = server.Create(aServerName, KStartCommand, serverUid); |
|
260 if (err != KErrNone) |
|
261 { |
|
262 return err; |
|
263 } |
|
264 server.Resume(); |
|
265 server.Close(); |
|
266 |
|
267 return KErrNone; |
|
268 } |
|
269 |
|
270 |
|
271 |
|
272 // ---------------------------------------------------------------------------- |
|
273 // RRsfwControl::SendRequest |
|
274 // ---------------------------------------------------------------------------- |
|
275 // |
|
276 TInt RRsfwControl::SendRequest(TInt aOpCode, TIpcArgs aArgs) |
|
277 { |
|
278 TInt err = SendReceive(aOpCode, aArgs); |
|
279 if (err == KErrServerTerminated) |
|
280 { |
|
281 // Close handle before opening new, otherwise client leaks old handle and panics CONE 36 |
|
282 Close(); |
|
283 |
|
284 // try to restart the server |
|
285 err = Connect(); |
|
286 if (err == KErrNone) |
|
287 { |
|
288 err = SendReceive(aOpCode, aArgs); |
|
289 } |
|
290 } |
|
291 return err; |
|
292 } |
|
293 |
|
294 // ---------------------------------------------------------------------------- |
|
295 // RRsfwControl::SendRequest |
|
296 // ---------------------------------------------------------------------------- |
|
297 // |
|
298 void RRsfwControl::SendRequest(TInt aOpCode, |
|
299 TIpcArgs aArgs, |
|
300 TRequestStatus& aStatus) |
|
301 { |
|
302 SendReceive(aOpCode, aArgs, aStatus); |
|
303 } |
|
304 |
|
305 // End of File |
|