javauis/coreui/inc/javacoreui.h
changeset 21 2a9601315dfc
child 67 63b81d807542
equal deleted inserted replaced
18:e8e63152f320 21:2a9601315dfc
       
     1 /*
       
     2 * Copyright (c) 2009 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: Interface for creating and destroying the Core UI
       
    15 *
       
    16 */
       
    17 
       
    18 #ifndef JAVACOREUI_H
       
    19 #define JAVACOREUI_H
       
    20 
       
    21 #include <memory>
       
    22 
       
    23 #include "dynamiclibloader.h"
       
    24 #include "javauid.h"
       
    25 #include "javacoreuiparams.h"
       
    26 
       
    27 namespace java // codescanner::namespace
       
    28 {
       
    29 namespace ui // codescanner::namespace
       
    30 {
       
    31 
       
    32 class CoreUi;
       
    33 
       
    34 typedef CoreUi& (*GetUiInstance)();
       
    35 typedef void (*ReleaseUi)();
       
    36 
       
    37 /**
       
    38  *  CoreUi offers a static method for getting an object
       
    39  *  implementing
       
    40  *  the interface and loading the shared library containing the actual
       
    41  *  implementation. The interface itself offers a way control the lifetime
       
    42  *  of the UI.
       
    43  */
       
    44 
       
    45 class CoreUi
       
    46 {
       
    47 public:
       
    48 
       
    49     /**
       
    50     * This method will ask the UI to start the main loop
       
    51     * @param appUid The Uid of the application.
       
    52     * @param uiParams Ui configuration parameters. If it
       
    53     *        is null, the default arguments will be used.
       
    54     * @throws java::util::ExceptionBase or std::exception in error cases.
       
    55     */
       
    56     virtual void start(const java::util::Uid& appUid,
       
    57                        CoreUiParams* uiParams = 0) = 0;
       
    58 
       
    59     //Destructor
       
    60     virtual ~CoreUi();
       
    61 
       
    62     /**
       
    63     * This inline method will load the shared library of the core UI.
       
    64     *
       
    65     * It is important that the user of this method is aware that the
       
    66     * implementation is available ONLY when the instance of
       
    67     * DynamicLibLoader is not deleted. When the user is absolutely sure
       
    68     * that no code is run from the loaded shared library, user should delete
       
    69     * the instance of DynamicLibLoader. The deletion will lead to
       
    70     * unloading the shared library.
       
    71     *
       
    72     * @param[out] loader User must store this argument as long as it needs
       
    73     *                    to run any code in the shared library. No other
       
    74                          APIs of the loader is needed to use.
       
    75     * @return A reference to instance implementing CoreUi in
       
    76     * success case.
       
    77     * @throws java::util::ExceptionBase or std::exception in error cases.
       
    78     */
       
    79     static CoreUi&
       
    80     getUiInstance(std::auto_ptr<java::util::DynamicLibLoader>& loader);
       
    81 
       
    82     /**
       
    83     * This inline method will close the core UI unless already closed and
       
    84     * clean resources.
       
    85     *
       
    86     * @param[in] loader A loeader that was used to load the dll.
       
    87     * @throws java::util::ExceptionBase or std::exception in error cases.
       
    88     */
       
    89     static void releaseUi(const std::auto_ptr<java::util::DynamicLibLoader>& loader);
       
    90 };
       
    91 
       
    92 #if defined RD_JAVA_UI_QT
       
    93 // This is an empty CoreUi impl for Java 3.0
       
    94 class CoreUiStub : public CoreUi
       
    95 {
       
    96 public:
       
    97     CoreUiStub() {}
       
    98     virtual ~CoreUiStub() {}
       
    99     virtual void init(const java::util::Uid& /*midletUid*/,
       
   100                       CoreUiParams* /*uiParams*/) {}
       
   101 
       
   102     virtual void start(const java::util::Uid& appUid,
       
   103                        CoreUiParams* uiParams = 0) {}
       
   104 };
       
   105 #endif // RD_JAVA_UI_QT
       
   106 
       
   107 } //end namespace ui
       
   108 } //end namespace java
       
   109 
       
   110 
       
   111 //START OF INLINE METHODS
       
   112 inline java::ui::CoreUi::~CoreUi() {}
       
   113 
       
   114 inline java::ui::CoreUi& java::ui::CoreUi::getUiInstance
       
   115 (std::auto_ptr<java::util::DynamicLibLoader>& loader)
       
   116 {
       
   117 #if defined RD_JAVA_UI_QT
       
   118 
       
   119     // The stub impl leaks memory, but is ok, since this
       
   120     // is not in use in MCL, but is for future development
       
   121     // enabler.
       
   122     CoreUiStub* stub = new CoreUiStub();
       
   123     return *stub;
       
   124 
       
   125 #else // RD_JAVA_UI_QT
       
   126 
       
   127     if (loader.get() == 0)
       
   128     {
       
   129         //Create an instance of DynamicLibLoader.
       
   130         loader.reset(new java::util::DynamicLibLoader("javacoreui"));
       
   131     }
       
   132 
       
   133     //Load the javaui and locates method getUiInstance. If getFunction
       
   134     //succeeds were are certain that createUiFunc points to valid method.
       
   135     GetUiInstance getUiInstance =
       
   136         reinterpret_cast<GetUiInstance>(loader->getFunction("getUiInstance",
       
   137                                         true));
       
   138 
       
   139     //Call the method which will create the UI.
       
   140     return getUiInstance();
       
   141 
       
   142 #endif // RD_JAVA_UI_QT
       
   143 }
       
   144 
       
   145 inline void java::ui::CoreUi::releaseUi(
       
   146     const  std::auto_ptr<java::util::DynamicLibLoader>& loader)
       
   147 {
       
   148 #ifndef RD_JAVA_UI_QT
       
   149     //Load the javaui and locates method getUiInstance. If getFunction
       
   150     //succeeds were are certain that createUiFunc points to valid method.
       
   151     ReleaseUi releaseUi =
       
   152         reinterpret_cast<ReleaseUi>(loader->getFunction("releaseUi", true));
       
   153 
       
   154     //Call the method which will release UI resources.
       
   155     releaseUi();
       
   156 
       
   157 #else // RD_JAVA_UI_QT
       
   158 
       
   159     return;
       
   160 
       
   161 #endif // RD_JAVA_UI_QT
       
   162 }
       
   163 
       
   164 #endif // JAVACOREUI_H