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