sysstatemgmt/systemstatemgr/cmd/src/cmdpersisthalattributes.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 <barsread2.h>
       
    18 #include <bautils.h>
       
    19 
       
    20 #include "cmdpersisthalattributes.h"
       
    21 #include "ssmdebug.h"
       
    22 #include "ssmpanic.h"
       
    23 #include "ssmcommandparameters.h"
       
    24 
       
    25 /**
       
    26 Used to create an instance of CCmdPersistHalAttributes class from a read stream.
       
    27 CSsmCommandList::InternalizeL() uses this method to construct a command from stream.
       
    28 
       
    29 @param aReadStream Read stream containing data through which object can be created
       
    30 @return	A pointer to an object of type CCmdPersistHalAttributes.
       
    31 */
       
    32 CCmdPersistHalAttributes* CCmdPersistHalAttributes::NewL(RReadStream& aReadStream)
       
    33 	{
       
    34 	CCmdPersistHalAttributes* self = new (ELeave) CCmdPersistHalAttributes();
       
    35 	CleanupStack::PushL(self);
       
    36 	self->InternalizeL(aReadStream);
       
    37 	CleanupStack::Pop(self);
       
    38 	return self;
       
    39 	}
       
    40 
       
    41 /**
       
    42 Used to create an instance of CCmdPersistHalAttributes class from given parameters.
       
    43 This method is used by SsmCommandFactory to create a command.
       
    44 
       
    45 @param aSeverity The severity of the command
       
    46 @return	A pointer to an object of type CCmdPersistHalAttributes.
       
    47 */
       
    48 CCmdPersistHalAttributes* CCmdPersistHalAttributes::NewL(TCmdErrorSeverity aSeverity)
       
    49 	{
       
    50 	CCmdPersistHalAttributes* self = new (ELeave) CCmdPersistHalAttributes(aSeverity);
       
    51 	return self;
       
    52 	}
       
    53 
       
    54 /**
       
    55 Used to create an instance of CCmdPersistHalAttributes class from resource.
       
    56 
       
    57 @param aCommandParameters Object data from a resource file
       
    58 @return	A pointer to an object of type CCmdPersistHalAttributes.
       
    59 */
       
    60 CCmdPersistHalAttributes* CCmdPersistHalAttributes::NewL(TSsmCommandParameters& aCommandParameters)
       
    61 	{
       
    62 	CCmdPersistHalAttributes* self = new (ELeave) CCmdPersistHalAttributes();
       
    63 	CleanupStack::PushL(self);
       
    64 	self->ConstructL(aCommandParameters);
       
    65 	CleanupStack::Pop(self);
       
    66 	return self;
       
    67 	}
       
    68 
       
    69 /**
       
    70 Used to create an instance of CCmdPersistHalAttributes class from CCmdPersistHalAttributes object
       
    71 Must be used only by CLE
       
    72 @param aCmdPersistHalAttributes CCmdPersistHalAttributes reference 
       
    73 @return A pointer to an object of type CCmdPersistHalAttributes.
       
    74 */
       
    75 CCmdPersistHalAttributes* CCmdPersistHalAttributes::NewLC(const CCmdPersistHalAttributes& aCmdPersistHalAttributes)
       
    76     {
       
    77     CCmdPersistHalAttributes* self = new (ELeave) CCmdPersistHalAttributes(aCmdPersistHalAttributes.Severity());
       
    78     CleanupStack::PushL(self);
       
    79     self->ConstructL(aCmdPersistHalAttributes);
       
    80     return self;
       
    81     }
       
    82 
       
    83 void CCmdPersistHalAttributes::ConstructL(const CCmdPersistHalAttributes& aCmdPersistHalAttributes)
       
    84     {
       
    85     iConditionalResourceId = aCmdPersistHalAttributes.ConditionalInformation();
       
    86 #ifdef SYMBIAN_SSM_FLEXIBLE_MERGE
       
    87 	if (iConditionalResourceId != 0)
       
    88         {
       
    89         SetCommandResourceFileNameL(aCmdPersistHalAttributes.GetCommandResourceFileName());
       
    90         } 
       
    91 #endif   
       
    92     }
       
    93 
       
    94 /**
       
    95 Destructor
       
    96 */	
       
    97 CCmdPersistHalAttributes::~CCmdPersistHalAttributes()
       
    98 	{
       
    99 	Cancel();
       
   100 	}
       
   101 
       
   102 /**
       
   103 Initialises the BIC's active object and initiates the command
       
   104  
       
   105 @param aStatus 	the TRequestStatus of the active object calling this BIC
       
   106 */	
       
   107 void CCmdPersistHalAttributes::Execute( TRequestStatus& aStatus )
       
   108 	{
       
   109 	aStatus = KRequestPending;
       
   110 	iExecuteRequest = &aStatus;
       
   111 	CompleteRequest(iStatus, KErrNone);
       
   112 	SetActive();
       
   113 	}
       
   114 
       
   115 /**
       
   116 Releases resources associated with this BIC
       
   117 */
       
   118 void CCmdPersistHalAttributes::Release()
       
   119 	{
       
   120 	delete this;
       
   121 	}
       
   122 
       
   123 /**
       
   124 Initiates a Cancel on the object. 
       
   125 */
       
   126 void CCmdPersistHalAttributes::ExecuteCancel()
       
   127 	{
       
   128 	Cancel();
       
   129 	CompleteExecuteRequest(KErrCancel);
       
   130 	}
       
   131 
       
   132 /**
       
   133 Returns the Type of the BIC
       
   134 @return	The type of the BIC
       
   135 */	
       
   136 TSsmCommandType CCmdPersistHalAttributes::Type() const
       
   137 	{
       
   138 	return (ESsmCmdPersistHalAttributes);
       
   139 	}
       
   140 
       
   141 /**
       
   142 Returns the Version of the BIC
       
   143 @return	The maximum supported version of the BIC
       
   144 */	
       
   145 TInt CCmdPersistHalAttributes::MaxSupportedVersion()
       
   146 	{
       
   147 	return (static_cast<TInt>(ECmdPersistHalAttributesInitialVersion));
       
   148 	}
       
   149 
       
   150 /**
       
   151 Configures the BIC using data contained in a ReadStream
       
   152  
       
   153 @param aReadStream 	A read stream containing BIC data
       
   154 */
       
   155 void CCmdPersistHalAttributes::InternalizeL(RReadStream& aReadStream)
       
   156 	{
       
   157 	iSeverity = static_cast<TCmdErrorSeverity>(aReadStream.ReadInt16L());
       
   158 	}
       
   159 
       
   160 /**
       
   161 Externalises the configuration of the BIC
       
   162  
       
   163 @param aWriteStream A write stream to write BIC data to
       
   164 */
       
   165 void CCmdPersistHalAttributes::ExternalizeL(RWriteStream& aWriteStream) const
       
   166 	{
       
   167 	aWriteStream.WriteInt16L(iSeverity);
       
   168 	}
       
   169 
       
   170 /**
       
   171 Completes the tasks of the BIC
       
   172 */
       
   173 void CCmdPersistHalAttributes::RunL()
       
   174 	{
       
   175 	// iStatus.Int() is always KErrNone as Execute() sets it to KErrNone
       
   176 	const TInt error = BaflUtils::PersistHAL();
       
   177 	
       
   178 	// These ASSERT_DEBUG statements are useful when the command is executed with 
       
   179 	// IgnoreFailure Severity. Any error is supressed with a panic in DEBUG builds
       
   180 	__ASSERT_DEBUG((KErrNone == error), PanicNow(KPanicCmdPersistHalAttributes, ECmdExecutionFailed));
       
   181 	
       
   182 	// If it fails in UREL builds, the error is just returned to CLE
       
   183 	CompleteExecuteRequest(error);
       
   184 	}
       
   185 
       
   186 /**
       
   187 Called to handle any cleanup if RunL leaves
       
   188  
       
   189 @param aError The error to finish with
       
   190 @return	KErrNone
       
   191 */
       
   192 TInt CCmdPersistHalAttributes::RunError(TInt aError)
       
   193 	{
       
   194 	CompleteExecuteRequest(aError);
       
   195 	return KErrNone;
       
   196 	}
       
   197 
       
   198 /**
       
   199 Called during cancellation of the active BIC
       
   200 */
       
   201 void CCmdPersistHalAttributes::DoCancel()
       
   202 	{
       
   203 	}
       
   204 
       
   205 /**
       
   206 Default constructor.
       
   207 */
       
   208 CCmdPersistHalAttributes::CCmdPersistHalAttributes()
       
   209 	{
       
   210 	}
       
   211 
       
   212 /**
       
   213 Overloaded constructor
       
   214 
       
   215 @param aSeverity The severity of the command
       
   216 */
       
   217 CCmdPersistHalAttributes::CCmdPersistHalAttributes(TCmdErrorSeverity aSeverity)
       
   218 	: CSsmCommandBase(aSeverity)
       
   219 	{
       
   220 	}
       
   221 
       
   222 /**
       
   223 Constructs the object through read stream.
       
   224 
       
   225 @param aReadStream A read stream containing BIC data
       
   226 */
       
   227 void CCmdPersistHalAttributes::ConstructL(RReadStream& aReadStream)
       
   228 	{
       
   229 	InternalizeL(aReadStream);
       
   230 	}
       
   231 
       
   232 /**
       
   233 Constructs an object from resource file.
       
   234 
       
   235 @param aCommandParameters Object data from a resource file
       
   236 */
       
   237 void CCmdPersistHalAttributes::ConstructL(TSsmCommandParameters& aCommandParameters)
       
   238 	{
       
   239 	RResourceReader& reader = aCommandParameters.MainReader();
       
   240 	const TSsmCommandType type = static_cast<TSsmCommandType>(reader.ReadInt16L());
       
   241 	SSMLOGLEAVEIFFALSE(type == Type(), KErrNotSupported);
       
   242 	const TInt version = reader.ReadInt16L();
       
   243 	SSMLOGLEAVEIFFALSE(__COMPARE_VERSION(version, CCmdPersistHalAttributes::MaxSupportedVersion()), KErrNotSupported);
       
   244 	iSeverity = static_cast<TCmdErrorSeverity>(reader.ReadInt16L());
       
   245 	}
       
   246