javauis/coreui/inc/javacoreui.h
changeset 76 4ad59aaee882
parent 21 2a9601315dfc
child 83 26b2b12093af
equal deleted inserted replaced
69:773449708c84 76:4ad59aaee882
     1 /*
     1 /*
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    18 #ifndef JAVACOREUI_H
    18 #ifndef JAVACOREUI_H
    19 #define JAVACOREUI_H
    19 #define JAVACOREUI_H
    20 
    20 
    21 #include <memory>
    21 #include <memory>
    22 
    22 
       
    23 #include "libraryloaderexception.h"
    23 #include "dynamiclibloader.h"
    24 #include "dynamiclibloader.h"
    24 #include "javauid.h"
    25 #include "javauid.h"
    25 #include "javacoreuiparams.h"
    26 #include "javacoreuiparams.h"
       
    27 #include "logger.h"
    26 
    28 
    27 namespace java // codescanner::namespace
    29 namespace java // codescanner::namespace
    28 {
    30 {
    29 namespace ui // codescanner::namespace
    31 namespace ui // codescanner::namespace
    30 {
    32 {
    70     * unloading the shared library.
    72     * unloading the shared library.
    71     *
    73     *
    72     * @param[out] loader User must store this argument as long as it needs
    74     * @param[out] loader User must store this argument as long as it needs
    73     *                    to run any code in the shared library. No other
    75     *                    to run any code in the shared library. No other
    74                          APIs of the loader is needed to use.
    76                          APIs of the loader is needed to use.
    75     * @return A reference to instance implementing CoreUi in
    77     * @return true if the dll could be loaded and the start method was
       
    78     *         succesfully called.
    76     * success case.
    79     * success case.
    77     * @throws java::util::ExceptionBase or std::exception in error cases.
    80     * @throws java::util::ExceptionBase or std::exception in error cases.
    78     */
    81     */
    79     static CoreUi&
    82     static bool start(std::auto_ptr<java::util::DynamicLibLoader>& loader,
    80     getUiInstance(std::auto_ptr<java::util::DynamicLibLoader>& loader);
    83                       const java::util::Uid& appUid,
       
    84                       CoreUiParams* uiParams = 0);
    81 
    85 
    82     /**
    86     /**
    83     * This inline method will close the core UI unless already closed and
    87     * This inline method will close the core UI unless already closed and
    84     * clean resources.
    88     * clean resources.
    85     *
    89     *
    86     * @param[in] loader A loeader that was used to load the dll.
    90     * @param[in] loader A loeader that was used to load the dll.
       
    91     * @return true if the dll could be loaded and the release method was
       
    92     *         succesfully called.
    87     * @throws java::util::ExceptionBase or std::exception in error cases.
    93     * @throws java::util::ExceptionBase or std::exception in error cases.
    88     */
    94     */
    89     static void releaseUi(const std::auto_ptr<java::util::DynamicLibLoader>& loader);
    95     static bool releaseUi(std::auto_ptr<java::util::DynamicLibLoader>& loader);
    90 };
    96 };
    91 
    97 
    92 #if defined RD_JAVA_UI_QT
    98 } // end namespace ui
    93 // This is an empty CoreUi impl for Java 3.0
    99 } // end namespace java
    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 
   100 
   110 
   101 
   111 //START OF INLINE METHODS
   102 const char* const COREUI_LIB_NAME = "javacoreui";
       
   103 // START OF INLINE METHODS
   112 inline java::ui::CoreUi::~CoreUi() {}
   104 inline java::ui::CoreUi::~CoreUi() {}
   113 
   105 
   114 inline java::ui::CoreUi& java::ui::CoreUi::getUiInstance
   106 inline bool java::ui::CoreUi::start(
   115 (std::auto_ptr<java::util::DynamicLibLoader>& loader)
   107     std::auto_ptr<java::util::DynamicLibLoader>& loader,
       
   108     const java::util::Uid& appUid,
       
   109     CoreUiParams* uiParams)
   116 {
   110 {
   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)
   111     if (loader.get() == 0)
   128     {
   112     {
   129         //Create an instance of DynamicLibLoader.
   113         // Create an instance of DynamicLibLoader.
   130         loader.reset(new java::util::DynamicLibLoader("javacoreui"));
   114         loader.reset(new java::util::DynamicLibLoader(COREUI_LIB_NAME));
   131     }
   115     }
   132 
   116 
   133     //Load the javaui and locates method getUiInstance. If getFunction
   117     try
   134     //succeeds were are certain that createUiFunc points to valid method.
   118     {
   135     GetUiInstance getUiInstance =
   119         // Load the javaui and locates method getUiInstance. If getFunction
   136         reinterpret_cast<GetUiInstance>(loader->getFunction("getUiInstance",
   120         // succeeds were are certain that createUiFunc points to valid method.
   137                                         true));
   121         GetUiInstance getUiInstance =
   138 
   122             reinterpret_cast<GetUiInstance>(loader->getFunction("getUiInstance",
   139     //Call the method which will create the UI.
   123                                             true));
   140     return getUiInstance();
   124         // Call the method which will create the UI.
   141 
   125         getUiInstance().start(appUid, uiParams);
   142 #endif // RD_JAVA_UI_QT
   126         return true;
       
   127     }
       
   128     catch (java::util::LibraryLoaderException& ex)
       
   129     {
       
   130         loader.reset();
       
   131         LOG1(EJavaUI, EInfo, "No coreUi available (start): %s", ex.toString().c_str());
       
   132     }
       
   133     return false;
   143 }
   134 }
   144 
   135 
   145 inline void java::ui::CoreUi::releaseUi(
   136 inline bool java::ui::CoreUi::releaseUi(
   146     const  std::auto_ptr<java::util::DynamicLibLoader>& loader)
   137     std::auto_ptr<java::util::DynamicLibLoader>& loader)
   147 {
   138 {
   148 #ifndef RD_JAVA_UI_QT
   139     if (loader.get() == 0)
   149     //Load the javaui and locates method getUiInstance. If getFunction
   140     {
   150     //succeeds were are certain that createUiFunc points to valid method.
   141         // Create an instance of DynamicLibLoader.
   151     ReleaseUi releaseUi =
   142         loader.reset(new java::util::DynamicLibLoader(COREUI_LIB_NAME));
   152         reinterpret_cast<ReleaseUi>(loader->getFunction("releaseUi", true));
   143     }
       
   144     try
       
   145     {
       
   146         ReleaseUi releaseUi =
       
   147             reinterpret_cast<ReleaseUi>(loader->getFunction("releaseUi", true));
   153 
   148 
   154     //Call the method which will release UI resources.
   149         // Call the method which will release UI resources.
   155     releaseUi();
   150         releaseUi();
   156 
   151         return true;
   157 #else // RD_JAVA_UI_QT
   152     }
   158 
   153     catch (java::util::LibraryLoaderException& ex)
   159     return;
   154     {
   160 
   155         loader.reset();
   161 #endif // RD_JAVA_UI_QT
   156         LOG1(EJavaUI, EInfo, "No coreUi available (release): %s", ex.toString().c_str());
       
   157     }
       
   158     return false;
   162 }
   159 }
   163 
   160 
   164 #endif // JAVACOREUI_H
   161 #endif // JAVACOREUI_H