locationmapnavfw/library/src/mnproviderimpl.cpp
branchRCL_3
changeset 44 2b4ea9893b66
parent 42 02ba3f1733c6
child 45 6b6920c56e2f
equal deleted inserted replaced
42:02ba3f1733c6 44:2b4ea9893b66
     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:  CMnProviderImpl class implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <e32base.h>
       
    20 #include <ecom/ecom.h>
       
    21 #ifndef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    22 #include <apaid.h>
       
    23 #else
       
    24 #include <apaid.h>
       
    25 #include <apaidpartner.h>
       
    26 #endif
       
    27 #include <apgcli.h>
       
    28 #include <swi/sisregistryentry.h>
       
    29 #include <swi/sistruststatus.h>
       
    30 #include <swi/sisregistrypackage.h>
       
    31 
       
    32 #include "mnserviceclientbase.h"
       
    33 #include "mnappserviceuids.hrh"
       
    34 
       
    35 #include "mnpluginuids.hrh"
       
    36 #include "mnproviderimpl.h"
       
    37 
       
    38 #include "mndebug.h"
       
    39 
       
    40 // ======== LOCAL FUNCTIONS ========
       
    41 
       
    42 extern TUid ServiceUid( CMnProvider::TService aService );
       
    43 
       
    44 // ---------------------------------------------------------------------------
       
    45 //  Cleanup item for RImplInfoPtrArray
       
    46 // ---------------------------------------------------------------------------
       
    47 //
       
    48 void CleanupImplementationsArray( TAny* aArray )
       
    49     {
       
    50     ( static_cast<RImplInfoPtrArray*>( aArray ) )->ResetAndDestroy();
       
    51     }
       
    52 
       
    53 // ======== MEMBER FUNCTIONS ========
       
    54 
       
    55 // ---------------------------------------------------------------------------
       
    56 // ---------------------------------------------------------------------------
       
    57 //
       
    58 CMnProviderImpl::CMnProviderImpl()
       
    59     {
       
    60     }
       
    61 
       
    62 // ---------------------------------------------------------------------------
       
    63 // ---------------------------------------------------------------------------
       
    64 //
       
    65 CMnProviderImpl::~CMnProviderImpl()
       
    66     {
       
    67     delete iName;
       
    68     delete iShortName;
       
    69     delete iVendorName;
       
    70     REComSession::FinalClose();    
       
    71     }
       
    72 
       
    73 // ---------------------------------------------------------------------------
       
    74 // ---------------------------------------------------------------------------
       
    75 //
       
    76 CMnProviderImpl* CMnProviderImpl::NewL( TUid aProvider )
       
    77     {
       
    78     CMnProviderImpl* self = new(ELeave) CMnProviderImpl;
       
    79     CleanupStack::PushL( self );
       
    80     self->ConstructL( aProvider );
       
    81     CleanupStack::Pop( self );
       
    82     return self;
       
    83     }
       
    84 
       
    85 // ---------------------------------------------------------------------------
       
    86 // ---------------------------------------------------------------------------
       
    87 //
       
    88 CMnProviderImpl* CMnProviderImpl::NewL(
       
    89     TUid aAppUid, 
       
    90     RApaLsSession& aApaSession, 
       
    91     Swi::RSisRegistrySession& aSisSession )
       
    92     {
       
    93     CMnProviderImpl* self = new(ELeave) CMnProviderImpl;
       
    94     CleanupStack::PushL( self );
       
    95     self->ConstructL( aAppUid, aApaSession, aSisSession );
       
    96     CleanupStack::Pop( self );
       
    97     return self;
       
    98     }
       
    99 
       
   100 // ---------------------------------------------------------------------------
       
   101 // ---------------------------------------------------------------------------
       
   102 //
       
   103 void CMnProviderImpl::ConstructL( TUid aProvider )
       
   104     {
       
   105     RApaLsSession apa;
       
   106     User::LeaveIfError( apa.Connect() );
       
   107     CleanupClosePushL( apa );
       
   108 
       
   109     Swi::RSisRegistrySession sis;
       
   110     User::LeaveIfError( sis.Connect() );
       
   111     CleanupClosePushL( sis );
       
   112 
       
   113     ConstructL( aProvider, apa, sis );
       
   114     
       
   115     CleanupStack::PopAndDestroy( &sis );
       
   116     CleanupStack::PopAndDestroy( &apa );
       
   117     }
       
   118     
       
   119 // ---------------------------------------------------------------------------
       
   120 // ---------------------------------------------------------------------------
       
   121 //
       
   122 void CMnProviderImpl::ConstructL(
       
   123     TUid aAppUid, 
       
   124     RApaLsSession& aApaSession, 
       
   125     Swi::RSisRegistrySession& aSisSession )
       
   126     {
       
   127     iUid = aAppUid;
       
   128     ReadAppArcInfoL( aApaSession );
       
   129     ReadServiceFeaturesL( aApaSession );
       
   130     ReadPackageInfoL( aSisSession );
       
   131     }
       
   132 
       
   133 // ---------------------------------------------------------------------------
       
   134 // ---------------------------------------------------------------------------
       
   135 //
       
   136 void CMnProviderImpl::ReadAppArcInfoL( RApaLsSession& aApa )
       
   137     {
       
   138     LOG("CMnProviderImpl::ReadAppArcInfoL");
       
   139     
       
   140     TApaAppInfo appInfo;
       
   141     User::LeaveIfError( aApa.GetAppInfo( appInfo, iUid ) );
       
   142     
       
   143     SetNameL( appInfo.iCaption );
       
   144     SetShortNameL( appInfo.iShortCaption );
       
   145     
       
   146     // get additional data from SERVICE_INFO structs
       
   147     
       
   148     const TInt KGranularity = 8;
       
   149     CArrayFixFlat< TUid >* serviceUids = 
       
   150         new (ELeave) CArrayFixFlat< TUid > ( KGranularity );
       
   151     CleanupStack::PushL( serviceUids );
       
   152         
       
   153     aApa.GetAppServicesL( iUid, *serviceUids );
       
   154     
       
   155     for ( TInt s = 0; s < serviceUids->Count(); s++ )
       
   156         {
       
   157         switch ( (*serviceUids)[s].iUid )
       
   158             {
       
   159             case KMnAppMapViewService:
       
   160                 iServices |= EServiceMapView;
       
   161                 break;
       
   162             case KMnAppNavigationService:
       
   163                 iServices |= EServiceNavigation;
       
   164                 break;
       
   165             case KMnAppGeocodingService:
       
   166                 iServices |= EServiceGeocoding;
       
   167                 break;
       
   168             case KMnAppMapImageService:
       
   169                 iServices |= EServiceMapImage;
       
   170                 break;
       
   171             }
       
   172         }
       
   173 
       
   174     CleanupStack::PopAndDestroy( serviceUids );
       
   175     }
       
   176 
       
   177 // ---------------------------------------------------------------------------
       
   178 // ---------------------------------------------------------------------------
       
   179 //
       
   180 TBool CMnProviderImpl::ReadMnServiceInfoL(
       
   181     RApaLsSession& aApaSession, 
       
   182     TUid aServiceUid, 
       
   183     TMnAppServiceInfo& aServiceInfo)
       
   184     {
       
   185     LOG1("CMnProviderImpl::ReadMnServiceInfoL appSvcUid 0x%X", aServiceUid.iUid);
       
   186 
       
   187     TBool found = EFalse;
       
   188 
       
   189     CApaAppServiceInfoArray* infoArray = aApaSession.GetAppServiceOpaqueDataLC( iUid, aServiceUid );
       
   190     if ( infoArray )
       
   191         {
       
   192         TArray< TApaAppServiceInfo > array = infoArray->Array();
       
   193         for ( TInt i = 0; i < array.Count(); i++ )
       
   194             {
       
   195             TPtrC8 ptr = array[i].OpaqueData();
       
   196             
       
   197             if ( ptr.Size() == sizeof ( TMnAppServiceInfo ) )
       
   198                 {
       
   199                 memcpy(&aServiceInfo, ptr.Ptr(), sizeof ( TMnAppServiceInfo ) );
       
   200                 found = ETrue;
       
   201                 break;
       
   202                 }
       
   203             }
       
   204         }
       
   205 
       
   206     CleanupStack::PopAndDestroy( infoArray );            
       
   207     return found;
       
   208     }
       
   209 
       
   210 // ---------------------------------------------------------------------------
       
   211 // ---------------------------------------------------------------------------
       
   212 //
       
   213 void CMnProviderImpl::CheckServiceFeaturesL( 
       
   214     RApaLsSession& aApaSession,
       
   215     CMnProvider::TService aService, 
       
   216     TUint32& aServiceFeatures )
       
   217     {
       
   218     TMnAppServiceInfo info;
       
   219     TBool found = ReadMnServiceInfoL( aApaSession, ServiceUid( aService ), info );
       
   220     if ( found && info.iServiceFeatures )
       
   221         {
       
   222         aServiceFeatures = info.iServiceFeatures;
       
   223         }
       
   224     else
       
   225         {
       
   226         iServices &= ~aService;
       
   227         }
       
   228     }
       
   229 
       
   230 // ---------------------------------------------------------------------------
       
   231 // ---------------------------------------------------------------------------
       
   232 //
       
   233 void CMnProviderImpl::ReadServiceFeaturesL( RApaLsSession& aApaSession )
       
   234     {
       
   235     if ( iServices & EServiceMapView )
       
   236         {
       
   237         CheckServiceFeaturesL( aApaSession, EServiceMapView, iMapViewFeatures );
       
   238         }
       
   239 
       
   240     if ( iServices & EServiceNavigation )
       
   241         {
       
   242         CheckServiceFeaturesL( aApaSession, EServiceNavigation, iNavigationFeatures );
       
   243         }
       
   244 
       
   245     if ( iServices & EServiceGeocoding )
       
   246         {
       
   247         CheckServiceFeaturesL( aApaSession, EServiceGeocoding, iGeocodingFeatures );
       
   248         }
       
   249 
       
   250     if ( iServices & EServiceMapImage )
       
   251         {
       
   252         CheckServiceFeaturesL( aApaSession, EServiceMapImage, iMapImageFeatures );
       
   253         if ( !IsConverterPluginFoundL() )
       
   254             {
       
   255             iServices &= ~EServiceMapImage;
       
   256             iMapImageFeatures = 0;
       
   257             }
       
   258         }
       
   259     }
       
   260 
       
   261 // ---------------------------------------------------------------------------
       
   262 // ---------------------------------------------------------------------------
       
   263 //
       
   264 #ifndef __WINS__
       
   265 
       
   266 void CMnProviderImpl::ReadPackageInfoL( Swi::RSisRegistrySession& aSisSession )
       
   267     {
       
   268     LOG("CMnProviderImpl::ReadPackageInfoL");
       
   269 
       
   270     Swi::CSisRegistryPackage* package = aSisSession.SidToPackageL(iUid);
       
   271     CleanupStack::PushL( package );
       
   272     
       
   273     Swi::RSisRegistryEntry entry;
       
   274     User::LeaveIfError( entry.OpenL( aSisSession, *package ) );
       
   275     CleanupClosePushL( entry );
       
   276     
       
   277     // FW wants to know trust level of Provider Applications
       
   278     Swi::TSisTrustStatus trust = entry.TrustStatusL();
       
   279     iIsTrusted = ( trust.ValidationStatus() >= Swi::EValidatedToAnchor );
       
   280         
       
   281     // other needed info
       
   282     SetVersion( entry.VersionL() );
       
   283     
       
   284     HBufC* vendorName = entry.LocalizedVendorNameL();
       
   285     CleanupStack::PushL( vendorName );
       
   286     SetVendorNameL( vendorName->Des() );
       
   287     CleanupStack::PopAndDestroy( vendorName );
       
   288 
       
   289     CleanupStack::PopAndDestroy( &entry );
       
   290     CleanupStack::PopAndDestroy( package );
       
   291     }
       
   292 
       
   293 #else
       
   294 
       
   295 void CMnProviderImpl::ReadPackageInfoL( Swi::RSisRegistrySession& /*aSisSession */ )
       
   296     {
       
   297     LOG("CMnProviderImpl::ReadPackageInfoL");
       
   298     iIsTrusted = ETrue;
       
   299     }
       
   300 
       
   301 #endif
       
   302 
       
   303 // ---------------------------------------------------------------------------
       
   304 // ---------------------------------------------------------------------------
       
   305 //
       
   306 TBool CMnProviderImpl::IsTrusted()
       
   307     {
       
   308     return iIsTrusted;
       
   309     }
       
   310 
       
   311 // ---------------------------------------------------------------------------
       
   312 // ---------------------------------------------------------------------------
       
   313 //
       
   314 TBool CMnProviderImpl::IsConverterPluginFoundL()
       
   315     {
       
   316     TUid converterIf = { KMnMapImageConverterIf };
       
   317 
       
   318     const TInt KNumUidHexDigits = 8;
       
   319     TBuf8<KNumUidHexDigits> uidText8;
       
   320     
       
   321     _LIT8( KUidHexText, "%08X" );
       
   322     uidText8.Format( KUidHexText, iUid );
       
   323 
       
   324     TEComResolverParams resolverParams;
       
   325     resolverParams.SetDataType( uidText8 );
       
   326 
       
   327     RImplInfoPtrArray implementations;
       
   328     CleanupStack::PushL( TCleanupItem( CleanupImplementationsArray, &implementations ) );
       
   329     
       
   330     REComSession::ListImplementationsL( converterIf, resolverParams, implementations );
       
   331     TBool found = ( implementations.Count() > 0 );
       
   332     CleanupStack::PopAndDestroy(); // cleanup item    
       
   333     return found;
       
   334     }
       
   335 
       
   336 // ---------------------------------------------------------------------------
       
   337 // ---------------------------------------------------------------------------
       
   338 //
       
   339 void CMnProviderImpl::SetNameL( const TDesC& aName )
       
   340     {
       
   341     __ASSERT_DEBUG( !iName, Panic( KErrGeneral ) );
       
   342     iName = aName.AllocL();
       
   343     }
       
   344     
       
   345 // ---------------------------------------------------------------------------
       
   346 // ---------------------------------------------------------------------------
       
   347 //
       
   348 void CMnProviderImpl::SetShortNameL( const TDesC& aShortName )
       
   349     {
       
   350     __ASSERT_DEBUG( !iShortName, Panic( KErrGeneral ) );
       
   351     iShortName = aShortName.AllocL();
       
   352     }
       
   353     
       
   354 // ---------------------------------------------------------------------------
       
   355 // ---------------------------------------------------------------------------
       
   356 //
       
   357 void CMnProviderImpl::SetVendorNameL( const TDesC& aVendorName )
       
   358     {
       
   359     __ASSERT_DEBUG( !iVendorName, Panic( KErrGeneral ) );
       
   360     iVendorName = aVendorName.AllocL();
       
   361     }
       
   362     
       
   363 // ---------------------------------------------------------------------------
       
   364 // ---------------------------------------------------------------------------
       
   365 //
       
   366 void CMnProviderImpl::SetVersion( TVersion aVersion )
       
   367     {
       
   368     iVersion = aVersion;
       
   369     }
       
   370     
       
   371 // ---------------------------------------------------------------------------
       
   372 // ---------------------------------------------------------------------------
       
   373 //
       
   374 void CMnProviderImpl::SetSupportedServices( TServices aServices )
       
   375     {
       
   376     iServices = aServices;
       
   377     }
       
   378     
       
   379 // ---------------------------------------------------------------------------
       
   380 // From class CMnProvider.
       
   381 // ---------------------------------------------------------------------------
       
   382 //
       
   383 TUint32 CMnProviderImpl::SupportedFeatures( TService aService ) const
       
   384     {
       
   385     switch ( aService )
       
   386         {
       
   387         case EServiceMapView:
       
   388             return iMapViewFeatures;
       
   389             
       
   390         case EServiceNavigation:
       
   391             return iNavigationFeatures;
       
   392             
       
   393         case EServiceGeocoding:
       
   394             return iGeocodingFeatures;
       
   395 
       
   396         case EServiceMapImage:
       
   397             return iMapImageFeatures;
       
   398 
       
   399         default:
       
   400             return 0;
       
   401         }
       
   402     }