javauis/mmapi_qt/baseline/src/metadatacontrol.cpp
changeset 23 98ccebc37403
child 26 dc7c549001d5
equal deleted inserted replaced
21:2a9601315dfc 23:98ccebc37403
       
     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 CMMAMetaDataControl
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <logger.h>
       
    20 #include "com_nokia_microedition_media_control_MetaDataControl.h"
       
    21 
       
    22 #include "mmafunctionserver.h"
       
    23 #include "cmmametadatacontrol.h"
       
    24 #include "s60commonutils.h"
       
    25 #include "jstringutils.h"
       
    26 using namespace java::util;
       
    27     
       
    28 //#include "mmapiutils.h"
       
    29 
       
    30 
       
    31 /* ...getKeyCount
       
    32  *
       
    33  * Returns the number of metadata keys or symbian error code
       
    34  */
       
    35 
       
    36 JNIEXPORT jint JNICALL Java_com_nokia_microedition_media_control_MetaDataControl__1getKeysCount
       
    37 (JNIEnv* /*aJniEnv*/, jobject, jint aEventSourceHandle, jint aMetaDataControlHandle)
       
    38 {
       
    39     MMAFunctionServer* eventSource =
       
    40         reinterpret_cast< MMAFunctionServer* >(aEventSourceHandle);
       
    41     CMMAMetaDataControl* metaDataControl =
       
    42         reinterpret_cast< CMMAMetaDataControl* >(aMetaDataControlHandle);
       
    43 
       
    44     TInt keys;
       
    45     TInt err = eventSource->ExecuteTrap(&CMMAMetaDataControl::StaticKeysCountL, metaDataControl, &keys);
       
    46 
       
    47     return err == KErrNone ? keys : err;
       
    48 }
       
    49 
       
    50 
       
    51 /* ... getKey
       
    52  *
       
    53  * Get the key name at the given index from the actual native implementation. If no key is available,
       
    54  * return null.
       
    55  *
       
    56  * The ownership of the native data is received from the actual native implementation.
       
    57  * The data is duplicated to the Java side and the native data is destroyed here.
       
    58  */
       
    59 
       
    60 JNIEXPORT jstring JNICALL Java_com_nokia_microedition_media_control_MetaDataControl__1getKey
       
    61 (JNIEnv* aJniEnv, jobject, jint aEventSourceHandle, jint aMetaDataControlHandle, jint aIndex)
       
    62 {
       
    63     MMAFunctionServer* eventSource =
       
    64         reinterpret_cast< MMAFunctionServer *>(aEventSourceHandle);
       
    65 
       
    66     CMMAMetaDataControl* metaDataControl =
       
    67         reinterpret_cast< CMMAMetaDataControl* >(aMetaDataControlHandle);
       
    68 
       
    69     HBufC* key = NULL;
       
    70     jstring javaStr = NULL;
       
    71 
       
    72     TInt err = eventSource->ExecuteTrap(&CMMAMetaDataControl::StaticKeyL, metaDataControl, &key, aIndex);
       
    73 
       
    74     if (err == KErrNone)
       
    75     {
       
    76         javaStr = S60CommonUtils::NativeToJavaString(*aJniEnv, key->Des());
       
    77     }
       
    78     delete key;
       
    79 
       
    80     return javaStr;
       
    81 }
       
    82 
       
    83 /* ...getKeyValue
       
    84  *
       
    85  * Get the value of the given key from the actual native implementation. If no key is available,
       
    86  * return null (as specified in the MetaDataControl interface).
       
    87  *
       
    88  * The ownership of the native data is received from the actual native implementation.
       
    89  * The data is duplicated to the Java side and the native data is destroyed here.
       
    90  */
       
    91 
       
    92 JNIEXPORT jstring JNICALL Java_com_nokia_microedition_media_control_MetaDataControl__1getKeyValue
       
    93 (JNIEnv* aJniEnv, jobject, jint aEventSourceHandle, jint aMetaDataControlHandle, jstring aKey)
       
    94 {
       
    95     MMAFunctionServer* eventSource =
       
    96         reinterpret_cast< MMAFunctionServer* >(aEventSourceHandle);
       
    97 
       
    98     CMMAMetaDataControl* metaDataControl =
       
    99         reinterpret_cast< CMMAMetaDataControl* >(aMetaDataControlHandle);
       
   100 
       
   101     HBufC* value = NULL;
       
   102     JStringUtils key(*aJniEnv, aKey);
       
   103 
       
   104     TInt retVal = eventSource->ExecuteTrap(
       
   105                       &CMMAMetaDataControl::StaticKeyValueL,
       
   106                       metaDataControl,
       
   107                       &value,
       
   108                       (TDesC*) &key);
       
   109 
       
   110     jstring retString = NULL;
       
   111 
       
   112     if (KErrNone == retVal)
       
   113     {
       
   114         retString = S60CommonUtils::NativeToJavaString(*aJniEnv, *value);
       
   115     }
       
   116 
       
   117     delete value;
       
   118 
       
   119     return retString;
       
   120 }
       
   121 
       
   122 //  END OF FILE