|
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 CPrinterControlPoint class |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <f32file.h> |
|
20 #include <in_sock.h> |
|
21 #include <upnpservice.h> |
|
22 #include <upnpdevice.h> |
|
23 #include <upnpaction.h> |
|
24 #include <upnphttpmessagefactory.h> |
|
25 |
|
26 #include "cuplogger.h" |
|
27 #include "cprintercontrolpoint.h" |
|
28 #include "mpcpobserver.h" |
|
29 |
|
30 // CONSTANTS |
|
31 #define KMaxCancelReqs 100 |
|
32 |
|
33 // ----------------------------------------------------------------------------- |
|
34 // CPrinterControlPoint::NewL |
|
35 // Two-phased constructor |
|
36 // ----------------------------------------------------------------------------- |
|
37 // |
|
38 EXPORT_C CPrinterControlPoint* CPrinterControlPoint::NewL(MPCPObserver& aPCPObserver) |
|
39 { |
|
40 LOG("[CPrinterControlPoint] \tCPrinterControlPoint::NewL"); |
|
41 CPrinterControlPoint* self = new (ELeave) CPrinterControlPoint( aPCPObserver); |
|
42 CleanupStack::PushL( self ); |
|
43 self -> ConstructL( ); |
|
44 CleanupStack::Pop( self ); |
|
45 return self; |
|
46 } |
|
47 |
|
48 // ----------------------------------------------------------------------------- |
|
49 // CPrinterControlPoint::CPrinterControlPoint |
|
50 // C++ default constructor |
|
51 // ----------------------------------------------------------------------------- |
|
52 // |
|
53 CPrinterControlPoint::CPrinterControlPoint( MPCPObserver& aPCPObserver) |
|
54 : CUpnpControlPoint(), iPCPObserver( aPCPObserver ) |
|
55 { |
|
56 } |
|
57 |
|
58 |
|
59 // ----------------------------------------------------------------------------- |
|
60 // CPrinterControlPoint::ConstructL |
|
61 // Two-phased constructor |
|
62 // ----------------------------------------------------------------------------- |
|
63 // |
|
64 void CPrinterControlPoint::ConstructL() |
|
65 { |
|
66 LOG("[CPrinterControlPoint] \tCPrinterControlPoint::ConstructL"); |
|
67 _LIT8( KPrinter, "Printer:1" ); |
|
68 |
|
69 // Base class ConstructL |
|
70 CUpnpControlPoint::ConstructL( KPrinter()); |
|
71 |
|
72 // Share Xhtml folder (create if necessary) |
|
73 RFs fsSession; |
|
74 User::LeaveIfError( fsSession.Connect() ); |
|
75 CleanupClosePushL( fsSession ); |
|
76 TInt err = fsSession.MkDirAll( KUPnPXhtmlPath() ); |
|
77 if (err != KErrNone && err != KErrAlreadyExists) |
|
78 { |
|
79 User::Leave(err); |
|
80 } |
|
81 CleanupStack::PopAndDestroy(&fsSession); |
|
82 |
|
83 iJobStateEvents = NULL; |
|
84 |
|
85 // Start printer search |
|
86 TPtrC8 device_ptr; |
|
87 device_ptr.Set( KPrinterDevice ); |
|
88 SearchL( device_ptr ); |
|
89 |
|
90 } |
|
91 |
|
92 |
|
93 // ----------------------------------------------------------------------------- |
|
94 // CPrinterControlPoint::~CPrinterControlPoint |
|
95 // C++ default destructor |
|
96 // ----------------------------------------------------------------------------- |
|
97 // |
|
98 EXPORT_C CPrinterControlPoint::~CPrinterControlPoint() |
|
99 { |
|
100 LOG("[CPrinterControlPoint] \tCPrinterControlPoint::~CPrinterControlPoint()"); |
|
101 iCancelledJobSIDs.Close(); |
|
102 |
|
103 if(iJobStateEvents) |
|
104 { |
|
105 delete iJobStateEvents; |
|
106 } |
|
107 } |
|
108 |
|
109 // ----------------------------------------------------------------------------- |
|
110 // CPrinterControlPoint::CreateJobL |
|
111 // Create printer job |
|
112 // ----------------------------------------------------------------------------- |
|
113 // |
|
114 EXPORT_C TInt CPrinterControlPoint::CreateJobL( CUpnpDevice* aPrinter, const TDesC8& aPrintFile, |
|
115 const TDesC8& aUserName, const TDesC8& aCopies, const TDesC8& aSides, |
|
116 const TDesC8& aNumberUp, const TDesC8& aOrientationRequest, const TDesC8& aMediaSize, |
|
117 const TDesC8& aMediaType, const TDesC8& aPrintQuality, TBool aPrintBasic ) |
|
118 { |
|
119 LOG("[CPrinterControlPoint] \tCPrinterControlPoint::CreateJobL"); |
|
120 |
|
121 if(!aPrinter) |
|
122 { |
|
123 User::Leave(KErrArgument); |
|
124 } |
|
125 |
|
126 if(iJobStateEvents) |
|
127 { |
|
128 iJobStateEvents->InitL(); |
|
129 } |
|
130 else |
|
131 { |
|
132 iJobStateEvents = CJobStateEvents::NewL(); |
|
133 } |
|
134 |
|
135 // Set printer as authorized device |
|
136 // - remove the previous printer address from allowed list |
|
137 // - add the current printer address to allowed list |
|
138 |
|
139 TBuf8<20> logStr; |
|
140 CUpnpHttpMessage::AddrOutput(aPrinter->Address(), logStr); |
|
141 LOG81("[CPrinterControlPoint::CreateJobL]/t Printer address: %S", &logStr); |
|
142 |
|
143 // Check services |
|
144 TPrintService serviceType; |
|
145 CUpnpService* service = GetServiceFromDevice( aPrinter, serviceType ); |
|
146 |
|
147 |
|
148 if (serviceType == EServiceNone) |
|
149 { |
|
150 User::Leave(KErrNotSupported); |
|
151 } |
|
152 |
|
153 if (aPrintBasic) |
|
154 { |
|
155 // Force to use PrintBasic:1 |
|
156 serviceType = EPrintBasic; |
|
157 } |
|
158 |
|
159 // PrintBasic:1 or PrintEnhanced:1 supported |
|
160 SubscribeL( service ); |
|
161 CUpnpAction* action; |
|
162 |
|
163 // Create action according to service type |
|
164 |
|
165 if (serviceType == EPrintEnhanced) |
|
166 { |
|
167 LOG("[CPrinterControlPoint] \t -PrintEnhanced:1 - CreateJobV2"); |
|
168 action = service->CreateActionLC( KCreateJobV2 ); |
|
169 } |
|
170 |
|
171 else // serviceType == EPrintBasic |
|
172 { |
|
173 LOG("[CPrinterControlPoint] \t -PrintBasic:1 - CreateJob"); |
|
174 action = service->CreateActionLC( KCreateJob() ); |
|
175 } |
|
176 |
|
177 User::LeaveIfNull(action); |
|
178 |
|
179 // Common arguments for both action types |
|
180 User::LeaveIfError(action -> SetArgumentL( KJobName, aPrintFile )); |
|
181 User::LeaveIfError(action -> SetArgumentL( KUserName, aUserName)); |
|
182 User::LeaveIfError(action -> SetArgumentL( KDocFormat, KUPnPDocFormat() )); |
|
183 User::LeaveIfError(action -> SetArgumentL( KCopies, aCopies )); |
|
184 User::LeaveIfError(action -> SetArgumentL( KSides, aSides )); |
|
185 User::LeaveIfError(action -> SetArgumentL( KNumberUp, aNumberUp )); |
|
186 User::LeaveIfError(action -> SetArgumentL( KOrientationRequest, aOrientationRequest )); |
|
187 User::LeaveIfError(action -> SetArgumentL( KSize, aMediaSize )); |
|
188 User::LeaveIfError(action -> SetArgumentL( KType, aMediaType )); |
|
189 User::LeaveIfError(action -> SetArgumentL( KQuality, aPrintQuality )); |
|
190 |
|
191 if (serviceType == EPrintEnhanced) |
|
192 { |
|
193 // Fill in the rest arguments |
|
194 User::LeaveIfError(action->SetArgumentL( KCriticalAttributes, KNullDesC8() )); |
|
195 } |
|
196 |
|
197 // Send action |
|
198 SendL( action ); |
|
199 |
|
200 // return session id |
|
201 TInt sessionId = action->SessionId(); |
|
202 CleanupStack::Pop(); // action |
|
203 return sessionId; |
|
204 } |
|
205 |
|
206 // ----------------------------------------------------------------------------- |
|
207 // CPrinterControlPoint::PrintingFinishedL |
|
208 // ----------------------------------------------------------------------------- |
|
209 // |
|
210 EXPORT_C void CPrinterControlPoint::PrintingFinishedL( CUpnpDevice* aPrinter ) |
|
211 { |
|
212 |
|
213 LOG("[CPrinterControlPoint::PrintingFinishedL] \t"); |
|
214 |
|
215 // Check services |
|
216 TPrintService serviceType; |
|
217 CUpnpService* service = GetServiceFromDevice( aPrinter, serviceType ); |
|
218 |
|
219 if (serviceType == EServiceNone) |
|
220 { |
|
221 User::Leave(KErrNotSupported); |
|
222 } |
|
223 |
|
224 // Service is PrintBasic:1 or PrintEnhanced:1 - Unsubscribe |
|
225 UnsubscribeL(service); |
|
226 |
|
227 LOG("[CPrinterControlPoint::PrintingFinishedL] \t - unsubscribed... ...deleting event"); |
|
228 |
|
229 // init job state events |
|
230 if ( iJobStateEvents ) |
|
231 { |
|
232 iJobStateEvents->InitL(); |
|
233 } |
|
234 // Remove last printer address from allowed list |
|
235 |
|
236 LOG("[CPrinterControlPoint::PrintingFinishedL] \t - out"); |
|
237 } |
|
238 |
|
239 |
|
240 |
|
241 // ----------------------------------------------------------------------------- |
|
242 // CPrinterControlPoint::CancelJobL |
|
243 // Cancel printer job |
|
244 // ----------------------------------------------------------------------------- |
|
245 // |
|
246 EXPORT_C void CPrinterControlPoint::CancelJobL( CUpnpDevice* aPrinter, |
|
247 const TDesC8& aJobId ) |
|
248 { |
|
249 |
|
250 LOG81("[CPrinterControlPoint] \tCPrinterControlPoint::CancelJobL %S", &aJobId); |
|
251 |
|
252 // Check services |
|
253 TPrintService serviceType; |
|
254 CUpnpService* service = GetServiceFromDevice( aPrinter, serviceType ); |
|
255 |
|
256 if (serviceType == EServiceNone) |
|
257 { |
|
258 User::Leave(KErrNotSupported); |
|
259 } |
|
260 |
|
261 // Service is PrintBasic:1 or PrintEnhanced:1 |
|
262 DoCancelJobL(*service, aJobId); |
|
263 } |
|
264 |
|
265 // ----------------------------------------------------------------------------- |
|
266 // CPrinterControlPoint::CancelJobL |
|
267 // Cancel printer job by session id |
|
268 // ----------------------------------------------------------------------------- |
|
269 // |
|
270 EXPORT_C void CPrinterControlPoint::CancelJobL( const TInt aSessionId ) |
|
271 { |
|
272 |
|
273 LOG1("[CPrinterControlPoint::CancelJobL] \t by session id %d", aSessionId); |
|
274 |
|
275 // Add id to cancelled jobs - nothing else to do at this point |
|
276 // Actual cancelling is done when a message with this session id and job id is received from printer |
|
277 iCancelledJobSIDs.AppendL(aSessionId); |
|
278 |
|
279 // If number of pending cancel request exceeds KMaxCancelReqs delete the oldest request |
|
280 if (iCancelledJobSIDs.Count() > KMaxCancelReqs) |
|
281 { |
|
282 iCancelledJobSIDs.Remove(0); |
|
283 } |
|
284 |
|
285 |
|
286 } |
|
287 |
|
288 |
|
289 // ----------------------------------------------------------------------------- |
|
290 // CPrinterControlPoint::GetPrinterAttributesL |
|
291 // |
|
292 // ----------------------------------------------------------------------------- |
|
293 // |
|
294 EXPORT_C void CPrinterControlPoint::GetPrinterAttributesL( CUpnpDevice* aPrinter ) |
|
295 { |
|
296 |
|
297 LOG("[CPrinterControlPoint::GetPrinterAttributesL]"); |
|
298 |
|
299 // Check services |
|
300 TPrintService serviceType; |
|
301 CUpnpService* service = GetServiceFromDevice( aPrinter, serviceType ); |
|
302 |
|
303 if (serviceType == EServiceNone) |
|
304 { |
|
305 User::Leave(KErrNotSupported); |
|
306 } |
|
307 |
|
308 if( serviceType == EPrintBasic ) |
|
309 { |
|
310 CUpnpAction* action = service -> CreateActionLC( KGetPrinterAttr ); |
|
311 User::LeaveIfNull(action); |
|
312 SendL( action ); |
|
313 CleanupStack::Pop(); // action |
|
314 } |
|
315 |
|
316 if( serviceType == EPrintEnhanced ) |
|
317 { |
|
318 CUpnpAction* action = service -> CreateActionLC( KGetPrinterAttrV2 ); |
|
319 User::LeaveIfNull(action); |
|
320 SendL( action ); |
|
321 CleanupStack::Pop(); // action |
|
322 } |
|
323 |
|
324 } |
|
325 |
|
326 // ----------------------------------------------------------------------------- |
|
327 // CPrinterControlPoint::GetMarginsL |
|
328 // |
|
329 // ----------------------------------------------------------------------------- |
|
330 // |
|
331 EXPORT_C void CPrinterControlPoint::GetMarginsL( CUpnpDevice* aPrinter, const TDesC8& aMediaSize, const TDesC8& aMediaType ) |
|
332 { |
|
333 |
|
334 LOG("[CPrinterControlPoint::GetMarginsL]"); |
|
335 |
|
336 // Check services |
|
337 TPrintService serviceType; |
|
338 CUpnpService* service = GetServiceFromDevice( aPrinter, serviceType ); |
|
339 |
|
340 if( serviceType == EPrintEnhanced ) |
|
341 { |
|
342 CUpnpAction* action = service -> CreateActionLC( KGetMargins ); |
|
343 User::LeaveIfNull(action); |
|
344 User::LeaveIfError(action -> SetArgumentL( KSize, aMediaSize )); |
|
345 User::LeaveIfError(action -> SetArgumentL( KType, aMediaType)); |
|
346 SendL( action ); |
|
347 CleanupStack::Pop(); // action |
|
348 } |
|
349 else |
|
350 { |
|
351 User::Leave(KErrNotSupported); |
|
352 } |
|
353 |
|
354 } |
|
355 |
|
356 // ----------------------------------------------------------------------------- |
|
357 // CPrinterControlPoint::GetMarginsL |
|
358 // |
|
359 // ----------------------------------------------------------------------------- |
|
360 // |
|
361 EXPORT_C void CPrinterControlPoint::GetMediaListL( CUpnpDevice* aPrinter, const TDesC8& aMediaSize, const TDesC8& aMediaType ) |
|
362 { |
|
363 |
|
364 LOG("[CPrinterControlPoint::GetMediaListL]"); |
|
365 |
|
366 // Check services |
|
367 TPrintService serviceType; |
|
368 CUpnpService* service = GetServiceFromDevice( aPrinter, serviceType ); |
|
369 |
|
370 if( serviceType == EPrintEnhanced ) |
|
371 { |
|
372 CUpnpAction* action = service -> CreateActionLC( KGetMediaList ); |
|
373 User::LeaveIfNull(action); |
|
374 User::LeaveIfError(action -> SetArgumentL( KSize, aMediaSize )); |
|
375 User::LeaveIfError(action -> SetArgumentL( KType, aMediaType)); |
|
376 SendL( action ); |
|
377 CleanupStack::Pop(); // action |
|
378 } |
|
379 else |
|
380 { |
|
381 User::Leave(KErrNotSupported); |
|
382 } |
|
383 |
|
384 } |
|
385 |
|
386 |
|
387 // ----------------------------------------------------------------------------- |
|
388 // CPrinterControlPoint::GetJobAttributesL |
|
389 // |
|
390 // ----------------------------------------------------------------------------- |
|
391 // |
|
392 EXPORT_C void CPrinterControlPoint::GetJobAttributesL( CUpnpDevice* aPrinter, |
|
393 const TDesC8& aJobId ) |
|
394 { |
|
395 |
|
396 LOG("[CPrinterControlPoint::GetJobAttributesL]"); |
|
397 |
|
398 // Check services |
|
399 TPrintService serviceType; |
|
400 CUpnpService* service = GetServiceFromDevice( aPrinter, serviceType ); |
|
401 |
|
402 if (serviceType == EServiceNone) |
|
403 { |
|
404 User::Leave(KErrNotSupported); |
|
405 } |
|
406 |
|
407 CUpnpAction* action = service -> CreateActionLC( KGetJobAttr ); |
|
408 User::LeaveIfNull(action); |
|
409 User::LeaveIfError(action -> SetArgumentL( KJobId, aJobId )); |
|
410 SendL( action ); |
|
411 CleanupStack::Pop(); // action |
|
412 |
|
413 } |
|
414 |
|
415 |
|
416 // ----------------------------------------------------------------------------- |
|
417 // CPrinterControlPoint::StateUpdatedL |
|
418 // From ControlPoint |
|
419 // ----------------------------------------------------------------------------- |
|
420 // |
|
421 EXPORT_C void CPrinterControlPoint::StateUpdatedL( CUpnpService* aService ) |
|
422 { |
|
423 // Seven evented state variables (see PrintEnhanced:1 and PrintBasic:1 specification for details): |
|
424 // PrinterState, PrinterStateReasons, JobIdList, JobEndState, |
|
425 // JobMediaSheetsConpleted, JobAbortState and ContentCompleteList |
|
426 |
|
427 // JobEndState == JobId,JobName,JobOriginatingUser, |
|
428 // JobMediaSheetsConpleted,job-completion-state |
|
429 |
|
430 LOG("[CPrinterControlPoint::StateUpdatedL]"); |
|
431 |
|
432 User::LeaveIfNull(aService); |
|
433 |
|
434 JobStateLog(aService); |
|
435 |
|
436 CUpnpStateVariable* prntState = aService->StateVariable( KPrinterState() ); |
|
437 CUpnpStateVariable* prntStateReasons = aService->StateVariable( KPrinterStateReasons() ); |
|
438 CUpnpStateVariable* jobIdList = aService->StateVariable( KJobIdList() ); |
|
439 CUpnpStateVariable* jobEndState = aService->StateVariable( KJobEndState() ); |
|
440 CUpnpStateVariable* sheets = aService->StateVariable( KSheetsCompleted() ); |
|
441 |
|
442 // The next ones are supported only in PrintEnhanced:1 |
|
443 CUpnpStateVariable* jobAbortState = aService->StateVariable( KJobAbortState() ); |
|
444 CUpnpStateVariable* contentCompList = aService->StateVariable( KContentCompleteList() ); |
|
445 |
|
446 if ( iJobStateEvents ) |
|
447 { |
|
448 if( prntState ) |
|
449 { |
|
450 TPtrC8 ptr = RemoveTags( prntState->Value()); |
|
451 if(iJobStateEvents->ChangedEventL(ptr, CJobStateEvents::EPrinterState)) |
|
452 iPCPObserver.PrinterStateUpdated( ptr ); |
|
453 } |
|
454 if ( prntStateReasons ) |
|
455 { |
|
456 TPtrC8 ptr = RemoveTags( prntStateReasons->Value()); |
|
457 if(iJobStateEvents->ChangedEventL(ptr, CJobStateEvents::EPrinterStateReasons)) |
|
458 iPCPObserver.PrinterStateReasonsUpdated( ptr ); |
|
459 } |
|
460 |
|
461 if ( jobIdList ) |
|
462 { |
|
463 TPtrC8 ptr = RemoveTags( jobIdList->Value()); |
|
464 if(iJobStateEvents->ChangedEventL( ptr, CJobStateEvents::EJobIdList)) |
|
465 iPCPObserver.JobIdListUpdated( ptr ); |
|
466 } |
|
467 |
|
468 if ( jobEndState ) |
|
469 { |
|
470 TPtrC8 ptr = RemoveTags( jobEndState->Value()); |
|
471 if(iJobStateEvents->ChangedEventL( ptr, CJobStateEvents::EJobEndState)) |
|
472 iPCPObserver.JobEndStateUpdated( ptr ); |
|
473 } |
|
474 |
|
475 if ( sheets ) |
|
476 { |
|
477 TPtrC8 ptr = RemoveTags( sheets->Value()); |
|
478 if(iJobStateEvents->ChangedEventL(ptr, CJobStateEvents::EJobMediaSheetsCompleted)) |
|
479 iPCPObserver.JobMediaSheetsCompletedUpdated( ptr ); |
|
480 } |
|
481 |
|
482 if ( jobAbortState ) |
|
483 { |
|
484 TPtrC8 ptr = RemoveTags( jobAbortState->Value()); |
|
485 if(iJobStateEvents->ChangedEventL(ptr, CJobStateEvents::EContentCompleteList)) |
|
486 iPCPObserver.JobAbortStateUpdated( ptr ); |
|
487 } |
|
488 |
|
489 if ( contentCompList ) |
|
490 { |
|
491 TPtrC8 ptr = RemoveTags( contentCompList->Value()); |
|
492 if(iJobStateEvents->ChangedEventL( ptr, CJobStateEvents::EJobAbortState)) |
|
493 iPCPObserver.ContentCompleteListUpdated( ptr ); |
|
494 } |
|
495 } |
|
496 } |
|
497 |
|
498 // ----------------------------------------------------------------------------- |
|
499 // CPrinterControlPoint::DeviceDiscoveredL |
|
500 // ----------------------------------------------------------------------------- |
|
501 // |
|
502 EXPORT_C void CPrinterControlPoint::DeviceDiscoveredL( CUpnpDevice* aDevice) |
|
503 { |
|
504 LOG("[CPrinterControlPoint::DeviceDiscoveredL]"); |
|
505 iPCPObserver.DeviceDiscoveredL( aDevice ); |
|
506 } |
|
507 |
|
508 |
|
509 // ----------------------------------------------------------------------------- |
|
510 // CPrinterControlPoint::DeviceDisappearedL |
|
511 // ----------------------------------------------------------------------------- |
|
512 // |
|
513 EXPORT_C void CPrinterControlPoint::DeviceDisappearedL( CUpnpDevice* aDevice ) |
|
514 { |
|
515 LOG("[CPrinterControlPoint::DeviceDisappearedL]"); |
|
516 iPCPObserver.DeviceDisappeared( aDevice ); |
|
517 } |
|
518 |
|
519 // ----------------------------------------------------------------------------- |
|
520 // CPrinterControlPoint::ActionResponseReceivedL |
|
521 // ----------------------------------------------------------------------------- |
|
522 // |
|
523 EXPORT_C void CPrinterControlPoint::ActionResponseReceivedL( CUpnpAction* aAction ) |
|
524 { |
|
525 User::LeaveIfNull(aAction); |
|
526 |
|
527 LOG8S("[CPrinterControlPoint::ActionResponseReceivedL]\t - action: ", aAction->Name()); |
|
528 |
|
529 // First check out for pending cancel responses (ie. cancel requestes with session id) |
|
530 TInt sessionId = aAction->SessionId(); |
|
531 TInt index = iCancelledJobSIDs.Find(sessionId); |
|
532 |
|
533 if ( index >= 0 ) |
|
534 { |
|
535 // Cancel requested for this session's job |
|
536 const TDesC8& jobId = aAction->ArgumentValue( KJobId() ); |
|
537 |
|
538 if (jobId.Length() > 0) |
|
539 { |
|
540 LOG("[CPrinterControlPoint::ActionResponseReceivedL] \t - Executing session id based canceling"); |
|
541 DoCancelJobL( aAction->Service(), jobId); |
|
542 |
|
543 // Remove "queued" cancel job's session id from array |
|
544 iCancelledJobSIDs.Remove(index); |
|
545 |
|
546 // No need to handle create job responses for this job id since it was canceled |
|
547 if(( aAction->Name().Compare( KCreateJob ) == 0 ) || |
|
548 ( aAction->Name().Compare( KCreateURIJob ) == 0)) |
|
549 { |
|
550 return; |
|
551 } |
|
552 } |
|
553 } |
|
554 |
|
555 TInt err = KErrNone; |
|
556 if( EHttp200Ok != aAction->Error() ) |
|
557 { |
|
558 err = aAction->Error(); |
|
559 } |
|
560 |
|
561 // Check CreateJobResponse |
|
562 if( aAction->Name().Compare( KCreateJob ) == 0 || aAction->Name().Compare( KCreateJobV2 ) == 0 ) |
|
563 { |
|
564 if( KErrNone == err ) |
|
565 { |
|
566 const TDesC8& jobName = aAction->ArgumentValue( KJobName() ); |
|
567 const TDesC8& dataSinkUrl = aAction->ArgumentValue( KDataSink() ); |
|
568 |
|
569 // Send XHTML-print data (print data) via HTTP POST |
|
570 |
|
571 LOG("[CPrinterControlPoint] \t - Sending XHTML-print data via HTTP POST"); |
|
572 TInetAddr addr; |
|
573 CUpnpHttpMessage::AddrInput(addr, DataSinkUrlAddress( dataSinkUrl )); |
|
574 addr.SetPort( DataSinkUrlPort( dataSinkUrl ) ); |
|
575 |
|
576 CUpnpHttpMessage* printDataMessage; |
|
577 //CUpnpHttpMessage* printPictureMessage; |
|
578 |
|
579 |
|
580 printDataMessage = RUpnpHttpMessageFactory::HttpPostL( addr, DataSinkUrlPath( dataSinkUrl ) ); |
|
581 |
|
582 //printPictureMessage = RUpnpHttpMessageFactory::HttpPostL( addr, DataSinkUrlPath( dataSinkUrl ) ); |
|
583 |
|
584 TFileName8 filePath; |
|
585 filePath.Copy( KUPnPXhtmlPath() ); |
|
586 filePath.Append(jobName); |
|
587 printDataMessage->SetOutFilenameL( filePath ); |
|
588 |
|
589 TRAP(err, SendL( printDataMessage )); |
|
590 |
|
591 } |
|
592 |
|
593 iPCPObserver.CreateJobResponse( aAction, err ); |
|
594 |
|
595 |
|
596 LOG1("[CPrinterControlPoint] \t - HTTP POST returns: %d", err); |
|
597 } |
|
598 else if( aAction->Name().Compare( KCreateURIJob ) == 0 ) |
|
599 { |
|
600 iPCPObserver.CreateJobResponse( aAction, err ); |
|
601 } |
|
602 else if( aAction->Name().Compare( KCancelJob ) == 0 ) |
|
603 { |
|
604 iPCPObserver.CancelJobResponse( aAction, err ); |
|
605 } |
|
606 else if( aAction->Name().Compare( KGetPrinterAttr ) == 0 ) |
|
607 { |
|
608 iPCPObserver.GetPrinterAttributesResponse( aAction, err ); |
|
609 } |
|
610 else if( aAction->Name().Compare( KGetPrinterAttrV2 ) == 0 ) |
|
611 { |
|
612 iPCPObserver.GetPrinterAttributesResponse( aAction, err ); |
|
613 } |
|
614 else if( aAction->Name().Compare( KGetJobAttr ) == 0 ) |
|
615 { |
|
616 iPCPObserver.GetJobAttributesResponse( aAction, err ); |
|
617 } |
|
618 else if( aAction->Name().Compare( KGetMargins ) == 0 ) |
|
619 { |
|
620 iPCPObserver.GetMarginsResponse( aAction, err ); |
|
621 } |
|
622 else if( aAction->Name().Compare( KGetMediaList ) == 0 ) |
|
623 { |
|
624 iPCPObserver.GetMediaListResponse( aAction, err ); |
|
625 } |
|
626 else |
|
627 { |
|
628 //to avoid lint error |
|
629 } |
|
630 |
|
631 } |
|
632 |
|
633 // ----------------------------------------------------------------------------- |
|
634 // CPrinterControlPoint::HttpResponseReceivedL |
|
635 // ----------------------------------------------------------------------------- |
|
636 // |
|
637 EXPORT_C void CPrinterControlPoint::HttpResponseReceivedL( |
|
638 CUpnpHttpMessage* aMessage ) |
|
639 { |
|
640 LOG("[CPrinterControlPoint::HttpResponseReceivedL] \t"); |
|
641 if(aMessage) |
|
642 { |
|
643 LOG1( "[CPrinterControlPoint] \t - HTTP Response: %d", aMessage->Error() ); |
|
644 } |
|
645 } |
|
646 |
|
647 // private functions |
|
648 |
|
649 // ----------------------------------------------------------------------------- |
|
650 // CPrinterControlPoint::GetServiceFromDevice |
|
651 // ----------------------------------------------------------------------------- |
|
652 // |
|
653 CUpnpService* CPrinterControlPoint::GetServiceFromDevice( CUpnpDevice* aPrinter, TPrintService& aService ) |
|
654 { |
|
655 LOG("[CPrinterControlPoint::GetServiceFromDevice]"); |
|
656 CUpnpService* service = NULL; |
|
657 aService = EServiceNone; |
|
658 |
|
659 if(!aPrinter) |
|
660 { |
|
661 return service; |
|
662 } |
|
663 |
|
664 const RPointerArray<CUpnpDevice>& devices = DeviceList(); |
|
665 |
|
666 //Search of printer device |
|
667 for( TInt i = 0; i < devices.Count(); i++ ) |
|
668 { |
|
669 if( devices[i]->DeviceType().Compare( aPrinter->DeviceType() ) == 0 && |
|
670 devices[i]->Uuid().Compare( aPrinter->Uuid() ) == 0 ) |
|
671 { |
|
672 // Printer found - search of services |
|
673 RPointerArray<CUpnpService>& services = devices[i]->ServiceList(); |
|
674 |
|
675 for( TInt j = 0; j < services.Count(); j++ ) |
|
676 { |
|
677 //PrintBasic:1 |
|
678 if( services[j]->ServiceType().Compare( KPrintBasic ) == 0 ) |
|
679 { |
|
680 aService = EPrintBasic; |
|
681 service = services[j]; |
|
682 continue; // Continue to search for PrintEnhanced:1 |
|
683 } |
|
684 |
|
685 // PrintEnhanced:1 |
|
686 if( services[j]->ServiceType().Compare( KPrintEnhanced ) == 0 ) |
|
687 { |
|
688 aService = EPrintEnhanced; |
|
689 service = services[j]; |
|
690 break; |
|
691 } |
|
692 |
|
693 } |
|
694 break; |
|
695 } |
|
696 } |
|
697 |
|
698 return service; |
|
699 } |
|
700 |
|
701 |
|
702 // ----------------------------------------------------------------------------- |
|
703 // CPrinterControlPoint::DataSinkUrlAddress |
|
704 // ----------------------------------------------------------------------------- |
|
705 // |
|
706 const TPtrC8 CPrinterControlPoint::DataSinkUrlAddress( const TDesC8& aDataSinkUrl ) |
|
707 { |
|
708 LOG("[CPrinterControlPoint::DataSinkUrlAddress] \t"); |
|
709 |
|
710 if ( aDataSinkUrl.Length() > UpnpHTTP::KHTTPUrl().Length() ) |
|
711 { |
|
712 TPtrC8 addrAndPath = aDataSinkUrl.Right(aDataSinkUrl.Length()-UpnpHTTP::KHTTPUrl().Length()); |
|
713 TInt index = addrAndPath.Find( KUPnPColon() ); |
|
714 if ( index == KErrNotFound ) |
|
715 { |
|
716 index = addrAndPath.Find( KUPnPSlash() ); |
|
717 } |
|
718 |
|
719 if ( index == KErrNotFound ) |
|
720 { |
|
721 return TPtrC8( KNullDesC8().Ptr(), 0); |
|
722 } |
|
723 |
|
724 TPtrC8 addr = addrAndPath.Left( index ); |
|
725 |
|
726 return addr; |
|
727 } |
|
728 |
|
729 return TPtrC8( KNullDesC8().Ptr(), 0); |
|
730 } |
|
731 |
|
732 // ----------------------------------------------------------------------------- |
|
733 // CPrinterControlPoint::DataSinkUrlPath |
|
734 // ----------------------------------------------------------------------------- |
|
735 // |
|
736 const TPtrC8 CPrinterControlPoint::DataSinkUrlPath( const TDesC8& aDataSinkUrl ) |
|
737 { |
|
738 LOG("[CPrinterControlPoint::DataSinkUrlPath] \t"); |
|
739 |
|
740 if ( aDataSinkUrl.Length() > KHttpPrefix().Length() ) |
|
741 { |
|
742 TPtrC8 addrAndPath = aDataSinkUrl.Right(aDataSinkUrl.Length()-KHttpPrefix().Length()); |
|
743 TPtrC8 addr; |
|
744 |
|
745 // Find slash from URL and remove it, if it exists. |
|
746 TInt index = addrAndPath.Find( KUPnPSlash() ); |
|
747 // If not found, assume that path is right as is |
|
748 if ( index == KErrNotFound ) |
|
749 { |
|
750 addr.Set( addrAndPath.Right( addrAndPath.Length() ) ); |
|
751 } |
|
752 // Slash found, copy data after it |
|
753 else |
|
754 { |
|
755 addr.Set( addrAndPath.Right( addrAndPath.Length() - index ) ); |
|
756 } |
|
757 return addr; |
|
758 } |
|
759 else |
|
760 { |
|
761 return TPtrC8( KNullDesC8().Ptr(), 0); |
|
762 } |
|
763 } |
|
764 |
|
765 // ----------------------------------------------------------------------------- |
|
766 // CPrinterControlPoint::DataSinkUrlPort |
|
767 // |
|
768 // ----------------------------------------------------------------------------- |
|
769 // |
|
770 TInt CPrinterControlPoint::DataSinkUrlPort( const TDesC8& aDataSinkUrl ) |
|
771 { |
|
772 LOG("[CPrinterControlPoint::DataSinkUrlPort] \t"); |
|
773 |
|
774 if (aDataSinkUrl.Length() > KHttpPrefix().Length()) |
|
775 { |
|
776 TPtrC8 addrAndPath = aDataSinkUrl.Right(aDataSinkUrl.Length()-KHttpPrefix().Length()); |
|
777 TInt separIndex = addrAndPath.Find( KUPnPColon ); |
|
778 if ( separIndex == KErrNotFound ) |
|
779 { |
|
780 return KDefaultHttpPortNumber; |
|
781 } |
|
782 TInt slashIndex = addrAndPath.Find( KUPnPSlash() ); |
|
783 if ( slashIndex != -1 ) |
|
784 { |
|
785 TPtrC8 port = addrAndPath.Mid( separIndex+1, slashIndex-separIndex ); |
|
786 |
|
787 TLex8 lex( port ); |
|
788 TInt prt; |
|
789 lex.Val( prt ); |
|
790 |
|
791 return prt; |
|
792 } |
|
793 else |
|
794 { |
|
795 TPtrC8 port = addrAndPath.Right( addrAndPath.Length()-separIndex-1 ); |
|
796 |
|
797 TLex8 lex( port ); |
|
798 TInt prt; |
|
799 lex.Val( prt ); |
|
800 |
|
801 return prt; |
|
802 } |
|
803 } |
|
804 return KDefaultHttpPortNumber; |
|
805 } |
|
806 |
|
807 |
|
808 // ----------------------------------------------------------------------------- |
|
809 // CPrinterControlPoint::DoCancelJobL |
|
810 // |
|
811 // ----------------------------------------------------------------------------- |
|
812 // |
|
813 void CPrinterControlPoint::DoCancelJobL(CUpnpService& aService, const TDesC8& aJobId) |
|
814 { |
|
815 LOG("[CPrinterControlPoint::DoCancelJobL]"); |
|
816 CUpnpAction* action = aService.CreateActionLC( KCancelJob ); |
|
817 User::LeaveIfNull(action); |
|
818 User::LeaveIfError(action->SetArgumentL( KJobId, aJobId )); |
|
819 SendL( action ); |
|
820 CleanupStack::Pop(); // action |
|
821 } |
|
822 |
|
823 //-------------------------------------------------------------------------------------------- |
|
824 // |
|
825 // CPrinterControlPoint::RemoveTags |
|
826 // |
|
827 //-------------------------------------------------------------------------------------------- |
|
828 TPtrC8 CPrinterControlPoint::RemoveTags( const TDesC8& aString) |
|
829 { |
|
830 LOG("[CPrinterControlPoint::RemoveTags]\t"); |
|
831 _LIT8(KUPnPStartTag, ">"); |
|
832 _LIT8(KUPnPEndTag, "</"); |
|
833 _LIT8(KUPnPEmptyTag, "<*/>"); |
|
834 |
|
835 TPtrC8 midPtr; |
|
836 midPtr.Set(aString); |
|
837 |
|
838 // Return if no tags |
|
839 TInt startPos = aString.Find(KUPnPStartTag()); |
|
840 if(KErrNotFound == startPos) |
|
841 { |
|
842 return midPtr; |
|
843 } |
|
844 |
|
845 // Return if empty |
|
846 if(KErrNotFound < aString.Match(KUPnPEmptyTag())) |
|
847 { |
|
848 return TPtrC8( KNullDesC8().Ptr(), 0); |
|
849 } |
|
850 |
|
851 // Return the mid of tags |
|
852 startPos += KUPnPStartTag().Length(); |
|
853 |
|
854 TInt endPos = aString.Find(KUPnPEndTag()); |
|
855 if(KErrNotFound == endPos) |
|
856 { |
|
857 return midPtr; |
|
858 } |
|
859 |
|
860 midPtr.Set(aString.Mid(startPos, endPos - startPos)); |
|
861 return midPtr; |
|
862 } |
|
863 |
|
864 //-------------------------------------------------------------------------------------------- |
|
865 // |
|
866 // CPrinterControlPoint::RemoveTags |
|
867 // |
|
868 //-------------------------------------------------------------------------------------------- |
|
869 void CPrinterControlPoint::JobStateLog(CUpnpService* aService) |
|
870 { |
|
871 if(!aService) |
|
872 { |
|
873 return; |
|
874 } |
|
875 LOG81("CPrinterControlPoint::JobStateLog\t prntState\t\t : %S", &(aService->StateVariable( KPrinterState() )->Value())); |
|
876 LOG81("CPrinterControlPoint::JobStateLog\t prntStateReasons: %S", &(aService->StateVariable( KPrinterStateReasons() )->Value())); |
|
877 LOG81("CPrinterControlPoint::JobStateLog\t jobIdList\t\t : %S", &(aService->StateVariable( KJobIdList() )->Value())); |
|
878 LOG81("CPrinterControlPoint::JobStateLog\t jobEndState\t : %S", &(aService->StateVariable( KJobEndState() )->Value())); |
|
879 LOG81("CPrinterControlPoint::JobStateLog\t sheets\t\t\t : %S", &(aService->StateVariable( KSheetsCompleted() )->Value())); |
|
880 LOG81("CPrinterControlPoint::JobStateLog\t jobAbortState\t : %S", &(aService->StateVariable( KJobAbortState() )->Value())); |
|
881 LOG81("CPrinterControlPoint::JobStateLog\t contentCompList : %S", &(aService->StateVariable( KContentCompleteList() )->Value())); |
|
882 } |
|
883 |
|
884 // End Of File |