featuremgmt/featureregistry/src/api/featreg_wrapper.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 // Implementation of wrapper API for querying support for features on a device, It 
       
    15 // internally uses Feature Manager query APIs.
       
    16 // 
       
    17 //
       
    18 
       
    19 #include <e32uid.h>
       
    20 #include <featdiscovery.h>  
       
    21 #include "featregpan.h"
       
    22 #include "featreg.h"
       
    23 #include "featregcmn.h"
       
    24 
       
    25 // Class to hold pointers to Cleanup stack & Feature Manager CFeatureDiscovery
       
    26 // virtual methods from CBase that result in these _TZ entries being generated.
       
    27 //NONSHARABLE_CLASS is used to remove _ZTI & _ZTV entry from def file . 
       
    28 NONSHARABLE_CLASS (CImplFeatDisc ) : public CBase
       
    29 	{
       
    30 	public:
       
    31 		static CImplFeatDisc* NewL();
       
    32 		~CImplFeatDisc();
       
    33 	private:
       
    34 		CImplFeatDisc();
       
    35 		void ConstructL();
       
    36 	
       
    37 	public:
       
    38 	
       
    39 	CFeatureDiscovery *iFeatDis;
       
    40 	CTrapCleanup * iCleanup;
       
    41 	};
       
    42 	
       
    43 
       
    44 CImplFeatDisc::CImplFeatDisc() :   
       
    45 	iFeatDis( NULL ), 
       
    46 	iCleanup(NULL)
       
    47 	{
       
    48 		
       
    49 	}
       
    50 	
       
    51 CImplFeatDisc::~CImplFeatDisc()
       
    52 	{
       
    53 	delete iFeatDis;
       
    54 	iFeatDis = 0;
       
    55 	
       
    56 	delete iCleanup;
       
    57 	iCleanup = 0;
       
    58 	}
       
    59 
       
    60 void CImplFeatDisc::ConstructL()
       
    61     {
       
    62     iFeatDis = CFeatureDiscovery::NewL();
       
    63     }
       
    64 	
       
    65 
       
    66 CImplFeatDisc* CImplFeatDisc::NewL()
       
    67     {
       
    68     CImplFeatDisc* self = new( ELeave ) CImplFeatDisc();
       
    69     CleanupStack::PushL( self );
       
    70     self->ConstructL();
       
    71     CleanupStack::Pop( self );
       
    72 
       
    73     return self;
       
    74     }
       
    75 
       
    76 
       
    77 /**
       
    78  * Dummy feature registry implementation object - never instantiated.
       
    79  * @internalComponent
       
    80  */
       
    81 class RFeatureRegistry::TImpl
       
    82 	{
       
    83 	TUint32 iDummy;
       
    84 	};
       
    85 
       
    86 /**
       
    87  * Opens connection to the Feature Registry for making non-static queries.
       
    88  * Note all non-static queries return state at the time Open() was called;
       
    89  * Feature Registry changes are not observed until instance closed and re-opened.
       
    90  *
       
    91  * @return KErrNone if successful, negative system-wide error code if fails
       
    92  * @publishedPartner
       
    93  * @deprecated
       
    94  */
       
    95 EXPORT_C TInt RFeatureRegistry::Open()
       
    96 	{
       
    97 	__ASSERT_ALWAYS(iImpl == NULL, Panic(EFeatRegInvalidUse));
       
    98 	
       
    99 	CTrapCleanup *cleanup = NULL;
       
   100 	
       
   101 	if(User::TrapHandler() == NULL)
       
   102 		{
       
   103 		cleanup = CTrapCleanup::New();	
       
   104 		if(cleanup == NULL)
       
   105 	        {
       
   106 	        return KErrNoMemory;
       
   107 	        }
       
   108 		}
       
   109 	
       
   110 	CImplFeatDisc  *ptrh = NULL; 	
       
   111 	TRAPD( err,  ptrh = CImplFeatDisc::NewL() );
       
   112     if ( err == KErrNone )
       
   113         {
       
   114     	ptrh->iCleanup = cleanup;
       
   115         iImpl = reinterpret_cast<TImpl*> (ptrh);
       
   116         }
       
   117     else
       
   118     	delete cleanup;
       
   119 	return err;
       
   120 	}
       
   121 
       
   122 /**
       
   123  * Queries support for feature on the device.
       
   124  * Non-static version requiring open instance of class.
       
   125  * Recommended when making multiple queries.
       
   126  * Note: returns support for feature from the time Open() was called.
       
   127  *
       
   128  * @param aFeatureUid Unique identifier of feature being queried
       
   129  * @return positive value if feature is supported, zero if feature is not supported,
       
   130  *     or negative system-wide error code if could not be determined.
       
   131  * @pre this registry instance is open
       
   132  * @panic FeatReg EFeatRegInvalidUse if this registry instance is not open
       
   133  * @publishedPartner
       
   134  * @deprecated
       
   135  */
       
   136 EXPORT_C TInt RFeatureRegistry::QuerySupport(TUid aFeatureUid)
       
   137 	{
       
   138 	
       
   139 	TUint32 dummyInfo;
       
   140 	return QuerySupport(aFeatureUid, dummyInfo);
       
   141 	}
       
   142 
       
   143 /**
       
   144  * Queries support for feature on the device.
       
   145  * Non-static version requiring open instance of class.
       
   146  * Recommended when making multiple queries.
       
   147  * Note: returns support for feature from the time Open() was called.
       
   148  *
       
   149  * @param aFeatureUid Unique identifier of feature being queried
       
   150  * @param aInfo addition status information about feature
       
   151  * @return positive value if feature is supported, zero if feature is not supported,
       
   152  *     or negative system-wide error code if could not be determined.
       
   153  * @pre this registry instance is open
       
   154  * @panic FeatReg EFeatRegInvalidUse if this registry instance is not open
       
   155  * @publishedPartner
       
   156  * @deprecated
       
   157  */
       
   158 EXPORT_C TInt RFeatureRegistry::QuerySupport(TUid aFeatureUid, TUint32& aInfo)
       
   159 	{
       
   160 	__ASSERT_ALWAYS(iImpl != NULL, Panic(EFeatRegInvalidUse));
       
   161 
       
   162 	CImplFeatDisc *ptrh  = reinterpret_cast<CImplFeatDisc*> (iImpl);
       
   163 	
       
   164 	if(ptrh->iFeatDis->IsSupported(aFeatureUid))
       
   165 		{
       
   166 		
       
   167 		//FeatReg support only ROM features so EStatusUpgradableBit has no meaning
       
   168 		//So aInfo always set to EStatusSupportBit in this wrapper
       
   169 		aInfo = EStatusSupportBit;
       
   170 		return EStatusSupportBit;		
       
   171 		}
       
   172 
       
   173 	// feature not supported
       
   174 	aInfo =0;
       
   175 	return 0;
       
   176 	}
       
   177 
       
   178 /**
       
   179  * Closes this registry instance.
       
   180  * @publishedPartner
       
   181  * @deprecated
       
   182  */
       
   183 EXPORT_C void RFeatureRegistry::Close()
       
   184 	{
       
   185 	CImplFeatDisc *ptrh  = reinterpret_cast<CImplFeatDisc*> (iImpl);
       
   186 	delete ptrh;
       
   187 	ptrh = 0;
       
   188 	}
       
   189 
       
   190 /**
       
   191  * Queries support for feature on the device.
       
   192  * Static version recommended for single queries.
       
   193  *
       
   194  * @param aFeatureUid Unique identifier of feature being queried
       
   195  * @return positive value if feature is supported, zero if feature is not supported,
       
   196  *     or negative system-wide error code if could not be determined.
       
   197  * @publishedPartner
       
   198  * @deprecated
       
   199  */
       
   200 EXPORT_C TInt RFeatureRegistry::QuerySupportS(TUid aFeatureUid)
       
   201 	{
       
   202 	TUint32 dummyInfo;
       
   203 	return QuerySupportS(aFeatureUid, dummyInfo);
       
   204 	}
       
   205 
       
   206 /**
       
   207  * Queries support for feature on the device.
       
   208  * Static version recommended for single queries.
       
   209  *
       
   210  * @param aFeatureUid Unique identifier of feature being queried
       
   211  * @param aInfo addition status information about feature
       
   212  * @return positive value if feature is supported, zero if feature is not supported,
       
   213  *     or negative system-wide error code if could not be determined.
       
   214  * @publishedPartner
       
   215  * @deprecated
       
   216  */
       
   217 EXPORT_C TInt RFeatureRegistry::QuerySupportS(TUid aFeatureUid, TUint32& aInfo)
       
   218 	{
       
   219 	CTrapCleanup * cleanup = NULL;
       
   220 	if(User::TrapHandler() == NULL)
       
   221 		{
       
   222 		cleanup = CTrapCleanup::New();
       
   223 		if(cleanup == NULL)
       
   224 	        {
       
   225 	        return KErrNoMemory;
       
   226 	        }
       
   227 		}
       
   228 	TBool supported = EFalse;
       
   229 	TRAPD( err,  supported = CFeatureDiscovery::IsFeatureSupportedL(aFeatureUid) );
       
   230 	
       
   231 	if(cleanup != NULL)
       
   232 		delete cleanup;
       
   233      
       
   234 	if (err != KErrNone)
       
   235 		{
       
   236 		return err;
       
   237 		}
       
   238 		
       
   239     if ( supported)
       
   240         {
       
   241 		//FeatReg support only ROM features so EStatusUpgradableBit has no meaning
       
   242 		//So aInfo always set to EStatusSupportBit in this wrapper
       
   243 		aInfo = EStatusSupportBit;
       
   244 		return EStatusSupportBit;		
       
   245         }
       
   246    
       
   247 	// feature not supported
       
   248 	aInfo =0;
       
   249 	return 0;
       
   250 
       
   251 	}
       
   252 	
       
   253 
       
   254 // CLASS DECLARATION
       
   255 
       
   256 /**
       
   257 Dummy class. Contains placeholder for a removed RFeatureRegistryNotify function to prevent BC break.
       
   258 @internalComponent
       
   259 */
       
   260 class Dummy
       
   261     {
       
   262 
       
   263     public: // New functions
       
   264 
       
   265         IMPORT_C static void Dummy1();
       
   266         IMPORT_C static void Dummy2();
       
   267         IMPORT_C static TInt Dummy3();
       
   268         IMPORT_C static void Dummy4(TRequestStatus &);
       
   269     };
       
   270 
       
   271 // ================= MEMBER FUNCTIONS =======================
       
   272 
       
   273 
       
   274 /**
       
   275 Dummy method
       
   276 @internalComponent
       
   277 */
       
   278 EXPORT_C void Dummy::Dummy1() { }
       
   279 
       
   280 /**
       
   281 Dummy method
       
   282 @internalComponent
       
   283 */
       
   284 EXPORT_C void Dummy::Dummy2() {  }
       
   285 /**
       
   286 Dummy method
       
   287 @internalComponent
       
   288 @return KErrNotSupported
       
   289 */
       
   290 EXPORT_C TInt Dummy::Dummy3() 
       
   291 {  
       
   292 return KErrNotSupported;
       
   293 }
       
   294 
       
   295 /**
       
   296 Dummy method
       
   297 @internalComponent
       
   298 */
       
   299 EXPORT_C void Dummy::Dummy4(TRequestStatus &) {  }
       
   300 
       
   301 
       
   302 
       
   303 
       
   304