javauis/m3g_akn/src/jni/interface.inl
changeset 21 2a9601315dfc
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:
       
    15 *
       
    16 */
       
    17 #include "javax_microedition_m3g_Interface.h"
       
    18 
       
    19 TInt initM3GEventSourceL(JNIEnv& aJni,jobject aPeer,TJavaEventServer aServer);
       
    20 
       
    21 /*!
       
    22  * \brief Error handler for the Java interface
       
    23  *
       
    24  * Converts M3G errors to exceptions and throws them automatically.
       
    25  */
       
    26 static void errorHandler(M3Genum errorCode, M3GInterface /*m3g*/)
       
    27 {
       
    28     CSynchronization::InstanceL()->SetErrorCode(errorCode);
       
    29 }
       
    30 
       
    31 
       
    32 JNIEXPORT jint JNICALL Java_javax_microedition_m3g_Interface__1initEventSource
       
    33 (JNIEnv *aEnv, jclass aPeer, /*jint aContext,*/ jint aServer)
       
    34 {
       
    35     TInt ret(0);
       
    36     TRAPD(err, ret = initM3GEventSourceL(*aEnv, aPeer, aServer));
       
    37     if (err == KErrNone)
       
    38     {
       
    39         return ret;
       
    40     }
       
    41     return err;
       
    42 }
       
    43 
       
    44 
       
    45 JNIEXPORT void JNICALL Java_javax_microedition_m3g_Interface__1finalizeEventSource(JNIEnv* aEnv, jclass, jint aEventSourceHandle)
       
    46 {
       
    47     CJavaM3GEventSource* eventSource = JavaUnhand<CJavaM3GEventSource>(aEventSourceHandle);
       
    48     eventSource->Dispose(*aEnv);
       
    49     eventSource = NULL;
       
    50 }
       
    51 
       
    52 static int createInterface(M3Gparams* aCs)
       
    53 {
       
    54     return ((unsigned) m3gCreateInterface(aCs));
       
    55 }
       
    56 
       
    57 JNIEXPORT jint JNICALL Java_javax_microedition_m3g_Interface__1ctor(JNIEnv* aEnv, jclass, jint aEventSourceHandle)
       
    58 {
       
    59     M3Gparams cs;
       
    60     memset(&cs, 0, sizeof(cs));
       
    61     cs.mallocFunc = malloc;
       
    62     cs.freeFunc   = free;
       
    63     cs.errorFunc = errorHandler;
       
    64 
       
    65     M3G_DO_LOCK
       
    66     /* Call to the Eventserver side */
       
    67     CJavaM3GEventSource* eventSource = JavaUnhand<CJavaM3GEventSource>(aEventSourceHandle);
       
    68     jint handle = eventSource->Execute(&createInterface, &cs);
       
    69     M3G_DO_UNLOCK(aEnv);
       
    70     return handle;
       
    71 }
       
    72 
       
    73 JNIEXPORT jint JNICALL Java_javax_microedition_m3g_Interface__1getClassID
       
    74 (JNIEnv* aEnv, jclass, jint aHObject)
       
    75 {
       
    76     M3G_DO_LOCK
       
    77     jint handle = m3gGetClass((M3GObject)aHObject);
       
    78     M3G_DO_UNLOCK(aEnv);
       
    79     return handle;
       
    80 }