|
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: Contains the CRsBtDevice class definition. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "crsbtdevice.h" |
|
20 #include "clog.h" |
|
21 #include "imageprint.h" |
|
22 |
|
23 ////////////////////////////////////////////////////////////////////// |
|
24 // Construction/Destruction |
|
25 ////////////////////////////////////////////////////////////////////// |
|
26 |
|
27 CRsBtDevice::CRsBtDevice() |
|
28 { |
|
29 } |
|
30 |
|
31 CRsBtDevice::~CRsBtDevice() |
|
32 { |
|
33 LOG("CRsBtDevice::~CRsBtDevice begin"); |
|
34 delete iPrinterModel; |
|
35 delete iDevice; |
|
36 |
|
37 iCapabilities.Close(); |
|
38 LOG("CRsBtDevice::~CRsBtDevice end"); |
|
39 } |
|
40 |
|
41 CRsBtDevice* CRsBtDevice::NewL(const TNameRecord &aName) |
|
42 { |
|
43 CRsBtDevice* self = CRsBtDevice::NewLC(aName); |
|
44 CleanupStack::Pop(self); |
|
45 return self; |
|
46 } |
|
47 |
|
48 CRsBtDevice* CRsBtDevice::NewL() |
|
49 { |
|
50 CRsBtDevice* self = CRsBtDevice::NewLC(); |
|
51 CleanupStack::Pop(self); |
|
52 return self; |
|
53 } |
|
54 |
|
55 CRsBtDevice* CRsBtDevice::NewLC(const TNameRecord &aName) |
|
56 { |
|
57 CRsBtDevice* self = new (ELeave) CRsBtDevice(); |
|
58 CleanupStack::PushL(self); |
|
59 self->ConstructL(aName); |
|
60 return self; |
|
61 } |
|
62 |
|
63 CRsBtDevice* CRsBtDevice::NewLC() |
|
64 { |
|
65 CRsBtDevice* self = new (ELeave) CRsBtDevice(); |
|
66 CleanupStack::PushL(self); |
|
67 self->ConstructL(); |
|
68 return self; |
|
69 } |
|
70 |
|
71 CRsBtDevice* CRsBtDevice::NewLC(const CRsBtDevice &a) |
|
72 { |
|
73 CRsBtDevice* self = new (ELeave) CRsBtDevice(); |
|
74 CleanupStack::PushL(self); |
|
75 self->ConstructL(a); |
|
76 return self; |
|
77 } |
|
78 |
|
79 CRsBtDevice* CRsBtDevice::NewL(const CRsBtDevice &a) |
|
80 { |
|
81 CRsBtDevice* self = CRsBtDevice::NewLC(a); |
|
82 CleanupStack::Pop(self); |
|
83 return self; |
|
84 } |
|
85 |
|
86 void CRsBtDevice::ConstructL(const TNameRecord &aName) |
|
87 { |
|
88 LOG1("CRsBtDevice::ConstructL aName.iName: %S", &(aName.iName)); |
|
89 TInquirySockAddr sockAddr = (TInquirySockAddr)aName.iAddr; |
|
90 |
|
91 TBTDeviceClass devClass(sockAddr.MajorServiceClass(), |
|
92 sockAddr.MajorClassOfDevice(), |
|
93 sockAddr.MinorClassOfDevice()); |
|
94 |
|
95 iDevice = CBTDevice::NewL(sockAddr.BTAddr()); |
|
96 |
|
97 iDevice->SetDeviceClass(devClass); |
|
98 iDevice->SetFriendlyNameL(aName.iName); |
|
99 |
|
100 Init(); |
|
101 |
|
102 LOG("CRsBtDevice::ConstructL end"); |
|
103 } |
|
104 |
|
105 void CRsBtDevice::ConstructL() |
|
106 { |
|
107 iDevice = CBTDevice::NewL(); |
|
108 Init(); |
|
109 } |
|
110 |
|
111 void CRsBtDevice::ConstructL(const CRsBtDevice &a) |
|
112 { |
|
113 iDevice = CBTDevice::NewL(); |
|
114 if(a.iDevice) |
|
115 iDevice->UpdateL(*(a.iDevice)); |
|
116 |
|
117 iBPPPort = a.iBPPPort; |
|
118 iSTSPort = a.iSTSPort; |
|
119 iOPPPort = a.iOPPPort; |
|
120 iSupportedProtocols = a.iSupportedProtocols; |
|
121 iVendor = a.iVendor; |
|
122 iJustFound = a.iJustFound; |
|
123 iTimeDiscovered = a.iTimeDiscovered; |
|
124 iTimeLastUsed = a.iTimeLastUsed; |
|
125 |
|
126 iUsed = a.iUsed; |
|
127 |
|
128 iPrinterModel = NULL; |
|
129 if(a.iPrinterModel) |
|
130 iPrinterModel = a.iPrinterModel->AllocL(); |
|
131 |
|
132 iInternalDeviceId = a.iInternalDeviceId; |
|
133 iDisappeared = a.iDisappeared; |
|
134 iUsedProtocol = a.iUsedProtocol; |
|
135 |
|
136 iCapabilities.Reset(); |
|
137 for(TInt i = 0; i < a.iCapabilities.Count(); ++i) |
|
138 { |
|
139 |
|
140 TPrintCapability capab; |
|
141 capab.iCapabilityID = a.iCapabilities[i].iCapabilityID; |
|
142 capab.iType = a.iCapabilities[i].iType; |
|
143 capab.iLow = a.iCapabilities[i].iLow; |
|
144 capab.iHigh = a.iCapabilities[i].iHigh; |
|
145 capab.iDefaultValue = a.iCapabilities[i].iDefaultValue; |
|
146 capab.iEnumCount = a.iCapabilities[i].iEnumCount; |
|
147 |
|
148 for(TInt j = 0; j < a.iCapabilities[i].iEnumCount; ++j) |
|
149 { |
|
150 capab.iEnumCodes[j] = a.iCapabilities[i].iEnumCodes[j]; |
|
151 } |
|
152 |
|
153 AddCapability(capab); |
|
154 } |
|
155 } |
|
156 |
|
157 void CRsBtDevice::Init() |
|
158 { |
|
159 iBPPPort = 0; |
|
160 iSTSPort = 0; |
|
161 iOPPPort = 0; |
|
162 iSupportedProtocols = 0; |
|
163 iVendor = TPrinter::EVendorNone; |
|
164 iJustFound = EFalse; |
|
165 iTimeDiscovered.UniversalTime(); |
|
166 iTimeLastUsed.UniversalTime(); |
|
167 iPrinterModel = NULL; |
|
168 |
|
169 iInternalDeviceId = KErrNotFound; |
|
170 iDisappeared = ETrue; |
|
171 iUsedProtocol = 0; |
|
172 |
|
173 iCapabilities.Reset(); |
|
174 iUsed = EFalse; |
|
175 } |
|
176 |
|
177 /** |
|
178 * Standard method to allow object to be streamed out to a file. |
|
179 * @param aStream Stream that object will be written to, should have already been opened. |
|
180 */ |
|
181 void CRsBtDevice::ExternalizeL(RWriteStream& aStream) const |
|
182 { |
|
183 LOG("[CRsBtDevice::ExternalizeL]\t Begin"); |
|
184 |
|
185 aStream.WriteInt32L(iInternalDeviceId); |
|
186 aStream.WriteUint32L(iBPPPort); |
|
187 aStream.WriteUint32L(iSTSPort); |
|
188 aStream.WriteUint32L(iOPPPort); |
|
189 aStream.WriteInt32L(iSupportedProtocols); |
|
190 aStream.WriteUint32L(Vendor()); |
|
191 |
|
192 TUint32 temp = iTimeLastUsed.Int64(); |
|
193 aStream.WriteUint32L( temp ); |
|
194 temp = iTimeLastUsed.Int64() >> 32; |
|
195 aStream.WriteUint32L( temp ); |
|
196 temp = iTimeDiscovered.Int64(); |
|
197 aStream.WriteUint32L( temp ); |
|
198 temp = iTimeDiscovered.Int64() >> 32; |
|
199 aStream.WriteUint32L( temp ); |
|
200 |
|
201 |
|
202 aStream.WriteInt32L(iPrinterModel->Des().MaxLength()); |
|
203 aStream << *iPrinterModel; |
|
204 |
|
205 ExternalizeCapabilitiesL(aStream); |
|
206 |
|
207 aStream << *iDevice; |
|
208 |
|
209 LOG("[CRsBtDevice::ExternalizeL]\t end"); |
|
210 } |
|
211 |
|
212 void CRsBtDevice::ExternalizeCapabilitiesL(RWriteStream& aStream) const |
|
213 { |
|
214 LOG("CRsBtDevice::ExternalizeCapabilitiesL begin"); |
|
215 |
|
216 aStream.WriteInt32L(iCapabilities.Count()); |
|
217 for(TInt i = 0; i < iCapabilities.Count(); ++i) |
|
218 { |
|
219 aStream.WriteInt32L(iCapabilities[i].iCapabilityID); |
|
220 aStream.WriteInt32L(iCapabilities[i].iType); |
|
221 aStream.WriteInt32L(iCapabilities[i].iDefaultValue); |
|
222 aStream.WriteInt32L(iCapabilities[i].iLow); |
|
223 aStream.WriteInt32L(iCapabilities[i].iHigh); |
|
224 aStream.WriteInt32L(iCapabilities[i].iEnumCount); |
|
225 for(TInt j = 0; j < KMaxEnumAmount; ++j) |
|
226 { |
|
227 aStream.WriteInt32L(iCapabilities[i].iEnumCodes[j]); |
|
228 } |
|
229 } |
|
230 } |
|
231 |
|
232 |
|
233 /** |
|
234 * Standard method to allow object to be streamed in from a file. |
|
235 * @param aStream Stream that object will be read from, should have already been opened. |
|
236 */ |
|
237 void CRsBtDevice::InternalizeL(RReadStream& aStream) |
|
238 { |
|
239 LOG("[CRsBtDevice::InternalizeL]\t Begin"); |
|
240 |
|
241 TUint timeLastHigh, timeLastLow, timeDiscHigh, timeDiscLow; |
|
242 TInt maxlen; |
|
243 |
|
244 iInternalDeviceId = aStream.ReadInt32L(); |
|
245 iBPPPort = aStream.ReadUint32L(); |
|
246 iSTSPort = aStream.ReadUint32L(); |
|
247 iOPPPort = aStream.ReadUint32L(); |
|
248 |
|
249 iSupportedProtocols = aStream.ReadInt32L(); |
|
250 SetVendor(static_cast<TPrinter::TPrinterVendor>( aStream.ReadUint32L() )); |
|
251 |
|
252 timeLastLow = aStream.ReadUint32L(); |
|
253 timeLastHigh = aStream.ReadUint32L(); |
|
254 timeDiscLow = aStream.ReadUint32L(); |
|
255 timeDiscHigh = aStream.ReadUint32L(); |
|
256 |
|
257 TInt64 temp; |
|
258 temp = timeLastHigh; |
|
259 temp = temp << 32; |
|
260 iTimeLastUsed = temp | timeLastLow; |
|
261 temp = timeDiscHigh; |
|
262 temp = temp << 32; |
|
263 iTimeDiscovered = temp | timeDiscLow; |
|
264 |
|
265 delete iPrinterModel; |
|
266 iPrinterModel = NULL; |
|
267 maxlen = aStream.ReadInt32L(); |
|
268 iPrinterModel = HBufC::NewL(aStream,maxlen); |
|
269 |
|
270 InternalizeCapabilitiesL(aStream); |
|
271 |
|
272 iDevice->InternalizeL(aStream); |
|
273 iUsed = ETrue; |
|
274 |
|
275 LOG1("[CRsBtDevice::InternalizeL]\t End for: %S", &FriendlyName()); |
|
276 } |
|
277 |
|
278 void CRsBtDevice::InternalizeCapabilitiesL(RReadStream& aStream) |
|
279 { |
|
280 LOG("[CRsBtDevice::InternalizeCapabilitiesL]\t begin"); |
|
281 |
|
282 iCapabilities.Reset(); |
|
283 |
|
284 TInt count = aStream.ReadInt32L(); |
|
285 for(TInt i = 0; i < count; ++i) |
|
286 { |
|
287 TPrintCapability capability; |
|
288 capability.iCapabilityID = aStream.ReadInt32L(); |
|
289 capability.iType = (TPrintCapability::ECapType)aStream.ReadInt32L(); |
|
290 capability.iDefaultValue = aStream.ReadInt32L(); |
|
291 capability.iLow = aStream.ReadInt32L(); |
|
292 capability.iHigh = aStream.ReadInt32L(); |
|
293 capability.iEnumCount = aStream.ReadInt32L(); |
|
294 for(TInt j = 0; j < KMaxEnumAmount; ++j) |
|
295 { |
|
296 capability.iEnumCodes[j] = aStream.ReadInt32L(); |
|
297 } |
|
298 iCapabilities.Append(capability); |
|
299 } |
|
300 } |
|
301 |
|
302 |
|
303 /** |
|
304 * Create a copy of the current object. |
|
305 * \returns A pointer to the new object, the caller takes ownership of the object. |
|
306 */ |
|
307 CRsBtDevice* CRsBtDevice::CopyL() |
|
308 { |
|
309 CRsBtDevice* newDevice = NewLC(); |
|
310 newDevice->UpdateAllL(*this); |
|
311 CleanupStack::Pop(); // newDevice |
|
312 return newDevice; |
|
313 } |
|
314 |
|
315 /** |
|
316 * Create a copy of the current object. |
|
317 * \returns A pointer to the new object, the caller takes ownership of the object. |
|
318 */ |
|
319 CRsBtDevice* CRsBtDevice::CopyL(CRsBtDevice& aSource) |
|
320 { |
|
321 CRsBtDevice* newDevice = NewLC(); |
|
322 newDevice->UpdateAllL(aSource); |
|
323 CleanupStack::Pop(); // newDevice |
|
324 return newDevice; |
|
325 } |
|
326 |
|
327 /** |
|
328 * \returns Address of descriptor containing the Bluetooth friendly name of the device. |
|
329 */ |
|
330 const TDesC& CRsBtDevice::FriendlyName() const |
|
331 { |
|
332 return iDevice->FriendlyName(); |
|
333 } |
|
334 |
|
335 /** |
|
336 * Stores the BPP port (channel). |
|
337 * @param aPort BPP port (channel) as unsigned integer. If CRsBtDevice::SetBPPPort is not called, initialized as 0. |
|
338 */ |
|
339 void CRsBtDevice::SetBPPPort(TUint aPort) |
|
340 { |
|
341 iBPPPort = aPort; |
|
342 } |
|
343 |
|
344 /** |
|
345 * Stores the status port (channel). |
|
346 * @param aPort Status port (channel) as unsigned integer. If CRsBtDevice::SetSTSPort is not called, initialized as 0. |
|
347 */ |
|
348 void CRsBtDevice::SetSTSPort(TUint aPort) |
|
349 { |
|
350 iSTSPort = aPort; |
|
351 } |
|
352 |
|
353 /** |
|
354 * Stores the OPP port (channel). |
|
355 * @param aPort OPP port (channel) as unsigned integer. If CRsBtDevice::SetOPPPort is not called, initialized as 0. |
|
356 */ |
|
357 void CRsBtDevice::SetOPPPort(TUint aPort) |
|
358 { |
|
359 iOPPPort = aPort; |
|
360 } |
|
361 |
|
362 |
|
363 /** |
|
364 * Stores the protocols that this device support. |
|
365 * @param aSupportedProtocols The Supported Protocols by this device |
|
366 */ |
|
367 void CRsBtDevice::SetSupportedProtocols(TUint aSupportedProtocols) |
|
368 { |
|
369 iSupportedProtocols = aSupportedProtocols; |
|
370 } |
|
371 |
|
372 /** |
|
373 * Obtain the supported protocols by this device |
|
374 * \returns The supported protocols by this device TUint @sa KImagePrint_PrinterProtocol_BPP @sa KImagePrint_PrinterProtocol_OPP_Printer @sa KImagePrint_PrinterProtocol_OPP_PC |
|
375 */ |
|
376 TUint CRsBtDevice::SupportedProtocols() const |
|
377 { |
|
378 return iSupportedProtocols; |
|
379 } |
|
380 |
|
381 /** |
|
382 * Compares the Bluetooth device address of this Bluetooth device to the address of the passed in device. |
|
383 * @param aDevice Bluetooth device to compare this object to. |
|
384 * \returns True, Bluetooth device addresses are identical, False, Bluetooth device addresses as not identical. |
|
385 */ |
|
386 TBool CRsBtDevice::Equals( const CRsBtDevice &aDevice ) const |
|
387 { |
|
388 return (aDevice.iDevice->BDAddr() == iDevice->BDAddr()); |
|
389 } |
|
390 |
|
391 /** |
|
392 * \returns Bluetooth device address. |
|
393 */ |
|
394 const TBTDevAddr& CRsBtDevice::BDAddr() const |
|
395 { |
|
396 return iDevice->BDAddr(); |
|
397 } |
|
398 |
|
399 /** |
|
400 * \returns BPP port (channel) as an unsigned integer. If CRsBtDevice::SetBPPPort is not called, initialized as 0. |
|
401 */ |
|
402 TUint CRsBtDevice::BPPPort() const |
|
403 { |
|
404 return iBPPPort; |
|
405 } |
|
406 |
|
407 /** |
|
408 * \returns status port (channel) as an unsigned integer. If CRsBtDevice::SetSTSPort is not called, initialized as 0. |
|
409 */ |
|
410 TUint CRsBtDevice::STSPort() const |
|
411 { |
|
412 return iSTSPort; |
|
413 } |
|
414 |
|
415 /** |
|
416 * \returns OPP port (channel) as an unsigned integer. If CRsBtDevice::SetOPPPort is not called, initialized as 0. |
|
417 */ |
|
418 TUint CRsBtDevice::OPPPort() const |
|
419 { |
|
420 return iOPPPort; |
|
421 } |
|
422 |
|
423 void CRsBtDevice::SetDisappeared(TBool aDisappeared) |
|
424 { |
|
425 iDisappeared = aDisappeared; |
|
426 } |
|
427 |
|
428 TBool CRsBtDevice::IsDisappeared() const |
|
429 { |
|
430 return iDisappeared; |
|
431 } |
|
432 |
|
433 /** |
|
434 * First calls CRsBtDevice::UpdateDeviceAndBPP, then updates any remaining data from the current device, |
|
435 * includes whether device is saved in the device cache, the number of prints, and time stamps of |
|
436 * discovery and when last used. |
|
437 * @param aDevice Device whose data will be used to update current device. |
|
438 * \returns True, data of the current device was updated, False, nothing changed. |
|
439 */ |
|
440 TBool CRsBtDevice::UpdateAllL(CRsBtDevice &aDevice) |
|
441 { |
|
442 TBool modified = EFalse; |
|
443 |
|
444 modified = UpdateDeviceAndBPPL(aDevice); |
|
445 |
|
446 if (iTimeDiscovered != aDevice.iTimeDiscovered) |
|
447 { |
|
448 iTimeDiscovered = aDevice.iTimeDiscovered; |
|
449 modified = ETrue; |
|
450 } |
|
451 |
|
452 if (iTimeLastUsed != aDevice.iTimeLastUsed) |
|
453 { |
|
454 iTimeLastUsed = aDevice.iTimeLastUsed; |
|
455 modified = ETrue; |
|
456 } |
|
457 |
|
458 return modified; |
|
459 } |
|
460 |
|
461 /** |
|
462 * First calls CRsBtDevice::UpdateDevice, then updates the current devices BPP/OPP data, |
|
463 * includes BPP/OPP supported information and BPP/OPP port. |
|
464 * @param aDevice Device whose data will be used to update current device. |
|
465 * \returns True, data of the current device was updated, False, nothing changed. |
|
466 */ |
|
467 TBool CRsBtDevice::UpdateDeviceAndBPPL(CRsBtDevice &aDevice) |
|
468 { |
|
469 TBool modified = EFalse; |
|
470 |
|
471 modified = UpdateDeviceL(aDevice); |
|
472 |
|
473 if ((iSupportedProtocols & aDevice.SupportedProtocols()) != iSupportedProtocols) |
|
474 { |
|
475 iSupportedProtocols = aDevice.SupportedProtocols(); |
|
476 modified = ETrue; |
|
477 } |
|
478 |
|
479 if (iBPPPort != aDevice.BPPPort()) |
|
480 { |
|
481 iBPPPort = aDevice.BPPPort(); |
|
482 modified = ETrue; |
|
483 } |
|
484 |
|
485 if (iSTSPort != aDevice.STSPort()) |
|
486 { |
|
487 iSTSPort = aDevice.STSPort(); |
|
488 modified = ETrue; |
|
489 } |
|
490 |
|
491 if (iOPPPort != aDevice.OPPPort()) |
|
492 { |
|
493 iOPPPort = aDevice.OPPPort(); |
|
494 modified = ETrue; |
|
495 } |
|
496 |
|
497 return modified; |
|
498 } |
|
499 |
|
500 /** |
|
501 * Update the current devices Bluetooth device data, includes device address, friendly name and device class. |
|
502 * @param aDevice Device whose data will be used to update current device. |
|
503 * \returns True, data of the current device was updated, False, nothing changed. |
|
504 */ |
|
505 TBool CRsBtDevice::UpdateDeviceL(CRsBtDevice &aDevice) |
|
506 { |
|
507 TBool modified = EFalse; |
|
508 |
|
509 if( iDevice->BDAddr() != aDevice.iDevice->BDAddr() || |
|
510 iDevice->FriendlyName() != aDevice.iDevice->FriendlyName() || |
|
511 ! (DeviceClass() == aDevice.DeviceClass()) ) |
|
512 { |
|
513 iDevice->UpdateL(*(aDevice.iDevice)); |
|
514 modified = ETrue; |
|
515 } |
|
516 |
|
517 if( iPrinterModel ) |
|
518 { |
|
519 delete iPrinterModel; |
|
520 iPrinterModel = NULL; |
|
521 modified = ETrue; |
|
522 } |
|
523 if( aDevice.iPrinterModel ) |
|
524 { |
|
525 iPrinterModel = aDevice.iPrinterModel->AllocL(); |
|
526 modified = ETrue; |
|
527 } |
|
528 if( Vendor() != aDevice.Vendor() ) |
|
529 { |
|
530 SetVendor(aDevice.Vendor()); |
|
531 modified = ETrue; |
|
532 } |
|
533 |
|
534 return modified; |
|
535 } |
|
536 |
|
537 /** |
|
538 * First calls CRsBtDevice::UpdateDeviceAndBPP, then updates any remaining data from the current device, |
|
539 * includes whether device is saved in the device cache, the number of prints, and time stamps of |
|
540 * discovery and when last used. |
|
541 * @param aDevice Device whose data will be used to update current device. |
|
542 * \returns True, data of the current device was updated, False, nothing changed. |
|
543 */ |
|
544 TBool CRsBtDevice::UpdateUsedL(CRsBtDevice &aDevice) |
|
545 { |
|
546 TBool modified = EFalse; |
|
547 |
|
548 modified = UpdateDeviceAndBPPL(aDevice); |
|
549 |
|
550 if (iTimeDiscovered != aDevice.TimeDiscovered()) |
|
551 { |
|
552 iTimeDiscovered = aDevice.TimeDiscovered(); |
|
553 modified = ETrue; |
|
554 } |
|
555 |
|
556 if (iTimeLastUsed != aDevice.TimeLastUsed()) |
|
557 { |
|
558 iTimeLastUsed = aDevice.TimeLastUsed(); |
|
559 modified = ETrue; |
|
560 } |
|
561 |
|
562 if ( !iDisappeared ) |
|
563 { |
|
564 iDisappeared = ETrue; |
|
565 modified = ETrue; |
|
566 } |
|
567 |
|
568 if (iUsedProtocol != (iUsedProtocol & aDevice.SupportedProtocols()) ) |
|
569 { |
|
570 iUsedProtocol = aDevice.UsedProtocol(); |
|
571 modified = ETrue; |
|
572 } |
|
573 |
|
574 return modified; |
|
575 } |
|
576 |
|
577 |
|
578 /** |
|
579 * \returns The time stamp of when the device was last used. |
|
580 */ |
|
581 TTime CRsBtDevice::TimeLastUsed() const |
|
582 { |
|
583 return iTimeLastUsed; |
|
584 } |
|
585 |
|
586 void CRsBtDevice::SetTimeLastUsed(TTime aTime) |
|
587 { |
|
588 iTimeLastUsed = aTime; |
|
589 } |
|
590 |
|
591 /** |
|
592 * \returns The time stamp of when the device was first discovered. |
|
593 */ |
|
594 TTime CRsBtDevice::TimeDiscovered() const |
|
595 { |
|
596 return iTimeDiscovered; |
|
597 } |
|
598 |
|
599 void CRsBtDevice::SetTimeDiscovered(TTime aTime) |
|
600 { |
|
601 iTimeDiscovered = aTime; |
|
602 } |
|
603 |
|
604 /** |
|
605 * \returns The Bluetooth device class. |
|
606 */ |
|
607 TBTDeviceClass CRsBtDevice::DeviceClass() const |
|
608 { |
|
609 return iDevice->DeviceClass(); |
|
610 } |
|
611 |
|
612 void CRsBtDevice::SetPrinterModelL(const TDesC& aModelName) |
|
613 { |
|
614 LOG1("CRsBtDevice::SetPrinterModelL aModelName: %S", &aModelName); |
|
615 HBufC* temp = aModelName.AllocL(); |
|
616 TPtr ptr = temp->Des(); |
|
617 ptr.UpperCase(); |
|
618 delete iPrinterModel; |
|
619 iPrinterModel = temp; |
|
620 LOG("CRsBtDevice::SetPrinterModelL end"); |
|
621 } |
|
622 |
|
623 const TDesC& CRsBtDevice::GetPrinterModel() const |
|
624 { |
|
625 return *iPrinterModel; |
|
626 } |
|
627 |
|
628 // This is not stored in the cache! |
|
629 void CRsBtDevice::SetJustFound(TBool aJustFound) |
|
630 { |
|
631 iJustFound = aJustFound; |
|
632 } |
|
633 |
|
634 // This is not stored in the cache! |
|
635 TBool CRsBtDevice::IsJustFound() const |
|
636 { |
|
637 return iJustFound; |
|
638 } |
|
639 |
|
640 TInt CRsBtDevice::DeviceId() const |
|
641 { |
|
642 return iInternalDeviceId; |
|
643 } |
|
644 |
|
645 void CRsBtDevice::SetDeviceId(TInt aNewId) |
|
646 { |
|
647 iInternalDeviceId = aNewId; |
|
648 } |
|
649 |
|
650 void CRsBtDevice::SetVendor( TPrinter::TPrinterVendor aVendor ) |
|
651 { |
|
652 LOG1("CRsBtDevice::SetVendor aVendor: %d", aVendor); |
|
653 iVendor = aVendor; |
|
654 |
|
655 LOG("CRsBtDevice::SetVendor end"); |
|
656 } |
|
657 |
|
658 TPrinter::TPrinterVendor CRsBtDevice::Vendor() const |
|
659 { |
|
660 return iVendor; |
|
661 } |
|
662 |
|
663 // ----------------------------------------------------------------------------- |
|
664 // CRsBtDevice::Used |
|
665 // ----------------------------------------------------------------------------- |
|
666 TBool CRsBtDevice::IsUsed() const |
|
667 { |
|
668 return iUsed; |
|
669 } |
|
670 |
|
671 // ----------------------------------------------------------------------------- |
|
672 // CRsBtDevice::SetUsed |
|
673 // ----------------------------------------------------------------------------- |
|
674 void CRsBtDevice::SetUsed(TBool aUsed) |
|
675 { |
|
676 iUsed = aUsed; |
|
677 } |
|
678 |
|
679 // ----------------------------------------------------------------------------- |
|
680 // CRsBtDevice::GetUsedProtocol |
|
681 // ----------------------------------------------------------------------------- |
|
682 // |
|
683 TInt CRsBtDevice::UsedProtocol() const |
|
684 { |
|
685 return iUsedProtocol; |
|
686 } |
|
687 |
|
688 // ----------------------------------------------------------------------------- |
|
689 // CRsBtDevice::SetUsedProtocol |
|
690 // ----------------------------------------------------------------------------- |
|
691 // |
|
692 TInt CRsBtDevice::ComposeUsedProtocol(TInt aRequestedProtocols) |
|
693 { |
|
694 LOG2("CRsBtDevice::ComposeUsedProtocol]\t iRequestedProtocols: %d, supported: %d", |
|
695 aRequestedProtocols, SupportedProtocols()); |
|
696 |
|
697 if ((aRequestedProtocols & KImagePrint_PrinterProtocol_BPP) && (SupportedProtocols() & KImagePrint_PrinterProtocol_BPP)) |
|
698 { |
|
699 SetUsedProtocol(KImagePrint_PrinterProtocol_BPP); |
|
700 } |
|
701 else if ((aRequestedProtocols & KImagePrint_PrinterProtocol_OPP_Printer) && (SupportedProtocols() & KImagePrint_PrinterProtocol_OPP_Printer)) |
|
702 { |
|
703 SetUsedProtocol(KImagePrint_PrinterProtocol_OPP_Printer); |
|
704 } |
|
705 else if ((aRequestedProtocols & KImagePrint_PrinterProtocol_OPP_PC) && (SupportedProtocols() & KImagePrint_PrinterProtocol_OPP_PC)) |
|
706 { |
|
707 SetUsedProtocol(KImagePrint_PrinterProtocol_OPP_PC); |
|
708 } |
|
709 else |
|
710 { |
|
711 // This shouldn't happen at all, we have an error in the code |
|
712 LOG("[CRsBtDevice::ComposeUsedProtocol]\t ERROR! Protocol Mismatch."); |
|
713 SetUsedProtocol(0); |
|
714 } |
|
715 return UsedProtocol(); |
|
716 } |
|
717 |
|
718 // ----------------------------------------------------------------------------- |
|
719 // CRsBtDevice::SetUsedProtocol |
|
720 // ----------------------------------------------------------------------------- |
|
721 // |
|
722 void CRsBtDevice::SetUsedProtocol(TInt aUsedProtocol) |
|
723 { |
|
724 iUsedProtocol = aUsedProtocol; |
|
725 } |
|
726 |
|
727 // ----------------------------------------------------------------------------- |
|
728 // CRsBtDevice::GetCapabilityIDs |
|
729 // ----------------------------------------------------------------------------- |
|
730 // |
|
731 void CRsBtDevice::GetCapabilityIDs(RArray<TInt>& aCapabilityIDs ) |
|
732 { |
|
733 LOG1("[CBtPrintingDevice::GetCapabilityIDs]\t iCapabilities.Count(): %d", iCapabilities.Count()); |
|
734 for (TInt i=0; i < iCapabilities.Count(); i++) |
|
735 { |
|
736 aCapabilityIDs.Append(iCapabilities[i].iCapabilityID); |
|
737 LOG2("[CBtPrintingDevice::GetCapabilityIDs]\t iCapabilities[%d]: %d", i, iCapabilities[i].iCapabilityID); |
|
738 } |
|
739 } |
|
740 |
|
741 // ----------------------------------------------------------------------------- |
|
742 // CRsBtDevice::GetCapability |
|
743 // ----------------------------------------------------------------------------- |
|
744 // |
|
745 TInt CRsBtDevice::GetCapability(const TInt aCapabilityID, TPrintCapability& aCapability) |
|
746 { |
|
747 for (TInt i=0; i < iCapabilities.Count(); i++) |
|
748 { |
|
749 if (aCapabilityID == iCapabilities[i].iCapabilityID) |
|
750 { |
|
751 // copy capability to ouput param |
|
752 aCapability.iCapabilityID = aCapabilityID; |
|
753 aCapability.iDefaultValue = iCapabilities[i].iDefaultValue; |
|
754 aCapability.iType = iCapabilities[i].iType; |
|
755 aCapability.iEnumCount = 0; |
|
756 |
|
757 |
|
758 for (TInt j=0; j < iCapabilities[i].iEnumCount; j++) |
|
759 { |
|
760 aCapability.iEnumCodes[j] = iCapabilities[i].iEnumCodes[j]; |
|
761 aCapability.iEnumCount++; |
|
762 } |
|
763 |
|
764 return KErrNone; |
|
765 } |
|
766 } |
|
767 |
|
768 return KErrNotSupported; |
|
769 } |
|
770 |
|
771 //-------------------------------------------------------------------------------------------- |
|
772 // CRsBtDevice::SetDefaultCapability |
|
773 //-------------------------------------------------------------------------------------------- |
|
774 TInt CRsBtDevice::SetDefaultCapability(TInt aCapabilityID, TInt aValue) |
|
775 { |
|
776 LOG2("[CBtPrintingDevice::SetDefaultCapability]\t capab: %d, value: %d", aCapabilityID, aValue); |
|
777 |
|
778 // Check Validity against the target capability ranges |
|
779 for (TInt c=0; c<iCapabilities.Count(); ++c) |
|
780 { |
|
781 if (iCapabilities[c].iCapabilityID == aCapabilityID) |
|
782 { |
|
783 if ((iCapabilities[c].iType == TPrintCapability::Int) || |
|
784 (iCapabilities[c].iType == TPrintCapability::Float)) |
|
785 { |
|
786 if (((aValue < iCapabilities[c].iLow) && (iCapabilities[c].iLow != -1)) || |
|
787 ((aValue > iCapabilities[c].iHigh) && (iCapabilities[c].iHigh != -1))) |
|
788 { |
|
789 LOG1("[CBtPrintingDevice::SetJobSettingL]\t capability ranges error; return %d", KErrInvalidData); |
|
790 return KErrInvalidData; |
|
791 } |
|
792 else |
|
793 { |
|
794 iCapabilities[c].iDefaultValue = aValue; |
|
795 LOG1("[CBtPrintingDevice::SetDefaultCapability]\t %d matches", iCapabilities[c].iType); |
|
796 return KErrNone; |
|
797 } |
|
798 |
|
799 } |
|
800 else // enum |
|
801 { |
|
802 for (TInt e = 0; e < iCapabilities[c].iEnumCount; ++e) |
|
803 { |
|
804 if (aValue == iCapabilities[c].iEnumCodes[e]) |
|
805 { |
|
806 iCapabilities[c].iDefaultValue = aValue; |
|
807 LOG("[CBtPrintingDevice::SetDefaultCapability]\t enum matches"); |
|
808 return KErrNone; |
|
809 } |
|
810 } |
|
811 } |
|
812 } |
|
813 } |
|
814 LOG("[CBtPrintingDevice::SetDefaultCapability]\t capab/value doesn't match"); |
|
815 return KErrInvalidData; |
|
816 } |
|
817 |
|
818 //-------------------------------------------------------------------------------------------- |
|
819 // CRsBtDevice::AddCapability |
|
820 //-------------------------------------------------------------------------------------------- |
|
821 void CRsBtDevice::AddCapability(TPrintCapability& aCapability) |
|
822 { |
|
823 LOG1("[CBtPrintingDevice::AddCapability]\t %d", aCapability.iCapabilityID); |
|
824 |
|
825 for (TInt i=0; i < iCapabilities.Count(); i++) |
|
826 { |
|
827 if (aCapability.iCapabilityID == iCapabilities[i].iCapabilityID) |
|
828 { |
|
829 iCapabilities[i] = aCapability; |
|
830 return; |
|
831 } |
|
832 } |
|
833 |
|
834 iCapabilities.Append(aCapability); |
|
835 } |
|
836 |
|
837 //-------------------------------------------------------------------------------------------- |
|
838 // CRsBtDevice::CapabilityIDCount |
|
839 //-------------------------------------------------------------------------------------------- |
|
840 TInt CRsBtDevice::CapabilityCount() const |
|
841 { |
|
842 return iCapabilities.Count(); |
|
843 } |
|
844 |
|
845 //-------------------------------------------------------------------------------------------- |
|
846 // CRsBtDevice::GetPrinter |
|
847 //-------------------------------------------------------------------------------------------- |
|
848 TPrinter CRsBtDevice::ToTPrinter() |
|
849 { |
|
850 LOG("[CRsBtDevice::GetTPrinter]\t"); |
|
851 |
|
852 TPrinter printer; |
|
853 printer.iDisplayName = FriendlyName(); |
|
854 if(0 == printer.iDisplayName.Length()) |
|
855 { |
|
856 TBuf<20> tmpName; |
|
857 tmpName.AppendNum(DeviceId()); |
|
858 printer.iDisplayName = tmpName; |
|
859 } |
|
860 printer.iPrinterID = DeviceId(); |
|
861 printer.iProtocol = UsedProtocol(); |
|
862 printer.iVendor = Vendor(); |
|
863 |
|
864 |
|
865 // Set properties |
|
866 printer.iProperties = 0; |
|
867 if(IsUsed()) |
|
868 { |
|
869 printer.iProperties |= TPrinter::Cached; |
|
870 } |
|
871 if(KImagePrint_PrinterProtocol_BPP == printer.iProtocol) |
|
872 { |
|
873 printer.iProperties |= TPrinter::SupportsPreview; |
|
874 } |
|
875 |
|
876 return printer; |
|
877 } |
|
878 |
|
879 // End of File |