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