|
1 // Copyright (c) 1997-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 <e32std.h> |
|
17 #include <e32base.h> |
|
18 #include <f32file.h> |
|
19 |
|
20 #include <s32file.h> |
|
21 #include <s32mem.h> |
|
22 #include "FAXSTPAN.H" |
|
23 |
|
24 #include "FAXSTORE.H" |
|
25 #include "faxpageinfo.h" |
|
26 |
|
27 |
|
28 GLDEF_C void Panic (TFaxStorePanic aPanic) |
|
29 // Panic the process with ETEXT as the category. |
|
30 // |
|
31 |
|
32 { |
|
33 User::Panic (_L ("FaxStrm"), aPanic); |
|
34 } |
|
35 |
|
36 // END OF COPIED |
|
37 |
|
38 EXPORT_C TFaxBandHeader::TFaxBandHeader (): |
|
39 iNumScanLines (0), |
|
40 iStreamId (KNullStreamId) |
|
41 /** |
|
42 @capability None |
|
43 */ |
|
44 { |
|
45 } |
|
46 |
|
47 EXPORT_C TFaxBandHeader::TFaxBandHeader (TStreamId aStreamId): |
|
48 iNumScanLines (0), |
|
49 iStreamId (aStreamId) |
|
50 /** |
|
51 @capability None |
|
52 */ |
|
53 { |
|
54 } |
|
55 |
|
56 EXPORT_C void TFaxBandHeader::InternalizeL (RReadStream & aStream) |
|
57 /** |
|
58 @capability None |
|
59 */ |
|
60 { |
|
61 iNumScanLines = aStream.ReadInt32L (); |
|
62 aStream >> iStreamId; |
|
63 } |
|
64 |
|
65 EXPORT_C void TFaxBandHeader::ExternalizeL (RWriteStream & aStream) const |
|
66 /** |
|
67 @capability None |
|
68 */ |
|
69 { |
|
70 aStream.WriteInt32L (iNumScanLines); |
|
71 aStream << iStreamId; |
|
72 } |
|
73 |
|
74 CFaxPageInfo::CFaxPageInfo (): |
|
75 iResolution (EFaxNormal) |
|
76 { |
|
77 __DECLARE_NAME (_S ("CFaxPageInfo")); |
|
78 } |
|
79 |
|
80 EXPORT_C CFaxPageInfo *CFaxPageInfo::NewL () |
|
81 /** |
|
82 @capability None |
|
83 */ |
|
84 { |
|
85 CFaxPageInfo *pageinfo = new (ELeave) CFaxPageInfo (); |
|
86 CleanupStack::PushL (pageinfo); |
|
87 pageinfo->iBandHeaderList = new (ELeave) CArrayFixFlat < TFaxBandHeader > (8); |
|
88 CleanupStack::Pop (); |
|
89 return pageinfo; |
|
90 } |
|
91 |
|
92 EXPORT_C CFaxPageInfo::~CFaxPageInfo () |
|
93 { |
|
94 delete iBandHeaderList; |
|
95 } |
|
96 |
|
97 EXPORT_C void CFaxPageInfo::InternalizeL (RReadStream & aStream) |
|
98 /** |
|
99 @capability None |
|
100 */ |
|
101 { |
|
102 iResolution = (TFaxResolution) aStream.ReadInt8L (); |
|
103 aStream >> *iBandHeaderList; |
|
104 aStream >> iSenderId; |
|
105 iCompression = (TFaxCompression) aStream.ReadInt32L (); |
|
106 iReservedFlag2 = aStream.ReadInt32L (); |
|
107 } |
|
108 |
|
109 EXPORT_C void CFaxPageInfo::ExternalizeL (RWriteStream & aStream) const |
|
110 /** |
|
111 @capability None |
|
112 */ |
|
113 { |
|
114 aStream.WriteInt8L ((TInt8) iResolution); |
|
115 aStream << *iBandHeaderList; |
|
116 aStream << iSenderId; |
|
117 aStream.WriteInt32L (iCompression); |
|
118 aStream.WriteInt32L (iReservedFlag2); |
|
119 } |
|
120 /********************************************************************/ |
|
121 |
|
122 CFaxPages::CFaxPages () |
|
123 { |
|
124 __DECLARE_NAME (_S ("CFaxPages")); |
|
125 } |
|
126 |
|
127 EXPORT_C CFaxPages *CFaxPages::NewL () |
|
128 /** |
|
129 @capability None |
|
130 */ |
|
131 { |
|
132 CFaxPages *faxpages = new (ELeave) CFaxPages (); |
|
133 CleanupStack::PushL (faxpages); |
|
134 faxpages->iPageStreamIdList = new (ELeave) CArrayFixFlat < TStreamId > (8); |
|
135 CleanupStack::Pop (); |
|
136 return faxpages; |
|
137 } |
|
138 |
|
139 EXPORT_C CFaxPages::~CFaxPages () |
|
140 { |
|
141 delete iPageStreamIdList; |
|
142 } |
|
143 |
|
144 EXPORT_C void CFaxPages::InternalizeL (RReadStream & aStream) |
|
145 /** |
|
146 @capability None |
|
147 */ |
|
148 { |
|
149 aStream >> *iPageStreamIdList; |
|
150 } |
|
151 |
|
152 EXPORT_C void CFaxPages::ExternalizeL (RWriteStream & aStream) const |
|
153 /** |
|
154 @capability None |
|
155 */ |
|
156 { |
|
157 aStream << *iPageStreamIdList; |
|
158 } |
|
159 /********************************************************************/ |
|
160 |
|
161 CWriteFaxPages::CWriteFaxPages (CStreamStore & aStore, TInt aMaxScanLinesInBand): |
|
162 iMaxScanLinesInBand (aMaxScanLinesInBand ? aMaxScanLinesInBand : 64), |
|
163 iStore (&aStore) |
|
164 { |
|
165 __DECLARE_NAME (_S ("CWriteFaxPages")); |
|
166 } |
|
167 |
|
168 void CWriteFaxPages::ConstructL () |
|
169 { |
|
170 iFaxPages = CFaxPages::NewL (); |
|
171 iCurrentPage = CFaxPageInfo::NewL (); |
|
172 iFaxT4 = CFaxT4::NewL (); |
|
173 } |
|
174 |
|
175 TBool CWriteFaxPages::BandCompleted () |
|
176 { |
|
177 TInt count = iCurrentPage->iBandHeaderList->Count (); |
|
178 return (!count) || ((*iCurrentPage->iBandHeaderList)[count - 1].iNumScanLines == iMaxScanLinesInBand); |
|
179 } |
|
180 |
|
181 EXPORT_C CWriteFaxPages *CWriteFaxPages::NewL (CStreamStore & aStore, TInt aMaxScanLinesInBand) |
|
182 /** Creates a CWriteFaxPages object, which offers the public API for writing fax |
|
183 pages to a stream store. |
|
184 |
|
185 This function is called by CWriteFaxFile as part of creating a fax file. |
|
186 |
|
187 @param aStore The store to which fax pages are to be added. |
|
188 @param aMaxScanLinesInBand The maximum number of scan lines in a band. Faxes |
|
189 pages are stored in bands - to speed up display time. It is recommended |
|
190 that developers use 64 - the value used by CWriteFaxFile. |
|
191 @leave KErrNoMemory There is insufficient memory to perform the operation. |
|
192 @return A pointer to the newly created object. |
|
193 @capability None |
|
194 */ |
|
195 { |
|
196 CWriteFaxPages *writefaxpages = new (ELeave) CWriteFaxPages (aStore, aMaxScanLinesInBand); |
|
197 CleanupStack::PushL (writefaxpages); |
|
198 writefaxpages->ConstructL (); |
|
199 CleanupStack::Pop (); |
|
200 return writefaxpages; |
|
201 } |
|
202 |
|
203 EXPORT_C CWriteFaxPages::~CWriteFaxPages () |
|
204 /** Destructor. |
|
205 |
|
206 Closes the write stream, and frees all resources owned by the object, prior |
|
207 to its destruction. */ |
|
208 { |
|
209 iWriteStream.Close (); |
|
210 delete iFaxT4; |
|
211 delete iFaxPages; |
|
212 delete iCurrentPage; |
|
213 } |
|
214 |
|
215 EXPORT_C void CWriteFaxPages::StartPage (TFaxResolution aResolution, TFaxCompression aCompression, TInt aFlag2) |
|
216 /** |
|
217 Initialize fax page, set page parameters. |
|
218 |
|
219 @param aResolution defines fax resolution |
|
220 @param aCompression defines fax compression |
|
221 @param aFlag2 reserved flag. |
|
222 @capability None |
|
223 */ |
|
224 { |
|
225 iFaxT4->PageInitialize (aResolution, aCompression, aFlag2); |
|
226 } |
|
227 |
|
228 EXPORT_C void CWriteFaxPages::EndPageL (TFaxResolution aResolution, TFaxBufSenderId & aSenderId, TFaxCompression aCompression, TInt aFlag2) |
|
229 /** |
|
230 Sets parameters for the current page, writes it to the stream and appends to the fax pages set. |
|
231 |
|
232 @param aResolution defines fax resolution |
|
233 @param aSenderId Sender Id. |
|
234 @param aCompression defines fax compression |
|
235 @param aFlag2 reserved flag. |
|
236 @capability None |
|
237 */ |
|
238 { |
|
239 if (!BandCompleted ()) |
|
240 { |
|
241 iWriteStream.CommitL (); |
|
242 iWriteStream.Close (); |
|
243 } |
|
244 iCurrentPage->iResolution = aResolution; |
|
245 iCurrentPage->iSenderId = aSenderId; |
|
246 iCurrentPage->iCompression = aCompression; |
|
247 iCurrentPage->iReservedFlag2 = aFlag2; |
|
248 TStreamId streamid = iWriteStream.CreateL (*iStore); |
|
249 iWriteStream << *iCurrentPage; |
|
250 iWriteStream.CommitL (); |
|
251 iWriteStream.Close (); |
|
252 iFaxPages->iPageStreamIdList->AppendL (streamid); |
|
253 iCurrentPage->iBandHeaderList->Reset (); |
|
254 } |
|
255 |
|
256 EXPORT_C TStreamId CWriteFaxPages::CommitPageL () |
|
257 /** |
|
258 Place FaxPages into write stream. |
|
259 |
|
260 @return Stream Id. |
|
261 @capability None |
|
262 */ |
|
263 { |
|
264 TStreamId streamid = iWriteStream.CreateL (*iStore); |
|
265 iWriteStream << *iFaxPages; |
|
266 iWriteStream.CommitL (); |
|
267 iWriteStream.Close (); |
|
268 iStore->CommitL (); |
|
269 return streamid; |
|
270 } |
|
271 |
|
272 EXPORT_C void CWriteFaxPages::AddScanLineL (const TDesC8 & aScanLine) |
|
273 /** Adds raw scan lines to the write stream. |
|
274 |
|
275 The function first encodes the scan line, using the format specified in the |
|
276 StartPage() function, and then adds it to the write stream. |
|
277 |
|
278 @param aScanline The current raw scan line. |
|
279 @capability None |
|
280 */ |
|
281 { |
|
282 iFaxT4->EncodeScanLine (aScanLine, iEncodedScanLine); |
|
283 AddEncodedScanLineL (iEncodedScanLine); |
|
284 } |
|
285 |
|
286 EXPORT_C void CWriteFaxPages::AddEncodedScanLineL (const TDesC8 & anEncodedScanLine) |
|
287 /** Adds encoded scan lines to the write stream. |
|
288 |
|
289 @param anEncodedScanLine The encoded scan line (MH or MR). |
|
290 @capability None |
|
291 */ |
|
292 { |
|
293 if (BandCompleted ()) |
|
294 { |
|
295 TStreamId streamid = iWriteStream.CreateL (*iStore); |
|
296 iCurrentPage->iBandHeaderList->AppendL (TFaxBandHeader (streamid)); |
|
297 } |
|
298 |
|
299 TInt count = iCurrentPage->iBandHeaderList->Count (); |
|
300 TFaxBandHeader *bandheader = &(*iCurrentPage->iBandHeaderList)[count - 1]; |
|
301 iWriteStream << anEncodedScanLine; |
|
302 bandheader->iNumScanLines++; |
|
303 bandheader->iNumBytes += anEncodedScanLine.Length (); |
|
304 |
|
305 if (BandCompleted ()) |
|
306 { |
|
307 iWriteStream.CommitL (); |
|
308 iWriteStream.Close (); |
|
309 } |
|
310 } |
|
311 /********************************************************************/ |
|
312 |
|
313 CWriteFaxFile::CWriteFaxFile () |
|
314 { |
|
315 __DECLARE_NAME (_S ("CWriteFaxFile")); |
|
316 } |
|
317 |
|
318 void CWriteFaxFile::ConstructL () |
|
319 { |
|
320 User::LeaveIfError (iFs.Connect ()); |
|
321 } |
|
322 |
|
323 const TUid KUidPsiFaxApp = {268435908}; |
|
324 |
|
325 void CWriteFaxFile::DoOpenL (TInt aMaxScanLinesInBand) |
|
326 { |
|
327 iFileStore = CDirectFileStore::ReplaceL (iFs, iFileName, EFileWrite); |
|
328 TUidType type (KDirectFileStoreLayoutUid, TUid::Uid (KFaxFileStoreUidVal), KUidPsiFaxApp); |
|
329 iFileStore->SetTypeL (type); |
|
330 iWriteFaxPages = CWriteFaxPages::NewL (*iFileStore, aMaxScanLinesInBand); |
|
331 } |
|
332 |
|
333 EXPORT_C CWriteFaxFile *CWriteFaxFile::NewL () |
|
334 /** Constructs a CWriteFaxFile object, which offers the public API for creating |
|
335 a fax store file. |
|
336 |
|
337 As part of the construction process, the object opens a session with the file |
|
338 server. |
|
339 |
|
340 @return A pointer to the newly created object. |
|
341 @capability None |
|
342 */ |
|
343 { |
|
344 CWriteFaxFile *writefaxfile = new (ELeave) CWriteFaxFile; |
|
345 CleanupStack::PushL (writefaxfile); |
|
346 writefaxfile->ConstructL (); |
|
347 CleanupStack::Pop (); |
|
348 return writefaxfile; |
|
349 } |
|
350 |
|
351 EXPORT_C CWriteFaxFile::~CWriteFaxFile () |
|
352 /** Destructor. |
|
353 |
|
354 Closes the session with the file server, and frees all resources owned by |
|
355 the object, prior to its destruction. */ |
|
356 { |
|
357 Close (); |
|
358 iFs.Close (); |
|
359 } |
|
360 |
|
361 LOCAL_C void DoAbort (TAny * aPtr) |
|
362 { |
|
363 ((CWriteFaxFile *) aPtr)->AbortWrite (); |
|
364 } |
|
365 |
|
366 EXPORT_C void CWriteFaxFile::OpenL (const TDesC & aFileName, TInt aMaxScanLinesInBand) |
|
367 /** Creates and opens a fax file for writing. |
|
368 |
|
369 The function also allocates memory to create a CWriteFaxPages object which |
|
370 is pointed to by the class data member. This object defines the API for writing |
|
371 pages to the file store. |
|
372 |
|
373 Fax files which have been opened should be paired with a Close() function. |
|
374 |
|
375 @param aFileName The name of the new fax file. |
|
376 @param aMaxScanLinesInBand The maximum number of scan lines in a band. Fax |
|
377 pages are stored in bands for quick retrieval/display. If zero is passed then |
|
378 it will default to 64 otherwise the passed value will take effect. |
|
379 @capability None |
|
380 */ |
|
381 { |
|
382 |
|
383 iFileName = aFileName; |
|
384 CleanupStack::PushL (TCleanupItem (DoAbort, this)); |
|
385 DoOpenL (aMaxScanLinesInBand); |
|
386 CleanupStack::Pop (); |
|
387 } |
|
388 |
|
389 |
|
390 EXPORT_C void CWriteFaxFile::CommitL () |
|
391 /** Commits the current fax page created using the CWriteFaxPages API to |
|
392 the fax file. |
|
393 |
|
394 Committing a page writes it to the fax file, rather than storing it in temporary |
|
395 memory. The function should be called after each page is added, to ensure |
|
396 that only one fax page can be lost if there is an out of memory error. |
|
397 @capability None |
|
398 */ |
|
399 { |
|
400 TStreamId streamid = iWriteFaxPages->CommitPageL (); |
|
401 iFileStore->SetRootL (streamid); |
|
402 iFileStore->CommitL (); |
|
403 } |
|
404 |
|
405 |
|
406 EXPORT_C void CWriteFaxFile::Close () |
|
407 /** Closes the fax file, and deletes the resources owned by the object. |
|
408 |
|
409 Although this function is called in the destructor, it is good programming |
|
410 practice to invoke it manually to pair previous OpenL() calls. |
|
411 @capability None |
|
412 */ |
|
413 { |
|
414 delete iWriteFaxPages; |
|
415 iWriteFaxPages = NULL; |
|
416 delete iFileStore; |
|
417 iFileStore = NULL; |
|
418 } |
|
419 |
|
420 EXPORT_C void CWriteFaxFile::AbortWrite () |
|
421 /** Aborts the creation of the fax store file, and then deletes the file. |
|
422 |
|
423 It can be called by developer programs, and is called automatically if OpenL() |
|
424 leaves. |
|
425 @capability None |
|
426 */ |
|
427 { |
|
428 Close (); |
|
429 iFs.Delete (iFileName); |
|
430 } |
|
431 /********************************************************************/ |
|
432 |
|
433 CReadFaxPages::CReadFaxPages (CStreamStore & aStore): |
|
434 iStore (&aStore) |
|
435 { |
|
436 __DECLARE_NAME (_S ("CReadFaxPages")); |
|
437 } |
|
438 |
|
439 void CReadFaxPages::ConstructL (TStreamId aStreamId) |
|
440 { |
|
441 iFaxPages = CFaxPages::NewL (); |
|
442 iCurrentPage = CFaxPageInfo::NewL (); |
|
443 iFaxT4 = CFaxT4::NewL (); |
|
444 iReadStream.OpenL (*iStore, aStreamId); |
|
445 iReadStream >> *iFaxPages; |
|
446 iReadStream.Close (); |
|
447 SetPageL (0); |
|
448 } |
|
449 |
|
450 EXPORT_C CReadFaxPages *CReadFaxPages::NewL (CStreamStore & aStore, TStreamId aStreamId) |
|
451 /** Creates a CReadFaxPages object, which offers the public API for reading fax |
|
452 pages from a stream store. |
|
453 |
|
454 This function is called by CReadFaxFile when opening a fax file. |
|
455 |
|
456 @param aStore The store from which fax pages are to be read. |
|
457 @param aStreamId The root ID of the stream store. |
|
458 @leave KErrNoMemory There is insufficient memory to perform the operation. |
|
459 @return A pointer to the newly created object. |
|
460 @capability None |
|
461 */ |
|
462 { |
|
463 CReadFaxPages *readfaxpages = new (ELeave) CReadFaxPages (aStore); |
|
464 CleanupStack::PushL (readfaxpages); |
|
465 readfaxpages->ConstructL (aStreamId); |
|
466 CleanupStack::Pop (); |
|
467 return readfaxpages; |
|
468 } |
|
469 |
|
470 EXPORT_C CReadFaxPages::~CReadFaxPages () |
|
471 /** Destructor. |
|
472 |
|
473 Closes the stream, and frees all resources owned by the object, prior to its |
|
474 destruction. */ |
|
475 { |
|
476 iReadStream.Close (); |
|
477 delete iFaxT4; |
|
478 delete iFaxPages; |
|
479 delete iCurrentPage; |
|
480 } |
|
481 |
|
482 EXPORT_C TInt CReadFaxPages::NumPages () const |
|
483 /** Gets the number of pages in the store. |
|
484 |
|
485 @return The number of fax pages in the store. |
|
486 @capability None |
|
487 */ |
|
488 { |
|
489 return iFaxPages->iPageStreamIdList->Count (); |
|
490 } |
|
491 |
|
492 EXPORT_C void CReadFaxPages::SetPageL (TInt aNum) |
|
493 /** Sets a selected page to be the current page, and resets the current scan line |
|
494 to the first scan line in the page. |
|
495 |
|
496 @param aNum The number of the new page. |
|
497 @capability None |
|
498 */ |
|
499 { |
|
500 __ASSERT_DEBUG ((aNum >= 0) && (aNum < iFaxPages->iPageStreamIdList->Count ()), Panic (EFaxPageIndexOutOfRange)); |
|
501 iReadStream.Close (); |
|
502 iReadStream.OpenL (*iStore, (*iFaxPages->iPageStreamIdList)[aNum]); |
|
503 iReadStream >> *iCurrentPage; |
|
504 iReadStream.Close (); |
|
505 iFaxT4->PageInitialize (iCurrentPage->iResolution, iCurrentPage->iCompression, iCurrentPage->iReservedFlag2); |
|
506 SeekScanLineL (0); |
|
507 } |
|
508 |
|
509 EXPORT_C TFaxPageInfo CReadFaxPages::CurrentPageInfo () const |
|
510 /** Gets the information for the current fax page, where the current page was set |
|
511 in a previous call to the SetPageL() function. |
|
512 |
|
513 @return The information for the current fax page |
|
514 @capability None |
|
515 */ |
|
516 { |
|
517 TFaxPageInfo info; |
|
518 info.iResolution = iCurrentPage->iResolution; |
|
519 info.iSenderId = iCurrentPage->iSenderId; |
|
520 info.iCompression = iCurrentPage->iCompression; |
|
521 info.iReservedFlag2 = iCurrentPage->iReservedFlag2; |
|
522 info.iNumScanLines = 0; |
|
523 TInt count = iCurrentPage->iBandHeaderList->Count (); |
|
524 for (TInt i = 0; i < count; i++) |
|
525 info.iNumScanLines += (*iCurrentPage->iBandHeaderList)[i].iNumScanLines; |
|
526 return info; |
|
527 } |
|
528 |
|
529 EXPORT_C void CReadFaxPages::SeekScanLineL (TInt anIndex) |
|
530 /** Sets the specified scan line as the current scan line. |
|
531 |
|
532 @param anIndex The index of the scan line. |
|
533 @capability None |
|
534 */ |
|
535 { |
|
536 __ASSERT_DEBUG ((anIndex >= 0) && (anIndex < CurrentPageInfo ().iNumScanLines), Panic (EFaxScanLineIndexOutOfRange)); |
|
537 TInt numscanlines = 0; |
|
538 TInt count = iCurrentPage->iBandHeaderList->Count (); |
|
539 for (iBandIndex = 0; (iBandIndex < count) && ((numscanlines + (*iCurrentPage->iBandHeaderList)[iBandIndex].iNumScanLines) <= anIndex); iBandIndex++) |
|
540 numscanlines += (*iCurrentPage->iBandHeaderList)[iBandIndex].iNumScanLines; |
|
541 |
|
542 SetBandL (iBandIndex); |
|
543 TBuf8 < KFaxT4MaxDesLength > encodedscanline; |
|
544 for (iScanLineOffset = 0; iScanLineOffset < (anIndex - numscanlines);) |
|
545 GetEncodedScanLineL (encodedscanline); |
|
546 } |
|
547 |
|
548 EXPORT_C TInt CReadFaxPages::GetScanLineL (TDes8 & aScanLine) |
|
549 /** Gets the raw scan line specified in a previous call to the SeekScanLineL() |
|
550 function. |
|
551 |
|
552 The scan line is stored in compressed form, but is retrieved by this function |
|
553 in raw form for viewing. |
|
554 |
|
555 @param aScanLine On return, contains the scan line. |
|
556 @return KErrNone if successful, otherwise another of the system-wide error |
|
557 codes. |
|
558 @capability None |
|
559 */ |
|
560 { |
|
561 GetEncodedScanLineL (iEncodedScanLine); |
|
562 return iFaxT4->DecodeScanLine (aScanLine, iEncodedScanLine); |
|
563 } |
|
564 |
|
565 EXPORT_C void CReadFaxPages::GetEncodedScanLineL (TDes8 & anEncodedScanLine) |
|
566 /** Gets the encoded scan line specified in a previous call to the SeekScanLineL() |
|
567 function. |
|
568 |
|
569 @param anEncodedScanLine On return, contains the encoded scan line. |
|
570 @capability None |
|
571 */ |
|
572 { |
|
573 if (iScanLineOffset == (*iCurrentPage->iBandHeaderList)[iBandIndex].iNumScanLines) |
|
574 SetBandL (iBandIndex + 1); |
|
575 iReadStream >> anEncodedScanLine; |
|
576 iScanLineOffset++; |
|
577 } |
|
578 |
|
579 void CReadFaxPages::SetBandL (TInt anIndex) |
|
580 { |
|
581 __ASSERT_DEBUG ((anIndex >= 0) && (anIndex < iCurrentPage->iBandHeaderList->Count ()), Panic (EFaxBandIndexOutOfRange)); |
|
582 iBandIndex = anIndex; |
|
583 iReadStream.Close (); |
|
584 iReadStream.OpenL (*iStore, (*iCurrentPage->iBandHeaderList)[iBandIndex].iStreamId); |
|
585 iScanLineOffset = 0; |
|
586 } |
|
587 /********************************************************************/ |
|
588 |
|
589 CReadFaxFile::CReadFaxFile () |
|
590 { |
|
591 __DECLARE_NAME (_S ("CReadFaxFile")); |
|
592 } |
|
593 |
|
594 void CReadFaxFile::ConstructL () |
|
595 { |
|
596 User::LeaveIfError (iFs.Connect ()); |
|
597 } |
|
598 |
|
599 void CReadFaxFile::DoOpenL (const TDesC & aFileName) |
|
600 { |
|
601 iFileStore = CDirectFileStore::OpenL (iFs, aFileName, EFileStream | EFileRead | EFileShareReadersOnly); |
|
602 if (iFileStore->Type ()[1] != TUid::Uid (KFaxFileStoreUidVal)) |
|
603 User::Leave (KErrNotSupported); |
|
604 TStreamId streamid = iFileStore->Root (); |
|
605 iReadFaxPages = CReadFaxPages::NewL (*iFileStore, streamid); |
|
606 } |
|
607 |
|
608 EXPORT_C CReadFaxFile *CReadFaxFile::NewL () |
|
609 /** Constructs a CReadFaxFile object, which offers the public API for opening a |
|
610 fax file for reading. |
|
611 |
|
612 As part of the construction process, the object starts a session with the |
|
613 file server. |
|
614 |
|
615 @return A pointer to the newly created object. |
|
616 @capability None |
|
617 */ |
|
618 { |
|
619 CReadFaxFile *readfaxfile = new (ELeave) CReadFaxFile; |
|
620 CleanupStack::PushL (readfaxfile); |
|
621 readfaxfile->ConstructL (); |
|
622 CleanupStack::Pop (); |
|
623 return readfaxfile; |
|
624 } |
|
625 |
|
626 EXPORT_C CReadFaxFile::~CReadFaxFile () |
|
627 /** Destructor. |
|
628 |
|
629 Closes the session with the file server, and frees all resources owned by |
|
630 the object, prior to its destruction. */ |
|
631 { |
|
632 Close (); |
|
633 iFs.Close (); |
|
634 } |
|
635 |
|
636 EXPORT_C void CReadFaxFile::OpenL (const TDesC & aFileName) |
|
637 /** Opens a fax file for reading. |
|
638 |
|
639 The function also allocates memory to create a CReadFaxPages object - which |
|
640 is pointed to by the iReadFaxPages class data member. This class defines the |
|
641 API for reading individual pages from the file store. |
|
642 |
|
643 Fax files which have been opened should be paired with a Close() function. |
|
644 |
|
645 @param aFileName The name of the fax file. |
|
646 @capability None |
|
647 */ |
|
648 { |
|
649 CleanupClosePushL (*this); |
|
650 DoOpenL (aFileName); |
|
651 CleanupStack::Pop (); |
|
652 } |
|
653 |
|
654 EXPORT_C void CReadFaxFile::Close () |
|
655 /** Closes the fax file, and deletes the resources owned by the object. |
|
656 |
|
657 Although this function is called in the destructor, it is good programming |
|
658 practice to invoke it manually to pair previous OpenL() calls. |
|
659 @capability None |
|
660 */ |
|
661 { |
|
662 delete iReadFaxPages; |
|
663 iReadFaxPages = NULL; |
|
664 delete iFileStore; |
|
665 iFileStore = NULL; |
|
666 } |