sysstatemgmt/systemstatemgr/cmd/src/cmdsetpandskey.cpp
changeset 0 4e1aa6a622a0
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     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 #include <s32strm.h>
       
    17 #include <e32property.h>
       
    18 #include <barsread2.h>
       
    19 
       
    20 #include "ssmcommandparameters.h"
       
    21 #include "cmdsetpandskey.h"
       
    22 #include "ssmdebug.h"
       
    23 #include "ssmpanic.h"
       
    24 
       
    25 #ifdef SYMBIAN_SSM_FLEXIBLE_MERGE
       
    26 /**
       
    27 Used to create an instance of CCmdSetPAndSKey class, from given parameters.
       
    28 This method is used by SsmCommandFactory to create a command.
       
    29 
       
    30 @param aSeverity The severity of the command
       
    31 @param aCategory The UID that identifies the property category.
       
    32 @param aKey The property sub-key, i.e. the key that identifies the specific property within the category.
       
    33 @param aValue The new property value.
       
    34 @param aPriority The priority of the command in the list
       
    35 @return	A pointer to an object of type CCmdSetPAndSKey.
       
    36 */
       
    37 CCmdSetPAndSKey* CCmdSetPAndSKey::NewL(TCmdErrorSeverity aSeverity, const TUid& aCategory, TUint aKey, TInt aValue, const TUint16 aPriority)
       
    38 	{
       
    39 	CCmdSetPAndSKey* self = new (ELeave) CCmdSetPAndSKey(aSeverity, aCategory, aKey, aValue, aPriority);
       
    40 	return self;
       
    41 	}
       
    42 #endif
       
    43 
       
    44 /**
       
    45 Used to create an instance of CCmdSetPAndSKey class, from given parameters.
       
    46 This method is used by SsmCommandFactory to create a command.
       
    47 
       
    48 @param aSeverity The severity of the command
       
    49 @param aCategory The UID that identifies the property category.
       
    50 @param aKey The property sub-key, i.e. the key that identifies the specific property within the category.
       
    51 @param aValue The new property value.
       
    52 @return	A pointer to an object of type CCmdSetPAndSKey.
       
    53 */
       
    54 CCmdSetPAndSKey* CCmdSetPAndSKey::NewL(TCmdErrorSeverity aSeverity, const TUid& aCategory, TUint aKey, TInt aValue)
       
    55 	{
       
    56 	CCmdSetPAndSKey* self = new (ELeave) CCmdSetPAndSKey(aSeverity, aCategory, aKey, aValue);
       
    57 	return self;
       
    58 	}
       
    59 
       
    60 /**
       
    61 Used to create an instance of CCmdSetPAndSKey class from a read stream.
       
    62 CSsmCommandList::InternalizeL() uses this method to construct a command from stream.
       
    63 
       
    64 @param aReadStream Read stream containing data through which object can be created
       
    65 @return	A pointer to an object of type CCmdSetPAndSKey.
       
    66 */
       
    67 CCmdSetPAndSKey* CCmdSetPAndSKey::NewL(RReadStream& aReadStream)
       
    68 	{
       
    69 	CCmdSetPAndSKey* self = new (ELeave) CCmdSetPAndSKey();
       
    70 	CleanupStack::PushL(self);
       
    71 	self->ConstructL(aReadStream);
       
    72 	CleanupStack::Pop(self);
       
    73 	return self;
       
    74 	}
       
    75 
       
    76 /**
       
    77 Used to create an instance of CCmdSetPAndSKey class from resource.
       
    78 
       
    79 @param aCommandParameters Object data from a resource file
       
    80 @return	A pointer to an object of type CCmdSetPAndSKey.
       
    81 */
       
    82 CCmdSetPAndSKey* CCmdSetPAndSKey::NewL(TSsmCommandParameters& aCommandParameters)
       
    83 	{
       
    84 	CCmdSetPAndSKey* self = new (ELeave) CCmdSetPAndSKey();
       
    85 	CleanupStack::PushL(self);
       
    86 	self->ConstructL(aCommandParameters);
       
    87 	CleanupStack::Pop(self);
       
    88 	return self;
       
    89 	}
       
    90 
       
    91 /**
       
    92 Used to create an instance of CCmdSetPAndSKey class from CCmdSetPAndSKey object
       
    93 Must be used only by CLE
       
    94 @param aCmdSetPAndSKey CCmdSetPAndSKey reference 
       
    95 @return A pointer to an object of type CCmdSetPAndSKey.
       
    96 */
       
    97 CCmdSetPAndSKey* CCmdSetPAndSKey::NewLC(const CCmdSetPAndSKey& aCmdSetPAndSKey)
       
    98     {
       
    99 #ifdef SYMBIAN_SSM_FLEXIBLE_MERGE
       
   100     CCmdSetPAndSKey* self = new (ELeave) CCmdSetPAndSKey(aCmdSetPAndSKey.Severity(),aCmdSetPAndSKey.Category(),
       
   101                                                          aCmdSetPAndSKey.Key(),aCmdSetPAndSKey.Value(),aCmdSetPAndSKey.Priority());
       
   102 #else
       
   103     CCmdSetPAndSKey* self = new (ELeave) CCmdSetPAndSKey(aCmdSetPAndSKey.Severity(),aCmdSetPAndSKey.Category(),
       
   104                                                              aCmdSetPAndSKey.Key(),aCmdSetPAndSKey.Value());
       
   105 #endif
       
   106     CleanupStack::PushL(self);
       
   107     self->ConstructL(aCmdSetPAndSKey);
       
   108     return self;
       
   109     }
       
   110 
       
   111 void CCmdSetPAndSKey::ConstructL(const CCmdSetPAndSKey& aCmdSetPAndSKey)
       
   112     {
       
   113     iConditionalResourceId = aCmdSetPAndSKey.ConditionalInformation();
       
   114 #ifdef SYMBIAN_SSM_FLEXIBLE_MERGE
       
   115 	if (iConditionalResourceId != 0)
       
   116         {
       
   117         SetCommandResourceFileNameL(aCmdSetPAndSKey.GetCommandResourceFileName());
       
   118         } 
       
   119 #endif 
       
   120      }   
       
   121 
       
   122 /**
       
   123 Returns the version of the BIC
       
   124 @return		The maximum supported version of the BIC
       
   125 */
       
   126 TInt CCmdSetPAndSKey::MaxSupportedVersion()
       
   127 	{
       
   128 #ifdef SYMBIAN_SSM_FLEXIBLE_MERGE
       
   129 	return (static_cast<TInt>(ECmdSetPAndSKeyVersionWithPriority));
       
   130 #else
       
   131 	return (static_cast<TInt>(ECmdSetPAndSKeyInitialVersion));
       
   132 #endif	
       
   133 	}
       
   134 
       
   135 /**
       
   136 Destructor
       
   137 */
       
   138 CCmdSetPAndSKey::~CCmdSetPAndSKey()
       
   139 	{
       
   140 	Cancel();
       
   141 	}
       
   142 
       
   143 /**
       
   144 Execute this command
       
   145 @param aStatus 	The TRequestStatus which is completed when value is set either 
       
   146 				with KErrNone or with error value.
       
   147 */
       
   148 void CCmdSetPAndSKey::Execute(TRequestStatus& aStatus)
       
   149 	{
       
   150 	aStatus = KRequestPending;
       
   151 	iExecuteRequest = &aStatus;
       
   152 
       
   153 	SetActive();
       
   154 	TRequestStatus* status = &iStatus;
       
   155 	User::RequestComplete(status, KErrNone);
       
   156 	}
       
   157 
       
   158 /**
       
   159 Releases resources associated with this BIC
       
   160 */
       
   161 void CCmdSetPAndSKey::Release()
       
   162 	{
       
   163 	delete this;
       
   164 	}
       
   165 
       
   166 /**
       
   167 Cancels the BIC
       
   168 */
       
   169 void CCmdSetPAndSKey::ExecuteCancel()
       
   170 	{
       
   171 	//cancel the outstanding request
       
   172 	Cancel();
       
   173 	//and complete the request with KErrCancel
       
   174 	CompleteExecuteRequest(KErrCancel);
       
   175 	}
       
   176 
       
   177 /**
       
   178 Returns the type of the BIC
       
   179 @return Type of BIC
       
   180 */
       
   181 TSsmCommandType CCmdSetPAndSKey::Type() const
       
   182 	{
       
   183 	return (ESsmCmdSetPAndSKey);
       
   184 	}
       
   185 
       
   186 /**
       
   187 Externalises the configuration of the BIC
       
   188 
       
   189 @param aWriteStream A write stream to write BIC data to
       
   190 */
       
   191  void CCmdSetPAndSKey::ExternalizeL(RWriteStream& aWriteStream) const
       
   192  	{
       
   193  	aWriteStream.WriteInt16L(iSeverity);
       
   194  	aWriteStream.WriteUint32L(iCategory.iUid);
       
   195  	aWriteStream.WriteUint32L(iKey);
       
   196  	aWriteStream.WriteInt16L(iValue);
       
   197 #ifdef SYMBIAN_SSM_FLEXIBLE_MERGE
       
   198 	aWriteStream.WriteUint16L(iPriority);
       
   199 #endif
       
   200  	}
       
   201  
       
   202 void CCmdSetPAndSKey::RunL()
       
   203 	{
       
   204 	TInt err = RProperty::Set(iCategory, iKey, iValue);
       
   205 	DEBUGPRINT3A("Value %d is set with err : %d", iValue, err);
       
   206 	if (KErrNotFound == err)
       
   207 		{
       
   208 		DEBUGPRINT1A("key not defined");
       
   209 		//try to define
       
   210 		_LIT_SECURITY_POLICY_PASS(KReadPolicy);
       
   211 		_LIT_SECURITY_POLICY_S0(KWritePolicy, RProcess().SecureId());
       
   212 		DEBUGPRINT1A("Defining key");
       
   213  		err = RProperty::Define(iCategory, iKey, RProperty::EInt, KReadPolicy, KWritePolicy);
       
   214  		DEBUGPRINT2A("Key defined with err : %d", err);
       
   215 	 	if (KErrNone == err)
       
   216 	 		{
       
   217 	 		DEBUGPRINT1A("Property defined, setting it again");
       
   218 	 		// and set it again
       
   219 	 		err = RProperty::Set(iCategory, iKey, iValue);
       
   220 	 		DEBUGPRINT2A("Value set with err : %d", err);
       
   221 	 		}		
       
   222 		}
       
   223 	//complete the request
       
   224 	CompleteExecuteRequest(err);
       
   225 	}
       
   226 
       
   227 /**
       
   228 Cancellation of an outstanding request.
       
   229 */
       
   230 void CCmdSetPAndSKey::DoCancel()
       
   231 	{
       
   232 	// This command need not to cancel as iStatus is always completed before it's SetActive()
       
   233 	}
       
   234 
       
   235 /**
       
   236 Complete the command request with aError. It gets called when RunL leaves.
       
   237 
       
   238 @param aError Error code with which RunL has left.
       
   239 @return KErrNone, as error is handled in this function.
       
   240 */
       
   241 TInt CCmdSetPAndSKey::RunError(TInt aError)
       
   242 	{
       
   243 	DEBUGPRINT2A("CCmdSetPAndSKey::RunError called with reason %d", aError);
       
   244 	CompleteExecuteRequest(aError);
       
   245 	return KErrNone;
       
   246 	}
       
   247 
       
   248 #ifdef SYMBIAN_SSM_FLEXIBLE_MERGE
       
   249 /**
       
   250 Overloaded constructor
       
   251 
       
   252 @param aSeverity 	The severity of the command
       
   253 @param aCategory 	The UID that identifies the property category.
       
   254 @param aKey 		The property sub-key, i.e. the key that identifies the specific property within the 
       
   255 					category.
       
   256 @param aValue 		The new property value.
       
   257 @param aPriority 	The priority of the command in the list
       
   258 */	
       
   259 CCmdSetPAndSKey::CCmdSetPAndSKey(TCmdErrorSeverity aSeverity, const TUid& aCategory, TUint aKey, TInt aValue, const TUint16 aPriority)
       
   260 	: CSsmCommandBase(aSeverity, aPriority), iCategory(aCategory), iKey(aKey), iValue(aValue)
       
   261 	{
       
   262 	}
       
   263 #endif
       
   264 
       
   265 /**
       
   266 Overloaded constructor
       
   267 
       
   268 @param aSeverity 	The severity of the command
       
   269 @param aCategory 	The UID that identifies the property category.
       
   270 @param aKey 		The property sub-key, i.e. the key that identifies the specific property within the 
       
   271 					category.
       
   272 @param aValue 		The new property value.
       
   273 */	
       
   274 CCmdSetPAndSKey::CCmdSetPAndSKey(TCmdErrorSeverity aSeverity, const TUid& aCategory, TUint aKey, TInt aValue)
       
   275 	: CSsmCommandBase(aSeverity), iCategory(aCategory), iKey(aKey), iValue(aValue)
       
   276 	{
       
   277 	}
       
   278 
       
   279 /**
       
   280  Default constructor.
       
   281  */
       
   282 CCmdSetPAndSKey::CCmdSetPAndSKey()
       
   283 	{
       
   284 	}
       
   285 
       
   286 /**
       
   287 Constructs the object through read stream.
       
   288 @param aReadStream
       
   289 */
       
   290 void CCmdSetPAndSKey::ConstructL(RReadStream& aReadStream)
       
   291 	{
       
   292 	InternalizeL(aReadStream);
       
   293 	}
       
   294 
       
   295 /**
       
   296 Constructs an object from resource file.
       
   297 
       
   298 @param aCommandParameters Object data from a resource file
       
   299 */
       
   300 void CCmdSetPAndSKey::ConstructL(TSsmCommandParameters& aCommandParameters)
       
   301 	{
       
   302 	RResourceReader& reader = aCommandParameters.MainReader();
       
   303 	const TSsmCommandType type = static_cast<TSsmCommandType>(reader.ReadInt16L());
       
   304 	SSMLOGLEAVEIFFALSE(type == Type(), KErrNotSupported);
       
   305 	const TInt version = reader.ReadInt16L();
       
   306 	SSMLOGLEAVEIFFALSE(__COMPARE_VERSION(version, CCmdSetPAndSKey::MaxSupportedVersion()), KErrNotSupported);
       
   307 	iSeverity = static_cast<TCmdErrorSeverity>(reader.ReadInt16L());
       
   308 	iCategory = TUid::Uid(reader.ReadUint32L());
       
   309 	iKey = reader.ReadUint32L();
       
   310 	iValue = reader.ReadInt16L();
       
   311 #ifdef SYMBIAN_SSM_FLEXIBLE_MERGE
       
   312 	iPriority = (version > ECmdSetPAndSKeyInitialVersion) ? reader.ReadUint16L() : KDefaultCommandPriority;
       
   313 #endif
       
   314 	}
       
   315 
       
   316 /**
       
   317 Configures the BIC using data contained in a ReadStream
       
   318  
       
   319 @param aReadStream 	A read stream containing BIC data
       
   320 */
       
   321 void CCmdSetPAndSKey::InternalizeL(RReadStream& aReadStream)
       
   322 	{
       
   323 	iSeverity = static_cast<TCmdErrorSeverity>(aReadStream.ReadInt16L());
       
   324 	iCategory.iUid = aReadStream.ReadUint32L();
       
   325 	iKey = aReadStream.ReadUint32L();
       
   326 	iValue = aReadStream.ReadInt16L();
       
   327 #ifdef SYMBIAN_SSM_FLEXIBLE_MERGE
       
   328 	iPriority = aReadStream.ReadUint16L();
       
   329 #endif	
       
   330 	}
       
   331