landmarks/locationlandmarks/clientlib/src/EPos_CPosLandmarkDatabase.cpp
changeset 0 667063e416a2
child 8 6fcbaa43369c
equal deleted inserted replaced
-1:000000000000 0:667063e416a2
       
     1 /*
       
     2 * Copyright (c) 2002-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: Handle to a landmark database.
       
    15 *
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #include <ecom/ecom.h>
       
    21 #include <uri16.h>
       
    22 #include "EPos_CPosLandmarkDatabase.h"
       
    23 #include "EPos_LandmarksUids.hrh"
       
    24 
       
    25 
       
    26 // ================= MEMBER FUNCTIONS =======================
       
    27 
       
    28 // -----------------------------------------------------------------------------
       
    29 // -----------------------------------------------------------------------------
       
    30 //
       
    31 EXPORT_C CPosLandmarkDatabase::CPosLandmarkDatabase()
       
    32     {
       
    33     }
       
    34 
       
    35 // -----------------------------------------------------------------------------
       
    36 // -----------------------------------------------------------------------------
       
    37 //
       
    38 EXPORT_C CPosLandmarkDatabase* CPosLandmarkDatabase::OpenL()
       
    39     {
       
    40     TUid implementationUid;
       
    41     implementationUid.iUid = KPosLmLocalDatabaseImplUid;
       
    42 
       
    43     // Check if any implementation supports this protocol
       
    44     TUid interfaceUid;
       
    45     interfaceUid.iUid = KPosLmDatabaseIfUid;
       
    46 
       
    47     RImplInfoPtrArray implInfoArray;
       
    48     REComSession::ListImplementationsL(interfaceUid, implInfoArray);
       
    49     if (implInfoArray.Count() == 0)
       
    50         {
       
    51         User::Leave(KErrNotSupported);
       
    52         }
       
    53     else
       
    54         {
       
    55         implInfoArray.ResetAndDestroy();
       
    56         }
       
    57 
       
    58     TAny* ptr = REComSession::CreateImplementationL(
       
    59         implementationUid,
       
    60         _FOFF(CPosLandmarkDatabase, iDtorIdKey),
       
    61         NULL);
       
    62 
       
    63     return reinterpret_cast<CPosLandmarkDatabase*>(ptr);
       
    64     }
       
    65 
       
    66 // -----------------------------------------------------------------------------
       
    67 // -----------------------------------------------------------------------------
       
    68 //
       
    69 EXPORT_C CPosLandmarkDatabase* CPosLandmarkDatabase::OpenL(
       
    70     const TDesC&  aDatabaseUri)
       
    71     {
       
    72     // Determine which implementation id to use by checking the protocol of
       
    73     // the URI (e.g. http). If no protocol is specified "file" is used.
       
    74     _LIT8(KDefaultProtocol, "file");
       
    75     _LIT(KProtocolDelimiter, "://");
       
    76 
       
    77     TInt position = aDatabaseUri.Find(KProtocolDelimiter);
       
    78 
       
    79     TEComResolverParams params;
       
    80     HBufC8* protocol8 = NULL;
       
    81 
       
    82     if (position != KErrNotFound && position != 0)
       
    83         {
       
    84         protocol8 = HBufC8::NewLC(position + 1);
       
    85         protocol8->Des().FillZ();
       
    86         protocol8->Des().Copy(aDatabaseUri.Left(position));
       
    87         params.SetDataType(*protocol8);
       
    88         }
       
    89     else
       
    90         {
       
    91         params.SetDataType(KDefaultProtocol);
       
    92         }
       
    93 
       
    94     // Check if any implementation supports this protocol
       
    95     TUid interfaceUid;
       
    96     interfaceUid.iUid = KPosLmDatabaseIfUid;
       
    97 
       
    98     RImplInfoPtrArray implInfoArray;
       
    99     REComSession::ListImplementationsL(interfaceUid, params, implInfoArray);
       
   100     if (implInfoArray.Count() == 0)
       
   101         {
       
   102         User::Leave(KErrNotSupported);
       
   103         }
       
   104     else
       
   105         {
       
   106         implInfoArray.ResetAndDestroy();
       
   107         }
       
   108 
       
   109     // Send the protocol name to the Ecom server
       
   110     // which determines the implementation.
       
   111     HBufC* strPtr = aDatabaseUri.AllocLC();
       
   112 
       
   113     TAny* ptr = REComSession::CreateImplementationL(
       
   114         interfaceUid,
       
   115         _FOFF(CPosLandmarkDatabase, iDtorIdKey),
       
   116         strPtr,
       
   117         params);
       
   118 
       
   119     CleanupStack::PopAndDestroy(strPtr);
       
   120 
       
   121     if (protocol8)
       
   122         {
       
   123         CleanupStack::PopAndDestroy(protocol8);
       
   124         }
       
   125 
       
   126     return reinterpret_cast<CPosLandmarkDatabase*>(ptr);
       
   127     }
       
   128 
       
   129 // -----------------------------------------------------------------------------
       
   130 // -----------------------------------------------------------------------------
       
   131 //
       
   132 EXPORT_C CPosLandmarkDatabase::~CPosLandmarkDatabase()
       
   133     {
       
   134     // Destroy any instance variables and then inform the framework that this
       
   135     // specific instance of the interface has been destroyed.
       
   136     REComSession::DestroyedImplementation(iDtorIdKey);
       
   137     }
       
   138 
       
   139 // -----------------------------------------------------------------------------
       
   140 // -----------------------------------------------------------------------------
       
   141 //
       
   142 TUid CPosLandmarkDatabase::ImplementationId() const
       
   143     {
       
   144     return REComSession::GetImplementationUidL (iDtorIdKey);//iDtorIdKey;
       
   145     //return iDtorIdKey;
       
   146     }
       
   147