javaextensions/pim/jni/src/serializer.cpp
branchRCL_3
changeset 14 04becd199f91
equal deleted inserted replaced
13:f5050f1da672 14:04becd199f91
       
     1 /*
       
     2 * Copyright (c) 2008 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:  Serializer JNI wrapper.
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 //  INCLUDE FILES
       
    20 
       
    21 #include "com_nokia_mj_impl_pim_Serializer.h"
       
    22 #include <badesca.h>
       
    23 #include "pimcommon.h"
       
    24 #include "pimbasemanager.h"
       
    25 #include "pimbaseserializer.h"
       
    26 #include "pimbaseitem.h"
       
    27 #include "pimutils.h"
       
    28 #include "logger.h"
       
    29 
       
    30 JNIEXPORT jint
       
    31 JNICALL Java_com_nokia_mj_impl_pim_Serializer__1createSerializer(
       
    32     JNIEnv* aJniEnv, jobject /*aPeer*/, jint aManagerHandle,
       
    33     jintArray aError)
       
    34 {
       
    35     JELOG2(EPim);
       
    36     pimbasemanager* manager =
       
    37         reinterpret_cast< pimbasemanager*>(aManagerHandle);
       
    38     pimbaseserializer* serializer = NULL;
       
    39     int error = 0;
       
    40     try
       
    41     {
       
    42         serializer = pimbaseserializer::getInstance(manager);
       
    43     }
       
    44     catch (int aError)
       
    45     {
       
    46         error = aError;
       
    47     }
       
    48     SetJavaErrorCode(aJniEnv, aError, error);
       
    49 
       
    50     return reinterpret_cast<int>(serializer);
       
    51 }
       
    52 
       
    53 JNIEXPORT void
       
    54 JNICALL Java_com_nokia_mj_impl_pim_Serializer__1dispose(
       
    55     JNIEnv* /*aJniEnv*/, jobject /*aPeer*/, jint aSerializerHandle)
       
    56 {
       
    57     JELOG2(EPim);
       
    58     pimbaseserializer* serializer =
       
    59         reinterpret_cast< pimbaseserializer *>(aSerializerHandle);
       
    60 
       
    61     delete serializer;
       
    62 }
       
    63 
       
    64 JNIEXPORT jintArray
       
    65 JNICALL Java_com_nokia_mj_impl_pim_Serializer__1fromSerialFormat(
       
    66     JNIEnv* aJniEnv, jobject /*aPeer*/, jint aSerializerHandle,
       
    67     jbyteArray aBytes, jint aByteLength, jint aEncoding,
       
    68     jintArray aError)
       
    69 {
       
    70     JELOG2(EPim);
       
    71     pimbaseserializer* serializer =
       
    72         reinterpret_cast< pimbaseserializer *>(aSerializerHandle);
       
    73 
       
    74     jintArray itemArray = serializer->fromSerialFormat(
       
    75                               aJniEnv, aBytes, aByteLength, aEncoding, aError);
       
    76 
       
    77     // The ownership of these items is transferred to the Java side,
       
    78     // to the caller of the method
       
    79     return itemArray;
       
    80 }
       
    81 
       
    82 JNIEXPORT jbyteArray
       
    83 JNICALL Java_com_nokia_mj_impl_pim_Serializer__1toSerialFormat(
       
    84     JNIEnv* aJniEnv, jobject /*aPeer*/, jint aSerializerHandle,
       
    85     jint aItemHandle, jint aEncoding, jintArray aError)
       
    86 {
       
    87     JELOG2(EPim);
       
    88     pimbaseserializer* serializer =
       
    89         reinterpret_cast< pimbaseserializer *>(aSerializerHandle);
       
    90 
       
    91     pimbaseitem* item =
       
    92         reinterpret_cast< pimbaseitem *>(aItemHandle);
       
    93 
       
    94     jbyteArray retVal = serializer->toSerialFormat(item,
       
    95                         aEncoding, aJniEnv, aError);
       
    96 
       
    97     // the byte array is owned on the java side
       
    98     return retVal;
       
    99 }
       
   100 
       
   101 JNIEXPORT jobjectArray
       
   102 JNICALL Java_com_nokia_mj_impl_pim_Serializer__1supportedSerialFormats(
       
   103     JNIEnv* aJniEnv, jobject /*aPeer*/, jint aSerializerHandle,
       
   104     jint aPimListType, jintArray aError)
       
   105 {
       
   106     JELOG2(EPim);
       
   107     pimbaseserializer* serializer =
       
   108         reinterpret_cast< pimbaseserializer *>(aSerializerHandle);
       
   109 
       
   110     TPIMListType listType = static_cast<TPIMListType>(aPimListType);
       
   111 
       
   112     jobjectArray retVal = serializer->supportedSerialFormats(
       
   113                               listType, aJniEnv, aError);
       
   114 
       
   115     return retVal;
       
   116 }