|
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 // Contents : for routine for saving/restoring fax header information |
|
15 // amended 26/10/98 - replaced sizeof(TRawScanLine) with KFaxBytesPerScanLine |
|
16 // |
|
17 // |
|
18 |
|
19 #include <e32std.h> |
|
20 #include <e32base.h> |
|
21 #include <f32file.h> |
|
22 |
|
23 #include "CFAXIO.H" //public header |
|
24 |
|
25 _LIT(KHeaderFile, "FAXHEAD.DAT"); |
|
26 const TDriveNumber KDriveNumber = EDriveC; |
|
27 |
|
28 /********************************************************************/ |
|
29 |
|
30 EXPORT_C CFaxHeaderLines *CFaxHeaderLines::NewLC () |
|
31 /** Constructs a CFaxHeaderLines object, which is used to read and write the fax |
|
32 header line data file. |
|
33 |
|
34 As is usual in Symbian OS, the only difference between this function and NewL() |
|
35 is that this variant pushes the object to the cleanup stack. |
|
36 |
|
37 As part of the construction process, the object opens a session with the file |
|
38 server. |
|
39 |
|
40 @leave KErrNoMemory There is insufficient memory to perform the operation. |
|
41 @return Pointer to the newly created object. |
|
42 @capability None |
|
43 */ |
|
44 { |
|
45 CFaxHeaderLines *self = new (ELeave) CFaxHeaderLines; |
|
46 CleanupStack::PushL (self); |
|
47 self->ConstructL (); |
|
48 return self; |
|
49 } |
|
50 /********************************************************************/ |
|
51 |
|
52 EXPORT_C CFaxHeaderLines *CFaxHeaderLines::NewL () |
|
53 /** Constructs a CFaxHeaderLines object, which is used to read and write the fax |
|
54 header line data file. |
|
55 |
|
56 As part of the construction process, the object opens a session with the file |
|
57 server. |
|
58 |
|
59 @leave KErrNoMemory There is insufficient memory to perform the operation. |
|
60 @return A pointer to the newly created object. |
|
61 @capability None |
|
62 */ |
|
63 { |
|
64 CFaxHeaderLines *self = NewLC (); |
|
65 CleanupStack::Pop (); |
|
66 return self; |
|
67 } |
|
68 /********************************************************************/ |
|
69 /** |
|
70 Default constructor |
|
71 */ |
|
72 CFaxHeaderLines::CFaxHeaderLines() |
|
73 : iAdoptedHeaderFile(NULL), iUseAdpotedFileHandle(EFalse) |
|
74 { |
|
75 //Empty |
|
76 } |
|
77 |
|
78 /** |
|
79 Overloaded constructor |
|
80 */ |
|
81 CFaxHeaderLines::CFaxHeaderLines(RFile* aHeaderFile) |
|
82 : iAdoptedHeaderFile(aHeaderFile), iUseAdpotedFileHandle(ETrue) |
|
83 { |
|
84 //Empty |
|
85 } |
|
86 |
|
87 void CFaxHeaderLines::ConstructL () |
|
88 { |
|
89 if(!iUseAdpotedFileHandle) |
|
90 { |
|
91 User::LeaveIfError (iFileSession.Connect ()); |
|
92 } |
|
93 } |
|
94 /********************************************************************/ |
|
95 |
|
96 CFaxHeaderLines::~CFaxHeaderLines () |
|
97 /** Closes the open header line data file and shuts down the file server session. */ |
|
98 { |
|
99 if(!iUseAdpotedFileHandle) |
|
100 { |
|
101 iFile.Close (); |
|
102 iFileSession.Close (); |
|
103 } |
|
104 |
|
105 } |
|
106 /********************************************************************/ |
|
107 |
|
108 EXPORT_C void CFaxHeaderLines::WriteRawFontLineL (const TInt alineNumber,TRawScanLine & aUncompressedDataLine) |
|
109 /** Writes header line font bitmap scan lines to the header line data file. |
|
110 |
|
111 It should be called to add every scan line in the font bitmap. |
|
112 |
|
113 @param alineNumber The line number of the current scan line. |
|
114 @param aUncompressedDataLine A reference to a raw font bitmap scan line to |
|
115 be added to the header line data file. |
|
116 @capability None |
|
117 */ |
|
118 { |
|
119 iSeekpos=sizeof (TFaxHeaderInfo); |
|
120 iSeekpos+=KFaxBytesPerScanLine*iOurFaxHeaderInfoPckg().iHeaderFontHeightInLines; |
|
121 iSeekpos+=KFaxBytesPerScanLine*alineNumber; |
|
122 User::LeaveIfError (File().Seek (ESeekStart, iSeekpos)); |
|
123 User::LeaveIfError (File().Write (aUncompressedDataLine, KFaxBytesPerScanLine)); |
|
124 } |
|
125 /********************************************************************/ |
|
126 |
|
127 EXPORT_C void CFaxHeaderLines::WriteRawHeaderLineL (const TInt alineNumber,TRawScanLine & aUncompressedDataLine) |
|
128 /** Writes the header line template's scan lines to the header line data file. |
|
129 It should be called to add every scan line in the template. |
|
130 |
|
131 @param alineNumber The line number of the current scan line. |
|
132 @param aUncompressedDataLine A reference to a raw header line template scan |
|
133 line to be added to the header line data file. |
|
134 @capability None |
|
135 */ |
|
136 { |
|
137 iSeekpos=sizeof (TFaxHeaderInfo); |
|
138 iSeekpos+=KFaxBytesPerScanLine*alineNumber; |
|
139 User::LeaveIfError (File().Seek (ESeekStart, iSeekpos)); |
|
140 User::LeaveIfError (File().Write (aUncompressedDataLine, KFaxBytesPerScanLine)); |
|
141 } |
|
142 /********************************************************************/ |
|
143 |
|
144 EXPORT_C void CFaxHeaderLines::WriteFaxHeaderInfoL (TFaxHeaderInfo & aFaxHeaderInfo) |
|
145 /** Creates and opens the fax header data file, and then writes font and character |
|
146 offset information to it. |
|
147 |
|
148 The font and character offset information is used by the fax server to determine |
|
149 at which position the font bitmap characters should be inserted in the header |
|
150 line template to create the send-time header line for a page. |
|
151 |
|
152 Since this function creates and opens the file, it should be called before |
|
153 the other write functions. |
|
154 |
|
155 @param aFaxHeaderInfo The fax header line information to be written to the |
|
156 file. |
|
157 @capability None |
|
158 */ |
|
159 { |
|
160 iOurFaxHeaderInfoPckg() = aFaxHeaderInfo; |
|
161 iSeekpos=0; |
|
162 if(!iUseAdpotedFileHandle) |
|
163 { |
|
164 TFileName headerFileName; |
|
165 GenerateHeaderPathL(headerFileName); |
|
166 User::LeaveIfError (iFile.Replace (iFileSession, headerFileName, EFileWrite)); |
|
167 } |
|
168 User::LeaveIfError (File().Seek (ESeekStart, iSeekpos)); |
|
169 User::LeaveIfError (File().Write (iOurFaxHeaderInfoPckg, sizeof (TFaxHeaderInfo))); |
|
170 } |
|
171 /********************************************************************/ |
|
172 |
|
173 EXPORT_C void CFaxHeaderLines::ReadRawFontLineL (const TInt alineNumber,TRawScanLine & aUncompressedDataLine) |
|
174 /** Reads the font bitmap's scan lines from the header line data file. |
|
175 |
|
176 It should be called to read every scan line in the bitmap. |
|
177 |
|
178 In normal operation the function is called by the fax server prior to sending |
|
179 a page. |
|
180 |
|
181 @param alineNumber The line number to be read. |
|
182 @param aUncompressedDataLine On return, contains a reference to the raw scan |
|
183 line. |
|
184 @capability None |
|
185 */ |
|
186 { |
|
187 iSeekpos=sizeof (TFaxHeaderInfo); |
|
188 iSeekpos+=KFaxBytesPerScanLine*iOurFaxHeaderInfoPckg().iHeaderFontHeightInLines; |
|
189 iSeekpos+=KFaxBytesPerScanLine*alineNumber; |
|
190 User::LeaveIfError (File().Seek (ESeekStart, iSeekpos)); |
|
191 User::LeaveIfError (File().Read (aUncompressedDataLine, KFaxBytesPerScanLine)); |
|
192 } |
|
193 /********************************************************************/ |
|
194 |
|
195 EXPORT_C void CFaxHeaderLines::ReadRawHeaderLineL (const TInt alineNumber,TRawScanLine & aUncompressedDataLine) |
|
196 /** Reads the header line template's scan lines from the header line data file. |
|
197 It should be called to read every scan line in the template. |
|
198 |
|
199 In normal operation the function is called by the fax server prior to sending |
|
200 a page. |
|
201 |
|
202 @param alineNumber The line number of the scan line to be read. |
|
203 @param aUncompressedDataLine On return, contains the scan line. |
|
204 @capability None |
|
205 */ |
|
206 { |
|
207 iSeekpos=sizeof (TFaxHeaderInfo); |
|
208 iSeekpos+=KFaxBytesPerScanLine*alineNumber; |
|
209 User::LeaveIfError (File().Seek (ESeekStart, iSeekpos)); |
|
210 User::LeaveIfError (File().Read (aUncompressedDataLine, KFaxBytesPerScanLine)); |
|
211 } |
|
212 /********************************************************************/ |
|
213 |
|
214 EXPORT_C void CFaxHeaderLines::ReadFaxHeaderInfoL (TFaxHeaderInfo & aFaxHeaderInfo) |
|
215 /** Opens the fax header data file, and then reads font and character offset information |
|
216 from it. |
|
217 |
|
218 The font and character offset information is used by the fax server to determine |
|
219 at which position the font bitmap characters should be inserted in the header |
|
220 line template to create the send time header line for a page. |
|
221 |
|
222 Since this function opens the file, it should be called before the other read |
|
223 functions. |
|
224 |
|
225 @param aFaxHeaderInfo On return, contains header line information from the |
|
226 header data file. |
|
227 @capability None |
|
228 */ |
|
229 { |
|
230 iSeekpos=0; |
|
231 if(!iUseAdpotedFileHandle) |
|
232 { |
|
233 TFileName headerFileName; |
|
234 GenerateHeaderPathL(headerFileName); |
|
235 User::LeaveIfError (iFile.Open (iFileSession, headerFileName, EFileRead)); |
|
236 } |
|
237 User::LeaveIfError (File().Seek (ESeekStart, iSeekpos)); |
|
238 User::LeaveIfError (File().Read (iOurFaxHeaderInfoPckg, sizeof (TFaxHeaderInfo))); |
|
239 aFaxHeaderInfo = iOurFaxHeaderInfoPckg(); |
|
240 } |
|
241 |
|
242 /** |
|
243 Constructs a CFaxHeaderLines object, which is used to read and write the fax |
|
244 header line data file. |
|
245 |
|
246 This overload allows an already open file handle to be passed in which is used to access the file. |
|
247 This function is not intended for public use. |
|
248 |
|
249 @internalTechnology |
|
250 @param aHeaderFile Pointer to file handle. |
|
251 @return Pointer to the newly created object. |
|
252 @capability None |
|
253 @released |
|
254 */ |
|
255 EXPORT_C CFaxHeaderLines* CFaxHeaderLines::NewLC (RFile* aHeaderFile) |
|
256 { |
|
257 CFaxHeaderLines *self = new (ELeave) CFaxHeaderLines(aHeaderFile); |
|
258 CleanupStack::PushL (self); |
|
259 self->ConstructL (); |
|
260 return self; |
|
261 } |
|
262 |
|
263 /** |
|
264 Generates the header path to place the faxhead.dat file. |
|
265 If platform security is enforced this path will be the private path of the client process. As this directory structure may not exist |
|
266 This function will generate the directory structure if it does not exist. |
|
267 If platform security is not enforced this path will be c:\system\... |
|
268 |
|
269 |
|
270 @internalTechnology |
|
271 @param aHeaderPath contains the generated private path |
|
272 @capability None |
|
273 @released |
|
274 */ |
|
275 EXPORT_C void CFaxHeaderLines::GeneratePathForHeaderFileL(TDes& aHeaderPath) |
|
276 { |
|
277 GenerateHeaderPathL(aHeaderPath); |
|
278 } |
|
279 |
|
280 /** |
|
281 Return reference to open file handle. |
|
282 */ |
|
283 inline RFile& CFaxHeaderLines::File() |
|
284 { |
|
285 if(iUseAdpotedFileHandle) |
|
286 { |
|
287 return *iAdoptedHeaderFile; |
|
288 } |
|
289 else |
|
290 { |
|
291 return iFile; |
|
292 } |
|
293 } |
|
294 |
|
295 /** |
|
296 Generates the header path to place the faxhead.dat file. |
|
297 */ |
|
298 void CFaxHeaderLines::GenerateHeaderPathL(TDes& aHeaderPath) |
|
299 { |
|
300 TDriveUnit driveUnit(KDriveNumber); |
|
301 TDriveName drive=driveUnit.Name(); |
|
302 aHeaderPath.Insert(0, drive); |
|
303 TPath headerPath; |
|
304 //append private path |
|
305 RFs rfs; |
|
306 User::LeaveIfError(rfs.Connect()); |
|
307 CleanupClosePushL(rfs); |
|
308 rfs.PrivatePath(headerPath); |
|
309 //generate directory structure. |
|
310 TInt ret = rfs.CreatePrivatePath(driveUnit); |
|
311 if(ret != KErrNone && ret!=KErrAlreadyExists) |
|
312 { |
|
313 User::Leave(ret); |
|
314 } |
|
315 CleanupStack::PopAndDestroy(); //rfs |
|
316 |
|
317 aHeaderPath.Append(headerPath); |
|
318 aHeaderPath.Append(KHeaderFile); |
|
319 } |
|
320 |
|
321 /********************************************************************/ |
|
322 |