Symbian
Symbian OS Library

SYMBIAN OS V9.3

[Index] [Spacer] [Previous] [Next]



Using CReadFaxFile


Opening the file

The first phase in reading a fax is to use CReadFaxFile::OpenL() to open the fax file. In the following fragment it is assumed that the CReadFaxFile object has already been created.

// Create descriptors for file name and panic text
_LIT(KFaxFileName, "c:\\test.fax"); 
_LIT(KPanicOpenReadFile,"Opening read file");
// create error variable, and scan line buffer
TInt err;
TBuf8<216> scanlineRead;

// Open fax file. Panic if there is an error
TRAP(err,readFaxFile->OpenL(KFaxFileName));
if (err!=KErrNone)
    User::Panic(KPanicOpenReadFile,err);

The code fragment above shows the function opening the fax file test.fax. The OpenL() function is invoked under a trap harness, and the thread has been set up to panic if it leaves.

The function also allocates memory for the CWriteFaxPages member data, which is used to actually read pages from the store.

[Top]


Reading pages from the fax file

Reading pages from the fax file involves first determining the number of pages in the file, and then iterating through each page and extracting the scan lines. In the code fragment below, it is assumed that the program has already used CReadFaxPages::NumPages() to get the number of pages in the fax store, and indexed to the required page using CReadFaxPages::SetPageL().

// create descriptors for panic text
_LIT(KPanicReadingScanline, "Reading scanline");
_LIT(KPanicIncorrectReadback, "Incorrect readback");

//get the number of scan lines in the page
TInt numberLines=iReadFaxPages->CurrentPageInfo().iNumScanLines;

// iterate through the scan lines. 
for (row=0; row<numberLines; row++)
    {
    // go to selected row and read it. Panic if there is an error.
    readFaxFile->iReadFaxPages->SeekScanLineL(row);
    TRAP(err,readFaxFile->iReadFaxPages->GetScanLineL(scanlineRead));
    if (err!=KErrNone)
        User::Panic(KPanicReadingScanline,err);

    // check that scan line has been correctly retrieved. 
    //Panic if it hasn’t.
    __ASSERT_ALWAYS(scanlineRead[0]==row,User::Panic(KPanicIncorrectReadback,KErrGeneral));
    }

The code first finds the number of scan lines in the fax page, and then iterates through the page reading each scan line. It then checks that the scan lines are correct, by comparing them to what was saved in test.fax — see . The thread panics if there is a problem reading the scan line, or if the retrieved scan line does not match what was originally stored in the file.

[Top]


Closing the file

After all desired pages have been read, the file is no longer needed and should be closed. This is done using the fragment below.

readFaxFile->Close();    // close the file.