javaextensions/location/landmarks/src/landmarkstoremanager.cpp
branchRCL_3
changeset 19 04becd199f91
equal deleted inserted replaced
16:f5050f1da672 19: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:  JNI implementation of LandmarkStoreManager class
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 // INTERNAL INCLUDES
       
    20 #include    "com_nokia_mj_impl_location_LandmarkStoreManager.h"
       
    21 #include    "jstringutils.h"
       
    22 #include    "clapilandmarkstoremanager.h"
       
    23 #include    "lapijnicommon.h"
       
    24 #include    "lapipanics.h"
       
    25 #include    "locationfunctionserver.h"
       
    26 
       
    27 using namespace java::location;
       
    28 
       
    29 LOCAL_C void CreateManagerL(TInt* aManagerHandle)
       
    30 {
       
    31     JELOG2(EJavaLocation);
       
    32     CLAPILandmarkStoreManager* manager = CLAPILandmarkStoreManager::NewL();
       
    33     CleanupStack::PushL(manager);
       
    34     // Add object to event source
       
    35     TInt managerHandle = reinterpret_cast<TInt>(manager);
       
    36     CleanupStack::Pop(manager);
       
    37     // Return the handle to the JNI context
       
    38     *aManagerHandle = managerHandle;
       
    39 }
       
    40 
       
    41 /*
       
    42  * Class:     com_nokia_microedition_location_LandmarkStoreManager
       
    43  * Method:    _createNativePeer
       
    44  * Signature: (I)I
       
    45  */
       
    46 JNIEXPORT jint
       
    47 JNICALL Java_com_nokia_mj_impl_location_LandmarkStoreManager__1createNativePeer(
       
    48     JNIEnv* /*aJniEnv*/,
       
    49     jobject /*aPeer*/,
       
    50     jint aEventSourceHandle)
       
    51 {
       
    52     JELOG2(EJavaLocation);
       
    53 
       
    54     LocationFunctionServer* eventSource =
       
    55         reinterpret_cast< LocationFunctionServer*>(aEventSourceHandle);
       
    56 
       
    57     TInt managerHandle = KErrGeneral;
       
    58 
       
    59     TInt error = eventSource->ExecuteTrap(
       
    60                      CreateManagerL,
       
    61                      &managerHandle);
       
    62 
       
    63     // Return the handle if it was successfully obtained
       
    64     return error == KErrNone ? managerHandle : error;
       
    65 }
       
    66 
       
    67 LOCAL_C void OpenStoreL(CLAPILandmarkStoreManager* aManager,
       
    68                         const TDesC* aStoreName, TInt* aStoreHandle)
       
    69 {
       
    70     __ASSERT_DEBUG(aStoreName, LAPIError::Panic(ELAPIPanicNullArgument));
       
    71 
       
    72     // KNulDesC indicates that the default store should be opened
       
    73     CLAPILandmarkStore* store = aManager->OpenStoreL(*aStoreName);
       
    74 
       
    75     // Add opened store to the event source
       
    76     TInt storeHandle = reinterpret_cast<TInt>(store);
       
    77 
       
    78     *aStoreHandle = storeHandle;
       
    79 }
       
    80 
       
    81 /*
       
    82  * Class:     com_nokia_microedition_location_LandmarkStoreManager
       
    83  * Method:    _openStore
       
    84  * Signature: (IILjava/lang/String;)I
       
    85  */
       
    86 JNIEXPORT jint
       
    87 JNICALL Java_com_nokia_mj_impl_location_LandmarkStoreManager__1openStore(
       
    88     JNIEnv* aJniEnv,
       
    89     jobject /*aPeer*/,
       
    90     jint aEventSourceHandle,
       
    91     jint aManagerHandle,
       
    92     jstring aStoreName)
       
    93 {
       
    94     JELOG2(EJavaLocation);
       
    95     LocationFunctionServer* eventSource =
       
    96         reinterpret_cast< LocationFunctionServer*>(aEventSourceHandle);
       
    97     CLAPILandmarkStoreManager* manager =
       
    98         reinterpret_cast< CLAPILandmarkStoreManager*>(aManagerHandle);
       
    99 
       
   100     const JStringUtils storeName(*aJniEnv, aStoreName);
       
   101     const TDesC* storeNameArg = (aStoreName ? &storeName : &KNullDesC());
       
   102 
       
   103     TInt storeHandle = KErrGeneral;
       
   104 
       
   105     TInt error = eventSource->ExecuteTrap(
       
   106                      OpenStoreL,
       
   107                      manager,
       
   108                      storeNameArg,
       
   109                      &storeHandle);
       
   110 
       
   111     // Return the handle if it was successfully obtained
       
   112     return error == KErrNone ? storeHandle : error;
       
   113 }
       
   114 
       
   115 LOCAL_C void CreateStoreL(CLAPILandmarkStoreManager* aManager,
       
   116                           const TDesC* aStoreName)
       
   117 {
       
   118     aManager->CreateStoreL(*aStoreName);
       
   119 }
       
   120 
       
   121 /*
       
   122  * Class:     com_nokia_microedition_location_LandmarkStoreManager
       
   123  * Method:    _createStore
       
   124  * Signature: (IILjava/lang/String;)I
       
   125  */
       
   126 JNIEXPORT jint
       
   127 JNICALL Java_com_nokia_mj_impl_location_LandmarkStoreManager__1createStore(
       
   128     JNIEnv* aJniEnv,
       
   129     jobject /*aPeer*/,
       
   130     jint aEventSourceHandle,
       
   131     jint aManagerHandle,
       
   132     jstring aStoreName)
       
   133 {
       
   134     JELOG2(EJavaLocation);
       
   135 
       
   136     LocationFunctionServer* eventSource =
       
   137         reinterpret_cast< LocationFunctionServer*>(aEventSourceHandle);
       
   138     CLAPILandmarkStoreManager* manager =
       
   139         reinterpret_cast< CLAPILandmarkStoreManager*>(aManagerHandle);
       
   140 
       
   141     // Store name must not be null
       
   142     const JStringUtils storeName(*aJniEnv, aStoreName);
       
   143 
       
   144     TInt error = eventSource->ExecuteTrap(
       
   145                      CreateStoreL,
       
   146                      manager,
       
   147                      static_cast< const TDesC*>(&storeName));
       
   148 
       
   149     LOG1(EJavaLocation,EInfo, "Java_com_nokia_microedition_location_LandmarkStoreManager__1createStore - error %d", error);
       
   150     return error;
       
   151 }
       
   152 
       
   153 LOCAL_C void DeleteStoreL(CLAPILandmarkStoreManager* aManager,
       
   154                           const TDesC* aStoreName)
       
   155 {
       
   156     aManager->DeleteStoreL(*aStoreName);
       
   157 }
       
   158 
       
   159 /*
       
   160  * Class:     com_nokia_microedition_location_LandmarkStoreManager
       
   161  * Method:    _deleteStore
       
   162  * Signature: (IILjava/lang/String;)I
       
   163  */
       
   164 JNIEXPORT jint
       
   165 JNICALL Java_com_nokia_mj_impl_location_LandmarkStoreManager__1deleteStore(
       
   166     JNIEnv* aJniEnv,
       
   167     jobject /*aPeer*/,
       
   168     jint aEventSourceHandle,
       
   169     jint aManagerHandle,
       
   170     jstring aStoreName)
       
   171 {
       
   172     JELOG2(EJavaLocation);
       
   173     LocationFunctionServer* eventSource =
       
   174         reinterpret_cast< LocationFunctionServer*>(aEventSourceHandle);
       
   175     CLAPILandmarkStoreManager* manager =
       
   176         reinterpret_cast< CLAPILandmarkStoreManager*>(aManagerHandle);
       
   177 
       
   178     // Store name must not be null
       
   179     const JStringUtils storeName(*aJniEnv, aStoreName);
       
   180 
       
   181     TInt error = eventSource->ExecuteTrap(
       
   182                      DeleteStoreL,
       
   183                      manager,
       
   184                      static_cast< const TDesC*>(&storeName));
       
   185 
       
   186     LOG1(EJavaLocation,EInfo, "Java_com_nokia_microedition_location_LandmarkStoreManager__1deleteStore - error %d", error);
       
   187     return error;
       
   188 }
       
   189 
       
   190 LOCAL_C void RemoveLandmarkStore(CLAPILandmarkStoreManager* aManager,
       
   191                                  CLAPILandmarkStore* aLandmarkStore)
       
   192 {
       
   193     if (aLandmarkStore)
       
   194     {
       
   195         aManager->RemoveStore(*aLandmarkStore);
       
   196     }
       
   197 }
       
   198 
       
   199 /*
       
   200  * Class:     com_nokia_microedition_location_LandmarkStoreManager
       
   201  * Method:    _removeStore
       
   202  * Signature: (III)V
       
   203  */
       
   204 JNIEXPORT void
       
   205 JNICALL Java_com_nokia_mj_impl_location_LandmarkStoreManager__1removeStore(
       
   206     JNIEnv* /*aJniEnv*/,
       
   207     jobject /*aPeer*/,
       
   208     jint aEventSourceHandle,
       
   209     jint aManagerHandle,
       
   210     jint aStoreHandle)
       
   211 {
       
   212     JELOG2(EJavaLocation);
       
   213 
       
   214     LocationFunctionServer* eventSource =
       
   215         reinterpret_cast< LocationFunctionServer*>(aEventSourceHandle);
       
   216     CLAPILandmarkStoreManager* manager =
       
   217         reinterpret_cast< CLAPILandmarkStoreManager*>(aManagerHandle);
       
   218     CLAPILandmarkStore* landmarkStore =
       
   219         reinterpret_cast< CLAPILandmarkStore*>(aStoreHandle);
       
   220 
       
   221     eventSource->ExecuteV(
       
   222         RemoveLandmarkStore,
       
   223         manager,
       
   224         landmarkStore);
       
   225 }
       
   226 
       
   227 LOCAL_C void ListStoresL(JNIEnv *aJniEnv, CLAPILandmarkStoreManager* aManager,
       
   228                          jobjectArray* aStoreUris)
       
   229 {
       
   230     JELOG2(EJavaLocation);
       
   231 
       
   232     // Get an array of landmark store uris from the manager
       
   233     CDesCArray* stores = aManager->LandmarkStoresL();
       
   234     CleanupStack::PushL(stores);
       
   235 
       
   236     // Create a java object array from the store uris: Java-side takes
       
   237     // the ownership of the new object array
       
   238     *aStoreUris = CopyToNewJavaStringArrayL(*aJniEnv, *stores);
       
   239     CleanupStack::PopAndDestroy(stores);
       
   240 }
       
   241 
       
   242 /*
       
   243  * Class:     com_nokia_microedition_location_LandmarkStoreManager
       
   244  * Method:    _listStores
       
   245  * Signature: (II)[Ljava/lang/String;
       
   246  */
       
   247 JNIEXPORT jobjectArray
       
   248 JNICALL Java_com_nokia_mj_impl_location_LandmarkStoreManager__1listStores(
       
   249     JNIEnv* aJniEnv,
       
   250     jobject /*aPeer*/,
       
   251     jint aEventSourceHandle,
       
   252     jint aManagerHandle,
       
   253     jintArray aErrors)
       
   254 {
       
   255     JELOG2(EJavaLocation);
       
   256 
       
   257     LocationFunctionServer* eventSource =
       
   258         reinterpret_cast< LocationFunctionServer*>(aEventSourceHandle);
       
   259     CLAPILandmarkStoreManager* manager =
       
   260         reinterpret_cast< CLAPILandmarkStoreManager*>(aManagerHandle);
       
   261 
       
   262     // Ownership of the name array is transferred to Java side
       
   263     jobjectArray javaStringArray = NULL;
       
   264 
       
   265     TInt error = eventSource->ExecuteTrap(
       
   266                      ListStoresL,
       
   267                      eventSource->getValidJniEnv(),
       
   268                      manager,
       
   269                      &javaStringArray);
       
   270 
       
   271     LOG1(EJavaLocation,EInfo, "Java_com_nokia_microedition_location_LandmarkStoreManager__1listStores - error %d", error);
       
   272 
       
   273     SetJavaErrorCode(*aJniEnv, aErrors, error);
       
   274     return javaStringArray;
       
   275 }
       
   276 
       
   277 /*
       
   278  * Class:     com_nokia_microedition_location_LandmarkStoreManager
       
   279  * Method:    _dispose
       
   280  * Signature: (II)V
       
   281  */
       
   282 JNIEXPORT void
       
   283 JNICALL Java_com_nokia_mj_impl_location_LandmarkStoreManager__1dispose(
       
   284     JNIEnv* /*aJniEnv*/,
       
   285     jobject /*aPeer*/,
       
   286     jint /*aFunctionServerHandle*/,
       
   287     jint aManagerHandle)
       
   288 {
       
   289     JELOG2(EJavaLocation);
       
   290 
       
   291     CBase* object = reinterpret_cast< CBase*>(aManagerHandle);
       
   292     delete object;
       
   293 }
       
   294 
       
   295 // End of file