javacommons/utils/src/applicationinfoservice.cpp
branchRCL_3
changeset 19 04becd199f91
equal deleted inserted replaced
16:f5050f1da672 19:04becd199f91
       
     1 /*
       
     2 * Copyright (c) 2008 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:  ApplicationInfoService provide a storage place for singleton
       
    15 *                instance of ApplicationInfo object.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #include "logger.h"
       
    21 #include "monitor.h"
       
    22 #include "javaoslayer.h"
       
    23 #include "applicationinfo.h"
       
    24 #include "applicationinfosetter.h"
       
    25 #include "exceptionbase.h"
       
    26 
       
    27 
       
    28 // ======== STATIC VARIABLES ========
       
    29 
       
    30 /**
       
    31 * Singleton
       
    32 */
       
    33 
       
    34 //OS_NONSHARABLE_CLASS(AppInfoGlobals)
       
    35 class AppInfoGlobals
       
    36 {
       
    37 public:
       
    38     AppInfoGlobals() : mAppInfo(0)
       
    39     {
       
    40     }
       
    41 
       
    42 public:
       
    43     const java::runtime::ApplicationInfo* mAppInfo;
       
    44 };
       
    45 
       
    46 
       
    47 #if defined(__WINSCW__)
       
    48 
       
    49 #include <pls.h>
       
    50 AppInfoGlobals* getAppInfoGlobals()
       
    51 {
       
    52     // Access the PLS of this process
       
    53     AppInfoGlobals* globals  =
       
    54         Pls<AppInfoGlobals>(TUid::Uid(0x200211DE));
       
    55     return globals;
       
    56 }
       
    57 
       
    58 #else
       
    59 
       
    60 static AppInfoGlobals* sGlobals = 0;
       
    61 
       
    62 AppInfoGlobals* getAppInfoGlobals()
       
    63 {
       
    64     if (sGlobals == 0)
       
    65     {
       
    66         sGlobals = new AppInfoGlobals();
       
    67     }
       
    68     return sGlobals;
       
    69 }
       
    70 #endif
       
    71 
       
    72 OS_EXPORT java::runtime::ApplicationInfo::ApplicationInfo()
       
    73 {
       
    74 }
       
    75 
       
    76 OS_EXPORT java::runtime::ApplicationInfo::~ApplicationInfo()
       
    77 {
       
    78 }
       
    79 
       
    80 OS_EXPORT void java::util::setApplicationInfoProvider(const java::runtime::ApplicationInfo& appInfo)
       
    81 {
       
    82     AppInfoGlobals* globals = getAppInfoGlobals();
       
    83     if (globals->mAppInfo != 0)
       
    84     {
       
    85         delete globals->mAppInfo;
       
    86     }
       
    87     globals->mAppInfo = &appInfo;
       
    88 }
       
    89 
       
    90 OS_EXPORT const java::runtime::ApplicationInfo& java::runtime::ApplicationInfo::getInstance()
       
    91 {
       
    92     AppInfoGlobals* globals = getAppInfoGlobals();
       
    93     if (globals->mAppInfo == 0)
       
    94     {
       
    95         {
       
    96             std::string errorStr = "ApplicationInfo service provider not available";
       
    97             throw java::util::ExceptionBase(errorStr, __FILE__, __FUNCTION__, __LINE__);
       
    98         }
       
    99     }
       
   100     return *globals->mAppInfo;
       
   101 }