|
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 "FAXSTUB.H" |
|
17 |
|
18 TTsyTimer::TTsyTimer() |
|
19 { |
|
20 iPending=EFalse; |
|
21 } |
|
22 |
|
23 CFaxSession *CFaxSession::NewLC () |
|
24 { |
|
25 return NULL; |
|
26 } |
|
27 |
|
28 CFaxSession *CFaxSession::NewL () |
|
29 { |
|
30 CFaxSession* faxstub=new(ELeave) CFaxSession(); |
|
31 CleanupStack::PushL(faxstub); |
|
32 faxstub->ConstructL(); |
|
33 CleanupStack::Pop(); |
|
34 return faxstub; |
|
35 } |
|
36 |
|
37 CFaxSession::CFaxSession() |
|
38 : CBase() |
|
39 {} |
|
40 |
|
41 void CFaxSession::SetCallBack(MFaxCompletionBase* aCompletionBase) |
|
42 { |
|
43 iCompletion = aCompletionBase; |
|
44 } |
|
45 |
|
46 void CFaxSession::ConstructL() |
|
47 { |
|
48 iFaxTimer = CFaxTimer::NewL(); |
|
49 } |
|
50 |
|
51 CFaxSession::~CFaxSession() |
|
52 { |
|
53 |
|
54 if(iFaxTimer) //-- LYN-585JX9, code improvements by Dmitry Lyokhin. 11.03.02 |
|
55 { |
|
56 iFaxTimer->RemoveTimer(iRxConnect); |
|
57 iFaxTimer->RemoveTimer(iRxFaxData); |
|
58 iFaxTimer->RemoveTimer(iRxPostPage); |
|
59 iFaxTimer->RemoveTimer(iTxConnect); |
|
60 iFaxTimer->RemoveTimer(iTxFaxData); |
|
61 iFaxTimer->RemoveTimer(iTxPostPage); |
|
62 |
|
63 delete iFaxTimer; |
|
64 } |
|
65 |
|
66 |
|
67 } |
|
68 |
|
69 |
|
70 TInt CFaxSession::FxOpen(TFaxServerSessionSettings& aFaxSettings,RFax::TProgress* aProgress) |
|
71 { |
|
72 iTransferProgress = aProgress; |
|
73 iTransferProgress->iLastUpdateTime = KDefaultLastUpdateTime; |
|
74 iTransferProgress->iAnswerback = KDefaultAnswerBack; |
|
75 iTransferProgress->iPhase = KDefaultPhase; |
|
76 iTransferProgress->iResolution = KDefaultResolution; |
|
77 iTransferProgress->iCompression = KDefaultCompression; |
|
78 iTransferProgress->iPage = KDefaultPageNumber; |
|
79 iTransferProgress->iLines = KDefaultLinesNumber; |
|
80 iTransferProgress->iSpeed = KDefaultSpeed; |
|
81 TFaxServerSessionSettings copy; |
|
82 copy = aFaxSettings; |
|
83 TBuf8<KMaxFileName> tmpName; |
|
84 |
|
85 __FLOG_FAXSTUB (_L8("FaxStub:\tFxOpen called.")); |
|
86 __FLOG_FAXSTUB (_L8("FaxStub:\tFax settings received: ")); |
|
87 __FLOG_FAXSTUB1(_L8("Phone Number : %S"),©.iPhoneNumber); |
|
88 __FLOG_FAXSTUB1(_L8("Fax Init String : %S"),©.iFaxInitString); |
|
89 __FLOG_FAXSTUB1(_L8("Fax Mode: %d"),copy.iMode); |
|
90 __FLOG_FAXSTUB1(_L8("Fax Class: %d"),copy.iFaxClass); |
|
91 |
|
92 |
|
93 tmpName.Copy(_L8("Port Driver Name: ")); |
|
94 tmpName.Append(copy.iPortDriverName); |
|
95 __FLOG_FAXSTUB(tmpName); |
|
96 |
|
97 tmpName.Copy(_L8("Comm Port Name: ")); |
|
98 tmpName.Append(copy.iCommPortName); |
|
99 __FLOG_FAXSTUB(tmpName); |
|
100 |
|
101 tmpName.Copy(_L8("Fax ID: ")); |
|
102 tmpName.Append(copy.iFaxId); |
|
103 __FLOG_FAXSTUB(tmpName); |
|
104 |
|
105 |
|
106 __FLOG_FAXSTUB1(_L8("Max speed: %d"),copy.iMaxSpeed); |
|
107 __FLOG_FAXSTUB1(_L8("Min speed: %d"),copy.iMinSpeed); |
|
108 __FLOG_FAXSTUB1(_L8("Tx compression: %d"),copy.iTxCompression); |
|
109 __FLOG_FAXSTUB1(_L8("Rx compression: %d"),copy.iRxCompression); |
|
110 __FLOG_FAXSTUB1(_L8("Fax on demand delay: %d"),copy.iFaxOnDemandDelay); |
|
111 __FLOG_FAXSTUB1(_L8("Tx Fax Res: %d"),copy.iTxResolution); |
|
112 __FLOG_FAXSTUB1(_L8("Tx pages: %d"),copy.iTxPages); |
|
113 __FLOG_FAXSTUB1(_L8("Rx Fax Res: %d"),copy.iRxResolution); |
|
114 return KErrNone; |
|
115 } |
|
116 |
|
117 TInt CFaxSession::FxClose() |
|
118 { |
|
119 __FLOG_FAXSTUB(_L8("FaxStub:\tFxClose called.")); |
|
120 delete this; |
|
121 return KErrNone; |
|
122 } |
|
123 |
|
124 // Rx Fax |
|
125 void CFaxSession::RxConnect() |
|
126 { |
|
127 __FLOG_FAXSTUB(_L8("FaxStub:\tRxConnect called.")); |
|
128 iFaxTimer->QueueTimer(iRxConnect,ASYNC_TIMEOUT,CFaxSession::RxConnectHandler,this); |
|
129 iFaxTimer->QueueTimer(iProgressChanger,ASYNC_LONGTIMEOUT,CFaxSession::ProgressChanger,this); |
|
130 } |
|
131 |
|
132 TInt CFaxSession::RxConnectHandler(TAny* aPtr) |
|
133 { |
|
134 CFaxSession* faxHayes = REINTERPRET_CAST(CFaxSession*,aPtr); |
|
135 TTime timeAtLastRing; |
|
136 TTimeIntervalMicroSeconds cadence; |
|
137 faxHayes->iCompletion->GetCadenceAndTimeOfLastRing(cadence,timeAtLastRing); |
|
138 |
|
139 __FLOG_FAXSTUB2(_L8("FaxStub:\tTime at last RING is %d:%d"),timeAtLastRing.DateTime().Second(),timeAtLastRing.DateTime().MicroSecond()); |
|
140 __FLOG_FAXSTUB1(_L8("FaxStub:\tCadence is %d microseconds"),cadence.Int64()); |
|
141 |
|
142 faxHayes->iCompletion->RxConnectComplete(KErrNone); |
|
143 faxHayes->iFaxTimer->ResetPending(((CFaxSession*)aPtr)->iRxConnect); |
|
144 return KErrNone; |
|
145 } |
|
146 |
|
147 void CFaxSession::RxFaxData(TDes8& aData) |
|
148 { |
|
149 __FLOG_FAXSTUB(_L8("FaxStub:\tRxFaxData called.")); |
|
150 aData = _L8("INCOMING FAX DATA!!"); |
|
151 iFaxTimer->QueueTimer(iRxFaxData,ASYNC_TIMEOUT,CFaxSession::RxFaxDataHandler,this); |
|
152 } |
|
153 |
|
154 TInt CFaxSession::RxFaxDataHandler(TAny* aPtr) |
|
155 { |
|
156 CFaxSession* faxHayes = REINTERPRET_CAST(CFaxSession*,aPtr); |
|
157 faxHayes->iCompletion->RxFaxDataComplete(KErrNone); |
|
158 faxHayes->iFaxTimer->ResetPending(((CFaxSession*)aPtr)->iRxFaxData); |
|
159 return KErrNone; |
|
160 } |
|
161 |
|
162 void CFaxSession::RxPostPage() |
|
163 { |
|
164 __FLOG_FAXSTUB(_L8("FaxStub:\tRxPostPage called.")); |
|
165 iFaxTimer->QueueTimer(iRxPostPage,ASYNC_TIMEOUT,CFaxSession::RxPostPageHandler,this); |
|
166 } |
|
167 |
|
168 TInt CFaxSession::RxPostPageHandler(TAny* aPtr) |
|
169 { |
|
170 CFaxSession* faxHayes = REINTERPRET_CAST(CFaxSession*,aPtr); |
|
171 faxHayes->iCompletion->RxPostPageComplete(KErrNone); |
|
172 faxHayes->iFaxTimer->ResetPending(((CFaxSession*)aPtr)->iRxPostPage); |
|
173 return KErrNone; |
|
174 } |
|
175 |
|
176 // Tx Fax |
|
177 |
|
178 void CFaxSession::TxConnect() |
|
179 { |
|
180 __FLOG_FAXSTUB(_L8("FaxStub:\tTxConnect called.")); |
|
181 iFaxTimer->QueueTimer(iTxConnect,ASYNC_TIMEOUT,CFaxSession::TxConnectHandler,this); |
|
182 } |
|
183 |
|
184 TInt CFaxSession::TxConnectHandler(TAny* aPtr) |
|
185 { |
|
186 CFaxSession* faxHayes = REINTERPRET_CAST(CFaxSession*,aPtr); |
|
187 faxHayes->iCompletion->TxConnectComplete(KErrNone); |
|
188 faxHayes->iFaxTimer->ResetPending(((CFaxSession*)aPtr)->iTxConnect); |
|
189 return KErrNone; |
|
190 } |
|
191 |
|
192 void CFaxSession::TxFaxData(const TDesC8& /*aData*/) |
|
193 { |
|
194 __FLOG_FAXSTUB(_L8("FaxStub:\tTxFaxData called.")); |
|
195 iFaxTimer->QueueTimer(iTxFaxData,ASYNC_TIMEOUT,CFaxSession::TxFaxDataHandler,this); |
|
196 } |
|
197 |
|
198 TInt CFaxSession::TxFaxDataHandler(TAny* aPtr) |
|
199 { |
|
200 CFaxSession* faxHayes = REINTERPRET_CAST(CFaxSession*,aPtr); |
|
201 faxHayes->iCompletion->TxFaxDataComplete(KErrNone); |
|
202 faxHayes->iFaxTimer->ResetPending(((CFaxSession*)aPtr)->iTxFaxData); |
|
203 return KErrNone; |
|
204 } |
|
205 |
|
206 void CFaxSession::TxPostPage() |
|
207 { |
|
208 __FLOG_FAXSTUB(_L8("FaxStub:\tTxPostPage called.")); |
|
209 iFaxTimer->QueueTimer(iTxPostPage,ASYNC_TIMEOUT,CFaxSession::TxPostPageHandler,this); |
|
210 } |
|
211 |
|
212 TInt CFaxSession::TxPostPageHandler(TAny* aPtr) |
|
213 { |
|
214 CFaxSession* faxHayes = REINTERPRET_CAST(CFaxSession*,aPtr); |
|
215 faxHayes->iCompletion->TxPostPageComplete(KErrNone); |
|
216 faxHayes->iFaxTimer->ResetPending(((CFaxSession*)aPtr)->iTxPostPage); |
|
217 return KErrNone; |
|
218 } |
|
219 |
|
220 void CFaxSession::Cancel() |
|
221 { |
|
222 __FLOG_FAXSTUB(_L8("FaxStub:\tCancel called - set iTransferProgress.iPhase to EDisconnection")); |
|
223 iTransferProgress->iPhase = EDisconnection; |
|
224 } |
|
225 |
|
226 TInt CFaxSession::ProgressChanger(TAny* aPtr) |
|
227 { |
|
228 CFaxSession* faxHayes = REINTERPRET_CAST(CFaxSession*,aPtr); |
|
229 faxHayes->iTransferProgress->iLines++; |
|
230 return KErrNone; |
|
231 } |
|
232 |
|
233 // CFaxTimer |
|
234 |
|
235 CFaxTimer* CFaxTimer::NewL() |
|
236 { |
|
237 CFaxTimer* faxTimer = new(ELeave)CFaxTimer(); |
|
238 CleanupStack::PushL(faxTimer); |
|
239 faxTimer->ConstructL(); |
|
240 CleanupStack::Pop(); |
|
241 return faxTimer; |
|
242 } |
|
243 |
|
244 CFaxTimer::CFaxTimer() |
|
245 {} |
|
246 |
|
247 void CFaxTimer::ConstructL() |
|
248 { |
|
249 iTimer=CDeltaTimer::NewL(CActive::EPriorityHigh,KEtelFaxTimerGranularity); |
|
250 } |
|
251 |
|
252 CFaxTimer::~CFaxTimer() |
|
253 { |
|
254 delete iTimer; |
|
255 } |
|
256 |
|
257 void CFaxTimer::QueueTimer(TTsyTimer& aTsyTimer, |
|
258 TTimeIntervalMicroSeconds32 aTimeInMicroSeconds, |
|
259 TInt (*aFunction)(TAny *aPtr),TAny* aPtr) |
|
260 { |
|
261 TCallBack callBackFn(aFunction,aPtr); |
|
262 aTsyTimer.iEntry.Set(callBackFn); |
|
263 |
|
264 aTsyTimer.iPending=ETrue; |
|
265 aTimeInMicroSeconds=aTimeInMicroSeconds.Int()+(KEtelFaxTimerGranularity>>2); |
|
266 if(aTimeInMicroSeconds.Int()<100000) |
|
267 aTimeInMicroSeconds=aTimeInMicroSeconds.Int()+KEtelFaxTimerGranularity; |
|
268 iTimer->Queue(aTimeInMicroSeconds,aTsyTimer.iEntry); |
|
269 } |
|
270 |
|
271 TBool CFaxTimer::RemoveTimer(TTsyTimer& aTsyTimer) |
|
272 { |
|
273 if (aTsyTimer.iPending) |
|
274 { |
|
275 aTsyTimer.iPending=EFalse; |
|
276 iTimer->Remove(aTsyTimer.iEntry); |
|
277 return ETrue; |
|
278 } |
|
279 return EFalse; |
|
280 } |
|
281 |
|
282 void CFaxTimer::ResetPending(TTsyTimer& aTsyTimer) |
|
283 { |
|
284 aTsyTimer.iPending=EFalse; |
|
285 } |
|
286 |
|
287 TFaxServerSessionSettings& |
|
288 TFaxServerSessionSettings::operator=(const TFaxServerSessionSettings& aSettings) |
|
289 { |
|
290 iPhoneNumber = aSettings.iPhoneNumber; iLogging = aSettings.iLogging; |
|
291 iFaxInitString = aSettings.iFaxInitString; iMode = aSettings.iMode;; |
|
292 iFaxClass = aSettings.iFaxClass; |
|
293 iPortDriverName = aSettings.iPortDriverName; iCommPortName = aSettings.iCommPortName; iFaxId = aSettings.iFaxId; |
|
294 iMaxSpeed = aSettings.iMaxSpeed; |
|
295 iMinSpeed = aSettings.iMinSpeed; |
|
296 iPreferredECM = aSettings.iPreferredECM; iFaxOnDemandDelay = aSettings.iFaxOnDemandDelay; iTxResolution = aSettings.iTxResolution; iTxCompression = aSettings.iTxCompression; iTxPages = aSettings.iTxPages; |
|
297 iRxResolution = aSettings.iRxResolution; iRxCompression = aSettings.iRxCompression; return(*this); |
|
298 } |
|
299 |
|
300 // |
|
301 // First Ordinal Functions |
|
302 // |
|
303 extern "C" |
|
304 { |
|
305 IMPORT_C CFaxSession* LibEntry(void); // Force "Proper Name" export |
|
306 } |
|
307 |
|
308 EXPORT_C CFaxSession* LibEntry() |
|
309 { |
|
310 return CFaxSession::NewL(); |
|
311 } |