javacommons/utils/inc.s60/javasymbianoslayer.h
branchRCL_3
changeset 14 04becd199f91
equal deleted inserted replaced
13:f5050f1da672 14:04becd199f91
       
     1 /*
       
     2 * Copyright (c) 2007-2007 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef JAVASYMBIANOSLAYER_H
       
    20 #define JAVASYMBIANOSLAYER_H
       
    21 
       
    22 #include <e32base.h>
       
    23 #include <appversion.h>
       
    24 
       
    25 #include "javaosheaders.h"
       
    26 #include "javauid.h"
       
    27 
       
    28 typedef void*(* FuncPtr)();
       
    29 
       
    30 typedef FuncPtr(*LookupFunc)(const char* methodname);
       
    31 
       
    32 struct FuncTable
       
    33 {
       
    34     const char*    mFuncName;
       
    35     unsigned int   mFuncAddr;
       
    36 };
       
    37 
       
    38 OS_IMPORT FuncPtr findMethod(const char* funcName, const FuncTable funcTable[],
       
    39                              int tableSize);
       
    40 
       
    41 OS_IMPORT HBufC* stringToDes(const char* str);
       
    42 
       
    43 OS_IMPORT wchar_t* desToWstring(TPtr16& aDes);
       
    44 
       
    45 /**
       
    46  * This method is supported only in S60 environment.
       
    47  * Converts integer to Uid object.
       
    48  * @param aId Id to be converted.
       
    49  * @param aOutUid Output parameter.
       
    50  * @return filled Uid object. Return object is equal with "aOutUid" parameter.
       
    51  *         Id is converted to hexadecimal format. Length of the number is always
       
    52  *         8 digits. See examples:
       
    53  *          1234        =>  [00001234]
       
    54  *          0x123456ab  =>  [123456ab]
       
    55  *          1289        =>  [00000509]
       
    56  */
       
    57 OS_IMPORT java::util::Uid& TUidToUid(const TUid& aId,java::util::Uid& aOutUid);
       
    58 
       
    59 /**
       
    60  * This method is supported only in S60 environment.
       
    61  * Converts Uid class to int. Supported formats:
       
    62  * [123456ab]
       
    63  * 0x123456ab
       
    64  * 123456ab
       
    65  * This operation strips following characters from the beginning and end of the string:
       
    66  * " ", "\n" and "\t".
       
    67  * @param aUid Length of the actual number is assumed to be 8 digit.
       
    68  * @param aOutId Output parameter. Uid object converted to int.
       
    69  * @return KErrNone is conversion was done successfully.
       
    70  *         KErrArgument if conversion failed for following errors:
       
    71  *         - Length of the number is not 8 digits after stripping and removing angle brackets.
       
    72  *         - Conversion from wstring to TUint fails.
       
    73  *         - Converted number is bigger than 0xEFFFFFFF or less than 0.
       
    74  */
       
    75 OS_IMPORT TInt uidToTUid(const java::util::Uid& aUid,TUid& aOutId);
       
    76 
       
    77 /**
       
    78  * Convert wide string AppVersion representation to TAppVersion.
       
    79  *
       
    80  * @param aString uid as wide string.
       
    81  * @return TAppVersion.
       
    82  */
       
    83 OS_IMPORT TAppVersion wstringToAppVersion(const std::wstring& aVersionString);
       
    84 
       
    85 /**
       
    86  * Convert wide string to HBufC. Ownership is moved to caller.
       
    87  *
       
    88  * @param aString wide string.
       
    89  * @return wide string as HBufC.
       
    90  */
       
    91 OS_IMPORT HBufC* wstringToBuf(const std::wstring& aString);
       
    92 
       
    93 template <class T>
       
    94 class CleanupResetAndDestroy
       
    95 {
       
    96 public:
       
    97     inline static void PushL(T& aRef);
       
    98 private:
       
    99     static void ResetAndDestroy(TAny *aPtr);
       
   100 };
       
   101 template <class T>
       
   102 inline void CleanupResetAndDestroyPushL(T& aRef);
       
   103 
       
   104 template <class T>
       
   105 inline void CleanupResetAndDestroy<T>::PushL(T& aRef)
       
   106 {
       
   107     CleanupStack::PushL(TCleanupItem(&ResetAndDestroy,&aRef));
       
   108 }
       
   109 template <class T>
       
   110 void CleanupResetAndDestroy<T>::ResetAndDestroy(TAny *aPtr)
       
   111 {
       
   112     (STATIC_CAST(T*,aPtr))->ResetAndDestroy();
       
   113 }
       
   114 template <class T>
       
   115 inline void CleanupResetAndDestroyPushL(T& aRef)
       
   116 {
       
   117     CleanupResetAndDestroy<T>::PushL(aRef);
       
   118 }
       
   119 
       
   120 
       
   121 #endif // JAVASYMBIANOSLAYER_H