|
1 /* |
|
2 * Copyright (c) 2002-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: Declares CUPnPPrintingDevice class |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <upnpsettings.h> |
|
20 #include <fbs.h> |
|
21 #include <upnpitem.h> |
|
22 #include <upnphttpmessage.h> |
|
23 #include <upnphttpmessagefactory.h> |
|
24 #include <upnpicons.mbg> |
|
25 |
|
26 #include "cupnpprintingdevice.h" |
|
27 #include "cuplogger.h" |
|
28 #include "upconsts.h" |
|
29 |
|
30 _LIT( KIconsFileName, "imageprintdata\\protocols\\upnpicons.mbm" ); |
|
31 |
|
32 //-------------------------------------------------------------------------------------------- |
|
33 // |
|
34 // CUPnPPrintingDevice::NewL |
|
35 // |
|
36 //-------------------------------------------------------------------------------------------- |
|
37 MProtPrintingDevice* CUPnPPrintingDevice::NewL() |
|
38 { |
|
39 LOG("[CUPnPPrintingDevice]\t ConstructL"); |
|
40 return new (ELeave) CUPnPPrintingDevice(); |
|
41 } |
|
42 |
|
43 //-------------------------------------------------------------------------------------------- |
|
44 // |
|
45 // CUPnPPrintingDevice::ConstructL |
|
46 // |
|
47 //-------------------------------------------------------------------------------------------- |
|
48 void CUPnPPrintingDevice::ConstructL(const TDesC& /*aDLLPath*/) |
|
49 { |
|
50 LOG("[CUPnPPrintingDevice]\t ConstructL"); |
|
51 |
|
52 iPrinterContainer = CUPPrinterContainer::NewL(); |
|
53 iPrinterTimer = CPeriodic::NewL(CActive::EPriorityStandard); |
|
54 iPrintFactory = CUPPrintFactory::NewL(); |
|
55 |
|
56 LOG("[CUPnPPrintingDevice]\t Done."); |
|
57 } |
|
58 |
|
59 //-------------------------------------------------------------------------------------------- |
|
60 // |
|
61 // CUPnPPrintingDevice::~CUPnPPrintingDevice |
|
62 // |
|
63 //-------------------------------------------------------------------------------------------- |
|
64 CUPnPPrintingDevice::~CUPnPPrintingDevice() |
|
65 { |
|
66 if (iPrinterTimer){ |
|
67 iPrinterTimer->Cancel(); |
|
68 delete iPrinterTimer; |
|
69 } |
|
70 |
|
71 if (iPrinterControl) |
|
72 delete iPrinterControl; |
|
73 |
|
74 if (iFbsBitmap) |
|
75 delete iFbsBitmap; |
|
76 |
|
77 if (iPrintingJob) |
|
78 delete iPrintingJob; |
|
79 |
|
80 if (iPrinterContainer) |
|
81 delete iPrinterContainer; |
|
82 |
|
83 if (iPrintFactory) |
|
84 delete iPrintFactory; |
|
85 |
|
86 REComSession::DestroyedImplementation( iDtor_ID_Key ); |
|
87 } |
|
88 |
|
89 //-------------------------------------------------------------------------------------------- |
|
90 // |
|
91 // CUPnPPrintingDevice::DiscoveryTimeoutCBL |
|
92 // |
|
93 //-------------------------------------------------------------------------------------------- |
|
94 TBool CUPnPPrintingDevice::DiscoveryTimeoutCBL(TAny *aWho) |
|
95 { |
|
96 CUPnPPrintingDevice *cbTarget = static_cast<CUPnPPrintingDevice*>(aWho); |
|
97 return cbTarget->DoDiscoveryTimeoutL(ETrue); |
|
98 } |
|
99 |
|
100 |
|
101 //-------------------------------------------------------------------------------------------- |
|
102 // |
|
103 // CUPnPPrintingDevice::StatusTimeoutCBL |
|
104 // |
|
105 //-------------------------------------------------------------------------------------------- |
|
106 TBool CUPnPPrintingDevice::StatusTimeoutCBL(TAny *aWho) |
|
107 { |
|
108 CUPnPPrintingDevice *cbTarget = static_cast<CUPnPPrintingDevice*>(aWho); |
|
109 TInt res = KErrNone; |
|
110 TInt err = KErrNone; |
|
111 TRAP(err, res = cbTarget->DoStatusTimeoutL()); |
|
112 if(KErrNone != err) |
|
113 { |
|
114 cbTarget->FinishPrinting(KErrTimedOut, err); |
|
115 //Don't run the callback again |
|
116 res = EFalse; |
|
117 } |
|
118 return res; |
|
119 } |
|
120 |
|
121 |
|
122 //-------------------------------------------------------------------------------------------- |
|
123 // |
|
124 // CUPnPPrintingDevice::SubmitTimeoutCBL |
|
125 // |
|
126 //-------------------------------------------------------------------------------------------- |
|
127 TInt CUPnPPrintingDevice::SubmitTimeoutCBL(TAny *aWho) |
|
128 { |
|
129 CUPnPPrintingDevice *cbTarget = static_cast<CUPnPPrintingDevice*>(aWho); |
|
130 cbTarget->DoSubmitTimeoutL(); |
|
131 return EFalse; // Don't run the callback again |
|
132 } |
|
133 |
|
134 |
|
135 |
|
136 |
|
137 // =============================== |
|
138 // From MProtPrintingDevice. |
|
139 // =============================== |
|
140 // General |
|
141 //-------------------------------------------------------------------------------------------- |
|
142 // |
|
143 // CUPnPPrintingDevice::Version |
|
144 // |
|
145 //-------------------------------------------------------------------------------------------- |
|
146 TVersion CUPnPPrintingDevice::Version() |
|
147 { |
|
148 LOG("[CUPnPPrintingDevice]\t Version"); |
|
149 return TVersion(KVersionMajor, KVersionMinor, KVersionBuild); |
|
150 } |
|
151 |
|
152 //-------------------------------------------------------------------------------------------- |
|
153 // |
|
154 // CUPnPPrintingDevice::SupportedProtocols |
|
155 // |
|
156 //-------------------------------------------------------------------------------------------- |
|
157 TUint CUPnPPrintingDevice::SupportedProtocols() |
|
158 { |
|
159 return KImagePrint_PrinterProtocol_UPnP; |
|
160 } |
|
161 |
|
162 //-------------------------------------------------------------------------------------------- |
|
163 // |
|
164 // CUPnPPrintingDevice::RegisterIdleObserver |
|
165 // |
|
166 //-------------------------------------------------------------------------------------------- |
|
167 void CUPnPPrintingDevice::RegisterIdleObserver(MProtIdleObserver* /*aObserver*/) |
|
168 { |
|
169 |
|
170 } |
|
171 |
|
172 |
|
173 // Discovery. |
|
174 //-------------------------------------------------------------------------------------------- |
|
175 // |
|
176 // CUPnPPrintingDevice::StartDiscoveryL |
|
177 // |
|
178 //-------------------------------------------------------------------------------------------- |
|
179 void CUPnPPrintingDevice::StartDiscoveryL(MProtDiscoveryObserver& aObserver, TUint aProtocol) |
|
180 { |
|
181 LOG("[CUPnPPrintingDevice]\t StartDiscoveryL"); |
|
182 iDiscoveryObserver = &aObserver; |
|
183 iPrintersFound = EFalse; |
|
184 |
|
185 |
|
186 TRAPD(err, StartDiscoveryInternalL(aProtocol)) |
|
187 if(KErrNone != err) |
|
188 { |
|
189 iDiscoveryObserver->DiscoveryStatusL(EDiscoveryFinished, err, 0); |
|
190 } |
|
191 |
|
192 return; |
|
193 } |
|
194 |
|
195 |
|
196 //-------------------------------------------------------------------------------------------- |
|
197 // |
|
198 // CUPnPPrintingDevice::StartDiscoveryL |
|
199 // |
|
200 //-------------------------------------------------------------------------------------------- |
|
201 void CUPnPPrintingDevice::StartDiscoveryInternalL(TUint aProtocol) |
|
202 { |
|
203 LOG("[CUPnPPrintingDevice]\t StartDiscoveryInternalL"); |
|
204 |
|
205 if (!(aProtocol & KImagePrint_PrinterProtocol_UPnP)) |
|
206 { |
|
207 iDiscoveryObserver->DiscoveryStatusL(EDiscoveryFinished, KErrNotSupported, 0); |
|
208 return; |
|
209 } |
|
210 |
|
211 switch ( iState ) |
|
212 { |
|
213 case EUPnPDiscovery: // Already discovering |
|
214 break; |
|
215 case EUPnPUninitialized: |
|
216 { |
|
217 LOG("[CUPnPPrintingDevice]\t starting discovery"); |
|
218 // (Re)start printer control point |
|
219 RestartControlPointL(); |
|
220 // No devices available - return printers from cache and start timer |
|
221 SendPrinterListL(EFalse); |
|
222 } |
|
223 break; |
|
224 case EUPnPJobReady: |
|
225 case EUPnPReady: |
|
226 { |
|
227 LOG("[CUPnPPrintingDevice]\t returning latest printer list"); |
|
228 SendPrinterListL(); |
|
229 } |
|
230 break; |
|
231 case EUPnPCancellingDiscovery: |
|
232 case EUPnPCancelling: |
|
233 case EUPnPPrintingStarted: |
|
234 case EUPnPPrinting: |
|
235 default: |
|
236 { |
|
237 LOG("[CUPnPPrintingDevice]\t cannot start discovery"); |
|
238 iDiscoveryObserver->DiscoveryStatusL(EDiscoveryFinished, KErrInvalidSequence, 0); |
|
239 break; |
|
240 } |
|
241 |
|
242 } |
|
243 } |
|
244 |
|
245 //-------------------------------------------------------------------------------------------- |
|
246 // |
|
247 // CUPnPPrintingDevice::RemoveCachedDeviceL |
|
248 // |
|
249 //-------------------------------------------------------------------------------------------- |
|
250 TInt CUPnPPrintingDevice::RemoveCachedDeviceL(TInt aDeviceID) |
|
251 { |
|
252 LOG("[CUPnPPrintingDevice::RemoveCachedDeviceL]"); |
|
253 return iPrinterContainer->RemoveCachedDeviceL(aDeviceID); |
|
254 } |
|
255 |
|
256 //-------------------------------------------------------------------------------------------- |
|
257 // |
|
258 // CUPnPPrintingDevice::CancelDiscovery |
|
259 // |
|
260 //-------------------------------------------------------------------------------------------- |
|
261 void CUPnPPrintingDevice::CancelDiscovery(TBool aDoCallBack) |
|
262 { |
|
263 LOG("[CUPnPPrintingDevice]\t CancelDiscovery"); |
|
264 if (iState == EUPnPDiscovery) |
|
265 { |
|
266 iState = EUPnPCancellingDiscovery; |
|
267 if (aDoCallBack && iDiscoveryObserver) |
|
268 { |
|
269 //We're not interested if the call back leaves |
|
270 TRAP_IGNORE(iDiscoveryObserver->DiscoveryStatusL(EDiscoveryCancelling, KErrNone, 0)); |
|
271 } |
|
272 |
|
273 // This needs to be trapped since this function is not named as leaving - no need to chekc the error value |
|
274 TRAP_IGNORE( DoDiscoveryTimeoutL( EFalse ) ); |
|
275 } |
|
276 } |
|
277 |
|
278 // Print |
|
279 //-------------------------------------------------------------------------------------------- |
|
280 // |
|
281 // CUPnPPrintingDevice::CreatePrintJobL |
|
282 // |
|
283 //-------------------------------------------------------------------------------------------- |
|
284 TInt CUPnPPrintingDevice::CreatePrintJobL(TInt aDeviceId, RPointerArray<TDesC>& aImages, MProtPrintEventObserver& aObserver) |
|
285 { |
|
286 LOG("[CUPnPPrintingDevice]\t CreatePrintJobL"); |
|
287 iPrintEventObserver = &aObserver; |
|
288 |
|
289 switch ( iState ) |
|
290 { |
|
291 case EUPnPReady: |
|
292 case EUPnPJobReady: |
|
293 { |
|
294 LOG("[CUPnPPrintingDevice]\t initializing job container"); |
|
295 InitJobL(aDeviceId, aImages); |
|
296 return KErrNone; |
|
297 } |
|
298 case EUPnPCancelling: |
|
299 case EUPnPPrintingStarted: |
|
300 case EUPnPPrinting: |
|
301 case EUPnPCancellingDiscovery: |
|
302 case EUPnPUninitialized: |
|
303 default: |
|
304 { |
|
305 LOG("[CUPnPPrintingDevice]\t cannot create job"); |
|
306 break; |
|
307 } |
|
308 |
|
309 } |
|
310 return KErrInvalidSequence; |
|
311 } |
|
312 |
|
313 //-------------------------------------------------------------------------------------------- |
|
314 // |
|
315 // CUPnPPrintingDevice::SubmitPrintJobL |
|
316 // |
|
317 //-------------------------------------------------------------------------------------------- |
|
318 void CUPnPPrintingDevice::SubmitPrintJobL() |
|
319 { |
|
320 |
|
321 LOG("[CUPnPPrintingDevice]\t SubmitPrintJobL"); |
|
322 TInt err = KErrNone; |
|
323 |
|
324 switch ( iState ) |
|
325 { |
|
326 case EUPnPPrintingStarted: |
|
327 case EUPnPPrinting: |
|
328 break; // Already printing |
|
329 case EUPnPJobReady: |
|
330 { |
|
331 LOG("[CUPnPPrintingDevice]\t submitting jobs"); |
|
332 |
|
333 // Share jobs |
|
334 TRAP(err, iPrintingJob->ShareImagesL()); |
|
335 if (err != KErrNone) |
|
336 { |
|
337 LOG1("[CUPnPPrintingDevice]\t -Sharing failed: %d", err); |
|
338 break; |
|
339 } |
|
340 |
|
341 LOG1("[CUPnPPrintingDevice::SubmitPrintJobL]\t start printing with state=%d", iState); |
|
342 iState = EUPnPSubmittingJob; |
|
343 TRAP(err, StartPrintingL()); |
|
344 if (err != KErrNone) |
|
345 iState = EUPnPJobReady; |
|
346 |
|
347 LOG1("[CUPnPPrintingDevice::SubmitPrintJobL]\t StartPrintingL leaves with %d", err); |
|
348 LOG1("[CUPnPPrintingDevice::SubmitPrintJobL]\t state=%d", iState); |
|
349 } |
|
350 break; |
|
351 case EUPnPDiscovery: |
|
352 case EUPnPCancelling: |
|
353 case EUPnPCancellingDiscovery: |
|
354 case EUPnPUninitialized: |
|
355 case EUPnPReady: |
|
356 default: |
|
357 { |
|
358 LOG("[CUPnPPrintingDevice]\t Invalid sequence to submit job"); |
|
359 err = KErrInvalidSequence; |
|
360 } |
|
361 break; |
|
362 } |
|
363 |
|
364 if(KErrNone != err) |
|
365 { |
|
366 if (iPrintEventObserver) |
|
367 iPrintEventObserver->PrintJobErrorEvent(EObexSendError, err); |
|
368 else |
|
369 User::Leave(err); |
|
370 } |
|
371 } |
|
372 |
|
373 //-------------------------------------------------------------------------------------------- |
|
374 // |
|
375 // CUPnPPrintingDevice::CancelPrintJob |
|
376 // |
|
377 //-------------------------------------------------------------------------------------------- |
|
378 TInt CUPnPPrintingDevice::CancelPrintJob() |
|
379 { |
|
380 LOG("[CUPnPPrintingDevice]\t CancelPrintJob"); |
|
381 return DoCancelPrinting(); |
|
382 } |
|
383 |
|
384 //-------------------------------------------------------------------------------------------- |
|
385 // |
|
386 // CUPnPPrintingDevice::ContinuePrintJobL |
|
387 // |
|
388 //-------------------------------------------------------------------------------------------- |
|
389 TInt CUPnPPrintingDevice::ContinuePrintJobL() |
|
390 { |
|
391 return KErrInvalidSequence; |
|
392 } |
|
393 |
|
394 //-------------------------------------------------------------------------------------------- |
|
395 // |
|
396 // CUPnPPrintingDevice::GetNumPrintPages |
|
397 // |
|
398 //-------------------------------------------------------------------------------------------- |
|
399 TInt CUPnPPrintingDevice::GetNumPrintPages() |
|
400 { |
|
401 if( iPrintingJob ) |
|
402 return iPrintingJob->Sheets(); |
|
403 else |
|
404 return KErrInvalidSequence; |
|
405 } |
|
406 |
|
407 //-------------------------------------------------------------------------------------------- |
|
408 // |
|
409 // CUPnPPrintingDevice::GetPrintJobStatus |
|
410 // |
|
411 //-------------------------------------------------------------------------------------------- |
|
412 TInt CUPnPPrintingDevice::GetPrintJobStatus() |
|
413 { |
|
414 if (iState == EUPnPPrinting) |
|
415 return KErrInvalidSequence; |
|
416 return KErrNone; |
|
417 } |
|
418 |
|
419 //-------------------------------------------------------------------------------------------- |
|
420 // |
|
421 // CUPnPPrintingDevice::GetPrinterStatus |
|
422 // |
|
423 //-------------------------------------------------------------------------------------------- |
|
424 TInt CUPnPPrintingDevice::GetPrinterStatus(TInt /*aDeviceId*/) |
|
425 { |
|
426 return KErrNone; |
|
427 } |
|
428 |
|
429 //-------------------------------------------------------------------------------------------- |
|
430 // |
|
431 // CUPnPPrintingDevice::GetDeviceCapabilityIDsL |
|
432 // |
|
433 //-------------------------------------------------------------------------------------------- |
|
434 TInt CUPnPPrintingDevice::GetDeviceCapabilityIDsL(TInt /*aDeviceID*/, RArray<TInt>& aCapabilityIDs) |
|
435 { |
|
436 LOG("[CUPnPPrintingDevice]\t GetDeviceCapabilityIDsL"); |
|
437 |
|
438 if (iState == EUPnPUninitialized) |
|
439 { |
|
440 LOG("[CUPnPPrintingDevice]\t No devices discovered"); |
|
441 return KErrInvalidSequence; |
|
442 } |
|
443 |
|
444 // Return supported settings from XHTML file factory |
|
445 iPrintFactory->GetCapabilityIDs(aCapabilityIDs); |
|
446 return KErrNone; |
|
447 } |
|
448 |
|
449 //-------------------------------------------------------------------------------------------- |
|
450 // |
|
451 // CUPnPPrintingDevice::GetDeviceCapabilityL |
|
452 // |
|
453 //-------------------------------------------------------------------------------------------- |
|
454 TInt CUPnPPrintingDevice::GetDeviceCapabilityL(TInt /*aDeviceID*/, TInt aCapabilityID, TPrintCapability& aCapability) |
|
455 { |
|
456 LOG("[CUPnPPrintingDevice]\t GetDeviceCapabilityL"); |
|
457 |
|
458 if (iState == EUPnPUninitialized) |
|
459 { |
|
460 LOG("[CUPnPPrintingDevice]\t No devices discovered"); |
|
461 return KErrInvalidSequence; |
|
462 } |
|
463 |
|
464 // Return value from XHTML-print file factory |
|
465 return iPrintFactory->GetCapability(aCapabilityID, aCapability); |
|
466 } |
|
467 |
|
468 //-------------------------------------------------------------------------------------------- |
|
469 // |
|
470 // CUPnPPrintingDevice::GetJobSetting |
|
471 // |
|
472 //-------------------------------------------------------------------------------------------- |
|
473 TInt CUPnPPrintingDevice::GetJobSetting(TInt aCapabilityID, TInt& aValue) |
|
474 { |
|
475 LOG("[CUPnPPrintingDevice]\t GetJobSetting"); |
|
476 if (iState != EUPnPJobReady) |
|
477 { |
|
478 LOG("[CUPnPPrintingDevice]\t Invalid state"); |
|
479 return KErrInvalidSequence; |
|
480 } |
|
481 |
|
482 return iPrintFactory->GetPrintSetting(aCapabilityID, aValue); |
|
483 } |
|
484 |
|
485 //-------------------------------------------------------------------------------------------- |
|
486 // |
|
487 // CUPnPPrintingDevice::SetJobSettingL |
|
488 // |
|
489 //-------------------------------------------------------------------------------------------- |
|
490 TInt CUPnPPrintingDevice::SetJobSettingL(TInt aCapabilityID, TInt aValue, TInt& aAffectedCapability) |
|
491 { |
|
492 LOG("[CUPnPPrintingDevice]\t SetJobSettingL"); |
|
493 if (iState != EUPnPJobReady) |
|
494 { |
|
495 LOG("[CUPnPPrintingDevice]\t Invalid state"); |
|
496 return KErrInvalidSequence; |
|
497 } |
|
498 |
|
499 // Set setting in job container |
|
500 aAffectedCapability = aCapabilityID; |
|
501 return iPrintFactory->SetPrintSetting(aCapabilityID, aValue); |
|
502 } |
|
503 |
|
504 //-------------------------------------------------------------------------------------------- |
|
505 // |
|
506 // CUPnPPrintingDevice::GetNumPreviewPages |
|
507 // |
|
508 //-------------------------------------------------------------------------------------------- |
|
509 TInt CUPnPPrintingDevice::GetNumPreviewPages() |
|
510 { |
|
511 return KErrNotSupported; |
|
512 } |
|
513 |
|
514 //-------------------------------------------------------------------------------------------- |
|
515 // |
|
516 // CUPnPPrintingDevice::GetJobTemplateIconL |
|
517 // |
|
518 //-------------------------------------------------------------------------------------------- |
|
519 TInt CUPnPPrintingDevice::GetJobTemplateIconL(TInt /*aTemplateID*/, TInt& aFsBitmapHandle) |
|
520 { |
|
521 TInt res = KErrNone; |
|
522 |
|
523 if(iFbsBitmap) |
|
524 aFsBitmapHandle = iFbsBitmap->Handle(); |
|
525 else |
|
526 { |
|
527 iFbsBitmap = new (ELeave) CFbsBitmap(); |
|
528 TFileName iconsFileName; |
|
529 iconsFileName.Append( KDC_RESOURCE_FILES_DIR ); |
|
530 iconsFileName.Append( KIconsFileName ); |
|
531 res = iFbsBitmap->Load( iconsFileName ,EMbmUpnpiconsIcon ); |
|
532 |
|
533 if( res == KErrNone ) |
|
534 aFsBitmapHandle = iFbsBitmap->Handle(); |
|
535 else |
|
536 { |
|
537 aFsBitmapHandle = 0; |
|
538 delete iFbsBitmap; |
|
539 iFbsBitmap = NULL; |
|
540 } |
|
541 } |
|
542 |
|
543 return res; |
|
544 } |
|
545 |
|
546 //-------------------------------------------------------------------------------------------- |
|
547 // |
|
548 // CUPnPPrintingDevice::CreatePreviewImage |
|
549 // |
|
550 //-------------------------------------------------------------------------------------------- |
|
551 TInt CUPnPPrintingDevice::CreatePreviewImage(TInt /*aPageNumber*/) |
|
552 { |
|
553 return KErrNotSupported; |
|
554 } |
|
555 |
|
556 |
|
557 //-------------------------------------------------------------------------------------------- |
|
558 // |
|
559 // CUPnPPrintingDevice::SetNumsOfCopiesL |
|
560 // |
|
561 //-------------------------------------------------------------------------------------------- |
|
562 void CUPnPPrintingDevice::SetNumsOfCopiesL( const RArray<TInt>& aNumsOfCopies, TInt& aErr ) |
|
563 { |
|
564 if(iState != EUPnPJobReady) |
|
565 aErr = KErrInvalidSequence; |
|
566 else |
|
567 aErr = iPrintingJob->SetNumsOfCopies(aNumsOfCopies); |
|
568 |
|
569 return; |
|
570 } |
|
571 |
|
572 // ========================================================================================== |
|
573 // From MPCPObserver |
|
574 // ========================================================================================== |
|
575 //-------------------------------------------------------------------------------------------- |
|
576 // |
|
577 // CUPnPPrintingDevice::CreateJobResponse |
|
578 // |
|
579 //-------------------------------------------------------------------------------------------- |
|
580 void CUPnPPrintingDevice::CreateJobResponse( CUpnpAction* aAction, TInt aErrorCode ) |
|
581 { |
|
582 LOG1("[CUPnPPrintingDevice::CreateJobResponse]\t Error: %d", aErrorCode); |
|
583 |
|
584 if(!aAction) |
|
585 return; |
|
586 |
|
587 if (iState == EUPnPCancelling || iPrintingJob->SessionId() != aAction->SessionId()) |
|
588 return; |
|
589 |
|
590 if(KErrNone != aErrorCode) |
|
591 { |
|
592 FinishPrinting(EObexConnectError, aErrorCode); |
|
593 return; |
|
594 } |
|
595 |
|
596 ResetTimer(); |
|
597 iPrintingJob->SetJobId(aAction->ArgumentValue(KJobId())); |
|
598 |
|
599 iState = EUPnPPrintingStarted; |
|
600 |
|
601 TBuf8<KMaxIdLength> id; |
|
602 iPrintingJob->GetJobId(id); |
|
603 |
|
604 LOG("[CUPnPPrintingDevice]\t ******"); |
|
605 LOG81("[CUPnPPrintingDevice]\t -Printing started with job id: * %S", &id); |
|
606 LOG("[CUPnPPrintingDevice]\t ******"); |
|
607 |
|
608 // Printing started - restart timer |
|
609 StartTimer(KPrinterResponseTimeout, KPrinterResponseTimeout, TCallBack(StatusTimeoutCBL, this) ); |
|
610 } |
|
611 |
|
612 |
|
613 //-------------------------------------------------------------------------------------------- |
|
614 // |
|
615 // CUPnPPrintingDevice::CancelJobResponse |
|
616 // |
|
617 //-------------------------------------------------------------------------------------------- |
|
618 void CUPnPPrintingDevice::CancelJobResponse( CUpnpAction* /*aAction*/, TInt aErrorCode ) |
|
619 { |
|
620 LOG1("[CUPnPPrintingDevice::CancelJobResponse]\t Error: %d", aErrorCode); |
|
621 |
|
622 FinishPrinting(aErrorCode, KErrNone); |
|
623 if (iPrintEventObserver && KErrNone == aErrorCode) |
|
624 iPrintEventObserver->PrintJobProgressEvent(EDone, iPrintingJob->Progress(), ECancelling); |
|
625 } |
|
626 //-------------------------------------------------------------------------------------------- |
|
627 // |
|
628 // CUPnPPrintingDevice::GetPrinterAttributesResponse |
|
629 // |
|
630 //-------------------------------------------------------------------------------------------- |
|
631 void CUPnPPrintingDevice::GetPrinterAttributesResponse( CUpnpAction* aAction, TInt aErrorCode ) |
|
632 { |
|
633 LOG1("[CUPnPPrintingDevice::GetPrinterAttributesResponse]\t Error: %d", aErrorCode); |
|
634 |
|
635 if(!aAction) |
|
636 return; |
|
637 |
|
638 if (KErrNone != aErrorCode) |
|
639 { |
|
640 FinishPrinting(KErrGeneral, aErrorCode); |
|
641 return; |
|
642 } |
|
643 |
|
644 // Cancel and restart timer |
|
645 // Read printer attributes from action and update job status |
|
646 TUPnPState state = EStateUnknown; |
|
647 TRAPD(err, state = iPrintingJob->UpdateJobState(aAction->ArgumentValue( KPrinterState() ), |
|
648 aAction->ArgumentValue( KPrinterStateReasons() ), |
|
649 aAction->ArgumentValue( KJobIdList() ), |
|
650 aAction->ArgumentValue( KJobId() ), |
|
651 aAction->ArgumentValue( KSheetsCompleted() ) ) ); |
|
652 if(KErrNone != err) |
|
653 { |
|
654 FinishPrinting(KErrGeneral, err); |
|
655 return; |
|
656 } |
|
657 |
|
658 UpdatePrintingStatus(state); |
|
659 } |
|
660 |
|
661 |
|
662 //-------------------------------------------------------------------------------------------- |
|
663 // |
|
664 // CUPnPPrintingDevice::GetJobAttributesResponse |
|
665 // |
|
666 //-------------------------------------------------------------------------------------------- |
|
667 void CUPnPPrintingDevice::GetJobAttributesResponse( CUpnpAction* aAction, TInt aErrorCode ) |
|
668 { |
|
669 LOG1("[CUPnPPrintingDevice::GetJobAttributesResponse]\t Error: %d", aErrorCode); |
|
670 |
|
671 if (KErrNone != aErrorCode) |
|
672 { |
|
673 LOG1("[CUPnPPrintingDevice:.GetJobAttributesResponse]\t - GetPrinterAttributesL with error: %d", aErrorCode); |
|
674 |
|
675 TInt err = KErrNone; |
|
676 CUpnpDevice* printer = GetPrinter(); |
|
677 if(!printer) |
|
678 err = KErrNoMemory; |
|
679 else |
|
680 TRAP(err, iPrinterControl->GetPrinterAttributesL(printer)); |
|
681 |
|
682 if(KErrNone != err) |
|
683 FinishPrinting(KErrGeneral, err); |
|
684 |
|
685 return; |
|
686 } |
|
687 |
|
688 if(!aAction) |
|
689 return; |
|
690 |
|
691 LOG81("[CUPnPPrintingDevice::GetJobAttributesResponse]\t sheets: ", &(aAction->ArgumentValue( KSheetsCompleted() ))); |
|
692 LOG81("[CUPnPPrintingDevice::GetJobAttributesResponse]\t name: ", &(aAction->ArgumentValue( KJobName() ))); |
|
693 LOG81("[CUPnPPrintingDevice::GetJobAttributesResponse]\t origin: ", &(aAction->ArgumentValue( KUserName() ))); |
|
694 LOG81("[CUPnPPrintingDevice::GetJobAttributesResponse]\t id: ", &(aAction->ArgumentValue( KJobId() ))); |
|
695 |
|
696 TBuf8<KMaxIdLength> id; |
|
697 iPrintingJob->GetJobId(id); |
|
698 |
|
699 TUPnPState state = EStateUnknown; |
|
700 state = iPrintingJob->JobMediaSheetsCompletedUpdated(id, aAction->ArgumentValue( KSheetsCompleted() ) ); |
|
701 |
|
702 UpdatePrintingStatus(state); |
|
703 } |
|
704 |
|
705 //-------------------------------------------------------------------------------------------- |
|
706 // |
|
707 // CUPnPPrintingDevice::GetMarginsResponse |
|
708 // |
|
709 //-------------------------------------------------------------------------------------------- |
|
710 void CUPnPPrintingDevice::GetMarginsResponse( CUpnpAction* /*aAction*/, TInt aErrorCode ) |
|
711 { |
|
712 LOG1("[CUPnPPrintingDevice::GetMarginsResponse]\t Error: %d", aErrorCode); |
|
713 if (KErrNone != aErrorCode) |
|
714 { |
|
715 FinishPrinting(KErrGeneral, aErrorCode); |
|
716 return; |
|
717 } |
|
718 |
|
719 } |
|
720 |
|
721 //-------------------------------------------------------------------------------------------- |
|
722 // |
|
723 // CUPnPPrintingDevice::GetMediaListResponse |
|
724 // |
|
725 //-------------------------------------------------------------------------------------------- |
|
726 void CUPnPPrintingDevice::GetMediaListResponse( CUpnpAction* /*aAction*/, TInt aErrorCode ) |
|
727 { |
|
728 LOG1("[CUPnPPrintingDevice::GetMediaListResponse]\t Error: %d", aErrorCode); |
|
729 if (KErrNone != aErrorCode) |
|
730 { |
|
731 FinishPrinting(KErrGeneral, aErrorCode); |
|
732 return; |
|
733 } |
|
734 |
|
735 } |
|
736 |
|
737 //-------------------------------------------------------------------------------------------- |
|
738 // |
|
739 // CUPnPPrintingDevice::StateUpdatedResponse |
|
740 // |
|
741 //-------------------------------------------------------------------------------------------- |
|
742 void CUPnPPrintingDevice::StateUpdatedResponse( const TDesC8& /*aPrinterState*/, |
|
743 const TDesC8& /*aPrinterStateReasons*/, |
|
744 const TDesC8& /*aJobIdList*/, |
|
745 const TDesC8& /*aJobEndState*/, |
|
746 const TDesC8& /*aJobMediaSheetsCompleted*/, |
|
747 const TDesC8& /*aJobAbortState*/, |
|
748 const TDesC8& /*aContentCompleteList*/ ) |
|
749 { |
|
750 LOG("[CUPnPPrintingDevice::StateUpdatedResponse]\t"); |
|
751 } |
|
752 |
|
753 //-------------------------------------------------------------------------------------------- |
|
754 // |
|
755 // CUPnPPrintingDevice::PrinterStateUpdated |
|
756 // |
|
757 //-------------------------------------------------------------------------------------------- |
|
758 void CUPnPPrintingDevice::PrinterStateUpdated( const TDesC8& aEvent ) |
|
759 { |
|
760 // no need to check the states: we're not printing |
|
761 if(EUPnPPrintingStarted != iState && EUPnPPrinting != iState) |
|
762 return; |
|
763 |
|
764 LOG81("[CUPnPPrintingDevice::PrinterStateUpdated]\t:%S",&aEvent); |
|
765 iStatusTimeout = EFalse; |
|
766 TUPnPState state = iPrintingJob->PrinterStateUpdated(aEvent); |
|
767 UpdatePrintingStatus(state); |
|
768 } |
|
769 |
|
770 //-------------------------------------------------------------------------------------------- |
|
771 // |
|
772 // CUPnPPrintingDevice::PrinterStateReasonsUpdated |
|
773 // |
|
774 //-------------------------------------------------------------------------------------------- |
|
775 void CUPnPPrintingDevice::PrinterStateReasonsUpdated( const TDesC8& aEvent ) |
|
776 { |
|
777 // no need to check the states: we're not printing |
|
778 if(EUPnPPrintingStarted != iState && EUPnPPrinting != iState) |
|
779 return; |
|
780 |
|
781 LOG81("[CUPnPPrintingDevice::PrinterStateReasonsUpdated]\t: %S",&aEvent); |
|
782 iStatusTimeout = EFalse; |
|
783 TUPnPState state = iPrintingJob->PrinterStateReasonsUpdated(aEvent); |
|
784 UpdatePrintingStatus(state); |
|
785 } |
|
786 |
|
787 //-------------------------------------------------------------------------------------------- |
|
788 // |
|
789 // CUPnPPrintingDevice::JobIdListUpdated |
|
790 // |
|
791 //-------------------------------------------------------------------------------------------- |
|
792 void CUPnPPrintingDevice::JobIdListUpdated( const TDesC8& aEvent ) |
|
793 { |
|
794 // no need to check the states: we're not printing |
|
795 if(EUPnPPrintingStarted != iState && EUPnPPrinting != iState) |
|
796 return; |
|
797 |
|
798 LOG81("[CUPnPPrintingDevice::JobIdListUpdated]\t:%S",&aEvent); |
|
799 iStatusTimeout = EFalse; |
|
800 TUPnPState state = iPrintingJob->JobIdListUpdated(aEvent); |
|
801 UpdatePrintingStatus(state); |
|
802 } |
|
803 |
|
804 //-------------------------------------------------------------------------------------------- |
|
805 // |
|
806 // CUPnPPrintingDevice::JobEndStateUpdated |
|
807 // |
|
808 //-------------------------------------------------------------------------------------------- |
|
809 void CUPnPPrintingDevice::JobEndStateUpdated( const TDesC8& aEvent ) |
|
810 { |
|
811 // no need to check the states: we're not printing |
|
812 if(EUPnPPrintingStarted != iState && EUPnPPrinting != iState) |
|
813 return; |
|
814 |
|
815 LOG81("[CUPnPPrintingDevice::JobEndStateUpdated]\t:%S",&aEvent); |
|
816 |
|
817 TUPnPState state = EStateUnknown; |
|
818 TRAPD(err, state = iPrintingJob->JobEndStateUpdatedL(aEvent)); |
|
819 if(KErrNone != err) |
|
820 { |
|
821 LOG1("[CUPnPPrintingDevice::JobEndStateUpdated]\t leaving with error %d. Continue with timer.",err); |
|
822 return; |
|
823 } |
|
824 |
|
825 iStatusTimeout = EFalse; |
|
826 UpdatePrintingStatus(state); |
|
827 } |
|
828 |
|
829 //-------------------------------------------------------------------------------------------- |
|
830 // |
|
831 // CUPnPPrintingDevice::JobMediaSheetsCompletedUpdated |
|
832 // |
|
833 //-------------------------------------------------------------------------------------------- |
|
834 void CUPnPPrintingDevice::JobMediaSheetsCompletedUpdated( const TDesC8& aEvent ) |
|
835 { |
|
836 // no need to check the states: we're not printing |
|
837 if(EUPnPPrintingStarted != iState && EUPnPPrinting != iState) |
|
838 return; |
|
839 |
|
840 LOG81("[CUPnPPrintingDevice::JobMediaSheetsCompletedUpdated]\t:%S",&aEvent); |
|
841 iStatusTimeout = EFalse; |
|
842 TUPnPState state = iPrintingJob->JobMediaSheetsCompletedUpdated(aEvent); |
|
843 UpdatePrintingStatus(state); |
|
844 } |
|
845 |
|
846 //-------------------------------------------------------------------------------------------- |
|
847 // |
|
848 // CUPnPPrintingDevice::ContentCompleteListUpdated |
|
849 // |
|
850 //-------------------------------------------------------------------------------------------- |
|
851 void CUPnPPrintingDevice::ContentCompleteListUpdated( const TDesC8& aEvent ) |
|
852 { |
|
853 // no need to check the states: we're not printing |
|
854 if(EUPnPPrintingStarted != iState && EUPnPPrinting != iState) |
|
855 return; |
|
856 |
|
857 LOG81("[CUPnPPrintingDevice::ContentCompleteListUpdated]\t:%S",&aEvent); |
|
858 iStatusTimeout = EFalse; |
|
859 TUPnPState state = iPrintingJob->ContentCompleteListUpdated(aEvent); |
|
860 UpdatePrintingStatus(state); |
|
861 } |
|
862 |
|
863 //-------------------------------------------------------------------------------------------- |
|
864 // |
|
865 // CUPnPPrintingDevice::JobAbortStateUpdated |
|
866 // |
|
867 //-------------------------------------------------------------------------------------------- |
|
868 void CUPnPPrintingDevice::JobAbortStateUpdated( const TDesC8& aEvent ) |
|
869 { |
|
870 // no need to check the states: we're not printing |
|
871 if(EUPnPPrintingStarted != iState && EUPnPPrinting != iState) |
|
872 return; |
|
873 |
|
874 LOG81("[CUPnPPrintingDevice::JobAbortStateUpdated]\t:%S",&aEvent); |
|
875 |
|
876 TUPnPState state = EStateUnknown; |
|
877 TRAPD(err, state = iPrintingJob->JobAbortStateUpdatedL(aEvent)); |
|
878 if(KErrNone != err) |
|
879 { |
|
880 LOG1("[CUPnPPrintingDevice::JobAbortStateUpdatedL]\t leaving with error %d. Continue with timer.",err); |
|
881 return; |
|
882 } |
|
883 |
|
884 iStatusTimeout = EFalse; |
|
885 UpdatePrintingStatus(state); |
|
886 } |
|
887 |
|
888 //-------------------------------------------------------------------------------------------- |
|
889 // |
|
890 // CUPnPPrintingDevice::DeviceDiscoveredL |
|
891 // |
|
892 //-------------------------------------------------------------------------------------------- |
|
893 void CUPnPPrintingDevice::DeviceDiscoveredL( CUpnpDevice* aDevice ) |
|
894 { |
|
895 |
|
896 LOG("[CUPnPPrintingDevice::DeviceDiscovered]\t "); |
|
897 TInt id; |
|
898 TInt err = KErrNone; |
|
899 |
|
900 if(!aDevice) |
|
901 return; |
|
902 |
|
903 //Trap this: the iDiscoveryObserver will othervise never know about error |
|
904 TRAP(err, iPrinterContainer->AddPrinterL(*aDevice, id)); |
|
905 |
|
906 // Inform about error and leave |
|
907 if(KErrNone != err && KErrAlreadyExists != err) |
|
908 { |
|
909 if(iDiscoveryObserver && iState == EUPnPDiscovery) |
|
910 { |
|
911 iDiscoveryObserver->DiscoveryStatusL(EDiscoveryFinished, err, 0); |
|
912 } |
|
913 User::Leave(err); |
|
914 } |
|
915 |
|
916 iPrintersFound = ETrue; |
|
917 if (iState == EUPnPUninitialized) |
|
918 { |
|
919 iState = EUPnPReady; |
|
920 } |
|
921 |
|
922 if(iState == EUPnPDiscovery && iDiscoveryObserver && KErrAlreadyExists != err) |
|
923 { |
|
924 |
|
925 TInt index = iPrinterContainer->PrinterIndex(id); |
|
926 TPrinter printer = iPrinterContainer->ToTPrinter(index); |
|
927 iDiscoveryObserver->FoundDeviceL(printer); |
|
928 } |
|
929 |
|
930 if (iState == EUPnPSubmittingJob) |
|
931 { |
|
932 // Check if the discovered printer is the one we're trying to print with |
|
933 if (iPrintingJob->PrinterId() == id) |
|
934 { |
|
935 // Stop submit timer and submit job |
|
936 ResetTimer(); |
|
937 TRAP(err, SubmitJobToPcpL(*aDevice, id) ); |
|
938 |
|
939 // If error occured inform client - leaving not necessary here |
|
940 if (err != KErrNone) |
|
941 { |
|
942 if (iPrintEventObserver) |
|
943 { |
|
944 iPrintEventObserver->PrintJobErrorEvent(EObexConnectError, err); |
|
945 } |
|
946 iState = EUPnPJobReady; |
|
947 } |
|
948 } |
|
949 } |
|
950 LOG("[CUPnPPrintingDevice::DeviceDiscovered]\t -out"); |
|
951 } |
|
952 |
|
953 //-------------------------------------------------------------------------------------------- |
|
954 // |
|
955 // CUPnPPrintingDevice::DeviceDisappeared |
|
956 // |
|
957 //-------------------------------------------------------------------------------------------- |
|
958 void CUPnPPrintingDevice::DeviceDisappeared( CUpnpDevice* aDevice ) |
|
959 { |
|
960 LOG("[CUPnPPrintingDevice]\t DeviceDisappeared"); |
|
961 if ( aDevice ) |
|
962 { |
|
963 // Notify protocol client if we're in discovery state |
|
964 if(iState == EUPnPDiscovery && iDiscoveryObserver) |
|
965 { |
|
966 TInt index = iPrinterContainer->PrinterIndex( *aDevice ); |
|
967 if (index >= 0) |
|
968 { |
|
969 LOG("[CUPnPPrintingDevice]\t informing observer"); |
|
970 TPrinter printer = iPrinterContainer->ToTPrinter(index); |
|
971 |
|
972 // Notification needs to be trapped because this is not a leaving function |
|
973 TRAP_IGNORE(iDiscoveryObserver->RemoveDeviceL(printer)); |
|
974 |
|
975 iPrinterContainer->RemovePrinter(index); |
|
976 } |
|
977 } |
|
978 else |
|
979 { |
|
980 LOG("[CUPnPPrintingDevice]\t saving to disappeared list"); |
|
981 // Trapped because this is not a leaving function |
|
982 TRAP_IGNORE(iPrinterContainer->PrinterDisappeared( *aDevice )); |
|
983 } |
|
984 } |
|
985 if ( iPrinterContainer->PrinterCount() < 1 ) |
|
986 { |
|
987 iPrintersFound = EFalse; |
|
988 } |
|
989 } |
|
990 |
|
991 |
|
992 ///////////////////////// |
|
993 // Protected. |
|
994 ///////////////////////// |
|
995 |
|
996 |
|
997 ///////////////////////// |
|
998 // Private. |
|
999 ///////////////////////// |
|
1000 //-------------------------------------------------------------------------------------------- |
|
1001 // |
|
1002 // CUPnPPrintingDevice::CUPnPPrintingDevice |
|
1003 // |
|
1004 //-------------------------------------------------------------------------------------------- |
|
1005 CUPnPPrintingDevice::CUPnPPrintingDevice() |
|
1006 { |
|
1007 iPrinterTimer = NULL; |
|
1008 iState = EUPnPUninitialized; |
|
1009 iPrintersFound = EFalse; |
|
1010 iTriedReadCacheAndFail = EFalse; |
|
1011 ResetTimer(); |
|
1012 } |
|
1013 |
|
1014 //-------------------------------------------------------------------------------------------- |
|
1015 // |
|
1016 // CUPnPPrintingDevice::RestartControlPointL |
|
1017 // |
|
1018 //-------------------------------------------------------------------------------------------- |
|
1019 void CUPnPPrintingDevice::RestartControlPointL() |
|
1020 { |
|
1021 if (iPrinterControl) |
|
1022 { |
|
1023 delete iPrinterControl; |
|
1024 iPrinterControl = NULL; |
|
1025 } |
|
1026 |
|
1027 iFriendlyName.Copy(KUPnPUserName()); |
|
1028 |
|
1029 CUpnpSettings *rep = CUpnpSettings::NewL( KCRUidUPnPStack ); |
|
1030 CleanupStack::PushL(rep); |
|
1031 //Get Access Point from central repository |
|
1032 TInt iapId = -1; |
|
1033 User::LeaveIfError( rep->Get( CUpnpSettings::KUPnPStackIapId, iapId )); |
|
1034 |
|
1035 //Check accessPoint and leave if not ok |
|
1036 if( iapId < 0 ) |
|
1037 { |
|
1038 if(iDiscoveryObserver) |
|
1039 iDiscoveryObserver->DiscoveryStatusL(EDiscoveryFinished, KErrAbort, 0); |
|
1040 User::Leave( KErrAbort ); |
|
1041 } |
|
1042 |
|
1043 CleanupStack::PopAndDestroy(rep); |
|
1044 |
|
1045 |
|
1046 // Create printer control point - search starts right away |
|
1047 LOG("[CUPnPPrintingDevice]\t - Printer control point"); |
|
1048 iPrinterControl = CPrinterControlPoint::NewL(*this); |
|
1049 } |
|
1050 |
|
1051 |
|
1052 //-------------------------------------------------------------------------------------------- |
|
1053 // |
|
1054 // CUPnPPrintingDevice::SendPrinterListL |
|
1055 // |
|
1056 //-------------------------------------------------------------------------------------------- |
|
1057 void CUPnPPrintingDevice::SendPrinterListL(TBool aSync) |
|
1058 { |
|
1059 LOG("[CUPnPPrintingDevice]\t SendPrinterListL Begin"); |
|
1060 TInt err = KErrNone; |
|
1061 if (aSync) |
|
1062 { |
|
1063 // Remove disappeared devices from array |
|
1064 iPrinterContainer->SyncPrinterArray(); |
|
1065 } |
|
1066 |
|
1067 if (iPrinterContainer->PrinterCount() < 1 && !iTriedReadCacheAndFail) |
|
1068 { |
|
1069 // Read printer cache |
|
1070 LOG("[CUPnPPrintingDevice]\t SendPrinterListL xxx trying read cache file"); |
|
1071 TRAP(err, iPrinterContainer->ReadCacheL()); |
|
1072 if(KErrNone != err) |
|
1073 { |
|
1074 LOG1("[CUPnPPrintingDevice]\t SendPrinterListL xxx some error file reading %d", err); |
|
1075 if(err == KErrNotFound) |
|
1076 { |
|
1077 iPrintersFound = EFalse; |
|
1078 iTriedReadCacheAndFail = ETrue; |
|
1079 } |
|
1080 else |
|
1081 User::Leave(err); |
|
1082 } |
|
1083 else |
|
1084 { |
|
1085 LOG("[CUPnPPrintingDevice]\t SendPrinterListL xxx cachefile readed"); |
|
1086 iPrintersFound = EFalse; |
|
1087 } |
|
1088 |
|
1089 if(aSync) |
|
1090 { |
|
1091 RestartControlPointL(); |
|
1092 } |
|
1093 } |
|
1094 |
|
1095 if (iPrinterContainer->PrinterCount() > 0 && iDiscoveryObserver) |
|
1096 { |
|
1097 for (TInt i=0; i< iPrinterContainer->PrinterCount(); i++) |
|
1098 { |
|
1099 TPrinter t = iPrinterContainer->ToTPrinter(i); |
|
1100 iDiscoveryObserver->FoundDeviceL( t ); |
|
1101 } |
|
1102 } |
|
1103 |
|
1104 if (!iPrintersFound) |
|
1105 { |
|
1106 // start timed search |
|
1107 StartTimer(KPrinterDiscoveryTimeout, KPrinterDiscoveryTimeout, TCallBack(DiscoveryTimeoutCBL, this) ); |
|
1108 iState = EUPnPDiscovery; |
|
1109 iTriedReadCacheAndFail = EFalse; |
|
1110 } |
|
1111 else |
|
1112 { |
|
1113 iDiscoveryObserver->DiscoveryStatusL(EDiscoveryFinished, KErrNone, 0); |
|
1114 } |
|
1115 LOG("[CUPnPPrintingDevice]\t SendPrinterListL end"); |
|
1116 } |
|
1117 |
|
1118 //-------------------------------------------------------------------------------------------- |
|
1119 // |
|
1120 // CUPnPPrintingDevice::DoDiscoveryTimeoutL |
|
1121 // |
|
1122 //-------------------------------------------------------------------------------------------- |
|
1123 TBool CUPnPPrintingDevice::DoDiscoveryTimeoutL(TBool aDoCallBack) |
|
1124 { |
|
1125 LOG("[CUPnPPrintingDevice]\t DoDiscoveryTimeOut"); |
|
1126 |
|
1127 ResetTimer(); |
|
1128 switch( iState ) |
|
1129 { |
|
1130 case EUPnPCancellingDiscovery: |
|
1131 { |
|
1132 LOG("[CUPnPPrintingDevice]\t cancelling discovery"); |
|
1133 |
|
1134 if (iPrinterContainer->PrinterCount() > 0) |
|
1135 { |
|
1136 iPrintersFound = ETrue; |
|
1137 } |
|
1138 |
|
1139 if (aDoCallBack && iDiscoveryObserver) |
|
1140 { |
|
1141 iDiscoveryObserver->DiscoveryStatusL(EDiscoveryFinished, KErrNone, 0); |
|
1142 } |
|
1143 |
|
1144 } |
|
1145 break; |
|
1146 case EUPnPDiscovery: |
|
1147 { |
|
1148 LOG("[CUPnPPrintingDevice]\t discovery timeout"); |
|
1149 |
|
1150 // Notify about cached devices, which weren't discovered |
|
1151 RPointerArray<CUPPrinter> cachedPrinters; |
|
1152 CleanupClosePushL(cachedPrinters); |
|
1153 iPrinterContainer->GetDisappearedPrinters(cachedPrinters); |
|
1154 for (TInt i=0; i < cachedPrinters.Count(); i++) |
|
1155 { |
|
1156 TPrinter printer = cachedPrinters[i]->ToTPrinter(); |
|
1157 iDiscoveryObserver->RemoveDeviceL(printer); |
|
1158 } |
|
1159 |
|
1160 CleanupStack::PopAndDestroy(); //cachedPrinters |
|
1161 |
|
1162 // Remove disappeared printers and cached printers, which weren't found printers from container |
|
1163 iPrinterContainer->SyncPrinterArray(); |
|
1164 |
|
1165 if (iPrinterContainer->PrinterCount() > 0) |
|
1166 { |
|
1167 iPrintersFound = ETrue; |
|
1168 } |
|
1169 |
|
1170 // Notify client's observer |
|
1171 if (aDoCallBack && iDiscoveryObserver) |
|
1172 iDiscoveryObserver->DiscoveryStatusL(EDiscoveryFinished, KErrNone, 0); |
|
1173 |
|
1174 } |
|
1175 break; |
|
1176 default: |
|
1177 break; |
|
1178 } |
|
1179 |
|
1180 if (!iPrintersFound) |
|
1181 { |
|
1182 LOG("[CUPnPPrintingDevice]\t no printers found"); |
|
1183 iState = EUPnPUninitialized; |
|
1184 } |
|
1185 else |
|
1186 { |
|
1187 iState = EUPnPReady; |
|
1188 } |
|
1189 |
|
1190 //Don't run this callback again |
|
1191 return EFalse; |
|
1192 } |
|
1193 |
|
1194 //-------------------------------------------------------------------------------------------- |
|
1195 // |
|
1196 // CUPnPPrintingDevice::DoStatusTimeoutL |
|
1197 // |
|
1198 //-------------------------------------------------------------------------------------------- |
|
1199 TBool CUPnPPrintingDevice::DoStatusTimeoutL() |
|
1200 { |
|
1201 LOG("[CUPnPPrintingDevice]\t DoStatusTimeOut"); |
|
1202 |
|
1203 if (iState == EUPnPCancelling || iState == EUPnPSubmittingJob) |
|
1204 { |
|
1205 // Printer did not response to cancel or create job |
|
1206 LOG("[CUPnPPrintingDevice]\t - no response for cancel or create."); |
|
1207 FinishPrinting(KErrGeneral, EPbCheckPrinter); |
|
1208 return EFalse; // do not call again |
|
1209 } |
|
1210 |
|
1211 if (iState == EUPnPPrinting || iState == EUPnPPrintingStarted) |
|
1212 { |
|
1213 --iPendingCount; |
|
1214 |
|
1215 // No printing status notifications received |
|
1216 CUpnpDevice* printer = GetPrinter(); |
|
1217 if (!printer || iStatusTimeout || 0 > iPendingCount) |
|
1218 { |
|
1219 // print error - cancel printing |
|
1220 LOG("[CUPnPPrintingDevice]\t - print error - cancel printing."); |
|
1221 LOG1("[CUPnPPrintingDevice]\t - iStatusTimeout: %d", iStatusTimeout); |
|
1222 LOG1("[CUPnPPrintingDevice]\t - iPendingCount: %d", iPendingCount); |
|
1223 ResetTimer(); |
|
1224 if (iPrintEventObserver) |
|
1225 iPrintEventObserver->PrintJobErrorEvent(KErrTimedOut, EPbCheckPrinter); |
|
1226 DoCancelPrinting(); |
|
1227 return EFalse; // do not call again |
|
1228 } |
|
1229 |
|
1230 iStatusTimeout = ETrue; |
|
1231 |
|
1232 LOG1("[CUPnPPrintingDevice]\t - GetPrinterAttributesL with iState: %d", iState); |
|
1233 iPrinterControl->GetPrinterAttributesL(printer); |
|
1234 |
|
1235 /*LOG1("[CUPnPPrintingDevice]\t - GetJobAttributesL with iState: %d", iState); |
|
1236 TBuf8<KMaxIdLength> id; |
|
1237 iPrintingJob->GetJobId(id); |
|
1238 iPrinterControl->GetJobAttributesL(printer, id);*/ |
|
1239 } |
|
1240 |
|
1241 return ETrue; // call again |
|
1242 } |
|
1243 |
|
1244 |
|
1245 |
|
1246 //-------------------------------------------------------------------------------------------- |
|
1247 // |
|
1248 // CUPnPPrintingDevice::InitJobL |
|
1249 // |
|
1250 //-------------------------------------------------------------------------------------------- |
|
1251 void CUPnPPrintingDevice::InitJobL(TInt aDeviceId, RPointerArray<TDesC>& aImages) |
|
1252 { |
|
1253 LOG("[CUPnPPrintingDevice::InitJobL]\t"); |
|
1254 |
|
1255 // Check that device exists |
|
1256 CUPPrinter* printer = iPrinterContainer->Printer(aDeviceId); |
|
1257 if (!printer) |
|
1258 { |
|
1259 LOG("[CUPnPPrintingDevice]\t printer not found"); |
|
1260 User::Leave(KErrArgument); |
|
1261 } |
|
1262 |
|
1263 // Create job |
|
1264 if (iPrintingJob) |
|
1265 { |
|
1266 delete iPrintingJob; |
|
1267 iPrintingJob = NULL; |
|
1268 } |
|
1269 |
|
1270 // Change format of file list |
|
1271 RArray<TFileName> imageList; |
|
1272 CleanupClosePushL(imageList); |
|
1273 for (TInt i=0; i < aImages.Count(); i++) |
|
1274 { |
|
1275 LOG81("[InitJobL]\t ", aImages[i]); |
|
1276 imageList.Append( *(aImages[i]) ); |
|
1277 } |
|
1278 |
|
1279 // Create job object |
|
1280 iPrintingJob = CUPPrintingJob::NewL(printer, imageList, iPrintFactory, iFriendlyName); |
|
1281 CleanupStack::PopAndDestroy(&imageList); |
|
1282 |
|
1283 // Update state and return |
|
1284 iState = EUPnPJobReady; |
|
1285 } |
|
1286 |
|
1287 //-------------------------------------------------------------------------------------------- |
|
1288 // |
|
1289 // CUPnPPrintingDevice::StartPrintingL |
|
1290 // |
|
1291 //-------------------------------------------------------------------------------------------- |
|
1292 void CUPnPPrintingDevice::StartPrintingL() |
|
1293 { |
|
1294 LOG("[CUPnPPrintingDevice::StartPrintingL]\t"); |
|
1295 ResetTimer(); |
|
1296 |
|
1297 // Get pointer to correct CDevice |
|
1298 CUPPrinter* upPrinter = static_cast<CUPPrinter*>(User::LeaveIfNull( |
|
1299 iPrinterContainer->Printer(iPrintingJob->PrinterId()))); |
|
1300 |
|
1301 CUpnpDevice* printer = upPrinter->Device(); |
|
1302 |
|
1303 if (!printer) |
|
1304 { |
|
1305 LOG("[CUPnPPrintingDevice]\t -UPnP Printer pointer was NULL"); |
|
1306 |
|
1307 // Try to discover selected printer - start timer |
|
1308 StartTimer(KPrinterSubmitTimeout, KPrinterSubmitTimeout, TCallBack(SubmitTimeoutCBL, this) ); |
|
1309 return; |
|
1310 } |
|
1311 |
|
1312 // Send create job to PCP |
|
1313 SubmitJobToPcpL(*printer, iPrintingJob->PrinterId()); |
|
1314 } |
|
1315 |
|
1316 //-------------------------------------------------------------------------------------------- |
|
1317 // |
|
1318 // CUPnPPrintingDevice::DoSubmitTimeoutL |
|
1319 // |
|
1320 //-------------------------------------------------------------------------------------------- |
|
1321 void CUPnPPrintingDevice::DoSubmitTimeoutL() |
|
1322 { |
|
1323 LOG("[CUPnPPrintingDevice]\t CUPnPPrintingDevice::DoSubmitTimeoutL"); |
|
1324 |
|
1325 ResetTimer(); |
|
1326 |
|
1327 TRAPD(err, SubmitJobToPcpL(iPrintingJob->PrinterId())); |
|
1328 |
|
1329 if( err != KErrNone) |
|
1330 { |
|
1331 if (iPrintEventObserver) |
|
1332 iPrintEventObserver->PrintJobErrorEvent(EObexConnectError, err); |
|
1333 iState = EUPnPJobReady; |
|
1334 } |
|
1335 |
|
1336 } |
|
1337 |
|
1338 |
|
1339 |
|
1340 //-------------------------------------------------------------------------------------------- |
|
1341 // |
|
1342 // CUPnPPrintingDevice::SubmitJobToPcpL |
|
1343 // |
|
1344 //-------------------------------------------------------------------------------------------- |
|
1345 void CUPnPPrintingDevice::SubmitJobToPcpL(TInt aDeviceID) |
|
1346 { |
|
1347 LOG("[CUPnPPrintingDevice::SubmitJobToPcpL(TInt)]\t"); |
|
1348 |
|
1349 // Get pointer to correct CDevice |
|
1350 CUPPrinter* printer = NULL; |
|
1351 |
|
1352 TInt printerIndex = iPrinterContainer->PrinterIndex(aDeviceID); |
|
1353 if (printerIndex >= 0) |
|
1354 { |
|
1355 printer = |
|
1356 static_cast<CUPPrinter*> (User::LeaveIfNull(iPrinterContainer->Printer(printerIndex))); |
|
1357 } |
|
1358 |
|
1359 SubmitJobToPcpL(*(printer->Device()), aDeviceID); |
|
1360 } |
|
1361 |
|
1362 //-------------------------------------------------------------------------------------------- |
|
1363 // |
|
1364 // CUPnPPrintingDevice::SubmitJobToPcpL |
|
1365 // |
|
1366 //-------------------------------------------------------------------------------------------- |
|
1367 void CUPnPPrintingDevice::SubmitJobToPcpL(CUpnpDevice& aPrinter, TInt aPrinterID) |
|
1368 { |
|
1369 LOG("[CUPnPPrintingDevice::SubmitJobToPcpL(CDevice&, TInt)]\t"); |
|
1370 |
|
1371 // Init settings |
|
1372 TPtrC8 userName; |
|
1373 iPrintingJob->GetUserName(userName); |
|
1374 |
|
1375 // Get and convert xhtml file |
|
1376 TFileName8 fileName; |
|
1377 |
|
1378 LOG("[CUPnPPrintingDevice::SubmitJobToPcpL]\t -before GetPrintFileL call"); |
|
1379 iPrintingJob->GetPrintFileL(fileName); |
|
1380 LOG("[CUPnPPrintingDevice::SubmitJobToPcpL]\t -after GetPrintFile call"); |
|
1381 |
|
1382 User::LeaveIfNull(&aPrinter); |
|
1383 |
|
1384 LOG("[CUPnPPrintingDevice::SubmitJobToPcpL]\t -before CreateJobL call"); |
|
1385 TInt sessionId = iPrinterControl->CreateJobL(&aPrinter, fileName, userName, KUPnPOne(), KUPnPDeviceSetting(), |
|
1386 KUPnPDeviceSetting(), KUPnPDeviceSetting(), KUPnPDeviceSetting(), KUPnPDeviceSetting(), KUPnPDeviceSetting()); |
|
1387 LOG("[CUPnPPrintingDevice::SubmitJobToPcpL]\t -after CreateJobL call"); |
|
1388 |
|
1389 iPrintingJob->SetSessionId(sessionId); |
|
1390 iPendingCount = KPendingLimit + iPrintingJob->ImageCount(); |
|
1391 |
|
1392 LOG1("[CUPnPPrintingDevice]\t -Printing started successfully - timer can expire %d times", iPendingCount); |
|
1393 |
|
1394 //Add printer in cache if doesn't exist |
|
1395 iPrinterContainer->UpdateCacheL(aPrinterID); |
|
1396 |
|
1397 StartTimer(KPrinterResponseTimeout, KPrinterResponseTimeout, TCallBack(StatusTimeoutCBL, this) ); |
|
1398 } |
|
1399 |
|
1400 //-------------------------------------------------------------------------------------------- |
|
1401 // |
|
1402 // CUPnPPrintingDevice::DoCancelPrintJob() |
|
1403 // |
|
1404 //-------------------------------------------------------------------------------------------- |
|
1405 TInt CUPnPPrintingDevice::DoCancelPrinting() |
|
1406 { |
|
1407 LOG("[CUPnPPrintingDevice]\t DoCancelPrinting()"); |
|
1408 |
|
1409 if (iState == EUPnPPrintingStarted || iState == EUPnPPrinting || iState == EUPnPSubmittingJob) |
|
1410 { |
|
1411 // Cancel printer response timer first |
|
1412 LOG("[CUPnPPrintingDevice]\t -Canceling timer"); |
|
1413 ResetTimer(); |
|
1414 |
|
1415 // Cancel current job |
|
1416 iState = EUPnPCancelling; |
|
1417 CUpnpDevice* printer = GetPrinter(); |
|
1418 if (!printer) |
|
1419 { |
|
1420 LOG("[CUPnPPrintingDevice]\t Invalid printer"); |
|
1421 return KErrArgument; |
|
1422 } |
|
1423 |
|
1424 TInt err; |
|
1425 TBuf8<KMaxIdLength> id; |
|
1426 iPrintingJob->GetJobId(id); |
|
1427 |
|
1428 if (id.Length() >= 1) |
|
1429 { |
|
1430 LOG81("[CUPnPPrintingDevice]\t Cancel with job id %S", &id); |
|
1431 TRAP(err, iPrinterControl->CancelJobL(printer, id)) |
|
1432 } |
|
1433 else |
|
1434 { |
|
1435 LOG81("[CUPnPPrintingDevice]\t Cancel with session id %S", iPrintingJob->SessionId()); |
|
1436 TRAP(err, iPrinterControl->CancelJobL(iPrintingJob->SessionId()) ); |
|
1437 } |
|
1438 |
|
1439 if(KErrNone != err) |
|
1440 { |
|
1441 LOG1("[CUPnPPrintingDevice]\t Cancel failed with error %d -> roughly finish printing ", err); |
|
1442 FinishPrinting(KErrGeneral, err); |
|
1443 return err; |
|
1444 } |
|
1445 |
|
1446 // Start timer for cancel response |
|
1447 StartTimer(KPrinterResponseTimeout, KPrinterResponseTimeout, TCallBack(StatusTimeoutCBL, this) ); |
|
1448 |
|
1449 return KErrNone; |
|
1450 } |
|
1451 |
|
1452 if (iState == EUPnPJobReady) |
|
1453 { |
|
1454 return KErrNone; |
|
1455 } |
|
1456 |
|
1457 return KErrInvalidSequence; |
|
1458 } |
|
1459 |
|
1460 //-------------------------------------------------------------------------------------------- |
|
1461 // |
|
1462 // CUPnPPrintingDevice::UpdatePrintingStatus() |
|
1463 // |
|
1464 //-------------------------------------------------------------------------------------------- |
|
1465 void CUPnPPrintingDevice::UpdatePrintingStatus(TUPnPState aJobState) |
|
1466 { |
|
1467 LOG1("[CUPnPPrintingDevice::UpdatePrintingStatus]\t - JobState: %d", aJobState); |
|
1468 |
|
1469 /* Printer stopped */ |
|
1470 if(EPrinterStateStopped == aJobState || EStatePending == aJobState) |
|
1471 { |
|
1472 iStatusTimeout = EFalse; |
|
1473 // Finish printing if reason found. Otherwise wait timer or new message |
|
1474 if(ENoMessage != iPrintingJob->JobState()->Reason()) |
|
1475 { |
|
1476 LOG1("[CUPnPPrintingDevice]\t - state NOK -> Cancel with %d", iPrintingJob->JobStateReason()); |
|
1477 if (iPrintEventObserver) |
|
1478 iPrintEventObserver->PrintJobErrorEvent(KErrGeneral, iPrintingJob->JobStateReason()); |
|
1479 DoCancelPrinting(); |
|
1480 } |
|
1481 return; |
|
1482 } |
|
1483 |
|
1484 // Job aborted |
|
1485 if(EJobStateAborted == aJobState) |
|
1486 { |
|
1487 LOG("[CUPnPPrintingDevice]\t - EJobStateAborted -> Finish"); |
|
1488 FinishPrinting(KErrGeneral, iPrintingJob->JobStateReason()); |
|
1489 return; |
|
1490 } |
|
1491 |
|
1492 if(EStateReady == aJobState) |
|
1493 { |
|
1494 // Printing finished for current job |
|
1495 LOG("[CUPnPPrintingDevice]\t - Printing finished"); |
|
1496 iPrintEventObserver->PrintJobProgressEvent(EDone, iPrintingJob->Progress(), ENoMessage); |
|
1497 |
|
1498 // FinishPrinting |
|
1499 FinishPrinting(); |
|
1500 return; |
|
1501 } |
|
1502 |
|
1503 iPrintEventObserver->PrintJobProgressEvent(EActive, iPrintingJob->Progress(), ENoMessage); |
|
1504 iStatusTimeout = EFalse; |
|
1505 LOG("[CUPnPPrintingDevice::UpdatePrintingStatus]\t - out"); |
|
1506 } |
|
1507 |
|
1508 //-------------------------------------------------------------------------------------------- |
|
1509 // |
|
1510 // CUPnPPrintingDevice::FinishPrinting |
|
1511 // |
|
1512 //-------------------------------------------------------------------------------------------- |
|
1513 void CUPnPPrintingDevice::FinishPrinting() |
|
1514 { |
|
1515 LOG("[CUPnPPrintingDevice::FinishPrinting]\t "); |
|
1516 |
|
1517 LOG("[CUPnPPrintingDevice]\t -Reset timer"); |
|
1518 ResetTimer(); |
|
1519 |
|
1520 LOG("[CUPnPPrintingDevice]\t -Unshare"); |
|
1521 iPrintingJob->UnShareImages(); |
|
1522 |
|
1523 LOG("[CUPnPPrintingDevice]\t -Init ids"); |
|
1524 iPrintingJob->SetJobId(KNullDesC8()); |
|
1525 iPrintingJob->SetSessionId(KErrNotFound); |
|
1526 iPendingCount = KPendingLimit; |
|
1527 |
|
1528 LOG("[CUPnPPrintingDevice]\t -Update state"); |
|
1529 if(NULL != GetPrinter()) |
|
1530 iState = EUPnPJobReady; |
|
1531 else |
|
1532 iState = EUPnPReady; |
|
1533 LOG1("[CUPnPPrintingDevice]\t FinishPrinting: state=%d", iState); |
|
1534 |
|
1535 |
|
1536 // Inform control point |
|
1537 // No can do if this leaves -> ignore leave |
|
1538 TRAP_IGNORE(iPrinterControl->PrintingFinishedL(GetPrinter())); |
|
1539 LOG("[CUPnPPrintingDevice::FinishPrinting]\t -out"); |
|
1540 } |
|
1541 |
|
1542 //-------------------------------------------------------------------------------------------- |
|
1543 // |
|
1544 // CUPnPPrintingDevice::FinishPrinting |
|
1545 // |
|
1546 //-------------------------------------------------------------------------------------------- |
|
1547 void CUPnPPrintingDevice::FinishPrinting(TInt aErrorCode, TInt aErrorMessage) |
|
1548 { |
|
1549 FinishPrinting(); |
|
1550 |
|
1551 if (iPrintEventObserver && KErrNone != aErrorCode) |
|
1552 iPrintEventObserver->PrintJobErrorEvent(aErrorCode, aErrorMessage); |
|
1553 } |
|
1554 |
|
1555 //-------------------------------------------------------------------------------------------- |
|
1556 // |
|
1557 // CUPnPPrintingDevice::GetPrinter |
|
1558 // |
|
1559 //-------------------------------------------------------------------------------------------- |
|
1560 CUpnpDevice* CUPnPPrintingDevice::GetPrinter() |
|
1561 { |
|
1562 LOG("[CUPnPPrintingDevice::GetPrinter]"); |
|
1563 |
|
1564 if(iPrintingJob) |
|
1565 { |
|
1566 CUPPrinter* uaPrinter = iPrinterContainer->Printer(iPrintingJob->PrinterId()); |
|
1567 if (uaPrinter) |
|
1568 { |
|
1569 return uaPrinter->Device(); |
|
1570 } |
|
1571 } |
|
1572 return NULL; |
|
1573 } |
|
1574 |
|
1575 //-------------------------------------------------------------------------------------------- |
|
1576 // |
|
1577 // CUPnPPrintingDevice::ResetTimer |
|
1578 // |
|
1579 //-------------------------------------------------------------------------------------------- |
|
1580 void CUPnPPrintingDevice::ResetTimer() |
|
1581 { |
|
1582 LOG("[CUPnPPrintingDevice::ResetTimer]\t"); |
|
1583 |
|
1584 if(iPrinterTimer) |
|
1585 iPrinterTimer->Cancel(); |
|
1586 iStatusTimeout = EFalse; |
|
1587 } |
|
1588 |
|
1589 //-------------------------------------------------------------------------------------------- |
|
1590 // |
|
1591 // CUPnPPrintingDevice::ResetTimer |
|
1592 // |
|
1593 //-------------------------------------------------------------------------------------------- |
|
1594 void CUPnPPrintingDevice::StartTimer(TTimeIntervalMicroSeconds32 aDelay, |
|
1595 TTimeIntervalMicroSeconds32 anInterval, |
|
1596 TCallBack aCallBack) |
|
1597 { |
|
1598 LOG("[CUPnPPrintingDevice::StartTimer]\t"); |
|
1599 |
|
1600 ResetTimer(); |
|
1601 |
|
1602 iPrinterTimer->Start(aDelay, anInterval, aCallBack ); |
|
1603 |
|
1604 } |
|
1605 |
|
1606 // End of File |