symport/e32/euser/us_exec.cpp
changeset 1 0a7b44b10206
child 2 806186ab5e14
equal deleted inserted replaced
0:c55016431358 1:0a7b44b10206
       
     1 // Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of the License "Symbian Foundation License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // e32\euser\us_exec.cpp
       
    15 // 
       
    16 //
       
    17 
       
    18 #include "us_std.h"
       
    19 #include "us_data.h"
       
    20 #include <e32kpan.h>
       
    21 #include <unicode.h>
       
    22 #include <videodriver.h>
       
    23 #include "compareimp.h"
       
    24 
       
    25 #ifdef __VC32__
       
    26   #pragma setlocale("english")
       
    27 #endif
       
    28 
       
    29 #ifdef __TOOLS2__
       
    30 #include <stdlib.h>
       
    31 
       
    32 extern TInt gAllocCount;
       
    33 extern TInt gAllocFailRate;
       
    34 extern RAllocator::TAllocFail gAllocFailType;
       
    35 
       
    36 #endif
       
    37 
       
    38 _LIT(KLitSpace, " ");
       
    39 _LIT(KLitOpeningBracket, "(");
       
    40 _LIT(KLitMinusSign, "-");
       
    41 _LIT(KLitZeroPad, "0");
       
    42 
       
    43 // Private use area ranges of printable/non-printable characters.
       
    44 // This is a sorted list of numbers indicating the ranges in which characters
       
    45 // are printable and non-printable. The elements 0, 2, 4... are the first
       
    46 // characters of printable ranges and The elements 1, 3, 5... are the first
       
    47 // characters of non-printable ranges
       
    48 // We will assume that anything in the End User Sub-area is printable.
       
    49 static const TInt PUAPrintableRanges[] =
       
    50 	{
       
    51 	0xE000, 0xF6D9,		// End user area + unassigned corporate use area
       
    52 	0xF6DB, 0xF6DC,		// Replacement for character not in font
       
    53 	0xF6DE, 0xF700,		// various EIKON and Agenda symbols
       
    54 	0x10000, KMaxTInt	// everything else printable
       
    55 	};
       
    56 
       
    57 static TBool IsPUAPrintable(TInt aChar)
       
    58 	{
       
    59 	if (0x110000 <= aChar)
       
    60 		return 0;	// non-characters not printable
       
    61 	TInt i = 0;
       
    62 	while (PUAPrintableRanges[i] <= aChar)
       
    63 		++i;
       
    64 	return i & 1;
       
    65 	}
       
    66 
       
    67 
       
    68 
       
    69 #ifndef __TOOLS2__
       
    70 EXPORT_C TBool User::JustInTime()
       
    71 /**
       
    72 Tests whether just-in-time debugging is on or off.
       
    73 
       
    74 The function is used by the Kernel, on the Emulator, to decide whether to do
       
    75 just-in-time debugging for panics. The function applies to the current process.
       
    76 
       
    77 Unless overridden by calling User::SetJustInTime(EFalse), just-in-time debugging 
       
    78 is on by default.
       
    79 
       
    80 @return True, if just-in-time debugging is on. False otherwise.
       
    81 @see RProcess::JustInTime
       
    82 */
       
    83 	{
       
    84 
       
    85 	return RProcess().JustInTime();
       
    86 	}
       
    87 
       
    88 
       
    89 
       
    90 
       
    91 EXPORT_C void User::SetJustInTime(const TBool aBoolean)
       
    92 /**
       
    93 Sets just-in-time debugging for this process on or off.
       
    94 
       
    95 While the function can be called by code running on both the Emulator and ARM,
       
    96 it only has an effect on the Emulator. Turning just-in-time debugging off
       
    97 prevents the debug Emulator closing down when a panic occurs.
       
    98 
       
    99 By default, just-in-time debugging is on.
       
   100 
       
   101 Note that the emulator handles panics in the nomal manner, i.e. by killing 
       
   102 the thread.
       
   103 
       
   104 @param aBoolean ETrue, if just-in-time debugging is to be set on. EFalse, 
       
   105                 if just-in-time debugging is to be set off.
       
   106                 EFalse causes _asm 3 calls to be disabled.
       
   107 @see RProcess::SetJustInTime
       
   108 */
       
   109 	{
       
   110 
       
   111 	RProcess().SetJustInTime(aBoolean);
       
   112 	}
       
   113 #endif // __TOOLS2__
       
   114 
       
   115 extern const LCharSet* GetLocaleDefaultCharSet();
       
   116 extern const LCharSet* GetLocalePreferredCharSet();
       
   117 
       
   118 // Convert to folded.
       
   119 EXPORT_C TUint User::Fold(TUint aChar)
       
   120 /**
       
   121 @deprecated
       
   122 
       
   123 Folds the specified character.
       
   124 
       
   125 Folding converts the character to a form which can be used in tolerant
       
   126 comparisons without control over the operations performed. Tolerant comparisons
       
   127 are those which ignore character differences like case and accents.
       
   128 
       
   129 The result of folding a character depends on the locale and on whether this 
       
   130 is a UNICODE build or not.
       
   131 
       
   132 Note that for a non-UNICODE build, if the binary value of the character aChar
       
   133 is greater than or equal to 0x100, then the character returned is the same as
       
   134 the character passed to the function.
       
   135 
       
   136 @param aChar The character to be folded.
       
   137 
       
   138 @return The folded character.
       
   139 
       
   140 @see TChar::Fold()
       
   141 */
       
   142 	{
       
   143 	// ASCII chars excluding 'i's can be handled by naive folding
       
   144 	if (aChar < 0x80 && aChar != 'I')
       
   145 		return (aChar >= 'A' && aChar <= 'Z') ? (aChar | 0x0020) : aChar;
       
   146 	else
       
   147 		return TUnicode(aChar).Fold(TChar::EFoldStandard,GetLocaleCharSet()->iCharDataSet);
       
   148 	}
       
   149 
       
   150 
       
   151 
       
   152 
       
   153 // Convert to a folded version, specifying the folding methods.
       
   154 EXPORT_C TUint User::Fold(TUint aChar,TInt aFlags)
       
   155 /**
       
   156 Folds the character according to a specified folding method.
       
   157 
       
   158 @param aChar  The character to be folded.
       
   159 @param aFlags A set of flags defining the folding method. They are:
       
   160 
       
   161               TChar::EFoldCase, convert characters to their lower case form,
       
   162               if any;
       
   163               
       
   164               TChar::EFoldAccents, strip accents;
       
   165               
       
   166               TChar::EFoldDigits, convert digits representing values 0..9 to
       
   167               characters '0'..'9';
       
   168               
       
   169               TChar::EFoldSpaces, convert all spaces (ordinary, fixed-width,
       
   170               ideographic, etc.) to ' ';
       
   171               
       
   172               TChar::EFoldKana, convert hiragana to katakana;
       
   173               
       
   174               TChar::EFoldWidth, fold full width and half width variants to
       
   175               their standard forms;
       
   176               
       
   177               TChar::EFoldAll, use all of the above folding methods.
       
   178               
       
   179 @return The folded character.
       
   180 @see TChar::Fold()
       
   181 */
       
   182 	{
       
   183 	return TUnicode(aChar).Fold(aFlags,GetLocaleCharSet()->iCharDataSet);
       
   184 	}
       
   185 
       
   186 
       
   187 
       
   188 
       
   189 // Convert to collated.
       
   190 EXPORT_C TUint User::Collate(TUint aChar)
       
   191 /**
       
   192 Converts the character to its collated form.
       
   193 
       
   194 Collating is the process of removing differences between characters that are 
       
   195 deemed unimportant for the purposes of ordering characters. The result of 
       
   196 the conversion depends on the locale and on whether this is a UNICODE build 
       
   197 or not.
       
   198 
       
   199 Note that for a non UNICODE build, if the binary value of the character aChar
       
   200 is greater than or equal to 0x100, then the character returned is the same as
       
   201 the character passed to the function.
       
   202 
       
   203 @param aChar The character to be folded.
       
   204 
       
   205 @return The converted character.
       
   206 */
       
   207 	{
       
   208 	return TUnicode(aChar).Fold(TChar::EFoldStandard,GetLocaleCharSet()->iCharDataSet);
       
   209 	}
       
   210 
       
   211 
       
   212 
       
   213 
       
   214 // Convert to lower case.
       
   215 EXPORT_C TUint User::LowerCase(TUint aChar)
       
   216 /**
       
   217 Converts the specified character to lower case.
       
   218 
       
   219 The result of the conversion depends on the locale and on whether this is
       
   220 a UNICODE build or not.
       
   221 
       
   222 Note that for a non-UNICODE build, if the binary value of the character
       
   223 aChar is greater than or equal to 0x100, then the character returned is
       
   224 the same as the character passed to the function.
       
   225 
       
   226 @param aChar The character to be converted to lower case.
       
   227 
       
   228 @return The lower case character.
       
   229 */
       
   230 	{
       
   231 	// ASCII chars excluding 'i's can be handled by naive folding
       
   232 	if (aChar < 0x80 && aChar != 'I')
       
   233 		return (aChar >= 'A' && aChar <= 'Z') ? (aChar | 0x0020) : aChar;
       
   234 	else
       
   235 		return TUnicode(aChar).GetLowerCase(GetLocaleCharSet()->iCharDataSet);
       
   236 	}
       
   237 
       
   238 
       
   239 
       
   240 
       
   241 // Convert to upper case.
       
   242 EXPORT_C TUint User::UpperCase(TUint aChar)
       
   243 /**
       
   244 Converts a specified character to upper case.
       
   245 
       
   246 The result of the conversion depends on the locale and on whether this is
       
   247 a UNICODE build or not.
       
   248 
       
   249 Note that for a non UNICODE build, if the binary value of the character aChar
       
   250 is greater than or equal to 0x100, then the character returned is the same as
       
   251 the character passed to the function.
       
   252 
       
   253 @param aChar The character to be converted to upper case.
       
   254 
       
   255 @return The upper case character.
       
   256 */
       
   257 	{
       
   258 	// ASCII chars excluding 'i's can be handled by naive folding
       
   259 	if (aChar < 0x80 && aChar != 'i')
       
   260 		return (aChar >= 'a' && aChar <= 'z') ? (aChar & ~0x0020) : aChar;
       
   261 	else
       
   262 		return TUnicode(aChar).GetUpperCase(GetLocaleCharSet()->iCharDataSet);
       
   263 	}
       
   264 
       
   265 
       
   266 
       
   267 
       
   268 // Return the title case version of a character, which is the case of composite characters like Dz.
       
   269 EXPORT_C TUint User::TitleCase(TUint aChar)
       
   270 /**
       
   271 Converts a specified character to its title case version.
       
   272 
       
   273 @param aChar The character to be converted.
       
   274 
       
   275 @return The converted character.
       
   276 */
       
   277 	{
       
   278 	return TUnicode(aChar).GetTitleCase(GetLocaleCharSet()->iCharDataSet);
       
   279 	}
       
   280 
       
   281 
       
   282 
       
   283 
       
   284 EXPORT_C TUint TChar::GetUpperCase() const
       
   285 /**
       
   286 Gets the character value after conversion to uppercase or the character's 
       
   287 own value, if no uppercase form exists.
       
   288 
       
   289 The character object itself is not changed.
       
   290 
       
   291 @return The character value after conversion to uppercase.
       
   292 */
       
   293 	{
       
   294 	return User::UpperCase(iChar);
       
   295 	}
       
   296 
       
   297 
       
   298 
       
   299 
       
   300 EXPORT_C TUint TChar::GetLowerCase() const
       
   301 /**
       
   302 Gets the character value after conversion to lowercase or the character's 
       
   303 own value, if no lowercase form exists.
       
   304 
       
   305 The character object itself is not changed.
       
   306 
       
   307 @return The character value after conversion to lowercase.
       
   308 */
       
   309 	{
       
   310 	return User::LowerCase(iChar);
       
   311 	}
       
   312 
       
   313 
       
   314 
       
   315 
       
   316 EXPORT_C TUint TChar::GetTitleCase() const
       
   317 /**
       
   318 Gets the character value after conversion to titlecase or the character's 
       
   319 own value, if no titlecase form exists.
       
   320 
       
   321 The titlecase form of a character is identical to its uppercase form unless 
       
   322 a specific titlecase form exists.
       
   323 
       
   324 @return The value of the character value after conversion to titlecase form.
       
   325 */
       
   326 	{
       
   327 	return User::TitleCase(iChar);
       
   328 	}
       
   329 
       
   330 
       
   331 
       
   332 
       
   333 EXPORT_C TBool TChar::IsLower() const
       
   334 /**
       
   335 Tests whether the character is lowercase.
       
   336 
       
   337 @return True, if the character is lowercase; false, otherwise.
       
   338 */
       
   339 	{
       
   340 	return GetCategory() == TChar::ELlCategory;
       
   341 	}
       
   342 
       
   343 
       
   344 
       
   345 
       
   346 EXPORT_C TBool TChar::IsUpper() const
       
   347 /**
       
   348 Tests whether the character is uppercase.
       
   349 
       
   350 @return True, if the character is uppercase; false, otherwise.
       
   351 */
       
   352 	{
       
   353 	return GetCategory() == TChar::ELuCategory;
       
   354 	}
       
   355 
       
   356 
       
   357 
       
   358 // Return TRUE if the character is title case, which is the case of composite characters like Dz.
       
   359 EXPORT_C TBool TChar::IsTitle() const
       
   360 /**
       
   361 Tests whether this character is in titlecase.
       
   362 
       
   363 @return True, if this character is in titlecase; false, otherwise.
       
   364 */
       
   365 	{
       
   366 	return GetCategory() == TChar::ELtCategory;
       
   367 	}
       
   368 
       
   369 
       
   370 
       
   371 
       
   372 EXPORT_C TBool TChar::IsAlpha() const
       
   373 /**
       
   374 Tests whether the character is alphabetic.
       
   375 
       
   376 For Unicode, the function returns TRUE for all letters, including those from 
       
   377 syllabaries and ideographic scripts. The function returns FALSE for letter-like 
       
   378 characters that are in fact diacritics. Specifically, the function returns 
       
   379 TRUE for categories: ELuCategory, ELtCategory, ELlCategory, and ELoCategory; 
       
   380 it returns FALSE for all other categories including ELmCategory.
       
   381 
       
   382 @return True, if the character is alphabetic; false, otherwise.
       
   383 
       
   384 @see TChar::IsAlphaDigit()
       
   385 @see TChar::TCategory
       
   386 */
       
   387 	{
       
   388 	return GetCategory() <= TChar::EMaxLetterOrLetterModifierCategory;
       
   389 	}
       
   390 
       
   391 
       
   392 
       
   393 
       
   394 EXPORT_C TBool TChar::IsDigit() const
       
   395 /**
       
   396 Tests whether the character is a standard decimal digit.
       
   397 
       
   398 For Unicode, this function returns TRUE only
       
   399 for the digits '0'...'9' (U+0030...U+0039), 
       
   400 not for other digits in scripts like Arabic, Tamil, etc.
       
   401 
       
   402 @return True, if the character is a standard decimal digit; false, otherwise.
       
   403 
       
   404 @see TChar::GetCategory()
       
   405 @see TChar::GetNumericValue
       
   406 */
       
   407 	{
       
   408 	return iChar >= '0' && iChar <= '9'; // standard decimal digits only
       
   409 	}
       
   410 
       
   411 
       
   412 
       
   413 
       
   414 EXPORT_C TBool TChar::IsAlphaDigit() const
       
   415 /**
       
   416 Tests whether the character is alphabetic or a decimal digit.
       
   417 
       
   418 It is identical to (IsAlpha()||IsDigit()).
       
   419 
       
   420 @return True, if the character is alphabetic or a decimal digit; false, otherwise.
       
   421 
       
   422 @see TChar::IsAlpha()
       
   423 @see TChar::IsDigit()
       
   424 */
       
   425 	{
       
   426 	TInt cat = (TInt)GetCategory();
       
   427 	return cat <= TChar::EMaxLetterOrLetterModifierCategory ||
       
   428 		   (iChar < 256 && cat == TChar::ENdCategory);	// accept any letter, but accept only standard digits
       
   429 	}
       
   430 
       
   431 
       
   432 
       
   433 
       
   434 EXPORT_C TBool TChar::IsHexDigit() const
       
   435 /** 
       
   436 Tests whether the character is a hexadecimal digit (0-9, a-f, A-F).
       
   437 
       
   438 @return True, if the character is a hexadecimal digit; false, otherwise.
       
   439 */
       
   440 	{
       
   441 	/*
       
   442 	The following code will actually run faster than the non-Unicode version, which needs
       
   443 	to call the Exec function.
       
   444 	*/
       
   445 	return iChar <= 'f' && iChar >= '0' &&
       
   446 		   (iChar <= '9' || iChar >= 'a' || (iChar >= 'A' && iChar <= 'F'));	// only standard hex digits will do
       
   447 	}
       
   448 
       
   449 
       
   450 
       
   451 
       
   452 EXPORT_C TBool TChar::IsSpace() const
       
   453 /**
       
   454 Tests whether the character is a white space character.
       
   455 
       
   456 White space includes spaces, tabs and separators.
       
   457 
       
   458 For Unicode, the function returns TRUE for all characters in the categories: 
       
   459 EZsCategory, EZlCategory and EZpCategory, and also for the characters 0x0009 
       
   460 (horizontal tab), 0x000A (linefeed), 0x000B (vertical tab), 0x000C (form feed), 
       
   461 and 0x000D (carriage return).
       
   462 
       
   463 @return True, if the character is white space; false, otherwise.
       
   464 
       
   465 @see TChar::TCategory
       
   466 */
       
   467 	{
       
   468 	/*
       
   469 	The Unicode characters 0009 .. 000D (tab, linefeed, vertical tab, formfeed, carriage return)
       
   470 	have the category Cc (control); however, we want to avoid breaking traditional programs
       
   471 	by getting IsSpace() to return TRUE for them.
       
   472 	*/
       
   473 	return (iChar <= 0x000D && iChar >= 0x0009) ||
       
   474 		   (GetCategory() & 0xF0) == TChar::ESeparatorGroup;
       
   475 	}
       
   476 
       
   477 
       
   478 
       
   479 
       
   480 EXPORT_C TBool TChar::IsPunctuation() const
       
   481 /**
       
   482 Tests whether the character is a punctuation character.
       
   483 
       
   484 For Unicode, punctuation characters are any character in the categories:
       
   485 EPcCategory, EPdCategory, EPsCategory, EPeCategory, EPiCategory,
       
   486 EPfCategory, EPoCategory.
       
   487 
       
   488 @return True, if the character is punctuation; false, otherwise.
       
   489 
       
   490 @see TChar::TCategory
       
   491 */
       
   492 	{
       
   493 	return (GetCategory() & 0xF0) == TChar::EPunctuationGroup;
       
   494 	}
       
   495 
       
   496 
       
   497 
       
   498 
       
   499 EXPORT_C TBool TChar::IsGraph() const
       
   500 /**
       
   501 Tests whether the character is a graphic character.
       
   502 
       
   503 For Unicode, graphic characters include printable characters but not the space 
       
   504 character. Specifically, graphic characters are any character except those 
       
   505 in categories: EZsCategory,EZlCategory,EZpCategory, ECcCategory,ECfCategory,
       
   506 ECsCategory, ECoCategory, and ,ECnCategory.
       
   507 
       
   508 Note that for ISO Latin-1, all alphanumeric and punctuation characters are 
       
   509 graphic.
       
   510 
       
   511 @return True, if the character is a graphic character; false, otherwise.
       
   512 
       
   513 @see TChar::TCategory
       
   514 */
       
   515 	{
       
   516 	TUint type = TUnicode(iChar).GetCategory(0);
       
   517 	return type <= TChar::EMaxGraphicCategory ||
       
   518 		(type == TChar::ECoCategory && IsPUAPrintable(iChar));
       
   519 	}
       
   520 
       
   521 
       
   522 
       
   523 
       
   524 EXPORT_C TBool TChar::IsPrint() const
       
   525 /**
       
   526 Tests whether the character is a printable character.
       
   527 
       
   528 For Unicode, printable characters are any character except those in categories: 
       
   529 ECcCategory, ECfCategory, ECsCategory, ECoCategory and ECnCategory.
       
   530 
       
   531 Note that for ISO Latin-1, all alphanumeric and punctuation characters, plus 
       
   532 space, are printable.
       
   533 
       
   534 @return True, if the character is printable; false, otherwise.
       
   535 
       
   536 @see TChar::TCategory
       
   537 */
       
   538 	{
       
   539 	TUint type = TUnicode(iChar).GetCategory(0);
       
   540 	return type <= TChar::EMaxPrintableCategory ||
       
   541 		(type == TChar::ECoCategory && IsPUAPrintable(iChar));
       
   542 	}
       
   543 
       
   544 
       
   545 
       
   546 
       
   547 EXPORT_C TBool TChar::IsControl() const
       
   548 /**
       
   549 Tests whether the character is a control character.
       
   550 
       
   551 For Unicode, the function returns TRUE for all characters in the categories: 
       
   552 ECcCategory, ECfCategory, ECsCategory, ECoCategory and ECnCategoryCc.
       
   553 
       
   554 @return True, if the character is a control character; false, otherwise.
       
   555 
       
   556 @see TChar::TCategory
       
   557 */
       
   558 	{
       
   559 	return GetCategory() == TChar::ECcCategory;
       
   560 	}
       
   561 
       
   562 
       
   563 
       
   564 
       
   565 EXPORT_C TBool TChar::IsAssigned() const
       
   566 /**
       
   567 Tests whether this character has an assigned meaning in the Unicode encoding.
       
   568 
       
   569 All characters outside the range 0x0000 - 0xFFFF are unassigned and there 
       
   570 are also many unassigned characters within the Unicode range.
       
   571 
       
   572 Locales can change the assigned/unassigned status of characters. This means 
       
   573 that the precise behaviour of this function is locale-dependent.
       
   574 
       
   575 @return True, if this character has an assigned meaning; false, otherwise.
       
   576 */
       
   577 	{
       
   578 	return GetCategory() <= TChar::EMaxAssignedCategory;
       
   579 	}
       
   580 
       
   581 
       
   582 
       
   583 
       
   584 EXPORT_C void TChar::GetInfo(TCharInfo& aInfo) const
       
   585 /** 
       
   586 Gets this character;s standard category information. 
       
   587 
       
   588 This includes everything except its CJK width and decomposition, if any.
       
   589 
       
   590 @param aInfo On return, contains the character's standard category information.
       
   591 */
       
   592 	{
       
   593 	TUnicode(iChar).GetInfo(aInfo,GetLocaleCharSet()->iCharDataSet);
       
   594 	}
       
   595 
       
   596 
       
   597 
       
   598 
       
   599 EXPORT_C TChar::TCategory TChar::GetCategory() const
       
   600 /**
       
   601 Gets this character's Unicode category.
       
   602 
       
   603 @return This character's Unicode category.
       
   604 */
       
   605 	{
       
   606 	//for unicode non private user area just use the default charset
       
   607 	if (iChar>=0xE000 && iChar<=0xF8FF)
       
   608 		return TUnicode(iChar).GetCategory(GetLocaleCharSet()->iCharDataSet);
       
   609 	else
       
   610 		return TUnicode(iChar).GetCategory(GetLocaleDefaultCharSet()->iCharDataSet);
       
   611 	}
       
   612 
       
   613 
       
   614 
       
   615 
       
   616 EXPORT_C TChar::TBdCategory TChar::GetBdCategory() const
       
   617 /**
       
   618 Gets the bi-directional category of a character.
       
   619 
       
   620 For more information on the bi-directional algorithm, see Unicode Technical 
       
   621 Report No. 9 available at: http://www.unicode.org/unicode/reports/tr9/.
       
   622 
       
   623 @return The character's bi-directional category.
       
   624 */
       
   625 	{
       
   626 	return TUnicode(iChar).GetBdCategory(GetLocaleCharSet()->iCharDataSet);
       
   627 	}
       
   628 
       
   629 
       
   630 
       
   631 
       
   632 EXPORT_C TInt TChar::GetCombiningClass() const
       
   633 /**
       
   634 Gets this character's combining class.
       
   635 
       
   636 Note that diacritics and other combining characters have non-zero combining 
       
   637 classes.
       
   638 
       
   639 @return The combining class.
       
   640 */
       
   641 	{
       
   642 	//for unicode non private user area just use the default charset
       
   643 	if (iChar>=0xE000 && iChar<=0xF8FF)
       
   644 		return TUnicode(iChar).GetCombiningClass(GetLocaleCharSet()->iCharDataSet);
       
   645 	else
       
   646 		return TUnicode(iChar).GetCombiningClass(GetLocaleDefaultCharSet()->iCharDataSet);
       
   647 	}
       
   648 
       
   649 
       
   650 
       
   651 
       
   652 EXPORT_C TBool TChar::IsMirrored() const
       
   653 /**
       
   654 Tests whether this character has the mirrored property.
       
   655 
       
   656 Mirrored characters, like ( ) [ ] < >, change direction according to the
       
   657 directionality of the surrounding characters. For example, an opening
       
   658 parenthesis 'faces right' in Hebrew or Arabic, and to say that 2 < 3 you would
       
   659 have to say that 3 > 2, where the '>' is, in this example, a less-than sign to
       
   660 be read right-to-left.
       
   661 
       
   662 @return True, if this character has the mirrored property; false, otherwise.
       
   663 */
       
   664 	{
       
   665 	return TUnicode(iChar).IsMirrored(GetLocaleCharSet()->iCharDataSet);
       
   666 	}
       
   667 
       
   668 
       
   669 
       
   670 
       
   671 EXPORT_C TInt TChar::GetNumericValue() const
       
   672 /**
       
   673 Gets the integer numeric value of this character.
       
   674 
       
   675 Numeric values need not be in the range 0..9; the Unicode character set
       
   676 includes various other numeric characters such as the Roman and Tamil numerals
       
   677 for 500, 1000, etc.
       
   678 
       
   679 @return The numeric value: -1 if the character has no integer numeric 
       
   680         value,-2 if the character has a fractional numeric value.
       
   681 */
       
   682 	{
       
   683 	return TUnicode(iChar).GetNumericValue(GetLocaleCharSet()->iCharDataSet);
       
   684 	}
       
   685 
       
   686 
       
   687 
       
   688 
       
   689 EXPORT_C TChar::TCjkWidth TChar::GetCjkWidth() const
       
   690 /**
       
   691 Gets the Chinese, Japanese, Korean (CJK) notional width.
       
   692 
       
   693 Some display systems used in East Asia display characters on a grid of
       
   694 fixed-width character cells like the standard MSDOS display mode.
       
   695 
       
   696 Some characters, e.g. the Japanese katakana syllabary, take up a single
       
   697 character cell and some characters, e.g., kanji, Chinese characters used in
       
   698 Japanese, take up two. These are called half-width and full-width characters.
       
   699 This property is fixed and cannot be overridden for particular locales.
       
   700 
       
   701 For more information on returned widths, see Unicode Technical Report 11 on 
       
   702 East Asian Width available at: http://www.unicode.org/unicode/reports/tr11/
       
   703 
       
   704 @return The notional width of an east Asian character.
       
   705 */
       
   706 	{
       
   707 	return TUnicode(iChar).GetCjkWidth();
       
   708 	}
       
   709 
       
   710 
       
   711 
       
   712 
       
   713 /**
       
   714 Composes a string of Unicode characters to produce a single character result.
       
   715 
       
   716 For example, 0061 ('a') and 030A (combining ring above) compose to give 00E5 
       
   717 ('a' with ring above).
       
   718 
       
   719 A canonical decomposition is a relationship between a string of characters -  
       
   720 usually a base character and one or more diacritics - and a composed character. 
       
   721 The Unicode standard requires that compliant software treats composed
       
   722 characters identically with their canonical decompositions. The mappings used
       
   723 by these functions are fixed and cannot be overridden for particular locales.
       
   724 
       
   725 @param aResult If successful, the composed character value. If unsuccessful, 
       
   726                this value contains 0xFFFF.
       
   727 @param aSource String of source Unicode characters.
       
   728 
       
   729 @return True, if the compose operation is successful in combining the entire
       
   730 		sequence of characters in the descriptor into a single compound
       
   731 		character; false, otherwise.
       
   732 */
       
   733 
       
   734 EXPORT_C TBool TChar::Compose(TUint& aResult,const TDesC16& aSource)
       
   735 	{
       
   736 	aResult = 0xFFFF;
       
   737 	if(aSource.Length() > 0)
       
   738 		{
       
   739 		TChar combined;
       
   740 		if(::CombineAsMuchAsPossible(aSource, combined) == aSource.Length())
       
   741 			{
       
   742 			aResult = (TUint)combined;
       
   743 			return ETrue;
       
   744 			}
       
   745 		}
       
   746 	return EFalse;
       
   747 	}
       
   748 
       
   749 
       
   750 
       
   751 
       
   752 /**
       
   753 Maps this character to its maximal canonical decomposition.
       
   754 
       
   755 For example, 01E1 ('a' with dot above and macron) decomposes into 0061 ('a') 
       
   756 0307 (dot) and 0304 (macron).
       
   757 
       
   758 Note that this function is used during collation, as performed by
       
   759 the Mem::CompareC() function, to convert the compared strings to their maximal
       
   760 canonical decompositions.
       
   761 
       
   762 @param aResult If successful, the descriptor represents the canonical decomposition 
       
   763                of this character. If unsuccessful, the descriptor is empty.
       
   764                
       
   765 @return True if decomposition is successful; false, otherwise.
       
   766 
       
   767 @see Mem::CompareC()
       
   768 @see TChar::Compose()
       
   769 */
       
   770 EXPORT_C TBool TChar::Decompose(TPtrC16& aResult) const
       
   771 	{
       
   772 	return ::DecomposeChar(iChar, aResult);
       
   773 	}
       
   774 
       
   775 
       
   776 
       
   777 #ifndef __TOOLS2__
       
   778 EXPORT_C TInt TFindChunk::Next(TFullName &aResult)
       
   779 /**
       
   780 Finds the full name of the next chunk which matches the match pattern.
       
   781 
       
   782 @param aResult A reference to a TBuf descriptor with a defined maximum length. 
       
   783                If a matching chunk is found, its full name is set into
       
   784                this descriptor.
       
   785                If no matching chunk is found, the descriptor length is set
       
   786                to zero.
       
   787                
       
   788 @return KErrNone, if a matching chunk is found;
       
   789         KErrNotFound otherwise.
       
   790 */
       
   791 	{
       
   792 	return NextObject(aResult,EChunk);
       
   793 	}
       
   794 
       
   795 
       
   796 
       
   797 
       
   798 
       
   799 EXPORT_C TUint8 * RChunk::Base() const
       
   800 /**
       
   801 Gets a pointer to the base of the chunk's reserved region.
       
   802 
       
   803 @return A pointer to the base of the chunk's reserved region.
       
   804 */
       
   805 	{
       
   806 
       
   807 	return(Exec::ChunkBase(iHandle));
       
   808 	}
       
   809 
       
   810 
       
   811 
       
   812 
       
   813 EXPORT_C TInt RChunk::Size() const
       
   814 /**
       
   815 Gets the current size of this chunk's committed region.
       
   816 
       
   817 @return The size of the chunk's committed region.
       
   818 */
       
   819 	{
       
   820 
       
   821 	return(Exec::ChunkSize(iHandle));
       
   822 	}
       
   823 
       
   824 
       
   825 
       
   826 
       
   827 EXPORT_C TInt RChunk::Bottom() const
       
   828 /**
       
   829 Gets the offset of the bottom of the double ended chunk's committed region 
       
   830 from the base of the chunk's reserved region.
       
   831 
       
   832 Note that the lowest valid address in a double ended chunk is the sum of the 
       
   833 base of the chunk's reserved region plus the value of Bottom().
       
   834 
       
   835 @return The offset of the bottom of the chunk's committed region from the 
       
   836         base of the chunk's reserved region.
       
   837 */
       
   838 	{
       
   839 
       
   840 	return(Exec::ChunkBottom(iHandle));
       
   841 	}
       
   842 
       
   843 
       
   844 
       
   845 
       
   846 EXPORT_C TInt RChunk::Top() const
       
   847 /**
       
   848 Gets the offset of the top of the double ended chunk's committed region 
       
   849 from the base of the chunk's reserved region.
       
   850 
       
   851 Note that the highest valid address in a double ended chunk is the the sum 
       
   852 of the base of the chunk's reserved region plus the value of Top() - 1.
       
   853 
       
   854 @return The offset of the top of the chunk's committed region from the base 
       
   855         of the chunk's reserved region.
       
   856 */
       
   857 	{
       
   858 
       
   859 	return(Exec::ChunkTop(iHandle));
       
   860 	}
       
   861 
       
   862 
       
   863 
       
   864 
       
   865 EXPORT_C TInt RChunk::MaxSize() const
       
   866 /**
       
   867 Gets the maximum size of this chunk.
       
   868 
       
   869 This maximum size of this chunk is set when the chunk is created.
       
   870 
       
   871 @return The maximum size of this chunk.
       
   872 */
       
   873 	{
       
   874 
       
   875 	return(Exec::ChunkMaxSize(iHandle));
       
   876 	}
       
   877 
       
   878 
       
   879 
       
   880 /**
       
   881 Finds the full name of the next LDD factory object which matches the match pattern.
       
   882 
       
   883 @param aResult A reference to a TBuf descriptor with a defined maximum length. 
       
   884                If a matching LDD factory object is found, its full name is set into
       
   885                this descriptor.
       
   886                If no matching LDD factory object is found, the descriptor length is set
       
   887                to zero.
       
   888                
       
   889 @return KErrNone, if a matching LDD factory object is found;
       
   890         KErrNotFound otherwise.
       
   891 */
       
   892 EXPORT_C TInt TFindLogicalDevice::Next(TFullName &aResult)
       
   893 	{
       
   894 	return NextObject(aResult,ELogicalDevice);
       
   895 	}
       
   896 
       
   897 /**
       
   898 Finds the full name of the next PDD factory object which matches the match pattern.
       
   899 
       
   900 @param aResult A reference to a TBuf descriptor with a defined maximum length. 
       
   901                If a matching PDD factory object is found, its full name is set into
       
   902                this descriptor.
       
   903                If no matching PDD factory object is found, the descriptor length is set
       
   904                to zero.
       
   905                
       
   906 @return KErrNone, if a matching PDD factory object is found;
       
   907         KErrNotFound otherwise.
       
   908 */
       
   909 EXPORT_C TInt TFindPhysicalDevice::Next(TFullName &aResult)
       
   910 	{
       
   911 	return NextObject(aResult,EPhysicalDevice);
       
   912 	}
       
   913 
       
   914 /**
       
   915 Gets the device capabilities.
       
   916 
       
   917 @param aDes	A descriptor into which capability's information is to be written.
       
   918 */
       
   919 EXPORT_C void RDevice::GetCaps(TDes8 &aDes) const
       
   920 	{
       
   921 
       
   922 	Exec::LogicalDeviceGetCaps(iHandle,aDes);
       
   923 	}
       
   924 
       
   925 /**
       
   926 Checks if a device supports a particular version.
       
   927 
       
   928 @param aVer	The requested device version.
       
   929 
       
   930 @return	ETrue if supported, EFalse if not.
       
   931 */
       
   932 EXPORT_C TBool RDevice::QueryVersionSupported(const TVersion &aVer) const
       
   933 	{
       
   934 
       
   935 	return(Exec::LogicalDeviceQueryVersionSupported(iHandle,aVer));
       
   936 	}
       
   937 
       
   938 /**
       
   939 Checks if a specified unit number, additional info and a specific PDD is supported.
       
   940 
       
   941 @param aUnit			The requested unit number.
       
   942 @param aPhysicalDevice	The requested PDD name.
       
   943 @param anInfo			The additional information.
       
   944 
       
   945 @return ETrue if supported, EFalse if not. 
       
   946 */
       
   947 EXPORT_C TBool RDevice::IsAvailable(TInt aUnit, const TDesC* aPhysicalDevice, const TDesC8* anInfo) const
       
   948 	{
       
   949 	TInt r;
       
   950 	if(aPhysicalDevice)
       
   951 		{
       
   952 		TBuf8<KMaxKernelName> physicalDevice;
       
   953 		physicalDevice.Copy(*aPhysicalDevice);
       
   954 		r = Exec::LogicalDeviceIsAvailable(iHandle,aUnit,(TDesC8*)&physicalDevice,anInfo);
       
   955 		}
       
   956 	else
       
   957 		r = Exec::LogicalDeviceIsAvailable(iHandle,aUnit,(TDesC8*)NULL,anInfo);
       
   958 
       
   959 	return r;
       
   960 	}
       
   961 
       
   962 
       
   963 /**
       
   964 Queues an asynchronous request for the device driver, taking no parameters.
       
   965  
       
   966 The request is handled on the kernel-side by the logical channel's
       
   967 DLogicalChannelBase::Request().
       
   968 
       
   969 Outstanding requests can be cancelled by calling DoCancel().
       
   970 
       
   971 @param aReqNo   A number identifying the request to the logical channel. 
       
   972 @param aStatus  The request status object for this request.     
       
   973 */
       
   974 EXPORT_C void RBusLogicalChannel::DoRequest(TInt aReqNo,TRequestStatus &aStatus)
       
   975 	{
       
   976 
       
   977 	TAny *a[2];
       
   978 	a[0]=NULL;
       
   979 	a[1]=NULL;
       
   980 	aStatus=KRequestPending;
       
   981 	Exec::ChannelRequest(iHandle,~aReqNo,&aStatus,&a[0]);
       
   982 	}
       
   983 
       
   984 
       
   985 
       
   986 
       
   987 /**
       
   988 Queues an asynchronous request for the device driver, taking one parameter.
       
   989  
       
   990 The request is handled on the kernel-side by the logical channel's
       
   991 DLogicalChannelBase::Request().
       
   992 
       
   993 Outstanding requests can be cancelled by calling DoCancel().
       
   994 
       
   995 @param aReqNo   A number identifying the request to the logical channel. 
       
   996 @param aStatus  The request status object for this request.
       
   997 @param a1       A 32-bit value passed to the kernel-side. Its meaning depends
       
   998                 on the device driver requirements.           
       
   999 */
       
  1000 EXPORT_C void RBusLogicalChannel::DoRequest(TInt aReqNo,TRequestStatus &aStatus,TAny *a1)
       
  1001 	{
       
  1002 
       
  1003 	TAny *a[2];
       
  1004 	a[0]=a1;
       
  1005 	a[1]=NULL;
       
  1006 	aStatus=KRequestPending;
       
  1007 	Exec::ChannelRequest(iHandle,~aReqNo,&aStatus,&a[0]);
       
  1008 	}
       
  1009 
       
  1010 
       
  1011 
       
  1012 
       
  1013 /**
       
  1014 Queues an asynchronous request for the device driver, taking two parameters.
       
  1015  
       
  1016 The request is handled on the kernel-side by the logical channel's
       
  1017 DLogicalChannelBase::Request().
       
  1018 
       
  1019 Outstanding requests can be cancelled by calling DoCancel().
       
  1020 
       
  1021 @param aReqNo   A number identifying the request to the logical channel. 
       
  1022 @param aStatus  The request status object for this request.
       
  1023 @param a1       A 32-bit value passed to the kernel-side. Its meaning depends
       
  1024                 on the device driver requirements.           
       
  1025 @param a2       A 32-bit value passed to the kernel-side. Its meaning depends
       
  1026                 on the device driver requirements.           
       
  1027 */
       
  1028 EXPORT_C void RBusLogicalChannel::DoRequest(TInt aReqNo,TRequestStatus &aStatus,TAny *a1,TAny *a2)
       
  1029 	{
       
  1030 
       
  1031 	TAny *a[2];
       
  1032 	a[0]=a1;
       
  1033 	a[1]=a2;
       
  1034 	aStatus=KRequestPending;
       
  1035 	Exec::ChannelRequest(iHandle,~aReqNo,&aStatus,&a[0]);
       
  1036 	}
       
  1037 
       
  1038 
       
  1039 
       
  1040 
       
  1041 /**
       
  1042 Cancels one or more outstanding asynchronous requests.
       
  1043 
       
  1044 All outstanding requests complete with KErrCancel.
       
  1045 
       
  1046 @param aRequestMask A set of bits identifying the requests to be cancelled.
       
  1047                     Each bit can be used to identify a separate outstanding
       
  1048                     request. It is up to the driver to define how the bits map
       
  1049                     to those outstanding requests.
       
  1050 */
       
  1051 EXPORT_C void RBusLogicalChannel::DoCancel(TUint aRequestMask)
       
  1052 	{
       
  1053 
       
  1054 	Exec::ChannelRequest(iHandle,KMaxTInt,(TAny*)aRequestMask,0);
       
  1055 	}
       
  1056 
       
  1057 
       
  1058 
       
  1059 
       
  1060 /**
       
  1061 Makes a synchronous request to the device driver, taking no parameters.
       
  1062 
       
  1063 This function does not return until the request has completed, successfully
       
  1064 or otherwise.
       
  1065 
       
  1066 @param aFunction A number identifying the request.
       
  1067 
       
  1068 @return KErrNone, if successful; otherwise one of the other system-wide
       
  1069         error codes.
       
  1070         The value returned depends on the implementation of the device driver.
       
  1071 */
       
  1072 EXPORT_C TInt RBusLogicalChannel::DoControl(TInt aFunction)
       
  1073 	{
       
  1074 
       
  1075 	return Exec::ChannelRequest(iHandle,aFunction,NULL,NULL);
       
  1076 	}
       
  1077 
       
  1078 
       
  1079 
       
  1080 
       
  1081 /**
       
  1082 Makes a synchronous request to the device driver, taking one parameter.
       
  1083 
       
  1084 This function does not return until the request has completed, successfully
       
  1085 or otherwise.
       
  1086 
       
  1087 @param aFunction A number identifying the request.
       
  1088 @param a1        A 32-bit value passed to the kernel-side. Its meaning depends
       
  1089                  on the device driver requirements.           
       
  1090 
       
  1091 @return KErrNone, if successful; otherwise one of the other system-wide
       
  1092         error codes.
       
  1093         The value returned depends on the implementation of the device driver.
       
  1094 */
       
  1095 EXPORT_C TInt RBusLogicalChannel::DoControl(TInt aFunction,TAny *a1)
       
  1096 	{
       
  1097 
       
  1098 	return Exec::ChannelRequest(iHandle,aFunction,a1,NULL);
       
  1099 	}
       
  1100 
       
  1101 
       
  1102 
       
  1103 
       
  1104 /**
       
  1105 Makes a synchronous request to the device driver, taking two parameters.
       
  1106 
       
  1107 This function does not return until the request has completed, successfully
       
  1108 or otherwise.
       
  1109 
       
  1110 @param aFunction A number identifying the request.
       
  1111 @param a1        A 32-bit value passed to the kernel-side. Its meaning depends
       
  1112                  on the device driver requirements.           
       
  1113 @param a2        A 32-bit value passed to the kernel-side. Its meaning depends
       
  1114                  on the device driver requirements.           
       
  1115 
       
  1116 @return KErrNone, if successful; otherwise one of the other system-wide
       
  1117         error codes.
       
  1118         The value returned depends on the implementation of the device driver.
       
  1119 */
       
  1120 EXPORT_C TInt RBusLogicalChannel::DoControl(TInt aFunction,TAny *a1,TAny *a2)
       
  1121 	{
       
  1122 
       
  1123 	return Exec::ChannelRequest(iHandle,aFunction,a1,a2);
       
  1124 	}
       
  1125 
       
  1126 
       
  1127 
       
  1128 
       
  1129 EXPORT_C void User::WaitForAnyRequest()
       
  1130 /**
       
  1131 Waits for any asynchronous request to complete.
       
  1132 
       
  1133 The current thread waits on its request semaphore.
       
  1134 
       
  1135 The function completes, and control returns to the caller when the current 
       
  1136 thread's request semaphore is signalled by any of the service providers which 
       
  1137 handle these asynchronous requests.
       
  1138 
       
  1139 The request status of all outstanding asynchronous requests must be examined 
       
  1140 to determine which request is complete.
       
  1141 
       
  1142 @see TRequestStatus
       
  1143 */
       
  1144 	{
       
  1145 
       
  1146 	Exec::WaitForAnyRequest();
       
  1147 	}
       
  1148 #endif // __TOOLS2__
       
  1149 
       
  1150 
       
  1151 
       
  1152 EXPORT_C void User::WaitForRequest(TRequestStatus &aStatus)
       
  1153 /**
       
  1154 Waits for a specific asynchronous request to complete.
       
  1155 
       
  1156 The current thread waits on its request semaphore.
       
  1157 
       
  1158 The function completes and control returns to the caller when the current 
       
  1159 thread's request semaphore is signalled by the service provider handling the 
       
  1160 request associated with aStatus. Before signalling, the service provider sets 
       
  1161 an appropriate value in aStatus, other than KRequestPending.
       
  1162 
       
  1163 Note that if other asynchronous requests complete before the one associated
       
  1164 with aStatus, the request semaphore is adjusted so that knowledge of their
       
  1165 completion is not lost. In this a case, a subsequent call to
       
  1166 User::WaitForAnyRequest() or User::WaitForRequest() will complete and return
       
  1167 immediately.
       
  1168 
       
  1169 @param aStatus A reference to the request status object associated with the 
       
  1170                specific asynchronous request.
       
  1171                
       
  1172 @see KRequestPending
       
  1173 */
       
  1174 	{
       
  1175 #ifndef __TOOLS2__
       
  1176 	TInt i=(-1);
       
  1177 	do
       
  1178 		{
       
  1179 		i++;
       
  1180 		Exec::WaitForAnyRequest();
       
  1181 		} while (aStatus==KRequestPending);
       
  1182 	if (i)
       
  1183 		Exec::RequestSignal(i);
       
  1184 #else
       
  1185 	// There's been no need to implement an active scheduler yet for TOOLS2
       
  1186 #endif // __TOOLS2__
       
  1187 	}
       
  1188 
       
  1189 
       
  1190 
       
  1191 #ifndef __TOOLS2__
       
  1192 EXPORT_C void User::WaitForRequest(TRequestStatus &aStatus1,TRequestStatus &aStatus2)
       
  1193 /**
       
  1194 Waits for either of two specific asynchronous requests to complete.
       
  1195 
       
  1196 The current thread waits on its request semaphore.
       
  1197 
       
  1198 The function completes and control returns to the caller when the current 
       
  1199 thread's request semaphore is signalled by either the service provider handling 
       
  1200 the request associated with aStatus1 or the service provider handling the 
       
  1201 request associated with aStatus2. Before signalling, the completing service 
       
  1202 provider sets an appropriate value in the status object, other
       
  1203 than KRequestPending.
       
  1204 
       
  1205 Note that if other asynchronous requests complete before the ones associated
       
  1206 with aStatus1 and aStatus2, the request semaphore is adjusted so that knowledge
       
  1207 of their completion is not lost. In this a case, a subsequent call to
       
  1208 User::WaitForAnyRequest() or User::WaitForRequest() will complete and return
       
  1209 immediately.
       
  1210 
       
  1211 @param aStatus1 A reference to the request status object associated with the 
       
  1212                 first specific asynchronous request.
       
  1213 @param aStatus2 A reference to the request status object associated with the 
       
  1214                 second specific asynchronous request.
       
  1215 
       
  1216 @see KRequestPending                
       
  1217 */
       
  1218 	{
       
  1219 
       
  1220 	TInt i=(-1);
       
  1221 	do
       
  1222 		{
       
  1223 		i++;
       
  1224 		Exec::WaitForAnyRequest();
       
  1225 		} while (aStatus1==KRequestPending && aStatus2==KRequestPending);
       
  1226 	if (i)
       
  1227 		Exec::RequestSignal(i);
       
  1228 	}
       
  1229 
       
  1230 
       
  1231 
       
  1232 
       
  1233 EXPORT_C void User::WaitForNRequest(TRequestStatus * aStatusArray[], TInt aNum)
       
  1234 /**
       
  1235  Waits for any one of  specific asynchronous requests to complete.
       
  1236   
       
  1237 The current thread waits on its request semaphore.
       
  1238  
       
  1239 The function completes and control returns to the caller when the current 
       
  1240 thread's request semaphore is signalled by either the service provider handling 
       
  1241 the request associated with aStatus1 or the service provider handling the 
       
  1242 request associated with aStatus2. Before signalling, the completing service 
       
  1243 provider sets an appropriate value in the status object, other
       
  1244 than KRequestPending.
       
  1245  
       
  1246 Note that if other asynchronous requests complete before the ones associated
       
  1247 with aStatusArray the request semaphore is adjusted so that knowledge
       
  1248 of their completion is not lost. In this a case, a subsequent call to
       
  1249 User::WaitForAnyRequest() or User::WaitForRequest() will complete and return
       
  1250 immediately. 
       
  1251 @param aStatArray[] A reference to the request status object associated with the 
       
  1252                     first specific asynchronous request.
       
  1253 @param TInt aNum    
       
  1254 */
       
  1255 	{
       
  1256      	TRequestStatus* aptr;
       
  1257      	TBool m = ETrue;
       
  1258      	TInt i = (-1);
       
  1259      	do
       
  1260 		{
       
  1261 	 	i++;
       
  1262         	Exec::WaitForAnyRequest();
       
  1263         	for(TInt j = 0; j<aNum; j++)
       
  1264         		{
       
  1265          		aptr =  aStatusArray[j];
       
  1266          		if(aptr)
       
  1267          			{
       
  1268          			if(aptr->Int()!= KRequestPending)
       
  1269          				{	
       
  1270          				m = EFalse;	
       
  1271          				break;
       
  1272          				}
       
  1273          			}
       
  1274         		}
       
  1275      		}while(m);
       
  1276 	if(i)
       
  1277 		Exec::RequestSignal(i);	
       
  1278 	}
       
  1279 
       
  1280 
       
  1281 
       
  1282 
       
  1283 EXPORT_C TInt TFindLibrary::Next(TFullName &aResult)
       
  1284 /**
       
  1285 Finds the next DLL whose full name matches the match pattern.
       
  1286 
       
  1287 If a DLL with a matching name is found, the function copies the full name of
       
  1288 the DLL into the descriptor aResult.
       
  1289 
       
  1290 @param aResult A buffer for the fullname of the DLL. This is a template
       
  1291                specialisation of TBuf defining a modifiable buffer descriptor
       
  1292                taking a maximum length of KMaxFullName.
       
  1293                If no matching DLL is found, the descriptor length is
       
  1294                set to zero. 
       
  1295                
       
  1296 @return KErrNone, if a matching DLL is found;
       
  1297         KErrNotFound, otherwise.
       
  1298 */
       
  1299 	{
       
  1300 	return NextObject(aResult,ELibrary);
       
  1301 	}
       
  1302 
       
  1303 
       
  1304 
       
  1305 
       
  1306 EXPORT_C TLibraryFunction RLibrary::Lookup(TInt anOrdinal) const
       
  1307 /**
       
  1308 Gets a pointer to the function at the specified ordinal within this DLL.
       
  1309 
       
  1310 @param anOrdinal The ordinal of the required function in this DLL.
       
  1311                  This value must be positive.
       
  1312 
       
  1313 @return A pointer to the function at position anOrdinal in this DLL.
       
  1314         The value is NULL if there is no function at that ordinal. 
       
  1315         
       
  1316 @panic USER 116 if anOrdinal is negative
       
  1317 */
       
  1318 	{
       
  1319 	__ASSERT_ALWAYS(anOrdinal>=0,Panic(EBadLookupOrdinal));
       
  1320 	return (Exec::LibraryLookup(iHandle,anOrdinal));
       
  1321 	}
       
  1322 
       
  1323 
       
  1324 
       
  1325 EXPORT_C TFileName RLibrary::FileName() const
       
  1326 /**
       
  1327 Gets the name of the DLL's file.
       
  1328 
       
  1329 @return The DLL's filname.
       
  1330 */
       
  1331 	{
       
  1332 
       
  1333 	TFileName n;
       
  1334 	TPtr8 n8(((TUint8*)n.Ptr()) + KMaxFileName, KMaxFileName);
       
  1335 	Exec::LibraryFileName(iHandle,n8);
       
  1336 	n.Copy(n8);
       
  1337 	return(n);
       
  1338 	}
       
  1339 
       
  1340 
       
  1341 
       
  1342 
       
  1343 EXPORT_C TUidType RLibrary::Type() const
       
  1344 /**
       
  1345 Gets this DLL's UID type.
       
  1346 
       
  1347 The UID type is a property of a Symbian OS file; for a DLL, its value is set
       
  1348 during the building of that DLL.
       
  1349 
       
  1350 @return The UID type of this DLL. Note that the first TUid component of
       
  1351         the TUidType has the value KDynamicLibraryUid.
       
  1352 */
       
  1353 	{
       
  1354 
       
  1355 	TUidType u;
       
  1356 	Exec::LibraryType(iHandle,u);
       
  1357 	return(u);
       
  1358 	}
       
  1359 
       
  1360 
       
  1361 
       
  1362 
       
  1363 EXPORT_C TInt RLibrary::GetRamSizes(TInt& aCodeSize, TInt& aConstDataSize)
       
  1364 /**
       
  1365 Gets the current size of the code and the const data for this DLL.
       
  1366 
       
  1367 This function can be called on a RAM loaded DLL or a ROM based DLL.
       
  1368 
       
  1369 @param aCodeSize      The current size of the code for a RAM loaded DLL.
       
  1370                       This is zero for a ROM based DLL.
       
  1371 
       
  1372 @param aConstDataSize The current size of the const data for a RAM loaded DLL.
       
  1373                       This is zero for a ROM based DLL.
       
  1374 
       
  1375 @return KErrNone if successful, otherwise one of the system-wide error codes. 
       
  1376 */
       
  1377 	{
       
  1378 	TModuleMemoryInfo info;
       
  1379 	TInt r=Exec::LibraryGetMemoryInfo(iHandle,info);
       
  1380 	if (r==KErrNone)
       
  1381 		{
       
  1382 		aCodeSize=info.iCodeSize;
       
  1383 		aConstDataSize=info.iConstDataSize;
       
  1384 		}
       
  1385 	return r;
       
  1386 	}
       
  1387 
       
  1388 
       
  1389 
       
  1390 
       
  1391 /**
       
  1392 Sets the home time to a specified time value.
       
  1393 
       
  1394 @param aTime A reference to a time representation object containing the time 
       
  1395              value.
       
  1396              
       
  1397 @return KErrNone if successful or one of the system-wide error codes.
       
  1398 
       
  1399 @deprecated Set the time using User::SetUTCTime if the UTC time is known;
       
  1400 			otherwise, use the timezone server to set the time.
       
  1401 
       
  1402 @capability WriteDeviceData
       
  1403 */
       
  1404 EXPORT_C TInt User::SetHomeTime(const TTime &aTime)
       
  1405 	{
       
  1406 	return(Exec::SetUTCTimeAndOffset(aTime.Int64(),0,ETimeSetTime|ETimeSetLocalTime,0));
       
  1407 	}
       
  1408 
       
  1409 /**
       
  1410 Sets the secure home time to a specified time value.
       
  1411 
       
  1412 @param aTime A reference to a time representation object containing the 
       
  1413 			 secure time value.
       
  1414              
       
  1415 @return KErrNone if successful or one of the system-wide error codes.
       
  1416 
       
  1417 @capability TCB
       
  1418 @capability WriteDeviceData
       
  1419 */
       
  1420 EXPORT_C TInt User::SetHomeTimeSecure(const TTime &aTime)
       
  1421 	{
       
  1422 	return(Exec::SetUTCTimeAndOffset(aTime.Int64(),0,ETimeSetTime|ETimeSetLocalTime|ETimeSetSecure,0));
       
  1423 	}
       
  1424 
       
  1425 
       
  1426 
       
  1427 /**
       
  1428 Sets the UTC time to a specified time value.
       
  1429 
       
  1430 @param aUTCTime A reference to a time representation object containing the time 
       
  1431                 value.
       
  1432              
       
  1433 @return KErrNone if successful or one of the system-wide error codes.
       
  1434 
       
  1435 @capability WriteDeviceData
       
  1436 */
       
  1437 EXPORT_C TInt User::SetUTCTime(const TTime &aUTCTime)
       
  1438 	{
       
  1439 	return(Exec::SetUTCTimeAndOffset(aUTCTime.Int64(),0,ETimeSetTime,0));
       
  1440 	}
       
  1441 
       
  1442 /**
       
  1443 Sets the secure UTC time to a specified time value.
       
  1444 
       
  1445 @param aUTCTime A reference to a time representation object containing the secure time 
       
  1446                 value.
       
  1447              
       
  1448 @return KErrNone if successful or one of the system-wide error codes.
       
  1449 
       
  1450 @capability TCB
       
  1451 @capability WriteDeviceData
       
  1452 */
       
  1453 EXPORT_C TInt User::SetUTCTimeSecure(const TTime &aUTCTime)
       
  1454 	{
       
  1455 	return(Exec::SetUTCTimeAndOffset(aUTCTime.Int64(),0,ETimeSetTime|ETimeSetSecure,0));
       
  1456 	}
       
  1457 
       
  1458 /**
       
  1459 Gets the UTC offset - the difference between UTC and the current local time
       
  1460 due to any time zones and daylight savings time that may be in effect. A positive
       
  1461 offset indicates a time ahead of UTC, a negative offset indicates a time behind UTC.
       
  1462 
       
  1463 @return The UTC offset, in seconds.
       
  1464 */
       
  1465 EXPORT_C TTimeIntervalSeconds User::UTCOffset()
       
  1466 	{
       
  1467 	return(TTimeIntervalSeconds(Exec::UTCOffset()));
       
  1468 	}
       
  1469 
       
  1470 
       
  1471 /**
       
  1472 Sets the UTC offset to the given number of seconds. This should include both time
       
  1473 zone differences and the effect of any applicable daylight savings time.
       
  1474 A positive offset indicates a time ahead of UTC, a negative offset indicates a time
       
  1475 behind UTC.
       
  1476 
       
  1477 @param aOffset The UTC offset, in seconds.
       
  1478 
       
  1479 @capability WriteDeviceData
       
  1480 */
       
  1481 EXPORT_C void User::SetUTCOffset(TTimeIntervalSeconds aOffset)
       
  1482 	{
       
  1483 	Exec::SetUTCTimeAndOffset(0,aOffset.Int(),ETimeSetOffset,0);
       
  1484 	}
       
  1485 
       
  1486 
       
  1487 /**
       
  1488 Sets the UTC time and UTC offset to the specified values, atomically. This is equivalent
       
  1489 to calling both SetUTCTime and SetUTCOffset, but without the possibility of an incorrect
       
  1490 time being observed between the two calls. If the operation is not successful, an error
       
  1491 code will be returned and both the time and offset will be left unchanged.
       
  1492 
       
  1493 @param aUTCTime A reference to a time representation object containing the time 
       
  1494                 value.
       
  1495 @param aOffset The UTC offset, in seconds.
       
  1496              
       
  1497 @return KErrNone if successful or one of the system-wide error codes.
       
  1498 
       
  1499 @capability WriteDeviceData
       
  1500 */
       
  1501 EXPORT_C TInt User::SetUTCTimeAndOffset(const TTime &aUTCTime, TTimeIntervalSeconds aOffset)
       
  1502 	{
       
  1503 	return(Exec::SetUTCTimeAndOffset(aUTCTime.Int64(),aOffset.Int(),ETimeSetTime|ETimeSetOffset,0));
       
  1504 	}
       
  1505 #endif // __TOOLS2__
       
  1506 
       
  1507 /**
       
  1508 Gets the current tick count.
       
  1509 
       
  1510 The period between ticks is usually 1/64 second, but may be hardware dependent.
       
  1511 
       
  1512 @return The machine dependent tick count.
       
  1513 */
       
  1514 EXPORT_C TUint User::TickCount()
       
  1515 	{
       
  1516 
       
  1517 	return(Exec::TickCount());
       
  1518 	}
       
  1519 
       
  1520 
       
  1521 
       
  1522 #ifndef __TOOLS2__
       
  1523 
       
  1524 EXPORT_C TTimeIntervalSeconds User::InactivityTime()
       
  1525 /**
       
  1526 Gets the time since the last user activity.
       
  1527 
       
  1528 @return The time interval.
       
  1529 */
       
  1530 	{
       
  1531 
       
  1532 	return TTimeIntervalSeconds(Exec::UserInactivityTime());
       
  1533 	}
       
  1534 
       
  1535 
       
  1536 
       
  1537 
       
  1538 /**
       
  1539 Resets all user inactivity timers.
       
  1540 */
       
  1541 EXPORT_C void User::ResetInactivityTime()
       
  1542 	{
       
  1543 	Exec::ResetInactivityTime();
       
  1544 	}
       
  1545 #endif // __TOOLS2__
       
  1546 
       
  1547 
       
  1548 
       
  1549 /**
       
  1550 Gets the nanokernel tick count.
       
  1551 
       
  1552 This is the current value of the machine's millisecond tick counter.
       
  1553 
       
  1554 On the emulator the resolution defaults to 5 milliseconds; however
       
  1555 you can change it to N milliseconds when you launch the emulator
       
  1556 from the command line by specifying -Dtimerresolution=N as a parameter
       
  1557 to epoc.exe, for example:
       
  1558 @code
       
  1559 epoc.exe -Dtimerresolution=3
       
  1560 @endcode
       
  1561 
       
  1562 On most hardware the resolution is about 1 millisecond.
       
  1563 
       
  1564 You can get the nanokernel tick period in microseconds by calling
       
  1565 into the Hardware Abstraction Layer:
       
  1566 
       
  1567 @code
       
  1568 TInt nanokernel_tick_period;
       
  1569 HAL::Get(HAL::ENanoTickPeriod, nanokernel_tick_period);
       
  1570 @endcode
       
  1571 
       
  1572 @return The nanokernel tick count.
       
  1573 */
       
  1574 EXPORT_C TUint32 User::NTickCount()
       
  1575 	{
       
  1576 
       
  1577 	return Exec::NTickCount();
       
  1578 	}
       
  1579 
       
  1580 
       
  1581 
       
  1582 #ifndef __TOOLS2__
       
  1583 
       
  1584 /**
       
  1585 Gets the fast counter.
       
  1586 
       
  1587 This is the current value of the machine's high resolution timer.  If a high
       
  1588 resolution timer is not available, it uses the millisecond timer instead.
       
  1589 
       
  1590 The freqency of this counter can be determined by reading the HAL attribute
       
  1591 EFastCounterFrequency.
       
  1592 
       
  1593 @return The fast counter value.
       
  1594 */
       
  1595 EXPORT_C TUint32 User::FastCounter()
       
  1596 	{
       
  1597 
       
  1598 	return Exec::FastCounter();
       
  1599 	}
       
  1600 
       
  1601 
       
  1602 
       
  1603 
       
  1604 EXPORT_C TTimerLockSpec User::LockPeriod()
       
  1605 /**
       
  1606 Returns which of the periods the clock is currently in.
       
  1607 
       
  1608 @return The fraction of a second at which the timer completes.
       
  1609 */
       
  1610 	{
       
  1611 
       
  1612 	return(Exec::LockPeriod());
       
  1613 	}
       
  1614 
       
  1615 
       
  1616 
       
  1617 
       
  1618 EXPORT_C TName RHandleBase::Name() const
       
  1619 /**
       
  1620 Gets the name of the handle.
       
  1621 
       
  1622 @return The name of the handle.
       
  1623 */
       
  1624 	{
       
  1625 
       
  1626 	TName n;
       
  1627 	TPtr8 n8(((TUint8*)n.Ptr()) + KMaxName, KMaxName);
       
  1628 	Exec::HandleName(iHandle,n8);
       
  1629 	n.Copy(n8);
       
  1630 	return(n);
       
  1631 	}
       
  1632 
       
  1633 
       
  1634 
       
  1635 
       
  1636 EXPORT_C TFullName RHandleBase::FullName() const
       
  1637 /**
       
  1638 Gets the full name of the handle.
       
  1639 
       
  1640 Note: This method is stack consuming (it takes 512 bytes on stack to execute).
       
  1641 For an alternative way to obtain the full name of the object, see RHandleBase::FullName(TDes& aName) const.
       
  1642 
       
  1643 @see RHandleBase::FullName(TDes& aName) const
       
  1644 @return The full name of the handle.
       
  1645 */
       
  1646 	{
       
  1647 
       
  1648 	TFullName n;
       
  1649 	TPtr8 n8(((TUint8*)n.Ptr()) + KMaxFullName, KMaxFullName);
       
  1650 	Exec::HandleFullName(iHandle,n8);
       
  1651 	n.Copy(n8);
       
  1652 	return(n);
       
  1653 	}
       
  1654 
       
  1655 
       
  1656 
       
  1657 
       
  1658 EXPORT_C void RHandleBase::FullName(TDes& aName) const
       
  1659 /**
       
  1660 Gets the full name of the handle.
       
  1661 
       
  1662 @param aName On return, contains the full name of the handle.
       
  1663 
       
  1664 @panic KERN-EXEC 35, If full name of the handler is longer that the maximum length of aName descriptor.
       
  1665 					 To avoid this, the maximum length of aName should be at least KMaxFullName.
       
  1666 @see KMaxFullName
       
  1667 */
       
  1668 	{
       
  1669 
       
  1670 	// Kernel will copy string in n8, whose data lives in the upper half of aName desciptor data
       
  1671 	TPtr8 n8(((TUint8*)aName.Ptr()) + aName.MaxLength(), aName.MaxLength());
       
  1672 	Exec::HandleFullName(iHandle,n8);
       
  1673 	aName.Copy(n8); // Expands 8bit descriptor into 16bit unicode descriptor.
       
  1674 	}
       
  1675 
       
  1676 
       
  1677 
       
  1678 
       
  1679 EXPORT_C void RHandleBase::HandleInfo(THandleInfo* anInfo)
       
  1680 /**
       
  1681 Gets information about the handle.
       
  1682 
       
  1683 @param anInfo A pointer to a THandleInfo object supplied by the caller;
       
  1684               on return, contains the handle information. 
       
  1685 */
       
  1686 	{
       
  1687 
       
  1688 	Exec::HandleInfo(iHandle,anInfo);
       
  1689 	}
       
  1690 
       
  1691 EXPORT_C TInt RHandleBase::BTraceId() const
       
  1692 /**
       
  1693 Returns a unique object identifier for use with BTrace
       
  1694 */
       
  1695 	{
       
  1696 	return Exec::GetBTraceId(iHandle);
       
  1697 	}
       
  1698 
       
  1699 
       
  1700 
       
  1701 EXPORT_C TUint RHandleBase::Attributes() const
       
  1702 //
       
  1703 // Get handle attributes
       
  1704 //
       
  1705 	{
       
  1706 
       
  1707 	return Exec::HandleAttributes(iHandle);
       
  1708 	}
       
  1709 #endif // __TOOLS2__
       
  1710 
       
  1711 
       
  1712 
       
  1713 EXPORT_C TInt User::AllocLen(const TAny *aCell)
       
  1714 /**
       
  1715 Gets the length of the specified allocated heap cell.
       
  1716 
       
  1717 The cell is assumed to be in the current thread's heap.
       
  1718 
       
  1719 @param aCell A pointer to the allocated cell whose length
       
  1720              is to be fetched.
       
  1721 
       
  1722 @return The length of the allocated cell.
       
  1723 */
       
  1724 	{
       
  1725 #ifndef __TOOLS2__
       
  1726 	return(GetHeap()->AllocLen(aCell));
       
  1727 #else
       
  1728 	TUint8* p = ((TUint8*)aCell) - sizeof(TInt);
       
  1729 	return *((TInt*)p);
       
  1730 #endif // __TOOLS2__
       
  1731 	}
       
  1732 
       
  1733 
       
  1734 
       
  1735 
       
  1736 EXPORT_C TAny* User::Alloc(TInt aSize)
       
  1737 /**
       
  1738 Allocates a cell of specified size from the current thread's heap.
       
  1739 
       
  1740 If there is insufficient memory available on the heap from which to allocate a cell 
       
  1741 of the required size, the function returns NULL.
       
  1742 
       
  1743 The resulting size of the allocated cell may be rounded up to a value greater 
       
  1744 than aSize, but is guaranteed to be not less than aSize.
       
  1745 
       
  1746 @param aSize The size of the cell to be allocated from the current thread's 
       
  1747              heap.
       
  1748              
       
  1749 @return A pointer to the allocated cell. NULL, if there is insufficient memory 
       
  1750         available.
       
  1751         
       
  1752 @panic USER 47, if the maximum unsigned value of aSize is greater
       
  1753                 than or equal to KMaxTInt/2. For example,
       
  1754                 calling Alloc(-1) raises this panic.
       
  1755 */
       
  1756 	{
       
  1757 #ifndef __TOOLS2__
       
  1758 	return(GetHeap()->Alloc(aSize));
       
  1759 #else
       
  1760 #ifdef _DEBUG
       
  1761 	// Simulate heap failure
       
  1762 	gAllocCount++;
       
  1763 	switch (gAllocFailType)
       
  1764 		{
       
  1765 		case RAllocator::EFailNext:
       
  1766 			if (gAllocCount == gAllocFailRate)
       
  1767 				return NULL;
       
  1768 			break;
       
  1769 		case RAllocator::EDeterministic:
       
  1770 			if (gAllocCount % gAllocFailRate == 0)
       
  1771 				return NULL;
       
  1772 			break;
       
  1773 		default:
       
  1774 			break;
       
  1775 		}
       
  1776 #endif // _DEBUG
       
  1777 	TUint8* p = (TUint8*)malloc(aSize + sizeof(TInt));
       
  1778 	if ( p == NULL ) {
       
  1779 		return NULL;
       
  1780 	}
       
  1781 	*((TInt*)p) = aSize;
       
  1782 	return p + sizeof(TInt);
       
  1783 #endif // __TOOLS2__
       
  1784 	}
       
  1785 
       
  1786 
       
  1787 
       
  1788 
       
  1789 EXPORT_C TAny* User::AllocL(TInt aSize)
       
  1790 /**
       
  1791 Allocates a cell of specified size from the current thread's heap, and leaves 
       
  1792 if there is insufficient memory in the heap.
       
  1793 
       
  1794 The resulting size of the allocated cell may be rounded up to a value greater 
       
  1795 than aSize, but is guaranteed to be not less than aSize.
       
  1796 
       
  1797 @param aSize The size of the cell to be allocated from the current thread's 
       
  1798              heap.
       
  1799 
       
  1800 @return A pointer to the allocated cell.
       
  1801 
       
  1802 @panic USER 47, if the maximum unsigned value of aSize is greater
       
  1803                 than or equal to KMaxTInt/2. For example,
       
  1804                 calling Alloc(-1) raises this panic.
       
  1805 */
       
  1806 	{
       
  1807 #ifndef __TOOLS2__
       
  1808 	return(GetHeap()->AllocL(aSize));
       
  1809 #else
       
  1810 		TAny* p = User::Alloc(aSize);
       
  1811 	if (!p)
       
  1812 		User::LeaveNoMemory();
       
  1813 	return p;
       
  1814 #endif // __TOOLS2__
       
  1815 	}
       
  1816 
       
  1817 
       
  1818 
       
  1819 
       
  1820 EXPORT_C TAny *User::AllocLC(TInt aSize)
       
  1821 /**
       
  1822 Allocates a cell of specified size from the current thread's default heap, and,
       
  1823 if successful, places a pointer to the cell onto the cleanup stack.
       
  1824 
       
  1825 The function leaves if there is insufficient memory in the heap.
       
  1826 
       
  1827 The resulting size of the allocated cell may be rounded up to a value greater 
       
  1828 than aSize, but is guaranteed to be not less than aSize.
       
  1829 
       
  1830 @param aSize The size of the cell to be allocated from the current thread's
       
  1831              default heap.
       
  1832              
       
  1833 @return A pointer to the allocated cell.
       
  1834 
       
  1835 @panic USER 47, if the maximum unsigned value of aSize is greater
       
  1836                 than or equal to KMaxTInt/2. For example,
       
  1837                 calling Alloc(-1) raises this panic.
       
  1838 */
       
  1839 	{
       
  1840 #ifndef __TOOLS2__
       
  1841 	return(GetHeap()->AllocLC(aSize));
       
  1842 #else
       
  1843 	TAny* p = User::AllocL(aSize);
       
  1844 	CleanupStack::PushL(p);
       
  1845 	return p;
       
  1846 #endif // __TOOLS2__
       
  1847 	}
       
  1848 
       
  1849 
       
  1850 
       
  1851 
       
  1852 EXPORT_C TAny* User::AllocZ(TInt aSize)
       
  1853 /**
       
  1854 Allocates a cell of specified size from the current thread's default heap,
       
  1855 and clears it to binary zeroes.
       
  1856 
       
  1857 If there is insufficient memory available on the heap from which to allocate a cell 
       
  1858 of the required size, the function returns NULL.
       
  1859 
       
  1860 The resulting size of the allocated cell may be rounded up to a value greater 
       
  1861 than aSize, but is guaranteed to be not less than aSize.
       
  1862 
       
  1863 @param aSize The size of the cell to be allocated from the current thread's 
       
  1864              default heap.
       
  1865              
       
  1866 @return A pointer to the allocated cell. NULL, if there is insufficient memory 
       
  1867         available.
       
  1868         
       
  1869 @panic USER 47, if the maximum unsigned value of aSize is greater
       
  1870                 than or equal to KMaxTInt/2. For example,
       
  1871                 calling Alloc(-1) raises this panic.
       
  1872 */
       
  1873 	{
       
  1874 #ifndef __TOOLS2__
       
  1875 	return GetHeap()->AllocZ(aSize);
       
  1876 #else
       
  1877 	TAny* p = User::Alloc(aSize);
       
  1878 	if (p)
       
  1879 		memset(p, '\0', aSize);
       
  1880 	return p;
       
  1881 #endif // __TOOLS2__
       
  1882 	}
       
  1883 
       
  1884 
       
  1885 
       
  1886 
       
  1887 EXPORT_C TAny* User::AllocZL(TInt aSize)
       
  1888 /**
       
  1889 Allocates a cell of specified size from the current thread's default heap,
       
  1890 clears it to binary zeroes, and leaves if there is insufficient memory in
       
  1891 the heap.
       
  1892 
       
  1893 The resulting size of the allocated cell may be rounded up to a value greater 
       
  1894 than aSize, but is guaranteed to be not less than aSize.
       
  1895 
       
  1896 @param aSize The size of the cell to be allocated from the current thread's 
       
  1897              heap.
       
  1898 
       
  1899 @return A pointer to the allocated cell.
       
  1900 
       
  1901 @panic USER 47, if the maximum unsigned value of aSize is greater
       
  1902                 than or equal to KMaxTInt/2. For example,
       
  1903                 calling Alloc(-1) raises this panic.
       
  1904 */
       
  1905 	{
       
  1906 #ifndef __TOOLS2__
       
  1907 	return GetHeap()->AllocZL(aSize);
       
  1908 #else
       
  1909 	TAny* p = User::AllocZ(aSize);
       
  1910 	if (!p)
       
  1911 		User::LeaveNoMemory();
       
  1912 	return p;
       
  1913 #endif // __TOOLS2__
       
  1914 	}
       
  1915 
       
  1916 
       
  1917 
       
  1918 EXPORT_C TInt User::Available(TInt &aBiggestBlock)
       
  1919 /**
       
  1920 Gets the total free space currently available on the current thread's 
       
  1921 default heap, and the space available in the largest free block.
       
  1922 
       
  1923 The space available represents the total space which can be allocated.
       
  1924 
       
  1925 Note that compressing the heap may reduce the total free space available and the space 
       
  1926 available in the largest free block.
       
  1927 
       
  1928 @param aBiggestBlock On return, contains the space available in the largest
       
  1929                      free block on the current thread's default heap.
       
  1930                      
       
  1931 @return The total free space currently available on the current thread's heap.
       
  1932 */
       
  1933 	{
       
  1934 #ifndef __TOOLS2__
       
  1935 	return(GetHeap()->Available(aBiggestBlock));
       
  1936 #else
       
  1937 	aBiggestBlock = 0x100000;
       
  1938 	return 0x40000000;
       
  1939 #endif // __TOOLS2__
       
  1940 	}
       
  1941 
       
  1942 
       
  1943 
       
  1944 #ifndef __TOOLS2__
       
  1945 EXPORT_C void User::Check()
       
  1946 /**
       
  1947 Checks the validity of the current thread's default heap.
       
  1948 
       
  1949 The function walks through the list of allocated cells and the list of free
       
  1950 cells checking that the heap is consistent and complete.
       
  1951 
       
  1952 @panic USER 47 if any corruption is found, specifically	a bad allocated
       
  1953                heap cell size.
       
  1954 @panic USER 48 if any corruption is found, specifically a bad allocated
       
  1955                heap cell address.
       
  1956 @panic USER 49 if any corruption is found, specifically a bad free heap
       
  1957                cell address.
       
  1958 */
       
  1959 	{
       
  1960 
       
  1961 	GetHeap()->Check();
       
  1962 	}
       
  1963 #endif // __TOOLS2__
       
  1964 
       
  1965 
       
  1966 
       
  1967 EXPORT_C void User::Free(TAny *aCell)
       
  1968 /**
       
  1969 Frees the specified cell and returns it to the current thread's default heap.
       
  1970 
       
  1971 @param aCell A pointer to a valid cell to be freed. If NULL this function 
       
  1972              call will be ignored.
       
  1973              
       
  1974 @panic USER 42, if aCell is not NULL and does not point to a valid cell.
       
  1975 */
       
  1976 	{
       
  1977 #ifndef __TOOLS2__
       
  1978 	if (aCell)
       
  1979 		GetHeap()->Free(aCell);
       
  1980 #else
       
  1981 	if (aCell)
       
  1982 		{
       
  1983 		TUint8* p = ((TUint8*)aCell) - sizeof(TInt);
       
  1984 		free(p);
       
  1985 		}
       
  1986 #endif // __TOOLS2__
       
  1987 	}
       
  1988 
       
  1989 
       
  1990 
       
  1991 
       
  1992 EXPORT_C void User::FreeZ(TAny * &aCell)
       
  1993 /**
       
  1994 Frees the specified cell, returns it to the current thread's default heap, and resets 
       
  1995 the pointer to NULL.
       
  1996 
       
  1997 @param aCell A reference to a pointer to a valid cell to be freed. If NULL 
       
  1998              this function call will be ignored.
       
  1999              
       
  2000 @panic USER 42, if aCell is not NULL and does not point to a valid cell.             
       
  2001 */
       
  2002 	{
       
  2003 #ifndef __TOOLS2__
       
  2004 	if (aCell)
       
  2005 		GetHeap()->FreeZ(aCell);
       
  2006 #else
       
  2007 	User::Free(aCell);
       
  2008 	aCell = NULL;
       
  2009 #endif // __TOOLS2__
       
  2010 	}
       
  2011 
       
  2012 
       
  2013 
       
  2014 
       
  2015 EXPORT_C TAny* User::ReAlloc(TAny* aCell, TInt aSize, TInt aMode)
       
  2016 /**
       
  2017 Increases or decreases the size of an existing cell in the current
       
  2018 thread's heap.
       
  2019 
       
  2020 If the cell is being decreased in size, then it is guaranteed not to move,
       
  2021 and the function returns the pointer originally passed in aCell. Note that the
       
  2022 length of the cell will be the same if the difference between the old size
       
  2023 and the new size is smaller than the minimum cell size.
       
  2024 
       
  2025 If the cell is being increased in size, i.e. aSize is bigger than its
       
  2026 current size, then the function tries to grow the cell in place.
       
  2027 If successful, then the function returns the pointer originally
       
  2028 passed in aCell. If unsuccessful, then:
       
  2029 -# if the cell cannot be moved, i.e. aMode has the ENeverMove bit set, then
       
  2030    the function returns NULL.
       
  2031 -# if the cell can be moved, i.e. aMode does not have the ENeverMove bit set,
       
  2032    then the function tries to allocate a new replacement cell, and, if
       
  2033    successful, returns a pointer to the new cell; if unsuccessful, it
       
  2034    returns NULL.
       
  2035 
       
  2036 Note that in debug mode, the function returns NULL if the cell cannot be grown
       
  2037 in place, regardless of whether the ENeverMove bit is set.
       
  2038 
       
  2039 If the reallocated cell is at a different location from the original cell, then
       
  2040 the content of the original cell is copied to the reallocated cell.
       
  2041 
       
  2042 If the supplied pointer, aCell is NULL, then the function attempts to allocate
       
  2043 a new cell, but only if the cell can be moved, i.e. aMode does not have
       
  2044 the ENeverMove bit set.
       
  2045 
       
  2046 Note the following general points:
       
  2047 - If reallocation fails, the content of the original cell is preserved.
       
  2048 - The resulting size of the re-allocated cell may be rounded up to a value
       
  2049   greater than aSize, but is guaranteed to be not less than aSize.
       
  2050  
       
  2051 @param aCell A pointer to the cell to be reallocated. This may be NULL.
       
  2052 
       
  2053 @param aSize The new size of the cell. This may be bigger or smaller than the
       
  2054              size of the original cell. The value can also be zero, but this is
       
  2055              interpreted as a request for a cell of minimum size; the net
       
  2056              effect is the same as if the caller had explicitly requested
       
  2057              a cell of minimum size.
       
  2058              Note that the minimum size of a heap cell is device dependent.
       
  2059              
       
  2060 @param aMode Flags controlling the reallocation. The only bit which has any
       
  2061              effect on this function is that defined by the enumeration
       
  2062              ENeverMove of the enum RAllocator::TReAllocMode.
       
  2063              If this is set, then any successful reallocation guarantees not
       
  2064              to have changed the start address of the cell.
       
  2065              By default, this parameter is zero.
       
  2066 
       
  2067 @return A pointer to the reallocated cell. This may be the same as the original
       
  2068         pointer supplied through aCell. NULL if there is insufficient memory to
       
  2069         reallocate the cell, or to grow it in place.
       
  2070 
       
  2071 @panic USER 42, if aCell is not NULL, and does not point to a valid cell.
       
  2072 @panic USER 47, if the maximum unsigned value of aSize is greater
       
  2073                 than or equal to KMaxTInt/2. For example,
       
  2074                 calling ReAlloc(someptr,-1) raises this panic.
       
  2075 
       
  2076 @see RAllocator::TReAllocMode
       
  2077 */
       
  2078 	{
       
  2079 #ifndef __TOOLS2__
       
  2080 	return GetHeap()->ReAlloc(aCell, aSize, aMode);
       
  2081 #else
       
  2082 	if (!aCell)
       
  2083 		return User::Alloc(aSize);
       
  2084 	else
       
  2085 		{
       
  2086 #ifdef _DEBUG
       
  2087 		// Simulate heap failure
       
  2088 		gAllocCount++;
       
  2089 		switch (gAllocFailType)
       
  2090 			{
       
  2091 			case RAllocator::EFailNext:
       
  2092 				if (gAllocCount == gAllocFailRate)
       
  2093 					return NULL;
       
  2094 				break;
       
  2095 			case RAllocator::EDeterministic:
       
  2096 				if (gAllocCount % gAllocFailRate == 0)
       
  2097 					return NULL;
       
  2098 				break;
       
  2099 			default:
       
  2100 				break;
       
  2101 			}
       
  2102 #endif // _DEBUG
       
  2103 		TUint8* o = ((TUint8*)aCell) - sizeof(TInt);
       
  2104 		TUint8* n = (TUint8*)realloc(o, aSize + sizeof(TInt));
       
  2105 		if (n)
       
  2106 			{
       
  2107 			*((TInt*)n) = aSize;
       
  2108 			return n + sizeof(TInt);
       
  2109 			}
       
  2110 		}
       
  2111 	return NULL;
       
  2112 #endif // __TOOLS2__
       
  2113 	}
       
  2114 
       
  2115 
       
  2116 
       
  2117 
       
  2118 EXPORT_C TAny* User::ReAllocL(TAny* aCell, TInt aSize, TInt aMode)
       
  2119 /**
       
  2120 Increases or decreases the size of an existing cell, and leaves 
       
  2121 if there is insufficient memory in the current thread's default heap.
       
  2122 
       
  2123 If the cell is being decreased in size, then it is guaranteed not to move,
       
  2124 and the function returns the pointer originally passed in aCell. Note that the
       
  2125 length of the cell will be the same if the difference between the old size
       
  2126 and the new size is smaller than the minimum cell size.
       
  2127 
       
  2128 If the cell is being increased in size, i.e. aSize is bigger than its
       
  2129 current size, then the function tries to grow the cell in place.
       
  2130 If successful, then the function returns the pointer originally
       
  2131 passed in aCell. If unsuccessful, then:
       
  2132 -# if the cell cannot be moved, i.e. aMode has the ENeverMove bit set, then
       
  2133    the function leaves.
       
  2134 -# if the cell can be moved, i.e. aMode does not have the ENeverMove bit set,
       
  2135    then the function tries to allocate a new replacement cell, and, if
       
  2136    successful, returns a pointer to the new cell; if unsuccessful, it
       
  2137    leaves.
       
  2138 
       
  2139 Note that in debug mode, the function leaves if the cell cannot be grown
       
  2140 in place, regardless of whether the ENeverMove bit is set.
       
  2141 
       
  2142 If the reallocated cell is at a different location from the original cell, then
       
  2143 the content of the original cell is copied to the reallocated cell.
       
  2144 
       
  2145 If the supplied pointer, aCell is NULL, then the function attempts to allocate
       
  2146 a new cell, but only if the cell can be moved, i.e. aMode does not have
       
  2147 the ENeverMove bit set.
       
  2148 
       
  2149 Note the following general points:
       
  2150 - If reallocation fails, the content of the original cell is preserved.
       
  2151 - The resulting size of the re-allocated cell may be rounded up to a value
       
  2152   greater than aSize, but is guaranteed to be not less than aSize.
       
  2153 
       
  2154 @param aCell A pointer to the cell to be reallocated. This may be NULL.
       
  2155 
       
  2156 @param aSize The new size of the cell. This may be bigger or smaller than the
       
  2157              size of the original cell. The value can also be zero, but this is
       
  2158              interpreted as a request for a cell of minimum size; the net
       
  2159              effect is the same as if the caller had explicitly requested
       
  2160              a cell of minimum size.
       
  2161              Note that the minimum size of a heap cell is device dependent.
       
  2162              
       
  2163 @param aMode Flags controlling the reallocation. The only bit which has any
       
  2164              effect on this function is that defined by the enumeration
       
  2165              ENeverMove of the enum RAllocator::TReAllocMode.
       
  2166              If this is set, then any successful reallocation guarantees not
       
  2167              to have changed the start address of the cell.
       
  2168              By default, this parameter is zero.
       
  2169 
       
  2170 @return A pointer to the reallocated cell. This may be the same as the original
       
  2171         pointer supplied through aCell.
       
  2172 
       
  2173 @panic USER 42, if aCell is not NULL, and does not point to a valid cell.
       
  2174 @panic USER 47, if the maximum unsigned value of aSize is greater
       
  2175                 than or equal to KMaxTInt/2. For example,
       
  2176                 calling ReAlloc(someptr,-1) raises this panic.
       
  2177 
       
  2178 @see RAllocator::TReAllocMode
       
  2179 */
       
  2180 	{
       
  2181 #ifndef __TOOLS2__
       
  2182 	return GetHeap()->ReAllocL(aCell, aSize, aMode);
       
  2183 #else
       
  2184 	TAny* p = ReAlloc(aCell, aSize, aMode);
       
  2185 	if (!p)
       
  2186 		User::LeaveNoMemory();
       
  2187 	return p;
       
  2188 #endif // __TOOLS2__
       
  2189 	}
       
  2190 
       
  2191 
       
  2192 
       
  2193 #ifndef __TOOLS2__
       
  2194 EXPORT_C RAllocator& User::Allocator()
       
  2195 /**
       
  2196 Gets the current thread's default current heap.
       
  2197 
       
  2198 @return The current heap.
       
  2199 */
       
  2200 	{
       
  2201 
       
  2202 	return *GetHeap();
       
  2203 	}		
       
  2204 
       
  2205 
       
  2206 
       
  2207 
       
  2208 EXPORT_C TInt User::AllocSize(TInt &aTotalAllocSize)
       
  2209 /**
       
  2210 Gets the total number of cells allocated on the current thread's default heap, 
       
  2211 and the total space allocated to them.
       
  2212 
       
  2213 @param aTotalAllocSize On return, contains the total space allocated to
       
  2214                        the cells.
       
  2215                        
       
  2216 @return The number of cells currently allocated on the current thread's heap.
       
  2217 */
       
  2218 	{
       
  2219 
       
  2220 	return(GetHeap()->AllocSize(aTotalAllocSize));
       
  2221 	}
       
  2222 
       
  2223 
       
  2224 
       
  2225 
       
  2226 EXPORT_C TInt User::CountAllocCells()
       
  2227 /**
       
  2228 Gets the total number of cells allocated on the current thread's default heap.
       
  2229 
       
  2230 
       
  2231 @return The number of cells allocated on the current thread's default user heap.
       
  2232 */
       
  2233 	{
       
  2234 	return(GetHeap()->Count());
       
  2235 	}  
       
  2236 
       
  2237 
       
  2238 
       
  2239 
       
  2240 EXPORT_C TInt User::CountAllocCells(TInt &aFreeCount)
       
  2241 /**
       
  2242 Gets the the total number of cells allocated, and the number of free cells, 
       
  2243 on the current thread's default heap.
       
  2244 
       
  2245 @param aFreeCount On return, contains the number of free cells 
       
  2246                   on the current thread's default heap.
       
  2247 
       
  2248 @return The number of cells allocated on the current thread's default heap.
       
  2249 */
       
  2250 	{
       
  2251 
       
  2252 	return(GetHeap()->Count(aFreeCount));
       
  2253 	}
       
  2254 
       
  2255 
       
  2256 
       
  2257 
       
  2258 EXPORT_C RAllocator* User::SwitchAllocator(RAllocator* aA)
       
  2259 /**
       
  2260 Changes the current thread's heap.
       
  2261 	
       
  2262 @param aA A pointer to the new heap handle.
       
  2263 
       
  2264 @return A pointer to the old heap handle.
       
  2265 */
       
  2266 	{
       
  2267 	
       
  2268 #ifdef __USERSIDE_THREAD_DATA__
       
  2269 	// Just cache the pointer user-side.  We still need to let the kernel know what's going on so
       
  2270 	// the heap can be cleaned up correctly later.
       
  2271 	LocalThreadData()->iHeap=aA;
       
  2272 #endif
       
  2273 	return Exec::HeapSwitch(aA);
       
  2274 	}
       
  2275 #endif // __TOOLS2__
       
  2276 
       
  2277 // The suffix table
       
  2278 const TText16* const __DefaultDateSuffixTable[KMaxSuffixes] =
       
  2279 	{
       
  2280 	_S16("st"),_S16("nd"),_S16("rd"),_S16("th"),_S16("th"),
       
  2281 	_S16("th"),_S16("th"),_S16("th"),_S16("th"),_S16("th"),
       
  2282 	_S16("th"),_S16("th"),_S16("th"),_S16("th"),_S16("th"),
       
  2283 	_S16("th"),_S16("th"),_S16("th"),_S16("th"),_S16("th"),
       
  2284 	_S16("st"),_S16("nd"),_S16("rd"),_S16("th"),_S16("th"),
       
  2285 	_S16("th"),_S16("th"),_S16("th"),_S16("th"),_S16("th"),
       
  2286 	_S16("st")
       
  2287 	};
       
  2288 
       
  2289 // The day names
       
  2290 const TText16* const __DefaultDayTable[KMaxDays] =
       
  2291 	{
       
  2292 	_S16("Monday"),
       
  2293 	_S16("Tuesday"),
       
  2294 	_S16("Wednesday"),
       
  2295 	_S16("Thursday"),
       
  2296 	_S16("Friday"),
       
  2297 	_S16("Saturday"),
       
  2298 	_S16("Sunday")
       
  2299 	};
       
  2300 
       
  2301 // The abbreviated day names
       
  2302 const TText16* const __DefaultDayAbbTable[KMaxDays] =
       
  2303 	{
       
  2304 	_S16("Mon"),
       
  2305 	_S16("Tue"),
       
  2306 	_S16("Wed"),
       
  2307 	_S16("Thu"),
       
  2308 	_S16("Fri"),
       
  2309 	_S16("Sat"),
       
  2310 	_S16("Sun")
       
  2311 	};
       
  2312 
       
  2313 // The month names
       
  2314 const TText16* const __DefaultMonthTable[KMaxMonths] =
       
  2315 	{
       
  2316 	_S16("January"),
       
  2317 	_S16("February"),
       
  2318 	_S16("March"),
       
  2319 	_S16("April"),
       
  2320 	_S16("May"),
       
  2321 	_S16("June"),
       
  2322 	_S16("July"),
       
  2323 	_S16("August"),
       
  2324 	_S16("September"),
       
  2325 	_S16("October"),
       
  2326 	_S16("November"),
       
  2327 	_S16("December")
       
  2328 	};
       
  2329 
       
  2330 // The abbreviated month names
       
  2331 const TText16* const __DefaultMonthAbbTable[KMaxMonths] =
       
  2332 	{
       
  2333 	_S16("Jan"),
       
  2334 	_S16("Feb"),
       
  2335 	_S16("Mar"),
       
  2336 	_S16("Apr"),
       
  2337 	_S16("May"),
       
  2338 	_S16("Jun"),
       
  2339 	_S16("Jul"),
       
  2340 	_S16("Aug"),
       
  2341 	_S16("Sep"),
       
  2342 	_S16("Oct"),
       
  2343 	_S16("Nov"),
       
  2344 	_S16("Dec")
       
  2345 	};
       
  2346 
       
  2347 // The am/pm strings
       
  2348 const TText16* const __DefaultAmPmTable[KMaxAmPms] =
       
  2349 	{
       
  2350 	_S16("am"),
       
  2351 	_S16("pm")
       
  2352 	};
       
  2353 
       
  2354 const TText16* const __DefaultLMsgTable[ELocaleMessages_LastMsg] =
       
  2355 	{
       
  2356 // Fileserver
       
  2357 	_S16("Retry"),								// Button 1
       
  2358 	_S16("Stop"),									// Button 2
       
  2359 	_S16("Put the disk back"),					// Put the card back - line1
       
  2360 	_S16("or data will be lost"),					// Put the card back - line2
       
  2361 	_S16("Batteries too low"),					// Low power - line1
       
  2362 	_S16("Cannot complete write to disk"),		// Low power - line2
       
  2363 	_S16("Disk error - cannot complete write"),	// Disk error - line1
       
  2364 	_S16("Retry or data will be lost"),			// Disk error - line2
       
  2365 // SoundDriver
       
  2366 	_S16("Chimes"),								// Chimes
       
  2367 	_S16("Rings"),								// Rings
       
  2368 	_S16("Signal"),								// Signal
       
  2369 // MediaDriver diskname (max 16 chars)
       
  2370 	_S16("Internal"),								// Internal
       
  2371 	_S16("External(01)"),							// External(01)
       
  2372 	_S16("External(02)"),							// External(02)
       
  2373 	_S16("External(03)"),							// External(03)
       
  2374 	_S16("External(04)"),							// External(04)
       
  2375 	_S16("External(05)"),							// External(05)
       
  2376 	_S16("External(06)"),							// External(06)
       
  2377 	_S16("External(07)"),							// External(07)
       
  2378 	_S16("External(08)"),							// External(08)
       
  2379 // MediaDriver socketname (max 16 chars)
       
  2380 	_S16("Socket(01)"),							// Socket(01)
       
  2381 	_S16("Socket(02)"),							// Socket(02)
       
  2382 	_S16("Socket(03)"),							// Socket(03)
       
  2383 	_S16("Socket(04)")							// Socket(04)
       
  2384 	};
       
  2385 
       
  2386 #ifdef __TOOLS2__
       
  2387 TPckgBuf<TExtendedLocale> gLocale;
       
  2388 // gLocale.iLocale set, does not guarantee gLocale's other members are loaded.
       
  2389 TBool gLocaleSet = EFalse;
       
  2390 // gLocale set, all members of gLoacle loaded except iLocale, which is not guaranteed loaded or not.
       
  2391 TBool gLocaleExSet = EFalse;
       
  2392 #endif
       
  2393 
       
  2394 LOCAL_C void LocaleLanguageGet(SLocaleLanguage& locale)
       
  2395 	{
       
  2396 #ifndef __TOOLS2__
       
  2397 	TPckg<SLocaleLanguage> localeLanguageBuf(locale);
       
  2398 	TInt r = RProperty::Get(KUidSystemCategory, KLocaleLanguageKey, localeLanguageBuf);
       
  2399 	__ASSERT_DEBUG(r == KErrNone || r == KErrNotFound, Panic(EBadLocaleParameter));
       
  2400 #else
       
  2401 	TInt r = KErrNone;
       
  2402 	if (gLocaleExSet)
       
  2403 		{
       
  2404 		SLocaleLanguage* languageSettings = gLocale().GetLanguageSettings();
       
  2405 		memcpy(&locale, (void*)languageSettings, sizeof(SLocaleLanguage));
       
  2406 		}
       
  2407 	else
       
  2408 		r = KErrNotFound;
       
  2409 #endif // __TOOLS2__
       
  2410 	
       
  2411 	if(r == KErrNotFound)
       
  2412 		{
       
  2413 		locale.iLanguage			= ELangEnglish;
       
  2414 		locale.iDateSuffixTable		= (const TText16*)__DefaultDateSuffixTable;
       
  2415 		locale.iDayTable			= (const TText16*)__DefaultDayTable;
       
  2416 		locale.iDayAbbTable			= (const TText16*)__DefaultDayAbbTable;
       
  2417 		locale.iMonthTable			= (const TText16*)__DefaultMonthTable;
       
  2418 		locale.iMonthAbbTable		= (const TText16*)__DefaultMonthAbbTable;
       
  2419 		locale.iAmPmTable			= (const TText16*)__DefaultAmPmTable;
       
  2420 		locale.iMsgTable			= (const TText16* const*)__DefaultLMsgTable;
       
  2421 		}
       
  2422 	}
       
  2423 
       
  2424 LOCAL_C void LocaleSettingsGet(SLocaleLocaleSettings& locale)
       
  2425 	{
       
  2426 #ifndef __TOOLS2__
       
  2427 	TPckg<SLocaleLocaleSettings> localeSettingsBuf(locale);
       
  2428 	TInt r = RProperty::Get(KUidSystemCategory, KLocaleDataExtraKey, localeSettingsBuf);
       
  2429 	__ASSERT_DEBUG(r == KErrNone || r == KErrNotFound, Panic(EBadLocaleParameter));
       
  2430 #else
       
  2431 	TInt r = KErrNone;
       
  2432 	if (gLocaleExSet)
       
  2433 		{
       
  2434 		SLocaleLocaleSettings* extraSettings = gLocale().GetLocaleExtraSettings();
       
  2435 		memcpy(&locale, extraSettings, sizeof(SLocaleLocaleSettings));
       
  2436 		}
       
  2437 	else
       
  2438 		r = KErrNotFound;
       
  2439 #endif // __TOOLS2__
       
  2440 	
       
  2441 	if(r == KErrNotFound)
       
  2442 		{
       
  2443 		Mem::Copy(&locale.iCurrencySymbol[0], _S16("\x00a3"), sizeof(TText16) << 2);
       
  2444 		locale.iLocaleExtraSettingsDllPtr = NULL;
       
  2445 		}
       
  2446 	}
       
  2447 
       
  2448 LOCAL_C void LocaleTimeDateFormatGet(SLocaleTimeDateFormat& locale)
       
  2449 	{
       
  2450 #ifndef __TOOLS2__
       
  2451 	TPckg<SLocaleTimeDateFormat> localeTimeDateFormatBuf(locale);
       
  2452 	TInt r = RProperty::Get(KUidSystemCategory, KLocaleTimeDateFormatKey, localeTimeDateFormatBuf);
       
  2453 	__ASSERT_DEBUG(r == KErrNone || r == KErrNotFound, Panic(EBadLocaleParameter));
       
  2454 #else
       
  2455 	TInt r = KErrNone;
       
  2456 	if (gLocaleExSet)
       
  2457 		{
       
  2458 		SLocaleTimeDateFormat* timeDateFormat = gLocale().GetLocaleTimeDateFormat();
       
  2459 		memcpy(&locale, timeDateFormat, sizeof(SLocaleTimeDateFormat));
       
  2460 		}
       
  2461 	else
       
  2462 		r = KErrNotFound;
       
  2463 #endif // __TOOLS2__
       
  2464 	if(r == KErrNotFound)
       
  2465 		{
       
  2466 		Mem::Copy(&locale.iShortDateFormatSpec[0], _S16("%F%*D/%*M/%Y"), sizeof(TText16) * 13);
       
  2467 		Mem::Copy(&locale.iLongDateFormatSpec[0], _S16("%F%*D%X %N %Y"), sizeof(TText16) * 14);
       
  2468 		Mem::Copy(&locale.iTimeFormatSpec[0], _S16("%F%*I:%T:%S %*A"), sizeof(TText16) * 16);
       
  2469 		locale.iLocaleTimeDateFormatDllPtr = NULL;
       
  2470 		}
       
  2471 	}
       
  2472 
       
  2473 EXPORT_C void TDayName::Set(TDay aDay)
       
  2474 /**
       
  2475 Re-retrieves the current locale's text for the specified day of the week.
       
  2476 
       
  2477 @param aDay Identifies the day of the week.
       
  2478 
       
  2479 @panic USER 184, if the specified day is outside the permitted range.
       
  2480 */
       
  2481 	{
       
  2482 	
       
  2483 	__ASSERT_ALWAYS(aDay>=EMonday && aDay<=ESunday,Panic(EBadLocaleParameter));
       
  2484 	SLocaleLanguage localeLanguage;
       
  2485 	LocaleLanguageGet(localeLanguage);
       
  2486 	Copy((reinterpret_cast<const TText* const*>(localeLanguage.iDayTable))[aDay]);
       
  2487 	}
       
  2488 
       
  2489 
       
  2490 
       
  2491 
       
  2492 EXPORT_C void TDayNameAbb::Set(TDay aDay)
       
  2493 /**
       
  2494 Re-retrieves the current locale's abbreviated text for the specified day of 
       
  2495 the week.
       
  2496 
       
  2497 @param aDay Identifies the day of the week.
       
  2498 
       
  2499 @panic USER 184, if the specified day is outside the permitted range.
       
  2500 */
       
  2501 	{
       
  2502 
       
  2503 	__ASSERT_ALWAYS(aDay>=EMonday && aDay<=ESunday,Panic(EBadLocaleParameter));
       
  2504 	SLocaleLanguage localeLanguage;
       
  2505 	LocaleLanguageGet(localeLanguage);
       
  2506 	Copy((reinterpret_cast<const TText* const*>(localeLanguage.iDayAbbTable))[aDay]);
       
  2507 	}
       
  2508 
       
  2509 
       
  2510 
       
  2511 
       
  2512 EXPORT_C void TMonthName::Set(TMonth aMonth)
       
  2513 /**
       
  2514 Re-retrieves the current locale's text for the specified month.
       
  2515 
       
  2516 @param aMonth Identifies the month.
       
  2517 
       
  2518 @panic USER 184, if the specified month is outside the permitted range.
       
  2519 */
       
  2520 	{
       
  2521 
       
  2522 	__ASSERT_ALWAYS(aMonth>=EJanuary && aMonth<=EDecember,Panic(EBadLocaleParameter));
       
  2523 	SLocaleLanguage localeLanguage;
       
  2524 	LocaleLanguageGet(localeLanguage);
       
  2525 	Copy((reinterpret_cast<const TText* const*>(localeLanguage.iMonthTable))[aMonth]);
       
  2526 	}
       
  2527 
       
  2528 
       
  2529 
       
  2530 
       
  2531 EXPORT_C void TMonthNameAbb::Set(TMonth aMonth)
       
  2532 /**
       
  2533 Re-retrieves the current locale's abbreviated text for the specified month.
       
  2534 
       
  2535 @param aMonth Identifies the month.
       
  2536 
       
  2537 @panic USER 184, if the specified month is outside the permitted range.
       
  2538 */
       
  2539 	{
       
  2540 
       
  2541 	__ASSERT_ALWAYS(aMonth>=EJanuary && aMonth<=EDecember,Panic(EBadLocaleParameter));
       
  2542 	SLocaleLanguage localeLanguage;
       
  2543 	LocaleLanguageGet(localeLanguage);
       
  2544 	Copy((reinterpret_cast<const TText* const*>(localeLanguage.iMonthAbbTable))[aMonth]);
       
  2545 	}
       
  2546 
       
  2547 
       
  2548 
       
  2549 
       
  2550 EXPORT_C void TDateSuffix::Set(TInt aSuffix)
       
  2551 /**
       
  2552 Re-retrieves the current locale's date suffix text for the specified day of 
       
  2553 the month.
       
  2554 
       
  2555 @param aSuffix A value identifying the day of the month. The value can 
       
  2556                range from 0 to 30 so that the first day of the month is
       
  2557                identified by 0, the second day by 1 etc.
       
  2558                    
       
  2559 @panic USER 69, if aDateSuffix is outside the range 0 to 30.
       
  2560 */
       
  2561 	{
       
  2562 
       
  2563 	__ASSERT_ALWAYS(aSuffix>=0 && aSuffix<KMaxSuffixes,Panic(ETLoclSuffixOutOfRange));
       
  2564 	SLocaleLanguage localeLanguage;
       
  2565 	LocaleLanguageGet(localeLanguage);
       
  2566 	Copy((reinterpret_cast<const TText* const*>(localeLanguage.iDateSuffixTable))[aSuffix]);
       
  2567 	}
       
  2568 
       
  2569 
       
  2570 
       
  2571 
       
  2572 EXPORT_C void TAmPmName::Set(TAmPm aSelector)
       
  2573 /**
       
  2574 Re-retrieves the current locale's text for identifying time before or after 
       
  2575 noon as identified by the specified selector.
       
  2576 
       
  2577 @param aSelector The am/pm selector.
       
  2578 
       
  2579 @panic USER 69, if aDateSuffix is outside the range 0 to 30.
       
  2580 */
       
  2581 	{
       
  2582 
       
  2583 	__ASSERT_ALWAYS(aSelector==EAm || aSelector==EPm,Panic(ETLoclSuffixOutOfRange));
       
  2584 	SLocaleLanguage localeLanguage;
       
  2585 	LocaleLanguageGet(localeLanguage);
       
  2586 	Copy((reinterpret_cast<const TText* const*>(localeLanguage.iAmPmTable))[aSelector]);
       
  2587 	}
       
  2588 
       
  2589 
       
  2590 
       
  2591 
       
  2592 EXPORT_C void TCurrencySymbol::Set()
       
  2593 /**
       
  2594 Re-retrieves the current locale's currency symbol(s).
       
  2595 */
       
  2596 	{
       
  2597 	SLocaleLocaleSettings locale;
       
  2598 	LocaleSettingsGet(locale);
       
  2599 	Copy(&locale.iCurrencySymbol[0]);
       
  2600 	}
       
  2601 
       
  2602 
       
  2603 
       
  2604 
       
  2605 EXPORT_C void TShortDateFormatSpec::Set()
       
  2606 /**
       
  2607 Sets the contents of the short date format specification from the system-wide 
       
  2608 settings.
       
  2609 */
       
  2610 	{
       
  2611 	SLocaleTimeDateFormat locale;
       
  2612 	LocaleTimeDateFormatGet(locale);
       
  2613 	Copy(&locale.iShortDateFormatSpec[0]);
       
  2614 	}
       
  2615 
       
  2616 
       
  2617 
       
  2618 
       
  2619 EXPORT_C void TLongDateFormatSpec::Set()
       
  2620 /**
       
  2621 Sets the contents of the long date format specification from the system-wide 
       
  2622 settings.
       
  2623 */
       
  2624 	{
       
  2625 	SLocaleTimeDateFormat locale;
       
  2626 	LocaleTimeDateFormatGet(locale);
       
  2627 	Copy(&locale.iLongDateFormatSpec[0]);
       
  2628 	}
       
  2629 
       
  2630 
       
  2631 
       
  2632 
       
  2633 EXPORT_C void TTimeFormatSpec::Set()
       
  2634 /**
       
  2635 Sets the contents of the time string format specification from the system-wide
       
  2636 settings.
       
  2637 */
       
  2638 	{
       
  2639 	SLocaleTimeDateFormat locale;
       
  2640 	LocaleTimeDateFormatGet(locale);
       
  2641 	Copy(&locale.iTimeFormatSpec[0]);
       
  2642 	}
       
  2643 
       
  2644 
       
  2645 
       
  2646 EXPORT_C TInt User::SetCurrencySymbol(const TDesC& aSymbol)
       
  2647 /**
       
  2648 Sets the system wide currency symbol.
       
  2649 
       
  2650 On successful return from this function, a call to the Set() member function 
       
  2651 of a TCurrencySymbol object fetches the new currency symbol.
       
  2652 
       
  2653 @capability WriteDeviceData
       
  2654 
       
  2655 @param aSymbol A reference to the descriptor containing the currency symbol 
       
  2656                to be set.
       
  2657                
       
  2658 @return KErrNone if successful, otherwise one of the other system wide error codes.
       
  2659 
       
  2660 @panic USER 119, if the length of aSymbol is greater than KMaxCurrencySymbol. 
       
  2661 
       
  2662 @see TCurrencySymbol
       
  2663 @see TCurrencySymbol::Set()
       
  2664 @see KMaxCurrencySymbol
       
  2665 */
       
  2666 	{
       
  2667 
       
  2668 	TExtendedLocale locale;
       
  2669 	return locale.SetCurrencySymbol(aSymbol);
       
  2670 	}
       
  2671 
       
  2672 
       
  2673 
       
  2674 EXPORT_C TLanguage User::Language()
       
  2675 /**
       
  2676 Gets the language of the current locale.
       
  2677 
       
  2678 @return One of the TLanguage enumerators identifying the language of the
       
  2679         current locale.
       
  2680 */
       
  2681 	{
       
  2682 
       
  2683 	SLocaleLanguage localeLanguage;
       
  2684 	LocaleLanguageGet(localeLanguage);
       
  2685 	return localeLanguage.iLanguage;
       
  2686 	}
       
  2687 
       
  2688 
       
  2689 
       
  2690 
       
  2691 EXPORT_C TLocale::TLocale()
       
  2692 /**
       
  2693 Default constructor.
       
  2694 
       
  2695 It constructs the object with the system's locale settings.
       
  2696 
       
  2697 A single copy of the locale information is maintained by the system. This 
       
  2698 copy may be refreshed under application control with TLocale::Refresh(), and 
       
  2699 the settings may be saved to the system with TLocale::Set(). However, the 
       
  2700 settings are never updated by the system apart from under application control. 
       
  2701 This enables applications to guarantee that consistent locale information 
       
  2702 is used.
       
  2703 
       
  2704 @see TLocale::Refresh()
       
  2705 @see TLocale::Set()
       
  2706 */
       
  2707 	{
       
  2708 
       
  2709 	Refresh();
       
  2710 	}
       
  2711 
       
  2712 
       
  2713 const TUint8 __DefaultDateSeparator[KMaxDateSeparators] = { 0, '/', '/', 0 };
       
  2714 const TUint8 __DefaultTimeSeparator[KMaxTimeSeparators] = { 0, ':', ':', 0 };
       
  2715 
       
  2716 void TLocale::SetDefaults()
       
  2717 	{
       
  2718 	iCountryCode = 44;
       
  2719 	iUniversalTimeOffset = 0;
       
  2720 	iDateFormat = EDateEuropean;
       
  2721 	iTimeFormat = ETime12;
       
  2722 	iCurrencySymbolPosition = ELocaleBefore;
       
  2723 	iCurrencySpaceBetween = EFalse;
       
  2724 	iCurrencyDecimalPlaces = 2;
       
  2725 	iNegativeCurrencyFormat = TNegativeCurrencyFormat(EFalse);
       
  2726 	iCurrencyTriadsAllowed = ETrue;
       
  2727 	iThousandsSeparator = ',';
       
  2728 	iDecimalSeparator = '.';
       
  2729 	TInt i=0;
       
  2730 	for(; i<KMaxDateSeparators; i++)
       
  2731 		iDateSeparator[i] = __DefaultDateSeparator[i];
       
  2732 	for(i=0; i<KMaxTimeSeparators; i++)
       
  2733 		iTimeSeparator[i] = __DefaultTimeSeparator[i];
       
  2734 	iAmPmSymbolPosition = ELocaleAfter;
       
  2735 	iAmPmSpaceBetween = ETrue;
       
  2736 	iHomeDaylightSavingZone = EDstEuropean;
       
  2737 	iWorkDays = 0x1f;
       
  2738 	iStartOfWeek = EMonday;
       
  2739 	iClockFormat = EClockAnalog;
       
  2740 	iUnitsGeneral = EUnitsImperial;
       
  2741 	iUnitsDistanceLong =  EUnitsImperial;
       
  2742 	iUnitsDistanceShort =  EUnitsImperial;
       
  2743 	iExtraNegativeCurrencyFormatFlags = 0;
       
  2744 	iLanguageDowngrade[0] = ELangNone;
       
  2745 	iLanguageDowngrade[1] = ELangNone;
       
  2746 	iLanguageDowngrade[2] = ELangNone;
       
  2747 	iDigitType = EDigitTypeWestern;
       
  2748 	iDeviceTimeState = TDeviceTimeState(EDeviceUserTime);
       
  2749 	}
       
  2750 
       
  2751 EXPORT_C void TLocale::Refresh()
       
  2752 /**
       
  2753 Refreshes the contents of this object with the system's locale settings.
       
  2754 */
       
  2755 	{
       
  2756 
       
  2757 #ifndef __TOOLS2__	
       
  2758 	TPckg<TLocale> localeDataBuf(*this);
       
  2759 	TInt r = RProperty::Get(KUidSystemCategory, KLocaleDataKey, localeDataBuf);
       
  2760 	__ASSERT_DEBUG(r == KErrNone || r == KErrNotFound, Panic(EBadLocaleParameter));
       
  2761 	if(r == KErrNone)
       
  2762 		{
       
  2763 		iUniversalTimeOffset = Exec::UTCOffset();
       
  2764 		iDaylightSaving = 0;
       
  2765 		}
       
  2766 	else if(r == KErrNotFound)
       
  2767 			{
       
  2768 			SetDefaults();
       
  2769 			}
       
  2770 #else
       
  2771 	
       
  2772 	if (gLocaleSet)
       
  2773 		{
       
  2774 		TLocale* loc = gLocale().GetLocale();
       
  2775 		memcpy(this, (void*)loc, sizeof(TLocale));
       
  2776 		}
       
  2777 	else
       
  2778 		{
       
  2779 		SetDefaults();
       
  2780 		}
       
  2781 	
       
  2782 #endif // __TOOLS2__
       
  2783 	}
       
  2784 
       
  2785 
       
  2786 EXPORT_C TInt TLocale::Set() const
       
  2787 /**
       
  2788 Transfers the locale settings from this object to the system. Note that
       
  2789 the timezone offset and daylight savings flags are ignored as setting these
       
  2790 through TLocale is no longer supported.
       
  2791 
       
  2792 After this function has been called, other applications may use the new
       
  2793 settings for newly-constructed TLocale objects,
       
  2794 or if they use TLocale::Refresh(), to refresh their settings from
       
  2795 the system copy.
       
  2796 
       
  2797 @capability WriteDeviceData
       
  2798 
       
  2799 @return KErrNone if successful, otherwise one of the other system wide error codes.
       
  2800 
       
  2801 @see TLocale::Refresh()
       
  2802 */
       
  2803 	{
       
  2804 #ifndef __TOOLS2__
       
  2805 	TPckg<TLocale> localeDataBuf(*this);
       
  2806 	TInt r = RProperty::Set(KUidSystemCategory, KLocaleDataKey, localeDataBuf);
       
  2807 	if(r == KErrNone)
       
  2808 		{
       
  2809 		Exec::NotifyChanges(EChangesLocale);
       
  2810 		}
       
  2811 	return r;
       
  2812 #else
       
  2813 	TLocale* loc = gLocale().GetLocale();
       
  2814 	memcpy((void*)loc, this, sizeof(TLocale));
       
  2815 	gLocaleSet = ETrue;
       
  2816 	return KErrNone;
       
  2817 #endif
       
  2818 	}
       
  2819 
       
  2820 
       
  2821 #ifdef __TOOLS2__
       
  2822 RLoader gLocaleLoader;
       
  2823 #endif
       
  2824 
       
  2825 TInt TExtendedLocale::DoLoadLocale(const TDesC& aLocaleDllName, TLibraryFunction* aExportList)
       
  2826 	{
       
  2827 #ifndef __TOOLS2__
       
  2828 	RLoader loader;
       
  2829 	TInt r = loader.LoadLocale(aLocaleDllName, aExportList);
       
  2830 	return r;
       
  2831 #else
       
  2832 	gLocaleLoader.Free();
       
  2833 	TInt r = gLocaleLoader.LoadLocale(aLocaleDllName, aExportList);
       
  2834 	return r;
       
  2835 #endif
       
  2836 	}
       
  2837 
       
  2838 void TExtendedLocale::DoUpdateLanguageSettings(TLibraryFunction* aExportList)
       
  2839 	{
       
  2840 	iLanguageSettings.iLanguage = (TLanguage)aExportList[FnLanguage]();
       
  2841 	iLanguageSettings.iDateSuffixTable = (const TText*)aExportList[FnDateSuffixTable]();
       
  2842 	iLanguageSettings.iDayTable = (const TText*)aExportList[FnDayTable]();
       
  2843 	iLanguageSettings.iDayAbbTable = (const TText*)aExportList[FnDayAbbTable]();
       
  2844 	iLanguageSettings.iMonthTable = (const TText*)aExportList[FnMonthTable]();
       
  2845 	iLanguageSettings.iMonthAbbTable = (const TText*)aExportList[FnMonthAbbTable]();
       
  2846 	iLanguageSettings.iAmPmTable = (const TText*)aExportList[FnAmPmTable]();
       
  2847 	iLanguageSettings.iMsgTable = (const TText16* const*)aExportList[FnMsgTable]();
       
  2848 	}
       
  2849 
       
  2850 void TExtendedLocale::DoUpdateLocaleSettings(TLibraryFunction* aExportList)
       
  2851 	{
       
  2852 	Mem::Copy(&iLocaleExtraSettings.iCurrencySymbol[0], (const TAny*)aExportList[FnCurrencySymbol](), sizeof(TText) * (KMaxCurrencySymbol+1));
       
  2853 	iLocaleExtraSettings.iLocaleExtraSettingsDllPtr = (TAny*)aExportList[FnDateSuffixTable]();
       
  2854 	}
       
  2855 
       
  2856 void TExtendedLocale::DoUpdateTimeDateFormat(TLibraryFunction* aExportList)
       
  2857 	{
       
  2858 	Mem::Copy(&iLocaleTimeDateFormat.iShortDateFormatSpec[0], (const TAny*)aExportList[FnShortDateFormatSpec](), sizeof(TText) * (KMaxShortDateFormatSpec+1));
       
  2859 	Mem::Copy(&iLocaleTimeDateFormat.iLongDateFormatSpec[0], (const TAny*)aExportList[FnLongDateFormatSpec](), sizeof(TText) * (KMaxLongDateFormatSpec+1)) ;
       
  2860 	Mem::Copy(&iLocaleTimeDateFormat.iTimeFormatSpec[0], (const TAny*)aExportList[FnTimeFormatSpec](), sizeof(TText) * (KMaxTimeFormatSpec+1));
       
  2861 	iLocaleTimeDateFormat.iLocaleTimeDateFormatDllPtr = (TAny*)aExportList[FnDateSuffixTable]();
       
  2862 	}
       
  2863 
       
  2864 /**
       
  2865 Default constructor.
       
  2866 
       
  2867 It constructs an empty object
       
  2868 
       
  2869 This is an empty copy of TExtendedLocale. To get the system locale you can
       
  2870 use TExtendedLocale::LoadSystemSettings. The current settings may be saved to the system
       
  2871 with TLocale::SaveSystemSettings().
       
  2872 
       
  2873 @see TExtendedLocale::LoadSystemSettings
       
  2874 @see TExtendedLocale::SaveSystemSettings
       
  2875 */
       
  2876 EXPORT_C TExtendedLocale::TExtendedLocale()
       
  2877 	: iLocale(0)
       
  2878 	{
       
  2879 	Mem::FillZ(&iLanguageSettings, sizeof(TExtendedLocale) - sizeof(TLocale));
       
  2880 	}
       
  2881 
       
  2882 /**
       
  2883 Load system wide locale settings
       
  2884 
       
  2885 It initialises this TExtendedLocale with the system wide locale settings.
       
  2886 The settings stored in the TExtendedLocale are overwritten with the system
       
  2887 wide locale.
       
  2888 
       
  2889 @see TExtendedLocale::SaveSystemSettings
       
  2890 */
       
  2891 EXPORT_C void TExtendedLocale::LoadSystemSettings()
       
  2892 	{
       
  2893 	LocaleLanguageGet(iLanguageSettings);
       
  2894 	LocaleSettingsGet(iLocaleExtraSettings);
       
  2895 	LocaleTimeDateFormatGet(iLocaleTimeDateFormat);
       
  2896 	iDefaultCharSet = GetLocaleCharSet();
       
  2897 	iPreferredCharSet = GetLocalePreferredCharSet();
       
  2898 	iLocale.Refresh();
       
  2899 	}
       
  2900 
       
  2901 #ifndef __TOOLS2__
       
  2902 /**
       
  2903 Make the current locale information system wide
       
  2904 
       
  2905 It overwrites the system wide locale information with the locale information
       
  2906 stored in this TExtendedLocale.
       
  2907 This will generate a notification for system locale changes.
       
  2908 In case of an error, the locale might be in an unconsistent state.
       
  2909 
       
  2910 @capability WriteDeviceData
       
  2911 
       
  2912 @return KErrNone if successful, otherwise one of the other system wide error codes.
       
  2913 */
       
  2914 EXPORT_C TInt TExtendedLocale::SaveSystemSettings()
       
  2915 	{
       
  2916 
       
  2917 	TPckg<SLocaleLanguage> localeLanguageBuf(iLanguageSettings);
       
  2918 	TInt r = RProperty::Set(KUidSystemCategory, KLocaleLanguageKey, localeLanguageBuf);
       
  2919 	if(r != KErrNone)
       
  2920 		return r;
       
  2921 
       
  2922 	TPckg<SLocaleLocaleSettings> localeSettingsBuf(iLocaleExtraSettings);
       
  2923 	r = RProperty::Set(KUidSystemCategory, KLocaleDataExtraKey, localeSettingsBuf);
       
  2924 	if(r != KErrNone)
       
  2925 		return r;
       
  2926 
       
  2927 	TPckg<SLocaleTimeDateFormat> localeTimeDateFormatBuf(iLocaleTimeDateFormat);
       
  2928 	r = RProperty::Set(KUidSystemCategory, KLocaleTimeDateFormatKey, localeTimeDateFormatBuf);
       
  2929 	if(r != KErrNone)
       
  2930 		return r;
       
  2931 
       
  2932 	r = Exec::SetGlobalUserData(ELocaleDefaultCharSet, (TInt)iDefaultCharSet);
       
  2933 	if(r != KErrNone)
       
  2934 		return r;
       
  2935 
       
  2936 	r = Exec::SetGlobalUserData(ELocalePreferredCharSet, (TInt)iPreferredCharSet);
       
  2937 
       
  2938 	if(r == KErrNone)
       
  2939 		{
       
  2940 		iLocale.Set();
       
  2941 		}
       
  2942 
       
  2943 	return r;
       
  2944 	}
       
  2945 #endif // __TOOLS2__
       
  2946 
       
  2947 
       
  2948 /**
       
  2949 Loads a locale Dll and get the locale information
       
  2950 
       
  2951 It loads a locale DLL and it initialises the contents of this TExtendedLocale
       
  2952 with the locale information stored in the DLL. The locale information is only
       
  2953 stored in this TExtendedLocale. If you want to set the system wide settings with
       
  2954 the locale information in the DLL, you can call TExtendedLocale::SaveSystemSettings
       
  2955 after calling this function.
       
  2956 
       
  2957 @param aLocaleDllName The name of the locale DLL to be loaded
       
  2958 @return KErrNone if successful, system wide error if not
       
  2959 
       
  2960 @see TExtendedLocale::SaveSystemSettings 
       
  2961 */
       
  2962 EXPORT_C TInt TExtendedLocale::LoadLocale(const TDesC& aLocaleDllName)
       
  2963 	{
       
  2964 	TLibraryFunction data[KNumLocaleExports];
       
  2965 	TInt r = DoLoadLocale(aLocaleDllName, &data[0]);
       
  2966 	if(r == KErrNone)
       
  2967 		{
       
  2968 		iLocale.iExtraNegativeCurrencyFormatFlags=0x80000000;
       
  2969 	  	iLocale.iLanguageDowngrade[0] = ELangNone;
       
  2970 		iLocale.iLanguageDowngrade[1] = ELangNone;
       
  2971   		iLocale.iLanguageDowngrade[2] = ELangNone;
       
  2972 	  	iLocale.iDigitType = EDigitTypeWestern;
       
  2973 
       
  2974 		typedef void (*TLibFn)(TLocale*);
       
  2975 		((TLibFn)data[FnLocaleData])(&iLocale);
       
  2976 
       
  2977 		//Locale daylightsavings unchanged - we have travelled through space, not time
       
  2978 		if (iLocale.iExtraNegativeCurrencyFormatFlags&0x80000000)
       
  2979 			iLocale.iExtraNegativeCurrencyFormatFlags=0;		
       
  2980 		
       
  2981 		DoUpdateLanguageSettings(&data[0]);
       
  2982 		DoUpdateLocaleSettings(&data[0]);
       
  2983 		DoUpdateTimeDateFormat(&data[0]);
       
  2984 
       
  2985 		iPreferredCharSet = (const LCharSet*)data[FnCharSet]();
       
  2986 		iDefaultCharSet = iPreferredCharSet;
       
  2987 		gLocaleSet = ETrue;
       
  2988 		gLocaleExSet = ETrue;
       
  2989 		}
       
  2990 	return r;
       
  2991 	}
       
  2992 
       
  2993 /**
       
  2994 Loads a DLL and get some locale information
       
  2995 
       
  2996 It loads the specified locale DLL and depending on the aAspectGroup it overwrites
       
  2997 locale information in this TExtendedLocale with the locale information stored in the
       
  2998 DLL. aAspectGroup is a bitmap of TLocaleAspect values specifying what to be overwritten.
       
  2999 The locale information is only stored in this TExtendedLocale. If you want to set the
       
  3000 system wide settings with the locale information in the DLL, you can call
       
  3001 TExtendedLocale::SaveSystemSettings after calling this function.
       
  3002 
       
  3003 @param aAspectGroup A bitmap of TLocaleAspect values specifying what to be overwritten in
       
  3004 					this TExtendedLocale. (eg.: ELocaleLanguageSettings | ELocaleTimeDateSettings)
       
  3005 @param aLocaleDllName The name of the locale DLL to be loaded
       
  3006 
       
  3007 @return KErrNone if the method is successful, a system wide error code if not
       
  3008 
       
  3009 @see TLocaleAspect
       
  3010 @see TExtendedLocale::SaveSystemSettings
       
  3011 */
       
  3012 EXPORT_C TInt TExtendedLocale::LoadLocaleAspect(TUint aAspectGroup, const TDesC& aLocaleDllName)
       
  3013 	{
       
  3014 	TLibraryFunction data[KNumLocaleExports];
       
  3015 	TInt r = DoLoadLocale(aLocaleDllName, &data[0]);
       
  3016 	if(r == KErrNone)
       
  3017 		{
       
  3018 		if(aAspectGroup & ELocaleLanguageSettings)
       
  3019 			{
       
  3020 			DoUpdateLanguageSettings(&data[0]);
       
  3021 			}
       
  3022 		if(aAspectGroup & ELocaleCollateSetting)
       
  3023 			{
       
  3024 			iPreferredCharSet = (const LCharSet*)data[FnCharSet]();
       
  3025 			iDefaultCharSet = iPreferredCharSet;
       
  3026 			}
       
  3027 		if(aAspectGroup & ELocaleLocaleSettings)
       
  3028 			{
       
  3029 			DoUpdateLocaleSettings(&data[0]);
       
  3030 			}
       
  3031 		if(aAspectGroup & ELocaleTimeDateSettings)
       
  3032 			{
       
  3033 			DoUpdateTimeDateFormat(&data[0]);
       
  3034 			}
       
  3035 		}
       
  3036 	return r;
       
  3037 	}
       
  3038 
       
  3039 /**
       
  3040 Sets the currency symbol
       
  3041 
       
  3042 It sets the currency symbol. The maximum lenght for the currency symbol is
       
  3043 KMaxCurrencySymbol. Trying to pass a descriptor longer than that, will result
       
  3044 in a panic.
       
  3045 
       
  3046 @param aSymbol The new currency symbol
       
  3047 
       
  3048 @panic USER 119, if the length of aSymbol is greater than KMaxCurrencySymbol.
       
  3049 
       
  3050 @capability WriteDeviceData
       
  3051 
       
  3052 @return KErrNone if successful, otherwise one of the other system wide error codes.
       
  3053 */
       
  3054 EXPORT_C TInt TExtendedLocale::SetCurrencySymbol(const TDesC &aSymbol)
       
  3055 	{
       
  3056 	__ASSERT_ALWAYS(aSymbol.Length()<=KMaxCurrencySymbol,::Panic(ECurrencySymbolOverflow));
       
  3057 	
       
  3058 	LocaleSettingsGet(iLocaleExtraSettings);
       
  3059 	Mem::Copy(&iLocaleExtraSettings.iCurrencySymbol[0], aSymbol.Ptr(), aSymbol.Length() << 1);
       
  3060 	iLocaleExtraSettings.iCurrencySymbol[aSymbol.Length()] = 0;
       
  3061 #ifndef __TOOLS2__
       
  3062 	TInt r = RProperty::Set(KUidSystemCategory, KLocaleDataExtraKey, TPckg<SLocaleLocaleSettings>(iLocaleExtraSettings));
       
  3063 	return r;
       
  3064 #else
       
  3065 	return KErrNone;
       
  3066 #endif
       
  3067 	}
       
  3068 
       
  3069 
       
  3070 #ifndef __TOOLS2__
       
  3071 /**
       
  3072 Returns the name of the DLL containing the given bits of locale information
       
  3073 
       
  3074 Given the bits of locale information specified in aLocaleDataSet, it returns the name
       
  3075 of the locale DLL storing the information. TExtendedLocale can contain information from
       
  3076 different DLLs.
       
  3077 
       
  3078 @param aLocaleDataSet The TLocaleAspect specifying a group of locale properties
       
  3079 @param aDllName The descriptor that will contain the name of DLL containing the specifying
       
  3080 				bits of locale information (valid if the method is successful)
       
  3081 
       
  3082 @return KErrNone if successful, system wide error otherwise
       
  3083 */
       
  3084 EXPORT_C TInt TExtendedLocale::GetLocaleDllName(TLocaleAspect aLocaleDataSet, TDes& aDllName)
       
  3085 	{
       
  3086  	TBuf8<KMaxFullName> buf;
       
  3087 	TAny* ptr = 0;
       
  3088 	switch(aLocaleDataSet)
       
  3089 		{
       
  3090 		case ELocaleLanguageSettings:
       
  3091 			ptr = (TAny*)iLanguageSettings.iDateSuffixTable;
       
  3092 			break;
       
  3093 		case ELocaleCollateSetting:
       
  3094 			ptr = (TAny*)iPreferredCharSet;
       
  3095 			break;
       
  3096 		case ELocaleLocaleSettings:
       
  3097 			ptr = (TAny*)iLocaleExtraSettings.iLocaleExtraSettingsDllPtr;
       
  3098 			break;
       
  3099 		case ELocaleTimeDateSettings:
       
  3100 			ptr = (TAny*)iLocaleTimeDateFormat.iLocaleTimeDateFormatDllPtr;
       
  3101 			break;
       
  3102 		}
       
  3103  	TInt r = Exec::GetModuleNameFromAddress(ptr, buf);
       
  3104  	if (r == KErrNone)
       
  3105 		{
       
  3106  		aDllName.Copy(buf);
       
  3107  		}
       
  3108  	return r;
       
  3109 	}
       
  3110 #endif // __TOOLS2__
       
  3111 
       
  3112 /**
       
  3113 Get the Currency Symbol from SLocaleLocaleSettings object
       
  3114 
       
  3115 @return TPtrC Pointer holding the Currency Symbol
       
  3116 */
       
  3117 EXPORT_C TPtrC TExtendedLocale::GetCurrencySymbol()
       
  3118 	{
       
  3119 	TPtrC outCurrencySymbolPtr(iLocaleExtraSettings.iCurrencySymbol);
       
  3120 	return outCurrencySymbolPtr;
       
  3121 	}
       
  3122 	
       
  3123 /**
       
  3124 Get the Long Date Format from SLocaleTimeDateFormat object
       
  3125 
       
  3126 @return TPtrC Pointer holding the Long Date Format
       
  3127 */
       
  3128 EXPORT_C TPtrC TExtendedLocale::GetLongDateFormatSpec()
       
  3129 	{
       
  3130 	TPtrC outLongDateFormatPtr(iLocaleTimeDateFormat.iLongDateFormatSpec);
       
  3131 	return outLongDateFormatPtr;
       
  3132 	}
       
  3133 	
       
  3134 /**
       
  3135 Get the Short Date Format from SLocaleTimeDateFormat object
       
  3136 
       
  3137 @return TPtrC Pointer holding the Short Date Format
       
  3138 */
       
  3139 EXPORT_C TPtrC TExtendedLocale::GetShortDateFormatSpec()
       
  3140 	{
       
  3141 	TPtrC outShortDateFormatPtr(iLocaleTimeDateFormat.iShortDateFormatSpec);
       
  3142 	return outShortDateFormatPtr;
       
  3143 	}
       
  3144 	
       
  3145 /**
       
  3146 Get the Time Format from SLocaleTimeDateFormat object
       
  3147 
       
  3148 @return TPtrC Pointer holding the Time Format
       
  3149 */
       
  3150 EXPORT_C TPtrC TExtendedLocale::GetTimeFormatSpec()
       
  3151 	{
       
  3152 	TPtrC outTimeFormatPtr(iLocaleTimeDateFormat.iTimeFormatSpec);
       
  3153 	return outTimeFormatPtr;
       
  3154 	}
       
  3155 
       
  3156 #ifndef __TOOLS2__
       
  3157 EXPORT_C TInt UserSvr::LocalePropertiesSetDefaults()
       
  3158 	{
       
  3159 	_LIT_SECURITY_POLICY_C1(KLocaleWritePolicy,ECapabilityWriteDeviceData);
       
  3160 	_LIT_SECURITY_POLICY_PASS(KLocaleReadPolicy);
       
  3161 
       
  3162 	TInt r = RProperty::Define(KUidSystemCategory, KLocaleLanguageKey, RProperty::EByteArray, KLocaleReadPolicy, KLocaleWritePolicy, sizeof(TPckg<SLocaleLanguage>));
       
  3163 	if(r != KErrNone && r != KErrAlreadyExists)
       
  3164 		return r;
       
  3165 	
       
  3166 	SLocaleLanguage localeLanguage;
       
  3167 	localeLanguage.iLanguage			= ELangEnglish;
       
  3168 	localeLanguage.iDateSuffixTable		= (const TText16*)__DefaultDateSuffixTable;
       
  3169 	localeLanguage.iDayTable			= (const TText16*)__DefaultDayTable;
       
  3170 	localeLanguage.iDayAbbTable			= (const TText16*)__DefaultDayAbbTable;
       
  3171 	localeLanguage.iMonthTable			= (const TText16*)__DefaultMonthTable;
       
  3172 	localeLanguage.iMonthAbbTable		= (const TText16*)__DefaultMonthAbbTable;
       
  3173 	localeLanguage.iAmPmTable			= (const TText16*)__DefaultAmPmTable;
       
  3174 	localeLanguage.iMsgTable			= (const TText16* const*)__DefaultLMsgTable;
       
  3175 	r = RProperty::Set(KUidSystemCategory, KLocaleLanguageKey, TPckg<SLocaleLanguage>(localeLanguage));
       
  3176 	if(r != KErrNone)
       
  3177 		return r;
       
  3178 
       
  3179 	r = RProperty::Define(KUidSystemCategory, KLocaleDataKey, RProperty::EByteArray, KLocaleReadPolicy, KLocaleWritePolicy, sizeof(TPckg<TLocale>));
       
  3180 	if(r != KErrNone && r != KErrAlreadyExists)
       
  3181 		return r;
       
  3182 
       
  3183 	TLocale locale(0);
       
  3184 	locale.SetDefaults();
       
  3185 
       
  3186 	r = RProperty::Set(KUidSystemCategory, KLocaleDataKey, TPckg<TLocale>(locale));
       
  3187 	if(r != KErrNone)
       
  3188 		return r;
       
  3189 
       
  3190 	r = RProperty::Define(KUidSystemCategory, KLocaleDataExtraKey, RProperty::EByteArray, KLocaleReadPolicy, KLocaleWritePolicy, sizeof(TPckg<SLocaleLocaleSettings>));
       
  3191 	if(r != KErrNone && r != KErrAlreadyExists)
       
  3192 		return r;
       
  3193 
       
  3194 	SLocaleLocaleSettings localeSettings;
       
  3195 	Mem::Copy(&localeSettings.iCurrencySymbol[0], _S16("\x00a3"), sizeof(TText16) * 2);
       
  3196 
       
  3197 	r = RProperty::Set(KUidSystemCategory, KLocaleDataExtraKey, TPckg<SLocaleLocaleSettings>(localeSettings));
       
  3198 	if(r != KErrNone)
       
  3199 		return r;
       
  3200 
       
  3201 	r = RProperty::Define(KUidSystemCategory, KLocaleTimeDateFormatKey, RProperty::EByteArray, KLocaleReadPolicy, KLocaleWritePolicy, sizeof(TPckg<SLocaleLocaleSettings>));
       
  3202 	if(r != KErrNone && r != KErrAlreadyExists)
       
  3203 		return r;
       
  3204 
       
  3205 	SLocaleTimeDateFormat localeTimeDateFormat;
       
  3206 	Mem::Copy(&localeTimeDateFormat.iShortDateFormatSpec[0], _S16("%F%*D/%*M/%Y"), sizeof(TText16) * 13);
       
  3207 	Mem::Copy(&localeTimeDateFormat.iLongDateFormatSpec[0], _S16("%F%*D%X %N %Y"), sizeof(TText16) * 14);
       
  3208 	Mem::Copy(&localeTimeDateFormat.iTimeFormatSpec[0], _S16("%F%*I:%T:%S %*A"), sizeof(TText16) * 16);
       
  3209 
       
  3210 	r = RProperty::Set(KUidSystemCategory, KLocaleTimeDateFormatKey, TPckg<SLocaleTimeDateFormat>(localeTimeDateFormat));
       
  3211 	if(r != KErrNone)
       
  3212 		return r;
       
  3213 
       
  3214 	TInt charSet = (TInt)GetLocaleDefaultCharSet();
       
  3215 	r = Exec::SetGlobalUserData(ELocaleDefaultCharSet, charSet);
       
  3216 	if(r != KErrNone)
       
  3217 		return r;
       
  3218 
       
  3219 	r = Exec::SetGlobalUserData(ELocalePreferredCharSet, charSet);
       
  3220 
       
  3221 	return r;
       
  3222 	}
       
  3223 #endif // __TOOLS2__
       
  3224 
       
  3225 // TOverflowHandler class created to handle the descriptor overflow in TLoacle::FormatCurrency
       
  3226 NONSHARABLE_CLASS(TOverflowHandler) : public TDesOverflow
       
  3227 	{
       
  3228 	void Overflow(TDes& aDes);
       
  3229 	};
       
  3230 
       
  3231 void TOverflowHandler::Overflow(TDes&)
       
  3232 	{
       
  3233 	Panic(ETDes16Overflow);
       
  3234 	}
       
  3235 
       
  3236 
       
  3237 
       
  3238 
       
  3239 EXPORT_C void TLocale::FormatCurrency(TDes& aText, TInt aAmount)
       
  3240 /**
       
  3241 Renders a currency value as text, based on the locale's currency and numeric 
       
  3242 format settings. 
       
  3243 
       
  3244 These settings include the currency symbol, the symbol's position and the 
       
  3245 way negative values are formatted.
       
  3246 
       
  3247 @param aText   On return, contains the currency value as text, formatted
       
  3248                according to the locale's currency format settings.
       
  3249 @param aAmount The currency value to be formatted.
       
  3250 
       
  3251 @panic USER 11, if aText is not long enough to hold the formatted value.
       
  3252 */
       
  3253 	{
       
  3254 	TOverflowHandler overflowHandler;
       
  3255 	FormatCurrency(aText,overflowHandler,aAmount);   
       
  3256 	}
       
  3257 
       
  3258 
       
  3259 
       
  3260 
       
  3261 EXPORT_C void TLocale::FormatCurrency(TDes& aText, TInt64 aAmount)
       
  3262 /**
       
  3263 Renders a currency value as text, based on the locale's currency and numeric 
       
  3264 format settings. 
       
  3265 
       
  3266 These settings include the currency symbol, the symbol's position and the 
       
  3267 way negative values are formatted.
       
  3268 
       
  3269 @param aText   On return, contains the currency value as text, formatted
       
  3270                according to the locale's currency format settings.
       
  3271 @param aAmount The currency value to be formatted.
       
  3272 
       
  3273 @panic USER 11, if aText is not long enough to hold the formatted value.
       
  3274 */
       
  3275 	{
       
  3276 	TOverflowHandler overflowHandler;
       
  3277 	FormatCurrency(aText,overflowHandler, aAmount);
       
  3278 	}
       
  3279 
       
  3280 
       
  3281 
       
  3282 
       
  3283 EXPORT_C void TLocale::FormatCurrency(TDes& aText, TDesOverflow& aOverflowHandler, TInt aAmount)
       
  3284 /**
       
  3285 Renders a currency value as text, based on the locale's currency and numeric 
       
  3286 format settings. 
       
  3287 
       
  3288 These settings include the currency symbol, the symbol's position and the 
       
  3289 way negative values are formatted. If aText is not long enough to hold the 
       
  3290 formatted currency value, the overflow handler's Overflow() function is called.
       
  3291 
       
  3292 @param aText            On return, contains the currency value as text,
       
  3293                         formatted according to the locale's currency format
       
  3294                         settings.
       
  3295 @param aOverflowHandler An object derived from TDesOverflow which handles
       
  3296                         descriptor overflows.
       
  3297 @param aAmount          The currency value to be formatted.
       
  3298 */
       
  3299 	{
       
  3300 	TInt64 aLongerInt(aAmount);
       
  3301 	FormatCurrency(aText, aOverflowHandler, aLongerInt); 
       
  3302 	}
       
  3303 
       
  3304 
       
  3305 
       
  3306 
       
  3307 EXPORT_C void TLocale::FormatCurrency(TDes& aText, TDesOverflow& aOverflowHandler, TInt64 aAmount)
       
  3308 /**
       
  3309 Renders a currency value as text, based on the locale's currency and numeric 
       
  3310 format settings. 
       
  3311 
       
  3312 These settings include the currency symbol, the symbol's position and the 
       
  3313 way negative values are formatted. If aText is not long enough to hold the 
       
  3314 formatted currency value, the overflow handler's Overflow() function is called.
       
  3315 
       
  3316 @param aText            On return, contains the currency value as text,
       
  3317                         formatted according to the locale's currency format
       
  3318                         settings.
       
  3319 @param aOverflowHandler An object derived from TDesOverflow which handles
       
  3320                         descriptor  overflows.
       
  3321 @param aAmount          The currency value to be formatted.
       
  3322 */
       
  3323 	{
       
  3324 	// aAmount is in cents (or equivalent) rather than dollars (or equivalent)
       
  3325 	const TBool amountIsNegative=(aAmount<0);
       
  3326 	if (amountIsNegative)
       
  3327 		{
       
  3328 		aAmount=-aAmount;
       
  3329 		}
       
  3330 	aText.Num(aAmount, EDecimal);
       
  3331 	const TInt currencyDecimalPlaces=CurrencyDecimalPlaces();
       
  3332 	TInt positionOfDecimalSeparator=aText.Length();
       
  3333 	if (currencyDecimalPlaces>0)
       
  3334 		{
       
  3335 		while (positionOfDecimalSeparator <= currencyDecimalPlaces)
       
  3336 			{
       
  3337 			if (aText.Length() == aText.MaxLength())
       
  3338 				{
       
  3339 				aOverflowHandler.Overflow(aText);
       
  3340 				return;
       
  3341 				}
       
  3342 			aText.Insert(0,KLitZeroPad);
       
  3343 			++positionOfDecimalSeparator;
       
  3344 			}
       
  3345 		positionOfDecimalSeparator=aText.Length();
       
  3346 		positionOfDecimalSeparator-=currencyDecimalPlaces;
       
  3347 		TBuf<1> decimalSeparator;
       
  3348 		decimalSeparator.Append(DecimalSeparator());
       
  3349 		if (aText.Length() == aText.MaxLength())
       
  3350 			{
       
  3351 			aOverflowHandler.Overflow(aText);
       
  3352 			return;
       
  3353 			}
       
  3354 		aText.Insert(positionOfDecimalSeparator, decimalSeparator);
       
  3355 		}
       
  3356 	if (CurrencyTriadsAllowed())
       
  3357 		{
       
  3358 		TBuf<1> thousandsSeparator;
       
  3359 		thousandsSeparator.Append(ThousandsSeparator());
       
  3360 		TInt numberOfThousandsSeparator = positionOfDecimalSeparator/3;
       
  3361 		if ((aText.Length()+numberOfThousandsSeparator) > aText.MaxLength())
       
  3362 			{
       
  3363 			aOverflowHandler.Overflow(aText);
       
  3364 			return;
       
  3365 			}
       
  3366 		for (TInt i=positionOfDecimalSeparator-3; i>0; i-=3)
       
  3367 			{
       
  3368 			aText.Insert(i, thousandsSeparator);
       
  3369 			}
       
  3370 		}
       
  3371 	TInt positionToInsertCurrencySymbol = 0; 
       
  3372 	switch (CurrencySymbolPosition())
       
  3373 		{
       
  3374 		case ELocaleBefore:
       
  3375 			{
       
  3376 			if ((amountIsNegative) && (NegativeCurrencySymbolOpposite()))
       
  3377 				{
       
  3378 				positionToInsertCurrencySymbol=aText.Length();
       
  3379 				}
       
  3380 			else
       
  3381 				positionToInsertCurrencySymbol=0;
       
  3382 			}
       
  3383 			break;
       
  3384 		case ELocaleAfter:
       
  3385 			{
       
  3386 			if ((amountIsNegative) && (NegativeCurrencySymbolOpposite()))
       
  3387 				{
       
  3388 				positionToInsertCurrencySymbol=0;
       
  3389 				}
       
  3390 			else
       
  3391 				positionToInsertCurrencySymbol=aText.Length();
       
  3392 			}
       
  3393 			break;
       
  3394 		default:
       
  3395 			Panic(ETRegionOutOfRange);
       
  3396 			break;
       
  3397 		}
       
  3398 	if (CurrencySpaceBetween())
       
  3399 		{
       
  3400 		if (aText.Length() == aText.MaxLength())
       
  3401 			{
       
  3402 			aOverflowHandler.Overflow(aText);
       
  3403 			return;
       
  3404 			}
       
  3405 		if ((amountIsNegative) && (NegativeLoseSpace()))
       
  3406 			{
       
  3407 			// don't add the space
       
  3408 			}
       
  3409 		else
       
  3410 			{
       
  3411 			aText.Insert(positionToInsertCurrencySymbol, KLitSpace); 
       
  3412 			if (positionToInsertCurrencySymbol>0)
       
  3413 				{
       
  3414 				++positionToInsertCurrencySymbol;
       
  3415 				}
       
  3416 			}
       
  3417 		}
       
  3418 	TCurrencySymbol theCurrencySymbol;
       
  3419 	if ((aText.Length()+theCurrencySymbol.Length()) > aText.MaxLength())
       
  3420 		{
       
  3421 		aOverflowHandler.Overflow(aText);
       
  3422 		return;
       
  3423 		}
       
  3424 	aText.Insert(positionToInsertCurrencySymbol,theCurrencySymbol);
       
  3425 	if (amountIsNegative)
       
  3426 		{
       
  3427 		TInt positionToInsertInterveningMinusSign = 0;
       
  3428 		if ((CurrencySpaceBetween()) && !(NegativeLoseSpace()))
       
  3429 			{
       
  3430 			if (positionToInsertCurrencySymbol>0)
       
  3431 				{
       
  3432 				positionToInsertInterveningMinusSign = positionToInsertCurrencySymbol-1;
       
  3433 				}
       
  3434 			else
       
  3435 				{
       
  3436 				positionToInsertInterveningMinusSign = theCurrencySymbol.Length()+1;
       
  3437 				}
       
  3438 			}
       
  3439 		else
       
  3440 			{
       
  3441 			if (positionToInsertCurrencySymbol>0)
       
  3442 				{
       
  3443 				positionToInsertInterveningMinusSign = positionToInsertCurrencySymbol;
       
  3444 				}
       
  3445 			else
       
  3446 				{
       
  3447 				positionToInsertInterveningMinusSign = theCurrencySymbol.Length();
       
  3448 				}
       
  3449 			}
       
  3450 		switch (NegativeCurrencyFormat())
       
  3451 			{
       
  3452 			case EInBrackets:
       
  3453 				{
       
  3454 				if ((aText.Length()+2) > aText.MaxLength())
       
  3455 					{
       
  3456 					aOverflowHandler.Overflow(aText);
       
  3457 					return;
       
  3458 					}
       
  3459 				aText.Insert(0, KLitOpeningBracket);
       
  3460 				aText.Append(')');
       
  3461 				}
       
  3462 				break;
       
  3463 			case ELeadingMinusSign:
       
  3464 				{
       
  3465 				if (aText.Length() == aText.MaxLength())
       
  3466 					{
       
  3467 					aOverflowHandler.Overflow(aText);
       
  3468 					return;
       
  3469 					}
       
  3470 				aText.Insert(0, KLitMinusSign);
       
  3471 				}
       
  3472 				break;
       
  3473 			case ETrailingMinusSign:
       
  3474 				{
       
  3475 				if (aText.Length() == aText.MaxLength())
       
  3476 					{
       
  3477 					aOverflowHandler.Overflow(aText);
       
  3478 					return;
       
  3479 					}
       
  3480 				aText.Append(KLitMinusSign);
       
  3481 				}
       
  3482 				break;
       
  3483 			case EInterveningMinusSign:
       
  3484 				{
       
  3485 				if (aText.Length() == aText.MaxLength())
       
  3486 					{
       
  3487 					aOverflowHandler.Overflow(aText);
       
  3488 					return;
       
  3489 					}
       
  3490 				aText.Insert(positionToInsertInterveningMinusSign, KLitMinusSign);
       
  3491 				}
       
  3492 				break;
       
  3493 			default:
       
  3494 				Panic(ETRegionOutOfRange);
       
  3495 				break;
       
  3496 			}
       
  3497 		}
       
  3498 	}
       
  3499 
       
  3500 
       
  3501 EXPORT_C void TLocaleMessageText::Set(TLocaleMessage aMsgNo)
       
  3502 //
       
  3503 // Get some text from Locale
       
  3504 //
       
  3505 	{
       
  3506 	if(TUint(aMsgNo) < ELocaleMessages_LastMsg)
       
  3507 		{
       
  3508 		SLocaleLanguage localeLanguage;
       
  3509 		LocaleLanguageGet(localeLanguage);
       
  3510 		Copy((reinterpret_cast<const TText* const*>(localeLanguage.iMsgTable))[aMsgNo]);
       
  3511 		}
       
  3512 	else
       
  3513 		SetLength(0);
       
  3514 	}
       
  3515 
       
  3516 
       
  3517 
       
  3518 #ifndef __TOOLS2__
       
  3519 EXPORT_C TInt TFindServer::Next(TFullName &aResult)
       
  3520 /**
       
  3521 Gets the full name of the next server which matches the match pattern.
       
  3522 
       
  3523 @param aResult A reference to a descriptor with a defined maximum length.
       
  3524                If a matching server is found, its full name is set into
       
  3525                this descriptor. If no matching server is found,
       
  3526                the descriptor length is set to zero.
       
  3527                
       
  3528 @return KErrNone if a matching server is found, KErrNotFound otherwise.
       
  3529 */
       
  3530 	{
       
  3531 	return NextObject(aResult,EServer);
       
  3532 	}
       
  3533 
       
  3534 
       
  3535 
       
  3536 
       
  3537 EXPORT_C void RServer2::Receive(RMessage2& aMessage, TRequestStatus &aStatus)
       
  3538 //
       
  3539 // Receive a message from the server asynchronously.
       
  3540 //
       
  3541 	{
       
  3542 
       
  3543 	aStatus=KRequestPending;
       
  3544 	Exec::ServerReceive(iHandle, aStatus, &aMessage);
       
  3545 	}
       
  3546 
       
  3547 EXPORT_C void RServer2::Cancel()
       
  3548 //
       
  3549 // Cancel a pending message receive.
       
  3550 //
       
  3551 	{
       
  3552 
       
  3553 	Exec::ServerCancel(iHandle);
       
  3554 	}
       
  3555 
       
  3556 
       
  3557 
       
  3558 
       
  3559 EXPORT_C TInt TFindMutex::Next(TFullName &aResult)
       
  3560 /**
       
  3561 Finds the next global mutex whose full name matches the match pattern.
       
  3562 
       
  3563 If a global mutex with a matching name is found, the function copies its full 
       
  3564 name into the specified descriptor. It also saves the find-handle associated 
       
  3565 with the global mutex into the TFindHandleBase part of this object.
       
  3566 
       
  3567 @param aResult A reference to a descriptor with a defined maximum length. 
       
  3568                If a matching global mutex is found, its full name is set
       
  3569                into this descriptor. 
       
  3570                If no matching global mutex is found, the descriptor length
       
  3571                is set to zero.
       
  3572                
       
  3573 @return KErrNone if a matching global mutex is found;
       
  3574         KErrNotFound otherwise.
       
  3575 */
       
  3576 	{
       
  3577 	return NextObject(aResult,EMutex);
       
  3578 	}
       
  3579 
       
  3580 
       
  3581 
       
  3582 
       
  3583 /**
       
  3584 Acquire the mutex, waiting for it to become free if necessary.
       
  3585 
       
  3586 This function checks if the mutex is currently held. If not the mutex is marked
       
  3587 as held by the current thread and the call returns immediately. If the mutex is
       
  3588 held by another thread the current thread will suspend until the mutex becomes
       
  3589 free. If the mutex is already held by the current thread a count is maintained
       
  3590 of how many times the thread has acquired the mutex.
       
  3591 */
       
  3592 EXPORT_C void RMutex::Wait()
       
  3593 	{
       
  3594 
       
  3595 	Exec::MutexWait(iHandle);
       
  3596 	}
       
  3597 
       
  3598 
       
  3599 
       
  3600 
       
  3601 /**
       
  3602 Release the mutex.
       
  3603 
       
  3604 This function decrements the count of how many times the current thread has
       
  3605 acquired this mutex. If the count is now zero the mutex is marked as free and,
       
  3606 if any other threads are waiting for the mutex to become free, the highest
       
  3607 priority among those is made ready to run. However the mutex is not marked as
       
  3608 held by any thread - the thread which has just been awakened must actually run
       
  3609 in order to acquire the mutex.
       
  3610 
       
  3611 @pre The mutex must previously have been acquired by the current thread calling
       
  3612 Wait().
       
  3613 
       
  3614 @panic KERN-EXEC 1 If the mutex has not previously been acquired by the current
       
  3615 thread calling Wait().
       
  3616 */
       
  3617 EXPORT_C void RMutex::Signal()
       
  3618 	{
       
  3619 
       
  3620 	Exec::MutexSignal(iHandle);
       
  3621 	}
       
  3622 
       
  3623 
       
  3624 
       
  3625 /**
       
  3626 Test if this mutex is held by the current thread.
       
  3627 @return True if the current thread has waited on the mutex, false otherwise.
       
  3628 */
       
  3629 EXPORT_C TBool RMutex::IsHeld()
       
  3630 	{
       
  3631 	return Exec::MutexIsHeld(iHandle);
       
  3632 	}
       
  3633 
       
  3634 
       
  3635 /** Wait on a condition variable
       
  3636 
       
  3637 This call releases the specified mutex then atomically blocks the current
       
  3638 thread on this condition variable. The atomicity here is with respect to the
       
  3639 condition variable and mutex concerned. Specifically if the condition variable
       
  3640 is signalled at any time after the mutex is released then this thread will be
       
  3641 awakened. Once the thread has awakened it will reacquire the specified mutex
       
  3642 before this call returns (except in the case where the condition variable has
       
  3643 been deleted).
       
  3644 
       
  3645 The usage pattern for this is as follows:
       
  3646 
       
  3647 @code
       
  3648 	mutex.Wait();
       
  3649 	while(!CONDITION)
       
  3650 		condvar.Wait(mutex);
       
  3651 	STATEMENTS;
       
  3652 	mutex.Signal();
       
  3653 @endcode
       
  3654 
       
  3655 where CONDITION is an arbitrary condition involving any number of user-side
       
  3656 variables whose integrity is protected by the mutex.
       
  3657 
       
  3658 It is necessary to loop while testing the condition because there is **no** guarantee
       
  3659 that the condition has been satisfied when the condition variable is signalled.
       
  3660 Different threads may be waiting on different conditions or the condition may
       
  3661 have already been absorbed by another thread. All that can be said is that the
       
  3662 thread will awaken whenever something happens which **might** affect the condition.
       
  3663 
       
  3664 It needs to be stressed that if:
       
  3665 
       
  3666 @code
       
  3667 condvar.Wait(mutex);
       
  3668 @endcode
       
  3669 
       
  3670 completes, it does not necessarily mean that the condition is yet satisfied, hence the necessity for the loop.
       
  3671 
       
  3672 @param	aMutex		The mutex to be released and reacquired.
       
  3673 @return	KErrNone	if the condition variable has been signalled.
       
  3674 		KErrInUse	if another thread is already waiting on this condition
       
  3675 					variable in conjunction with a different mutex.
       
  3676 		KErrGeneral	if the condition variable is deleted.
       
  3677 
       
  3678 @pre	The specified mutex is held by the current thread.
       
  3679 @post	The specified mutex is held by the current thread unless the return
       
  3680 		value is KErrGeneral in which case the condition variable no longer
       
  3681 		exists.
       
  3682 
       
  3683 @panic	KERN-EXEC 0 if either the condition variable or mutex handles are not
       
  3684 		valid.
       
  3685 @panic	KERN-EXEC 54 if the current thread does not hold the specified mutex.
       
  3686 
       
  3687 @see	RCondVar::Signal()
       
  3688 @see	RCondVar::Broadcast()
       
  3689 */
       
  3690 EXPORT_C TInt RCondVar::Wait(RMutex& aMutex)
       
  3691 	{
       
  3692 	return Exec::CondVarWait(iHandle, aMutex.Handle(), 0);
       
  3693 	}
       
  3694 
       
  3695 
       
  3696 
       
  3697 /** Wait on a condition variable with timeout
       
  3698 
       
  3699 This is the same as RCondVar::Wait(RMutex) except that there is a time limit on
       
  3700 how long the current thread will block while waiting for the condition variable.
       
  3701 
       
  3702 @param	aMutex		The mutex to be released and reacquired.
       
  3703 @param	aTimeout	The maximum time to wait in microseconds.
       
  3704 					0 means no maximum.
       
  3705 @return	KErrNone	if the condition variable has been signalled.
       
  3706 		KErrInUse	if another thread is already waiting on this condition
       
  3707 					variable in conjunction with a different mutex.
       
  3708 		KErrGeneral	if the condition variable is deleted.
       
  3709 		KErrTimedOut if the timeout expired before the condition variable was
       
  3710 					signalled.
       
  3711 
       
  3712 @pre	The specified mutex is held by the current thread.
       
  3713 @post	The specified mutex is held by the current thread unless the return
       
  3714 		value is KErrGeneral in which case the condition variable no longer
       
  3715 		exists.
       
  3716 
       
  3717 @panic	KERN-EXEC 0 if either the condition variable or mutex handles are not
       
  3718 		valid.
       
  3719 @panic	KERN-EXEC 54 if the current thread does not hold the specified mutex.
       
  3720 
       
  3721 @see	RCondVar::Wait(RMutex)
       
  3722 */
       
  3723 EXPORT_C TInt RCondVar::TimedWait(RMutex& aMutex, TInt aTimeout)
       
  3724 	{
       
  3725 	return Exec::CondVarWait(iHandle, aMutex.Handle(), aTimeout);
       
  3726 	}
       
  3727 
       
  3728 
       
  3729 /** Signal a condition variable
       
  3730 
       
  3731 This unblocks a single thread which is currently blocked on the condition
       
  3732 variable. The highest priority waiting thread which is not explicitly suspended
       
  3733 will be the one unblocked. If there are no threads currently waiting this call
       
  3734 does nothing.
       
  3735 
       
  3736 It is not required that any mutex is held when calling this function but it is
       
  3737 recommended that the mutex associated with the condition variable is held since
       
  3738 otherwise a race condition can result from the condition variable being signalled
       
  3739 just after the waiting thread testing the condition and before it calls Wait().
       
  3740 
       
  3741 */
       
  3742 EXPORT_C void RCondVar::Signal()
       
  3743 	{
       
  3744 	Exec::CondVarSignal(iHandle);
       
  3745 	}
       
  3746 
       
  3747 
       
  3748 
       
  3749 /** Broadcast to a condition variable
       
  3750 
       
  3751 This unblocks all threads which are currently blocked on the condition
       
  3752 variable. If there are no threads currently waiting this call does nothing.
       
  3753 
       
  3754 It is not required that any mutex is held when calling this function but it is
       
  3755 recommended that the mutex associated with the condition variable is held since
       
  3756 otherwise a race condition can result from the condition variable being signalled
       
  3757 just after the waiting thread testing the condition and before it calls Wait().
       
  3758 
       
  3759 */
       
  3760 EXPORT_C void RCondVar::Broadcast()
       
  3761 	{
       
  3762 	Exec::CondVarBroadcast(iHandle);
       
  3763 	}
       
  3764 
       
  3765 
       
  3766 
       
  3767 
       
  3768 EXPORT_C TInt TFindProcess::Next(TFullName &aResult)
       
  3769 /**
       
  3770 Gets the full name of the next process which matches the match pattern.
       
  3771 
       
  3772 @param aResult A reference to a TBuf descriptor with a defined maximum length.
       
  3773                If a matching process is found, its full name is set into
       
  3774                this descriptor. If no matching process is found, the descriptor
       
  3775                length is set to zero.
       
  3776 
       
  3777 @return KErrNone if successful, otherwise one of the other  system-wide error
       
  3778         codes.
       
  3779 */
       
  3780 	{
       
  3781 	return NextObject(aResult,EProcess);
       
  3782 	}
       
  3783 
       
  3784 
       
  3785 
       
  3786 
       
  3787 EXPORT_C TUidType RProcess::Type() const
       
  3788 /**
       
  3789 Gets the Uid type associated with the process. 
       
  3790 
       
  3791 @return A reference to a TUidType object containing the process type.
       
  3792 */
       
  3793 	{
       
  3794 
       
  3795 	TUidType u;
       
  3796 	Exec::ProcessType(iHandle,u);
       
  3797 	return(u);
       
  3798 	}
       
  3799 
       
  3800 
       
  3801 
       
  3802 
       
  3803 EXPORT_C TProcessId RProcess::Id() const
       
  3804 /**
       
  3805 Gets the Id of this process.
       
  3806 
       
  3807 @return The Id of this process.
       
  3808 */
       
  3809 	{
       
  3810 
       
  3811 	return TProcessId( (TUint)Exec::ProcessId(iHandle) );
       
  3812 	}
       
  3813 
       
  3814 
       
  3815 
       
  3816 
       
  3817 EXPORT_C void RProcess::Resume()
       
  3818 /**
       
  3819 Makes the first thread in the process eligible for execution.
       
  3820 
       
  3821 @panic KERN-EXEC 32 if the process is not yet fully loaded.
       
  3822 
       
  3823 @see RThread::Resume()
       
  3824 */
       
  3825 	{
       
  3826 
       
  3827 	Exec::ProcessResume(iHandle);
       
  3828 	}
       
  3829 
       
  3830 
       
  3831 
       
  3832 EXPORT_C TFileName RProcess::FileName() const
       
  3833 /**
       
  3834 Gets a copy of the full path name of the loaded executable on which this 
       
  3835 process is based.
       
  3836 
       
  3837 This is the file name which is passed to the Create() member function of this 
       
  3838 RProcess.
       
  3839 
       
  3840 @return A TBuf descriptor with a defined maximum length containing the full 
       
  3841         path name of the file.
       
  3842         
       
  3843 @see RProcess::Create()
       
  3844 */
       
  3845 	{
       
  3846 
       
  3847 	TFileName n;
       
  3848 	TPtr8 n8(((TUint8*)n.Ptr()) + KMaxFileName, KMaxFileName);
       
  3849 	Exec::ProcessFileName(iHandle,n8);
       
  3850 	n.Copy(n8);
       
  3851 	return(n);
       
  3852 	}
       
  3853 #endif // __TOOLS2__
       
  3854 
       
  3855 
       
  3856 
       
  3857 EXPORT_C void User::CommandLine(TDes &aCommand)
       
  3858 /**
       
  3859 Gets a copy of the data which is passed as an argument to the thread function
       
  3860 of the current process's main thread when it is first scheduled to run.
       
  3861 
       
  3862 @param aCommand A modifiable descriptor supplied by the caller into which the
       
  3863                 argument data is put. The descriptor must be big enough to
       
  3864                 contain the expected data, otherwise the function raises
       
  3865                 a panic.
       
  3866 
       
  3867 @see User::CommandLineLength()
       
  3868 */
       
  3869 	{
       
  3870 	TPtr8 aCommand8((TUint8*)aCommand.Ptr(),aCommand.MaxLength()<<1);
       
  3871 	Exec::ProcessCommandLine(KCurrentProcessHandle,aCommand8);
       
  3872 	aCommand.SetLength(aCommand8.Length()>>1);
       
  3873 	}
       
  3874 
       
  3875 
       
  3876 
       
  3877 
       
  3878 EXPORT_C TInt User::CommandLineLength()
       
  3879 /**
       
  3880 Gets the length of the data which is passed as an argument to the thread
       
  3881 function of the current process's main thread when it is first scheduled
       
  3882 to run.
       
  3883 
       
  3884 @return The length of the argument data.
       
  3885 */
       
  3886 	{
       
  3887 	return Exec::ProcessCommandLineLength(KCurrentProcessHandle);
       
  3888 	}
       
  3889 
       
  3890 
       
  3891 
       
  3892 #ifndef __TOOLS2__
       
  3893 EXPORT_C TExitType RProcess::ExitType() const
       
  3894 /**
       
  3895 Tests whether the process has ended and, if it has ended, return how it ended.
       
  3896 
       
  3897 This information allows the caller to distinguish between normal termination 
       
  3898 and a panic.
       
  3899 
       
  3900 @return An enumeration whose enumerators describe how the process has ended.
       
  3901 */
       
  3902 	{
       
  3903 
       
  3904 	return(Exec::ProcessExitType(iHandle));
       
  3905 	}
       
  3906 
       
  3907 
       
  3908 
       
  3909 
       
  3910 EXPORT_C TInt RProcess::ExitReason() const
       
  3911 /** 
       
  3912 Gets the specific reason associated with the end of this process.
       
  3913 
       
  3914 The reason number together with the category name is a way of distinguishing
       
  3915 between different causes of process termination.
       
  3916 
       
  3917 If the process has panicked, this value is the panic number. If the process 
       
  3918 has ended as a result of a call to Kill(), then the value is the one supplied 
       
  3919 by Kill().
       
  3920 
       
  3921 If the process has not ended, then the returned value is zero.
       
  3922 
       
  3923 @return The reason associated with the end of the process.
       
  3924 
       
  3925 @see RProcess::Kill()
       
  3926 */
       
  3927 	{
       
  3928 
       
  3929 	return(Exec::ProcessExitReason(iHandle));
       
  3930 	}
       
  3931 
       
  3932 
       
  3933 
       
  3934 
       
  3935 EXPORT_C TExitCategoryName RProcess::ExitCategory() const
       
  3936 /**
       
  3937 Gets the name of the category associated with the end of the process.
       
  3938 
       
  3939 The category name together with the reason number is a way of distinguishing
       
  3940 between different causes of process termination.
       
  3941 
       
  3942 If the process has panicked, the category name is the panic category name; 
       
  3943 for example, E32USER-CBase or KERN-EXEC. If the process has ended as a result 
       
  3944 of a call to Kill(), then the category name is Kill.
       
  3945 
       
  3946 If the process has not ended, then the category name is empty, i.e. the length 
       
  3947 of the category name is zero.
       
  3948 
       
  3949 @return A descriptor with a defined maximum length containing the 
       
  3950         name of the category associated with the end of the process.
       
  3951         
       
  3952 @see RProcess::Kill()
       
  3953 */
       
  3954 	{
       
  3955 
       
  3956 	TExitCategoryName n;
       
  3957 	TPtr8 n8(((TUint8*)n.Ptr()) + KMaxExitCategoryName, KMaxExitCategoryName);
       
  3958 	Exec::ProcessExitCategory(iHandle,n8);
       
  3959 	n.Copy(n8);
       
  3960 	return(n);
       
  3961 	}
       
  3962 
       
  3963 
       
  3964 
       
  3965 
       
  3966 EXPORT_C TProcessPriority RProcess::Priority() const
       
  3967 /**
       
  3968 Gets the priority of this process.
       
  3969 
       
  3970 @return One of the TProcessPriority enumerator values.
       
  3971 */
       
  3972 	{
       
  3973 
       
  3974 	return(Exec::ProcessPriority(iHandle));
       
  3975 	}
       
  3976 
       
  3977 
       
  3978 
       
  3979 
       
  3980 EXPORT_C void RProcess::SetPriority(TProcessPriority aPriority) const
       
  3981 /**
       
  3982 Sets the priority of this process to one of the values defined by theTProcessPriority 
       
  3983 enumeration. The priority can be set to one of the four values:
       
  3984 
       
  3985 EPriorityLow
       
  3986 
       
  3987 EPriorityBackground
       
  3988 
       
  3989 EPriorityForeground
       
  3990 
       
  3991 EPriorityHigh
       
  3992 
       
  3993 The absolute priority of all threads owned by the process (and all threads 
       
  3994 owned by those threads etc.) are re-calculated.
       
  3995 
       
  3996 Notes:
       
  3997 
       
  3998 The priority values EPriorityWindowServer, EPriorityFileServer, EPriorityRealTimeServer 
       
  3999 and EPrioritySupervisor are internal to Symbian OS and any attempt to explicitly 
       
  4000 set any of these priority values causes a KERN-EXEC 14 panic to be raised.
       
  4001 
       
  4002 Any attempt to set the priority of a process which is protected and is different 
       
  4003 from the process owning the thread which invokes this function, causes a KERN-EXEC 
       
  4004 1 panic to be raised.
       
  4005 
       
  4006 A process can set its own priority whether it is protected or not.
       
  4007 
       
  4008 @param aPriority The priority value.
       
  4009 */
       
  4010 	{
       
  4011 
       
  4012 	Exec::ProcessSetPriority(iHandle,aPriority);
       
  4013 	}
       
  4014 
       
  4015 
       
  4016 
       
  4017 
       
  4018 /**
       
  4019 Tests whether "Just In Time" debugging is enabled or not for this process.
       
  4020 
       
  4021 @return True, when "Just In Time" debugging is enabled. False otherwise.
       
  4022 @see RProcess::SetJustInTime
       
  4023 */
       
  4024 
       
  4025 EXPORT_C TBool RProcess::JustInTime() const
       
  4026 	{
       
  4027 
       
  4028 	return (Exec::ProcessFlags(iHandle) & KProcessFlagJustInTime) != 0;
       
  4029 	}
       
  4030 
       
  4031 
       
  4032 /**
       
  4033 Enables or disables "Just In Time" debugging for this process.
       
  4034 This will only have an effect when running on the emulator.
       
  4035 
       
  4036 "Just In Time" debugging catches a thread just before it executes a panic
       
  4037 or exception routine.  Capturing a thread early, before it is terminated, 
       
  4038 allows the developer to more closely inspect what went wrong, before the 
       
  4039 kernel removes the thread.  In some cases, the developer can modify context,
       
  4040 program counter, and variables to recover the thread.  This is only possible
       
  4041 on the emulator.
       
  4042 
       
  4043 By default, "Just In Time" debugging is enabled.
       
  4044 
       
  4045 @param aBoolean ETrue, to enable just-in-time debugging.
       
  4046 				EFalse, to disable just-in-time debugging.
       
  4047 */
       
  4048 EXPORT_C void RProcess::SetJustInTime(TBool aState) const
       
  4049 	{
       
  4050 
       
  4051 	TUint32 set = aState ? KProcessFlagJustInTime : 0;
       
  4052 	Exec::ProcessSetFlags(iHandle, KProcessFlagJustInTime, set);
       
  4053 	}
       
  4054 
       
  4055 
       
  4056 
       
  4057 
       
  4058 EXPORT_C TInt RProcess::SecureApi(TInt /*aState*/)
       
  4059 	{
       
  4060 	return ESecureApiOn;
       
  4061 	}
       
  4062 
       
  4063 EXPORT_C TInt RProcess::DataCaging(TInt /*aState*/)
       
  4064 	{
       
  4065 	return EDataCagingOn;
       
  4066 	}
       
  4067 
       
  4068 
       
  4069 
       
  4070 EXPORT_C TInt RProcess::GetMemoryInfo(TModuleMemoryInfo& aInfo) const
       
  4071 /**
       
  4072 Gets the size and base address of the code and various data
       
  4073 sections of the process.
       
  4074 
       
  4075 The run addresses are also returned.
       
  4076 
       
  4077 @param aInfo On successful return, contains the base address and size of the 
       
  4078              sections.
       
  4079              
       
  4080 @return KErrNone, if successful; otherwise one of the other system wide error 
       
  4081         codes.
       
  4082 */
       
  4083 	{
       
  4084 
       
  4085 	return Exec::ProcessGetMemoryInfo(iHandle,aInfo);
       
  4086 	}
       
  4087 	
       
  4088 
       
  4089 EXPORT_C TAny* RProcess::ExeExportData(void)
       
  4090 /**
       
  4091 Retrieves pointer to named symbol export data from the current process, i.e. the
       
  4092 process calling this function.
       
  4093              
       
  4094 @return Pointer to export data when it is present, NULL if export data not found
       
  4095 @internalTechnology
       
  4096 @released
       
  4097 */
       
  4098 	{
       
  4099 
       
  4100 	return Exec::ProcessExeExportData();
       
  4101 	}
       
  4102 
       
  4103 
       
  4104 
       
  4105 EXPORT_C TInt TFindSemaphore::Next(TFullName &aResult)
       
  4106 /**
       
  4107 Finds the next global semaphore whose full name matches the match pattern.
       
  4108 
       
  4109 If a global semaphore with a matching name is found, the function copies its 
       
  4110 full name into the descriptor aResult. It also saves the find-handle associated 
       
  4111 with the global semaphore into the TFindHandleBase part of this TFindSemaphore 
       
  4112 object.
       
  4113 
       
  4114 @param aResult A reference to a TBuf descriptor with a defined maximum length. 
       
  4115                If a matching global semaphore is found, its full name is set
       
  4116                into this descriptor. 
       
  4117                If no matching global semaphore is found, the descriptor length
       
  4118                is set to zero. 
       
  4119                
       
  4120 @return KErrNone if a matching global semaphore is found;
       
  4121         KErrNotFound otherwise.
       
  4122 */
       
  4123 	{
       
  4124 	return NextObject(aResult,ESemaphore);
       
  4125 	}
       
  4126 
       
  4127 
       
  4128 
       
  4129 
       
  4130 EXPORT_C void RSemaphore::Wait()
       
  4131 /**
       
  4132 Waits for a signal on the semaphore.
       
  4133 
       
  4134 The function decrements the semaphore count by one and returns immediately 
       
  4135 if it is zero or positive.
       
  4136 
       
  4137 If the semaphore count is negative after being decremented, the calling thread is 
       
  4138 added to a queue of threads maintained by this semaphore.
       
  4139 
       
  4140 The thread waits until the semaphore is signalled. More than one thread can 
       
  4141 be waiting on a particular semaphore at a time. When there are multiple threads 
       
  4142 waiting on a semaphore, they are released in priority order.
       
  4143 
       
  4144 If the semaphore is deleted, all threads waiting on that semaphore are released.
       
  4145 */
       
  4146 	{
       
  4147 
       
  4148 	Exec::SemaphoreWait(iHandle, 0);
       
  4149 	}
       
  4150 
       
  4151 
       
  4152 
       
  4153 
       
  4154 EXPORT_C TInt RSemaphore::Wait(TInt aTimeout)
       
  4155 /**
       
  4156 Waits for a signal on the semaphore, or a timeout.
       
  4157 
       
  4158 @param aTimeout The timeout value in micoseconds
       
  4159 
       
  4160 @return KErrNone if the wait has completed normally;
       
  4161         KErrGeneral if the semaphore is being reset, i.e the semaphore
       
  4162         is about to  be deleted.
       
  4163         KErrArgument if aTimeout is negative;
       
  4164         otherwise one of the other system wide error codes indicating that
       
  4165         the timeout has expired.
       
  4166 */
       
  4167 	{
       
  4168 
       
  4169 	return Exec::SemaphoreWait(iHandle, aTimeout);
       
  4170 	}
       
  4171 
       
  4172 
       
  4173 
       
  4174 
       
  4175 EXPORT_C void RSemaphore::Signal()
       
  4176 /**
       
  4177 Signals the semaphore once.
       
  4178 
       
  4179 The function increments the semaphore count by one. If the count was negative 
       
  4180 before being incremented, the highest priority thread waiting on the semaphore's queue 
       
  4181 of threads is removed from that queue and, provided that it is not suspended 
       
  4182 for any other reason, is marked as ready to run.
       
  4183 */
       
  4184 	{
       
  4185 
       
  4186 	Exec::SemaphoreSignal1(iHandle);
       
  4187 	}
       
  4188 
       
  4189 
       
  4190 
       
  4191 
       
  4192 EXPORT_C void RSemaphore::Signal(TInt aCount)
       
  4193 /**
       
  4194 Signals the semaphore one or more times.
       
  4195 
       
  4196 The function increments the semaphore count. If the count was negative 
       
  4197 before being incremented, the highest priority thread waiting on the semaphore's queue 
       
  4198 of threads is removed from that queue and, provided that it is not suspended 
       
  4199 for any other reason, is marked as ready to run.
       
  4200 
       
  4201 @param aCount The number of times the semaphore is to be signalled.
       
  4202 */
       
  4203 	{
       
  4204 
       
  4205 	__ASSERT_ALWAYS(aCount>=0,Panic(ESemSignalCountNegative));
       
  4206 	Exec::SemaphoreSignalN(iHandle,aCount);
       
  4207 	}
       
  4208 
       
  4209 
       
  4210 
       
  4211 
       
  4212 EXPORT_C RCriticalSection::RCriticalSection()
       
  4213 	: iBlocked(1)
       
  4214 /**
       
  4215 Default constructor.
       
  4216 */
       
  4217 	{}
       
  4218 
       
  4219 
       
  4220 
       
  4221 
       
  4222 EXPORT_C void RCriticalSection::Close()
       
  4223 /**
       
  4224 Closes the handle to the critical section.
       
  4225 
       
  4226 As a critical section object is implemented using a semaphore, this has the 
       
  4227 effect of closing the handle to the semaphore.
       
  4228 */
       
  4229 	{
       
  4230 
       
  4231 	RSemaphore::Close();
       
  4232 	}
       
  4233 
       
  4234 
       
  4235 
       
  4236 
       
  4237 EXPORT_C void RCriticalSection::Wait()
       
  4238 /**
       
  4239 Waits for the critical section to become free.
       
  4240 
       
  4241 If no other thread is in the critical section, control returns immediately 
       
  4242 and the current thread can continue into the section.
       
  4243 
       
  4244 If another thread is already in the critical section, the current thread is 
       
  4245 marked as waiting (on a semaphore); the current thread is added to a queue
       
  4246 of threads maintained by this critical section.
       
  4247 */
       
  4248 	{
       
  4249 
       
  4250 	if (User::LockedDec(iBlocked)!=1)
       
  4251 		RSemaphore::Wait();
       
  4252 	}
       
  4253 
       
  4254 
       
  4255 
       
  4256 
       
  4257 EXPORT_C void RCriticalSection::Signal()
       
  4258 /**
       
  4259 Signals an exit from the critical section.
       
  4260 
       
  4261 A thread calls this function when it exits from the critical section.
       
  4262 The first eligible thread waiting on the critical section's queue of threads
       
  4263 is removed from that queue and, provided that it is not suspended for any other
       
  4264 reason, is marked as ready to run. That thread will, therefore, be the next to
       
  4265 proceed into the critical section.
       
  4266 */
       
  4267 	{
       
  4268 
       
  4269 	__ASSERT_ALWAYS(iBlocked<1,Panic(ECriticalSectionStraySignal));
       
  4270 	if (User::LockedInc(iBlocked)<0)
       
  4271 		RSemaphore::Signal();
       
  4272 	}
       
  4273 
       
  4274 
       
  4275 
       
  4276 
       
  4277 EXPORT_C TInt TFindThread::Next(TFullName &aResult)
       
  4278 /**
       
  4279 Gets the full name of the next global thread which matches the match pattern.
       
  4280 
       
  4281 @param aResult A reference to a TBuf descriptor with a defined maximum length.
       
  4282                If a matching global thread is found, its full name is set into
       
  4283                this descriptor. If no matching global thread is found,
       
  4284                the descriptor length is set to zero.
       
  4285 
       
  4286 @return KErrNone if successful, otherwise one of the other system-wide error
       
  4287                  codes.
       
  4288 */
       
  4289 	{
       
  4290 	return NextObject(aResult,EThread);
       
  4291 	}
       
  4292 
       
  4293 
       
  4294 
       
  4295 
       
  4296 EXPORT_C TThreadId RThread::Id() const
       
  4297 /**
       
  4298 Gets the Id of this thread.
       
  4299 
       
  4300 @return The Id of this thread.
       
  4301 */
       
  4302 	{
       
  4303 
       
  4304 	return TThreadId( (TUint)Exec::ThreadId(iHandle) );
       
  4305 	}
       
  4306 #endif
       
  4307 
       
  4308 
       
  4309 
       
  4310 EXPORT_C void RThread::HandleCount(TInt& aProcessHandleCount, TInt& aThreadHandleCount) const
       
  4311 /**
       
  4312 Gets the number of handles open in this thread, and the number of handles open 
       
  4313 in the process which owns this thread.
       
  4314 
       
  4315 @param aProcessHandleCount On return, contains the number of handles open in
       
  4316                            the process which owns this thread.
       
  4317 @param aThreadHandleCount  On return, contains the number of handles open in
       
  4318                            this thread.
       
  4319 */
       
  4320 	{
       
  4321 #ifndef __TOOLS2__
       
  4322 	Exec::HandleCount(iHandle,aProcessHandleCount,aThreadHandleCount);
       
  4323 #else
       
  4324 	aProcessHandleCount = aThreadHandleCount = 0;
       
  4325 #endif // __TOOLS2__
       
  4326 	}
       
  4327 
       
  4328 
       
  4329 
       
  4330 #ifndef __TOOLS2__
       
  4331 EXPORT_C TExceptionHandler User::ExceptionHandler()
       
  4332 /**
       
  4333 Gets a pointer to the exception handler for the current thread.
       
  4334 
       
  4335 @return A pointer to the exception handler.
       
  4336 */
       
  4337 	{
       
  4338 	return(Exec::ExceptionHandler(KCurrentThreadHandle));
       
  4339 	}
       
  4340 
       
  4341 
       
  4342 
       
  4343 
       
  4344 EXPORT_C TInt User::SetExceptionHandler(TExceptionHandler aHandler,TUint32 aMask)
       
  4345 /**
       
  4346 Sets a new exception handler for the current thread. Note that the handler is not
       
  4347 guaranteed to receive floating point exceptions (KExceptionFpe) when a hardware
       
  4348 floating point implementation is in use - see User::SetFloatingPointMode for
       
  4349 hardware floating point modes and whether they cause user-trappable exceptions.
       
  4350 
       
  4351 @param aHandler The new exception handler.
       
  4352 @param aMask    One or more flags defining the exception categories which
       
  4353                 the handler can handle.
       
  4354 
       
  4355 @return KErrNone if successful, otherwise another of the system-wide error codes.
       
  4356 
       
  4357 @see KExceptionAbort
       
  4358 @see KExceptionKill
       
  4359 @see KExceptionUserInterrupt
       
  4360 @see KExceptionFpe
       
  4361 @see KExceptionFault
       
  4362 @see KExceptionInteger
       
  4363 @see KExceptionDebug
       
  4364 */
       
  4365 	{
       
  4366 	return(Exec::SetExceptionHandler(KCurrentThreadHandle, aHandler, aMask));
       
  4367 	}
       
  4368 
       
  4369 
       
  4370 
       
  4371 
       
  4372 EXPORT_C void User::ModifyExceptionMask(TUint32 aClearMask, TUint32 aSetMask)
       
  4373 /**
       
  4374 Changes the set of exceptions which the current thread's exception
       
  4375 handler can deal with.
       
  4376 
       
  4377 aClearMask is the set of flags defining the set of exceptions which the
       
  4378 exception handler no longer deals with, while aSetMask is the set of flags
       
  4379 defining the new set of exceptions to be set.
       
  4380 
       
  4381 Flag clearing is done before flag setting.
       
  4382 
       
  4383 @param  aClearMask One or more flags defining the exceptions which the current
       
  4384                    exception handler no longer deals with.
       
  4385 @param  aSetMask   One or more flags defining the new set of exceptions which
       
  4386                    the current exception handler is to deal with.
       
  4387 */
       
  4388 	{
       
  4389 	Exec::ModifyExceptionMask(KCurrentThreadHandle, aClearMask, aSetMask);
       
  4390 	}
       
  4391 
       
  4392 
       
  4393 
       
  4394 
       
  4395 _LIT(KLitUserExec, "USER-EXEC");
       
  4396 EXPORT_C TInt User::RaiseException(TExcType aType)
       
  4397 /**
       
  4398 Raises an exception of a specified type on the current thread.
       
  4399 
       
  4400 If the thread has an exception handler to handle this type of exception,
       
  4401 then it is called.
       
  4402 
       
  4403 If the thread has no exception handler to handle this type of exception, then
       
  4404 the function raises a USER-EXEC 3 panic.
       
  4405 
       
  4406 Note that exception handlers are executed in the context of the thread on which
       
  4407 the exception is raised; control returns to the point of the exception. 
       
  4408 
       
  4409 @param aType The type of exception.
       
  4410 
       
  4411 @return KErrNone if successful, otherwise another of the system-wide
       
  4412         error codes.
       
  4413 */
       
  4414 	{
       
  4415 	if (Exec::IsExceptionHandled(KCurrentThreadHandle,aType,ETrue))
       
  4416 		{
       
  4417 		Exec::ThreadSetFlags(KCurrentThreadHandle, 0, KThreadFlagLastChance);
       
  4418 		TUint32 type = aType;
       
  4419 		User::HandleException(&type);
       
  4420 		}
       
  4421 	else
       
  4422 		User::Panic(KLitUserExec, ECausedException);
       
  4423 	return KErrNone;
       
  4424 	}
       
  4425 
       
  4426 
       
  4427 
       
  4428 
       
  4429 EXPORT_C TBool User::IsExceptionHandled(TExcType aType)
       
  4430 /**
       
  4431 Tests whether the specified exception type can be handled by the
       
  4432 current thread.
       
  4433 
       
  4434 @param aType The type of exception.
       
  4435 
       
  4436 @return True, if the thread has an exception handler which can handle
       
  4437         an exception of type aType.
       
  4438         False, if the thread has no exception handler or the thread has
       
  4439         an exception handler which cannot handle the exception defined
       
  4440         by aType.
       
  4441 */
       
  4442 	{
       
  4443 	return (Exec::IsExceptionHandled(KCurrentThreadHandle,aType,EFalse));
       
  4444 	}
       
  4445 
       
  4446 
       
  4447 
       
  4448 
       
  4449 EXPORT_C void RThread::Context(TDes8 &aDes) const
       
  4450 /**
       
  4451 Gets the register contents of this thread.
       
  4452 
       
  4453 @param aDes On return, contains the register contents, starting with R0.
       
  4454 */
       
  4455 	{
       
  4456 
       
  4457 	Exec::ThreadContext(iHandle,aDes);
       
  4458 	}
       
  4459 
       
  4460 
       
  4461 
       
  4462 
       
  4463 EXPORT_C void RThread::Resume() const
       
  4464 /**
       
  4465 Makes the thread eligible for execution.
       
  4466 
       
  4467 After a thread is created, it is put into a suspended state; the thread is 
       
  4468 not eligible to run until Resume() is called.
       
  4469 
       
  4470 This function must also be called to resume execution of this thread after 
       
  4471 it has been explicitly suspended by a call to Suspend().
       
  4472 
       
  4473 Note that when a thread is created, it is given the priority EPriorityNormal 
       
  4474 by default. The fact that a thread is initially put into a suspended state 
       
  4475 means that the thread priority can be changed by calling the thread's
       
  4476 SetPriority() member function before the thread is started by a call to Resume().
       
  4477 */
       
  4478 	{
       
  4479 
       
  4480 	Exec::ThreadResume(iHandle);
       
  4481 	}
       
  4482 
       
  4483 
       
  4484 
       
  4485 
       
  4486 EXPORT_C void RThread::Suspend() const
       
  4487 /**
       
  4488 Suspends execution of this thread.
       
  4489 
       
  4490 The thread is not scheduled to run until a subsequent call to Resume() is made.
       
  4491 */
       
  4492 	{
       
  4493 
       
  4494 	Exec::ThreadSuspend(iHandle);
       
  4495 	}
       
  4496 
       
  4497 
       
  4498 
       
  4499 
       
  4500 EXPORT_C TThreadPriority RThread::Priority() const
       
  4501 /**
       
  4502 Gets the priority of this thread.
       
  4503 
       
  4504 @return The priority.
       
  4505 */
       
  4506 	{
       
  4507 
       
  4508 	return(Exec::ThreadPriority(iHandle));
       
  4509 	}
       
  4510 
       
  4511 
       
  4512 
       
  4513 
       
  4514 EXPORT_C void RThread::SetProcessPriority(TProcessPriority aPriority) const
       
  4515 /**
       
  4516 Sets the priority of the process which owns this thread to one of the values 
       
  4517 defined by the TProcessPriority enumeration.
       
  4518 
       
  4519 The priority can be set to one of the four values:
       
  4520 
       
  4521 EPriorityLow
       
  4522 
       
  4523 EPriorityBackground
       
  4524 
       
  4525 EPriorityForeground
       
  4526 
       
  4527 EPriorityHigh
       
  4528 
       
  4529 The absolute priority of all threads owned by the process (and all threads 
       
  4530 owned by those threads etc.) are re-calculated.
       
  4531 
       
  4532 Note:
       
  4533 
       
  4534 The use of the priority values EPriorityWindowServer, EPriorityFileServer, 
       
  4535 EPriorityRealTimeServer and EPrioritySupervisor is restricted to Symbian OS, 
       
  4536 and any attempt to explicitly set any of these priority values raises a KERN-EXEC 
       
  4537 14 panic.
       
  4538 
       
  4539 @param aPriority The priority value.
       
  4540 
       
  4541 @deprecated Not allowed on threads in a different process.
       
  4542 			Replace with RProcess::SetPriority or RMessagePtr2::SetProcessPriority
       
  4543 */
       
  4544 	{
       
  4545 
       
  4546 	Exec::ThreadSetProcessPriority(iHandle,aPriority);
       
  4547 	}
       
  4548 
       
  4549 
       
  4550 
       
  4551 
       
  4552 EXPORT_C TProcessPriority RThread::ProcessPriority() const
       
  4553 /**
       
  4554 Gets the priority of the process which owns this thread.
       
  4555 
       
  4556 @return The process priority.
       
  4557 */
       
  4558 	{
       
  4559 
       
  4560 	return(Exec::ThreadProcessPriority(iHandle));
       
  4561 	}
       
  4562 
       
  4563 
       
  4564 
       
  4565 
       
  4566 EXPORT_C void RThread::SetPriority(TThreadPriority aPriority) const
       
  4567 /**
       
  4568 Sets the priority of the thread to one of the values defined by
       
  4569 the TThreadPriority enumeration. 
       
  4570 
       
  4571 The resulting absolute priority of the thread depends on the value of aPriority 
       
  4572 and the priority of the owning process.
       
  4573 
       
  4574 Use of the priority value EPriorityNull is restricted to Symbian OS, and any 
       
  4575 attempt to explicitly set this value causes a KERN-EXEC 14 panic to be raised.
       
  4576 
       
  4577 @param aPriority The priority value.
       
  4578 
       
  4579 @capability ProtServ if aPriority is EPriorityAbsoluteRealTime1 or higher
       
  4580 
       
  4581 @panic KERN-EXEC 14, if aPriority is invalid or set to EPriorityNull
       
  4582 @panic KERN-EXEC 46, if aPriority is EPriorityAbsoluteRealTime1 or higher
       
  4583                      and calling process does not have ProtServ capability
       
  4584 */
       
  4585 	{
       
  4586 
       
  4587 	Exec::ThreadSetPriority(iHandle,aPriority);
       
  4588 	}
       
  4589 
       
  4590 
       
  4591 
       
  4592 
       
  4593 EXPORT_C User::TCritical User::Critical(RThread aThread)
       
  4594 /**
       
  4595 Gets the critical state associated with the specified thread.
       
  4596 
       
  4597 @param aThread The thread whose critical state is to be retrieved.
       
  4598 
       
  4599 @return The critical state.
       
  4600 
       
  4601 @see User::SetCritical()
       
  4602 */
       
  4603 	{
       
  4604 	TUint32 flags = Exec::ThreadFlags(aThread.Handle());
       
  4605 	if (flags & KThreadFlagSystemPermanent)
       
  4606 		return ESystemPermanent;
       
  4607 	if (flags & KThreadFlagSystemCritical)
       
  4608 		return ESystemCritical;
       
  4609 	if (flags & KThreadFlagProcessPermanent)
       
  4610 		return EProcessPermanent;
       
  4611 	if (flags & KThreadFlagProcessCritical)
       
  4612 		return EProcessCritical;
       
  4613 	return ENotCritical;
       
  4614 	}
       
  4615 
       
  4616 
       
  4617 
       
  4618 
       
  4619 EXPORT_C User::TCritical User::Critical()
       
  4620 /**
       
  4621 Gets the critical state associated with the current thread.
       
  4622 
       
  4623 @return The critical state.
       
  4624 	
       
  4625 @see User::SetCritical()
       
  4626 */
       
  4627 	{
       
  4628 	RThread me;
       
  4629 	return User::Critical(me);
       
  4630 	}
       
  4631 
       
  4632 
       
  4633 
       
  4634 
       
  4635 /**
       
  4636 Sets up or changes the effect that termination of the current
       
  4637 thread has, either on its owning process, or on the whole system.
       
  4638 
       
  4639 The precise effect of thread termination is defined by 
       
  4640 the following specific values of the TCritical enum:
       
  4641 - ENotCritical
       
  4642 - EProcessCritical
       
  4643 - EProcessPermanent
       
  4644 - ESystemCritical
       
  4645 - ESystemPermanent
       
  4646 
       
  4647 Notes:
       
  4648 -# The enum value EAllThreadsCritical cannot be set using this function. It is
       
  4649 associated with a process, not a thread, and, if appropriate, should be set
       
  4650 using User::SetProcessCritical().
       
  4651 -# The states associated with ENotCritical, EProcessCritical,
       
  4652 EProcessPermanent, ESystemCritical and ESystemPermanent
       
  4653 are all mutually exclusive, i.e. the thread can only be in one of these states
       
  4654 at any one time
       
  4655 
       
  4656 @param aCritical The state to be set. 
       
  4657 
       
  4658 @return KErrNone, if successful;
       
  4659         KErrArgument, if EAllThreadsCritical is passed - this is a 
       
  4660         state associated with a process, and
       
  4661         you use User::SetProcessCritical() to set it.
       
  4662 
       
  4663 @capability ProtServ if aCritical==ESystemCritical or ESystemPermanent
       
  4664 
       
  4665 @see User::Critical()
       
  4666 @see User::ProcessCritical()
       
  4667 @see User::SetProcessCritical()
       
  4668 */
       
  4669 EXPORT_C TInt User::SetCritical(TCritical aCritical)
       
  4670 	{
       
  4671 	const TUint32 clear =	KThreadFlagSystemPermanent | KThreadFlagSystemCritical |
       
  4672 							KThreadFlagProcessPermanent | KThreadFlagProcessCritical;
       
  4673 	TUint32 set;
       
  4674 	switch (aCritical)
       
  4675 		{
       
  4676 		case ENotCritical:		set = 0;							break;
       
  4677 		case EProcessCritical:	set = KThreadFlagProcessCritical;	break;
       
  4678 		case EProcessPermanent:	set = KThreadFlagProcessPermanent;	break;
       
  4679 		case ESystemCritical:	set = KThreadFlagSystemCritical;	break;
       
  4680 		case ESystemPermanent:	set = KThreadFlagSystemPermanent;	break;
       
  4681 		default:													return KErrArgument;
       
  4682 		}
       
  4683 	Exec::ThreadSetFlags(KCurrentThreadHandle, clear, set);
       
  4684 	return KErrNone;
       
  4685 	}
       
  4686 
       
  4687 
       
  4688 
       
  4689 
       
  4690 EXPORT_C TInt User::SetRealtimeState(TRealtimeState aState)
       
  4691 	{
       
  4692 	const TUint32 clear =	KThreadFlagRealtime | KThreadFlagRealtimeTest;
       
  4693 	TUint32 set;
       
  4694 	switch (aState)
       
  4695 		{
       
  4696 		case ERealtimeStateOff:		set = 0;											break;
       
  4697 		case ERealtimeStateOn:		set = KThreadFlagRealtime;							break;
       
  4698 		case ERealtimeStateWarn:	set = KThreadFlagRealtime|KThreadFlagRealtimeTest;	break;
       
  4699 		default:																		return KErrArgument;
       
  4700 		}
       
  4701 	Exec::ThreadSetFlags(KCurrentThreadHandle, clear, set);
       
  4702 	return KErrNone;
       
  4703 	}
       
  4704 
       
  4705 
       
  4706 
       
  4707 
       
  4708 EXPORT_C User::TCritical User::ProcessCritical(RProcess aProcess)
       
  4709 /**
       
  4710 Gets the critical state associated with the specified process.
       
  4711 
       
  4712 @param aProcess The process whose critical state is to be retrieved.
       
  4713 
       
  4714 @return The critical state.
       
  4715 
       
  4716 @see User::SetProcessCritical()
       
  4717 */
       
  4718 	{
       
  4719 	TUint32 flags = Exec::ProcessFlags(aProcess.Handle());
       
  4720 	if (flags & KProcessFlagSystemPermanent)
       
  4721 		return ESystemPermanent;
       
  4722 	if (flags & KProcessFlagSystemCritical)
       
  4723 		return ESystemCritical;
       
  4724 	if (flags & (KThreadFlagProcessPermanent | KThreadFlagProcessCritical))
       
  4725 		return EAllThreadsCritical;
       
  4726 	return ENotCritical;
       
  4727 	}
       
  4728 
       
  4729 
       
  4730 
       
  4731 
       
  4732 EXPORT_C User::TCritical User::ProcessCritical()
       
  4733 /**
       
  4734 Gets the critical state associated with the current process.
       
  4735 
       
  4736 @return The critical state.
       
  4737 	
       
  4738 @see User::SetProcessCritical()
       
  4739 */
       
  4740 	{
       
  4741 	RProcess me;
       
  4742 	return User::ProcessCritical(me);
       
  4743 	}
       
  4744 
       
  4745 
       
  4746 
       
  4747 
       
  4748 EXPORT_C TInt User::SetProcessCritical(TCritical aCritical)
       
  4749 /**
       
  4750 Sets up or changes the effect that termination of subsequently created threads
       
  4751 will have, either on the owning process, or on the whole system.
       
  4752 
       
  4753 It is important to note that we are not referring to threads that have already
       
  4754 been created, but threads that will be created subsequent to a call to this function.
       
  4755 
       
  4756 The precise effect of thread termination is defined by the following specific
       
  4757 values of the TCritical enum: 
       
  4758 - ENotCritical
       
  4759 - EAllThreadsCritical
       
  4760 - ESystemCritical
       
  4761 - ESystemPermanent
       
  4762 
       
  4763 Notes:
       
  4764 -# The enum values EProcessCritical and EProcessPermanent cannot be set using
       
  4765 this function. They are states associated with
       
  4766 a thread, not a process, and, if appropriate, should be set
       
  4767 using User::SetCritical().
       
  4768 -# The states associated with ENotCritical, EAllThreadsCritical,
       
  4769 ESystemCritical and ESystemPermanent are all mutually exclusive, i.e. the
       
  4770 process can only be in one of these states at any one time.
       
  4771 
       
  4772 @param aCritical The state to be set. 
       
  4773 
       
  4774 @return KErrNone, if successful;
       
  4775         KErrArgument, if either EProcessCritical or EProcessPermanent
       
  4776         is passed - these are states associated with a thread, and
       
  4777         you use User::SetCritical() to set them.
       
  4778 
       
  4779 @capability ProtServ if aCritical==ESystemCritical or ESystemPermanent
       
  4780 
       
  4781 @see User::ProcessCritical()
       
  4782 @see User::SetCritical()
       
  4783 @see User::Critical()
       
  4784 */
       
  4785 	{
       
  4786 	const TUint32 clear =	KProcessFlagSystemPermanent | KProcessFlagSystemCritical |
       
  4787 							KThreadFlagProcessPermanent | KThreadFlagProcessCritical;
       
  4788 	TUint32 set;
       
  4789 	switch (aCritical)
       
  4790 		{
       
  4791 		case ENotCritical:			set = 0;							break;
       
  4792 		case EAllThreadsCritical:	set = KThreadFlagProcessCritical;	break;
       
  4793 		case ESystemCritical:		set = KProcessFlagSystemCritical;	break;
       
  4794 		case ESystemPermanent:		set = KProcessFlagSystemPermanent|KProcessFlagSystemCritical;	break;
       
  4795 		default:														return KErrArgument;
       
  4796 		}
       
  4797 	Exec::ProcessSetFlags(KCurrentProcessHandle, clear, set);
       
  4798 	return KErrNone;
       
  4799 	}
       
  4800 
       
  4801 
       
  4802 
       
  4803 
       
  4804 EXPORT_C TBool User::PriorityControl()
       
  4805 /**
       
  4806 Tests whether the current process allows other processes to switch its priority 
       
  4807 between 'foreground' and 'background'.
       
  4808 
       
  4809 @return True, if the current process allows other processes to switch its priority;
       
  4810         false, otherwise.
       
  4811 */
       
  4812 	{
       
  4813 	return Exec::ProcessFlags(KCurrentProcessHandle) & KProcessFlagPriorityControl;
       
  4814 	}
       
  4815 
       
  4816 
       
  4817 
       
  4818 
       
  4819 EXPORT_C void User::SetPriorityControl(TBool aEnable)
       
  4820 /**
       
  4821 Allows the current process to choose to have its priority switched by another
       
  4822 process between 'foreground' and 'background'.
       
  4823 
       
  4824 By default a process does not allow this.
       
  4825 
       
  4826 @param aEnable If ETrue, allows other processes to switch the current process's
       
  4827                priority.
       
  4828                If EFalse, prevents other processes from switching the current
       
  4829                process's priority.
       
  4830 */
       
  4831 	{
       
  4832 	TUint32 set = aEnable ? KProcessFlagPriorityControl : 0;
       
  4833 	Exec::ProcessSetFlags(KCurrentProcessHandle, KProcessFlagPriorityControl, set);
       
  4834 	}
       
  4835 
       
  4836 
       
  4837 
       
  4838 EXPORT_C TInt RThread::RequestCount() const
       
  4839 /**
       
  4840 Gets this thread's request semaphore count.
       
  4841 
       
  4842 The request semaphore is created when a thread is created, and is used to 
       
  4843 support asynchronous requests.
       
  4844 
       
  4845 A negative value implies that this thread is waiting for at least
       
  4846 one asynchronous request to complete.
       
  4847 
       
  4848 @return This thread's request semaphore count.
       
  4849 */
       
  4850 	{
       
  4851 
       
  4852 	return(Exec::ThreadRequestCount(iHandle));
       
  4853 	}
       
  4854 
       
  4855 
       
  4856 
       
  4857 
       
  4858 EXPORT_C TExitType RThread::ExitType() const
       
  4859 /**
       
  4860 Tests whether the thread has ended and, if it has ended, return how it ended.
       
  4861 
       
  4862 This information allows the caller to distinguish between normal termination 
       
  4863 and a panic.
       
  4864 
       
  4865 @return An enumeration whose enumerators describe how the thread has ended.
       
  4866 */
       
  4867 	{
       
  4868 
       
  4869 	return(Exec::ThreadExitType(iHandle));
       
  4870 	}
       
  4871 
       
  4872 
       
  4873 
       
  4874 
       
  4875 EXPORT_C TInt RThread::ExitReason() const
       
  4876 /**
       
  4877 Gets the specific reason associated with the end of this thread.
       
  4878 
       
  4879 The reason number together with the category name is a way of distinguishing 
       
  4880 between different causes of thread termination.
       
  4881 
       
  4882 If the thread has panicked, this value is the panic number. If the thread 
       
  4883 has ended as a result of a call to Kill(), then the value is the one supplied 
       
  4884 by Kill().
       
  4885 
       
  4886 If the thread is still alive, then the returned value is zero.
       
  4887 
       
  4888 @return The reason associated with the end of the thread.
       
  4889 */
       
  4890 	{
       
  4891 
       
  4892 	return(Exec::ThreadExitReason(iHandle));
       
  4893 	}
       
  4894 
       
  4895 
       
  4896 
       
  4897 
       
  4898 EXPORT_C TExitCategoryName RThread::ExitCategory() const
       
  4899 /**
       
  4900 Gets the name of the category associated with the end of the thread.
       
  4901 
       
  4902 The category name together with the reason number is a way of distinguishing
       
  4903 between different causes of thread termination.
       
  4904 
       
  4905 If the thread has panicked, the category name is the panic category name; 
       
  4906 for example, E32USER-CBase or KERN-EXEC. If the thread has ended as a result 
       
  4907 of call to Kill(), then the category name is Kill.
       
  4908 
       
  4909 If the thread has not ended, then the category name is empty, i.e. the length 
       
  4910 of the category name is zero.
       
  4911 
       
  4912 @return A TBuf descriptor with a defined maximum length containing the name 
       
  4913         of the category associated with the end of the thread.
       
  4914 
       
  4915 @see TBuf
       
  4916 */
       
  4917 	{
       
  4918 	TExitCategoryName n;
       
  4919 	TPtr8 n8(((TUint8*)n.Ptr()) + KMaxExitCategoryName, KMaxExitCategoryName);
       
  4920 	Exec::ThreadExitCategory(iHandle,n8);
       
  4921 	n.Copy(n8);
       
  4922 	return(n);
       
  4923 	}
       
  4924 
       
  4925 
       
  4926 
       
  4927 
       
  4928 EXPORT_C TInt RThread::StackInfo(TThreadStackInfo& aInfo) const
       
  4929 /**
       
  4930 Gets information about a thread's user mode stack.
       
  4931 
       
  4932 @param aInfo The TThreadStackInfo object to write the stack infomation to.
       
  4933 
       
  4934 @return KErrNone, if sucessful;
       
  4935 		KErrGeneral, if the thread doesn't have a user mode stack,
       
  4936 		or it has terminated.
       
  4937 
       
  4938 @see TThreadStackInfo
       
  4939 */
       
  4940 	{
       
  4941 	return(Exec::ThreadStackInfo(iHandle,aInfo));
       
  4942 	}
       
  4943 
       
  4944 
       
  4945 
       
  4946 
       
  4947 EXPORT_C TInt RThread::GetCpuTime(TTimeIntervalMicroSeconds& aCpuTime) const
       
  4948 /**
       
  4949 Gets the CPU usage for this thread.
       
  4950 
       
  4951 This function is not supported on version 8.0b or 8.1b, and returns
       
  4952 KErrNotSupported.  From 9.1 onwards it may be supported if the kernel has been
       
  4953 compiled with the MONITOR_THREAD_CPU_TIME macro defined.
       
  4954 
       
  4955 @param aCpuTime A reference to a time interval object supplied by the caller. 
       
  4956                                 
       
  4957 @return KErrNone - if thread CPU time is available.
       
  4958 
       
  4959         KErrNotSupported - if this feature is not supported on this
       
  4960         version or build of the OS.
       
  4961 */
       
  4962 	{
       
  4963 	return Exec::ThreadGetCpuTime(iHandle, (TInt64&)aCpuTime.Int64());
       
  4964 	}
       
  4965 #endif // __TOOLS2__
       
  4966 
       
  4967 
       
  4968 
       
  4969 EXPORT_C void User::After(TTimeIntervalMicroSeconds32 aInterval)
       
  4970 /**
       
  4971 Suspends the current thread until a specified time interval has expired.
       
  4972 
       
  4973 The resolution of the timer depends on the hardware, but is normally 
       
  4974 1 Symbian OS tick (approximately 1/64 second).
       
  4975 
       
  4976 @param aInterval The time interval for which the current thread is to be 
       
  4977                   suspended, in microseconds.
       
  4978                   
       
  4979 @panic USER 86, if the time interval is negative.
       
  4980 */
       
  4981 	{
       
  4982 
       
  4983 	__ASSERT_ALWAYS(aInterval.Int()>=0,::Panic(EExecAfterTimeNegative));
       
  4984 	TRequestStatus s=KRequestPending;
       
  4985 	Exec::After(aInterval.Int(),s);
       
  4986 	User::WaitForRequest(s);
       
  4987 	}
       
  4988 
       
  4989 
       
  4990 
       
  4991 
       
  4992 EXPORT_C void User::AfterHighRes(TTimeIntervalMicroSeconds32 aInterval)
       
  4993 /**
       
  4994 Suspends the current thread until a specified time interval has expired to
       
  4995 a resolution of 1ms .
       
  4996 
       
  4997 @param aInterval The time interval for which the current thread is to be 
       
  4998                   suspended, in microseconds.
       
  4999                   
       
  5000 @panic USER 86, if the time interval is negative.
       
  5001 */
       
  5002 	{
       
  5003 
       
  5004 	__ASSERT_ALWAYS(aInterval.Int()>=0,::Panic(EExecAfterTimeNegative));
       
  5005 	TRequestStatus s=KRequestPending;
       
  5006 	Exec::AfterHighRes(aInterval.Int(),s);
       
  5007 	User::WaitForRequest(s);
       
  5008 	}
       
  5009 
       
  5010 
       
  5011 
       
  5012 #ifndef __TOOLS2__
       
  5013 EXPORT_C TInt User::At(const TTime &aTime)
       
  5014 /**
       
  5015 Suspends the current thread until the specified absolute time, in the current time zone.
       
  5016 
       
  5017 If the machine is off at that time, the machine will be turned on again.
       
  5018 
       
  5019 @param aTime The absolute time, in the current time zone, until which the current thread is to
       
  5020              be suspended.
       
  5021 
       
  5022 @return On completion, contains the status of the request to suspend the
       
  5023         current thread:
       
  5024 
       
  5025         KErrNone - suspension of the current thread completed normally at 
       
  5026         the requested time.
       
  5027 
       
  5028         KErrAbort - suspension of the current thread was aborted 
       
  5029         because the system time changed.
       
  5030 
       
  5031         KErrUnderflow - the requested completion time is in the past.
       
  5032 
       
  5033         KErrOverFlow - the requested completion time is too far in the future.
       
  5034 */
       
  5035 	{
       
  5036 
       
  5037 	TRequestStatus s=KRequestPending;
       
  5038 	TInt64 time=aTime.Int64();
       
  5039 	time -= ((TInt64)User::UTCOffset().Int()) * 1000000;
       
  5040 	Exec::At(time,s);
       
  5041 	User::WaitForRequest(s);
       
  5042 	return(s.Int());
       
  5043 	}
       
  5044 
       
  5045 
       
  5046 
       
  5047 
       
  5048 EXPORT_C void RTimer::Cancel()
       
  5049 /**
       
  5050 Cancels any outstanding request for a timer event.
       
  5051 
       
  5052 Any outstanding timer event completes with KErrCancel.
       
  5053 */
       
  5054 	{
       
  5055 
       
  5056 	Exec::TimerCancel(iHandle);
       
  5057 	}
       
  5058 
       
  5059 
       
  5060 
       
  5061 
       
  5062 EXPORT_C void RTimer::After(TRequestStatus &aStatus,TTimeIntervalMicroSeconds32 aInterval)
       
  5063 //
       
  5064 // Request a relative timer.
       
  5065 //
       
  5066 /**
       
  5067 Requests an event after the specified interval.
       
  5068 
       
  5069 The counter for this type of request stops during power-down.
       
  5070 A 5 second timer will complete late if, for example, the machine is turned off
       
  5071 2 seconds after the request is made.
       
  5072 
       
  5073 @param aStatus    On completion, contains the status of the request.
       
  5074                   This is KErrNone if the timer completed normally at the
       
  5075                   requested time, otherwise another of the
       
  5076                   system-wide error codes.
       
  5077 
       
  5078 @param aInterval  The time interval, in microseconds, after which an event
       
  5079                   is to occur.
       
  5080 
       
  5081 @panic USER 87, if aInterval is negative.
       
  5082 @panic KERN-EXEC 15, if this function is called while a request for a timer
       
  5083        event is still outstanding.
       
  5084 */
       
  5085 	{
       
  5086 
       
  5087 	__ASSERT_ALWAYS(aInterval.Int()>=0,::Panic(ERTimerAfterTimeNegative));
       
  5088 	aStatus=KRequestPending;
       
  5089 	Exec::TimerAfter(iHandle,aStatus,aInterval.Int());
       
  5090 	}
       
  5091 
       
  5092 
       
  5093 
       
  5094 
       
  5095 EXPORT_C void RTimer::AfterTicks(TRequestStatus& aStatus, TInt aTicks)
       
  5096 //
       
  5097 // Request a relative timer in system ticks.
       
  5098 //
       
  5099 /**
       
  5100 Requests an event after the specified interval.
       
  5101 
       
  5102 The counter for this type of request stops during power-down.
       
  5103 A 5 tick timer will complete late if, for example, the machine is turned off
       
  5104 2 ticks after the request is made.
       
  5105 
       
  5106 @param aStatus    On completion, contains the status of the request.
       
  5107                   This is KErrNone if the timer completed normally at the
       
  5108                   requested time, otherwise another of the
       
  5109                   system-wide error codes.
       
  5110 
       
  5111 @param aTicks     The time interval, in system ticks, after which an event
       
  5112                   is to occur.
       
  5113 
       
  5114 @panic USER 87, if aTicks is negative.
       
  5115 @panic KERN-EXEC 15, if this function is called while a request for a timer
       
  5116        event is still outstanding.
       
  5117 */
       
  5118 	{
       
  5119 	__ASSERT_ALWAYS(aTicks >= 0, ::Panic(ERTimerAfterTimeNegative));
       
  5120 	aStatus = KRequestPending;
       
  5121 	Exec::TimerAfter(iHandle, aStatus, -aTicks);
       
  5122 	}
       
  5123 
       
  5124 
       
  5125 
       
  5126 
       
  5127 EXPORT_C void RTimer::HighRes(TRequestStatus &aStatus,TTimeIntervalMicroSeconds32 aInterval)
       
  5128 //
       
  5129 // Request a relative timer to a resolution of 1ms.
       
  5130 //
       
  5131 /**
       
  5132 Requests an event after the specified interval to a resolution of 1ms. 
       
  5133 The "HighRes timer" counter stops during power-down (the same as "after timer"). 
       
  5134 
       
  5135 @param aStatus    On completion, contains the status of the request.
       
  5136                   This is KErrNone if the timer completed normally at the
       
  5137                   requested time, otherwise another of the
       
  5138                   system-wide error codes.
       
  5139 
       
  5140 @param aInterval  The time interval, in microseconds, after which an event
       
  5141                   is to occur.
       
  5142 
       
  5143 @panic USER 87, if aInterval is negative.
       
  5144 @panic KERN-EXEC 15, if this function is called while a request for a timer
       
  5145        event is still outstanding.
       
  5146 */
       
  5147 	{
       
  5148 
       
  5149 	__ASSERT_ALWAYS(aInterval.Int()>=0,::Panic(ERTimerAfterTimeNegative));
       
  5150 	aStatus=KRequestPending;
       
  5151 	Exec::TimerHighRes(iHandle,aStatus,aInterval.Int());
       
  5152 	}
       
  5153 
       
  5154 
       
  5155 
       
  5156 
       
  5157 EXPORT_C void RTimer::At(TRequestStatus &aStatus,const TTime &aTime)
       
  5158 //
       
  5159 // Request an absolute timer.
       
  5160 //
       
  5161 /**
       
  5162 Requests an event at a given system time (in the current time zone).
       
  5163 
       
  5164 If the machine is off at that time, it is automatically turned on.
       
  5165 
       
  5166 @param aStatus On completion, contains the status of the request:
       
  5167                KErrNone, the timer completed normally at the requested time;
       
  5168                KErrCancel, the timer was cancelled;
       
  5169                KErrAbort, the timer was aborted because the system time changed;
       
  5170                KErrUnderflow, the requested completion time is in the past;
       
  5171                KErrOverFlow, the requested completion time is too far in the future;
       
  5172 @param aTime   The time at which the timer will expire.
       
  5173 
       
  5174 @panic KERN-EXEC 15, if this function is called while a request for a timer
       
  5175        event is still outstanding.
       
  5176 */
       
  5177 	{
       
  5178 
       
  5179 	aStatus=KRequestPending;
       
  5180 	TInt64 time=aTime.Int64();
       
  5181 	time -= ((TInt64)User::UTCOffset().Int()) * 1000000;
       
  5182 	Exec::TimerAt(iHandle,aStatus,time);
       
  5183 	}
       
  5184 
       
  5185 
       
  5186 
       
  5187 
       
  5188 EXPORT_C void RTimer::AtUTC(TRequestStatus &aStatus,const TTime &aUTCTime)
       
  5189 //
       
  5190 // Request an absolute timer in UTC time.
       
  5191 //
       
  5192 /**
       
  5193 Requests an event at a given UTC time.
       
  5194 
       
  5195 If the machine is off at that time, it is automatically turned on.
       
  5196 
       
  5197 @param aStatus On completion, contains the status of the request:
       
  5198                KErrNone, the timer completed normally at the requested time;
       
  5199                KErrCancel, the timer was cancelled;
       
  5200                KErrAbort, the timer was aborted because the system time changed;
       
  5201                KErrUnderflow, the requested completion time is in the past;
       
  5202                KErrOverFlow, the requested completion time is too far in the future;
       
  5203 @param aTime   The time at which the timer will expire.
       
  5204 
       
  5205 @panic KERN-EXEC 15, if this function is called while a request for a timer
       
  5206        event is still outstanding.
       
  5207 */
       
  5208 	{
       
  5209 
       
  5210 	aStatus=KRequestPending;
       
  5211 	Exec::TimerAt(iHandle,aStatus,aUTCTime.Int64());
       
  5212 	}
       
  5213 
       
  5214 
       
  5215 
       
  5216 
       
  5217 EXPORT_C void RTimer::Lock(TRequestStatus &aStatus,TTimerLockSpec aLock)
       
  5218 //
       
  5219 // Request an absolute timer.
       
  5220 //
       
  5221 /**
       
  5222 Requests an event on a specified second fraction.
       
  5223 
       
  5224 @param aStatus On completion, contains the status of the request:
       
  5225                KErrGeneral, the first time this is called;
       
  5226                KErrNone, the timer completed normally at the requested time;
       
  5227                KErrCancel, the timer was cancelled;
       
  5228                KErrAbort, the timer was aborted because the system time changed;
       
  5229                KErrUnderflow, the requested completion time is in the past;
       
  5230                KErrOverFlow, the requested completion time is too far in the future.
       
  5231 @param aLock   The fraction of a second at which the timer completes.
       
  5232 
       
  5233 @panic KERN-EXEC 15, if this function is called while a request for a timer
       
  5234        event is still outstanding.
       
  5235 */
       
  5236 	{
       
  5237 	aStatus=KRequestPending;
       
  5238 	Exec::TimerLock(iHandle,aStatus,aLock);
       
  5239 	}
       
  5240 
       
  5241 
       
  5242 /**
       
  5243 Requests an event to be triggered when aSeconds is exactly, (ie not greater or 
       
  5244 less than), the time elapsed (to the nearest second) since the last user activity.
       
  5245 If the event trigger time has been "missed", instead of triggering late,
       
  5246 the timer waits for the next user activity, to try and satisfy the condition.
       
  5247 
       
  5248 That is to say, if there was user activity within the last aSeconds,
       
  5249 the event will be triggered after aSeconds of continuous inactivity following that activity.
       
  5250 Otherwise, if there has been no such activity within this time, an event is
       
  5251 triggered after aSeconds of continuous inactivity following the next user activity
       
  5252 in the future.
       
  5253 
       
  5254 It follows from this, that you can request an event directly after the next
       
  5255 user activity by supplying a time interval of zero.
       
  5256 
       
  5257 
       
  5258 @param aStatus  On completion, contains the status of the request:
       
  5259                 KErrNone, the timer completed normally;
       
  5260                 KErrCancel, the timer was cancelled;
       
  5261                 KErrArgument, if aSeconds is less then zero;
       
  5262                 KErrOverflow, if aSecond reaches its limit (which is platform specific but greater then one and a half day).
       
  5263 @param aSeconds The time interval in seconds.
       
  5264 
       
  5265 @panic KERN-EXEC 15, if this function is called while a request for a timer
       
  5266        event is still outstanding.
       
  5267 */
       
  5268 EXPORT_C void RTimer::Inactivity(TRequestStatus &aStatus, TTimeIntervalSeconds aSeconds)
       
  5269 	{
       
  5270 	aStatus=KRequestPending;
       
  5271 	Exec::TimerInactivity(iHandle, aStatus, aSeconds.Int());
       
  5272 	}
       
  5273 
       
  5274 
       
  5275 
       
  5276 
       
  5277 EXPORT_C TInt RChangeNotifier::Logon(TRequestStatus& aStatus) const
       
  5278 /**
       
  5279 Issues a request for notification when changes occur in the environment. 
       
  5280 
       
  5281 A switch in locale, or crossing over past midnight, are examples of changes
       
  5282 that are reported.
       
  5283 
       
  5284 When a change in the environment occurs, the request completes and the 
       
  5285 TRquestStatus object will contain one or more of the bit values defined
       
  5286 by the TChanges enum.
       
  5287 
       
  5288 Alternatively, if an outstanding request is cancelled by a call to
       
  5289 this handle's LogonCancel() member function, then the request completes
       
  5290 with a KErrCancel.
       
  5291 
       
  5292 Note that if this is the first notification request after creation of
       
  5293 the change notifier, then this request completes immediately.
       
  5294 
       
  5295 @param aStatus A reference to the request status object.
       
  5296 
       
  5297 @return KErrInUse, if there is an outstanding request; KErrNone otherwise.
       
  5298 
       
  5299 @see TChanges
       
  5300 @see RChangeNotifier::Logon()
       
  5301 */
       
  5302 	{
       
  5303 	
       
  5304 	aStatus=KRequestPending;
       
  5305 	return(Exec::ChangeNotifierLogon(iHandle,aStatus));
       
  5306 	}
       
  5307 
       
  5308 
       
  5309 
       
  5310 
       
  5311 EXPORT_C TInt RChangeNotifier::LogonCancel() const
       
  5312 /**
       
  5313 Cancels an outstanding change notification request.
       
  5314 
       
  5315 @return KErrGeneral, if there is no outstanding request; KErrNone otherwise.
       
  5316 
       
  5317 @see RChangeNotifier::Logon()
       
  5318 */
       
  5319 	{
       
  5320 	
       
  5321 	return(Exec::ChangeNotifierLogoff(iHandle));
       
  5322 	}
       
  5323 
       
  5324 
       
  5325 
       
  5326 
       
  5327 EXPORT_C void UserSvr::CaptureEventHook()
       
  5328 //
       
  5329 // Capture the event hook
       
  5330 //
       
  5331 	{
       
  5332 
       
  5333 	Exec::CaptureEventHook();
       
  5334 	}
       
  5335 
       
  5336 EXPORT_C void UserSvr::ReleaseEventHook()
       
  5337 //
       
  5338 // Release the event hook
       
  5339 //
       
  5340 	{
       
  5341 
       
  5342 	Exec::ReleaseEventHook();
       
  5343 	}
       
  5344 
       
  5345 EXPORT_C void UserSvr::RequestEvent(TRawEventBuf &anEvent,TRequestStatus &aStatus)
       
  5346 //
       
  5347 // Request the next event.
       
  5348 //
       
  5349 	{
       
  5350 
       
  5351 	aStatus=KRequestPending;
       
  5352 	Exec::RequestEvent(anEvent,aStatus);
       
  5353 	}
       
  5354 
       
  5355 EXPORT_C void UserSvr::RequestEventCancel()
       
  5356 //
       
  5357 // Cancel the event request.
       
  5358 //
       
  5359 	{
       
  5360 
       
  5361 	Exec::RequestEventCancel();
       
  5362 	}
       
  5363 
       
  5364 /**
       
  5365 Add an event to the queue.
       
  5366 
       
  5367 @param anEvent The raw hardware event to be added to the event queue.
       
  5368 @return KErrNone, if successful; KErrPermissionDenied, if the caller has 
       
  5369 insufficient capability; otherwise, one of the other system-wide error codes.
       
  5370 
       
  5371 @capability SwEvent
       
  5372 @capability PowerMgmt for ESwitchOff, ERestartSystem, ECaseOpen and ECaseClose
       
  5373 */
       
  5374 EXPORT_C TInt UserSvr::AddEvent(const TRawEvent& anEvent)
       
  5375 	{
       
  5376 
       
  5377     return(Exec::AddEvent(anEvent));
       
  5378 	}
       
  5379 
       
  5380 EXPORT_C void UserSvr::ScreenInfo(TDes8 &anInfo)
       
  5381 //
       
  5382 // Get the screen info.
       
  5383 //
       
  5384 	{
       
  5385 
       
  5386 	Exec::HalFunction(EHalGroupDisplay,EDisplayHalScreenInfo,(TAny*)&anInfo,NULL);
       
  5387 	}
       
  5388 
       
  5389 #ifdef __USERSIDE_THREAD_DATA__
       
  5390 
       
  5391 EXPORT_C TAny* UserSvr::DllTls(TInt aHandle)
       
  5392 //
       
  5393 // Return the value of the Thread Local Storage variable.
       
  5394 //
       
  5395 	{
       
  5396 	return LocalThreadData()->DllTls(aHandle, KDllUid_Default);
       
  5397 	}
       
  5398 
       
  5399 EXPORT_C TAny* UserSvr::DllTls(TInt aHandle, TInt aDllUid)
       
  5400 //
       
  5401 // Return the value of the Thread Local Storage variable.
       
  5402 //
       
  5403 	{
       
  5404 	return LocalThreadData()->DllTls(aHandle, aDllUid);
       
  5405 	}
       
  5406 
       
  5407 #else
       
  5408 
       
  5409 EXPORT_C TAny* UserSvr::DllTls(TInt aHandle)
       
  5410 //
       
  5411 // Return the value of the Thread Local Storage variable.
       
  5412 //
       
  5413 	{
       
  5414 
       
  5415 	return Exec::DllTls(aHandle, KDllUid_Default);
       
  5416 	}
       
  5417 
       
  5418 EXPORT_C TAny* UserSvr::DllTls(TInt aHandle, TInt aDllUid)
       
  5419 //
       
  5420 // Return the value of the Thread Local Storage variable.
       
  5421 //
       
  5422 	{
       
  5423 
       
  5424 	return Exec::DllTls(aHandle, aDllUid);
       
  5425 	}
       
  5426 
       
  5427 #endif
       
  5428 
       
  5429 EXPORT_C void UserSvr::DllFileName(TInt aHandle, TDes& aFileName)
       
  5430 //
       
  5431 // Return the filename of this dll
       
  5432 //
       
  5433 	{
       
  5434 	TBuf8<KMaxFileName> n8;
       
  5435 	Exec::DllFileName(aHandle, n8);
       
  5436 	aFileName.Copy(n8);
       
  5437 	}
       
  5438 
       
  5439 EXPORT_C TBool UserSvr::TestBootSequence()
       
  5440 //
       
  5441 // Is the machine being booted by the test department?
       
  5442 //
       
  5443     {
       
  5444 
       
  5445 	return Exec::HalFunction(EHalGroupPower,EPowerHalTestBootSequence,NULL,NULL);
       
  5446     }
       
  5447 
       
  5448 /**
       
  5449 Register whether the W/S takes care of turning the screen on
       
  5450 */
       
  5451 EXPORT_C void UserSvr::WsRegisterSwitchOnScreenHandling(TBool aState)
       
  5452     {
       
  5453 
       
  5454 	Exec::HalFunction(EHalGroupDisplay,EDisplayHalWsRegisterSwitchOnScreenHandling,(TAny*)aState,NULL);
       
  5455     }
       
  5456 
       
  5457 EXPORT_C void UserSvr::WsSwitchOnScreen()
       
  5458 //
       
  5459 // W/S switch on the screen
       
  5460 //
       
  5461     {
       
  5462 
       
  5463 	Exec::HalFunction(EHalGroupDisplay,EDisplayHalWsSwitchOnScreen,NULL,NULL);
       
  5464     }
       
  5465 
       
  5466 
       
  5467 EXPORT_C TUint32 UserSvr::DebugMask()
       
  5468 /**
       
  5469 Return the kernel debug mask at index 0
       
  5470 */
       
  5471     {
       
  5472 	return Exec::DebugMask();
       
  5473     }
       
  5474 
       
  5475 
       
  5476 EXPORT_C TUint32 UserSvr::DebugMask(TUint aIndex)
       
  5477 /**
       
  5478 Return the kernel debug mask at the given index position
       
  5479 
       
  5480 @param aIndex An index of which 32 bit mask word is to be accessed
       
  5481 */
       
  5482     {
       
  5483 	return Exec::DebugMaskIndex(aIndex);
       
  5484     }
       
  5485 #endif // __TOOLS2__
       
  5486 
       
  5487 
       
  5488 EXPORT_C TTrapHandler *User::TrapHandler()
       
  5489 /**
       
  5490 Gets a pointer to the current thread's trap handler.
       
  5491 
       
  5492 Note that TTrapHandler is an abstract base class; a trap handler must be
       
  5493 implemented as a derived class.
       
  5494 
       
  5495 @return A pointer to the current thread's trap handler, if any. NULL, if no 
       
  5496         pre-existing trap handler is set.
       
  5497 */
       
  5498 	{
       
  5499 
       
  5500 	return GetTrapHandler();
       
  5501 	}
       
  5502 
       
  5503 
       
  5504 
       
  5505 
       
  5506 EXPORT_C TTrapHandler *User::SetTrapHandler(TTrapHandler *aHandler)
       
  5507 /**
       
  5508 Sets the current thread's trap handler and returns a pointer to any pre-existing 
       
  5509 trap handler.
       
  5510 
       
  5511 Pass a NULL pointer to this function to clear the trap handler.
       
  5512 
       
  5513 The trap handler works with the TRAP mechanism to handle the effects of a 
       
  5514 leave.
       
  5515 
       
  5516 Note that TTrapHandler is an abstract base class; a trap handler must be
       
  5517 implemented as a derived class.
       
  5518 
       
  5519 @param aHandler A pointer to the trap handler which is to be installed as 
       
  5520                 the current thread's trap handler.
       
  5521                 
       
  5522 @return A pointer to the current thread's pre-existing trap handler, if any. 
       
  5523         NULL, if no pre-existing trap handler is set.
       
  5524         
       
  5525 @see TRAP
       
  5526 @see TRAPD
       
  5527 */
       
  5528 	{
       
  5529 
       
  5530 	TTrapHandler* prev;
       
  5531 #if defined(__USERSIDE_THREAD_DATA__) && defined(__LEAVE_EQUALS_THROW__)
       
  5532 	prev = LocalThreadData()->iTrapHandler;
       
  5533 #else
       
  5534 	prev = Exec::SetTrapHandler(aHandler);
       
  5535 #endif
       
  5536 #ifdef __USERSIDE_THREAD_DATA__
       
  5537 	LocalThreadData()->iTrapHandler = aHandler;
       
  5538 #endif
       
  5539 	return prev;	
       
  5540 	}
       
  5541 
       
  5542 #ifndef __LEAVE_EQUALS_THROW__
       
  5543 EXPORT_C TTrapHandler* User::MarkCleanupStack()
       
  5544 /**
       
  5545 If there's a TTrapHandler installed marks the cleanup stack and returns 
       
  5546 the TTrapHandler for subsequent use in UnMarkCleanupStack. 
       
  5547 
       
  5548 Only intended for use in the defintion of TRAP and TRAPD and only when 
       
  5549 User::Leave is defined in terms of THROW.
       
  5550 
       
  5551 @return A pointer to the current thread's pre-existing trap handler, if any. 
       
  5552         NULL, if no pre-existing trap handler is set.
       
  5553 
       
  5554 @see TRAP
       
  5555 @see TRAPD
       
  5556 */
       
  5557 	{ 
       
  5558 	return (TTrapHandler*)0; 
       
  5559 	}
       
  5560 
       
  5561 
       
  5562 EXPORT_C void User::UnMarkCleanupStack(TTrapHandler* /*aHandler*/)
       
  5563 /**
       
  5564 If passed a non-null TTrapHandler unmarks the cleanup stack.
       
  5565 
       
  5566 Only intended for use in the defintion of TRAP and TRAPD and only when 
       
  5567 User::Leave is defined in terms of THROW.
       
  5568 
       
  5569 @see TRAP
       
  5570 @see TRAPD
       
  5571 */
       
  5572 	{}
       
  5573 
       
  5574 #else
       
  5575 
       
  5576 EXPORT_C TTrapHandler* User::MarkCleanupStack()
       
  5577 /**
       
  5578 If there's a TTrapHandler installed marks the cleanup stack and returns 
       
  5579 the TTrapHandler for subsequent use in UnMarkCleanupStack. 
       
  5580 
       
  5581 Only intended for use in the defintion of TRAP and TRAPD and only when 
       
  5582 User::Leave is defined in terms of THROW.
       
  5583 
       
  5584 @return A pointer to the current thread's pre-existing trap handler, if any. 
       
  5585         NULL, if no pre-existing trap handler is set.
       
  5586 
       
  5587 @see TRAP
       
  5588 @see TRAPD
       
  5589 */
       
  5590 	{
       
  5591 
       
  5592 	TTrapHandler* pH = GetTrapHandler();
       
  5593 	if (pH)
       
  5594 		pH->Trap();
       
  5595 	return pH;
       
  5596 	}
       
  5597 
       
  5598 EXPORT_C void User::UnMarkCleanupStack(TTrapHandler* aHandler)
       
  5599 /**
       
  5600 If passed a non-null TTrapHandler unmarks the cleanup stack.
       
  5601 
       
  5602 Only intended for use in the defintion of TRAP and TRAPD and only when 
       
  5603 User::Leave is defined in terms of THROW.
       
  5604 
       
  5605 @see TRAP
       
  5606 @see TRAPD
       
  5607 */
       
  5608 	{
       
  5609 
       
  5610 	if (aHandler)
       
  5611 		aHandler->UnTrap();
       
  5612 	}
       
  5613 
       
  5614 #endif
       
  5615 
       
  5616 #ifndef __TOOLS2__
       
  5617 EXPORT_C TInt User::Beep(TInt aFrequency,TTimeIntervalMicroSeconds32 aDuration)
       
  5618 /**
       
  5619 Makes a beep tone with a specified frequency and duration.
       
  5620 
       
  5621 This function should not be used. It exists to maintain compatibility with
       
  5622 older versions of Symban OS.
       
  5623 */
       
  5624 	{
       
  5625 
       
  5626 	return Exec::HalFunction(EHalGroupSound,ESoundHalBeep,(TAny*)aFrequency,(TAny*)aDuration.Int());
       
  5627 	}
       
  5628 
       
  5629 
       
  5630 
       
  5631 
       
  5632 // Unused, exists only for BC reasons
       
  5633 EXPORT_C TInt UserSvr::HalGet(TInt, TAny*)
       
  5634 	{
       
  5635 	return KErrNotSupported;
       
  5636 	}
       
  5637 
       
  5638 // Unused, exists only for BC reasons
       
  5639 EXPORT_C TInt UserSvr::HalSet(TInt, TAny*)
       
  5640 	{
       
  5641 	return KErrNotSupported;
       
  5642 	}
       
  5643 
       
  5644 EXPORT_C TInt UserSvr::HalFunction(TInt aGroup, TInt aFunction, TAny* a1, TAny* a2)
       
  5645 	{
       
  5646 
       
  5647 	return Exec::HalFunction(aGroup, aFunction, a1, a2);
       
  5648 	}
       
  5649 
       
  5650 EXPORT_C TInt UserSvr::HalFunction(TInt aGroup, TInt aFunction, TAny* a1, TAny* a2, TInt aDeviceNumber)
       
  5651 	{
       
  5652 
       
  5653 	return Exec::HalFunction(aGroup | (aDeviceNumber<<16), aFunction, a1, a2);
       
  5654 	}
       
  5655 
       
  5656 /**
       
  5657 @capability WriteDeviceData
       
  5658 */
       
  5659 EXPORT_C TInt UserSvr::SetMemoryThresholds(TInt aLowThreshold, TInt aGoodThreshold)
       
  5660 	{
       
  5661 	return Exec::SetMemoryThresholds(aLowThreshold,aGoodThreshold);
       
  5662 	}
       
  5663 
       
  5664 /**
       
  5665 @deprecated
       
  5666 @internalAll
       
  5667 @return EFalse
       
  5668 */
       
  5669 EXPORT_C TBool UserSvr::IpcV1Available()
       
  5670 	{
       
  5671 	return EFalse;
       
  5672 	}
       
  5673 
       
  5674 
       
  5675 
       
  5676 EXPORT_C void User::SetDebugMask(TUint32 aVal)
       
  5677 /**
       
  5678 Sets the debug mask.
       
  5679 
       
  5680 @param aVal A set of bit values as defined in nk_trace.h
       
  5681 */
       
  5682 	{
       
  5683 	Exec::SetDebugMask(aVal);
       
  5684 	}
       
  5685 
       
  5686 EXPORT_C void User::SetDebugMask(TUint32 aVal, TUint aIndex)
       
  5687 /**
       
  5688 Sets the debug mask at the given index
       
  5689 
       
  5690 @param aVal A set of bit values as defined in nk_trace.h
       
  5691 @param aIndex An index of which 32 bit mask word is to be accessed
       
  5692 */
       
  5693 	{
       
  5694 	Exec::SetDebugMaskIndex(aVal, aIndex);
       
  5695 	}
       
  5696 
       
  5697 
       
  5698 /**
       
  5699 Gets machine information.
       
  5700 
       
  5701 @publishedPartner
       
  5702 @deprecated Use HAL::Get() from the HAL library instead.
       
  5703 */
       
  5704 EXPORT_C TInt UserHal::MachineInfo(TDes8& anInfo)
       
  5705     {
       
  5706 	TInt bufLength=anInfo.MaxLength();
       
  5707 	__ASSERT_ALWAYS(bufLength==sizeof(TMachineInfoV2) || bufLength==sizeof(TMachineInfoV1),Panic(ETDes8BadDescriptorType));
       
  5708 
       
  5709 	// assemble a TMachineInfoV1 buffer
       
  5710 	TMachineInfoV2* info=&((TMachineInfoV2Buf&)anInfo)();
       
  5711 	// Variant stuff
       
  5712 	TVariantInfoV01Buf infoBuf;
       
  5713 	TInt r = Exec::HalFunction(EHalGroupVariant, EVariantHalVariantInfo, (TAny*)&infoBuf, NULL);
       
  5714 	if (KErrNone != r) return r;			// must always be implemented!
       
  5715 	TVariantInfoV01& variantInfo = infoBuf();
       
  5716 
       
  5717 	info->iRomVersion=variantInfo.iRomVersion;
       
  5718 	info->iMachineUniqueId=variantInfo.iMachineUniqueId;
       
  5719 	info->iLedCapabilities=variantInfo.iLedCapabilities;
       
  5720 	info->iProcessorClockInKHz=variantInfo.iProcessorClockInKHz;
       
  5721 	info->iSpeedFactor=variantInfo.iSpeedFactor;
       
  5722 
       
  5723 	// Video driver stuff
       
  5724 	TVideoInfoV01Buf vidinfoBuf;
       
  5725 	r = Exec::HalFunction(EHalGroupDisplay, EDisplayHalCurrentModeInfo, (TAny*)&vidinfoBuf, NULL);
       
  5726 	if (KErrNone == r)
       
  5727 		{
       
  5728 		TVideoInfoV01& vidinfo = vidinfoBuf();
       
  5729 		info->iDisplaySizeInPixels=vidinfo.iSizeInPixels;
       
  5730 		info->iPhysicalScreenSize=vidinfo.iSizeInTwips;
       
  5731 		}
       
  5732 	else								// no display driver
       
  5733 		{
       
  5734 		info->iDisplaySizeInPixels.iWidth=0;
       
  5735 		info->iDisplaySizeInPixels.iHeight=0;
       
  5736 		info->iPhysicalScreenSize.iWidth=0;
       
  5737 		info->iPhysicalScreenSize.iHeight=0;
       
  5738 		}
       
  5739 	TInt colors = 0;
       
  5740 	r = Exec::HalFunction(EHalGroupDisplay, EDisplayHalColors, &colors, NULL);
       
  5741 	info->iMaximumDisplayColors=(KErrNone == r)?colors:0;
       
  5742 	TInt val;
       
  5743 	info->iBacklightPresent= (KErrNone == Exec::HalFunction(EHalGroupDisplay, EDisplayHalBacklightOn, &val, NULL));
       
  5744 
       
  5745 	// Pointing device stuff
       
  5746 	TDigitiserInfoV01Buf xyinfoBuf;
       
  5747 	r = Exec::HalFunction(EHalGroupDigitiser, EDigitiserHalXYInfo, (TAny*)&xyinfoBuf, NULL);
       
  5748 	if (KErrNone == r)
       
  5749 		{
       
  5750 		info->iXYInputType=EXYInputPointer;					// XY is Digitiser
       
  5751 		TDigitiserInfoV01& xyinfo = xyinfoBuf();
       
  5752 		info->iXYInputSizeInPixels=xyinfo.iDigitiserSize;
       
  5753 		info->iOffsetToDisplayInPixels=xyinfo.iOffsetToDisplay;
       
  5754 		}
       
  5755 	else
       
  5756 		{
       
  5757 		TMouseInfoV01Buf mouseinfoBuf;
       
  5758 		r = Exec::HalFunction(EHalGroupMouse, EMouseHalMouseInfo, (TAny*)&mouseinfoBuf, NULL);
       
  5759 		if (KErrNone == r)
       
  5760 			{
       
  5761 			info->iXYInputType=EXYInputMouse;				// XY is Mouse
       
  5762 			TMouseInfoV01& mouseinfo = mouseinfoBuf();
       
  5763 			info->iXYInputSizeInPixels=mouseinfo.iMouseAreaSize;
       
  5764 			info->iOffsetToDisplayInPixels=mouseinfo.iOffsetToDisplay;
       
  5765 			}
       
  5766 		else
       
  5767 			{
       
  5768 			info->iXYInputType=EXYInputNone;				// no XY
       
  5769 			info->iXYInputSizeInPixels.iWidth=0;
       
  5770 			info->iXYInputSizeInPixels.iHeight=0;
       
  5771 			info->iOffsetToDisplayInPixels.iX=0;
       
  5772 			info->iOffsetToDisplayInPixels.iY=0;
       
  5773 			}
       
  5774 		}
       
  5775 
       
  5776 	// Keyboard stuff
       
  5777 	TKeyboardInfoV01Buf kbdinfoBuf;
       
  5778 	info->iKeyboardPresent= (KErrNone == Exec::HalFunction(EHalGroupKeyboard, EKeyboardHalKeyboardInfo, (TAny*)&kbdinfoBuf, NULL));
       
  5779 
       
  5780 	// Unused, obsolete parameters
       
  5781 	info->iKeyboardId=0;
       
  5782 	info->iDisplayId=0;
       
  5783 	if(bufLength==sizeof(TMachineInfoV2))
       
  5784 		{
       
  5785 		// assemble a TMachineInfoV2 buffer
       
  5786 		info->iLanguageIndex=0;
       
  5787 		info->iKeyboardIndex=0;
       
  5788 		}
       
  5789 
       
  5790 	anInfo.SetLength(bufLength);
       
  5791 
       
  5792     return KErrNone;
       
  5793     }
       
  5794 
       
  5795 /**
       
  5796 Gets memory information.
       
  5797 
       
  5798 @see HAL::Get()
       
  5799 
       
  5800 @publishedPartner
       
  5801 @deprecated Use HAL::Get() from the HAL library instead with attributes EMemoryRAM, EMemoryRAMFree or EMemoryROM.
       
  5802 */
       
  5803 EXPORT_C TInt UserHal::MemoryInfo(TDes8& anInfo)
       
  5804     {
       
  5805     return Exec::HalFunction(EHalGroupKernel,EKernelHalMemoryInfo,(TAny*)&anInfo,NULL);
       
  5806     }
       
  5807 
       
  5808 /**
       
  5809 Gets ROM configuration information.
       
  5810 
       
  5811 @publishedPartner
       
  5812 @deprecated No replacement.
       
  5813 */
       
  5814 EXPORT_C TInt UserHal::RomInfo(TDes8& anInfo)
       
  5815     {
       
  5816     return Exec::HalFunction(EHalGroupKernel,EKernelHalRomInfo,(TAny*)&anInfo,NULL);
       
  5817     }
       
  5818 
       
  5819 
       
  5820 
       
  5821 
       
  5822 /**
       
  5823 Gets drive information.
       
  5824 
       
  5825 @param anInfo A package buffer (TPckgBuf) containing a TDriveInfoV1 structure.
       
  5826               On return, this structure will contain the drive information.
       
  5827 	
       
  5828 @return KErrNone 
       
  5829 
       
  5830 @see TDriveInfoV1Buf
       
  5831 @see TDriveInfoV1
       
  5832 @see TPckgBuf
       
  5833 */
       
  5834 EXPORT_C TInt UserHal::DriveInfo(TDes8& anInfo)
       
  5835     {
       
  5836 	TDriveInfoV1Buf8 anInfo8;
       
  5837     TInt r = Exec::HalFunction(EHalGroupMedia,EMediaHalDriveInfo,(TAny*)&anInfo8,NULL);
       
  5838 	TDriveInfoV18& driveInfo8 = anInfo8();
       
  5839 	TDriveInfoV1* driveInfo = NULL;
       
  5840 	switch(((SBuf8*)&anInfo)->length>>KShiftDesType8) //type
       
  5841 		{
       
  5842 		case EPtr:
       
  5843 			 driveInfo = &((TPckg<TDriveInfoV1>&)anInfo)();
       
  5844 			 break;
       
  5845 		case EBuf:		
       
  5846 			 driveInfo = &((TDriveInfoV1Buf&)anInfo)();
       
  5847 			 break;
       
  5848 		default:
       
  5849 			__ASSERT_ALWAYS(EFalse,Panic(ETDes8BadDescriptorType));
       
  5850 		}
       
  5851 
       
  5852 	// A compile time assert to make sure that this function is examined if TDriveInfoV1
       
  5853 	// structure changes
       
  5854 	extern int TDriveInfoV1_structure_assert[(
       
  5855 		_FOFF(TDriveInfoV1,iRegisteredDriveBitmask)+4 == sizeof(TDriveInfoV1)
       
  5856 		&&
       
  5857 		sizeof(TDriveInfoV1) == 816
       
  5858 		)?1:-1];
       
  5859 	(void)TDriveInfoV1_structure_assert;
       
  5860 
       
  5861 	// Set length to size of old EKA1 TDriveInfoV1 (Will Panic if not big enough)
       
  5862 	TInt len = (TUint)_FOFF(TDriveInfoV1,iRegisteredDriveBitmask);
       
  5863 	anInfo.SetLength(len);
       
  5864 
       
  5865 	// Fill in info for old EKA1 TDriveInfoV1
       
  5866 	driveInfo->iTotalSupportedDrives = driveInfo8.iTotalSupportedDrives;
       
  5867 	driveInfo->iTotalSockets = driveInfo8.iTotalSockets;
       
  5868 	driveInfo->iRuggedFileSystem = driveInfo8.iRuggedFileSystem;
       
  5869 	TInt index;
       
  5870 	for(index=0;index<KMaxLocalDrives;index++)
       
  5871 		driveInfo->iDriveName[index].Copy(driveInfo8.iDriveName[index]);
       
  5872 	for(index=0;index<KMaxPBusSockets;index++)
       
  5873 		driveInfo->iSocketName[index].Copy(driveInfo8.iSocketName[index]);
       
  5874 
       
  5875 	// If anInfo is big enough then set new EKA2 members of TDriveInfoV1
       
  5876 	if((TUint)anInfo.MaxLength()>=(TUint)sizeof(TDriveInfoV1))
       
  5877 		{
       
  5878 		anInfo.SetLength(sizeof(TDriveInfoV1));
       
  5879 		driveInfo->iRegisteredDriveBitmask = driveInfo8.iRegisteredDriveBitmask;
       
  5880 		}
       
  5881 	return r;
       
  5882     }
       
  5883 
       
  5884 
       
  5885 
       
  5886 
       
  5887 /**
       
  5888 Gets the startup reason.
       
  5889 
       
  5890 @see HAL::Get() 
       
  5891 
       
  5892 @publishedPartner
       
  5893 @deprecated Use HAL::Get() from the HAL library instead with attributes ESystemStartupReason.
       
  5894 */
       
  5895 EXPORT_C TInt UserHal::StartupReason(TMachineStartupType& aReason)
       
  5896     {
       
  5897     return Exec::HalFunction(EHalGroupKernel,EKernelHalStartupReason,(TAny*)&aReason,NULL);
       
  5898     }
       
  5899 
       
  5900 
       
  5901 
       
  5902 
       
  5903 /**
       
  5904 Gets the reason why the kernel last faulted.
       
  5905 
       
  5906 @param aReason An integer that, on return, contains the reason code describing
       
  5907                why the kernel faulted. This is the fault number passed 
       
  5908                in a call to Kern::Fault().
       
  5909 
       
  5910 @return KErrNone
       
  5911 
       
  5912 @see Kern::Fault()
       
  5913 */
       
  5914 EXPORT_C TInt UserHal::FaultReason(TInt &aReason)
       
  5915 	{
       
  5916 
       
  5917 	return Exec::HalFunction(EHalGroupKernel,EKernelHalFaultReason,(TAny *)&aReason,NULL);
       
  5918 	}
       
  5919 
       
  5920 
       
  5921 
       
  5922 
       
  5923 /**
       
  5924 Gets the exception Id that describes the type of fault when
       
  5925 the kernel last faulted.
       
  5926 
       
  5927 The Id is the value contained in TArmExcInfo::iExcCode.
       
  5928  
       
  5929 @param anId An integer that, on return, contains the exception Id.
       
  5930 
       
  5931 @return KErrNone
       
  5932 
       
  5933 @see TArmExcInfo::iExcCode
       
  5934 @see TArmExcInfo
       
  5935 */
       
  5936 EXPORT_C TInt UserHal::ExceptionId(TInt &anId)
       
  5937 	{
       
  5938 
       
  5939 	return Exec::HalFunction(EHalGroupKernel,EKernelHalExceptionId, (TAny *)&anId, NULL);
       
  5940 	}
       
  5941 
       
  5942 
       
  5943 
       
  5944 /**
       
  5945 Gets the available exception information that describes the last kernel fault.
       
  5946 
       
  5947 @param aInfo A TExcInfo structure that, on return, contains the available
       
  5948              exception information.
       
  5949              
       
  5950 @return KErrNone
       
  5951 
       
  5952 @see TExcInfo        
       
  5953 */
       
  5954 EXPORT_C TInt UserHal::ExceptionInfo(TExcInfo &aInfo)
       
  5955 	{
       
  5956 
       
  5957 	return Exec::HalFunction(EHalGroupKernel,EKernelHalExceptionInfo, (TAny *)&aInfo, NULL);
       
  5958 	}
       
  5959 
       
  5960 
       
  5961 
       
  5962 
       
  5963 /**
       
  5964 Gets the page size for this device.
       
  5965 
       
  5966 @param anId An integer that, on return, contains the page size, in bytes,
       
  5967             for this device.
       
  5968 
       
  5969 @return KErrNone
       
  5970 */
       
  5971 EXPORT_C TInt UserHal::PageSizeInBytes(TInt& aSize)
       
  5972     {
       
  5973 
       
  5974     return Exec::HalFunction(EHalGroupKernel,EKernelHalPageSizeInBytes,(TAny*)&aSize,NULL);
       
  5975     }
       
  5976 
       
  5977 
       
  5978 
       
  5979 
       
  5980 /**
       
  5981 Switches the  device off.
       
  5982 
       
  5983 @return KErrNone, if successful; KErrPermissionDenied, if the calling process
       
  5984         has insufficient capability.
       
  5985 
       
  5986 @capability PowerMgmt
       
  5987 */
       
  5988 EXPORT_C TInt UserHal::SwitchOff()
       
  5989     {
       
  5990 	if(!RProcess().HasCapability(ECapabilityPowerMgmt,__PLATSEC_DIAGNOSTIC_STRING("Checked by UserHal::SwitchOff")))
       
  5991 		return KErrPermissionDenied;
       
  5992 	TInt r = Power::EnableWakeupEvents(EPwStandby);
       
  5993 	if(r!=KErrNone)
       
  5994 		return r;
       
  5995 	TRequestStatus s;
       
  5996 	Power::RequestWakeupEventNotification(s);
       
  5997 	Power::PowerDown();
       
  5998 	User::WaitForRequest(s);
       
  5999 	return s.Int();
       
  6000 //	return Exec::HalFunction(EHalGroupPower,EPowerHalSwitchOff,NULL,NULL);
       
  6001 	}
       
  6002 
       
  6003 
       
  6004 
       
  6005 
       
  6006 /**
       
  6007 Sets the calibration data for the digitiser (i.e. XY) input device.
       
  6008 
       
  6009 @param aCalibration The calibration data.
       
  6010 
       
  6011 @return KErrNone, if successful; KErrPermissionDenied, if the calling process
       
  6012         has insufficient capability.
       
  6013 
       
  6014 @see TDigitizerCalibration
       
  6015 
       
  6016 @capability WriteDeviceData
       
  6017 */
       
  6018 EXPORT_C TInt UserHal::SetXYInputCalibration(const TDigitizerCalibration& aCalibration)
       
  6019     {
       
  6020     return Exec::HalFunction(EHalGroupDigitiser,EDigitiserHalSetXYInputCalibration,(TAny*)&aCalibration,NULL);
       
  6021     }
       
  6022 
       
  6023 
       
  6024 
       
  6025 
       
  6026 /**
       
  6027 Gets the points on the display that the user should point to in order
       
  6028 to calibrate the digitiser (i.e. XY) input device.
       
  6029 
       
  6030 @param aCalibration A TDigitizerCalibration object that, on return, contains
       
  6031        the appropriate information.
       
  6032        
       
  6033 @return KerrNone, if successful; otherwise one of the other system wide
       
  6034         error codes. 
       
  6035 */
       
  6036 EXPORT_C TInt UserHal::CalibrationPoints(TDigitizerCalibration& aCalibration)
       
  6037     {
       
  6038 
       
  6039     return Exec::HalFunction(EHalGroupDigitiser,EDigitiserHalCalibrationPoints,(TAny*)&aCalibration,NULL);
       
  6040     }
       
  6041 
       
  6042 
       
  6043 
       
  6044 
       
  6045 /**
       
  6046 Gets the platform tick period.
       
  6047 
       
  6048 @param aTime The tick period in microseconds.
       
  6049 
       
  6050 @return KErrNone, if successful; otherwise one of the other system wide
       
  6051         error codes.
       
  6052 */
       
  6053 EXPORT_C TInt UserHal::TickPeriod(TTimeIntervalMicroSeconds32 &aTime)
       
  6054     {
       
  6055 
       
  6056     return Exec::HalFunction(EHalGroupKernel,EKernelHalTickPeriod,(TAny*)&aTime,NULL);
       
  6057     }
       
  6058 
       
  6059 
       
  6060 
       
  6061 /**
       
  6062 Saves the current digitiser (i.e. XY) input device calibration data.
       
  6063 
       
  6064 @return KErrNone, if successful; otherwise one of the other system wide
       
  6065         error codes, e.g. KErrNotSupported.
       
  6066 */
       
  6067 EXPORT_C TInt UserHal::SaveXYInputCalibration()
       
  6068     {
       
  6069 
       
  6070     return Exec::HalFunction(EHalGroupDigitiser,EDigitiserHalSaveXYInputCalibration,NULL,NULL);
       
  6071     }
       
  6072 
       
  6073 
       
  6074 
       
  6075 
       
  6076 /**
       
  6077 Restores the digitiser (i.e. XY) input device calibration data.
       
  6078 
       
  6079 @param aType A TDigitizerCalibration object that, on return, contains
       
  6080        the calibration data.
       
  6081 
       
  6082 @return KErrNone, if successful; KErrPermissionDenied, if the calling process
       
  6083         has insufficient capability; otherwise one of the other system wide
       
  6084         error codes, e.g. KErrNotSupported.
       
  6085 
       
  6086 @capability WriteDeviceData
       
  6087 */
       
  6088 EXPORT_C TInt UserHal::RestoreXYInputCalibration(TDigitizerCalibrationType aType)
       
  6089     {
       
  6090     return Exec::HalFunction(EHalGroupDigitiser,EDigitiserHalRestoreXYInputCalibration,(TAny*)aType,NULL);
       
  6091 	}
       
  6092 
       
  6093 
       
  6094 
       
  6095 
       
  6096 /**
       
  6097 Gets the machine configuration.
       
  6098 
       
  6099 @param aConfig On return contains the machine configuration data.
       
  6100 @param aSize   On return, contains the size of the data.
       
  6101 
       
  6102 @return KErrNone, if sucessful, otherwise one of the other system-wide
       
  6103         error codes.
       
  6104 
       
  6105 @capability ReadDeviceData
       
  6106 */
       
  6107 EXPORT_C TInt User::MachineConfiguration(TDes8& aConfig,TInt& aSize)
       
  6108     {
       
  6109 	return(Exec::MachineConfiguration(aConfig,aSize));
       
  6110     }
       
  6111 #endif // __TOOLS2__
       
  6112 
       
  6113 
       
  6114 
       
  6115 EXPORT_C TInt RDebug::Print(TRefByValue<const TDesC> aFmt,...)
       
  6116 //
       
  6117 // Print to the comms port
       
  6118 //
       
  6119     {
       
  6120 
       
  6121 	TestOverflowTruncate overflow;
       
  6122 	VA_LIST list;
       
  6123 	VA_START(list,aFmt);
       
  6124 	TBuf<0x100> buf;
       
  6125 	buf.AppendFormatList(aFmt,list,&overflow);
       
  6126 #ifdef _UNICODE
       
  6127 	TPtr8 p(buf.Collapse());
       
  6128 	Exec::DebugPrint((TAny*)&p, 0);
       
  6129 #else
       
  6130 	Exec::DebugPrint((TAny*)&buf, 0);
       
  6131 #endif
       
  6132 	return 0;
       
  6133     }
       
  6134 
       
  6135 class TestOverflowTruncate8 : public TDes8Overflow
       
  6136 	{
       
  6137 public:
       
  6138 	virtual void Overflow(TDes8& /*aDes*/) {}
       
  6139 	};
       
  6140 
       
  6141 EXPORT_C void RDebug::Printf(const char* aFmt, ...)
       
  6142 //
       
  6143 // Print to the comms port
       
  6144 //
       
  6145     {
       
  6146 
       
  6147 	TestOverflowTruncate8 overflow;
       
  6148 	VA_LIST list;
       
  6149 	VA_START(list,aFmt);
       
  6150 	TPtrC8 fmt((const TText8*)aFmt);
       
  6151 	TBuf8<0x100> buf;
       
  6152 	buf.AppendFormatList(fmt,list,&overflow);
       
  6153 	Exec::DebugPrint((TAny*)&buf, 0);
       
  6154     }
       
  6155 
       
  6156 EXPORT_C void RDebug::RawPrint(const TDesC8& aDes)
       
  6157 	{
       
  6158 	Exec::DebugPrint((TAny*)&aDes, 1);
       
  6159 	}
       
  6160 
       
  6161 EXPORT_C void RDebug::RawPrint(const TDesC16& aDes)
       
  6162 //
       
  6163 // Print to the comms port
       
  6164 //
       
  6165     {
       
  6166 	TBuf8<0x100> aDes8;
       
  6167 	if(aDes.Length()>0x100)
       
  6168 		{
       
  6169 		TPtrC ptr(aDes.Ptr(), 0x100);
       
  6170 		aDes8.Copy(ptr);
       
  6171 		}
       
  6172 	else
       
  6173 		aDes8.Copy(aDes);
       
  6174 	Exec::DebugPrint((TAny*)&aDes8, 1);
       
  6175 	}
       
  6176 
       
  6177 EXPORT_C TUint32 Math::Random()
       
  6178 /**
       
  6179 Gets 32 random bits from the kernel's random pool.
       
  6180 
       
  6181 @return The 32 random bits.
       
  6182 */
       
  6183 	{
       
  6184 
       
  6185 	return Exec::MathRandom();
       
  6186 	}
       
  6187 
       
  6188 
       
  6189 #ifndef __TOOLS2__
       
  6190 EXPORT_C void User::IMB_Range(TAny* aStart, TAny* aEnd)
       
  6191 /**
       
  6192 Does the necessary preparations to guarantee correct execution of code in the 
       
  6193 specified virtual address range.
       
  6194 
       
  6195 The function assumes that this code has been loaded or modified by user code.
       
  6196 Calling this function against uncommitted memory region is considered as S/W
       
  6197 bug and may generate exception on some memory models.
       
  6198 
       
  6199 The specified addresses are associated with a user writable code chunk as 
       
  6200 created by RChunk::CreateLocalCode().
       
  6201 
       
  6202 The function cleans the data cache to ensure that written data has been
       
  6203 committed to main memory and then flushes the instruction cache and branch
       
  6204 target buffer (BTB) to ensure that the code is loaded from main memory when
       
  6205 it is executed. 
       
  6206 The Kernel uses the size of the range specified to decide whether to clean/flush 
       
  6207 line-by-line or to simply clean/flush the entire cache.
       
  6208 
       
  6209 @param aStart The start virtual address of the region.
       
  6210 @param aEnd   The end virtual address of the region. This location is not within 
       
  6211               the region.
       
  6212               
       
  6213 @see RChunk::CreateLocalCode()
       
  6214 @see UserHeap::ChunkHeap()
       
  6215 */
       
  6216 	{
       
  6217 
       
  6218 	Exec::IMB_Range(aStart,(TUint32)aEnd-(TUint32)aStart);
       
  6219 	}
       
  6220 
       
  6221 
       
  6222 
       
  6223 
       
  6224 /**
       
  6225 Sets the specified handle into the specified environment data slot
       
  6226 for this process.
       
  6227 
       
  6228 The APPARC framework (class CApaApplication etc.) uses some of the slots internally,
       
  6229 so programs that use this framework should ensure that they only use slots available
       
  6230 for public use.
       
  6231 
       
  6232 @param aSlot   An index that identifies the environment data slot.
       
  6233                This is a value relative to zero;
       
  6234                i.e. 0 is the first item/slot.
       
  6235                This can range from 0 to 15.
       
  6236 @param aHandle The handle to be passed to this process.
       
  6237 
       
  6238 @return KErrNone, always.
       
  6239 
       
  6240 @panic KERN-EXEC 46 if this function is called by a thread running
       
  6241                     in a process that is not the creator of this process, or
       
  6242                     the handle is not local.
       
  6243 @panic KERN-EXEC 51 if aSlot is negative or is greater than or equal to
       
  6244                     the value of KArgIndex. 
       
  6245 @panic KERN-EXEC 52 if the specified slot is already in use.
       
  6246 
       
  6247 @see CApaApplication
       
  6248 @see CApaCommandLine::EnvironmentSlotForPublicUse()
       
  6249 */
       
  6250 EXPORT_C TInt RProcess::SetParameter(TInt aSlot, RHandleBase aHandle)
       
  6251 	{
       
  6252 	return Exec::ProcessSetHandleParameter(iHandle, aSlot, aHandle.Handle());
       
  6253 	}
       
  6254 
       
  6255 
       
  6256 
       
  6257 
       
  6258 /**
       
  6259 Sets the specified 16-bit descriptor data into the specified environment
       
  6260 data slot for this process.
       
  6261 
       
  6262 The APPARC framework (class CApaApplication etc.) uses some of the slots internally,
       
  6263 so programs that use this framework should ensure that they only use slots available
       
  6264 for public use.
       
  6265 
       
  6266 @param aSlot   An index that identifies the environment data slot.
       
  6267                This is a value relative to zero;
       
  6268                i.e. 0 is the first item/slot.
       
  6269                This can range from 0 to 15.
       
  6270 @param aDes    The 16-bit descriptor containing data be passed to this process.
       
  6271 
       
  6272 @return KErrNone, if successful, otherwise one of the other system
       
  6273         wide error codes.
       
  6274 
       
  6275 @panic KERN-EXEC 46 if this function is called by a thread running
       
  6276                     in a process that is not the creator of this process.
       
  6277 @panic KERN-EXEC 51 if aSlot is negative or is greater than or equal to
       
  6278                     the value of KArgIndex. 
       
  6279 @panic KERN-EXEC 52 if the specified slot is already in use.
       
  6280 @panic KERN-EXEC 53 if the length of data passed is negative.
       
  6281 
       
  6282 @see CApaApplication
       
  6283 @see CApaCommandLine::EnvironmentSlotForPublicUse()
       
  6284 */
       
  6285 EXPORT_C TInt RProcess::SetParameter(TInt aSlot, const TDesC16& aDes)
       
  6286 	{
       
  6287 	return Exec::ProcessSetDataParameter(iHandle, aSlot, (const TUint8*)aDes.Ptr(), 2*aDes.Length());
       
  6288 	}
       
  6289 
       
  6290 
       
  6291 
       
  6292 
       
  6293 /**
       
  6294 Sets the specified 8-bit descriptor data into the specified environment
       
  6295 data slot for this process.
       
  6296 
       
  6297 The APPARC framework (class CApaApplication etc.) uses some of the slots internally,
       
  6298 so programs that use this framework should ensure that they only use slots available
       
  6299 for public use.
       
  6300 
       
  6301 @param aSlot   An index that identifies the environment data slot.
       
  6302                This is a value relative to zero;
       
  6303                i.e. 0 is the first item/slot.
       
  6304                This can range from 0 to 15.
       
  6305 @param aDes    The 8-bit descriptor containing data be passed to this process.
       
  6306 
       
  6307 @return KErrNone, if successful, otherwise one of the other system
       
  6308         wide error codes.
       
  6309 
       
  6310 @panic KERN-EXEC 46 if this function is called by a thread running
       
  6311                     in a process that is not the creator of this process.
       
  6312 @panic KERN-EXEC 51 if aSlot is negative or is greater than or equal to
       
  6313                     the value of KArgIndex. 
       
  6314 @panic KERN-EXEC 52 if the specified slot is already in use.
       
  6315 @panic KERN-EXEC 53 if the length of data passed is negative.
       
  6316 
       
  6317 @see CApaApplication
       
  6318 @see CApaCommandLine::EnvironmentSlotForPublicUse()
       
  6319 */
       
  6320 EXPORT_C TInt RProcess::SetParameter(TInt aSlot, const TDesC8& aDes)
       
  6321 	{
       
  6322 	return Exec::ProcessSetDataParameter(iHandle, aSlot, aDes.Ptr(), aDes.Length());
       
  6323 	}
       
  6324 
       
  6325 
       
  6326 
       
  6327 
       
  6328 /**
       
  6329 Sets the specfied sub-session into the specified environment
       
  6330 data slot for this process.
       
  6331 
       
  6332 The APPARC framework (class CApaApplication etc.) uses some of the slots internally,
       
  6333 so programs that use this framework should ensure that they only use slots available
       
  6334 for public use.
       
  6335 
       
  6336 @param aSlot    An index that identifies the environment data slot.
       
  6337                 This is a value relative to zero;
       
  6338                 i.e. 0 is the first item/slot.
       
  6339                 This can range from 0 to 15.
       
  6340 @param aSession The sub-session.
       
  6341 
       
  6342 @return KErrNone, if successful, otherwise one of the other system
       
  6343         wide error codes.
       
  6344 
       
  6345 @panic KERN-EXEC 46 if this function is called by a thread running
       
  6346                     in a process that is not the creator of this process.
       
  6347 @panic KERN-EXEC 51 if aSlot is negative or is greater than or equal to
       
  6348                     the value of KArgIndex. 
       
  6349 @panic KERN-EXEC 52 if the specified slot is already in use.
       
  6350 @panic KERN-EXEC 53 if the length of data passed is negative.
       
  6351 
       
  6352 @see CApaApplication
       
  6353 @see CApaCommandLine::EnvironmentSlotForPublicUse()
       
  6354 */
       
  6355 EXPORT_C TInt RProcess::SetParameter(TInt aSlot, const RSubSessionBase& aSession)
       
  6356 	{
       
  6357 	TInt handle = aSession.SubSessionHandle();
       
  6358 	return Exec::ProcessSetDataParameter(iHandle, aSlot, (const TUint8*)&handle, sizeof(handle));
       
  6359 	}
       
  6360 
       
  6361 
       
  6362 
       
  6363 
       
  6364 /**
       
  6365 Sets the specfied integer value into the specified environment
       
  6366 data slot for this process.
       
  6367 
       
  6368 The APPARC framework (class CApaApplication etc.) uses some of the slots internally,
       
  6369 so programs that use this framework should ensure that they only use slots available
       
  6370 for public use.
       
  6371 
       
  6372 @param aSlot   An index that identifies the environment data slot.
       
  6373                This is a value relative to zero;
       
  6374                i.e. 0 is the first item/slot.
       
  6375                This can range from 0 to 15.
       
  6376 @param aData   The integer value.
       
  6377 
       
  6378 @return KErrNone, if successful, otherwise one of the other system
       
  6379         wide error codes.
       
  6380 
       
  6381 @panic KERN-EXEC 46 if this function is called by a thread running
       
  6382                     in a process that is not the creator of this process.
       
  6383 @panic KERN-EXEC 51 if aSlot is negative or is greater than or equal to
       
  6384                     the value of KArgIndex. 
       
  6385 @panic KERN-EXEC 52 if the specified slot is already in use.
       
  6386 @panic KERN-EXEC 53 if the length of data passed is negative.
       
  6387 
       
  6388 @see CApaApplication
       
  6389 @see CApaCommandLine::EnvironmentSlotForPublicUse()
       
  6390 */
       
  6391 EXPORT_C TInt RProcess::SetParameter(TInt aSlot, TInt aData)
       
  6392 	{
       
  6393 	return Exec::ProcessSetDataParameter(iHandle, aSlot, (TUint8*)&aData, sizeof(aData));
       
  6394 	}
       
  6395 
       
  6396 
       
  6397 
       
  6398 
       
  6399 EXPORT_C TInt User::GetTIntParameter(TInt aSlot,  TInt& aData)
       
  6400 /**
       
  6401 Gets the specified environment data item belonging to the
       
  6402 current process; this is assumed to be a 32 bit value.
       
  6403 
       
  6404 Environment data may be stored in the process and is passed to a child process
       
  6405 on creation of that child process.
       
  6406 
       
  6407 On successful return from this function, the data item is deleted from
       
  6408 the process. 
       
  6409 
       
  6410 @param aSlot An index that identifies the data item.
       
  6411              This is an index whose value is relative to zero;
       
  6412              i.e. 0 is the first item/slot.
       
  6413              This can range from 0 to 15, i.e. there are 16 slots. 
       
  6414 
       
  6415 @param aData On sucessful return, contains the environment data item.
       
  6416 
       
  6417 @return KErrNone, if successful;
       
  6418         KErrNotFound, if there is no data; 
       
  6419         KErrArgument, if the data is not binary data, or the data item in the
       
  6420                       process is longer than 32 bits.
       
  6421                       
       
  6422 @panic KERN-EXEC 51, if aSlot is negative or is greater than or equal to 16.                                   
       
  6423 */
       
  6424 	{
       
  6425 	TInt ret = Exec::ProcessGetDataParameter(aSlot, (TUint8*)&aData, sizeof(TInt));
       
  6426 	if (ret < 0)
       
  6427 		return ret;
       
  6428 	return KErrNone;
       
  6429 	}
       
  6430 
       
  6431 
       
  6432 
       
  6433 
       
  6434 EXPORT_C TInt User::ParameterLength(TInt aSlot)
       
  6435 /**
       
  6436 Gets the length of the specified item of environment data belonging to the
       
  6437 current process.
       
  6438 
       
  6439 Environment data may be stored in the process and is passed to a child process
       
  6440 on creation of that child process.
       
  6441 
       
  6442 @param aSlot An index that identifies the data item whose length is to be
       
  6443              retrieved. This is an index whose value is relative to zero;
       
  6444              i.e. 0 is the first item/slot.
       
  6445              This can range from 0 to 15, i.e. there are 16 slots.  
       
  6446              
       
  6447 @return KErrNotFound, if there is no data; 
       
  6448         KErrArgument, if the data is not binary data;
       
  6449         The length of the data item.
       
  6450              
       
  6451 @panic KERN-EXEC 51, if aSlot is negative or is greater than or equal to 16.             
       
  6452 */
       
  6453 	{
       
  6454 	TInt ret = Exec::ProcessDataParameterLength(aSlot);
       
  6455 	return ret;
       
  6456 	}
       
  6457 
       
  6458 
       
  6459 
       
  6460 
       
  6461 EXPORT_C TInt User::GetDesParameter(TInt aSlot, TDes8& aDes)
       
  6462 /**
       
  6463 Gets the specified environment data item belonging to the
       
  6464 current process; this is assumed to be an 8-bit descriptor.
       
  6465 
       
  6466 Environment data may be stored in the process and is passed to a child process
       
  6467 on creation of that child process.
       
  6468 
       
  6469 On successful return from this function, the data item is deleted from
       
  6470 the process. 
       
  6471 
       
  6472 @param aSlot An index that identifies the data item.
       
  6473              This is an index whose value is relative to zero;
       
  6474              i.e. 0 is the first item/slot.
       
  6475              This can range from 0 to 15, i.e. there are 16 slots. 
       
  6476 
       
  6477 @param aDes  On sucessful return, contains the environment data item; the
       
  6478              length of the descriptor is set to the length of the data item.
       
  6479 
       
  6480 @return KErrNone, if successful;
       
  6481         KErrNotFound, if there is no data; 
       
  6482         KErrArgument, if the data is not binary data, or the data item in the
       
  6483                       process is longer than the maximum length of aDes.
       
  6484                       
       
  6485 @panic KERN-EXEC 51, if aSlot is negative or is greater than or equal to 16.                                   
       
  6486 */
       
  6487 	{
       
  6488 	TInt ret = Exec::ProcessGetDataParameter(aSlot, (TUint8*)aDes.Ptr(), aDes.MaxLength());
       
  6489 	if (ret < 0)
       
  6490 		return ret;
       
  6491 	aDes.SetLength(ret);
       
  6492 	return KErrNone;
       
  6493 	}
       
  6494 
       
  6495 
       
  6496 
       
  6497 
       
  6498 EXPORT_C TInt User::GetDesParameter(TInt aSlot, TDes16& aDes)
       
  6499 /**
       
  6500 Gets the specified environment data item belonging to the
       
  6501 current process; this is assumed to be an 16-bit descriptor.
       
  6502 
       
  6503 Environment data may be stored in the process and is passed to a child process
       
  6504 on creation of that child process.
       
  6505 
       
  6506 On successful return from this function, the data item is deleted from
       
  6507 the process. 
       
  6508 
       
  6509 @param aSlot An index that identifies the data item.
       
  6510              This is an index whose value is relative to zero;
       
  6511              i.e. 0 is the first item/slot.
       
  6512              This can range from 0 to 15, i.e. there are 16 slots. 
       
  6513 
       
  6514 @param aDes  On sucessful return, contains the environment data item; the
       
  6515              length of the descriptor is set to the length of the data item.
       
  6516 
       
  6517 @return KErrNone, if successful;
       
  6518         KErrNotFound, if there is no data; 
       
  6519         KErrArgument, if the data is not binary data, or the data item in the
       
  6520                       process is longer than the maximum length of aDes.
       
  6521                       
       
  6522 @panic KERN-EXEC 51, if aSlot is negative or is greater than or equal to 16.                                   
       
  6523 */
       
  6524 	{
       
  6525 	TInt ret = Exec::ProcessGetDataParameter(aSlot, (TUint8*)aDes.Ptr(), 2*aDes.MaxLength());
       
  6526 	if (ret < 0)
       
  6527 		return ret;
       
  6528 	aDes.SetLength(ret/2);
       
  6529 	return KErrNone;
       
  6530 	}
       
  6531 
       
  6532 /**
       
  6533 Gets the linear address of the exception descriptor for the code module in which
       
  6534 a specified code address resides.
       
  6535 
       
  6536 @param	aCodeAddress The code address in question.
       
  6537 @return	The address of the exception descriptor, or zero if there is none.
       
  6538 
       
  6539 */
       
  6540 EXPORT_C TLinAddr UserSvr::ExceptionDescriptor(TLinAddr aCodeAddress)
       
  6541 	{
       
  6542 	return Exec::ExceptionDescriptor(aCodeAddress);
       
  6543 	}
       
  6544 
       
  6545 EXPORT_C TInt User::SetFloatingPointMode(TFloatingPointMode aMode, TFloatingPointRoundingMode aRoundingMode)
       
  6546 /**
       
  6547 Sets the hardware floating point mode for the current thread. This does not affect
       
  6548 software floating point calculations. The rounding mode can also be set. New threads created
       
  6549 by this thread will inherit the mode, thus to set the mode for a whole process, call this
       
  6550 method before you create any new threads.
       
  6551 
       
  6552 @param aMode         The floating point calculation mode to use.
       
  6553 @param aRoundingMode The floating point rounding mode to use, defaults to nearest.
       
  6554 
       
  6555 @return KErrNone if successful, KErrNotSupported if the hardware does not support the
       
  6556         chosen mode, or there is no floating point hardware present.
       
  6557 
       
  6558 @see TFloatingPointMode
       
  6559 @see TFloatingPointRoundingMode
       
  6560 */
       
  6561 	{
       
  6562 	return(Exec::SetFloatingPointMode(aMode, aRoundingMode));
       
  6563 	}
       
  6564 
       
  6565 
       
  6566 EXPORT_C TUint32 E32Loader::PagingPolicy()
       
  6567 /**
       
  6568 	Accessor function returns the code paging policy, as defined at ROM build time.
       
  6569 
       
  6570 	@return					Paging policy only.  This function applies
       
  6571 							EKernelConfigPagingPolicyMask to the config flags
       
  6572 							before returning the value.
       
  6573  */
       
  6574 	{
       
  6575 	return Exec::KernelConfigFlags() & EKernelConfigPagingPolicyMask;
       
  6576 	}
       
  6577 
       
  6578 
       
  6579 /** Queue a notifier to detect system idle
       
  6580 
       
  6581 @internalTechnology
       
  6582 @prototype
       
  6583 */
       
  6584 EXPORT_C void User::NotifyOnIdle(TRequestStatus& aStatus)
       
  6585 	{
       
  6586 	aStatus = KRequestPending;
       
  6587 	Exec::NotifyOnIdle(&aStatus);
       
  6588 	}
       
  6589 
       
  6590 
       
  6591 /** Cancel a miscellaneous notification requested by this thread
       
  6592 
       
  6593 Cancels a currently outstanding notification for system idle or object
       
  6594 deletion.
       
  6595 
       
  6596 @internalTechnology
       
  6597 @prototype
       
  6598 */
       
  6599 EXPORT_C void User::CancelMiscNotifier(TRequestStatus& aStatus)
       
  6600 	{
       
  6601 	Exec::CancelMiscNotifier(&aStatus);
       
  6602 	}
       
  6603 
       
  6604 
       
  6605 /** Queue a notifier to detect destruction of this object
       
  6606 
       
  6607 To cancel the notifier, use User::CancelMiscNotifier().
       
  6608 
       
  6609 @internalTechnology
       
  6610 @prototype
       
  6611 */
       
  6612 EXPORT_C void RHandleBase::NotifyDestruction(TRequestStatus& aStatus)
       
  6613 	{
       
  6614 	aStatus = KRequestPending;
       
  6615 	Exec::NotifyObjectDestruction(iHandle, &aStatus);
       
  6616 	}
       
  6617 
       
  6618 #else // __TOOLS2__
       
  6619 
       
  6620 #ifdef _DEBUG
       
  6621 // The following are for simulating heap failure
       
  6622 TInt gAllocCount = 0;
       
  6623 TInt gAllocFailRate = 0;
       
  6624 RAllocator::TAllocFail gAllocFailType = RAllocator::ENone;
       
  6625 #endif
       
  6626 
       
  6627 EXPORT_C void User::__DbgMarkStart(TBool aKernel)
       
  6628 	{
       
  6629 	}
       
  6630 
       
  6631 EXPORT_C TUint32 User::__DbgMarkEnd(TBool aKernel, TInt aCount)
       
  6632 	{
       
  6633 	return 0;
       
  6634 	}
       
  6635 
       
  6636 EXPORT_C void User::__DbgSetAllocFail(TBool aKernel, RAllocator::TAllocFail aFail, TInt aRate)
       
  6637 	{
       
  6638 #ifdef _DEBUG
       
  6639 	gAllocFailType = aFail;
       
  6640 
       
  6641 	switch (gAllocFailType)
       
  6642 		{
       
  6643 		case RAllocator::EFailNext:
       
  6644 			gAllocFailRate = gAllocCount + aRate;
       
  6645 			break;
       
  6646 		case RAllocator::EDeterministic:
       
  6647 			gAllocCount = 0;
       
  6648 			gAllocFailRate = aRate;
       
  6649 			break;
       
  6650 		default:
       
  6651 			break;
       
  6652 		}
       
  6653 #endif
       
  6654 	}
       
  6655 
       
  6656 EXPORT_C void User::__DbgMarkCheck(int, int, int, unsigned char const*, int)
       
  6657 	{
       
  6658 	}
       
  6659 
       
  6660 EXPORT_C void RHandleBase::Close()
       
  6661 	{
       
  6662 	}
       
  6663 
       
  6664 #endif // __TOOLS2__