javauis/amms_qt/jni/src/effectcontrol.cpp
branchRCL_3
changeset 18 9ac0a0a7da70
parent 17 0fd27995241b
child 19 71c436fe3ce0
equal deleted inserted replaced
17:0fd27995241b 18:9ac0a0a7da70
     1 /*
       
     2 * Copyright (c) 2005-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 for EffectControl
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 //#include <jutils.h>
       
    20 #include <logger.h>
       
    21 
       
    22 #include "com_nokia_amms_control_EffectControl.h"
       
    23 #include <mmafunctionserver.h>
       
    24 #include "cammseffectcontrolgroup.h"
       
    25 #include "jstringutils.h"
       
    26 #include "s60commonutils.h"
       
    27 using namespace java::util;
       
    28 #include <JniEnvWrapper.h>
       
    29 
       
    30 /**
       
    31  * wrapper for CAMMSEffectControlGroup::PresetNamesL()
       
    32  */
       
    33 LOCAL_C void GetPresetNamesL(CAMMSEffectControlGroup* aControl,
       
    34                              JNIEnv* aJni,
       
    35                              jobjectArray* aArray)
       
    36 {
       
    37     // JNI interface pointer can't be passed to different thread, so
       
    38     // it is needed to get valid JNI interface pointer for Event Server thread
       
    39     //aJni = JniEnvWrapper::GetValidJniRef();
       
    40 
       
    41     // Create new java String array and copy values from the values array
       
    42     *aArray = MMAPIUtils::CopyToNewJavaStringArrayL(*aJni, aControl->PresetNamesL());
       
    43 }
       
    44 
       
    45 /**
       
    46  * wrapper for CAMMSEffectControlGroup::PresetL()
       
    47  */
       
    48 static void GetPresetL(
       
    49     CAMMSEffectControlGroup* aControl,
       
    50     TDes* aPreset)
       
    51 {
       
    52     aControl->GetPresetL(*aPreset);
       
    53 }
       
    54 
       
    55 /**
       
    56  * wrapper for CAMMSEffectControlGroup::SetEnabledL()
       
    57  */
       
    58 static void SetEnabledL(CAMMSEffectControlGroup* aControl, TBool aEnabled)
       
    59 {
       
    60     aControl->SetEnabledL(aEnabled);
       
    61 }
       
    62 
       
    63 /**
       
    64  * wrapper for CAMMSEffectControlGroup::SetScopeL()
       
    65  */
       
    66 static void SetScopeL(CAMMSEffectControlGroup* aControl, TInt aScope)
       
    67 {
       
    68     aControl->SetScopeL((CAMMSEffectControlGroup::TEffectScope) aScope);
       
    69 }
       
    70 
       
    71 /**
       
    72  * wrapper for CAMMSEffectControlGroup::SetEnforcedL()
       
    73  */
       
    74 static void SetEnforcedL(CAMMSEffectControlGroup* aControl, TBool aEnforced)
       
    75 {
       
    76     aControl->SetEnforcedL(aEnforced);
       
    77 }
       
    78 
       
    79 /**
       
    80  * wrapper for CAMMSEffectControlGroup::SetPresetL()
       
    81  */
       
    82 static void SetPresetL(CAMMSEffectControlGroup* aControl, TDesC* aPreset)
       
    83 {
       
    84     aControl->SetPresetL(*aPreset);
       
    85 }
       
    86 
       
    87 /*
       
    88  * Class:     com_nokia_amms_control_EffectControl
       
    89  * Method:    _isEnabled
       
    90  * Signature: (II)I
       
    91  */
       
    92 JNIEXPORT jint JNICALL Java_com_nokia_amms_control_EffectControl__1isEnabled(
       
    93     JNIEnv*, jclass, jint aEventSource, jint aControl)
       
    94 {
       
    95     /*MMAFunctionServer* eventSource =
       
    96         reinterpret_cast< MMAFunctionServer *>(aEventSource);*/
       
    97 
       
    98     CAMMSEffectControlGroup* control = static_cast<CAMMSEffectControlGroup*>(
       
    99                                            reinterpret_cast< CAMMSControlGroup* >(aControl));
       
   100 
       
   101     return control->Enabled();
       
   102 }
       
   103 
       
   104 /*
       
   105  * Class:     com_nokia_amms_control_EffectControl
       
   106  * Method:    _isEnforced
       
   107  * Signature: (II)I
       
   108  */
       
   109 JNIEXPORT jint JNICALL Java_com_nokia_amms_control_EffectControl__1isEnforced(
       
   110     JNIEnv*, jclass, jint aEventSource, jint aControl)
       
   111 {
       
   112    /* MMAFunctionServer* eventSource =
       
   113         reinterpret_cast< MMAFunctionServer* >(aEventSource);*/
       
   114 
       
   115     CAMMSEffectControlGroup* control = static_cast<CAMMSEffectControlGroup*>(
       
   116                                            reinterpret_cast< CAMMSControlGroup* >(aControl));
       
   117 
       
   118     return control->Enforced();
       
   119 }
       
   120 
       
   121 /*
       
   122  * Class:     com_nokia_amms_control_EffectControl
       
   123  * Method:    _getPresetNames
       
   124  * Signature: (II[Ljava/lang/String;)I
       
   125  */
       
   126 JNIEXPORT jobjectArray JNICALL Java_com_nokia_amms_control_EffectControl__1getPresetNames(
       
   127     JNIEnv* aJni,
       
   128     jclass,
       
   129     jint aEventSource,
       
   130     jint aControl)
       
   131 {
       
   132     MMAFunctionServer* eventSource =
       
   133         reinterpret_cast< MMAFunctionServer* >(aEventSource);
       
   134 
       
   135     CAMMSEffectControlGroup* control = static_cast<CAMMSEffectControlGroup*>(
       
   136                                            reinterpret_cast< CAMMSControlGroup* >(aControl));
       
   137 
       
   138     jobjectArray presetNames = NULL;
       
   139 
       
   140     TInt error = eventSource->ExecuteTrap(GetPresetNamesL,
       
   141                                           control,
       
   142                                           aJni,
       
   143                                           &presetNames);
       
   144 
       
   145     // If an error happened, return null to Java
       
   146     if (error != KErrNone)
       
   147     {
       
   148         presetNames = NULL;
       
   149     }
       
   150     return presetNames;
       
   151 }
       
   152 
       
   153 /*
       
   154  * Class:     com_nokia_amms_control_EffectControl
       
   155  * Method:    _getPreset
       
   156  * Signature: (II[Ljava/lang/String;)I
       
   157  */
       
   158 JNIEXPORT jint JNICALL Java_com_nokia_amms_control_EffectControl__1getPreset(
       
   159     JNIEnv* aJni,
       
   160     jclass,
       
   161     jint aEventSource,
       
   162     jint aControl,
       
   163     jobjectArray aPreset)
       
   164 {
       
   165     MMAFunctionServer* eventSource =
       
   166         reinterpret_cast< MMAFunctionServer *>(aEventSource);
       
   167 
       
   168     CAMMSEffectControlGroup* control = static_cast<CAMMSEffectControlGroup*>(
       
   169 											reinterpret_cast< CAMMSControlGroup* >(aControl));
       
   170 
       
   171     TInt error;
       
   172     TBuf< KAMMSMaxPresetNameLength > preset;
       
   173 
       
   174     error = eventSource->ExecuteTrap(GetPresetL, control, (TDes*) &preset);
       
   175 
       
   176     if (error == KErrNone)
       
   177     {
       
   178         // return NULL if there is no preset set in the native class
       
   179         if (preset == KNullDesC)
       
   180         {
       
   181             aJni->SetObjectArrayElement(aPreset, 0, NULL);
       
   182         }
       
   183         else
       
   184         {
       
   185             jstring javaStr = S60CommonUtils::NativeToJavaString(*aJni, preset);
       
   186             if (!javaStr)
       
   187             {
       
   188                 return KErrNoMemory;
       
   189             }
       
   190 
       
   191             aJni->SetObjectArrayElement(aPreset, 0, javaStr);
       
   192         }
       
   193     }
       
   194 
       
   195     return error;
       
   196 }
       
   197 
       
   198 /*
       
   199  * Class:     com_nokia_amms_control_EffectControl
       
   200  * Method:    _setScope
       
   201  * Signature: (III)I
       
   202  */
       
   203 JNIEXPORT jint JNICALL Java_com_nokia_amms_control_EffectControl__1setScope(
       
   204     JNIEnv*, jclass, jint aEventSource, jint aControl, jint aScope)
       
   205 {
       
   206     MMAFunctionServer* eventSource =
       
   207         reinterpret_cast< MMAFunctionServer *>(aEventSource);
       
   208 
       
   209     CAMMSEffectControlGroup* control = static_cast<CAMMSEffectControlGroup*>(
       
   210                                            reinterpret_cast< CAMMSControlGroup *>(aControl));
       
   211 
       
   212     TInt error;
       
   213     error = eventSource->ExecuteTrap(SetScopeL, control, aScope);
       
   214     return error;
       
   215 }
       
   216 
       
   217 /*
       
   218  * Class:     com_nokia_amms_control_EffectControl
       
   219  * Method:    _setEnabled
       
   220  * Signature: (IIZ)I
       
   221  */
       
   222 JNIEXPORT jint JNICALL Java_com_nokia_amms_control_EffectControl__1setEnabled(
       
   223     JNIEnv*, jclass, jint aEventSource, jint aControl, jboolean aEnabled)
       
   224 {
       
   225     MMAFunctionServer* eventSource =
       
   226         reinterpret_cast< MMAFunctionServer* >(aEventSource);
       
   227 
       
   228     CAMMSEffectControlGroup* control = static_cast<CAMMSEffectControlGroup*>(
       
   229                                            reinterpret_cast< CAMMSControlGroup* >(aControl));
       
   230 
       
   231     TInt error;
       
   232     error = eventSource->ExecuteTrap(SetEnabledL, control, (TBool) aEnabled);
       
   233     return error;
       
   234 }
       
   235 
       
   236 /*
       
   237  * Class:     com_nokia_amms_control_EffectControl
       
   238  * Method:    _getScope
       
   239  * Signature: (II)I
       
   240  */
       
   241 JNIEXPORT jint JNICALL Java_com_nokia_amms_control_EffectControl__1getScope(
       
   242     JNIEnv*, jclass, jint aEventSource, jint aControl)
       
   243 {
       
   244     /*MMAFunctionServer* eventSource =
       
   245         reinterpret_cast< MMAFunctionServer* >(aEventSource);*/
       
   246 
       
   247     CAMMSEffectControlGroup* control = static_cast<CAMMSEffectControlGroup*>(
       
   248                                            reinterpret_cast< CAMMSControlGroup* >(aControl));
       
   249 
       
   250     return control->Scope();
       
   251 }
       
   252 
       
   253 /*
       
   254  * Class:     com_nokia_amms_control_EffectControl
       
   255  * Method:    _setPreset
       
   256  * Signature: (IILjava/lang/String;)I
       
   257  */
       
   258 JNIEXPORT jint JNICALL Java_com_nokia_amms_control_EffectControl__1setPreset(
       
   259     JNIEnv* aJni, jclass, jint aEventSource, jint aControl, jstring aPreset)
       
   260 {
       
   261     MMAFunctionServer* eventSource =
       
   262         reinterpret_cast< MMAFunctionServer *>(aEventSource);
       
   263 
       
   264     CAMMSEffectControlGroup* control = static_cast<CAMMSEffectControlGroup*>(
       
   265                                            reinterpret_cast< CAMMSControlGroup* >(aControl));
       
   266 
       
   267     TInt error;
       
   268     JStringUtils preset(*aJni, aPreset);
       
   269     error = eventSource->ExecuteTrap(SetPresetL, control, (TDesC*) &preset);
       
   270 
       
   271     ELOG1( EJavaAMMS, "AMMS:JNI:EffectControl:setPreset, err=%d", error);
       
   272 
       
   273     return error;
       
   274 }
       
   275 
       
   276 /*
       
   277  * Class:     com_nokia_amms_control_EffectControl
       
   278  * Method:    _setEnforced
       
   279  * Signature: (IIZ)I
       
   280  */
       
   281 JNIEXPORT jint JNICALL Java_com_nokia_amms_control_EffectControl__1setEnforced(
       
   282     JNIEnv*, jclass, jint aEventSource, jint aControl, jboolean aEnforced)
       
   283 {
       
   284     MMAFunctionServer* eventSource =
       
   285         reinterpret_cast< MMAFunctionServer* >(aEventSource);
       
   286 
       
   287     CAMMSEffectControlGroup* control = static_cast<CAMMSEffectControlGroup*>(
       
   288                                            reinterpret_cast< CAMMSControlGroup *>(aControl));
       
   289 
       
   290     TInt error;
       
   291     error = eventSource->ExecuteTrap(
       
   292                 SetEnforcedL,
       
   293                 control,
       
   294                 (TBool) aEnforced);
       
   295     return error;
       
   296 }
       
   297 
       
   298 
       
   299 
       
   300 //  End of File