os/persistentdata/featuremgmt/featuremgr/src/featdiscovery/featdiscoveryimpl.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/persistentdata/featuremgmt/featuremgr/src/featdiscovery/featdiscoveryimpl.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,191 @@
     1.4 +// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +
    1.20 +
    1.21 +#include <e32cmn.h>
    1.22 +#include <featdiscovery.h>
    1.23 +#include "featdiscoveryimpl.h"
    1.24 +#include "featurecontrol.h"
    1.25 +#include "featurecmn.h"
    1.26 +
    1.27 +// -----------------------------------------------------------------------------
    1.28 +// CFeatureDiscoveryImpl::CFeatureDiscoveryImpl* NewL()
    1.29 +// -----------------------------------------------------------------------------
    1.30 +//
    1.31 +CFeatureDiscoveryImpl* CFeatureDiscoveryImpl::NewL()
    1.32 +    {
    1.33 +    CFeatureDiscoveryImpl* self = new( ELeave ) CFeatureDiscoveryImpl();
    1.34 +    CleanupStack::PushL( self );
    1.35 +    self->ConstructL();
    1.36 +    CleanupStack::Pop( self );
    1.37 +
    1.38 +    return self;
    1.39 +    }
    1.40 +
    1.41 +
    1.42 +
    1.43 +// ---------------------------------------------------------
    1.44 +// CFeatureDiscoveryImpl::ConstructL
    1.45 +//
    1.46 +// Symbian OS default constructor, initializes variables and cache 
    1.47 +// ---------------------------------------------------------
    1.48 +//
    1.49 +void CFeatureDiscoveryImpl::ConstructL()
    1.50 +    {
    1.51 +    TInt err( iFeatControl.Connect() );
    1.52 +    User::LeaveIfError( err );
    1.53 +    }
    1.54 +
    1.55 +
    1.56 +// -----------------------------------------------------------------------------
    1.57 +// CFeatureDiscoveryImpl::~CFeatureDiscoveryImpl()
    1.58 +// -----------------------------------------------------------------------------
    1.59 +//
    1.60 +CFeatureDiscoveryImpl::~CFeatureDiscoveryImpl()
    1.61 +    {
    1.62 +    iFeatControl.Close();
    1.63 +    }
    1.64 +
    1.65 +
    1.66 +// -----------------------------------------------------------------------------
    1.67 +// CFeatureDiscoveryImpl::CFeatureDiscoveryImpl()
    1.68 +// -----------------------------------------------------------------------------
    1.69 +//
    1.70 +CFeatureDiscoveryImpl::CFeatureDiscoveryImpl()
    1.71 +    {
    1.72 +    }
    1.73 +
    1.74 +
    1.75 +// -----------------------------------------------------------------------------
    1.76 +// CFeatureDiscoveryImpl::IsFeatureSupportedL(TUid)
    1.77 +// -----------------------------------------------------------------------------
    1.78 +//
    1.79 +TBool CFeatureDiscoveryImpl::IsFeatureSupportedL(TUid aFeature)
    1.80 +    {
    1.81 +    RFeatureControl featControl;
    1.82 +    TInt err( featControl.Connect() );
    1.83 +    User::LeaveIfError( err );
    1.84 +    TFeatureEntry feature( aFeature );
    1.85 +    err = featControl.FeatureSupported( feature );
    1.86 +    featControl.Close();
    1.87 +    
    1.88 +    return (( err > 0 ) ? ETrue : EFalse );
    1.89 +    }
    1.90 +
    1.91 +// -----------------------------------------------------------------------------
    1.92 +// CFeatureDiscoveryImpl::IsSupported(TUid)
    1.93 +// -----------------------------------------------------------------------------
    1.94 +//
    1.95 +TBool CFeatureDiscoveryImpl::IsSupported(TUid aFeature)
    1.96 +    {
    1.97 +    TFeatureEntry feature( aFeature );
    1.98 +    
    1.99 +    return (( iFeatControl.FeatureSupported( feature ) > 0 ) ? ETrue : EFalse );
   1.100 +    }
   1.101 +
   1.102 +// -----------------------------------------------------------------------------
   1.103 +// CFeatureDiscoveryImpl::FeaturesSupportedL(TFeatureSet&)
   1.104 +// -----------------------------------------------------------------------------
   1.105 +//
   1.106 +void CFeatureDiscoveryImpl::FeaturesSupportedL( TFeatureSet& aFeatures )
   1.107 +    {
   1.108 +    RFeatureControl featControl;
   1.109 +    CleanupClosePushL( featControl );
   1.110 +    TInt err( featControl.Connect() );
   1.111 +    User::LeaveIfError( err );
   1.112 +    
   1.113 +    // Construct feature entry array used by feature control
   1.114 +    RFeatureArray features;
   1.115 +    CleanupClosePushL( features );
   1.116 +    TInt count( aFeatures.Count() );
   1.117 +    
   1.118 +    for(TInt i(0); i < count; i++)
   1.119 +        {
   1.120 +        TFeatureEntry feature( aFeatures.FeatureId( i ) );
   1.121 +        features.AppendL( feature );
   1.122 +        }
   1.123 +
   1.124 +    // Fetch feature information from server
   1.125 +    err = featControl.FeaturesSupported( features );
   1.126 +    User::LeaveIfError( err );
   1.127 +
   1.128 +    // Refresh count of features after query, non existing features are removed 
   1.129 +    count = features.Count();
   1.130 +    // Write information back to format feature discovery uses
   1.131 +    aFeatures.Reset();
   1.132 +    
   1.133 +    for(TInt i(0); i < count; i++)
   1.134 +        {
   1.135 +        const TUid uid( features[i].FeatureUid() );
   1.136 +        const TBool supported( features[i].FeatureFlags().IsSet( EFeatureSupported ) );
   1.137 +        err = aFeatures.Append( uid, supported );
   1.138 +        User::LeaveIfError( err );
   1.139 +        }
   1.140 +
   1.141 +    CleanupStack::PopAndDestroy( &features );
   1.142 +    CleanupStack::PopAndDestroy( &featControl );
   1.143 +    }
   1.144 +
   1.145 +// -----------------------------------------------------------------------------
   1.146 +// CFeatureDiscoveryImpl::FeaturesSupported(TFeatureSet&)
   1.147 +// -----------------------------------------------------------------------------
   1.148 +//
   1.149 +TInt CFeatureDiscoveryImpl::FeaturesSupported( TFeatureSet& aFeatures )
   1.150 +    {
   1.151 +    // Construct feature entry array used by feature control
   1.152 +    TInt err( KErrNone );
   1.153 +    RFeatureArray features;
   1.154 +    TInt count( aFeatures.Count() );
   1.155 +    
   1.156 +    for(TInt i(0); i < count; i++)
   1.157 +        {
   1.158 +        TFeatureEntry feature( aFeatures.FeatureId( i ) );
   1.159 +        err = features.Append( feature );
   1.160 +        if( err != KErrNone )
   1.161 +            {
   1.162 +            break;
   1.163 +            }
   1.164 +        }
   1.165 +
   1.166 +    if( err == KErrNone )
   1.167 +        {
   1.168 +        // Fetch feature information from server
   1.169 +        err = iFeatControl.FeaturesSupported( features );
   1.170 +        // Refresh count of features after query, non existing features are removed
   1.171 +        count = features.Count();
   1.172 +        }
   1.173 +
   1.174 +    if( err == KErrNone )
   1.175 +        {
   1.176 +        // Write information back to format feature discovery uses
   1.177 +        aFeatures.Reset();
   1.178 +        
   1.179 +        for(TInt i(0); i < count; i++)
   1.180 +            {
   1.181 +            const TUid uid( features[i].FeatureUid() );
   1.182 +            const TBool supported( features[i].FeatureFlags().IsSet( EFeatureSupported ) );
   1.183 +            err = aFeatures.Append( uid, supported );
   1.184 +            if( err != KErrNone )
   1.185 +                {
   1.186 +                break;
   1.187 +                }
   1.188 +            }
   1.189 +        }
   1.190 +    
   1.191 +    features.Close();
   1.192 +    return err;
   1.193 +    }
   1.194 +// EOF