javauis/mmapi_akn/baseline/src/ratecontrol.cpp
changeset 21 2a9601315dfc
equal deleted inserted replaced
18:e8e63152f320 21:2a9601315dfc
       
     1 /*
       
     2 * Copyright (c) 2002 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:  This class has JNI wrappers for CMMARateControl
       
    15 *
       
    16 */
       
    17 
       
    18 #include <jutils.h>
       
    19 
       
    20 #include "com_nokia_microedition_media_control_RateControl.h"
       
    21 #include "cmmaeventsource.h"
       
    22 #include "cmmaratecontrol.h"
       
    23 #include <jdebug.h>
       
    24 
       
    25 //
       
    26 // Wrapper functions which are needed in event source execution.
       
    27 // If method to be called can leave ExecuteTrap must be used,
       
    28 // otherwise Execute and ExecuteV can be used.
       
    29 //
       
    30 //
       
    31 
       
    32 /**
       
    33  * Local function which can be used to call CMMARateControl class methods.
       
    34  * Type of of the function pointer must be
       
    35  * TInt CMMARateControl::aFunc( TInt aData )
       
    36  *
       
    37  * @param aRateControl CMMARateControl pointer.
       
    38  * @param aFunc Pointer to the CMMARateControl method.
       
    39  * @param aData Parameter to passed to the aFunc method
       
    40  * @param aReturnValue The return value of the aFunc will
       
    41  *                     be assigned to this parameter.
       
    42  */
       
    43 LOCAL_C void ReturnIntParamIntFuncL(CMMARateControl* aRateControl,
       
    44                                     TInt(CMMARateControl::*aFuncL)(TInt),
       
    45                                     TInt aData,
       
    46                                     TInt* aReturnValue)
       
    47 {
       
    48     // call TInt CMMARateControl::aFunc( TInt aData ) method.
       
    49     *aReturnValue = (aRateControl->*aFuncL)(aData);
       
    50 }
       
    51 
       
    52 /**
       
    53  * Local function which can be used to call CMMARateControl class methods.
       
    54  * Type of of the function pointer must be
       
    55  * TInt CMMARateControl::aFunc()
       
    56  *
       
    57  * @param aRateControl CMMARateControl pointer.
       
    58  * @param aFunc Pointer to the CMMARateControl method.
       
    59  * @param aReturnValue The return value of the aFunc will
       
    60  *                     be assigned to this parameter.
       
    61  */
       
    62 LOCAL_C void ReturnIntFuncL(CMMARateControl* aRateControl,
       
    63                             TInt(CMMARateControl::*aFuncL)(),
       
    64                             TInt* aReturnValue)
       
    65 {
       
    66     // call TInt CMMARateControl::aFunc() method.
       
    67     *aReturnValue = (aRateControl->*aFuncL)();
       
    68 }
       
    69 
       
    70 //
       
    71 // JNI functions. Prototypes are generated and commented in Java class
       
    72 // com_nokia_microedition_media_control_RateControl
       
    73 //
       
    74 
       
    75 /**
       
    76  * JNI function from com.nokia.microedition.media.control.RateControl
       
    77  */
       
    78 JNIEXPORT jint JNICALL
       
    79 Java_com_nokia_microedition_media_control_RateControl__1getMinRate
       
    80 (JNIEnv*,
       
    81  jobject,
       
    82  jint aControlHandle,
       
    83  jint aEventSourceHandle)
       
    84 {
       
    85     // Get pointer to native event source.
       
    86     CMMAEventSource* eventSource =
       
    87         JavaUnhand< CMMAEventSource >(aEventSourceHandle);
       
    88 
       
    89     CMMARateControl* RateControl =
       
    90         JavaUnhand< CMMARateControl >(aControlHandle);
       
    91 
       
    92     TInt returnValue = 0;
       
    93 
       
    94     // Get value or the default.
       
    95     TInt error;
       
    96     error = eventSource->ExecuteTrap(&ReturnIntFuncL,
       
    97                                      RateControl,
       
    98                                      &CMMARateControl::MinRateL,
       
    99                                      &returnValue);
       
   100 
       
   101     DEBUG_INT("RateControl__1getMinRate return value %d", returnValue);
       
   102 
       
   103     return (error == KErrNone) ? returnValue : error;
       
   104 }
       
   105 
       
   106 /**
       
   107  * JNI function from com.nokia.microedition.media.control.RateControl
       
   108  */
       
   109 JNIEXPORT jint JNICALL
       
   110 Java_com_nokia_microedition_media_control_RateControl__1getRate
       
   111 (JNIEnv*,
       
   112  jobject,
       
   113  jint aControlHandle,
       
   114  jint aEventSourceHandle)
       
   115 {
       
   116     // Get pointer to native event source.
       
   117     CMMAEventSource* eventSource =
       
   118         JavaUnhand< CMMAEventSource >(aEventSourceHandle);
       
   119 
       
   120     CMMARateControl* RateControl =
       
   121         JavaUnhand< CMMARateControl >(aControlHandle);
       
   122 
       
   123 
       
   124     TInt returnValue = 0;
       
   125 
       
   126     // Get actual rate or the default value to the returnValue.
       
   127     TInt error;
       
   128     error = eventSource->ExecuteTrap(&ReturnIntFuncL,
       
   129                                      RateControl,
       
   130                                      &CMMARateControl::RateL,
       
   131                                      &returnValue);
       
   132 
       
   133     DEBUG_INT("RateControl__1getRate return value %d", returnValue);
       
   134 
       
   135     return (error == KErrNone) ? returnValue : error;
       
   136 }
       
   137 
       
   138 /**
       
   139  * JNI function from com.nokia.microedition.media.control.RateControl
       
   140  */
       
   141 JNIEXPORT jint JNICALL
       
   142 Java_com_nokia_microedition_media_control_RateControl__1setRate
       
   143 (JNIEnv*,
       
   144  jobject,
       
   145  jint aControlHandle,
       
   146  jint aEventSourceHandle,
       
   147  jint aRate)
       
   148 {
       
   149     // Get pointer to native event source.
       
   150     CMMAEventSource* eventSource =
       
   151         JavaUnhand< CMMAEventSource >(aEventSourceHandle);
       
   152 
       
   153     CMMARateControl* RateControl =
       
   154         JavaUnhand< CMMARateControl >(aControlHandle);
       
   155 
       
   156     // Return value will be actual rate set or default value if rate is not
       
   157     // available.
       
   158     TInt returnValue = 0;
       
   159 
       
   160     TInt error;
       
   161     error = eventSource->ExecuteTrap(&ReturnIntParamIntFuncL,
       
   162                                      RateControl,
       
   163                                      &CMMARateControl::SetRateL,
       
   164                                      aRate,
       
   165                                      &returnValue);
       
   166 
       
   167     DEBUG_INT("RateControl__1setRate return value %d", returnValue);
       
   168 
       
   169     return (error == KErrNone) ? returnValue : error;
       
   170 }
       
   171 
       
   172 /**
       
   173  * JNI function from com.nokia.microedition.media.control.RateControl
       
   174  */
       
   175 JNIEXPORT jint JNICALL
       
   176 Java_com_nokia_microedition_media_control_RateControl__1getMaxRate
       
   177 (JNIEnv*,
       
   178  jobject,
       
   179  jint aControlHandle,
       
   180  jint aEventSourceHandle)
       
   181 {
       
   182     // Get pointer to native event source.
       
   183     CMMAEventSource* eventSource =
       
   184         JavaUnhand< CMMAEventSource >(aEventSourceHandle);
       
   185 
       
   186     CMMARateControl* RateControl =
       
   187         JavaUnhand< CMMARateControl >(aControlHandle);
       
   188 
       
   189     TInt returnValue = 0;
       
   190     TInt error;
       
   191 
       
   192     error = eventSource->ExecuteTrap(&ReturnIntFuncL,
       
   193                                      RateControl,
       
   194                                      &CMMARateControl::MaxRateL,
       
   195                                      &returnValue);
       
   196     DEBUG_INT("RateControl__1getMaxRate return value %d", returnValue);
       
   197 
       
   198     return (error == KErrNone) ? returnValue : error;
       
   199 }
       
   200 
       
   201 //  END OF FILE