landmarks/locationlandmarks/tsrc/LandmarkTestModule/TestProvider/src/CDbManTestPluginBase.cpp
branchRCL_3
changeset 44 2b4ea9893b66
equal deleted inserted replaced
42:02ba3f1733c6 44:2b4ea9893b66
       
     1 /*
       
     2 * Copyright (c) 2005 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: 
       
    15 *   ?description_line
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 //#include <EPos_PosLmDbInfoExtension.h>
       
    23 #include "CDbManTestPluginBase.h"
       
    24 #include "FT_RPosLandmarkServer.h"
       
    25 
       
    26 
       
    27 // CONSTANTS
       
    28 _LIT(KPluginProtocol, "test");
       
    29 
       
    30 // MEMBER FUNCTIONS
       
    31 
       
    32 // Destructor
       
    33 CDbManTestPluginBase::~CDbManTestPluginBase()
       
    34     {
       
    35     iDatabases.ResetAndDestroy();
       
    36     }
       
    37 
       
    38 CDbManTestPluginBase::CDbManTestPluginBase()
       
    39     {
       
    40     }
       
    41 
       
    42 // -----------------------------------------------------------------------------
       
    43 // CDbManTestPluginBase::NewL
       
    44 // Two-phased constructor.
       
    45 // -----------------------------------------------------------------------------
       
    46 //
       
    47 CDbManTestPluginBase* CDbManTestPluginBase::NewL(TAny* aConstructionParams)
       
    48     {
       
    49     CDbManTestPluginBase* self = new( ELeave ) CDbManTestPluginBase;
       
    50     CleanupStack::PushL(self);
       
    51     self->BaseConstructL(aConstructionParams);
       
    52     CleanupStack::Pop(self);
       
    53     return self;
       
    54 
       
    55     }
       
    56  
       
    57 // ---------------------------------------------------------
       
    58 // CDbManTestPluginBase::ListDatabasesLC
       
    59 //
       
    60 // (other items were commented in a header).
       
    61 // ---------------------------------------------------------
       
    62 //
       
    63 CDesCArray* CDbManTestPluginBase::ListDatabasesLC() 
       
    64     {
       
    65     TInt count = iDatabases.Count();
       
    66     CDesCArrayFlat* result = 
       
    67        new(ELeave) CDesCArrayFlat(count == 0 ? 1 : count);
       
    68     CleanupStack::PushL(result);
       
    69 
       
    70     for (TInt i = 0; i < count; i++)
       
    71         {
       
    72         result->AppendL(iDatabases[i]->DatabaseUri());
       
    73         }
       
    74     return result;
       
    75     }
       
    76 
       
    77 // ---------------------------------------------------------
       
    78 // CDbManTestPluginBase::ListDatabasesL
       
    79 //
       
    80 // (other items were commented in a header).
       
    81 // ---------------------------------------------------------
       
    82 //
       
    83 void CDbManTestPluginBase::ListDatabasesL(
       
    84                RPointerArray<HPosLmDatabaseInfo>& aDatabaseInfoArray
       
    85         ) 
       
    86     {
       
    87     TInt count = iDatabases.Count();
       
    88 
       
    89     for (TInt i = 0; i < count; i++)
       
    90         {
       
    91         HPosLmDatabaseInfo* tmpDbInfo = 
       
    92             HPosLmDatabaseInfo::NewLC(*(iDatabases[i]));
       
    93         aDatabaseInfoArray.AppendL(tmpDbInfo);
       
    94         CleanupStack::Pop(tmpDbInfo);
       
    95         }
       
    96     }
       
    97 
       
    98 // ---------------------------------------------------------
       
    99 // CDbManTestPluginBase::RegisterDatabaseL
       
   100 //
       
   101 // (other items were commented in a header).
       
   102 // ---------------------------------------------------------
       
   103 //
       
   104 void CDbManTestPluginBase::RegisterDatabaseL(
       
   105                HPosLmDatabaseInfo& aDatabaseInfo
       
   106         ) 
       
   107     {
       
   108     if (DatabaseExistsL(aDatabaseInfo.DatabaseUri()))
       
   109         {
       
   110         User::Leave(KErrAlreadyExists);
       
   111         }
       
   112     HPosLmDatabaseInfo* tmpDbInfo = 
       
   113         HPosLmDatabaseInfo::NewLC(aDatabaseInfo);
       
   114     iDatabases.AppendL(tmpDbInfo);
       
   115     CleanupStack::Pop(tmpDbInfo);
       
   116     
       
   117     TPosLmDatabaseEvent event;
       
   118     event.iEventType = EPosLmDbDatabaseRegistered;
       
   119     Session().ReportEvent(event, aDatabaseInfo.DatabaseUri());    
       
   120     }
       
   121 
       
   122 // ---------------------------------------------------------
       
   123 // CDbManTestPluginBase::UnregisterDatabaseL
       
   124 //
       
   125 // (other items were commented in a header).
       
   126 // ---------------------------------------------------------
       
   127 //
       
   128 void CDbManTestPluginBase::UnregisterDatabaseL(
       
   129                const TDesC& aDatabaseUri
       
   130         ) 
       
   131     {
       
   132     TInt index = FindUri(aDatabaseUri);
       
   133     User::LeaveIfError(index);
       
   134     delete iDatabases[index];
       
   135     iDatabases.Remove(index);
       
   136     
       
   137     TPosLmDatabaseEvent event;
       
   138     event.iEventType = EPosLmDbDatabaseUnregistered;
       
   139     Session().ReportEvent(event, aDatabaseUri);
       
   140     }
       
   141 
       
   142 // ---------------------------------------------------------
       
   143 // CDbManTestPluginBase::UnregisterAllDatabasesL
       
   144 //
       
   145 // (other items were commented in a header).
       
   146 // ---------------------------------------------------------
       
   147 //
       
   148 void CDbManTestPluginBase::UnregisterAllDatabasesL() 
       
   149     {
       
   150     iDatabases.ResetAndDestroy();
       
   151     }
       
   152 
       
   153 // ---------------------------------------------------------
       
   154 // CDbManTestPluginBase::ModifyDatabaseSettingsL
       
   155 //
       
   156 // (other items were commented in a header).
       
   157 // ---------------------------------------------------------
       
   158 //
       
   159 void CDbManTestPluginBase::ModifyDatabaseSettingsL(
       
   160                const TDesC& aDatabaseUri,
       
   161                const TPosLmDatabaseSettings& aDatabaseSettings
       
   162         ) 
       
   163     {
       
   164     TInt index = FindUri(aDatabaseUri);
       
   165     User::LeaveIfError(index);
       
   166     iDatabases[index]->Settings() = aDatabaseSettings;
       
   167     
       
   168     TPosLmDatabaseEvent event;
       
   169     event.iEventType = EPosLmDbSettingsModified;
       
   170     Session().ReportEvent(event, aDatabaseUri);
       
   171     }
       
   172 
       
   173 // ---------------------------------------------------------
       
   174 // CDbManTestPluginBase::GetDatabaseInfoL
       
   175 //
       
   176 // (other items were commented in a header).
       
   177 // ---------------------------------------------------------
       
   178 //
       
   179 void CDbManTestPluginBase::GetDatabaseInfoL(
       
   180             HPosLmDatabaseInfo& aDatabaseInfo
       
   181         ) 
       
   182     {
       
   183     TInt index = FindUri(aDatabaseInfo.DatabaseUri());
       
   184     User::LeaveIfError(index);
       
   185     HPosLmDatabaseInfo* dbInfo = iDatabases[index];
       
   186     aDatabaseInfo.Settings() = dbInfo->Settings();
       
   187     }
       
   188 
       
   189 // ---------------------------------------------------------
       
   190 // CDbManTestPluginBase::DatabaseExistsL
       
   191 //
       
   192 // (other items were commented in a header).
       
   193 // ---------------------------------------------------------
       
   194 //
       
   195 TBool CDbManTestPluginBase::DatabaseExistsL( 
       
   196                const TDesC&  aDatabaseUri
       
   197         ) 
       
   198     {
       
   199     return FindUri(aDatabaseUri) >= 0 ? ETrue : EFalse;
       
   200     }
       
   201 
       
   202 // ---------------------------------------------------------
       
   203 // CDbManTestPluginBase::CreateDatabaseL
       
   204 //
       
   205 // (other items were commented in a header).
       
   206 // ---------------------------------------------------------
       
   207 //
       
   208 void CDbManTestPluginBase::CreateDatabaseL( 
       
   209                HPosLmDatabaseInfo& aDatabaseInfo
       
   210         ) 
       
   211     {
       
   212     // Do nothing
       
   213     //RegisterDatabaseL(aDatabaseInfo);
       
   214     //
       
   215     }
       
   216 
       
   217 // ---------------------------------------------------------
       
   218 // CDbManTestPluginBase::DeleteDatabaseL
       
   219 //
       
   220 // (other items were commented in a header).
       
   221 // ---------------------------------------------------------
       
   222 //
       
   223 void CDbManTestPluginBase::DeleteDatabaseL(
       
   224                const TDesC&  aDatabaseUri
       
   225         ) 
       
   226     {
       
   227     UnregisterDatabaseL(aDatabaseUri);
       
   228     }
       
   229 
       
   230 // ---------------------------------------------------------
       
   231 // CDbManTestPluginBase::CopyDatabaseL
       
   232 //
       
   233 // (other items were commented in a header).
       
   234 // ---------------------------------------------------------
       
   235 //
       
   236 void CDbManTestPluginBase::CopyDatabaseL(
       
   237                const TDesC&  aSourceUri,
       
   238                const TDesC&  aTargetUri
       
   239         ) 
       
   240     {
       
   241     TInt srcIndex = FindUri(aSourceUri);
       
   242     User::LeaveIfError(srcIndex);
       
   243     TInt trgIndex = FindUri(aTargetUri);
       
   244     if (trgIndex >= 0)
       
   245         {
       
   246         User::Leave(KErrAlreadyExists);
       
   247         }
       
   248     HPosLmDatabaseInfo* trgInfo = 
       
   249         HPosLmDatabaseInfo::NewLC(aTargetUri);
       
   250     iDatabases.AppendL(trgInfo);
       
   251     CleanupStack::Pop(trgInfo);
       
   252     }
       
   253     
       
   254 // ---------------------------------------------------------
       
   255 // CDbManTestPluginBase::DatabaseMedia
       
   256 //
       
   257 // (other items were commented in a header).
       
   258 // ---------------------------------------------------------
       
   259 //
       
   260 TMediaType CDbManTestPluginBase::DatabaseMedia(
       
   261                const TDesC& /* aDatabaseUri */
       
   262         ) 
       
   263     {
       
   264     return EMediaRemote;
       
   265     }
       
   266 
       
   267 // ---------------------------------------------------------
       
   268 // CDbManTestPluginBase::DatabaseDrive
       
   269 //
       
   270 // (other items were commented in a header).
       
   271 // ---------------------------------------------------------
       
   272 //
       
   273 TChar CDbManTestPluginBase::DatabaseDrive(
       
   274                const TDesC& /* aDatabaseUri */
       
   275         ) 
       
   276     {
       
   277     return 'U';
       
   278     }
       
   279     
       
   280 // ---------------------------------------------------------
       
   281 // CDbManTestPluginBase::Protocol
       
   282 //
       
   283 // (other items were commented in a header).
       
   284 // ---------------------------------------------------------
       
   285 //
       
   286 TPtrC CDbManTestPluginBase::Protocol() 
       
   287     {
       
   288     return TPtrC(KPluginProtocol);
       
   289     }
       
   290 
       
   291 // ---------------------------------------------------------
       
   292 // CDbManTestPluginBase::FindUri
       
   293 //
       
   294 // (other items were commented in a header).
       
   295 // ---------------------------------------------------------
       
   296 //
       
   297 TInt CDbManTestPluginBase::FindUri(const TDesC& aUri) 
       
   298     {
       
   299     TInt index;
       
   300     TInt count = iDatabases.Count();
       
   301     TBool found = EFalse;
       
   302     
       
   303     for (index = 0; index < count && !found; index++)
       
   304         {
       
   305         if (aUri.Compare(iDatabases[index]->DatabaseUri()) == 0)
       
   306             {
       
   307             found = ETrue;
       
   308             }
       
   309         }
       
   310     index--;
       
   311 
       
   312     if (!found)
       
   313         {
       
   314         index = KErrNotFound;
       
   315         }
       
   316     return index;
       
   317     }
       
   318 
       
   319 
       
   320 
       
   321 
       
   322 //  End of File