|
1 /* |
|
2 * Copyright (c) 2006-2007 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: Thumbnail server client-side session |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "thumbnailsession.h" |
|
21 #include "thumbnailmanagerconstants.h" |
|
22 |
|
23 // ======== MEMBER FUNCTIONS ======== |
|
24 |
|
25 // --------------------------------------------------------------------------- |
|
26 // RThumbnailSession::RThumbnailSession() |
|
27 // C++ default constructor can NOT contain any code, that might leave. |
|
28 // --------------------------------------------------------------------------- |
|
29 // |
|
30 RThumbnailSession::RThumbnailSession(): RSessionBase() |
|
31 { |
|
32 // No implementation required |
|
33 } |
|
34 |
|
35 |
|
36 // --------------------------------------------------------------------------- |
|
37 // RThumbnailSession::Connect() |
|
38 // --------------------------------------------------------------------------- |
|
39 // |
|
40 TInt RThumbnailSession::Connect() |
|
41 { |
|
42 StartServer(); |
|
43 |
|
44 // special case |
|
45 // wait possibly needed here to give an old server process |
|
46 // time to enter shutdown state |
|
47 User::After(1000); |
|
48 |
|
49 TInt err = CreateSession( KThumbnailServerName, Version(), KMessageSlots ); |
|
50 TInt retry = 1; |
|
51 |
|
52 // special case |
|
53 // old server still alive, wait and try again |
|
54 while (retry <= 10 && err != KErrNone) |
|
55 { |
|
56 User::After(retry * 50000); |
|
57 StartServer(); |
|
58 err = CreateSession( KThumbnailServerName, Version(), KMessageSlots ); |
|
59 retry++; |
|
60 } |
|
61 |
|
62 return err; |
|
63 } |
|
64 |
|
65 |
|
66 // --------------------------------------------------------------------------- |
|
67 // RThumbnailSession::Close() |
|
68 // Closes session |
|
69 // --------------------------------------------------------------------------- |
|
70 // |
|
71 void RThumbnailSession::Close() |
|
72 { |
|
73 RSessionBase::Close(); |
|
74 } |
|
75 |
|
76 |
|
77 // --------------------------------------------------------------------------- |
|
78 // RThumbnailSession::Version() |
|
79 // Closes session |
|
80 // --------------------------------------------------------------------------- |
|
81 // |
|
82 TVersion RThumbnailSession::Version() |
|
83 { |
|
84 return TVersion( KThumbnailServerMajorVersionNumber, |
|
85 KThumbnailServerMinorVersionNumber, KThumbnailServerBuildVersionNumber ) |
|
86 ; |
|
87 } |
|
88 |
|
89 |
|
90 // --------------------------------------------------------------------------- |
|
91 // RThumbnailSession::StartServer() |
|
92 // --------------------------------------------------------------------------- |
|
93 // |
|
94 TInt RThumbnailSession::StartServer() |
|
95 { |
|
96 TInt res( KErrNone ); |
|
97 // create server - if one of this name does not already exist |
|
98 |
|
99 TFindServer findServer( KThumbnailServerName ); |
|
100 TFullName name; |
|
101 if ( findServer.Next( name ) != KErrNone ) |
|
102 // we don't exist already |
|
103 { |
|
104 RProcess server; |
|
105 // Create the server process |
|
106 // KNullDesC param causes server's E32Main() to be run |
|
107 res = server.Create( KThumbnailServerExe, KNullDesC ); |
|
108 if ( res != KErrNone ) |
|
109 // thread created ok - now start it going |
|
110 { |
|
111 return res; |
|
112 } |
|
113 |
|
114 // Process created successfully |
|
115 TRequestStatus status; |
|
116 server.Rendezvous( status ); |
|
117 server.Resume(); // start it going |
|
118 |
|
119 // Wait until the completion of the server creation |
|
120 User::WaitForRequest( status ); |
|
121 |
|
122 if ( status != KErrNone ) |
|
123 { |
|
124 server.Close(); |
|
125 return status.Int(); |
|
126 } |
|
127 // Server created successfully |
|
128 server.Close(); // we're no longer interested in the other process |
|
129 |
|
130 } |
|
131 return res; |
|
132 } |
|
133 |
|
134 |
|
135 // --------------------------------------------------------------------------- |
|
136 // Request a thumbnail for an object file using file handle |
|
137 // --------------------------------------------------------------------------- |
|
138 // |
|
139 void RThumbnailSession::RequestThumbnailL( const RFile64& aFile, const TDesC& aTargetUri, |
|
140 TThumbnailRequestParamsPckg& aParams, TRequestStatus& aStatus ) |
|
141 { |
|
142 TIpcArgs args( &aParams, KCheckValue ); // 1st and 2nd argument |
|
143 User::LeaveIfError( aFile.TransferToServer( args, 2, 3 )); // 3th and 4th argument |
|
144 aParams().iTargetUri = aTargetUri; |
|
145 SendReceive( ERequestThumbByFileHandleAsync, args, aStatus ); |
|
146 } |
|
147 |
|
148 |
|
149 // --------------------------------------------------------------------------- |
|
150 // Request a thumbnail for an object file using file path |
|
151 // --------------------------------------------------------------------------- |
|
152 // |
|
153 void RThumbnailSession::RequestThumbnailL( const TDesC& aPath, const TDesC& aTargetUri, const TThumbnailId /*aThumbnailId*/, |
|
154 TThumbnailRequestParamsPckg& aParams, TRequestStatus& aStatus ) |
|
155 { |
|
156 TIpcArgs args( &aParams, KCheckValue); |
|
157 aParams().iFileName = aPath; |
|
158 aParams().iTargetUri = aTargetUri; |
|
159 |
|
160 if(aPath.Length()== 0) |
|
161 { |
|
162 SendReceive( ERequestThumbByIdAsync, args, aStatus ); |
|
163 } |
|
164 else |
|
165 { |
|
166 SendReceive( ERequestThumbByPathAsync, args, aStatus ); |
|
167 } |
|
168 } |
|
169 |
|
170 // --------------------------------------------------------------------------- |
|
171 // Request a thumbnail for an object file using file path |
|
172 // --------------------------------------------------------------------------- |
|
173 // |
|
174 void RThumbnailSession::RequestThumbnailL( const TThumbnailId aThumbnailId, |
|
175 const TDesC& /*aTargetUri*/, |
|
176 TThumbnailRequestParamsPckg& aParams, |
|
177 TRequestStatus& aStatus ) |
|
178 { |
|
179 TIpcArgs args( &aParams, KCheckValue ); |
|
180 aParams().iThumbnailId = aThumbnailId; |
|
181 SendReceive( ERequestThumbByIdAsync, args, aStatus ); |
|
182 } |
|
183 |
|
184 #if 0 |
|
185 // --------------------------------------------------------------------------- |
|
186 // Request a thumbnail for an object file using file path |
|
187 // --------------------------------------------------------------------------- |
|
188 // |
|
189 void RThumbnailSession::RequestThumbnailL( const TDesC& aPath, const TDesC& aTargetUri, |
|
190 TThumbnailRequestParamsPckg& aParams, TRequestStatus& aStatus ) |
|
191 { |
|
192 TIpcArgs args( &aParams ); |
|
193 aParams().iFileName = aPath; |
|
194 aParams().iTargetUri = aTargetUri; |
|
195 SendReceive( ERequestThumbByPathAsync, args, aStatus ); |
|
196 } |
|
197 #endif |
|
198 |
|
199 void RThumbnailSession::RequestSetThumbnailL( |
|
200 TDesC8* aBuffer, const TDesC& aTargetUri, |
|
201 TThumbnailRequestParamsPckg& aParams, |
|
202 TRequestStatus& aStatus ) |
|
203 { |
|
204 if( !aBuffer ) |
|
205 { |
|
206 User::Leave( KErrArgument ); |
|
207 } |
|
208 |
|
209 TIpcArgs args( &aParams, aBuffer, aBuffer->Length(), KCheckValue ); |
|
210 aParams().iTargetUri = aTargetUri; |
|
211 SendReceive( ERequestSetThumbnailByBuffer, args, aStatus ); |
|
212 } |
|
213 |
|
214 void RThumbnailSession::RequestSetThumbnailL( |
|
215 TInt aBitmapHandle, const TDesC& aTargetUri, |
|
216 TThumbnailRequestParamsPckg& aParams, |
|
217 TRequestStatus& aStatus ) |
|
218 { |
|
219 if( !aBitmapHandle ) |
|
220 { |
|
221 User::Leave( KErrArgument ); |
|
222 } |
|
223 |
|
224 TIpcArgs args( &aParams, aBitmapHandle, KCheckValue ); |
|
225 aParams().iTargetUri = aTargetUri; |
|
226 SendReceive( ERequestSetThumbnailByBitmap, args, aStatus ); |
|
227 } |
|
228 |
|
229 // --------------------------------------------------------------------------- |
|
230 // Release bitmap instance kept by server process |
|
231 // --------------------------------------------------------------------------- |
|
232 // |
|
233 void RThumbnailSession::ReleaseBitmap( TInt aBitmapHandle ) |
|
234 { |
|
235 TInt err = Send( EReleaseBitmap, TIpcArgs( aBitmapHandle )); |
|
236 while ( err == KErrServerBusy ) |
|
237 { |
|
238 err = Send( EReleaseBitmap, TIpcArgs( aBitmapHandle )); |
|
239 } |
|
240 } |
|
241 |
|
242 |
|
243 // --------------------------------------------------------------------------- |
|
244 // Cancel pending thumbnail request |
|
245 // --------------------------------------------------------------------------- |
|
246 // |
|
247 TInt RThumbnailSession::CancelRequest( TThumbnailRequestId aRequestId ) |
|
248 { |
|
249 TInt err = SendReceive( ECancelRequest, TIpcArgs( aRequestId )); |
|
250 while ( err == KErrServerBusy ) |
|
251 { |
|
252 err = SendReceive( ECancelRequest, TIpcArgs( aRequestId )); |
|
253 } |
|
254 return err; |
|
255 } |
|
256 |
|
257 |
|
258 // --------------------------------------------------------------------------- |
|
259 // Change priority of pending thumbnail request |
|
260 // --------------------------------------------------------------------------- |
|
261 // |
|
262 TInt RThumbnailSession::ChangePriority( TThumbnailRequestId aRequestId, TInt |
|
263 aNewPriority ) |
|
264 { |
|
265 TInt err = SendReceive( EChangePriority, TIpcArgs( aRequestId, aNewPriority )); |
|
266 while ( err == KErrServerBusy ) |
|
267 { |
|
268 err = SendReceive( EChangePriority, TIpcArgs( aRequestId, aNewPriority )); |
|
269 } |
|
270 return err; |
|
271 } |
|
272 |
|
273 // --------------------------------------------------------------------------- |
|
274 // Delete thumbnails for given object file |
|
275 // --------------------------------------------------------------------------- |
|
276 // |
|
277 TInt RThumbnailSession::CreateThumbnails( const RFile64& aFile, TDisplayMode aDisplayMode ) |
|
278 { |
|
279 TIpcArgs args( aDisplayMode ); // 1st argument |
|
280 TInt err = aFile.TransferToServer( args, 1, 2 ); // 2.&3. argument |
|
281 err = Send( ECreateThumbnails, args ); |
|
282 while ( err == KErrServerBusy ) |
|
283 { |
|
284 err = Send( ECreateThumbnails, args ); |
|
285 } |
|
286 return err; |
|
287 } |
|
288 |
|
289 |
|
290 // --------------------------------------------------------------------------- |
|
291 // Delete thumbnails for given object file |
|
292 // --------------------------------------------------------------------------- |
|
293 // |
|
294 void RThumbnailSession::DeleteThumbnails( const TDesC& aPath, |
|
295 TThumbnailRequestParamsPckg& aParams, TRequestStatus& aStatus ) |
|
296 { |
|
297 TIpcArgs args( &aParams, &aPath, KCheckValue); |
|
298 |
|
299 SendReceive( EDeleteThumbnails, args, aStatus ); |
|
300 } |
|
301 |
|
302 |
|
303 // --------------------------------------------------------------------------- |
|
304 // Delete thumbnails by TThumbnailId. |
|
305 // --------------------------------------------------------------------------- |
|
306 // |
|
307 void RThumbnailSession::DeleteThumbnails( const TThumbnailId aItemId, |
|
308 TThumbnailRequestParamsPckg& aParams, TRequestStatus& aStatus ) |
|
309 { |
|
310 TIpcArgs args( &aParams, aItemId, KCheckValue); |
|
311 |
|
312 SendReceive( EDeleteThumbnailsById, args, aStatus ); |
|
313 } |
|
314 |
|
315 |
|
316 // --------------------------------------------------------------------------- |
|
317 // Get a list of supported MIME types in a HBufC |
|
318 // --------------------------------------------------------------------------- |
|
319 // |
|
320 HBufC* RThumbnailSession::GetMimeTypeListL() |
|
321 { |
|
322 TInt size = 0; |
|
323 TPckg < TInt > pckg( size ); |
|
324 User::LeaveIfError( SendReceive( EGetMimeTypeBufferSize, TIpcArgs( &pckg ))); |
|
325 HBufC* res = HBufC::NewLC( size ); |
|
326 TPtr ptr = res->Des(); |
|
327 User::LeaveIfError( SendReceive( EGetMimeTypeList, TIpcArgs( &ptr ))); |
|
328 CleanupStack::Pop( res ); |
|
329 return res; |
|
330 } |
|
331 |
|
332 |
|
333 // --------------------------------------------------------------------------- |
|
334 // Update thumbnails. |
|
335 // --------------------------------------------------------------------------- |
|
336 // |
|
337 void RThumbnailSession::UpdateThumbnails( const TDesC& aPath, const TInt aOrientation, |
|
338 const TInt64 aModified, TThumbnailRequestParamsPckg& aParams, TRequestStatus& aStatus ) |
|
339 { |
|
340 aParams().iFileName = aPath; |
|
341 aParams().iTargetUri = KNullDesC; |
|
342 aParams().iOrientation = aOrientation; |
|
343 aParams().iModified = aModified; |
|
344 |
|
345 TIpcArgs args( &aParams, KCheckValue); |
|
346 |
|
347 SendReceive( EUpdateThumbnails, args, aStatus ); |
|
348 } |
|
349 |
|
350 |
|
351 // End of file |