javauis/nokiasound_akn/src/sound.cpp
branchRCL_3
changeset 83 26b2b12093af
parent 19 04becd199f91
equal deleted inserted replaced
77:7cee158cb8cd 83:26b2b12093af
       
     1 /*
       
     2 * Copyright (c) 2006-2007 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 class for Sound.java.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <e32def.h> // MAKE_TINT64 Warning fix
       
    20 
       
    21 #include "com_nokia_mid_sound_Sound.h"
       
    22 #include "CMIDSound.h"
       
    23 #include "javajniutils.h"
       
    24 #include "javacommonutils.h"
       
    25 #include "logger.h"
       
    26 
       
    27 /*
       
    28  * Class:     com_nokia_mid_sound_Sound
       
    29  * Method:    _dispose
       
    30  * Signature: (II)V
       
    31  */
       
    32 JNIEXPORT void JNICALL Java_com_nokia_mid_sound_Sound__1dispose
       
    33 (JNIEnv* /* aJni */, jobject /* aSound */, jint aHandle)
       
    34 {
       
    35     JELOG2(EJavaUI);
       
    36     CMIDSound* sound = reinterpret_cast<CMIDSound*>(aHandle);
       
    37     delete sound;
       
    38 }
       
    39 
       
    40 /*
       
    41  * Class:     com_nokia_mid_sound_Sound
       
    42  * Method:    _create
       
    43  * Signature: (I)I
       
    44  */
       
    45 JNIEXPORT jint JNICALL Java_com_nokia_mid_sound_Sound__1create
       
    46 (JNIEnv* aJni, jobject aSound)
       
    47 {
       
    48     JELOG2(EJavaUI);
       
    49 
       
    50     TInt handle(0);
       
    51     CMIDSound* sound = 0;
       
    52     TRAPD(err,
       
    53     {
       
    54         sound = CMIDSound::NewL(*aJni, aSound);
       
    55         if (sound != 0)
       
    56         {
       
    57             sound->InitProfileListener();
       
    58         }
       
    59     });
       
    60 
       
    61     if (err != KErrNone)
       
    62     {
       
    63 
       
    64         java::util::JniUtils::throwNewException(aJni, "java/lang/RuntimeException" ,
       
    65                                                 "Failed to create Native Peer " +
       
    66                                                 java::util::JavaCommonUtils::intToString(err));
       
    67     }
       
    68     else
       
    69     {
       
    70 
       
    71         handle = reinterpret_cast<TInt>(sound);
       
    72     }
       
    73     return handle;
       
    74 }
       
    75 
       
    76 /*
       
    77  * Class:     com_nokia_mid_sound_Sound
       
    78  * Method:    _init
       
    79  * Signature: (III[BIJ)I
       
    80  */
       
    81 JNIEXPORT jint JNICALL Java_com_nokia_mid_sound_Sound__1init
       
    82 (JNIEnv* aJni, jobject, jint aHandle, jint aType, jbyteArray aData,
       
    83  jint aFrequency, jlong aDuration)
       
    84 {
       
    85     JELOG2(EJavaUI);
       
    86     TInt freq(aFrequency);
       
    87     TInt64 duration = *reinterpret_cast<TInt64*>(&aDuration);
       
    88 
       
    89     CMIDSound* sound = reinterpret_cast<CMIDSound*>(aHandle);
       
    90 
       
    91     TPtrC8 ptr;
       
    92     jbyte* data = NULL;
       
    93 
       
    94     if (aType != com_nokia_mid_sound_Sound_FORMAT_BEEP)
       
    95     {
       
    96         if (!aData)
       
    97         {
       
    98             return KErrGeneral;
       
    99         }
       
   100         data = aJni->GetByteArrayElements(aData,0);
       
   101         jint length = aJni->GetArrayLength(aData);
       
   102         ptr.Set((TUint8*)data, length);
       
   103     }
       
   104 
       
   105     // Had to make SetBeep() due to number of maximum parameters in ExecuteTrap.
       
   106     sound->SetBeep(freq, duration);
       
   107     TInt err = sound->Init(aType, (const TDesC8*)&ptr);
       
   108 
       
   109     if (aType != com_nokia_mid_sound_Sound_FORMAT_BEEP)
       
   110     {
       
   111         aJni->ReleaseByteArrayElements(aData, data, 0);
       
   112     }
       
   113     return err;
       
   114 }
       
   115 
       
   116 /*
       
   117  * Class:     com_nokia_mid_sound_Sound
       
   118  * Method:    _release
       
   119  * Signature: (II)V
       
   120  */
       
   121 JNIEXPORT void JNICALL Java_com_nokia_mid_sound_Sound__1release
       
   122 (JNIEnv*, jobject, jint aHandle)
       
   123 {
       
   124     JELOG2(EJavaUI);
       
   125     CMIDSound* sound = reinterpret_cast<CMIDSound*>(aHandle);
       
   126     sound->Release();
       
   127 }
       
   128 
       
   129 
       
   130 /*
       
   131  * Class:     com_nokia_mid_sound_Sound
       
   132  * Method:    _play
       
   133  * Signature: (II)I
       
   134  */
       
   135 JNIEXPORT jint JNICALL Java_com_nokia_mid_sound_Sound__1play
       
   136 (JNIEnv*, jobject, jint aHandle, jint aLoop)
       
   137 {
       
   138     JELOG2(EJavaUI);
       
   139     CMIDSound* sound = reinterpret_cast<CMIDSound*>(aHandle);
       
   140     TInt err = sound->Play(aLoop);
       
   141     return err;
       
   142 }
       
   143 
       
   144 /*
       
   145  * Class:     com_nokia_mid_sound_Sound
       
   146  * Method:    _stop
       
   147  * Signature: (II)V
       
   148  */
       
   149 JNIEXPORT void JNICALL Java_com_nokia_mid_sound_Sound__1stop
       
   150 (JNIEnv*, jobject, jint aHandle)
       
   151 {
       
   152     JELOG2(EJavaUI);
       
   153     CMIDSound* sound = reinterpret_cast<CMIDSound*>(aHandle);
       
   154     sound->Stop();
       
   155 }
       
   156 
       
   157 /*
       
   158  * Class:     com_nokia_mid_sound_Sound
       
   159  * Method:    _resume
       
   160  * Signature: (II)V
       
   161  */
       
   162 JNIEXPORT void JNICALL Java_com_nokia_mid_sound_Sound__1resume
       
   163 (JNIEnv*, jobject, jint aHandle)
       
   164 {
       
   165     JELOG2(EJavaUI);
       
   166     CMIDSound* sound = reinterpret_cast<CMIDSound*>(aHandle);
       
   167     sound->Resume();
       
   168 }
       
   169 
       
   170 /*
       
   171  * Class:     com_nokia_mid_sound_Sound
       
   172  * Method:    _setVolume
       
   173  * Signature: (III)V
       
   174  */
       
   175 JNIEXPORT void JNICALL Java_com_nokia_mid_sound_Sound__1setVolume
       
   176 (JNIEnv*, jobject, jint aHandle, jint aVolume)
       
   177 {
       
   178     JELOG2(EJavaUI);
       
   179     CMIDSound* sound = reinterpret_cast<CMIDSound*>(aHandle);
       
   180     sound->SetVolume(aVolume);
       
   181 }
       
   182 
       
   183 /*
       
   184  * Class:     com_nokia_mid_sound_Sound
       
   185  * Method:    _volume
       
   186  * Signature: (II)I
       
   187  */
       
   188 JNIEXPORT jint JNICALL Java_com_nokia_mid_sound_Sound__1volume
       
   189 (JNIEnv*, jobject, jint aHandle)
       
   190 {
       
   191     JELOG2(EJavaUI);
       
   192     CMIDSound* sound = reinterpret_cast<CMIDSound*>(aHandle);
       
   193     TInt volume = sound->SoundVolume();
       
   194     return(volume);
       
   195 }
       
   196 
       
   197 /*
       
   198  * Class:     com_nokia_mid_sound_Sound
       
   199  * Method:    _getState
       
   200  * Signature: (II)I
       
   201  */
       
   202 JNIEXPORT jint JNICALL Java_com_nokia_mid_sound_Sound__1getState
       
   203 (JNIEnv*, jobject, jint aHandle)
       
   204 {
       
   205     JELOG2(EJavaUI);
       
   206     CMIDSound* sound = reinterpret_cast<CMIDSound*>(aHandle);
       
   207     TInt state = sound->PlayerState();
       
   208     return state;
       
   209 }