javauis/m2g_akn/src/jni/M2GManager.cpp
branchRCL_3
changeset 19 04becd199f91
equal deleted inserted replaced
16:f5050f1da672 19:04becd199f91
       
     1 /*
       
     2 * Copyright (c) 2005-2006 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:  JNI methods
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include "CM2GEventSource.h"
       
    20 #include "com_nokia_microedition_m2g_M2GManager.h"
       
    21 #include "CM2GSVGProxy.h"
       
    22 #include "CM2GEventSource.h"
       
    23 #include <swtcliententry.h>
       
    24 
       
    25 M2G_NS_START
       
    26 
       
    27 // EXTERNAL DATA STRUCTURES
       
    28 
       
    29 // EXTERNAL FUNCTION PROTOTYPES
       
    30 
       
    31 // CONSTANTS
       
    32 
       
    33 // MACROS
       
    34 
       
    35 // LOCAL CONSTANTS AND MACROS
       
    36 
       
    37 // MODULE DATA STRUCTURES
       
    38 
       
    39 // LOCAL FUNCTION PROTOTYPES
       
    40 
       
    41 // FORWARD DECLARATIONS
       
    42 
       
    43 // CLASS DECLARATION
       
    44 
       
    45 // ================================ FUNCTIONS ==================================
       
    46 
       
    47 // -----------------------------------------------------------------------------
       
    48 // Java_com_nokia_microedition_m2g_M2GManager::_createSvgEngine
       
    49 // -----------------------------------------------------------------------------
       
    50 /**
       
    51  * Calls MM2GSVGProxy::CreateSvgEngineL method.
       
    52  * @since Series S60 3.0
       
    53  * @param aProxy Proxy instance.
       
    54  * @param aHandle Svg engine handle
       
    55  */
       
    56 LOCAL_C void DoCreateSvgEngineL(MM2GSVGProxy* aProxy, TInt* aHandle)
       
    57 {
       
    58     aProxy->CreateSvgEngineL(*aHandle);
       
    59 }
       
    60 
       
    61 /**
       
    62  * JNI method
       
    63  */
       
    64 JNIEXPORT jint JNICALL
       
    65 Java_com_nokia_microedition_m2g_M2GManager__1createSvgEngine(
       
    66     JNIEnv* aJni,
       
    67     jclass,
       
    68     jint aEventSourceHandle,
       
    69     jint aSvgProxyHandle,
       
    70     jboolean /*aUiToolkit*/)
       
    71 {
       
    72     M2G_DEBUG_0("M2G_DEBUG: JNI ( M2GManager ) _createSvgEngine - begin");
       
    73     CM2GEventSource* eventSource = JavaUnhand< CM2GEventSource >(aEventSourceHandle);
       
    74     // Execute native engine method
       
    75     TInt handle = M2G_INVALID_HANDLE;
       
    76     if (eventSource && aSvgProxyHandle)
       
    77     {
       
    78         TInt err = eventSource->ExecuteTrap(
       
    79                        &DoCreateSvgEngineL,
       
    80                        JavaUnhand<MM2GSVGProxy>(aSvgProxyHandle),
       
    81                        &handle);
       
    82         handle = M2GGeneral::CheckErrorCodeAndHandle(
       
    83                      aJni, err, handle, M2G_INVALID_HANDLE);
       
    84     }
       
    85     M2G_DEBUG_1("M2G_DEBUG: JNI ( M2GManager ) _createSvgEngine: %d - end", handle);
       
    86     return handle;
       
    87 }
       
    88 
       
    89 // -----------------------------------------------------------------------------
       
    90 // Java_com_nokia_microedition_m2g_M2GManager::_createSvgProxy
       
    91 // -----------------------------------------------------------------------------
       
    92 /**
       
    93  * Creates an svg proxy.
       
    94  * @since Series S60 3.0
       
    95  * @param Svg proxy handle
       
    96  */
       
    97 LOCAL_C void DoCreateSvgProxyL(TInt* aHandle)
       
    98 {
       
    99     MM2GSVGProxy* proxy = CM2GSVGProxy::NewL();
       
   100     *aHandle = JavaMakeHandle(proxy);
       
   101 }
       
   102 
       
   103 /**
       
   104  * JNI method
       
   105  */
       
   106 JNIEXPORT jint JNICALL
       
   107 Java_com_nokia_microedition_m2g_M2GManager__1createSvgProxy(
       
   108     JNIEnv* aJni,
       
   109     jclass,
       
   110     jint aEventSourceHandle,
       
   111     jboolean aUiToolkit)
       
   112 {
       
   113     M2G_DEBUG_0("M2G_DEBUG: JNI ( M2GManager ) _createSvgProxy - begin");
       
   114     TInt handle = M2G_INVALID_HANDLE;
       
   115     TInt    err = KM2GNotOk;
       
   116     if (aUiToolkit)
       
   117     {
       
   118         MSwtClient* client = reinterpret_cast< MSwtClient* >(aEventSourceHandle);
       
   119         if (client)
       
   120         {
       
   121             typedef void (*pDoCreateSvgProxyL)(TInt* aHandle);
       
   122             pDoCreateSvgProxyL lDoCreateSvgProxyL = DoCreateSvgProxyL;
       
   123             TSwtM2gMethodWrapper1<TInt> DoCreateSvgProxy(
       
   124                 lDoCreateSvgProxyL,
       
   125                 &handle
       
   126             );
       
   127             err = client->Execute(DoCreateSvgProxy);
       
   128         }
       
   129     }
       
   130     else
       
   131     {
       
   132         CM2GEventSource* eventSource = JavaUnhand< CM2GEventSource >(aEventSourceHandle);
       
   133 
       
   134         if (eventSource)
       
   135         {
       
   136             err = eventSource->ExecuteTrap(&DoCreateSvgProxyL, &handle);
       
   137 
       
   138         }
       
   139     }
       
   140     handle = M2GGeneral::CheckErrorCodeAndHandle(aJni, err, handle, err);
       
   141     M2G_DEBUG_1("M2G_DEBUG: JNI ( M2GManager ) _createSvgProxy: %d - end", handle);
       
   142     return handle;
       
   143 }
       
   144 
       
   145 // -----------------------------------------------------------------------------
       
   146 // Java_com_nokia_microedition_m2g_M2GManager::_deleteSvgEngine
       
   147 // -----------------------------------------------------------------------------
       
   148 /**
       
   149  * Calls MM2GSVGProxy::DeleteSvgEnginedL method.
       
   150  * @since Series S60 3.0
       
   151  * @param aProxy Proxy instance.
       
   152  */
       
   153 LOCAL_C void DoDeleteSvgEngineL(MM2GSVGProxy* aProxy, TInt aSvgEngineHandle)
       
   154 {
       
   155     aProxy->DeleteSvgEngineL(
       
   156         STATIC_CAST(TM2GSvgEngineHandle, aSvgEngineHandle));
       
   157 }
       
   158 
       
   159 /**
       
   160  * JNI method
       
   161  */
       
   162 JNIEXPORT void JNICALL
       
   163 Java_com_nokia_microedition_m2g_M2GManager__1deleteSvgEngine(
       
   164     JNIEnv* aJni,
       
   165     jclass,
       
   166     jint aEventSourceHandle,
       
   167     jint aSvgProxyHandle,
       
   168     jint aSvgEngineHandle,
       
   169     jboolean /*aUiToolkit*/)
       
   170 {
       
   171     M2G_DEBUG_0("M2G_DEBUG: JNI ( M2GManager ) _deleteSvgEngine - begin");
       
   172     CM2GEventSource* eventSource = JavaUnhand< CM2GEventSource >(aEventSourceHandle);
       
   173     if (eventSource && aSvgProxyHandle && aSvgEngineHandle)
       
   174     {
       
   175         TInt err = eventSource->ExecuteTrap(
       
   176                        &DoDeleteSvgEngineL,
       
   177                        JavaUnhand<MM2GSVGProxy>(aSvgProxyHandle),
       
   178                        aSvgEngineHandle);
       
   179         M2GGeneral::CheckErrorCode(aJni, err);
       
   180     }
       
   181     M2G_DEBUG_0("M2G_DEBUG: JNI ( M2GManager ) _deleteSvgEngine: - end");
       
   182 }
       
   183 
       
   184 // -----------------------------------------------------------------------------
       
   185 // Java_com_nokia_microedition_m2g_M2GManager::_deleteSvgProxy
       
   186 // -----------------------------------------------------------------------------
       
   187 /**
       
   188  * Deletes a proxy object. NOTE: The proxy object has to be deleted inside same
       
   189  * thread as it was created, otherwice there will be problem to delete a CFbsBitmap
       
   190  * server object inside the SVGTopt componenet see KATA-6KYA9T (SVGEngineJI: SVGTopt
       
   191  * crashes when deleting svg document object that contains external resource)
       
   192  * @since Series S60 3.0
       
   193  * @param aProxy Proxy instance.
       
   194  */
       
   195 LOCAL_C void DoDeleteSvgProxyL(MM2GSVGProxy* aProxy)
       
   196 {
       
   197     delete aProxy;
       
   198 }
       
   199 
       
   200 /**
       
   201  * JNI method
       
   202  */
       
   203 JNIEXPORT void JNICALL
       
   204 Java_com_nokia_microedition_m2g_M2GManager__1deleteSvgProxy(
       
   205     JNIEnv* aJni,
       
   206     jclass,
       
   207     jint aEventSourceHandle,
       
   208     jint aSvgProxyHandle,
       
   209     jboolean aUiToolkit)
       
   210 {
       
   211     M2G_DEBUG_0("M2G_DEBUG: JNI ( M2GManager ) _deleteSvgProxy - begin");
       
   212     TInt            err = KM2GNotOk;
       
   213     if (aUiToolkit)
       
   214     {
       
   215         MM2GSVGProxy* proxy = JavaUnhand<MM2GSVGProxy>(aSvgProxyHandle);
       
   216         MSwtClient* client  = reinterpret_cast< MSwtClient* >(aEventSourceHandle);
       
   217         if (client && proxy)
       
   218         {
       
   219             typedef void (*pDoDeleteSvgProxyL)(MM2GSVGProxy* aProxy);
       
   220             pDoDeleteSvgProxyL lDoDeleteSvgProxyL = DoDeleteSvgProxyL;
       
   221             TSwtM2gMethodWrapper1<MM2GSVGProxy> DoDeleteSvgProxy(
       
   222                 lDoDeleteSvgProxyL,
       
   223                 proxy
       
   224             );
       
   225             err = client->Execute(DoDeleteSvgProxy);
       
   226         }
       
   227     }
       
   228     else
       
   229     {
       
   230         MM2GSVGProxy* proxy = JavaUnhand<MM2GSVGProxy>(aSvgProxyHandle);
       
   231         CM2GEventSource* eventSource = JavaUnhand< CM2GEventSource >(aEventSourceHandle);
       
   232         if (eventSource && proxy)
       
   233         {
       
   234             err = eventSource->ExecuteTrap(&DoDeleteSvgProxyL, proxy);
       
   235         }
       
   236     }
       
   237     M2GGeneral::CheckErrorCode(aJni, err);
       
   238     M2G_DEBUG_0("M2G_DEBUG: JNI ( M2GManager ) _deleteSvgProxy: - end");
       
   239 }
       
   240 
       
   241 // -----------------------------------------------------------------------------
       
   242 // Java_com_nokia_microedition_m2g_M2GManager::_finalizeEventSource
       
   243 // -----------------------------------------------------------------------------
       
   244 /**
       
   245  * JNI method
       
   246  */
       
   247 JNIEXPORT void JNICALL
       
   248 Java_com_nokia_microedition_m2g_M2GManager__1finalizeEventSource(
       
   249     JNIEnv *aJni, jclass, jint aEventSourceHandle, jboolean aUiToolkit)
       
   250 {
       
   251     M2G_DEBUG_1("M2G_DEBUG: JNI ( M2GManager ) _finalizeEventSource: %d", aEventSourceHandle);
       
   252     if (aUiToolkit)
       
   253     {
       
   254         MSwtClient* client  = reinterpret_cast< MSwtClient* >(aEventSourceHandle);
       
   255         if (client)
       
   256         {
       
   257             delete client;
       
   258             client = NULL;
       
   259         }
       
   260     }
       
   261     else
       
   262     {
       
   263         CM2GEventSource* eventSource = JavaUnhand< CM2GEventSource >(aEventSourceHandle);
       
   264         if (eventSource)
       
   265         {
       
   266             eventSource->Dispose(*aJni);
       
   267         }
       
   268         eventSource = NULL;
       
   269     }
       
   270 }
       
   271 
       
   272 // -----------------------------------------------------------------------------
       
   273 // Java_com_nokia_microedition_m2g_M2GManager::_initEventSource
       
   274 // -----------------------------------------------------------------------------
       
   275 /**
       
   276  * JNI method
       
   277  */
       
   278 JNIEXPORT jint JNICALL
       
   279 Java_com_nokia_microedition_m2g_M2GManager__1initEventSource(
       
   280     JNIEnv *aJni,
       
   281     jclass aPeer,
       
   282     jint aServer)
       
   283 {
       
   284     M2G_DEBUG_0("M2G_DEBUG: JNI ( M2GManager ) _initEventSource - begin");
       
   285     TRAPD(eventSourceHandle, eventSourceHandle = CM2GEventSource::NewL(
       
   286                 *aJni, aPeer, aServer));
       
   287     M2GGeneral::CheckHandle(aJni, eventSourceHandle);
       
   288     M2G_DEBUG_1("M2G_DEBUG: JNI ( M2GManager ) _initEventSource - end: %d", eventSourceHandle);
       
   289     return eventSourceHandle;
       
   290 }
       
   291 
       
   292 JNIEXPORT jint JNICALL
       
   293 Java_com_nokia_microedition_m2g_M2GManager__1initSwtEventSource(
       
   294     JNIEnv *aJni,
       
   295     jclass /*aPeer*/)
       
   296 {
       
   297     M2G_DEBUG_0("M2G_DEBUG: JNI ( M2GManager ) _initEventSource - begin");
       
   298 
       
   299     MSwtClient* client = NULL;
       
   300     TRAP_IGNORE(client = SWT::CreateClientL());
       
   301     if (!client)
       
   302     {
       
   303         return KErrNotFound;
       
   304     }
       
   305     M2GGeneral::CheckHandle(aJni, (int)client);
       
   306     M2G_DEBUG_1("M2G_DEBUG: JNI ( M2GManager ) _initEventSource - end: %d", eventSourceHandle);
       
   307     return (int)client;
       
   308 }
       
   309 M2G_NS_END