sysstatemgmt/systemstatemgr/cmd/src/cmdloadsup.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 
       
    19 #include "cmdloadsup.h"
       
    20 #include "ssmdebug.h"
       
    21 #include "ssmcommandparameters.h"
       
    22 
       
    23 /**
       
    24 Used to create an instance of CCmdLoadSup class from a read stream.
       
    25 CSsmCommandList::InternalizeL() uses this method to construct a command from stream.
       
    26 
       
    27 @param aReadStream Read stream containing data through which object can be created
       
    28 @return	A pointer to an object of type CCmdLoadSup.
       
    29 */
       
    30 CCmdLoadSup* CCmdLoadSup::NewL(RReadStream& aReadStream)
       
    31 	{
       
    32 	CCmdLoadSup* self = new (ELeave) CCmdLoadSup();
       
    33 	CleanupStack::PushL(self);
       
    34 	self->ConstructL(aReadStream);
       
    35 	CleanupStack::Pop(self);
       
    36 	return self;
       
    37 	}
       
    38 
       
    39 #ifdef SYMBIAN_SSM_FLEXIBLE_MERGE
       
    40 /**
       
    41 Used to create an instance of CCmdLoadSup class from given parameters.
       
    42 This method is used by SsmCommandFactory to create a command.
       
    43 
       
    44 @param aSeverity 			The severity of the command
       
    45 @param aExecutionBehaviour 	The execution behaviour of the command
       
    46 @param aRetries 			The number of allowed retries
       
    47 @param aInfo	 			SUP-specific info
       
    48 @param aPriority 			The priority of the command in the list
       
    49 @return	A pointer to an object of type CCmdLoadSup.
       
    50 */
       
    51 CCmdLoadSup* CCmdLoadSup::NewL(TCmdErrorSeverity aSeverity, TSsmExecutionBehaviour aExecutionBehaviour, TInt16 aRetries, const TSsmSupInfo& aInfo, const TUint16 aPriority)
       
    52 	{
       
    53 	CCmdLoadSup* self = new (ELeave) CCmdLoadSup(aSeverity, aExecutionBehaviour, aRetries, aPriority);
       
    54 	CleanupStack::PushL(self);
       
    55 	self->ConstructL(aInfo);
       
    56 	CleanupStack::Pop(self);
       
    57 	return self;
       
    58 	}
       
    59 #endif
       
    60 
       
    61 /**
       
    62 Used to create an instance of CCmdLoadSup class from given parameters.
       
    63 This method is used by SsmCommandFactory to create a command.
       
    64 
       
    65 @param aSeverity 			The severity of the command
       
    66 @param aExecutionBehaviour 	The execution behaviour of the command
       
    67 @param aRetries 			The number of allowed retries
       
    68 @param aInfo	 			SUP-specific info
       
    69 @return	A pointer to an object of type CCmdLoadSup.
       
    70 */
       
    71 CCmdLoadSup* CCmdLoadSup::NewL(TCmdErrorSeverity aSeverity, TSsmExecutionBehaviour aExecutionBehaviour, TInt16 aRetries, const TSsmSupInfo& aInfo)
       
    72 	{
       
    73 	CCmdLoadSup* self = new (ELeave) CCmdLoadSup(aSeverity, aExecutionBehaviour, aRetries);
       
    74 	CleanupStack::PushL(self);
       
    75 	self->ConstructL(aInfo);
       
    76 	CleanupStack::Pop(self);
       
    77 	return self;
       
    78 	}
       
    79 
       
    80 /**
       
    81 Used to create an instance of CCmdLoadSup class from resource.
       
    82 
       
    83 @param aCommandParameters Object data from a resource file
       
    84 @return	A pointer to an object of type CCmdLoadSup.
       
    85 */
       
    86 CCmdLoadSup* CCmdLoadSup::NewL(TSsmCommandParameters& aCommandParameters)
       
    87 	{
       
    88 	CCmdLoadSup* self = new (ELeave) CCmdLoadSup();
       
    89 	CleanupStack::PushL(self);
       
    90 	self->ConstructL(aCommandParameters);
       
    91 	CleanupStack::Pop(self);
       
    92 	return self;
       
    93 	}
       
    94 
       
    95 /**
       
    96 Used to create an instance of CCmdLoadSup class from CCmdLoadSup object
       
    97 Must be used only by CLE
       
    98 @param aCmdLoadSup CCmdLoadSup reference 
       
    99 @return A pointer to an object of type CCmdLoadSup.
       
   100 */
       
   101 CCmdLoadSup* CCmdLoadSup::NewLC(const CCmdLoadSup& aCmdLoadSup)
       
   102     {
       
   103 #ifdef SYMBIAN_SSM_FLEXIBLE_MERGE
       
   104     CCmdLoadSup* self = new (ELeave) CCmdLoadSup(aCmdLoadSup.Severity(),aCmdLoadSup.ExecutionBehaviour(),
       
   105                                                  aCmdLoadSup.Retries(),aCmdLoadSup.Priority());
       
   106 #else
       
   107     CCmdLoadSup* self = new (ELeave) CCmdLoadSup(aCmdLoadSup.Severity(),aCmdLoadSup.ExecutionBehaviour(),
       
   108                                                      aCmdLoadSup.Retries());
       
   109 #endif
       
   110     CleanupStack::PushL(self);
       
   111     self->ConstructL(aCmdLoadSup);
       
   112     return self;
       
   113     }
       
   114 
       
   115 void CCmdLoadSup::ConstructL(const CCmdLoadSup& aCmdLoadSup)
       
   116     {
       
   117     iConditionalResourceId = aCmdLoadSup.ConditionalInformation();
       
   118 #ifdef SYMBIAN_SSM_FLEXIBLE_MERGE
       
   119 	if (iConditionalResourceId != 0)
       
   120         {
       
   121         SetCommandResourceFileNameL(aCmdLoadSup.GetCommandResourceFileName());
       
   122         }
       
   123 #endif
       
   124     iSupInfo = aCmdLoadSup.SsmSupInfo();
       
   125     iSupInfoBuf = new (ELeave) TPckgC<TSsmSupInfo>(iSupInfo);
       
   126     }
       
   127 
       
   128 /**
       
   129 Destructor
       
   130 */	
       
   131 CCmdLoadSup::~CCmdLoadSup()
       
   132 	{
       
   133 	Cancel();
       
   134 	iSusCli.Close();
       
   135 	delete iSupInfoBuf;
       
   136 	}
       
   137 
       
   138 /**
       
   139 Initialises the BIC's active object and initiates the command
       
   140 
       
   141 @param aStatus 	the TRequestStatus of the active object calling this BIC
       
   142 */	
       
   143 void CCmdLoadSup::Execute(TRequestStatus& aStatus)
       
   144 	{
       
   145 	aStatus = KRequestPending;
       
   146 	iExecuteRequest = &aStatus;
       
   147 
       
   148 	if (iExecutionBehaviour != ESsmWaitForSignal)
       
   149 		{
       
   150 		// complete the execute request with KErrNone so that CLE can execute next command
       
   151 		CompleteExecuteRequest(KErrNone);
       
   152 		}
       
   153 
       
   154 	// try to connect and request to load a SUP
       
   155 	TInt err = ConnectAndLoadSup();	
       
   156 	if (KErrNone != err)
       
   157 		{
       
   158 		// we need to retry in case of failures otherwise we have successfully requested for transition
       
   159 		CompleteRequest(iStatus, err);
       
   160 		}
       
   161 	SetActive();
       
   162 	}
       
   163 
       
   164 /**
       
   165 Releases resources associated with this BIC
       
   166 */	
       
   167 void CCmdLoadSup::Release()
       
   168 	{
       
   169 	delete this;
       
   170 	}
       
   171 
       
   172 /**
       
   173 Initiates a Cancel on the object. 
       
   174 */	
       
   175 void CCmdLoadSup::ExecuteCancel()
       
   176 	{
       
   177 	Cancel();
       
   178 	CompleteDeferredExecuteRequest(KErrCancel);
       
   179 	}
       
   180 
       
   181 /**
       
   182 Returns the Type of the BIC
       
   183  
       
   184 @return	The Type of the BIC
       
   185 */	
       
   186 TSsmCommandType CCmdLoadSup::Type() const
       
   187 	{
       
   188 	return (ESsmCmdLoadSup);
       
   189 	}
       
   190 
       
   191 /**
       
   192 Returns the Version of the BIC
       
   193  
       
   194 @return	The maximum supported version of the BIC
       
   195 */	
       
   196 TInt CCmdLoadSup::MaxSupportedVersion()
       
   197 	{
       
   198 #ifdef SYMBIAN_SSM_FLEXIBLE_MERGE
       
   199 	return (static_cast<TInt>(ECmdLoadSupVersionWithPriority));
       
   200 #else
       
   201 	return (static_cast<TInt>(ECmdLoadSupInitialVersion));
       
   202 #endif
       
   203 	}
       
   204 
       
   205 /**
       
   206 Configures the BIC using data contained in a ReadStream
       
   207  
       
   208 @param aReadStream 	A read stream containing BIC data
       
   209 */
       
   210 void CCmdLoadSup::InternalizeL(RReadStream& aReadStream)
       
   211 	{
       
   212 	iSeverity = static_cast<TCmdErrorSeverity>(aReadStream.ReadInt16L());
       
   213 	iExecutionBehaviour = static_cast<TSsmExecutionBehaviour>(aReadStream.ReadUint8L());
       
   214 	TSsmSupInfo info;
       
   215 	info.InternalizeL(aReadStream);
       
   216 	iRetries = aReadStream.ReadInt16L();
       
   217 #ifdef SYMBIAN_SSM_FLEXIBLE_MERGE
       
   218 	iPriority = aReadStream.ReadUint16L();
       
   219 #endif
       
   220 	ConstructL(info);
       
   221 	}
       
   222 
       
   223 /**
       
   224 Externalises the configuration of the BIC
       
   225  
       
   226 @param aWriteStream A write stream to write BIC data to
       
   227 */
       
   228 void CCmdLoadSup::ExternalizeL(RWriteStream& aWriteStream) const
       
   229 	{
       
   230 	aWriteStream.WriteInt16L(iSeverity);
       
   231 	aWriteStream.WriteUint8L(iExecutionBehaviour);
       
   232 	iSupInfo.ExternalizeL(aWriteStream);
       
   233 	aWriteStream.WriteInt16L(iRetries);
       
   234 #ifdef SYMBIAN_SSM_FLEXIBLE_MERGE
       
   235 	aWriteStream.WriteUint16L(iPriority);
       
   236 #endif
       
   237 	}
       
   238 
       
   239 /**
       
   240 Completes the tasks of the BIC
       
   241 */
       
   242 void CCmdLoadSup::RunL()
       
   243 	{
       
   244 	DEBUGPRINT3A("CCmdLoadSup::RunL: Retry attempts %d Connected %d", iAttempts, iConnected);
       
   245 	if (iStatus.Int() != KErrNone)
       
   246 		{
       
   247 		if (++iAttempts >= iRetries)
       
   248 			{
       
   249 			SSMLOGLEAVE(iStatus.Int());				// exhausted retries
       
   250 			}
       
   251 		// try to connect and load sup
       
   252 		TInt err = ConnectAndLoadSup();	
       
   253 		if (KErrNone != err)
       
   254 			{
       
   255 			// we need to retry in case of failures
       
   256 			CompleteRequest(iStatus, err);
       
   257 			}
       
   258 		SetActive();
       
   259 		}
       
   260 	else
       
   261 		{
       
   262 		CompleteDeferredExecuteRequest(KErrNone);	// success
       
   263 		}
       
   264 	}
       
   265 
       
   266 /**
       
   267 Called to handle any cleanup if RunL leaves
       
   268  
       
   269 @param aError 	The error to finish with
       
   270 @return			KErrNone
       
   271 */
       
   272 TInt CCmdLoadSup::RunError(TInt aError)
       
   273 	{
       
   274 	CompleteDeferredExecuteRequest(aError);
       
   275 	return KErrNone;
       
   276 	}
       
   277 
       
   278 /**
       
   279 Called during cancellation of the active BIC
       
   280 */
       
   281 void CCmdLoadSup::DoCancel()
       
   282 	{
       
   283 	iSusCli.RequestLoadSupCancel();
       
   284 	}
       
   285 /**
       
   286 Default constructor.
       
   287 */
       
   288 CCmdLoadSup::CCmdLoadSup()
       
   289 	{
       
   290 	}
       
   291 
       
   292 
       
   293 #ifdef SYMBIAN_SSM_FLEXIBLE_MERGE
       
   294 /**
       
   295 Overloaded constructor
       
   296 
       
   297 @param aSeverity 	The severity of the command
       
   298 @param aExecutionBehaviour Execution behaviour for this command
       
   299 @param aRetries Number of retries used for this command
       
   300 @param aPriority The priority of the command in the list
       
   301 */	
       
   302 CCmdLoadSup::CCmdLoadSup(TCmdErrorSeverity aSeverity, TSsmExecutionBehaviour aExecutionBehaviour, TInt16 aRetries, const TUint16 aPriority)
       
   303 	: CSsmDeferrableCommand(aSeverity, aExecutionBehaviour, aPriority), iRetries(aRetries)
       
   304 	{
       
   305 	}
       
   306 #endif
       
   307 
       
   308 /**
       
   309 Overloaded constructor
       
   310 
       
   311 @param aSeverity 	The severity of the command
       
   312 @param aExecutionBehaviour Execution behaviour for this command
       
   313 @param aRetries Number of retries used for this command
       
   314 */	
       
   315 CCmdLoadSup::CCmdLoadSup(TCmdErrorSeverity aSeverity, TSsmExecutionBehaviour aExecutionBehaviour, TInt16 aRetries)
       
   316 	: CSsmDeferrableCommand(aSeverity, aExecutionBehaviour), iRetries(aRetries)
       
   317 	{
       
   318 	}
       
   319 
       
   320 /**
       
   321 Constructs the object through read stream.
       
   322 @param aReadStream A read stream containing BIC data
       
   323 */
       
   324 void CCmdLoadSup::ConstructL(RReadStream& aReadStream)
       
   325 	{
       
   326 	InternalizeL(aReadStream);
       
   327 	}
       
   328 
       
   329 /**
       
   330 Constructs an object from resource file.
       
   331 
       
   332 @param aCommandParameters Object data from a resource file
       
   333 */
       
   334 void CCmdLoadSup::ConstructL(TSsmCommandParameters& aCommandParameters)
       
   335 	{
       
   336 	RResourceReader& reader = aCommandParameters.MainReader();
       
   337 	const TSsmCommandType type = static_cast<TSsmCommandType>(reader.ReadInt16L());
       
   338 	SSMLOGLEAVEIFFALSE(type == Type(), KErrNotSupported);
       
   339 	const TInt version = reader.ReadInt16L();
       
   340 	SSMLOGLEAVEIFFALSE(__COMPARE_VERSION(version, CCmdLoadSup::MaxSupportedVersion()), KErrNotSupported);
       
   341 	iSeverity = static_cast<TCmdErrorSeverity>(reader.ReadInt16L());
       
   342 	iExecutionBehaviour = static_cast<TSsmExecutionBehaviour>(reader.ReadUint8L());
       
   343 	const TPtrC filename = reader.ReadTPtrCL();
       
   344 	const TUid uid = { reader.ReadUint32L() };
       
   345 	const TInt32 ordinal = reader.ReadInt32L();
       
   346 	iRetries = reader.ReadInt16L();
       
   347 
       
   348 #ifdef SYMBIAN_SSM_FLEXIBLE_MERGE
       
   349 	iPriority = (version > ECmdLoadSupInitialVersion) ? reader.ReadUint16L() : KDefaultCommandPriority;
       
   350 #endif
       
   351 	TSsmSupInfo info;
       
   352 	info.SetL(filename, ordinal, uid);
       
   353 	ConstructL(info);
       
   354 	}
       
   355 
       
   356 /**
       
   357 Constructs an object from TSsmSupInfo.
       
   358 @param aInfo SUP-specific info
       
   359 */
       
   360 void CCmdLoadSup::ConstructL(const TSsmSupInfo& aInfo)
       
   361 	{
       
   362 	iSupInfo.SetL(aInfo.FileName(), aInfo.NewLOrdinal(), aInfo.Identity());
       
   363 	iSupInfoBuf = new TPckgC<TSsmSupInfo>(iSupInfo);
       
   364 	SSMLOGLEAVEIFNULL(iSupInfoBuf);
       
   365 	ValidateL();
       
   366 	}
       
   367 
       
   368 /**
       
   369 Function to validate the data.
       
   370 @leave KErrArgument If commands data is not valid
       
   371 */
       
   372 void CCmdLoadSup::ValidateL()
       
   373 	{
       
   374 	CSsmDeferrableCommand::ValidateL();
       
   375 
       
   376 	SSMLOGLEAVEIFFALSE(iSupInfo.FileName().Length() >0, KErrArgument);
       
   377 	SSMLOGLEAVEIFFALSE(iSupInfo.NewLOrdinal() >0, KErrArgument);
       
   378 	SSMLOGLEAVEIFFALSE(iRetries >=0, KErrArgument);
       
   379 	}
       
   380 
       
   381 /**
       
   382 Function to connect to RSsmSusCli and request to load a SUP if connect is successful.
       
   383 @return KErrNone if connect is successful and RequestLoadSup() is called,
       
   384 otherwise return one of the system wide error codes
       
   385 */
       
   386 TInt CCmdLoadSup::ConnectAndLoadSup()
       
   387 	{
       
   388 	if (!iConnected)
       
   389 		{
       
   390 		TInt err = iSusCli.Connect();
       
   391 		if (KErrNone != err)
       
   392 			{
       
   393 			return err;
       
   394 			}
       
   395 		iConnected = ETrue;
       
   396 		}
       
   397 	const TDesC8& info = (*iSupInfoBuf);
       
   398 	iSusCli.RequestLoadSup(info, iStatus);
       
   399 
       
   400 	return KErrNone;
       
   401 	}
       
   402