|
1 /* |
|
2 * Copyright (c) 2004-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: Defines the CBtPrinterController class. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <obex.h> |
|
20 |
|
21 #include "crsbtdevice.h" |
|
22 #include "cbtprintercontroller.h" |
|
23 #include "cbtsoapcodec.h" |
|
24 #include "clog.h" |
|
25 #include "tbtmapper.h" |
|
26 #include "cbtdiscover.h" |
|
27 #include "printmessagecodes.h" |
|
28 #include "cbtstatuschannel.h" |
|
29 #include "cbtjobchannel.h" |
|
30 #include "rsutils.h" |
|
31 #include "btnotifierapi.h" |
|
32 |
|
33 //-------------------------------------------------------------------------------------------- |
|
34 // |
|
35 // CBtPrinterController::NewL |
|
36 // |
|
37 //-------------------------------------------------------------------------------------------- |
|
38 CBtPrinterController* CBtPrinterController::NewL(MBtPCObserver& aObs) |
|
39 { |
|
40 CBtPrinterController *self = NewLC(aObs); |
|
41 CleanupStack::Pop(); // self |
|
42 |
|
43 return self; |
|
44 } |
|
45 |
|
46 //-------------------------------------------------------------------------------------------- |
|
47 // |
|
48 // CBtPrinterController::NewLC |
|
49 // |
|
50 //-------------------------------------------------------------------------------------------- |
|
51 CBtPrinterController* CBtPrinterController::NewLC(MBtPCObserver& aObs) |
|
52 { |
|
53 CBtPrinterController *self = new (ELeave) CBtPrinterController(aObs); |
|
54 CleanupStack::PushL(self); |
|
55 self->ConstructL(); |
|
56 return self; |
|
57 } |
|
58 |
|
59 //-------------------------------------------------------------------------------------------- |
|
60 // |
|
61 // CBtPrinterController::CBtPrinterController |
|
62 // |
|
63 //-------------------------------------------------------------------------------------------- |
|
64 CBtPrinterController::CBtPrinterController(MBtPCObserver& aObs): |
|
65 iObs( aObs ), |
|
66 iJobChannel(NULL), |
|
67 iObjectChannel(NULL) |
|
68 { |
|
69 LOG("[CBtPrinterController::CBtPrinterController]\t"); |
|
70 } |
|
71 |
|
72 |
|
73 //-------------------------------------------------------------------------------------------- |
|
74 // |
|
75 // CBtPrinterController::~CBtPrinterController |
|
76 // |
|
77 //-------------------------------------------------------------------------------------------- |
|
78 CBtPrinterController::~CBtPrinterController() |
|
79 { |
|
80 LOG("[CBtPrinterController::~CBtPrinterController]\t"); |
|
81 |
|
82 ClearConnections(); |
|
83 |
|
84 if(iBtDiscoverEngine) |
|
85 { |
|
86 delete iBtDiscoverEngine; |
|
87 iBtDiscoverEngine = NULL; |
|
88 } |
|
89 |
|
90 if(iObjectChannel) |
|
91 { |
|
92 delete iObjectChannel; |
|
93 iObjectChannel = NULL; |
|
94 } |
|
95 |
|
96 if(iJobChannel) |
|
97 { |
|
98 delete iJobChannel; |
|
99 iJobChannel = NULL; |
|
100 } |
|
101 |
|
102 delete iQuery; |
|
103 |
|
104 iImageList.Reset(); |
|
105 iImageList.Close(); |
|
106 |
|
107 } |
|
108 |
|
109 //-------------------------------------------------------------------------------------------- |
|
110 // |
|
111 // CBtPrinterController::ConstructL |
|
112 // |
|
113 //-------------------------------------------------------------------------------------------- |
|
114 void CBtPrinterController::ConstructL() |
|
115 { |
|
116 LOG("[CBtPrinterController::ConstructL]\t begin"); |
|
117 iJobId = KErrNotFound; |
|
118 |
|
119 iBtDiscoverEngine = CRsBtDiscoverEngine::NewL(*this); |
|
120 |
|
121 LOG("[CBtPrinterController::ConstructL]\t channels"); |
|
122 iObjectChannel = NULL; |
|
123 iJobChannel = CBtJobChannel::NewL(iObs); |
|
124 |
|
125 iQuery = NULL; |
|
126 iProtocol = 0; |
|
127 |
|
128 InitJobVariables(); |
|
129 } |
|
130 |
|
131 |
|
132 //-------------------------------------------------------------------------------------------- |
|
133 // |
|
134 // CBtPrinterController::ConstructL |
|
135 // |
|
136 //-------------------------------------------------------------------------------------------- |
|
137 TInt CBtPrinterController::GetPercentSent() |
|
138 { |
|
139 LOG("[CBtPrinterController::GetPercentSent]\t"); |
|
140 |
|
141 return iPercents; |
|
142 } |
|
143 |
|
144 //-------------------------------------------------------------------------------------------- |
|
145 // |
|
146 // CBtPrinterController::Stop |
|
147 // |
|
148 //-------------------------------------------------------------------------------------------- |
|
149 void CBtPrinterController::Stop() |
|
150 { |
|
151 LOG("[CBtPrinterController::Stop]\t"); |
|
152 |
|
153 iJobChannel->Cancel(); |
|
154 |
|
155 ClearConnections(); |
|
156 } |
|
157 |
|
158 //-------------------------------------------------------------------------------------------- |
|
159 // |
|
160 // CBtPrinterController::IsConnected |
|
161 // |
|
162 //-------------------------------------------------------------------------------------------- |
|
163 TBool CBtPrinterController::IsConnected() |
|
164 { |
|
165 LOG("[CBtPrinterController::IsConnected]\t"); |
|
166 TBool connected = EFalse; |
|
167 |
|
168 if(iJobChannel && iJobChannel->IsConnected()) |
|
169 { |
|
170 connected = ETrue; |
|
171 LOG1("[CBtPrinterController::IsConnected]\t iJobChannel->IsConnected() %d", connected); |
|
172 } |
|
173 |
|
174 if(iObjectChannel && iObjectChannel->IsConnected()) |
|
175 { |
|
176 connected = ETrue; |
|
177 LOG1("[CBtPrinterController::IsConnected]\t iObjectChannel->IsConnected() %d", connected); |
|
178 } |
|
179 |
|
180 LOG1("[CBtPrinterController::IsConnected]\t return %d",connected); |
|
181 return connected; |
|
182 } |
|
183 |
|
184 //-------------------------------------------------------------------------------------------- |
|
185 // |
|
186 // CBtPrinterController::FinishPrinting |
|
187 // |
|
188 //-------------------------------------------------------------------------------------------- |
|
189 void CBtPrinterController::FinishPrinting() |
|
190 { |
|
191 LOG("[CBtPrinterController::FinishPrintingL]\t begin"); |
|
192 |
|
193 // Already finishing |
|
194 if(iFinish) |
|
195 { |
|
196 LOG("[CBtPrinterController::FinishPrintingL]\t already finishing"); |
|
197 return; |
|
198 } |
|
199 |
|
200 iFinish = ETrue; |
|
201 |
|
202 Stop(); |
|
203 |
|
204 LOG("[CBtPrinterController::FinishPrintingL]\t end"); |
|
205 return; |
|
206 } |
|
207 |
|
208 //-------------------------------------------------------------------------------------------- |
|
209 // |
|
210 // CBtPrinterController::StartDiscoveryL |
|
211 // |
|
212 //-------------------------------------------------------------------------------------------- |
|
213 void CBtPrinterController::StartDiscoveryL( TUint aProtocol) |
|
214 { |
|
215 LOG1("[CBtPrinterController::StartDiscoveryL]\t aProtocol: %d", aProtocol); |
|
216 |
|
217 iProtocol = aProtocol; |
|
218 iQuery = CBtOnQuery::NewL( *this ); |
|
219 iQuery->IsBluetoothOn(); |
|
220 |
|
221 LOG("CBtPrinterController::StartDiscoveryL end"); |
|
222 } |
|
223 |
|
224 //-------------------------------------------------------------------------------------------- |
|
225 // |
|
226 // CBtPrinterController::CancelDiscoveryL |
|
227 // |
|
228 //-------------------------------------------------------------------------------------------- |
|
229 void CBtPrinterController::CancelDiscovery() |
|
230 { |
|
231 LOG("[CBtPrinterController::CancelDiscovery]\t begin"); |
|
232 iBtDiscoverEngine->Stop(); |
|
233 |
|
234 LOG1( "[CBtPrinterController::CancelDiscovery]\t iBtDiscoverEngine->IsActive() = %d", iBtDiscoverEngine->IsActive() ); |
|
235 |
|
236 Stop(); |
|
237 } |
|
238 |
|
239 //-------------------------------------------------------------------------------------------- |
|
240 // |
|
241 // CBtPrinterController::GetCapabilitiesL |
|
242 // |
|
243 // Fully independent and synchronous method. Does not require any existing |
|
244 // connections and all connections will be deleted after execution. |
|
245 // |
|
246 //-------------------------------------------------------------------------------------------- |
|
247 void CBtPrinterController::GetCapabilitiesL(CRsBtDevice& aDevice) |
|
248 { |
|
249 LOG("[CBtPrinterController::GetCapabilitiesL]\t"); |
|
250 iJobChannel->Cancel(); |
|
251 iJobChannel->GetCapabilitiesL(aDevice); |
|
252 LOG("[CBtPrinterController::GetCapabilitiesL]\t out"); |
|
253 } |
|
254 |
|
255 |
|
256 //-------------------------------------------------------------------------------------------- |
|
257 // |
|
258 // CBtPrinterController::CreateJobL |
|
259 // |
|
260 //-------------------------------------------------------------------------------------------- |
|
261 void CBtPrinterController::CreateJobL(CRsBtDevice& aDevice, CPrintJob& aJob) |
|
262 { |
|
263 LOG("[CBtPrinterController::CreateJobL]\t begin"); |
|
264 |
|
265 iJobChannel->Cancel(); |
|
266 |
|
267 iImageList.Reset(); |
|
268 aJob.Images(iImageList); |
|
269 iImageCount = iImageList.Count(); |
|
270 LOG1("[CBtPrinterController::CreateJobL]\t iImageList.Count(): %d", iImageList.Count()); |
|
271 if(0 == iImageCount) |
|
272 User::Leave(KErrInvalidData); |
|
273 |
|
274 iJobId = KErrNotFound; |
|
275 |
|
276 iJobChannel->StartL(aDevice); |
|
277 |
|
278 iJobChannel->CreateJobL(aJob); |
|
279 LOG("[CBtPrinterController::CreateJobL]\t CreateJobL done"); |
|
280 |
|
281 LOG1("[CBtPrinterController::CreateJobL]\t aDevice.UsedProtocol() %d", aDevice.UsedProtocol()); |
|
282 if(KImagePrint_PrinterProtocol_BPP == aDevice.UsedProtocol()) |
|
283 { |
|
284 LOG("[CBtPrinterController::CreateJobL]\t before establishing"); |
|
285 EstablishObjectChannelL( aDevice ); |
|
286 } |
|
287 else |
|
288 { |
|
289 iJobId = 1; |
|
290 } |
|
291 |
|
292 LOG("[CBtPrinterController::CreateJobL]\t out"); |
|
293 } |
|
294 |
|
295 //-------------------------------------------------------------------------------------------- |
|
296 // |
|
297 // CBtPrinterController::GetPrinterStateL |
|
298 // |
|
299 //-------------------------------------------------------------------------------------------- |
|
300 void CBtPrinterController::GetPrinterStateL(CRsBtDevice& aDevice) |
|
301 { |
|
302 LOG("[CBtPrinterController::GetPrinterStateL]\t begin"); |
|
303 iJobChannel->Cancel(); |
|
304 |
|
305 if(!iJobChannel->IsConnected()) |
|
306 { |
|
307 iJobChannel->StartL(aDevice); |
|
308 } |
|
309 |
|
310 iJobChannel->GetPrinterStateL(); |
|
311 |
|
312 LOG("[CBtPrinterController::GetPrinterStateL]\t OUT"); |
|
313 } |
|
314 |
|
315 //-------------------------------------------------------------------------------------------- |
|
316 // |
|
317 // CBtPrinterController::GetJobAttributesL |
|
318 // |
|
319 //-------------------------------------------------------------------------------------------- |
|
320 void CBtPrinterController::GetJobAttributesL(CRsBtDevice& aDevice, TInt aJobId) |
|
321 { |
|
322 LOG("[CBtPrinterController::GetJobAttributesL]\t begin"); |
|
323 |
|
324 if(!iJobChannel || !iJobChannel->IsConnected()) |
|
325 { |
|
326 LOG("[CBtPrinterController::GetJobAttributesL]\t User::Leave(KErrInvalidSequence);"); |
|
327 User::Leave(KErrInvalidSequence); |
|
328 } |
|
329 |
|
330 LOG("[CBtPrinterController::GetJobAttributesL]\t iJobId = aJobId;"); |
|
331 iJobId = aJobId; |
|
332 |
|
333 LOG("[CBtPrinterController::GetJobAttributesL]\t iJobChannel->GetJobAttributesL(aJobId);"); |
|
334 iJobChannel->GetJobAttributesL(aJobId); |
|
335 } |
|
336 |
|
337 //-------------------------------------------------------------------------------------------- |
|
338 // |
|
339 // CBtPrinterController::CancelJobL |
|
340 // |
|
341 //-------------------------------------------------------------------------------------------- |
|
342 void CBtPrinterController::CancelJobL(CRsBtDevice& aDevice, TInt aJobId) |
|
343 { |
|
344 LOG("[CBtPrinterController::CancelJob(TInt)]\t begin"); |
|
345 |
|
346 if(!iJobChannel || !iJobChannel->IsConnected()) |
|
347 User::Leave(KErrInvalidSequence); |
|
348 |
|
349 iJobChannel->Cancel(); |
|
350 |
|
351 iJobId = aJobId; |
|
352 |
|
353 iJobChannel->CancelJobL(iJobId); |
|
354 } |
|
355 |
|
356 //-------------------------------------------------------------------------------------------- |
|
357 // |
|
358 // CBtPrinterController::GetEventL |
|
359 // |
|
360 //-------------------------------------------------------------------------------------------- |
|
361 void CBtPrinterController::GetEventL(TInt aJobId) |
|
362 { |
|
363 LOG("[CBtPrinterController::GetEvent]\t begin"); |
|
364 iJobId = aJobId; |
|
365 |
|
366 if(!iJobChannel || !iJobChannel->IsConnected()) |
|
367 User::Leave(KErrInvalidSequence); |
|
368 |
|
369 iJobChannel->GetEventL(aJobId); |
|
370 } |
|
371 |
|
372 //---------------------------------- |
|
373 |
|
374 /////////////////////////////// |
|
375 // Private |
|
376 /////////////////////////////// |
|
377 // From MRsBtDiscoverEngineObserver. |
|
378 //-------------------------------------------------------------------------------------------- |
|
379 // |
|
380 // CBtPrinterController::HandleDiscoveryEvent |
|
381 // |
|
382 //-------------------------------------------------------------------------------------------- |
|
383 void CBtPrinterController::HandleDiscoveryEvent(TInt aEvent, TInt aErrorCode) |
|
384 { |
|
385 LOG2("[CBtPrinterController::HandleDiscoveryEvent]\t aEvent: %d, aErrorCode: %d", aEvent, aErrorCode); |
|
386 |
|
387 switch ( aEvent ) |
|
388 { |
|
389 case MBtDiscoveryObserver::EFoundBtPrinter: |
|
390 LOG("[CBtPrinterController::HandleBtDiscoverEngineEventL]\t EFoundBtPrinter"); |
|
391 iObs.DeviceDiscovered(iBtDiscoverEngine->GetDevice()); |
|
392 break; |
|
393 case MBtDiscoveryObserver::ERemoveBtPrinter: |
|
394 LOG("[CBtPrinterController::HandleBtDiscoverEngineEventL]\t ERemoveBtPrinter"); |
|
395 iObs.DeviceDisappeared(iBtDiscoverEngine->GetDevice()); |
|
396 break; |
|
397 case MBtDiscoveryObserver::EDoneFindingPrinters: |
|
398 LOG("[CBtPrinterController::HandleBtDiscoverEngineEventL]\t EDoneFindingPrinters"); |
|
399 iObs.DiscoveryError(KErrNone); |
|
400 break; |
|
401 case MBtDiscoveryObserver::EErrorDuringDiscover: |
|
402 LOG("[CBtPrinterController::HandleBtDiscoverEngineEventL]\t EErrorDuringDiscover"); |
|
403 iObs.DiscoveryError(aErrorCode); |
|
404 break; |
|
405 default: |
|
406 break; |
|
407 } |
|
408 } |
|
409 |
|
410 // From MBtObjectServerObserver |
|
411 //-------------------------------------------------------------------------------------------- |
|
412 // |
|
413 // CBtPrinterController::HandleObjectServerEvent |
|
414 // |
|
415 //-------------------------------------------------------------------------------------------- |
|
416 void CBtPrinterController::HandleObjectServerEvent(TInt aStatus, TInt aInfo) |
|
417 { |
|
418 LOG2("[CBtPrinterController::OperationStatus]\t aStatus: %d, aInfo: %d", aStatus, aInfo); |
|
419 |
|
420 switch( aStatus ) |
|
421 { |
|
422 case KObjectServerStopped: |
|
423 LOG("[CBtPrinterController::OperationStatus]\t iObjectChannel stopped"); |
|
424 iServerError = KErrNone; |
|
425 break; |
|
426 case KObjectServerStarted: |
|
427 LOG("[CBtPrinterController::OperationStatus]\t KObjectServerStarted"); |
|
428 iServerError = KErrNone; |
|
429 iPercents = 0; |
|
430 iSentImages = 0; |
|
431 break; |
|
432 case KObjectServerAllFilesSent: // not used! |
|
433 iServerError = KErrNone; |
|
434 break; |
|
435 case KObjectServerPackageSent: |
|
436 iServerError = KErrNone; |
|
437 iPercents = 100 * ((iSentImages * 100) + aInfo) / (iImageCount * 100); |
|
438 LOG2("[CBtPrinterController::OperationStatus]\t iPercents %d, aInfo %d", iPercents, aInfo); |
|
439 iObs.GetEventResponse(iJobId, EBtStateSending, EBtStatePrinting, ENoMessage, KErrNone); |
|
440 break; |
|
441 case KObjectServerFileSent: |
|
442 LOG("[CBtPrinterController::OperationStatus]\t KObjectServerOneFileSent"); |
|
443 iServerError = KErrNone; |
|
444 |
|
445 iPercents = 100 * ((iSentImages * 100) + aInfo) / (iImageCount * 100); |
|
446 |
|
447 ++iSentImages; |
|
448 LOG2("[CBtPrinterController::OperationStatus]\t sent images: %d/%d", iSentImages, iImageCount); |
|
449 if(iSentImages == iImageCount) |
|
450 { |
|
451 iObs.GetEventResponse(iJobId, EBtStatePrinting, EBtStatePrinting, ENoMessage, KErrNone); |
|
452 } |
|
453 else |
|
454 { |
|
455 iObs.GetEventResponse(iJobId, EBtStateSending, EBtStatePrinting, ENoMessage, KErrNone); |
|
456 } |
|
457 break; |
|
458 case KErrNone: |
|
459 break; |
|
460 case KObjectServerBTDeviceMismatch: |
|
461 LOG("[CBtPrinterController::OperationStatus]\t KObjectServerBTDeviceMismatch"); |
|
462 break; |
|
463 case KObjectServerTransportUp: |
|
464 LOG("[CBtPrinterController::OperationStatus]\t KObjectServerTransportUp"); |
|
465 iObs.GetEventResponse(iJobId, EBtStateSending, EBtStatePrinting, ENoMessage, KErrNone); |
|
466 case KObjectServerConnected: |
|
467 iServerError = KErrNone; |
|
468 break; |
|
469 case KObjectServerError: |
|
470 LOG1("[CBtPrinterController::OperationStatus]\t KObjectServerError: %d", aInfo); |
|
471 iServerError = aInfo; |
|
472 //break here: other messages takes care of correct actions |
|
473 break; |
|
474 case KObjectServerDisconnected: |
|
475 LOG1("[CBtPrinterController::OperationStatus]\t disconnected, iServerError %d", iServerError); |
|
476 case KObjectServerTransportDown: |
|
477 LOG1("[CBtPrinterController::OperationStatus]\t transport down. iServerError %d", iServerError); |
|
478 if(KErrNone != iServerError) |
|
479 iObs.GetEventResponse(iJobId, EBtStateSending, EBtStatePrinting, iServerError, KErrDisconnected); |
|
480 iServerError = KErrNone; |
|
481 break; |
|
482 default: |
|
483 LOG("[CBtPrinterController::OperationStatus]\t default..."); |
|
484 break; |
|
485 } |
|
486 } |
|
487 |
|
488 //-------------------------------------------------------------------------------------------- |
|
489 // |
|
490 // CBtPrinterController::InitSyncVariables |
|
491 // |
|
492 //-------------------------------------------------------------------------------------------- |
|
493 void CBtPrinterController::InitJobVariables() |
|
494 { |
|
495 iPercents = 0; |
|
496 iImageCount = 0; |
|
497 iServerError = KErrNone; |
|
498 iFinish = EFalse; |
|
499 } |
|
500 |
|
501 //-------------------------------------------------------------------------------------------- |
|
502 // |
|
503 // CBtPrinterController::ClearConnections |
|
504 // |
|
505 //-------------------------------------------------------------------------------------------- |
|
506 void CBtPrinterController::ClearConnections() |
|
507 { |
|
508 LOG("[CBtPrinterController::ClearConnections]\t "); |
|
509 |
|
510 if(iBtDiscoverEngine) |
|
511 iBtDiscoverEngine->Cancel(); |
|
512 |
|
513 if(iObjectChannel) |
|
514 { |
|
515 iObjectChannel->Stop(); |
|
516 LOG("[CBtPrinterController::ClearConnections]\t **** iObjectChannel stop"); |
|
517 } |
|
518 |
|
519 if(iJobChannel) |
|
520 { |
|
521 LOG("[CBtPrinterController::ClearConnections]\t **** iJobChannel stop"); |
|
522 iJobChannel->Disconnect(); |
|
523 } |
|
524 |
|
525 InitJobVariables(); |
|
526 } |
|
527 |
|
528 //-------------------------------------------------------------------------------------------- |
|
529 // |
|
530 // CBtPrinterController::EstablishObjectChannelL |
|
531 // |
|
532 //-------------------------------------------------------------------------------------------- |
|
533 void CBtPrinterController::EstablishObjectChannelL( CRsBtDevice& aDevice ) |
|
534 { |
|
535 if( 0 == iImageList.Count()) |
|
536 User::Leave(KErrInvalidSequence); |
|
537 |
|
538 LOG("[CBtPrinterController::EstablishObjectChannelL]\t create iObjectChannel"); |
|
539 if(iObjectChannel) |
|
540 { |
|
541 delete iObjectChannel; |
|
542 iObjectChannel = NULL; |
|
543 } |
|
544 iObjectChannel = CBtObjectServer::NewL( aDevice.BDAddr(), iImageList, *this ); |
|
545 iObjectChannel->StartL(); |
|
546 |
|
547 iImageList.Reset(); |
|
548 |
|
549 } |
|
550 |
|
551 |
|
552 //-------------------------------------------------------------------------------------------- |
|
553 // |
|
554 // CBtPrinterController::BTOnCompleteL |
|
555 // |
|
556 //-------------------------------------------------------------------------------------------- |
|
557 void CBtPrinterController::BTOnCompleteL( TBool aResult ) |
|
558 { |
|
559 LOG("[CBtPrinterController::BTOnComplete] begin \t "); |
|
560 |
|
561 if( !aResult ) |
|
562 { |
|
563 LOG("[CBtPrinterController::BTOnComplete]\t cancelling discovery, bt is not activated \t "); |
|
564 CancelDiscovery(); |
|
565 iObs.DiscoveryError( ENoConnection ); |
|
566 } |
|
567 |
|
568 |
|
569 iBtDiscoverEngine->Start( iProtocol ); |
|
570 |
|
571 LOG("[CBtPrinterController::BTOnComplete] end \t "); |
|
572 } |
|
573 |
|
574 // End of File |