javacommons/utils/inc/javaoslayer.h
branchRCL_3
changeset 19 04becd199f91
child 35 85266cc22c7f
equal deleted inserted replaced
16:f5050f1da672 19: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 JAVAOSLAYER_H
       
    20 #define JAVAOSLAYER_H
       
    21 
       
    22 #include <string>
       
    23 #include <list>
       
    24 #include <vector>
       
    25 #include "javaosheaders.h"
       
    26 
       
    27 namespace java
       
    28 {
       
    29 namespace util
       
    30 {
       
    31 
       
    32 // Runtime specific bootclasspath identifier.
       
    33 const int BOOT_CLASSPATH_MIDP = 1;
       
    34 const int BOOT_CLASSPATH_INSTALLER = 2;
       
    35 const int BOOT_CLASSPATH_TCKRUNNER = 3;
       
    36 
       
    37 class DriveId;
       
    38 
       
    39 class JavaOsLayer
       
    40 {
       
    41 public:
       
    42     OS_IMPORT static
       
    43     void getOsSpecificLibName(std::string& result, const char* libName);
       
    44 
       
    45     OS_IMPORT static void getOsSpecificJavaRootPath(std::string& path);
       
    46 
       
    47     /**
       
    48     * Utility method for getting the root of OMJ binaries. By default the
       
    49     * method will set the path without drive letter (in file systems that
       
    50     * uses drive letters). The utility will append the leading slash to the
       
    51     * path(e.g. the result could be "\sys\bin\" not "\sys\bin").
       
    52     * If the append flag is set, then it is assumed that provided argument
       
    53     * 'path' includes the drive letter and the implentation will append ':'
       
    54     * and the valid path.
       
    55     * The utility will return a refrence to the path given as argument just
       
    56     * for helping e.g. concatenation.
       
    57     * <p>
       
    58     * Example in S60:
       
    59     *   std::string path;
       
    60     *   getBinRoot(path); //This will set path to contain "\sys\bin"
       
    61     *   std::string path = 'C';
       
    62     *   getBinRoot(path, true); //This will set path to contain "C:\sys\bin"
       
    63     *
       
    64     * @param[in/out] path Utility will either set or prepend the binary root
       
    65     *                depending on the value of argument 'append'
       
    66     * @param[in/out] append Whether to append the result into the argument
       
    67     *                'path' or override the content. Look the description
       
    68     *                above for further instructions.
       
    69     * @return Reference to argument 'path'.
       
    70     */
       
    71     OS_IMPORT static std::string& getBinRoot(std::string& path, bool append = false);
       
    72 
       
    73     /**
       
    74     * Utility method for getting the root of OMJ resources. The behavior of this
       
    75     * method is very similar to getBinRoot, so look for further information from
       
    76     * the description of the JavaOsLayer::getBinRoot()
       
    77     *
       
    78     * @param[in/out] path Utility will either set or prepend the resource root
       
    79     *                depending on the value of argument 'append'
       
    80     * @param[in/out] append Whether to append the result into the argument
       
    81     *                'path' or override the content. Look the description
       
    82     *                of JavaOsLayer::getBinRoot() for further instructions.
       
    83     * @return Reference to argument 'path'.
       
    84     */
       
    85     OS_IMPORT static std::string& getResRoot(std::string& path, bool append = false);
       
    86 
       
    87     /**
       
    88     * Utility method for getting the root of Midp work directory. The behavior of
       
    89     * thismethod is very similar to getBinRoot, so look for further information
       
    90     * from the description of the JavaOsLayer::getBinRoot()
       
    91     *
       
    92     * @param[in/out] path Utility will either set or prepend the Midp work
       
    93                           directory root depending on the value of argument
       
    94                           'append'
       
    95     * @param[in/out] append Whether to append the result into the argument
       
    96     *                       'path' or override the content. Look the
       
    97                              description of JavaOsLayer::getBinRoot() for
       
    98     *                        further instructions.
       
    99     * @return Reference to argument 'path'.
       
   100     */
       
   101     OS_IMPORT static std::string& getMidpRoot(std::string& path, bool append = false);
       
   102 
       
   103     /**
       
   104     * Utility method for getting the root of Java Captain's work directory.
       
   105     * The behavior of this method is very similar to getBinRoot, so look for
       
   106     * further information from the description of the JavaOsLayer::getBinRoot()
       
   107     *
       
   108     * @param[in/out] path Utility will either set or prepend the Java Captain's
       
   109     *                     work directory root depending on the value of argument
       
   110                           'append'
       
   111     * @param[in/out] append Whether to append the result into the argument
       
   112     *                       'path' or override the content. Look the
       
   113                             description of JavaOsLayer::getBinRoot() for
       
   114     *                       further instructions.
       
   115     * @return Reference to argument 'path'.
       
   116     */
       
   117     OS_IMPORT static std::string& getJavaCaptainRoot(std::string& path, bool append = false);
       
   118 
       
   119     /**
       
   120     * Utility method for getting the drive where the MIDP is installed in
       
   121     * systems supporting drive letters.
       
   122     * @return Instance of class DriveLetter conatining the drive letter as char and
       
   123     *         as integer. For further information see DriveLetter class description.
       
   124     */
       
   125     OS_IMPORT static DriveId  getMidpDrive();
       
   126     OS_IMPORT static void*    dlopen(const char* file);
       
   127     OS_IMPORT static void*    dlsym(void* handle, const char* name, bool containsByteCode = false);
       
   128     OS_IMPORT static int      dlclose(void* handle);
       
   129 
       
   130     /**
       
   131      * Utility method for tracing the startup time.
       
   132      * @param[in] header The header of the trace.
       
   133      * @param[in] freeMem The amount of free memory of the Java heap. Set to -1
       
   134      *                    if unknown.
       
   135      * @param[in] totalMem The size of the Java heap. Set to -1 if unknown.
       
   136      */
       
   137     OS_IMPORT static void startUpTrace(const std::string& header,
       
   138                                        int freeMem, int totalMem);
       
   139 
       
   140     /**
       
   141      * Populate bootclasspath ODC package names. If not found or error
       
   142      * it is left empty.
       
   143      *
       
   144      * @param[out] odcFiles   list of ODC files for bootclasspath.
       
   145      * @param[out] bcpEntites list of other bootclasspath enties than ODC
       
   146                               files e.g jar files.
       
   147      * @param[in] type bootclasspath type. If not in valid range midp
       
   148      *                 bootclasspath is set.
       
   149      */
       
   150     OS_IMPORT static void bootClassPath(std::list<std::wstring>& odcFiles,
       
   151                                         std::list<std::wstring>& bcpEntites,
       
   152                                         const int type);
       
   153 
       
   154 
       
   155 private: //Methods
       
   156     JavaOsLayer();                                //No default constructor allowed
       
   157     JavaOsLayer(const JavaOsLayer&);              //No copy constructor allowed
       
   158     JavaOsLayer& operator= (const JavaOsLayer&);  //No Assignment operator allowed
       
   159 
       
   160     /**
       
   161      * List directory entries.
       
   162      *
       
   163      * @param[in] dirPath direcotry path.
       
   164      * @param[out] entries directory entries.
       
   165      */
       
   166     static void listDirectory(std::string& dirPath, std::vector<std::string>& entries);
       
   167 
       
   168     /**
       
   169      * List odc file contents.
       
   170      *
       
   171      * @param[in] filePath path to file.
       
   172      * @param[out] entries odc file entries.
       
   173      */
       
   174     static void listOdcFile(std::string& filePath, std::vector<std::string>& entries);
       
   175 
       
   176     /**
       
   177      * Populate Classpath entries from given vector. This separetes ODC files from other
       
   178      * classpath entries and add full path of the items. Vector contains only file names
       
   179      * and postfixes i.e. myfile.odc or mygreat.jar.
       
   180      *
       
   181      * @param[in] pathPrefix Path prefix used to created full path.
       
   182      * @param[in] entries Class path entries.
       
   183      * @param[out] odcFiles All odc files from entries.
       
   184      * @param[out] bcpEntites All other entities.
       
   185      */
       
   186     static void populateCPEntries(const std::string& pathPrefix,
       
   187                                   const std::vector<std::string>& entries,
       
   188                                   std::list<std::wstring>& odcFiles,
       
   189                                   std::list<std::wstring>& bcpEntites);
       
   190 
       
   191     /**
       
   192      * Check all rom entries and if they are not matching to iad entries
       
   193      * adds them to deltaEntries.
       
   194      *
       
   195      * @param romEntries[in] ROM classpath entries.
       
   196      * @param iadEntries[in] IAD classpath entries.
       
   197      * @param deltaEntries[out] all ROM entries not deployed with IAD package.
       
   198      */
       
   199     static void deltaCPEntries(const std::vector<std::string>& romEntries,
       
   200                                const std::vector<std::string>& iadEntries,
       
   201                                std::vector<std::string>& deltaEntries);
       
   202 
       
   203 };
       
   204 
       
   205 /**
       
   206  * A class for storing both drive letter as char and as integer.
       
   207  * The integer value 0 means dirve letter A, 1 means drive letter B etc.
       
   208  */
       
   209 class DriveId
       
   210 {
       
   211 public:
       
   212 
       
   213     /**
       
   214      * The constructor that sets the object with default values. Useful for
       
   215      * platforms that don't have drive letter concept.
       
   216      */
       
   217     DriveId() : mLetter(0), mIndex(-1)
       
   218     {
       
   219         //Set the drive letter to be empty;
       
   220         mLetter = new char[1];
       
   221         mLetter[0]=0;
       
   222     }
       
   223 
       
   224     /**
       
   225      * The constructor with specified arguments.
       
   226      * @param[in] driveLetter Drive letter as char*. This can't be const, since
       
   227                   it will be deleted in the destructor;
       
   228      * @param[in] driveIndex  Drive letter as integer. 0='A', 1='B'...25='Z'
       
   229      */
       
   230     DriveId(char* driveLetter, int driveIndex) : mLetter(driveLetter),
       
   231             mIndex(driveIndex) {}
       
   232 
       
   233 
       
   234     /**
       
   235      * The destructor.
       
   236      */
       
   237     ~DriveId()
       
   238     {
       
   239         delete[] mLetter;
       
   240     }
       
   241     /**
       
   242      * Getter for the drive letter.
       
   243      * @return drive letter as char. The charcter case is unspecified. If
       
   244      *         some error has happened when solving the drive letter, the
       
   245      *         content is empty ''.
       
   246      */
       
   247     inline const char* getDriveLetter() const
       
   248     {
       
   249         return mLetter;
       
   250     }
       
   251 
       
   252     /**
       
   253      * Getter for the drive letter index.
       
   254      * @return drive letter index. If some error has happened when solving
       
   255      *         the drive letter or the system doesn't support drive letters
       
   256      *         -1 is returned.
       
   257      */
       
   258     inline int getDriveIndex() const
       
   259     {
       
   260         return mIndex;
       
   261     }
       
   262 
       
   263 private:
       
   264     char*   mLetter;
       
   265     int     mIndex;
       
   266 };
       
   267 
       
   268 
       
   269 } //end namespace util
       
   270 } //end namespace java
       
   271 
       
   272 #endif // JAVAOSLAYER_H