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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // EXTERNAL INCLUDES |
|
20 #include <s32file.h> |
|
21 #include <charconv.h> |
|
22 #include <bautils.h> |
|
23 #include <pathinfo.h> |
|
24 #include <utf.h> |
|
25 #include <obexbaseobject.h> |
|
26 #include <centralrepository.h> |
|
27 #include <driveinfo.h> |
|
28 |
|
29 #include "rsutils.h" |
|
30 #include "btprotocolconsts.h" |
|
31 #include "cbtonquery.h" |
|
32 #include "clog.h" |
|
33 |
|
34 namespace |
|
35 { |
|
36 const TInt KSegBufChunkSize=2048; |
|
37 #ifdef ENABLE_LOGGING // for removing compile warnings |
|
38 const TInt KLogBufferSize = 50; |
|
39 #endif |
|
40 } |
|
41 |
|
42 |
|
43 |
|
44 LOCAL_C TInt SearchAndReplace(TDes &aString, const TDesC &aSearch, const TDesC &aReplace) |
|
45 { |
|
46 TInt nPos, nLengthLeft; |
|
47 |
|
48 nLengthLeft = aString.MaxLength() - aString.Length(); |
|
49 |
|
50 nPos = aString.Find(aSearch); |
|
51 while (nPos != KErrNotFound) |
|
52 { |
|
53 if ((nLengthLeft - (aReplace.Length() - aSearch.Length())) < 0) |
|
54 { |
|
55 return KErrGeneral; |
|
56 } |
|
57 aString.Replace (nPos, aSearch.Length(), aReplace); |
|
58 nLengthLeft = aString.MaxLength() - aString.Length(); |
|
59 nPos = aString.Find(aSearch); |
|
60 } |
|
61 return KErrNone; |
|
62 } |
|
63 |
|
64 LOCAL_C void SearchAndReplaceL(CBufBase& aString, TDesC8& aSearch, TDesC8& aReplace) |
|
65 { |
|
66 TInt nExtraLength = 0; |
|
67 TInt nLength = aString.Size(); |
|
68 TInt nTempPos = 0; |
|
69 |
|
70 HBufC8* buf = HBufC8::NewLC(nLength); |
|
71 TPtr8 ptr(buf->Des()); |
|
72 aString.Read(0, ptr, nLength); |
|
73 |
|
74 TInt nPos = 0; |
|
75 while (nPos < nLength) |
|
76 { |
|
77 nTempPos = ptr.Mid(nPos).Find(aSearch); |
|
78 if (nTempPos == KErrNotFound) |
|
79 break; |
|
80 nPos += nTempPos; |
|
81 aString.Delete(nPos+nExtraLength, aSearch.Length()); |
|
82 aString.InsertL(nPos+nExtraLength, aReplace); |
|
83 nExtraLength += aReplace.Length()-aSearch.Length(); |
|
84 nPos++; |
|
85 } |
|
86 |
|
87 CleanupStack::PopAndDestroy(buf); |
|
88 } |
|
89 |
|
90 LOCAL_C void SearchAndReplace(TDes &aString, TChar aChar, TChar aReplace) |
|
91 { |
|
92 TBuf<1> aSrc1, aRep2; |
|
93 aSrc1.Append(aChar); |
|
94 aRep2.Append(aReplace); |
|
95 |
|
96 SearchAndReplace(aString, aSrc1, aRep2); |
|
97 } |
|
98 |
|
99 void RsUtils::CleanFileName(const TDesC &aOldFname, TDes& aNewFname) |
|
100 { |
|
101 LOG1("RsUtils::CleanFileName aOldFname: %S", &aOldFname); |
|
102 TInt nLen; |
|
103 |
|
104 const TUint colon=TChar(':'); |
|
105 |
|
106 if (aOldFname.Length() == 0 || aNewFname.Length() == 0) |
|
107 return; |
|
108 |
|
109 nLen = aOldFname.Length(); |
|
110 if(nLen > 3 && aOldFname[1] == colon) |
|
111 { |
|
112 // strip off c:\ at the front |
|
113 aNewFname = aOldFname.Right(nLen-3); |
|
114 } |
|
115 else |
|
116 aNewFname=aOldFname; |
|
117 |
|
118 // Change \ into / |
|
119 SearchAndReplace (aNewFname, '\\', '/'); |
|
120 LOG1("RsUtils::CleanFileName aNewFname: %S", &aNewFname); |
|
121 } |
|
122 |
|
123 |
|
124 LOCAL_C void ConvertFrom8To16Bit(const TDesC8& aSrc, TDes8& aDest) |
|
125 { |
|
126 const TInt srcLen = aSrc.Length(); |
|
127 const TInt destMaxLen = aDest.MaxSize(); |
|
128 |
|
129 if (srcLen*2 > destMaxLen) |
|
130 return; |
|
131 |
|
132 aDest.SetLength(srcLen*2); |
|
133 aDest.FillZ(); |
|
134 for (TInt i = 0; i < srcLen; i++) |
|
135 { |
|
136 aDest[2*i] = aSrc[i]; |
|
137 aDest[2*i+1] = 0x00; |
|
138 } |
|
139 } |
|
140 |
|
141 HBufC16* RsUtils::MakeXHTMLSafeL(const TDesC16& aString) |
|
142 { |
|
143 // Change XHTML special characters to their printable equivalents |
|
144 CBufSeg* seg=CBufSeg::NewL(KSegBufChunkSize); |
|
145 CleanupStack::PushL(seg); |
|
146 |
|
147 seg->InsertL(0, &aString[0], aString.Length()*2); |
|
148 |
|
149 TBuf8<16> src; |
|
150 TBuf8<18> rep; |
|
151 |
|
152 _LIT8(KAmpersand, "&"); |
|
153 ConvertFrom8To16Bit(KAmpersand, rep); |
|
154 ConvertFrom8To16Bit(_L8("&"), src); |
|
155 SearchAndReplaceL(*seg, src, rep); |
|
156 |
|
157 _LIT8(KLessthan, "<"); |
|
158 ConvertFrom8To16Bit(KLessthan, rep); |
|
159 ConvertFrom8To16Bit(_L8("<"), src); |
|
160 SearchAndReplaceL(*seg, src, rep); |
|
161 |
|
162 _LIT8(KGreaterthan, ">"); |
|
163 ConvertFrom8To16Bit(KGreaterthan, rep); |
|
164 ConvertFrom8To16Bit(_L8(">"), src); |
|
165 SearchAndReplaceL(*seg, src, rep); |
|
166 |
|
167 _LIT8(KApostrophe, "'"); |
|
168 ConvertFrom8To16Bit(KApostrophe, rep); |
|
169 ConvertFrom8To16Bit(_L8("\'"), src); |
|
170 SearchAndReplaceL(*seg, src, rep); |
|
171 |
|
172 _LIT8(KDoubleQuote, """); |
|
173 ConvertFrom8To16Bit(KDoubleQuote, rep); |
|
174 ConvertFrom8To16Bit(_L8("\""), src); |
|
175 SearchAndReplaceL(*seg, src, rep); |
|
176 |
|
177 // Replace the many types of newlines with the XHTML break sequence |
|
178 _LIT8(KTokenNewLine8,"<br/>"); |
|
179 ConvertFrom8To16Bit(KTokenNewLine8, rep); |
|
180 |
|
181 ConvertFrom8To16Bit(_L8("\r\n"), src); |
|
182 SearchAndReplaceL(*seg, src, rep); |
|
183 |
|
184 ConvertFrom8To16Bit(_L8("\n"), src); |
|
185 SearchAndReplaceL(*seg, src, rep); |
|
186 |
|
187 TUint16 newLine=0x2029; |
|
188 src.Copy(((TUint8*)&newLine),2); |
|
189 SearchAndReplaceL(*seg, src, rep); |
|
190 |
|
191 newLine=0x2028; |
|
192 src.Copy(((TUint8*)&newLine),2); |
|
193 SearchAndReplaceL(*seg, src, rep); |
|
194 |
|
195 |
|
196 TInt len = seg->Size()/2; |
|
197 HBufC16* retBuf = HBufC16::NewL(len); |
|
198 TPtr16 ptr16(retBuf->Des()); |
|
199 ptr16.SetLength(len); |
|
200 seg->Read(0, &ptr16[0], len*2); |
|
201 |
|
202 CleanupStack::PopAndDestroy(seg); |
|
203 |
|
204 return retBuf; |
|
205 |
|
206 } |
|
207 |
|
208 |
|
209 HBufC8* RsUtils::ConvertFromUnicodeToUtf8LC(const TDesC16& aUnicode) |
|
210 { |
|
211 CBufSeg* seg=CBufSeg::NewL(KSegBufChunkSize); |
|
212 CleanupStack::PushL(seg); |
|
213 |
|
214 const TInt KNumCharConvert = 30; |
|
215 |
|
216 HBufC8* buf = HBufC8::NewLC(KNumCharConvert*10); |
|
217 TPtr8 ptr(buf->Des()); |
|
218 |
|
219 TInt nInsertPos = 0; |
|
220 TInt nSrcPos = 0; |
|
221 TInt nLength = KNumCharConvert; |
|
222 TInt nSrcLength = aUnicode.Length(); |
|
223 TInt nUnconvCharsLeft = 0; |
|
224 |
|
225 //start loop |
|
226 while (nSrcPos < nSrcLength) |
|
227 { |
|
228 ptr.SetLength(0); |
|
229 nLength = Min(KNumCharConvert, nSrcLength-nSrcPos); |
|
230 |
|
231 //convert to utf8 |
|
232 nUnconvCharsLeft = CnvUtfConverter::ConvertFromUnicodeToUtf8(ptr, aUnicode.Mid(nSrcPos, nLength)); |
|
233 |
|
234 //append converted text to a buffer |
|
235 seg->InsertL(nInsertPos, ptr); |
|
236 |
|
237 nInsertPos += ptr.Length(); |
|
238 nSrcPos += (nLength-nUnconvCharsLeft); |
|
239 } |
|
240 CleanupStack::PopAndDestroy(buf); |
|
241 |
|
242 //copy converted data to a buffer to return |
|
243 nLength = seg->Size(); |
|
244 HBufC8* retBuf = HBufC8::NewL(nLength); |
|
245 TPtr8 ptrRet(retBuf->Des()); |
|
246 seg->Read(0, ptrRet, nLength); |
|
247 *retBuf=ptrRet; |
|
248 |
|
249 CleanupStack::PopAndDestroy(seg); |
|
250 |
|
251 CleanupStack::PushL(retBuf); |
|
252 return retBuf; |
|
253 } |
|
254 |
|
255 // correct order one... |
|
256 HBufC8* RsUtils::ConvertToUtf8SafeLC(const TDesC16& aUnicode) |
|
257 { |
|
258 if (!aUnicode.Length()) |
|
259 { |
|
260 HBufC8* buf = HBufC8::NewLC(1); |
|
261 return buf; |
|
262 } |
|
263 |
|
264 HBufC16* buf1 = MakeXHTMLSafeL(aUnicode); |
|
265 CleanupStack::PushL(buf1); |
|
266 HBufC8* retBuf = ConvertFromUnicodeToUtf8LC(*buf1); |
|
267 |
|
268 CleanupStack::Pop(retBuf); |
|
269 CleanupStack::PopAndDestroy(buf1); |
|
270 CleanupStack::PushL(retBuf); |
|
271 return retBuf; |
|
272 } |
|
273 |
|
274 |
|
275 void RsUtils::FindWidthHeightForPrinting(TInt &aWidth, TInt &aHeight, const TInt aMaxWidth, const TInt aMaxHeight) |
|
276 { |
|
277 if (aWidth*aMaxHeight == aHeight*aMaxWidth) |
|
278 { |
|
279 aWidth = aMaxWidth; |
|
280 aHeight = aMaxHeight; |
|
281 } |
|
282 else if (aWidth*aMaxHeight > aHeight*aMaxWidth) |
|
283 { |
|
284 aHeight = (aMaxWidth*aHeight)/aWidth; |
|
285 aWidth = aMaxWidth; |
|
286 } |
|
287 else |
|
288 { |
|
289 aWidth = (aMaxHeight*aWidth)/aHeight; |
|
290 aHeight = aMaxHeight; |
|
291 } |
|
292 } |
|
293 |
|
294 |
|
295 |
|
296 |
|
297 // All the helper functions |
|
298 |
|
299 |
|
300 // returns the file name |
|
301 |
|
302 TFileName RsUtils::FileName( const TFileName& aFullName ) |
|
303 { |
|
304 TParse parse; |
|
305 parse.Set(aFullName, NULL, NULL); |
|
306 return parse.NameAndExt(); |
|
307 } |
|
308 |
|
309 |
|
310 /** Test whether a path points to ROM. The file does not need to exist |
|
311 */ |
|
312 TBool RsUtils::PathIsInRom(const TFileName &aFileName) |
|
313 { |
|
314 LOG("RsUtils::PathIsInRom begin"); |
|
315 TParsePtrC parseSource( aFileName ); |
|
316 TInt driveId; |
|
317 TFileName path; |
|
318 DriveInfo::GetDefaultDrive( DriveInfo::EDefaultRom, driveId ); |
|
319 PathInfo::GetFullPath( path, driveId, PathInfo::ERomRootPath ); |
|
320 TParsePtrC parseRom( path ); |
|
321 |
|
322 TBool res = ( parseSource.Drive().CompareF( parseRom.Drive() ) == 0 ) ? ETrue : EFalse; |
|
323 LOG1("RsUtils::PathIsInRom res: %d", res); |
|
324 return res; |
|
325 } |
|
326 |
|
327 /** Returns a fullname with a drive not in rom |
|
328 */ |
|
329 TFileName RsUtils::PathNotRom(const TFileName &aFileName) |
|
330 { |
|
331 LOG1("RsUtils::PathNotRom aFileName: %S", &aFileName); |
|
332 |
|
333 if( PathIsInRom( aFileName ) ) |
|
334 { |
|
335 LOG("RsUtils::PathNotRom file in rom"); |
|
336 TParse parse; |
|
337 |
|
338 TInt driveId; |
|
339 TFileName path; |
|
340 DriveInfo::GetDefaultDrive( DriveInfo::EDefaultPhoneMemory, driveId ); |
|
341 PathInfo::GetRootPath( path, driveId ); |
|
342 TParsePtrC parsePhoneDrive( path ); |
|
343 |
|
344 TFileName drive = parsePhoneDrive.Drive(); |
|
345 parse.Set(drive, &aFileName, NULL); |
|
346 return parse.FullName(); |
|
347 } |
|
348 else |
|
349 { |
|
350 LOG("RsUtils::PathNotRom file NOT in rom"); |
|
351 return aFileName; |
|
352 } |
|
353 } |
|
354 |
|
355 |
|
356 |
|
357 TBool RsUtils::FileExists(const TDesC& aFileName, RFs& aFs) |
|
358 { |
|
359 return (BaflUtils::FileExists(aFs, aFileName)); |
|
360 } |
|
361 |
|
362 TInt RsUtils::FileSize(const TDesC& aFileName, TInt& aSize, RFs& aFs) |
|
363 { |
|
364 TEntry theFile; |
|
365 TInt error = aFs.Entry(aFileName, theFile); |
|
366 aSize = theFile.iSize; |
|
367 return error; |
|
368 } |
|
369 |
|
370 |
|
371 |
|
372 HBufC* RsUtils::ConcatenateStringsLC(const TDesC& aDes1, const TDesC& aDes2) |
|
373 { |
|
374 const TInt newLen=aDes1.Length()+aDes2.Length(); |
|
375 HBufC* newBuf=HBufC::NewLC(newLen); |
|
376 *newBuf=aDes1; |
|
377 TPtr newPtr(newBuf->Des()); |
|
378 newPtr.Append(aDes2); |
|
379 *newBuf=newPtr; |
|
380 return newBuf; |
|
381 } |
|
382 |
|
383 HBufC* RsUtils::ConcatenateStringsLC(const TDesC& aDes1, const TDesC& aDes2, const TDesC& aDes3) |
|
384 { |
|
385 HBufC* twoSt=ConcatenateStringsLC(aDes1,aDes2); |
|
386 HBufC* allThree=ConcatenateStringsLC(*twoSt,aDes3); |
|
387 CleanupStack::Pop(allThree); |
|
388 CleanupStack::PopAndDestroy(twoSt); |
|
389 CleanupStack::PushL(allThree); |
|
390 return allThree; |
|
391 } |
|
392 |
|
393 |
|
394 // WARNING: This function uses User::WaitForRequest, |
|
395 // so check carefully where to use it to avoid View Server 11 panic |
|
396 TBool RsUtils::IsBluetoothOn() |
|
397 { |
|
398 const TUid KPowerModeSettingNotifierUid = {0x100059E2}; // Notifier id for BT power mode setting |
|
399 TPckgBuf<TBool> pckg( ETrue ); // Input parameter |
|
400 TPckgBuf<TBool> resultPckg( EFalse ); // Output parameter |
|
401 RNotifier notif; |
|
402 if( notif.Connect() == KErrNone ) |
|
403 { |
|
404 TRequestStatus stat; |
|
405 notif.StartNotifierAndGetResponse(stat, KPowerModeSettingNotifierUid, pckg, resultPckg); |
|
406 User::WaitForRequest(stat); |
|
407 notif.CancelNotifier(KPowerModeSettingNotifierUid); |
|
408 notif.Close(); |
|
409 } |
|
410 return resultPckg(); |
|
411 } |
|
412 |
|
413 TLanguage RsUtils::GetPhoneLanguage() |
|
414 { |
|
415 return User::Language(); |
|
416 } |
|
417 |
|
418 |
|
419 TInt RsUtils::CreateDataFolder( RFs& aSession, TDes& aPath, TDriveNumber aDrive ) |
|
420 { |
|
421 LOG1("RsUtils::CreateDataFolder aDrive: %d", aDrive); |
|
422 _LIT( KColon, ":" ); |
|
423 TChar drive; |
|
424 TInt err = aSession.DriveToChar( aDrive, drive ); |
|
425 if( !err ) |
|
426 { |
|
427 err = aSession.CreatePrivatePath( aDrive ); |
|
428 if( !err ) |
|
429 { |
|
430 TFileName path; |
|
431 aSession.PrivatePath( path ); |
|
432 aPath.Zero(); |
|
433 aPath.Append( drive ); |
|
434 aPath.Append( KColon ); |
|
435 aPath.Append( path ); |
|
436 } |
|
437 } |
|
438 LOG1("RsUtils::CreateDataFolder end with aPath: %S", &aPath); |
|
439 LOG1("RsUtils::CreateDataFolder end with err: %d", err); |
|
440 return err; |
|
441 } |
|
442 |
|
443 |
|
444 TInt RsUtils::ValidateCacheFile( RFs& aSession, const TDesC& aFileName, |
|
445 TTimeIntervalMinutes aValidPeriod, TBool& aDeleted ) |
|
446 { |
|
447 aDeleted = EFalse; |
|
448 TEntry entry; |
|
449 TInt err = aSession.Entry( aFileName, entry ); |
|
450 |
|
451 if( !err ) |
|
452 { |
|
453 TTime now; |
|
454 now.UniversalTime(); |
|
455 now -= aValidPeriod; |
|
456 if( entry.iModified < now ) |
|
457 { |
|
458 // cache file was not used for a aValidPeriod period of time; delete it |
|
459 err = aSession.Delete( aFileName ); |
|
460 if( !err ) aDeleted = ETrue; |
|
461 } |
|
462 } |
|
463 LOG1("RsUtils::ValidateCacheFile aDeleted: %d", aDeleted); |
|
464 LOG1("RsUtils::ValidateCacheFile err: %d", err); |
|
465 return err; |
|
466 } |
|
467 |
|
468 void RsUtils::LogL( const CBufBase& aBuffer ) |
|
469 { |
|
470 #ifdef ENABLE_LOGGING |
|
471 #define _BUFBASE_LOGGING_ |
|
472 #ifdef _BUFBASE_LOGGING_ |
|
473 LOG("BUFBASE LOG BEGIN"); |
|
474 HBufC8* buffer=HBufC8::NewLC(KLogBufferSize); |
|
475 TPtr8 bufferPtr(buffer->Des()); |
|
476 TInt sizeleft=aBuffer.Size(); |
|
477 TInt amountToRead=KLogBufferSize; |
|
478 TInt location=0; |
|
479 while(sizeleft>0) |
|
480 { |
|
481 if(sizeleft<KLogBufferSize) |
|
482 amountToRead=sizeleft; |
|
483 aBuffer.Read(location,bufferPtr,amountToRead); |
|
484 LogL( *buffer ); |
|
485 sizeleft-=amountToRead; |
|
486 location+=amountToRead; |
|
487 } |
|
488 CleanupStack::PopAndDestroy(); // buffer |
|
489 LOG("BUFBASE LOG END"); |
|
490 #endif // _BUFBASE_LOGGING_ |
|
491 #endif // ENABLE_LOGGING |
|
492 } |
|
493 |
|
494 void RsUtils::LogL( CObexBaseObject& aBuffer ) |
|
495 { |
|
496 #ifdef ENABLE_LOGGING |
|
497 //#define _OBEXBASE_LOGGING_ |
|
498 #ifdef _OBEXBASE_LOGGING_ |
|
499 LOG("OBEXBASE LOG BEGIN"); |
|
500 LOG1("CObexBaseObject::Name length: %d", aBuffer.Name().Length()); |
|
501 LogL(aBuffer.Name()); |
|
502 LOG1("CObexBaseObject::Type length: %d", aBuffer.Type().Length()); |
|
503 LogL(aBuffer.Type()); |
|
504 LOG1("CObexBaseObject::Length: %d", aBuffer.Length()); |
|
505 LOG1("CObexBaseObject::Description length: %d", aBuffer.Description().Length()); |
|
506 LogL(aBuffer.Description()); |
|
507 LOG1("CObexBaseObject::Target length: %d", aBuffer.Target().Length()); |
|
508 LogL(aBuffer.Target()); |
|
509 const RPointerArray<HBufC8>* http = aBuffer.Http(); |
|
510 if( http ) |
|
511 { |
|
512 LOG1("http->Count: %d", http->Count()); |
|
513 for( TInt i = 0; i < http->Count(); i++ ) |
|
514 { |
|
515 LOG1("i: %d", i); |
|
516 LogL(*((*http)[i])); |
|
517 } |
|
518 } |
|
519 LOG1("CObexBaseObject::AppParam length: %d", aBuffer.AppParam().Length()); |
|
520 LogL(aBuffer.AppParam()); |
|
521 |
|
522 |
|
523 LOG("OBEXBASE LOG END"); |
|
524 #endif // _OBEXBASE_LOGGING_ |
|
525 #endif // ENABLE_LOGGING |
|
526 } |
|
527 |
|
528 void RsUtils::LogL( const TDesC8& aBuffer ) |
|
529 { |
|
530 #ifdef ENABLE_LOGGING |
|
531 HBufC16* bufC16 = HBufC16::NewLC( aBuffer.Length() ); |
|
532 TPtr16 ptr16 = bufC16->Des(); |
|
533 ptr16.Copy( aBuffer ); |
|
534 LogL( *bufC16 ); |
|
535 CleanupStack::PopAndDestroy(); // bufC16 |
|
536 #endif // ENABLE_LOGGING |
|
537 } |
|
538 |
|
539 void RsUtils::LogL( const TDesC16& aBuffer ) |
|
540 { |
|
541 #ifdef ENABLE_LOGGING |
|
542 TInt sizeleft = aBuffer.Length(); |
|
543 TInt amountToRead = KLogBufferSize; |
|
544 TInt location = 0; |
|
545 while( sizeleft > 0 ) |
|
546 { |
|
547 if( sizeleft < KLogBufferSize ) |
|
548 amountToRead = sizeleft; |
|
549 HBufC16* buffer = aBuffer.Mid( location, amountToRead ).AllocL(); |
|
550 _LIT( KFormattedString, "ACHTUNG!!! FORMATTED STRING ACHTUNG!!!" ); |
|
551 _LIT( KFormatMark, "%" ); |
|
552 if( buffer->Find( KFormatMark ) != KErrNotFound ) |
|
553 { |
|
554 delete buffer; |
|
555 buffer = NULL; |
|
556 buffer = KFormattedString().AllocL(); |
|
557 } |
|
558 LOG1("%S", buffer); |
|
559 delete buffer; |
|
560 buffer = NULL; |
|
561 sizeleft -= amountToRead; |
|
562 location += amountToRead; |
|
563 } |
|
564 #endif // ENABLE_LOGGING |
|
565 } |
|
566 |
|
567 void RsUtils::LogFileL( const TFileName& aName ) |
|
568 { |
|
569 #ifdef ENABLE_LOGGING |
|
570 //#define _FILE_LOGGING_ |
|
571 #ifdef _FILE_LOGGING_ |
|
572 LOG("FILE LOG BEGIN"); |
|
573 |
|
574 RFile file; |
|
575 RFs fs; |
|
576 User::LeaveIfError( fs.Connect() ); |
|
577 CleanupClosePushL( fs ); |
|
578 User::LeaveIfError( file.Open( fs, aName, EFileStream|EFileRead|EFileShareAny ) ); |
|
579 CleanupClosePushL( file ); |
|
580 TInt fileSize; |
|
581 User::LeaveIfError( file.Size( fileSize ) ); |
|
582 HBufC8* buffer=HBufC8::NewLC( KLogBufferSize ); |
|
583 TPtr8 bufferPtr( buffer->Des() ); |
|
584 TInt sizeleft = fileSize; |
|
585 TInt amountToRead = KLogBufferSize; |
|
586 TInt location = 0; |
|
587 while( sizeleft > 0 ) |
|
588 { |
|
589 if( sizeleft < KLogBufferSize ) |
|
590 amountToRead = sizeleft; |
|
591 |
|
592 User::LeaveIfError( file.Read( location, bufferPtr, amountToRead ) ); |
|
593 LogL( *buffer ); |
|
594 sizeleft -= amountToRead; |
|
595 location += amountToRead; |
|
596 } |
|
597 CleanupStack::PopAndDestroy( 3 ); // buffer, file, fs |
|
598 |
|
599 LOG("FILE LOG END"); |
|
600 #endif // _FILE_LOGGING_ |
|
601 #endif // ENABLE_LOGGING |
|
602 } |
|
603 |
|
604 //-------------------------------------------------------------------------------------------- |
|
605 // |
|
606 // RsUtils::GetLocalBTNameL |
|
607 // |
|
608 //-------------------------------------------------------------------------------------------- |
|
609 void RsUtils::GetLocalBTNameL(TDes8& aName) |
|
610 { |
|
611 LOG("[RsUtils::GetLocalBTNameL] BEGIN"); |
|
612 RSocketServ socketServ; |
|
613 User::LeaveIfError( socketServ.Connect() ); |
|
614 TProtocolDesc pInfo; |
|
615 TBuf<0x100> name; |
|
616 TInt error = KErrNone; |
|
617 |
|
618 _LIT( BTLinkManager, "BTLinkManager" ); |
|
619 error = socketServ.FindProtocol( BTLinkManager(), pInfo ); |
|
620 LOG1("[RsUtils::GetLocalBTNameL] socketServ.FindProtocol ends with: %d", error ); |
|
621 if( KErrNone == error ) |
|
622 { |
|
623 RHostResolver hostResolver; |
|
624 error = hostResolver.Open( socketServ, pInfo.iAddrFamily, pInfo.iProtocol ); |
|
625 LOG1("[RsUtils::GetLocalBTNameL] hostResolver.Open ends with: %d", error ); |
|
626 if( KErrNone == error ) |
|
627 { |
|
628 hostResolver.GetHostName( name ); |
|
629 hostResolver.Close(); |
|
630 } |
|
631 aName.Copy( name ); |
|
632 } |
|
633 if ( error != KErrNone ) |
|
634 { |
|
635 aName.Zero(); |
|
636 // KServiceClass == own ID |
|
637 aName.AppendNum(KServiceClass, EHex); |
|
638 } |
|
639 socketServ.Close(); |
|
640 LOG82("[CBtPrintingDevice::GetLocalBTNameL]\t GetLocalBTNameL(%S) %d", &aName, error); |
|
641 LOG("[RsUtils::GetLocalBTNameL] END"); |
|
642 |
|
643 } |
|
644 |
|
645 // End of File |
|