featuremgmt/featuremgr/inc/featdiscovery.h
changeset 0 08ec8eefde2f
equal deleted inserted replaced
-1:000000000000 0:08ec8eefde2f
       
     1 /*
       
     2 * Copyright (c) 2007-2009 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 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #ifndef FEATDISCOVERY_H
       
    21 #define FEATDISCOVERY_H
       
    22 
       
    23 //  INCLUDES
       
    24 #include <e32base.h>
       
    25 
       
    26 class CFeatureDiscoveryImpl;
       
    27 
       
    28 /**
       
    29 Wrapper class used for multiple feature queries.
       
    30 @publishedAll
       
    31 @released
       
    32 */
       
    33 
       
    34 class TFeatureSet
       
    35     {
       
    36     public:
       
    37 
       
    38 		/**
       
    39 		Constructor
       
    40 	    */
       
    41         IMPORT_C TFeatureSet();
       
    42 
       
    43 		/**
       
    44 		Destructor
       
    45 	    */
       
    46         IMPORT_C ~TFeatureSet();
       
    47 
       
    48 		/**
       
    49 		 Method to add features before querying support statuses. This
       
    50 		 method must be called to initialize feature array before querying
       
    51 		 support statuses from server with FeaturesSupported(L) and finally
       
    52 		 check the status with a call to IsFeatureSupported or AreAllFeaturesSupported.
       
    53 
       
    54 	     @return KErrNone if feature addition succeded.
       
    55 	             Otherwise one of the Symbian OS error codes
       
    56 	    */
       
    57 	    IMPORT_C TInt Append( TUid aFeature );
       
    58 
       
    59 		/**
       
    60 	     Method to check feature's support status.
       
    61 
       
    62 	     @param aFeature is the feature UID of the feature that is queried.
       
    63 		 @return a TBool indicating whether the feature is supported (ETrue)
       
    64 		 or not (EFalse). If the feature does not exist, the return value is
       
    65 		 EFalse.
       
    66 	    */
       
    67         IMPORT_C TBool IsFeatureSupported( TUid aFeature ) const;
       
    68 
       
    69 		/**
       
    70 		 Method to check whether all features queried are supported.
       
    71 
       
    72 	     @return ETrue if all features queried are supported or no features have been queried.
       
    73 	             Otherwise EFalse.
       
    74 	    */
       
    75 	    IMPORT_C TBool AreAllFeaturesSupported() const;
       
    76 
       
    77     public: // For CFeatureDiscoveryImpl internal use
       
    78 
       
    79         // Count number of features in TFeatureStat array.
       
    80         TInt Count();
       
    81 
       
    82         // Return id of feature in requested index from TFeatureStat array.
       
    83         TUid FeatureId( TInt aIndex ) const;
       
    84 
       
    85         // Reset TFeatureStat array.
       
    86         void Reset();
       
    87 
       
    88         // Append feature and status object into TFeatureStat array
       
    89         TInt Append( TUid aFeature, TBool aSupported );
       
    90 
       
    91     private:
       
    92         struct TFeatureStat
       
    93         {
       
    94             TUid iFeatureID;
       
    95             TBool iSupported;
       
    96         };
       
    97 
       
    98     private:
       
    99         // Feature id, status array
       
   100         RArray<TFeatureStat> iStatus;
       
   101 
       
   102         // Counter for checking feature count before and after query
       
   103         TInt iCount;
       
   104 
       
   105         // Reserved for future use.
       
   106         TUint32 iReserved;
       
   107     };
       
   108 
       
   109 /**
       
   110  The feature discovery API provides methods which are used to query which
       
   111  features are supported in the environment.
       
   112 
       
   113 @publishedAll
       
   114 @released
       
   115 */
       
   116 class CFeatureDiscovery : public CBase
       
   117     {
       
   118     public:
       
   119 
       
   120 	    /**
       
   121 	     This is a two-phase constructor method that is used to create
       
   122 	     a new instance of the CFeatureDiscovery class.
       
   123 
       
   124 	     @return a pointer to a new instance of the CFeatureDiscovery class.
       
   125 
       
   126 	     @leave Any One of the Symbian OS system-wide error codes
       
   127 	    */
       
   128 		IMPORT_C static CFeatureDiscovery* NewL();
       
   129 
       
   130 	    /**
       
   131 	     This is a two-phase constructor method that is used to create
       
   132 	     a new instance of the CFeatureDiscovery class. This method leaves
       
   133 	     the instance of the object on the cleanup stack.
       
   134 
       
   135 	     @return a pointer to a new instance of the CFeatureDiscovery class.
       
   136 
       
   137 	      @leave Any One of the Symbian OS system-wide error codes
       
   138 	    */
       
   139 		IMPORT_C static CFeatureDiscovery* NewLC();
       
   140 
       
   141 	    /**
       
   142 	     Destructor.
       
   143 	    */
       
   144 		virtual ~CFeatureDiscovery();
       
   145 
       
   146 		/**
       
   147 		 Static method to query the supported status of a feature on the
       
   148 		 device.
       
   149 
       
   150 		 @deprecated Use IsFeatureSupportedL(TUid aFeature) instead.
       
   151 
       
   152 		 @param aFeature is the feature ID of the feature that is queried.
       
   153 		 @return a TBool indicating whether the feature is supported (ETrue)
       
   154 		 or not (EFalse). If the feature does not exist, the return value is
       
   155 		 EFalse.
       
   156 
       
   157 		  @leave Any One of the Symbian OS system-wide error codes
       
   158 		*/
       
   159 		IMPORT_C static TBool IsFeatureSupportedL( TInt aFeature );
       
   160 
       
   161 		/**
       
   162 	     Dynamic method to query the supported status of a feature on the
       
   163 	     device. Before calling the method an instance of the CFeatureDiscovery
       
   164 	     class must be created by using one of the factory methods,
       
   165 	     NewL() or NewLC(). The created instance must be deleted after use.
       
   166 
       
   167 	     @deprecated Use IsSupported(TUid aFeature) instead.
       
   168 
       
   169 	     @param aFeature is the feature ID of the feature that is queried.
       
   170 	     @return a TBool indicating whether the feature is supported (ETrue)
       
   171 	     or not (EFalse). If the feature does not exist, the return value is
       
   172 	     EFalse.
       
   173 	    */
       
   174 		IMPORT_C TBool IsSupported( TInt aFeature ) const ;
       
   175 
       
   176 		/**
       
   177 	     Static method to query the supported status of a feature on the device.
       
   178 
       
   179 	     @param aFeature is the feature UID of the feature that is queried.
       
   180 	     @return a TBool indicating whether the feature is supported (ETrue)
       
   181 	     or not (EFalse). If the feature does not exist, the return value is
       
   182 	     EFalse.
       
   183 
       
   184 	     @leave Any One of the Symbian OS system-wide error codes
       
   185 	    */
       
   186 	    IMPORT_C static TBool IsFeatureSupportedL( TUid aFeature );
       
   187 
       
   188 		/**
       
   189 	     Dynamic method to query the supported status of a feature on the device.
       
   190 
       
   191 	     Before calling the method an instance of the CFeatureDiscovery class must
       
   192 	     be created by using one of the factory methods, NewL() or NewLC().
       
   193 	     The created instance must be deleted after use.
       
   194 
       
   195 	     @param aFeature is the feature UID of the feature that is queried.
       
   196 	     @return a TBool indicating whether the feature is supported (ETrue)
       
   197 	     or not (EFalse). If the feature does not exist, the return value is
       
   198 	     EFalse.
       
   199 	    */
       
   200 		IMPORT_C TBool IsSupported( TUid aFeature ) const ;
       
   201 
       
   202 		/**
       
   203 		 Static method to query the supported status of a set of features
       
   204 		 on the device.
       
   205 
       
   206 		 @param aFeatures is the wrapper class for feature array queried.
       
   207 
       
   208 		 @leave Any One of the Symbian OS system-wide error codes
       
   209 		*/
       
   210 		IMPORT_C static void FeaturesSupportedL( TFeatureSet& aFeatures );
       
   211 
       
   212 		/**
       
   213 	     Dynamic method to query the supported status of a set of features
       
   214 	     on the device. Before calling the method an instance of the
       
   215 	     CFeatureDiscovery class need to be created by using one of the
       
   216 	     factory methods, NewL() or NewLC(). The created instance must be
       
   217 	     deleted after use.
       
   218 
       
   219 	     @param aFeatures is the wrapper class for feature array queried.
       
   220 	     @return KErrNone if status query succeeded.
       
   221 	             Otherwise one of the Symbian OS error codes
       
   222 	    */
       
   223 		IMPORT_C TInt FeaturesSupported( TFeatureSet& aFeatures ) const;
       
   224 
       
   225     private:
       
   226 
       
   227 	    /**
       
   228 	     C++ default constructor.
       
   229 	    */
       
   230 		CFeatureDiscovery();
       
   231 
       
   232 	    /**
       
   233 	     By default Symbian OS constructor is private.
       
   234 	    */
       
   235 	    void ConstructL();
       
   236 
       
   237     private:
       
   238 
       
   239 		// Feature discovery implementation class
       
   240 		CFeatureDiscoveryImpl* iImpl;
       
   241     } ;
       
   242 
       
   243 /**
       
   244  Usage:
       
   245 
       
   246  @code
       
   247   #include <featdiscovery.h>
       
   248   #include <featureinfo.h> // for feature definitions
       
   249 
       
   250   // replace <featureUIDx> with a real UID )
       
   251 
       
   252   // If querying only one feature, it is more efficient to use the class
       
   253   // via the static method, IsFeatureSupportedL().
       
   254   // When querying more than one feature, it is more efficient to use the
       
   255   // class by creating an instance and calling the IsSupported() method.
       
   256 
       
   257   // Static way of using the class:
       
   258   TBool isSupported = CFeatureDiscovery::IsFeatureSupportedL(<featureUIDx>);
       
   259 
       
   260   // Dynamic way of using the class using NewL():
       
   261 
       
   262   // Call NewL() to create an instance of CFeatureDiscovery.
       
   263   CFeatureDiscovery* testA = CFeatureDiscovery::NewL();
       
   264 
       
   265   // Call the exported IsSupported() method to query whether features
       
   266   // are supported in the current environment or not.
       
   267   TBool usbSupported = testA->IsSupported(<featureUIDx>);
       
   268   TBool mmcSupported = testA->IsSupported(<featureUIDx>);
       
   269 
       
   270   // Delete the created instance of CFeatureDiscovery.
       
   271   delete testA;
       
   272 
       
   273   // Dynamic way of using the class using NewLC():
       
   274 
       
   275   // Call NewLC() to create an instance of CFeatureDiscovery.
       
   276   // The method leaves the instance of the object on the cleanup stack.
       
   277   CFeatureDiscovery* testB = CFeatureDiscovery::NewLC();
       
   278 
       
   279   // Call the exported IsSupported() method to query whether features
       
   280   // are supported in the current environment or not.
       
   281   TBool wcdmaSupported = testB->IsSupported(<featureUIDx>);
       
   282   TBool gsmSupported = testB->IsSupported(<featureUIDx>);
       
   283 
       
   284   // Dynamic way of using multiple feature query. This is preferred
       
   285   // way to fetch support statuses if there are several features to be
       
   286   // queried, because it involves less inter-process communication.
       
   287 
       
   288   TFeatureSet featset;
       
   289   User::LeaveIfError( featset.Append( <featureUIDx> ) );
       
   290   User::LeaveIfError( featset.Append( <featureUIDx> ) );
       
   291   TInt err = testB->FeaturesSupported( featset );
       
   292 	if(!err)
       
   293 		{
       
   294 			TBool uid1Supported = featset.IsFeatureSupported(<featureUIDx>);
       
   295 			TBool uid2Supported = featset.IsFeatureSupported(<featureUIDx>);
       
   296 			// ... or whether all QUERIED features are supported
       
   297 			TBool allSupported = featset.AreAllFeaturesSupported();
       
   298 		}
       
   299   // featset cleans array up in destructor on scope exit
       
   300 
       
   301   // Pop and delete the created instance of CFeatureDiscovery.
       
   302   CleanupStack::PopAndDestroy();
       
   303  @endcode
       
   304 */
       
   305 #endif  // FEATDISCOVERY_H
       
   306 
       
   307 // End of File