|
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 CUPJobState class |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <e32math.h> |
|
20 |
|
21 #include "cupjobstate.h" |
|
22 #include "upconsts.h" |
|
23 #include "cupprintingjob.h" |
|
24 #include "cuplogger.h" |
|
25 |
|
26 //-------------------------------------------------------------------------------------------- |
|
27 // |
|
28 // CUPJobState::NewL |
|
29 // |
|
30 //-------------------------------------------------------------------------------------------- |
|
31 CUPJobState* CUPJobState::NewL() |
|
32 { |
|
33 CUPJobState *self = NewLC(); |
|
34 CleanupStack::Pop(); // self |
|
35 |
|
36 return self; |
|
37 } |
|
38 |
|
39 //-------------------------------------------------------------------------------------------- |
|
40 // |
|
41 // CUPJobState::NewLC |
|
42 // |
|
43 //-------------------------------------------------------------------------------------------- |
|
44 CUPJobState* CUPJobState::NewLC() |
|
45 { |
|
46 CUPJobState *self = new (ELeave) CUPJobState(); |
|
47 CleanupStack::PushL(self); |
|
48 self->ConstructL(); |
|
49 |
|
50 return self; |
|
51 } |
|
52 |
|
53 //-------------------------------------------------------------------------------------------- |
|
54 // |
|
55 // CUPJobState::ConstructL |
|
56 // |
|
57 //-------------------------------------------------------------------------------------------- |
|
58 void CUPJobState::ConstructL() |
|
59 { |
|
60 LOG("[CUPFileParser]\t ConstructL"); |
|
61 Init(); |
|
62 InitErrorValues(); |
|
63 } |
|
64 |
|
65 //-------------------------------------------------------------------------------------------- |
|
66 // |
|
67 // CUPJobState::CUPJobState |
|
68 // |
|
69 //-------------------------------------------------------------------------------------------- |
|
70 CUPJobState::~CUPJobState() |
|
71 { |
|
72 Init(); |
|
73 iErrorValues.Reset(); |
|
74 } |
|
75 |
|
76 //-------------------------------------------------------------------------------------------- |
|
77 // |
|
78 // CUPJobState::Init |
|
79 // |
|
80 //-------------------------------------------------------------------------------------------- |
|
81 void CUPJobState::Init() |
|
82 { |
|
83 iSheetsCompleted = KErrNotFound; |
|
84 iSheetsToPrint = 0; // cannot be negative for progress |
|
85 iId.Copy(KNullDesC8()); |
|
86 iReason = ENoMessage; |
|
87 iState = EStateUnknown; |
|
88 iActiveId.Copy(KNullDesC8()); |
|
89 iEndState.Init(); |
|
90 } |
|
91 |
|
92 //-------------------------------------------------------------------------------------------- |
|
93 // |
|
94 // CUPJobState::InitErrorValues |
|
95 // |
|
96 //-------------------------------------------------------------------------------------------- |
|
97 void CUPJobState::InitErrorValues() |
|
98 { |
|
99 TMapError err; |
|
100 |
|
101 err.iErrorCode = ENoMessage; |
|
102 err.iErrorString.Set(KUPnPStateNone); |
|
103 iErrorValues.Append(err); |
|
104 |
|
105 err.iErrorCode = EPbCheckPrinter; |
|
106 err.iErrorString.Set(KUPnPStateAttentionRequired); |
|
107 iErrorValues.Append(err); |
|
108 |
|
109 err.iErrorCode = EPbStatusErrorReasonPaperJam; |
|
110 err.iErrorString.Set(KUPnPStateMediaJam); |
|
111 iErrorValues.Append(err); |
|
112 |
|
113 err.iErrorCode = EPbCheckPrinter; |
|
114 err.iErrorString.Set(KUPnPStatePaused); |
|
115 iErrorValues.Append(err); |
|
116 |
|
117 err.iErrorCode = EPbStatusErrorReasonHardwareCoverOpen; |
|
118 err.iErrorString.Set(KUPnPStateDoorOpen); |
|
119 iErrorValues.Append(err); |
|
120 |
|
121 err.iErrorCode = EPbStatusErrorReasonPaperNearlyEmpty; |
|
122 err.iErrorString.Set(KUPnPStateMediaLow); |
|
123 iErrorValues.Append(err); |
|
124 |
|
125 err.iErrorCode = EPbStatusErrorReasonPaperEmpty; |
|
126 err.iErrorString.Set(KUPnPStateMediaEmpty); |
|
127 iErrorValues.Append(err); |
|
128 |
|
129 err.iErrorCode = ENoMessage; |
|
130 err.iErrorString.Set(KUPnPStateOutputAreaAlmostFull); |
|
131 iErrorValues.Append(err); |
|
132 |
|
133 err.iErrorCode = EPbCheckPrinter; |
|
134 err.iErrorString.Set(KUPnPStateOutputAreaFull); |
|
135 iErrorValues.Append(err); |
|
136 |
|
137 err.iErrorCode = EPbStatusErrorReasonInkLow; |
|
138 err.iErrorString.Set(KUPnPStateMarkerSupplyLow); |
|
139 iErrorValues.Append(err); |
|
140 |
|
141 err.iErrorCode = EPbStatusErrorReasonInkEmpty; |
|
142 err.iErrorString.Set(KUPnPStateMarkerSupplyEmpty); |
|
143 iErrorValues.Append(err); |
|
144 |
|
145 err.iErrorCode = EPbStatusErrorReasonInk; |
|
146 err.iErrorString.Set(KUPnPStateMarkerFailure); |
|
147 iErrorValues.Append(err); |
|
148 |
|
149 err.iErrorCode = EPbStatusErrorReasonPaperMedia; |
|
150 err.iErrorString.Set(KUPnPStateMediaChangeRequest); |
|
151 iErrorValues.Append(err); |
|
152 |
|
153 err.iErrorCode = EPbCheckPrinter; |
|
154 err.iErrorString.Set(KUPnPStateVendorDefined); |
|
155 iErrorValues.Append(err); |
|
156 |
|
157 err.iErrorCode = EPbStatusErrorReasonFile; |
|
158 err.iErrorString.Set(KUPnPJobStateCopies); |
|
159 iErrorValues.Append(err); |
|
160 |
|
161 err.iErrorCode = EPbStatusErrorReasonFile; |
|
162 err.iErrorString.Set(KUPnPJobStateSides); |
|
163 iErrorValues.Append(err); |
|
164 |
|
165 err.iErrorCode = EPbStatusErrorReasonFile; |
|
166 err.iErrorString.Set(KUPnPJobStateNumberUp); |
|
167 iErrorValues.Append(err); |
|
168 |
|
169 err.iErrorCode = EPbStatusErrorReasonFile; |
|
170 err.iErrorString.Set(KUPnPJobStateOrientationRequested); |
|
171 iErrorValues.Append(err); |
|
172 |
|
173 err.iErrorCode = EPbStatusErrorReasonFile; |
|
174 err.iErrorString.Set(KUPnPJobStateMediaSize); |
|
175 iErrorValues.Append(err); |
|
176 |
|
177 err.iErrorCode = EPbStatusErrorReasonFile; |
|
178 err.iErrorString.Set(KUPnPJobStateMediaType); |
|
179 iErrorValues.Append(err); |
|
180 |
|
181 err.iErrorCode = EPbStatusErrorReasonFile; |
|
182 err.iErrorString.Set(KUPnPJobStatePrintQuality); |
|
183 iErrorValues.Append(err); |
|
184 |
|
185 err.iErrorCode = EPbStatusErrorReasonFile; |
|
186 err.iErrorString.Set(KUPnPJobStateTextLayout); |
|
187 iErrorValues.Append(err); |
|
188 |
|
189 err.iErrorCode = EPbStatusErrorReasonFile; |
|
190 err.iErrorString.Set(KUPnPJobStateImageLayout); |
|
191 iErrorValues.Append(err); |
|
192 |
|
193 err.iErrorCode = EPbStatusErrorReasonFile; |
|
194 err.iErrorString.Set(KUPnPJobStateImageOrientation); |
|
195 iErrorValues.Append(err); |
|
196 |
|
197 err.iErrorCode = EPbStatusErrorReasonFile; |
|
198 err.iErrorString.Set(KUPnPJobStatePdlFidelity); |
|
199 iErrorValues.Append(err); |
|
200 |
|
201 err.iErrorCode = EPbStatusErrorReasonFile; |
|
202 err.iErrorString.Set(KUPnPJobStateFontFamily); |
|
203 iErrorValues.Append(err); |
|
204 |
|
205 err.iErrorCode = EPbStatusErrorReasonFile; |
|
206 err.iErrorString.Set(KUPnPJobStateFontSize); |
|
207 iErrorValues.Append(err); |
|
208 |
|
209 err.iErrorCode = EPbStatusErrorReasonFile; |
|
210 err.iErrorString.Set(KUPnPJobStateFormatError); |
|
211 iErrorValues.Append(err); |
|
212 |
|
213 err.iErrorCode = EPbStatusErrorReasonFile; |
|
214 err.iErrorString.Set(KUPnPJobStateHttpError); |
|
215 iErrorValues.Append(err); |
|
216 |
|
217 err.iErrorCode = EPbStatusErrorReasonHardware; |
|
218 err.iErrorString.Set(KUPnPJobStateHwError); |
|
219 iErrorValues.Append(err); |
|
220 |
|
221 err.iErrorCode = EPbStatusErrorReasonFile; |
|
222 err.iErrorString.Set(KUPnPJobStateObjectFailure); |
|
223 iErrorValues.Append(err); |
|
224 |
|
225 err.iErrorCode = EPbStatusErrorReasonFile; |
|
226 err.iErrorString.Set(KUPnPJobStateUriNotFound); |
|
227 iErrorValues.Append(err); |
|
228 |
|
229 } |
|
230 |
|
231 //-------------------------------------------------------------------------------------------- |
|
232 // |
|
233 // CUPJobState::GetErrorValue |
|
234 // |
|
235 //-------------------------------------------------------------------------------------------- |
|
236 TInt CUPJobState::GetErrorValue(const TDesC8& aError) |
|
237 { |
|
238 LOG81("[CUPJobState::GetErrorValue]\t for: %S", &aError); |
|
239 for (TInt i = 0; i < iErrorValues.Count();++i) |
|
240 { |
|
241 if(0 == aError.Compare(iErrorValues[i].iErrorString)) |
|
242 { |
|
243 // LOG1("[CUPJobState::GetErrorValue]\t returns: %d", iErrorValues[i].iErrorCode); |
|
244 return iErrorValues[i].iErrorCode; |
|
245 } |
|
246 } |
|
247 // LOG("[CUPJobState::GetErrorValue]\t returns: EPbCheckPrinter"); |
|
248 return EPbCheckPrinter; |
|
249 } |
|
250 |
|
251 //-------------------------------------------------------------------------------------------- |
|
252 // |
|
253 // CUPJobState::SetState |
|
254 // |
|
255 //-------------------------------------------------------------------------------------------- |
|
256 void CUPJobState::SetState(TUPnPState aState) |
|
257 { |
|
258 LOG1("[CUPJobState::SetState]\t %d", aState); |
|
259 |
|
260 if(iActiveId.Length() < 1) |
|
261 { |
|
262 iState = EStateUnknown; |
|
263 return; |
|
264 } |
|
265 |
|
266 // return if state is one of the terminating states |
|
267 if( EStateReady == iState || |
|
268 EPrinterStateStopped == iState || |
|
269 EStatePending == iState || |
|
270 EJobStateAborted == iState || |
|
271 EJobStateCanceled == iState ) |
|
272 return; |
|
273 |
|
274 switch ( aState ) |
|
275 { |
|
276 case EPrinterStateStopped: |
|
277 case EStatePending: |
|
278 case EJobStateAborted: |
|
279 case EJobStateCanceled: |
|
280 case EStateReady: |
|
281 Init(); |
|
282 iState = aState; |
|
283 break; |
|
284 case EStatePrinting: |
|
285 iState = aState; |
|
286 break; |
|
287 case EJobStateSuccessful: |
|
288 iState = EStatePrinting; |
|
289 break; |
|
290 default: |
|
291 if(0 == iId.Compare(ActiveId())) |
|
292 { |
|
293 if(SheetsToPrint() == SheetsCompleted()) |
|
294 iState = EStateReady; |
|
295 else if (EStateUnknown == iState) |
|
296 iState = EStatePrinting; |
|
297 } |
|
298 break; |
|
299 } |
|
300 } |
|
301 |
|
302 |
|
303 //-------------------------------------------------------------------------------------------- |
|
304 // |
|
305 // CUPJobState::State |
|
306 // |
|
307 //-------------------------------------------------------------------------------------------- |
|
308 TUPnPState CUPJobState::State() |
|
309 { |
|
310 // LOG1("[CUPJobState::State]\t : %d",iState); |
|
311 return iState; |
|
312 } |
|
313 |
|
314 //-------------------------------------------------------------------------------------------- |
|
315 // |
|
316 // CUPJobState::SetActiveId |
|
317 // |
|
318 //-------------------------------------------------------------------------------------------- |
|
319 void CUPJobState::SetActiveId(const TDesC8& aId) |
|
320 { |
|
321 Init(); |
|
322 iActiveId.Copy(aId); |
|
323 } |
|
324 |
|
325 //-------------------------------------------------------------------------------------------- |
|
326 // |
|
327 // CUPJobState::ActiveId |
|
328 // |
|
329 //-------------------------------------------------------------------------------------------- |
|
330 TPtrC8 CUPJobState::ActiveId() |
|
331 { |
|
332 return iActiveId; |
|
333 } |
|
334 |
|
335 //-------------------------------------------------------------------------------------------- |
|
336 // |
|
337 // CUPJobState::SetSheetsCompleted |
|
338 // |
|
339 //-------------------------------------------------------------------------------------------- |
|
340 void CUPJobState::SetSheetsCompleted(const TDesC8& aSheetsCompleted) |
|
341 { |
|
342 // LOG1("[CUPJobState::SetSheetsCompleted]\t - at the beginning SheetsCompleted(): %d",SheetsCompleted()); |
|
343 // LOG8S("[CUPJobState::SetSheetsCompleted]\t - aSheetsCompleted: ",aSheetsCompleted); |
|
344 |
|
345 if(EStateReady == State()) |
|
346 { |
|
347 iSheetsCompleted = SheetsToPrint(); |
|
348 LOG1("[CUPJobState::SetSheetsCompleted]\t - State ready, set SheetsToPrint(): %d",SheetsToPrint()); |
|
349 } |
|
350 else |
|
351 { |
|
352 TLex8 sheetsLex(aSheetsCompleted); |
|
353 //Should here be an check about return value of Val??? /TTP |
|
354 sheetsLex.Val(iSheetsCompleted); |
|
355 } |
|
356 LOG1("[CUPJobState::SetSheetsCompleted]\t - iSheetsCompleted: %d",SheetsCompleted()); |
|
357 } |
|
358 |
|
359 //-------------------------------------------------------------------------------------------- |
|
360 // |
|
361 // CUPJobState::SheetsCompleted |
|
362 // |
|
363 //-------------------------------------------------------------------------------------------- |
|
364 TInt CUPJobState::SheetsCompleted() |
|
365 { |
|
366 return iSheetsCompleted; |
|
367 } |
|
368 |
|
369 //-------------------------------------------------------------------------------------------- |
|
370 // |
|
371 // CUPJobState::SetReason |
|
372 // |
|
373 //-------------------------------------------------------------------------------------------- |
|
374 void CUPJobState::SetReason(TInt aReason) |
|
375 { |
|
376 iReason = aReason; |
|
377 } |
|
378 |
|
379 //-------------------------------------------------------------------------------------------- |
|
380 // |
|
381 // CUPJobState::Reason |
|
382 // |
|
383 //-------------------------------------------------------------------------------------------- |
|
384 TInt CUPJobState::Reason() |
|
385 { |
|
386 return iReason; |
|
387 } |
|
388 |
|
389 //-------------------------------------------------------------------------------------------- |
|
390 // |
|
391 // CUPJobState::SetJobList |
|
392 // |
|
393 //-------------------------------------------------------------------------------------------- |
|
394 TUPnPState CUPJobState::SetJobList(const TDesC8& aJobIdList) |
|
395 { |
|
396 TInt pos = PendingJobId(aJobIdList); |
|
397 if(1 < pos) |
|
398 SetState(EStatePending); |
|
399 else if (1 == pos) |
|
400 { |
|
401 iId = ActiveId(); |
|
402 SetState(EStatePrinting); |
|
403 } |
|
404 |
|
405 return State(); |
|
406 } |
|
407 |
|
408 //-------------------------------------------------------------------------------------------- |
|
409 // |
|
410 // CUPJobState::SetSheetsToPrint |
|
411 // |
|
412 //-------------------------------------------------------------------------------------------- |
|
413 void CUPJobState::SetSheetsToPrint(TInt aSheets) |
|
414 { |
|
415 LOG1("[CUPJobState::SetSheetsToPrint]\t aSheets\t = %d", aSheets); |
|
416 if(0 < aSheets) |
|
417 iSheetsToPrint = aSheets; |
|
418 } |
|
419 |
|
420 //-------------------------------------------------------------------------------------------- |
|
421 // |
|
422 // CUPJobState::SheetsToPrint |
|
423 // |
|
424 //-------------------------------------------------------------------------------------------- |
|
425 TInt CUPJobState::SheetsToPrint() |
|
426 { |
|
427 // LOG1("[CUPJobState::SheetsToPrint]\t iSheetsToPrint\t = %d", iSheetsToPrint); |
|
428 return iSheetsToPrint; |
|
429 } |
|
430 |
|
431 //-------------------------------------------------------------------------------------------- |
|
432 // |
|
433 // CUPJobState::Progress |
|
434 // |
|
435 //-------------------------------------------------------------------------------------------- |
|
436 TInt CUPJobState::Progress(TInt aSheets) |
|
437 { |
|
438 TInt percentage = 0; |
|
439 if(State() == EStateReady) |
|
440 percentage = 100; |
|
441 else if(0 < SheetsCompleted() && 0 < aSheets) |
|
442 percentage = (((SheetsCompleted() << 8) / aSheets) * 100) >> 8; |
|
443 |
|
444 // LOG1("[CUPJobState::Progress]\t SheetsCompleted()\t = %d", SheetsCompleted()); |
|
445 // LOG1("[CUPJobState::Progress]\t aSheets\t\t\t = %d", aSheets); |
|
446 LOG1("[CUPJobState::Progress]\t percentage\t\t\t = %d%%", percentage); |
|
447 |
|
448 return percentage; |
|
449 } |
|
450 |
|
451 //-------------------------------------------------------------------------------------------- |
|
452 // |
|
453 // CUPJobState::Progress |
|
454 // |
|
455 //-------------------------------------------------------------------------------------------- |
|
456 TInt CUPJobState::Progress() |
|
457 { |
|
458 return Progress(SheetsToPrint()); |
|
459 } |
|
460 |
|
461 //-------------------------------------------------------------------------------------------- |
|
462 // |
|
463 // CUPJobState::UpdateJobState |
|
464 // |
|
465 //-------------------------------------------------------------------------------------------- |
|
466 TUPnPState CUPJobState::UpdateJobState(const TDesC8& aPrinterState, const TDesC8& aReason, const TDesC8& aJobList, const TDesC8& aJobId, const TDesC8& aSheetsCompleted) |
|
467 { |
|
468 LOG81("[CUPJobState::UpdateJobState]\t active job: %S", &(ActiveId())); |
|
469 |
|
470 LOG81("[CUPJobState]\t - aPrinterState: %S", &aPrinterState); |
|
471 LOG81("[CUPJobState]\t - aReason: %S", &aReason); |
|
472 LOG81("[CUPJobState]\t - aJobList: %S", &aJobList); |
|
473 LOG81("[CUPJobState]\t - aJobId: %S", &aJobId); |
|
474 LOG81("[CUPJobState]\t - aSheetsCompleted: %S", &aSheetsCompleted); |
|
475 |
|
476 SetReason(GetErrorValue(aReason)); |
|
477 |
|
478 //Set sheets for progress |
|
479 SetSheetsCompleted(aSheetsCompleted); |
|
480 |
|
481 // If printer state stopped, no reason to continue |
|
482 if(KErrNotFound != aPrinterState.Find(KUPnPPrinterStateStopped())) |
|
483 { |
|
484 SetState(EPrinterStateStopped); |
|
485 return State(); |
|
486 } |
|
487 |
|
488 // If job is in the list, state is printing or pending. Else the job does not exist. |
|
489 SetJobList(aJobList); |
|
490 if(EStatePending == State()) |
|
491 { |
|
492 SetReason(EPbStatusErrorReasonHardwarePrinterBusy); |
|
493 } |
|
494 else if(State() == EStatePrinting && aJobId.Compare(ActiveId()) != 0 ) |
|
495 { |
|
496 LOG82("[CUPJobState::State]\t - Ready: iState: %d, aJobId; %S",iState, &aJobId); |
|
497 SetState(EStateReady); |
|
498 } |
|
499 |
|
500 return State(); |
|
501 } |
|
502 |
|
503 //// PRIVATE /// |
|
504 |
|
505 |
|
506 //-------------------------------------------------------------------------------------------- |
|
507 // |
|
508 // CUPJobState::CUPJobState |
|
509 // |
|
510 //-------------------------------------------------------------------------------------------- |
|
511 CUPJobState::CUPJobState() |
|
512 { |
|
513 } |
|
514 |
|
515 //-------------------------------------------------------------------------------------------- |
|
516 // |
|
517 // CUPJobState::PendingJobId |
|
518 // |
|
519 //-------------------------------------------------------------------------------------------- |
|
520 TInt CUPJobState::PendingJobId(const TDesC8& aJobIdList) |
|
521 { |
|
522 if(0 >= aJobIdList.Length()) |
|
523 return KErrNotFound; |
|
524 |
|
525 TInt count = 0; |
|
526 TLex8 list(aJobIdList); |
|
527 |
|
528 TLex8 idLex(ActiveId()); |
|
529 TInt activeId; |
|
530 if (idLex.Val(activeId) != KErrNone) |
|
531 { |
|
532 return KErrArgument; |
|
533 } |
|
534 |
|
535 while(!list.Eos() && count < 50) |
|
536 { |
|
537 ++count; |
|
538 TInt val = KErrNotFound; |
|
539 if(KErrNone == list.Val(val)) |
|
540 { |
|
541 if(activeId == val) |
|
542 return count; |
|
543 else |
|
544 list.Inc(); |
|
545 } |
|
546 } |
|
547 return KErrNotFound; |
|
548 } |
|
549 |
|
550 //-------------------------------------------------------------------------------------------- |
|
551 // |
|
552 // CUPJobState::ParseState |
|
553 // |
|
554 //-------------------------------------------------------------------------------------------- |
|
555 TUPnPState CUPJobState::ParseState(const TDesC8& aState) |
|
556 { |
|
557 if(KErrNotFound != aState.Find(KUPnPJobStateSuccessful())) |
|
558 return EJobStateSuccessful; |
|
559 if(KErrNotFound != aState.Find(KUPnPJobStateAborted())) |
|
560 return EJobStateAborted; |
|
561 if(KErrNotFound != aState.Find(KUPnPJobStateCanceled())) |
|
562 return EJobStateCanceled; |
|
563 if(KErrNotFound != aState.Find(KUPnPPrinterStateIdle())) |
|
564 return EPrinterStateIdle; |
|
565 if(KErrNotFound != aState.Find(KUPnPPrinterStateProcessing())) |
|
566 return EPrinterStateProcessing; |
|
567 if(KErrNotFound != aState.Find(KUPnPPrinterStateStopped())) |
|
568 return EPrinterStateStopped; |
|
569 |
|
570 return EStateUnknown; |
|
571 } |
|
572 |
|
573 //-------------------------------------------------------------------------------------------- |
|
574 // |
|
575 // CUPJobState::ParseJobEndStateL |
|
576 // |
|
577 //-------------------------------------------------------------------------------------------- |
|
578 TInt CUPJobState::ParseJobEndStateL(const TDesC8& aJobEndState) |
|
579 { |
|
580 // LOG("[CUPJobState::ParseJobEndState]\t"); |
|
581 iEndState.Init(); |
|
582 TInt res = KErrNotFound; |
|
583 |
|
584 // Return if no data |
|
585 if(1 > aJobEndState.Length()) |
|
586 return res; |
|
587 |
|
588 // Parse current job and state from JobEndState |
|
589 _LIT8(KSeparator, ","); |
|
590 |
|
591 RArray<TPtrC8> strings; |
|
592 CleanupClosePushL(strings); |
|
593 strings.Reset(); |
|
594 |
|
595 TPtrC8 ptr(aJobEndState); |
|
596 TInt pos = aJobEndState.Find(KSeparator()); |
|
597 while(KErrNotFound != pos) |
|
598 { |
|
599 strings.Append(ptr.Left(pos)); |
|
600 pos += KSeparator().Length(); |
|
601 ptr.Set(ptr.Right(ptr.Length() - pos)); |
|
602 |
|
603 pos = ptr.Find(KSeparator()); |
|
604 if(KErrNotFound == pos) |
|
605 strings.Append(ptr); |
|
606 } |
|
607 |
|
608 // Assign strings in member variables if current job's state |
|
609 if(1 <= strings.Count() && 0 == strings[0].Compare(ActiveId())) |
|
610 { |
|
611 if(1 <= strings.Count()) |
|
612 { |
|
613 iId.Copy(strings[0]); |
|
614 iEndState.iId.Set(iId); |
|
615 } |
|
616 if(2 <= strings.Count()) |
|
617 iEndState.iJobName.Set(strings[1]); |
|
618 if(3 <= strings.Count()) |
|
619 iEndState.iOriginator.Set(strings[2]); |
|
620 if(4 <= strings.Count()) |
|
621 { |
|
622 SetSheetsCompleted(strings[3]); |
|
623 iEndState.iSheets = SheetsCompleted(); |
|
624 } |
|
625 if(5 <= strings.Count()) |
|
626 iEndState.iState = ParseState(strings[4]); |
|
627 if(6 <= strings.Count()) |
|
628 iEndState.iReason = GetErrorValue(strings[5]); |
|
629 |
|
630 res = KErrNone; |
|
631 } |
|
632 CleanupStack::PopAndDestroy( &strings ); |
|
633 |
|
634 return res; |
|
635 |
|
636 } |
|
637 |
|
638 //-------------------------------------------------------------------------------------------- |
|
639 // |
|
640 // CUPJobState::PrinterStateUpdated |
|
641 // |
|
642 //-------------------------------------------------------------------------------------------- |
|
643 TUPnPState CUPJobState::PrinterStateUpdated( const TDesC8& aEvent ) |
|
644 { |
|
645 // If printer state not stopped, no reason to assign it |
|
646 if(KErrNotFound < aEvent.Find(KUPnPPrinterStateStopped())) |
|
647 { |
|
648 SetState(EPrinterStateStopped); |
|
649 } |
|
650 return State(); |
|
651 } |
|
652 |
|
653 //-------------------------------------------------------------------------------------------- |
|
654 // |
|
655 // CUPJobState::PrinterStateReasonsUpdated |
|
656 // |
|
657 //-------------------------------------------------------------------------------------------- |
|
658 TUPnPState CUPJobState::PrinterStateReasonsUpdated( const TDesC8& aEvent ) |
|
659 { |
|
660 SetReason(GetErrorValue(aEvent)); |
|
661 return State(); |
|
662 } |
|
663 |
|
664 //-------------------------------------------------------------------------------------------- |
|
665 // |
|
666 // CUPJobState::JobIdListUpdated |
|
667 // |
|
668 //-------------------------------------------------------------------------------------------- |
|
669 TUPnPState CUPJobState::JobIdListUpdated( const TDesC8& aEvent ) |
|
670 { |
|
671 //Check if pending |
|
672 SetJobList(aEvent); |
|
673 if(EStatePending == State()) |
|
674 { |
|
675 SetReason(EPbStatusErrorReasonHardwarePrinterBusy); |
|
676 } |
|
677 return State(); |
|
678 } |
|
679 |
|
680 //-------------------------------------------------------------------------------------------- |
|
681 // |
|
682 // CUPJobState::JobEndStateUpdated |
|
683 // |
|
684 //-------------------------------------------------------------------------------------------- |
|
685 TUPnPState CUPJobState::JobEndStateUpdatedL( const TDesC8& aEvent ) |
|
686 { |
|
687 // init id |
|
688 iId.Copy(KNullDesC8()); |
|
689 |
|
690 // Parse if contains data and for this job |
|
691 TInt res = ParseJobEndStateL(aEvent); |
|
692 if(KErrNotFound != res) |
|
693 { |
|
694 SetState(iEndState.iState); |
|
695 |
|
696 // if any abort state updates never received, let's wait the one concerning this case |
|
697 if(EJobStateAborted == iEndState.iState && iEndState.iAbortState) |
|
698 return EStatePrinting; |
|
699 } |
|
700 return State(); |
|
701 } |
|
702 |
|
703 //-------------------------------------------------------------------------------------------- |
|
704 // |
|
705 // CUPJobState::JobMediaSheetsCompletedUpdated |
|
706 // |
|
707 //-------------------------------------------------------------------------------------------- |
|
708 TUPnPState CUPJobState::JobMediaSheetsCompletedUpdated( const TDesC8& aEvent ) |
|
709 { |
|
710 JobMediaSheetsCompletedUpdated(iId, aEvent); |
|
711 return State(); |
|
712 } |
|
713 |
|
714 //-------------------------------------------------------------------------------------------- |
|
715 // |
|
716 // CUPJobState::JobMediaSheetsCompletedUpdated |
|
717 // |
|
718 //-------------------------------------------------------------------------------------------- |
|
719 TUPnPState CUPJobState::JobMediaSheetsCompletedUpdated(const TDesC8& aId, const TDesC8& aEvent ) |
|
720 { |
|
721 LOG82("[CUPJobState::JobMediaSheetsCompletedUpdated]\t - aId: %S aEvent: %S", &aId, &aEvent); |
|
722 |
|
723 // id matches to active id |
|
724 if(0 == aId.Compare(ActiveId())) |
|
725 { |
|
726 SetSheetsCompleted(aEvent); |
|
727 |
|
728 // -1 for unknown, 0 for pending or processing (or finished) |
|
729 if( (-1 == SheetsCompleted()) || (0 == SheetsCompleted()) ) |
|
730 { |
|
731 LOG81("[CUPJobState::JobMediaSheetsCompletedUpdated]\t - aId:%S\t",&aId); |
|
732 } |
|
733 else if (SheetsToPrint() == SheetsCompleted()) |
|
734 { |
|
735 LOG1("[CUPJobState::JobMediaSheetsCompletedUpdated]\t - state ready -> SheetsToPrint(): %d",SheetsToPrint()); |
|
736 SetState(EStateReady); |
|
737 } |
|
738 else |
|
739 { |
|
740 LOG1("[CUPJobState::JobMediaSheetsCompletedUpdated]\t - state printing -> SheetsToPrint(): %d",SheetsToPrint()); |
|
741 SetState(EStatePrinting); |
|
742 } |
|
743 } |
|
744 |
|
745 return State(); |
|
746 } |
|
747 |
|
748 //-------------------------------------------------------------------------------------------- |
|
749 // |
|
750 // CUPJobState::ContentCompleteListUpdated |
|
751 // |
|
752 //-------------------------------------------------------------------------------------------- |
|
753 TUPnPState CUPJobState::ContentCompleteListUpdated( const TDesC8& /*aEvent*/ ) |
|
754 { |
|
755 return State(); |
|
756 } |
|
757 |
|
758 //-------------------------------------------------------------------------------------------- |
|
759 // |
|
760 // CUPJobState::JobAbortStateUpdated |
|
761 // |
|
762 //-------------------------------------------------------------------------------------------- |
|
763 TUPnPState CUPJobState::JobAbortStateUpdatedL( const TDesC8& aEvent ) |
|
764 { |
|
765 // Mark flag as true that any abort state messages never received |
|
766 iEndState.iAbortState = ETrue; |
|
767 |
|
768 // Parse if contains data and for this job |
|
769 TInt res = ParseJobEndStateL(aEvent); |
|
770 if(KErrNotFound != res) |
|
771 { |
|
772 SetReason(iEndState.iReason); |
|
773 SetState(iEndState.iState); |
|
774 } |
|
775 |
|
776 return State(); |
|
777 } |
|
778 |
|
779 // End of File |