locationmapnavfw/library/src/mnproviderfinder.cpp
changeset 0 667063e416a2
equal deleted inserted replaced
-1:000000000000 0:667063e416a2
       
     1 /*
       
     2 * Copyright (c) 2005-2006 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:  MnProviderFinder class implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <e32base.h>
       
    20 #include <apgcli.h>
       
    21 
       
    22 #include "mnappserviceuids.hrh"
       
    23 
       
    24 #include "mnproviderimpl.h"
       
    25 #include "mnproviderfinder.h"
       
    26 
       
    27 #include "mndebug.h"
       
    28 
       
    29 // ======== LOCAL FUNCTIONS ========
       
    30 
       
    31 // ---------------------------------------------------------------------------
       
    32 //  Cleanup item for RPointerArray<CMnProviderImpl>
       
    33 // ---------------------------------------------------------------------------
       
    34 //
       
    35 void CleanupPointerArray(TAny* aArray)
       
    36     {
       
    37     ( static_cast<RPointerArray<CMnProviderImpl>*>( aArray ) )->ResetAndDestroy();
       
    38     }
       
    39 
       
    40 // ---------------------------------------------------------------------------
       
    41 //  Finds service UID for given CMnProvider::TService
       
    42 // ---------------------------------------------------------------------------
       
    43 //
       
    44 TUid ServiceUid( CMnProvider::TService aService )
       
    45     {
       
    46     switch ( aService )
       
    47         {
       
    48         case CMnProvider::EServiceMapView:
       
    49             return TUid::Uid( KMnAppMapViewService );
       
    50 
       
    51         case CMnProvider::EServiceNavigation:
       
    52             return TUid::Uid( KMnAppNavigationService );
       
    53 
       
    54         case CMnProvider::EServiceGeocoding:
       
    55             return TUid::Uid( KMnAppGeocodingService );
       
    56 
       
    57         case CMnProvider::EServiceMapImage:
       
    58             return TUid::Uid( KMnAppMapImageService );
       
    59 
       
    60         default:
       
    61             return TUid::Uid( 0 );
       
    62         }
       
    63     }
       
    64 
       
    65 // ---------------------------------------------------------------------------
       
    66 //  Finds provider in given list by UID
       
    67 // ---------------------------------------------------------------------------
       
    68 //
       
    69 TInt FindProviderByUid( TUid aAppUid, RPointerArray<CMnProvider>& aProviders )
       
    70     {
       
    71     for (TInt i = 0; i < aProviders.Count(); i++)
       
    72         {
       
    73         if ( aProviders[i]->Uid().iUid == aAppUid.iUid )
       
    74             return i;
       
    75         }
       
    76     return KErrNotFound;
       
    77     }
       
    78 
       
    79 // ---------------------------------------------------------------------------
       
    80 // ---------------------------------------------------------------------------
       
    81 //
       
    82 void FindAllServiceProvidersL(
       
    83     RPointerArray<CMnProvider>& aProviders,
       
    84     CMnProvider::TServices aServices )
       
    85     {
       
    86     LOG("FindAllServiceProvidersL in");
       
    87 
       
    88     RApaLsSession apa;
       
    89     User::LeaveIfError( apa.Connect() );
       
    90     CleanupClosePushL( apa );
       
    91 
       
    92     Swi::RSisRegistrySession sis;
       
    93     User::LeaveIfError( sis.Connect() );
       
    94     CleanupClosePushL( sis );
       
    95 
       
    96     const CMnProvider::TService KKnownServices[] =
       
    97         {
       
    98         CMnProvider::EServiceMapView,
       
    99         CMnProvider::EServiceNavigation,
       
   100         CMnProvider::EServiceGeocoding,
       
   101         CMnProvider::EServiceMapImage
       
   102         };
       
   103     const TInt KNumKnownServices = sizeof( KKnownServices ) / sizeof ( CMnProvider::TService );
       
   104 
       
   105     // find all providers for known services
       
   106     for ( TInt i = 0; i < KNumKnownServices; i++ )
       
   107         {
       
   108         // but consider only required services
       
   109         if ( aServices & KKnownServices[i] )
       
   110             {
       
   111             TInt err = apa.GetServerApps( ServiceUid( KKnownServices[i] ) );
       
   112             while ( !err )
       
   113                 {
       
   114                 TApaAppInfo app;
       
   115                 err = apa.GetNextApp(app);
       
   116                 if ( !err )
       
   117                     {
       
   118                     // add this app to the list, if not added yet
       
   119                     TInt index = FindProviderByUid( app.iUid, aProviders );
       
   120                     if ( index == KErrNotFound )
       
   121                         {
       
   122                         // add new provider to the list
       
   123                         LOG2("found new provider candidate uid{%08X}, name{%S}", 
       
   124                             app.iUid.iUid, &app.iFullName);
       
   125 
       
   126                         // find all data about this provider
       
   127                         CMnProviderImpl* provider = NULL;
       
   128                         TRAP( err, provider = CMnProviderImpl::NewL( app.iUid, apa, sis ) );
       
   129                         if ( !err )
       
   130                             {
       
   131                             if ( provider->IsTrusted() )
       
   132                                 {
       
   133                                 CleanupStack::PushL( provider );
       
   134                                 aProviders.AppendL( provider );
       
   135                                 CleanupStack::Pop( provider );
       
   136                                 }
       
   137                             else
       
   138                                 {
       
   139                                 delete provider;
       
   140                                 LOG1("untrusted provider uid{%X}", app.iUid.iUid);
       
   141                                 }
       
   142                             }
       
   143                         else
       
   144                             {
       
   145                             // skip provider if cannot be constructed
       
   146                             LOG2("construction failed for uid{%X}, error %d", app.iUid.iUid, err);
       
   147                             }
       
   148                         }
       
   149                     }
       
   150                 }
       
   151             }
       
   152         }
       
   153 
       
   154     CleanupStack::PopAndDestroy( &sis );
       
   155     CleanupStack::PopAndDestroy( &apa );
       
   156 
       
   157     LOG("FindAllServiceProvidersL out");
       
   158     }
       
   159 
       
   160 // ======== MEMBER FUNCTIONS ========
       
   161 
       
   162 // ---------------------------------------------------------------------------
       
   163 // ---------------------------------------------------------------------------
       
   164 //
       
   165 EXPORT_C void MnProviderFinder::FindProvidersL(
       
   166     RPointerArray<CMnProvider>& aProviders)
       
   167     {
       
   168     CMnProvider::TServices allServices =
       
   169         CMnProvider::EServiceMapView |
       
   170         CMnProvider::EServiceNavigation |
       
   171         CMnProvider::EServiceGeocoding |
       
   172         CMnProvider::EServiceMapImage;
       
   173 
       
   174     FindAllServiceProvidersL( aProviders, allServices );
       
   175     }
       
   176 
       
   177 // ---------------------------------------------------------------------------
       
   178 // ---------------------------------------------------------------------------
       
   179 //
       
   180 EXPORT_C void MnProviderFinder::FindProvidersL(
       
   181     RPointerArray<CMnProvider>& aProviders,
       
   182     CMnProvider::TServices aRequiredServices)
       
   183     {
       
   184     FindAllServiceProvidersL( aProviders, aRequiredServices );
       
   185 
       
   186     // verify that providers meet service support requirements
       
   187     for ( TInt i = aProviders.Count() - 1; i >= 0; i-- )
       
   188         {
       
   189         CMnProvider* provider = aProviders[i];
       
   190         
       
   191         if ( ( provider->SupportedServices() & aRequiredServices ) != aRequiredServices )
       
   192             {
       
   193             aProviders.Remove( i );
       
   194             delete provider;
       
   195             }
       
   196         }
       
   197     }
       
   198