featuremgmt/featuremgr/src/featdiscovery/featdiscoveryimpl.cpp
changeset 0 08ec8eefde2f
equal deleted inserted replaced
-1:000000000000 0:08ec8eefde2f
       
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 
       
    17 
       
    18 #include <e32cmn.h>
       
    19 #include <featdiscovery.h>
       
    20 #include "featdiscoveryimpl.h"
       
    21 #include "featurecontrol.h"
       
    22 #include "featurecmn.h"
       
    23 
       
    24 // -----------------------------------------------------------------------------
       
    25 // CFeatureDiscoveryImpl::CFeatureDiscoveryImpl* NewL()
       
    26 // -----------------------------------------------------------------------------
       
    27 //
       
    28 CFeatureDiscoveryImpl* CFeatureDiscoveryImpl::NewL()
       
    29     {
       
    30     CFeatureDiscoveryImpl* self = new( ELeave ) CFeatureDiscoveryImpl();
       
    31     CleanupStack::PushL( self );
       
    32     self->ConstructL();
       
    33     CleanupStack::Pop( self );
       
    34 
       
    35     return self;
       
    36     }
       
    37 
       
    38 
       
    39 
       
    40 // ---------------------------------------------------------
       
    41 // CFeatureDiscoveryImpl::ConstructL
       
    42 //
       
    43 // Symbian OS default constructor, initializes variables and cache 
       
    44 // ---------------------------------------------------------
       
    45 //
       
    46 void CFeatureDiscoveryImpl::ConstructL()
       
    47     {
       
    48     TInt err( iFeatControl.Connect() );
       
    49     User::LeaveIfError( err );
       
    50     }
       
    51 
       
    52 
       
    53 // -----------------------------------------------------------------------------
       
    54 // CFeatureDiscoveryImpl::~CFeatureDiscoveryImpl()
       
    55 // -----------------------------------------------------------------------------
       
    56 //
       
    57 CFeatureDiscoveryImpl::~CFeatureDiscoveryImpl()
       
    58     {
       
    59     iFeatControl.Close();
       
    60     }
       
    61 
       
    62 
       
    63 // -----------------------------------------------------------------------------
       
    64 // CFeatureDiscoveryImpl::CFeatureDiscoveryImpl()
       
    65 // -----------------------------------------------------------------------------
       
    66 //
       
    67 CFeatureDiscoveryImpl::CFeatureDiscoveryImpl()
       
    68     {
       
    69     }
       
    70 
       
    71 
       
    72 // -----------------------------------------------------------------------------
       
    73 // CFeatureDiscoveryImpl::IsFeatureSupportedL(TUid)
       
    74 // -----------------------------------------------------------------------------
       
    75 //
       
    76 TBool CFeatureDiscoveryImpl::IsFeatureSupportedL(TUid aFeature)
       
    77     {
       
    78     RFeatureControl featControl;
       
    79     TInt err( featControl.Connect() );
       
    80     User::LeaveIfError( err );
       
    81     TFeatureEntry feature( aFeature );
       
    82     err = featControl.FeatureSupported( feature );
       
    83     featControl.Close();
       
    84     
       
    85     return (( err > 0 ) ? ETrue : EFalse );
       
    86     }
       
    87 
       
    88 // -----------------------------------------------------------------------------
       
    89 // CFeatureDiscoveryImpl::IsSupported(TUid)
       
    90 // -----------------------------------------------------------------------------
       
    91 //
       
    92 TBool CFeatureDiscoveryImpl::IsSupported(TUid aFeature)
       
    93     {
       
    94     TFeatureEntry feature( aFeature );
       
    95     
       
    96     return (( iFeatControl.FeatureSupported( feature ) > 0 ) ? ETrue : EFalse );
       
    97     }
       
    98 
       
    99 // -----------------------------------------------------------------------------
       
   100 // CFeatureDiscoveryImpl::FeaturesSupportedL(TFeatureSet&)
       
   101 // -----------------------------------------------------------------------------
       
   102 //
       
   103 void CFeatureDiscoveryImpl::FeaturesSupportedL( TFeatureSet& aFeatures )
       
   104     {
       
   105     RFeatureControl featControl;
       
   106     CleanupClosePushL( featControl );
       
   107     TInt err( featControl.Connect() );
       
   108     User::LeaveIfError( err );
       
   109     
       
   110     // Construct feature entry array used by feature control
       
   111     RFeatureArray features;
       
   112     CleanupClosePushL( features );
       
   113     TInt count( aFeatures.Count() );
       
   114     
       
   115     for(TInt i(0); i < count; i++)
       
   116         {
       
   117         TFeatureEntry feature( aFeatures.FeatureId( i ) );
       
   118         features.AppendL( feature );
       
   119         }
       
   120 
       
   121     // Fetch feature information from server
       
   122     err = featControl.FeaturesSupported( features );
       
   123     User::LeaveIfError( err );
       
   124 
       
   125     // Refresh count of features after query, non existing features are removed 
       
   126     count = features.Count();
       
   127     // Write information back to format feature discovery uses
       
   128     aFeatures.Reset();
       
   129     
       
   130     for(TInt i(0); i < count; i++)
       
   131         {
       
   132         const TUid uid( features[i].FeatureUid() );
       
   133         const TBool supported( features[i].FeatureFlags().IsSet( EFeatureSupported ) );
       
   134         err = aFeatures.Append( uid, supported );
       
   135         User::LeaveIfError( err );
       
   136         }
       
   137 
       
   138     CleanupStack::PopAndDestroy( &features );
       
   139     CleanupStack::PopAndDestroy( &featControl );
       
   140     }
       
   141 
       
   142 // -----------------------------------------------------------------------------
       
   143 // CFeatureDiscoveryImpl::FeaturesSupported(TFeatureSet&)
       
   144 // -----------------------------------------------------------------------------
       
   145 //
       
   146 TInt CFeatureDiscoveryImpl::FeaturesSupported( TFeatureSet& aFeatures )
       
   147     {
       
   148     // Construct feature entry array used by feature control
       
   149     TInt err( KErrNone );
       
   150     RFeatureArray features;
       
   151     TInt count( aFeatures.Count() );
       
   152     
       
   153     for(TInt i(0); i < count; i++)
       
   154         {
       
   155         TFeatureEntry feature( aFeatures.FeatureId( i ) );
       
   156         err = features.Append( feature );
       
   157         if( err != KErrNone )
       
   158             {
       
   159             break;
       
   160             }
       
   161         }
       
   162 
       
   163     if( err == KErrNone )
       
   164         {
       
   165         // Fetch feature information from server
       
   166         err = iFeatControl.FeaturesSupported( features );
       
   167         // Refresh count of features after query, non existing features are removed
       
   168         count = features.Count();
       
   169         }
       
   170 
       
   171     if( err == KErrNone )
       
   172         {
       
   173         // Write information back to format feature discovery uses
       
   174         aFeatures.Reset();
       
   175         
       
   176         for(TInt i(0); i < count; i++)
       
   177             {
       
   178             const TUid uid( features[i].FeatureUid() );
       
   179             const TBool supported( features[i].FeatureFlags().IsSet( EFeatureSupported ) );
       
   180             err = aFeatures.Append( uid, supported );
       
   181             if( err != KErrNone )
       
   182                 {
       
   183                 break;
       
   184                 }
       
   185             }
       
   186         }
       
   187     
       
   188     features.Close();
       
   189     return err;
       
   190     }
       
   191 // EOF