fep/frontendprocessor/source/FEPBCONFIG.CPP
changeset 0 eb1f2e154e89
equal deleted inserted replaced
-1:000000000000 0:eb1f2e154e89
       
     1 // Copyright (c) 1997-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 #include <fepbconfig.h>
       
    18 #include <fepbpanic.h>
       
    19 #include <centralrepository.h>
       
    20 #include <coedef.h>		// KUidFepFrameworkRepository
       
    21 #include <s32strm.h>
       
    22 #include <s32mem.h>
       
    23 #include "FEPBPRIV.H"
       
    24 #include <graphics/cone/coedefkeys.h>
       
    25 
       
    26 LOCAL_C void Panic(TFepBasePanic aPanic)
       
    27 	{
       
    28 	User::Panic(KLitFepBasePanicText, aPanic);
       
    29 	}
       
    30 //
       
    31 // TFepOnOrOffKeyData
       
    32 //
       
    33 
       
    34 EXPORT_C TBool TFepOnOrOffKeyData::operator==(const TFepOnOrOffKeyData& aAnother) const
       
    35 	{
       
    36 	return (iCharacterCodeForFoldedMatch==aAnother.iCharacterCodeForFoldedMatch) &&
       
    37 		   (iModifierMask==aAnother.iModifierMask) &&
       
    38 		   (iModifierValues==aAnother.iModifierValues);
       
    39 	}
       
    40 
       
    41 EXPORT_C TBool TFepOnOrOffKeyData::operator!=(const TFepOnOrOffKeyData& aAnother) const
       
    42 	{
       
    43 	return !operator==(aAnother);
       
    44 	}
       
    45 
       
    46 //
       
    47 // CFepGenericGlobalSettings
       
    48 //
       
    49 
       
    50 /** Allocates and constructs a new generic FEP settings object. 
       
    51 
       
    52 Reads the generic FEP data from the system settings. If the data is not 
       
    53 present in the system settings, it is read from the default values specified.
       
    54 
       
    55 @deprecated
       
    56 @param aConeEnvironment The FEP's control environment.
       
    57 @param aDefaultOnKeyData Default key event data for switching the FEP on.
       
    58 @param aDefaultOffKeyData Default key event data for switching the FEP off.
       
    59 @param aDefaultIsOn Whether the FEP is on or off by default.
       
    60 @return Pointer to the newly created object. */
       
    61 EXPORT_C CFepGenericGlobalSettings* CFepGenericGlobalSettings::NewL(CCoeEnv& aConeEnvironment, const TFepOnOrOffKeyData& aDefaultOnKeyData, const TFepOnOrOffKeyData& aDefaultOffKeyData, TBool aDefaultIsOn)
       
    62 	{
       
    63 	CFepGenericGlobalSettings* genericGlobalSettings=NewLC(aConeEnvironment, aDefaultOnKeyData, aDefaultOffKeyData, aDefaultIsOn);
       
    64 	CleanupStack::Pop(); // genericGlobalSettings
       
    65 	return genericGlobalSettings;
       
    66 	}
       
    67 
       
    68 /** Allocates and constructs a new generic FEP settings object. 
       
    69 
       
    70 Reads the generic FEP data from the system settings. If the data is not 
       
    71 present in the system settings, it is read from the default values specified. 
       
    72 Leaves a pointer to the object on the cleanup stack.
       
    73 
       
    74 @deprecated
       
    75 @param aConeEnvironment The FEP's control environment.
       
    76 @param aDefaultOnKeyData Default key event data for switching the FEP on.
       
    77 @param aDefaultOffKeyData Default key event data for switching the FEP off.
       
    78 @param aDefaultIsOn Whether the FEP is on or off by default.
       
    79 @return Pointer to the newly created object. */
       
    80 EXPORT_C CFepGenericGlobalSettings* CFepGenericGlobalSettings::NewLC(CCoeEnv& /*aConeEnvironment*/, const TFepOnOrOffKeyData& /*aDefaultOnKeyData*/, const TFepOnOrOffKeyData& /*aDefaultOffKeyData*/, TBool /*aDefaultIsOn*/)
       
    81 	{
       
    82 	CFepGenericGlobalSettings* genericGlobalSettings=new(ELeave) CFepGenericGlobalSettings;
       
    83 	CleanupStack::PushL(genericGlobalSettings);
       
    84 	genericGlobalSettings->ConstructL();
       
    85 	return genericGlobalSettings;
       
    86 	}
       
    87 
       
    88 /** Allocates and constructs a new generic FEP settings object. 
       
    89 
       
    90 Reads the generic FEP data from the system settings.
       
    91 
       
    92 @return Pointer to the newly created object. */
       
    93 EXPORT_C CFepGenericGlobalSettings* CFepGenericGlobalSettings::NewL()
       
    94 	{
       
    95 	CFepGenericGlobalSettings* const genericGlobalSettings=NewLC();
       
    96 	CleanupStack::Pop(genericGlobalSettings);
       
    97 	return genericGlobalSettings;
       
    98 	}
       
    99 
       
   100 /** Allocates and constructs a new generic FEP settings object. 
       
   101 
       
   102 Reads the generic FEP data from the system settings. 
       
   103 Leaves a pointer to the object on the cleanup stack.
       
   104 
       
   105 @return Pointer to the newly created object. */
       
   106 EXPORT_C CFepGenericGlobalSettings* CFepGenericGlobalSettings::NewLC()
       
   107 	{
       
   108 	CFepGenericGlobalSettings* const genericGlobalSettings=new(ELeave) CFepGenericGlobalSettings;
       
   109 	CleanupStack::PushL(genericGlobalSettings);
       
   110 	genericGlobalSettings->ConstructL();
       
   111 	return genericGlobalSettings;
       
   112 	}
       
   113 
       
   114 /** Gets the key event data which turns the FEP on.
       
   115 
       
   116 @return The key event data which turns the FEP on. */
       
   117 EXPORT_C TFepOnOrOffKeyData CFepGenericGlobalSettings::OnKeyData() const
       
   118 	{
       
   119 	return iOnKeyData;
       
   120 	}
       
   121 
       
   122 /** Sets the key event data which turns the FEP on.
       
   123 
       
   124 @param aOnKeyData The key event data which turns the FEP on. */
       
   125 EXPORT_C void CFepGenericGlobalSettings::SetOnKeyData(const TFepOnOrOffKeyData& aOnKeyData)
       
   126 	{
       
   127 	iOnKeyData=aOnKeyData;
       
   128 	iFlags|=EFlagStoreOnKeyData;
       
   129 	}
       
   130 
       
   131 /** Gets the key event data which turns the FEP off.
       
   132 
       
   133 @return The key event data which turns the FEP off. */
       
   134 EXPORT_C TFepOnOrOffKeyData CFepGenericGlobalSettings::OffKeyData() const
       
   135 	{
       
   136 	return iOffKeyData;
       
   137 	}
       
   138 
       
   139 /** Sets the key event data which turns the FEP off.
       
   140 
       
   141 @param aOffKeyData The key event data which turns the FEP off. */
       
   142 EXPORT_C void CFepGenericGlobalSettings::SetOffKeyData(const TFepOnOrOffKeyData& aOffKeyData)
       
   143 	{
       
   144 	iOffKeyData=aOffKeyData;
       
   145 	iFlags|=EFlagStoreOffKeyData;
       
   146 	}
       
   147 
       
   148 /** Tests whether the FEP is on or off.
       
   149 
       
   150 @return ETrue if the FEP is on, EFalse if the FEP is off. */
       
   151 EXPORT_C TBool CFepGenericGlobalSettings::IsOn() const
       
   152 	{
       
   153 	return iFlags&EFlagIsOn;
       
   154 	}
       
   155 
       
   156 /** Sets a flag indicating whether the FEP is on or off.
       
   157 
       
   158 @param aIsOn ETrue if the FEP is on, EFalse if the FEP is off. */
       
   159 EXPORT_C void CFepGenericGlobalSettings::SetIsOn(TBool aIsOn)
       
   160 	{
       
   161 	if (aIsOn)
       
   162 		iFlags|=EFlagIsOn;
       
   163 	else
       
   164 		iFlags&=~EFlagIsOn;
       
   165 
       
   166 	iFlags|=EFlagStoreIsOn;
       
   167 	}
       
   168 
       
   169 /** Stores the local copies of the generic FEP data as the system settings. 
       
   170 
       
   171 Causes all other running instances of the FEP to be updated with the new settings.
       
   172 @capability WriteDeviceData		To prevent corruption of FEP settings.
       
   173 */
       
   174 EXPORT_C void CFepGenericGlobalSettings::StoreChangesAndBroadcastL()
       
   175 	{
       
   176 	if (iFlags&(EFlagStoreIsOn|EFlagStoreOnKeyData|EFlagStoreOffKeyData))
       
   177 		{
       
   178 		CRepository* const repository=CRepository::NewLC(TUid::Uid(KUidFepFrameworkRepository));
       
   179 		TInt error=KErrNone;
       
   180 		do
       
   181 			{
       
   182 			User::LeaveIfError(repository->StartTransaction(CRepository::EConcurrentReadWriteTransaction));
       
   183 			repository->CleanupCancelTransactionPushL();
       
   184 			if (iFlags&EFlagStoreIsOn)
       
   185 				WriteOnStateAndBroadcastL(*repository, iFlags&EFlagIsOn, ERepositoryKeyMask_DynamicSetting);
       
   186 
       
   187 			if (iFlags&EFlagStoreOnKeyData)
       
   188 				WriteOnOrOffKeyDataAndBroadcastL(*repository, iOnKeyData, ERepositoryKey_DynamicOnKeyData);
       
   189 
       
   190 			if (iFlags&EFlagStoreOffKeyData)
       
   191 				WriteOnOrOffKeyDataAndBroadcastL(*repository, iOffKeyData, ERepositoryKey_DynamicOffKeyData);
       
   192 
       
   193 			CleanupStack::Pop(); // repository->CleanupCancelTransactionPushL
       
   194 			TUint32 notUsed=0;
       
   195 			error=repository->CommitTransaction(notUsed);
       
   196 			} 
       
   197 		while (error==KErrLocked);
       
   198 
       
   199 		User::LeaveIfError(error);
       
   200 		iFlags&=~(EFlagStoreIsOn|EFlagStoreOnKeyData|EFlagStoreOffKeyData);
       
   201 		CleanupStack::PopAndDestroy(repository);
       
   202 		}
       
   203 	}
       
   204 
       
   205 /** Reads the generic FEP data from the system settings. 
       
   206 
       
   207 If the FEP data is not present in the system settings, then it is set from 
       
   208 the default values (as passed to the NewL()).
       
   209 
       
   210 This function is called during construction of the object. */
       
   211 EXPORT_C void CFepGenericGlobalSettings::RefreshL()
       
   212 	{
       
   213 	TBool onState=EFalse;
       
   214 	TFepOnOrOffKeyData onKeyData(0, 0, 0);
       
   215 	TFepOnOrOffKeyData offKeyData(0, 0, 0);
       
   216 
       
   217 	CRepository* const repository=CRepository::NewLC(TUid::Uid(KUidFepFrameworkRepository));
       
   218 	TInt error=KErrNone;
       
   219 	do
       
   220 		{
       
   221 		User::LeaveIfError(repository->StartTransaction(CRepository::EConcurrentReadWriteTransaction));
       
   222 		repository->CleanupCancelTransactionPushL();
       
   223 		ReadOnState(*repository, onState, &error);
       
   224 		if (error==KErrNone)
       
   225 			ReadOnOrOffKeyData(*repository, onKeyData, ERepositoryKeyMask_OnKeyData, &error);
       
   226 
       
   227 		if (error==KErrNone)
       
   228 			ReadOnOrOffKeyData(*repository, offKeyData, ERepositoryKeyMask_OffKeyData, &error);
       
   229 
       
   230 		CleanupStack::PopAndDestroy(); // repository->CleanupCancelTransactionPushL
       
   231 		} 
       
   232 	while (error==KErrAbort);
       
   233 	
       
   234 	if (error!=KErrNotFound)
       
   235 		User::LeaveIfError(error);
       
   236 
       
   237 	CleanupStack::PopAndDestroy(repository);
       
   238 
       
   239 	// everything leaving has now succeeded, so assign member-objects
       
   240 	if (onState)
       
   241 		iFlags|=EFlagIsOn;
       
   242 	else
       
   243 		iFlags&=~EFlagIsOn;
       
   244 
       
   245 	iOnKeyData=onKeyData;
       
   246 	iOffKeyData=offKeyData;
       
   247 	iFlags&=~(EFlagStoreIsOn|EFlagStoreOnKeyData|EFlagStoreOffKeyData);
       
   248 	}
       
   249 
       
   250 /** @internalTechnology */
       
   251 EXPORT_C void CFepGenericGlobalSettings::ReadOnState(CRepository& aRepository, TBool& aOnState, TInt* aError/*=NULL*/)
       
   252 	{ // static
       
   253 	TInt error=aRepository.Get(ERepositoryKey_DynamicOnState, aOnState);
       
   254 	if (error!=KErrNone)
       
   255 		error=aRepository.Get(ERepositoryKey_DefaultOnState, aOnState);
       
   256 
       
   257 	if (aError!=NULL)
       
   258 		*aError=error;
       
   259 	}
       
   260 
       
   261 /** @internalTechnology */
       
   262 EXPORT_C void CFepGenericGlobalSettings::ReadOnOrOffKeyData(CRepository& aRepository, TFepOnOrOffKeyData& aOnOrOffKeyData, TUint32 aRepositoryKeyMask_OnOrOff, TInt* aError/*=NULL*/)
       
   263 	{ // static
       
   264 	TPckg<TFepOnOrOffKeyData> onOrOffKeyData(aOnOrOffKeyData);
       
   265 	TInt error=aRepository.Get((ERepositoryKeyMask_DynamicSetting|aRepositoryKeyMask_OnOrOff), onOrOffKeyData);
       
   266 	if (error!=KErrNone)
       
   267 		error=aRepository.Get((ERepositoryKeyMask_DefaultSetting|aRepositoryKeyMask_OnOrOff), onOrOffKeyData);
       
   268 
       
   269 	if (aError!=NULL)
       
   270 		*aError=error;
       
   271 	}
       
   272 
       
   273 /** @internalTechnology */
       
   274 EXPORT_C void CFepGenericGlobalSettings::WriteOnStateAndBroadcastL(CRepository& aRepository, TBool aOnState, TUint32 aRepositoryKeyMask_DefaultOrDynamic)
       
   275 	{ // static
       
   276 	const TUint32 repositoryKey=(aRepositoryKeyMask_DefaultOrDynamic|ERepositoryKeyMask_OnState);
       
   277 	User::LeaveIfError(aRepository.Set(repositoryKey, aOnState));
       
   278 	}
       
   279 
       
   280 /** @internalTechnology */
       
   281 EXPORT_C void CFepGenericGlobalSettings::WriteOnOrOffKeyDataAndBroadcastL(CRepository& aRepository, const TFepOnOrOffKeyData& aOnOrOffKeyData, TUint32 aRepositoryKey)
       
   282 	{ // static
       
   283 	const TPckgC<TFepOnOrOffKeyData> onOrOffKeyData(aOnOrOffKeyData);
       
   284 	User::LeaveIfError(aRepository.Set(aRepositoryKey, onOrOffKeyData));
       
   285 	}
       
   286 
       
   287 CFepGenericGlobalSettings::CFepGenericGlobalSettings()
       
   288 	:iFlags(0),
       
   289 	 iOnKeyData(0, 0, 0),
       
   290 	 iOffKeyData(0, 0, 0)
       
   291 	{
       
   292 	}
       
   293 
       
   294 void CFepGenericGlobalSettings::ConstructL()
       
   295 	{
       
   296 	RefreshL();
       
   297 	}
       
   298 
       
   299 
       
   300 //
       
   301 // MFepAttributeStorer
       
   302 //
       
   303 
       
   304 /** Reads all of the FEP's attributes from the system settings. 
       
   305 
       
   306 Calls the implementation of ReadAttributeDataFromStreamL() for each attribute.
       
   307 
       
   308 This function has identical behaviour to CCoeFep::ReadAllAttributesL().
       
   309 
       
   310 @param aConeEnvironment Not used. */
       
   311 EXPORT_C void MFepAttributeStorer::ReadAllAttributesL(CCoeEnv& /*aConeEnvironment*/)
       
   312 	{
       
   313 	CRepository* const repository=CRepository::NewLC(TUid::Uid(KUidFepSpecificSettingsRepository));
       
   314 	RBuf8 buffer;
       
   315 	CleanupClosePushL(buffer);
       
   316 	buffer.CreateL(NCentralRepositoryConstants::KMaxBinaryLength);
       
   317 	User::LeaveIfError(repository->StartTransaction(CRepository::EConcurrentReadWriteTransaction)); // a transaction ensures that a consistent set of values is read
       
   318 	repository->CleanupCancelTransactionPushL();
       
   319 
       
   320 	const TInt numberOfAttributes=NumberOfAttributes();
       
   321 	for (TInt i=numberOfAttributes-1; i>=0; --i)
       
   322 		{
       
   323 		const TUid attributeUid(AttributeAtIndex(i));
       
   324 		const TInt error=repository->Get(attributeUid.iUid, buffer);
       
   325 		if (error==KErrAbort)
       
   326 			{
       
   327 			// cause the loop to start all over again, since some other process has done a commit whilst we've been inside this transaction
       
   328 			i=numberOfAttributes;
       
   329 			continue;
       
   330 			}
       
   331 
       
   332 		if (error==KErrNone)
       
   333 			{
       
   334 			RDesReadStream readStream(buffer);
       
   335 			ReadAttributeDataFromStreamL(attributeUid, readStream);
       
   336 			}
       
   337 		}
       
   338 	CleanupStack::PopAndDestroy(3, repository);
       
   339 	}
       
   340 
       
   341 /** Call this function after changing the value of an attribute that needs to be 
       
   342 synchronised. 
       
   343 
       
   344 Writes the new value to the system-wide settings and causes 
       
   345 all other running instances of the FEP to be notified of the change.
       
   346 
       
   347 A panic occurs if aAttributeUid is not one of the FEP's attributes.
       
   348 
       
   349 @param aConeEnvironment The FEP's control environment.
       
   350 @param aAttributeUid The UID of the attribute whose value has changed.
       
   351 @capability WriteDeviceData */
       
   352 EXPORT_C void MFepAttributeStorer::WriteAttributeDataAndBroadcastL(CCoeEnv& aConeEnvironment, TUid aAttributeUid)
       
   353 	{
       
   354 	TFixedArray<TUid, 1> arrayOfOneAttribute;
       
   355 	arrayOfOneAttribute[0].iUid=aAttributeUid.iUid;
       
   356 	WriteAttributeDataAndBroadcastL(aConeEnvironment, arrayOfOneAttribute.Array());
       
   357 	}
       
   358 
       
   359 /** Call this function after changing the value of multiple attributes that need 
       
   360 to be synchronised. 
       
   361 
       
   362 Writes the new values to the system settings, and causes all other running 
       
   363 instances of the FEP to be notified of the change.
       
   364 
       
   365 A panic occurs if any of the attributes contained in aAttributeUids are not 
       
   366 among the FEP's attributes.
       
   367 
       
   368 @param aConeEnvironment Not used.
       
   369 @param aAttributeUids Array of UIDs of the attribute whose values have changed.
       
   370 @capability WriteDeviceData		To prevent corruption of FEP settings.
       
   371 */
       
   372 EXPORT_C void MFepAttributeStorer::WriteAttributeDataAndBroadcastL(CCoeEnv& /*aConeEnvironment*/, const TArray<TUid>& aAttributeUids)
       
   373 	{
       
   374 	CRepository* const repository=CRepository::NewLC(TUid::Uid(KUidFepSpecificSettingsRepository));
       
   375 	RBuf8 buffer;
       
   376 	CleanupClosePushL(buffer);
       
   377 	buffer.CreateL(NCentralRepositoryConstants::KMaxBinaryLength);
       
   378 	TInt error=KErrNone;
       
   379 	do
       
   380 		{
       
   381 		User::LeaveIfError(repository->StartTransaction(CRepository::EConcurrentReadWriteTransaction));
       
   382 		repository->CleanupCancelTransactionPushL();
       
   383 		for (TInt i=aAttributeUids.Count()-1; i>=0; --i)
       
   384 			{
       
   385 			const TUid attributeUid(aAttributeUids[i]);
       
   386 			__ASSERT_ALWAYS(NumberOfOccurrencesOfAttributeUid(attributeUid)==1, Panic(EPanicBadAttributeUid));
       
   387 			RDesWriteStream writeStream(buffer);
       
   388 			WriteAttributeDataToStreamL(attributeUid, writeStream);
       
   389 			writeStream.CommitL();
       
   390 			User::LeaveIfError(repository->Set(attributeUid.iUid, buffer));
       
   391 			}
       
   392 		CleanupStack::Pop(); // repository->CleanupCancelTransactionPushL
       
   393 		TUint32 notUsed=0;
       
   394 		error=repository->CommitTransaction(notUsed);
       
   395 		} while (error==KErrLocked);
       
   396 	User::LeaveIfError(error);
       
   397 	CleanupStack::PopAndDestroy(2, repository);
       
   398 	}
       
   399 
       
   400 EXPORT_C void MFepAttributeStorer::MFepAttributeStorer_Reserved_1()
       
   401 	{
       
   402 	}
       
   403 
       
   404 EXPORT_C void MFepAttributeStorer::MFepAttributeStorer_Reserved_2()
       
   405 	{
       
   406 	}
       
   407 
       
   408 TInt MFepAttributeStorer::NumberOfOccurrencesOfAttributeUid(TUid aAttributeUid) const
       
   409 	{
       
   410 	TInt numberOfOccurrencesOfAttributeUid=0;
       
   411 	for (TInt i=NumberOfAttributes()-1; i>=0; --i)
       
   412 		{
       
   413 		if (aAttributeUid==AttributeAtIndex(i))
       
   414 			{
       
   415 			++numberOfOccurrencesOfAttributeUid;
       
   416 			}
       
   417 		}
       
   418 	return numberOfOccurrencesOfAttributeUid;
       
   419 	}