|
1 /* |
|
2 * Copyright (c) 2007-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 #include <dirent.h> |
|
19 #include <memory> |
|
20 #include <string.h> // Needed for strcmp |
|
21 #include <iostream> |
|
22 #include <fstream> |
|
23 #include <iomanip> |
|
24 #include <sstream> |
|
25 #include <e32err.h> |
|
26 #include <f32file.h> |
|
27 #include <hal.h> |
|
28 #include <flogger.h> |
|
29 #include "logger.h" |
|
30 #include "javaoslayer.h" |
|
31 #include "javasymbianoslayer.h" |
|
32 #include "libraryloaderexception.h" |
|
33 #include "dynamiclibloader.h" |
|
34 #include "javacommonutils.h" |
|
35 #include "s60commonutils.h" |
|
36 |
|
37 using namespace java::util; |
|
38 |
|
39 const char * const BOOT_CLASSPATH_MIDP_FILE = "midpodclist"; |
|
40 const char * const BOOT_CLASSPATH_INSTALLER_FILE = "installerodclist"; |
|
41 const char * const BOOT_CLASSPATH_TCKRUNNER_FILE = "tckrunnerodclist"; |
|
42 |
|
43 _LIT(KStartUpTraceDir, "java\\full"); |
|
44 _LIT(KStartUpTraceFile, "startup.txt"); |
|
45 _LIT(KTraceSpaceExtra, " "); |
|
46 |
|
47 OS_EXPORT void JavaOsLayer::startUpTrace(const std::string& header, |
|
48 int freeMem, int totalMem) |
|
49 { |
|
50 if (header.length() == 0) |
|
51 { |
|
52 _LIT(KDash, "-"); |
|
53 RFileLogger::Write(KStartUpTraceDir, KStartUpTraceFile, |
|
54 EFileLoggingModeAppend, KDash); |
|
55 } |
|
56 else |
|
57 { |
|
58 TTime time; |
|
59 time.HomeTime(); |
|
60 const int maxStrLen = 41; |
|
61 TBuf<maxStrLen> str; |
|
62 _LIT(KFormatStr, "%-B%:0%J%:1%T%:2%S%.%*C2%:3%+B"); |
|
63 TRAP_IGNORE(time.FormatL(str, KFormatStr)); |
|
64 int mem = 0; |
|
65 int err = HAL::Get(HALData::EMemoryRAMFree, mem); |
|
66 if (err != KErrNone) |
|
67 { |
|
68 mem = err; |
|
69 } |
|
70 HBufC* buf = stringToDes(header.c_str()); |
|
71 const int maxLen = 41; |
|
72 int headerLen = Min(buf->Length(), maxLen); |
|
73 TPtrC headerPtr = buf->Left(headerLen); |
|
74 TPtrC spacePtr = KTraceSpaceExtra().Right(maxLen - headerLen); |
|
75 |
|
76 int heapUsageTotal; |
|
77 User::AllocSize(heapUsageTotal); |
|
78 |
|
79 _LIT(KOutStr, "%S%S Time(%S), SysMem(%d), pUsedHeap(%d), free(%d), total(%d)"); |
|
80 RFileLogger::WriteFormat(KStartUpTraceDir, KStartUpTraceFile, |
|
81 EFileLoggingModeAppend, |
|
82 KOutStr, |
|
83 &headerPtr, &spacePtr, &str, mem, heapUsageTotal, freeMem, totalMem); |
|
84 delete buf; |
|
85 } |
|
86 } |
|
87 |
|
88 |
|
89 OS_EXPORT void JavaOsLayer::getOsSpecificLibName(std::string& result, |
|
90 const char* libName) |
|
91 { |
|
92 // JELOG2(EUtils); |
|
93 if (libName) |
|
94 { |
|
95 result = libName; |
|
96 } |
|
97 else |
|
98 { |
|
99 ELOG(EUtils, "JavaOsLayer::getOsSpecificLibName() libname was null"); |
|
100 } |
|
101 } |
|
102 |
|
103 OS_EXPORT void JavaOsLayer::getOsSpecificJavaRootPath(std::string& path) |
|
104 { |
|
105 // JELOG2(EUtils); |
|
106 path = "c:\\java"; |
|
107 } |
|
108 |
|
109 OS_EXPORT std::string& JavaOsLayer::getBinRoot(std::string& path, bool append) |
|
110 { |
|
111 // JELOG2(EUtils); |
|
112 const char* start = ":\\sys\\bin\\"; |
|
113 if (append) |
|
114 { |
|
115 path += start; |
|
116 } |
|
117 else |
|
118 { |
|
119 path = start+1; |
|
120 } |
|
121 return path; |
|
122 } |
|
123 |
|
124 OS_EXPORT std::string& JavaOsLayer::getResRoot(std::string& path, bool append) |
|
125 { |
|
126 // JELOG2(EUtils); |
|
127 const char* start = ":\\resource\\java\\"; |
|
128 if (append) |
|
129 { |
|
130 path += start; |
|
131 } |
|
132 else |
|
133 { |
|
134 path = start+1; |
|
135 } |
|
136 return path; |
|
137 } |
|
138 |
|
139 OS_EXPORT std::string& JavaOsLayer::getMidpRoot(std::string& path, bool append) |
|
140 { |
|
141 // JELOG2(EUtils); |
|
142 const char* start = ":\\private\\102033E6\\"; |
|
143 // const char* start = ":\\private\\200211D9\\"; |
|
144 if (append) |
|
145 { |
|
146 path += start; |
|
147 } |
|
148 else |
|
149 { |
|
150 path = start+1; |
|
151 } |
|
152 /* |
|
153 TUint32 uid = RProcess().SecureId().iId; |
|
154 std::ostringstream oss; |
|
155 oss<<std::hex<<uid; |
|
156 path += oss.str(); |
|
157 path += "]\\"; |
|
158 */ |
|
159 return path; |
|
160 } |
|
161 |
|
162 OS_EXPORT std::string& JavaOsLayer::getJavaCaptainRoot(std::string& path, bool append) |
|
163 { |
|
164 // JELOG2(EUtils); |
|
165 const char* start = ":\\private\\200211DC\\"; |
|
166 if (append) |
|
167 { |
|
168 path += start; |
|
169 } |
|
170 else |
|
171 { |
|
172 path = start+1; |
|
173 } |
|
174 return path; |
|
175 } |
|
176 |
|
177 OS_EXPORT DriveId JavaOsLayer::getMidpDrive() |
|
178 { |
|
179 // JELOG2(EUtils); |
|
180 int driveNum = 1; |
|
181 TUint16 driveLetter = RProcess().FileName()[0]; |
|
182 RFs::CharToDrive(driveLetter, driveNum); |
|
183 char* drive = new char[2]; |
|
184 drive[0] = *((char*)&driveLetter); |
|
185 drive[1] = 0; |
|
186 return DriveId(drive, driveNum); |
|
187 } |
|
188 |
|
189 |
|
190 OS_EXPORT void* JavaOsLayer::dlopen(const char* libName) |
|
191 { |
|
192 JELOG2(EUtils); |
|
193 RLibrary* libAccess = 0; |
|
194 if (libName) |
|
195 { |
|
196 libAccess = new RLibrary(); |
|
197 if (libAccess) |
|
198 { |
|
199 HBufC* buf = stringToDes(libName); |
|
200 if (buf) |
|
201 { |
|
202 int status = libAccess->Load(*buf); |
|
203 LOG2(EUtils, EInfo, "JavaOsLayer::dlopen(%s), Handle: %X", |
|
204 libName, libAccess); |
|
205 delete buf; |
|
206 if (status != KErrNone) |
|
207 { |
|
208 delete libAccess; |
|
209 libAccess = 0; |
|
210 throw LibraryLoaderException(OPENING_LIBRARY_FAILED, status, |
|
211 "Error opening Symbian lib.", |
|
212 __FILE__, __FUNCTION__, __LINE__); |
|
213 |
|
214 } |
|
215 else |
|
216 { |
|
217 //The code below makes RLibrary accessible from any thread. |
|
218 // copies the handle without doing Open() |
|
219 RLibrary duplicate=*libAccess; |
|
220 // overwrite the original |
|
221 status = libAccess->Duplicate(RThread()); |
|
222 duplicate.Close(); // close the original |
|
223 } |
|
224 } |
|
225 } |
|
226 } |
|
227 else |
|
228 { |
|
229 ELOG(EUtils, "JavaOsLayer::dlopen() libname was null"); |
|
230 } |
|
231 return libAccess; |
|
232 } |
|
233 |
|
234 OS_EXPORT void* JavaOsLayer::dlsym(void* handle, const char* name, |
|
235 bool containsByteCode) |
|
236 { |
|
237 JELOG2(EUtils); |
|
238 void* func = 0; |
|
239 if (handle && name) |
|
240 { |
|
241 RLibrary* libAccess = reinterpret_cast<RLibrary*>(handle); |
|
242 LookupFunc lookup = (LookupFunc)libAccess->Lookup(containsByteCode?2:1); |
|
243 if (lookup) |
|
244 { |
|
245 func = (void*) lookup(name); |
|
246 LOG2(EUtils, EInfo, "JavaOsLayer::dlsym() fuction name: %s, " |
|
247 "fPtr: %X", name, func); |
|
248 if (func == 0) |
|
249 { |
|
250 ELOG1(EUtils, "dlsym failed for %s.", name); |
|
251 } |
|
252 } |
|
253 else |
|
254 { |
|
255 ELOG1(EUtils, |
|
256 "No lookup method in ordinal 1 when looking for %s.", name); |
|
257 } |
|
258 } |
|
259 else |
|
260 { |
|
261 ELOG2(EUtils, "JavaOsLayer::dlsym() null argument handle: %X, name %X", |
|
262 handle, name); |
|
263 } |
|
264 return func; |
|
265 } |
|
266 |
|
267 OS_EXPORT int JavaOsLayer::dlclose(void* handle) |
|
268 { |
|
269 JELOG2(EUtils); |
|
270 if (handle) |
|
271 { |
|
272 RLibrary* libAccess = reinterpret_cast<RLibrary*>(handle); |
|
273 libAccess->Close(); |
|
274 delete libAccess; |
|
275 } |
|
276 else |
|
277 { |
|
278 ELOG(EUtils, "dlclose failed, null handle"); |
|
279 } |
|
280 return 0; |
|
281 } |
|
282 OS_EXPORT void JavaOsLayer::bootClassPath(std::list<std::wstring>& odcFiles, |
|
283 std::list<std::wstring>& bcpEntites, |
|
284 const int pathType) |
|
285 { |
|
286 /* |
|
287 * getResRoot requires drive letter but VerifiedFileNameL adds correct one. |
|
288 * C drive used that it is checked first and if file is found that is used |
|
289 * after that z is checked. |
|
290 */ |
|
291 std::string path = "c"; |
|
292 JavaOsLayer::getResRoot(path, true); |
|
293 |
|
294 if (BOOT_CLASSPATH_MIDP == pathType) |
|
295 { |
|
296 path.append(BOOT_CLASSPATH_MIDP_FILE); |
|
297 } |
|
298 else if (BOOT_CLASSPATH_INSTALLER == pathType) |
|
299 { |
|
300 path.append(BOOT_CLASSPATH_INSTALLER_FILE); |
|
301 } |
|
302 else if (BOOT_CLASSPATH_TCKRUNNER == pathType) |
|
303 { |
|
304 path.append(BOOT_CLASSPATH_TCKRUNNER_FILE); |
|
305 } |
|
306 else |
|
307 { |
|
308 path.append(BOOT_CLASSPATH_MIDP_FILE); |
|
309 } |
|
310 |
|
311 std::auto_ptr<HBufC>pathDes(stringToDes(path.c_str())); |
|
312 TFileName realPathName; |
|
313 TRAPD(err, realPathName = S60CommonUtils::VerifiedFileNameL(*pathDes)); |
|
314 |
|
315 if (KErrNone == err) |
|
316 { |
|
317 std::wstring temp((wchar_t*)realPathName.PtrZ()); |
|
318 std::string odcFileName(temp.begin(), temp.end()); |
|
319 |
|
320 std::vector<std::string> romClasspathEntries; |
|
321 std::string dir_path("Z:\\resource\\java\\jvm\\lib\\jrt"); |
|
322 |
|
323 listDirectory(dir_path, romClasspathEntries); // This is always needed. |
|
324 |
|
325 if (odcFileName[0] == 'c' || odcFileName[0] == 'C') // IAD deployed |
|
326 { |
|
327 std::vector<std::string> updatedClasspathEntries; |
|
328 listOdcFile(path, updatedClasspathEntries); // Read all ODC files from odc file |
|
329 |
|
330 std::string::size_type const delimiter = path.rfind("\\"); |
|
331 path = path.substr(0, delimiter); // IAD ODC file directory |
|
332 |
|
333 populateCPEntries((path + "\\jvm\\lib\\jrt\\"), updatedClasspathEntries, odcFiles, bcpEntites); |
|
334 |
|
335 std::vector<std::string> romDeltaEntries; |
|
336 |
|
337 // Add all ROM entries that are not deployed using IAD. |
|
338 deltaCPEntries(romClasspathEntries, updatedClasspathEntries, romDeltaEntries); |
|
339 |
|
340 // Add ROM only entries |
|
341 populateCPEntries((dir_path + "\\"), romDeltaEntries, odcFiles, bcpEntites); |
|
342 } |
|
343 else // Classpath only at ROM so using dir listing. |
|
344 { |
|
345 populateCPEntries((dir_path + "\\"), romClasspathEntries, odcFiles, bcpEntites); |
|
346 } |
|
347 } |
|
348 else |
|
349 { |
|
350 ELOG1(EUtils, "Cannot get real path name for: '%s'", path.c_str()); |
|
351 } |
|
352 } |
|
353 |
|
354 void JavaOsLayer::listDirectory(std::string& aDirPath, std::vector<std::string>& aEntries) |
|
355 { |
|
356 DIR *pDIR = opendir(aDirPath.c_str()); // open directory |
|
357 |
|
358 if (pDIR == NULL) |
|
359 { |
|
360 std::string errorMsg("Cannot read ROM ODC files: "); |
|
361 errorMsg.append(strerror(errno)); |
|
362 errorMsg.append(" : dir: "); |
|
363 errorMsg.append(aDirPath.c_str()); |
|
364 ELOG(EUtils, errorMsg.c_str()); |
|
365 // Suppres error if no Java at all on device ROM. |
|
366 } |
|
367 |
|
368 struct dirent* pDirEnt = readdir(pDIR); |
|
369 while (pDirEnt != NULL) |
|
370 { |
|
371 aEntries.push_back(std::string(pDirEnt->d_name)); |
|
372 pDirEnt = readdir(pDIR); |
|
373 } |
|
374 |
|
375 closedir(pDIR); // Release the open directory |
|
376 } |
|
377 |
|
378 void JavaOsLayer::listOdcFile(std::string& filePath, std::vector<std::string>& entries) |
|
379 { |
|
380 std::ifstream odcFile; |
|
381 odcFile.open(filePath.c_str(), std::ifstream::in); |
|
382 |
|
383 if (odcFile) |
|
384 { |
|
385 std::string line; |
|
386 while (std::getline(odcFile, line)) |
|
387 { |
|
388 // Trim enter if exists. |
|
389 std::string::size_type const enter = line.find_last_not_of("\n"); |
|
390 entries.push_back(line.substr(0, enter)); |
|
391 } |
|
392 odcFile.close(); |
|
393 } |
|
394 else |
|
395 { |
|
396 ELOG1(EUtils, "Cannot read file: '%s'", filePath.c_str()); |
|
397 } |
|
398 } |
|
399 |
|
400 void JavaOsLayer::populateCPEntries(const std::string& pathPrefix, |
|
401 const std::vector<std::string>& entries, |
|
402 std::list<std::wstring>& odcFiles, |
|
403 std::list<std::wstring>& bcpEntites) |
|
404 { |
|
405 std::vector<std::string>::const_iterator iter; |
|
406 |
|
407 for (iter = entries.begin(); iter != entries.end(); ++iter) |
|
408 { |
|
409 std::string entryName((*iter)); |
|
410 entryName.insert(0, pathPrefix); // Full path needed. |
|
411 |
|
412 std::wstring wideEntryName = L""; |
|
413 |
|
414 try |
|
415 { |
|
416 wideEntryName = JavaCommonUtils::utf8ToWstring(entryName.c_str()); |
|
417 } |
|
418 catch (ExceptionBase& eb) |
|
419 { |
|
420 // Suppress error to skip invalid ones. |
|
421 ELOG2(EUtils, "utf8->wstring failed on cp entry: '%s' exp: %s ", |
|
422 entryName.c_str(), eb.toString().c_str()); |
|
423 } |
|
424 size_t pos = wideEntryName.rfind(L".odc"); |
|
425 bool isOdcFile = (pos != std::string::npos) && |
|
426 (pos == (wideEntryName.length() - 4)); |
|
427 if (isOdcFile) |
|
428 { |
|
429 odcFiles.push_back(wideEntryName); |
|
430 } |
|
431 else |
|
432 { |
|
433 bcpEntites.push_back(wideEntryName); |
|
434 } |
|
435 } |
|
436 } |
|
437 |
|
438 void JavaOsLayer::deltaCPEntries(const std::vector<std::string>& romEntries, |
|
439 const std::vector<std::string>& iadEntries, |
|
440 std::vector<std::string>& deltaEntries) |
|
441 { |
|
442 std::vector<std::string>::const_iterator iter; // ROM CP iter |
|
443 std::vector<std::string>::const_iterator matchIter; // IAD CP iter |
|
444 std::vector<std::string> romDeltaEntries; |
|
445 |
|
446 // Iterate through all rom entries |
|
447 for (iter = romEntries.begin(); iter != romEntries.end(); ++iter) |
|
448 { |
|
449 bool match = false; |
|
450 // and check if they do not match to IAD ones add to romDeltaEntries. |
|
451 for (matchIter = iadEntries.begin(); matchIter != iadEntries.end(); ++matchIter) |
|
452 { |
|
453 if ((*matchIter) == (*iter)) |
|
454 { |
|
455 match = true; |
|
456 break; |
|
457 } |
|
458 } |
|
459 |
|
460 if (!match) |
|
461 { |
|
462 deltaEntries.push_back((*iter)); |
|
463 } |
|
464 } |
|
465 } |
|
466 |
|
467 OS_EXPORT FuncPtr findMethod(const char* funcName, |
|
468 const FuncTable funcTable[], |
|
469 int tableSize) |
|
470 { |
|
471 // JELOG2(EUtils); |
|
472 int res = 0; |
|
473 int mid = 0; |
|
474 int top = 0; |
|
475 int bottom = tableSize-1; |
|
476 |
|
477 if (funcName == 0) |
|
478 { |
|
479 ELOG(EUtils, "findMethod failed, null funcName"); |
|
480 return 0; |
|
481 } |
|
482 if (funcTable == 0) |
|
483 { |
|
484 ELOG(EUtils, "findMethod failed, null funcTable"); |
|
485 return 0; |
|
486 } |
|
487 |
|
488 // Loop while the number of the items left in the list is greater |
|
489 // than 2. Each iteration will split the number of items left to search |
|
490 // in half |
|
491 while ((bottom - top) > 1) |
|
492 { |
|
493 // This case handles the normal serach case where the number of |
|
494 // items left to search is greater than 2 |
|
495 mid = (top + bottom) / 2; |
|
496 res = strcmp(funcName, funcTable[mid].mFuncName); |
|
497 if (res == 0) |
|
498 { |
|
499 return((FuncPtr) funcTable[mid].mFuncAddr); |
|
500 } |
|
501 if (res > 0) |
|
502 { |
|
503 top = mid; |
|
504 } |
|
505 else |
|
506 { |
|
507 bottom = mid; |
|
508 } |
|
509 } |
|
510 |
|
511 // If there are two items left in the list then the bottom item should be |
|
512 // checked for a match |
|
513 if (bottom != top) |
|
514 { |
|
515 // Check the bottom item to see if it is a match |
|
516 res=strcmp(funcName, funcTable[bottom].mFuncName); |
|
517 if (res == 0) |
|
518 { |
|
519 return ((FuncPtr) funcTable[bottom].mFuncAddr); |
|
520 } |
|
521 } |
|
522 |
|
523 // Check the top item to see if it is a match |
|
524 res=strcmp(funcName, funcTable[top].mFuncName); |
|
525 |
|
526 if (res == 0) |
|
527 { |
|
528 return ((FuncPtr) funcTable[top].mFuncAddr); |
|
529 } |
|
530 |
|
531 // Neither the top or bottom items were a match so the |
|
532 // method must not exist in the file |
|
533 return 0; |
|
534 } |
|
535 |
|
536 OS_EXPORT HBufC* stringToDes(const char* str) |
|
537 { |
|
538 // JELOG2(EUtils); |
|
539 HBufC* resultBuf = 0; |
|
540 try |
|
541 { |
|
542 if (str) |
|
543 { |
|
544 int len = strlen(str); |
|
545 resultBuf = HBufC::New(len + 1); |
|
546 TPtr ptr = resultBuf->Des(); |
|
547 TPtr8 ptr8((TUint8 *)str, len); |
|
548 ptr8.SetLength(len); |
|
549 ptr.Copy(ptr8); |
|
550 ptr.ZeroTerminate(); |
|
551 } |
|
552 } |
|
553 catch (...) |
|
554 { |
|
555 ELOG(EUtils, "stringToDes, exception"); |
|
556 } |
|
557 return resultBuf; |
|
558 } |
|
559 |
|
560 OS_EXPORT wchar_t* desToWstring(TPtr16& aDes) |
|
561 { |
|
562 return (wchar_t*) aDes.PtrZ(); |
|
563 } |
|
564 |
|
565 OS_EXPORT TAppVersion wstringToAppVersion(const std::wstring& aVersionString) |
|
566 { |
|
567 TAppVersion appVersion; |
|
568 char* temp = JavaCommonUtils::wstringToUtf8(aVersionString); |
|
569 std::string versionStr = temp; |
|
570 |
|
571 std::string::size_type idx = 0; |
|
572 idx = versionStr.find(".", idx); |
|
573 |
|
574 // 00.00.00 --> 00 00.00 |
|
575 if (idx != std::string::npos) |
|
576 { |
|
577 versionStr.replace(idx, 1, " "); |
|
578 } |
|
579 |
|
580 idx = versionStr.find(".", idx + 1); |
|
581 |
|
582 // 00 00.00 --> 00 00 00 |
|
583 if (idx != std::string::npos) |
|
584 { |
|
585 versionStr.replace(idx, 1, " "); |
|
586 } |
|
587 |
|
588 int major = 0; |
|
589 int minor = 0; |
|
590 int build = 0; |
|
591 int result = sscanf( |
|
592 versionStr.c_str(), "%d %d %d", &major, &minor, &build); |
|
593 |
|
594 if (major > 0) |
|
595 { |
|
596 appVersion.iMajor = major; |
|
597 } |
|
598 |
|
599 if (minor > 0) |
|
600 { |
|
601 appVersion.iMinor = minor; |
|
602 } |
|
603 |
|
604 if (build > 0) |
|
605 { |
|
606 appVersion.iBuild = build; |
|
607 } |
|
608 delete[] temp; |
|
609 |
|
610 return appVersion; |
|
611 } |
|
612 |
|
613 OS_EXPORT HBufC* wstringToBuf(const std::wstring& aString) |
|
614 { |
|
615 HBufC* stringBuf = HBufC::New(aString.size()); |
|
616 if (stringBuf != 0) |
|
617 { |
|
618 TPtr16 namePtr(stringBuf->Des()); |
|
619 namePtr.Append((const TUint16*)aString.c_str(), aString.size()); |
|
620 } |
|
621 return stringBuf; |
|
622 } |
|
623 |
|
624 /** |
|
625 * |
|
626 */ |
|
627 OS_EXPORT java::util::Uid& TUidToUid(const TUid& aId,java::util::Uid& aOutUid) |
|
628 { |
|
629 // JELOG2(EUtils); |
|
630 if (0 == aId.iUid) |
|
631 return aOutUid; |
|
632 |
|
633 std::wstringstream stream; |
|
634 stream.fill('0'); |
|
635 stream << std::setw(8) << std::hex << (int)aId.iUid; // codescanner::leave |
|
636 |
|
637 std::wstring idAsStr; |
|
638 idAsStr.reserve(11); |
|
639 idAsStr.append(L"["); |
|
640 idAsStr.append(stream.str()); |
|
641 idAsStr.append(L"]"); |
|
642 Uid tmpUid(idAsStr); |
|
643 aOutUid = tmpUid; |
|
644 return aOutUid; |
|
645 } |
|
646 |
|
647 /** |
|
648 * |
|
649 */ |
|
650 OS_EXPORT TInt uidToTUid(const java::util::Uid& aUid,TUid& aOutId) |
|
651 { |
|
652 // JELOG2(EUtils); |
|
653 long long tmpInt = 0; |
|
654 std::wstring uidAsStr = aUid.toString(); |
|
655 if (0 == uidAsStr.size()) |
|
656 return KErrArgument; |
|
657 |
|
658 JavaCommonUtils::trimWstring(uidAsStr,L'\n'); |
|
659 JavaCommonUtils::trimWstring(uidAsStr,L'\t'); |
|
660 JavaCommonUtils::trimWstring(uidAsStr,L' '); |
|
661 |
|
662 if ((10 != uidAsStr.size()) && (8 != uidAsStr.size())) |
|
663 return KErrArgument; |
|
664 |
|
665 if (('[' == uidAsStr.at(0)) && (']' == uidAsStr.at(uidAsStr.size()-1))) |
|
666 { |
|
667 if (10 != uidAsStr.size()) |
|
668 return KErrArgument; |
|
669 std::wstring plainNumStr = uidAsStr.substr(1,uidAsStr.size()-2); |
|
670 std::wstringstream stream(plainNumStr); |
|
671 stream >> std::hex >> tmpInt; // codescanner::leave |
|
672 if ((false == stream.eof()) || (stream.fail())) |
|
673 return KErrArgument; |
|
674 } |
|
675 else |
|
676 { |
|
677 std::wstringstream stream(uidAsStr); |
|
678 stream >> std::hex >> tmpInt; // codescanner::leave |
|
679 if ((false == stream.eof()) || (stream.fail())) |
|
680 return KErrArgument; |
|
681 } |
|
682 |
|
683 if ((tmpInt > 0xEFFFFFFF) || (tmpInt < 0)) |
|
684 return KErrArgument; |
|
685 aOutId.iUid = tmpInt; |
|
686 return KErrNone; |
|
687 } |
|
688 |