sysstatemgmt/systemstatemgr/cmd/src/ssmcustomcommandinfo.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 <e32base.h>
       
    17 #include <s32strm.h>
       
    18 #include <ssm/ssmcustomcommandinfo.h>
       
    19 
       
    20 #include "ssmdebug.h"
       
    21 
       
    22 /** 
       
    23 Constructor
       
    24 */
       
    25 EXPORT_C CSsmCustomCommandInfo::CSsmCustomCommandInfo()
       
    26 	: iOrdinal(1)
       
    27 	{
       
    28 	}
       
    29 
       
    30 /** 
       
    31 Destructor
       
    32 */
       
    33 EXPORT_C CSsmCustomCommandInfo::~CSsmCustomCommandInfo()
       
    34 	{
       
    35 	delete iParams;
       
    36 	}
       
    37 
       
    38 
       
    39 /** 
       
    40 Set command info contents
       
    41 
       
    42 @param aFileName	A Custom Command DLL file name
       
    43 @param aOrdinal		The ordinal to call to return a MSsmCustomCommand object
       
    44 @param aUnloading	Whether to unload the Custom Command DLL immediately when finished or not
       
    45 @param aRetries		The number of times to try calling the Custom Command if unsuccessful
       
    46 @param aParams		Optional user data to be passed to the Custom Command
       
    47 @leave				One of the system-wide error codes.
       
    48 */
       
    49 EXPORT_C void CSsmCustomCommandInfo::SetL(const TDesC& aFileName, TInt32 aOrdinal, TCmdCustomCommandLibUnloading aUnloading, TInt16 aRetries, const TDesC8& aParams)
       
    50 	{
       
    51 	iFileName = aFileName;
       
    52 	iOrdinal = aOrdinal;
       
    53 	iUnloading = aUnloading;
       
    54 	iRetries = aRetries;
       
    55 
       
    56 	delete iParams;
       
    57 	iParams = NULL;
       
    58 	if (aParams.Length())
       
    59 		{
       
    60 		iParams = aParams.AllocL();
       
    61 		}
       
    62 	}
       
    63 
       
    64 /** 
       
    65 Clear command info contents and reset to default values
       
    66 */
       
    67 EXPORT_C void CSsmCustomCommandInfo::Clear()
       
    68 	{
       
    69 	iFileName = KNullDesC;
       
    70 	iOrdinal = 1;
       
    71 	iUnloading = EUnloadOnCommandCompletion;
       
    72 	iRetries = 0;
       
    73 
       
    74 	delete iParams;
       
    75 	iParams = NULL;
       
    76 	}
       
    77 
       
    78 /** 
       
    79 @return The DLL name, or KNullDesC if empty
       
    80 */
       
    81 EXPORT_C const TFileName& CSsmCustomCommandInfo::FileName() const
       
    82 	{
       
    83 	return iFileName;
       
    84 	}
       
    85 
       
    86 /** 
       
    87 @return The ordinal called to obtain the MSsmCustomCommand object
       
    88 */
       
    89 EXPORT_C TInt32 CSsmCustomCommandInfo::Ordinal() const
       
    90 	{
       
    91 	return iOrdinal;
       
    92 	}
       
    93 
       
    94 /** 
       
    95 @return DLL unloading rule whether to unload the custom command dll after the command has completed or not at all
       
    96 @see TCmdCustomCommandLibUnloading
       
    97 */
       
    98 EXPORT_C TCmdCustomCommandLibUnloading CSsmCustomCommandInfo::Unloading() const
       
    99 	{
       
   100 	return iUnloading;
       
   101 	}
       
   102 
       
   103 /** 
       
   104 @return Number of retries on failure
       
   105 */
       
   106 EXPORT_C TInt16 CSsmCustomCommandInfo::Retries() const
       
   107 	{
       
   108 	return iRetries;
       
   109 	}
       
   110 
       
   111 /** 
       
   112 @return Params or KNullDesC8 if empty
       
   113 */
       
   114 EXPORT_C const TPtrC8 CSsmCustomCommandInfo::Params() const
       
   115 	{
       
   116 	TPtrC8 params;
       
   117 	if (iParams)
       
   118 		{
       
   119 		params.Set(*iParams);
       
   120 		}
       
   121 	else
       
   122 		{
       
   123 		params.Set(KNullDesC8);
       
   124 		}
       
   125 	return params;
       
   126 	}
       
   127 
       
   128 /** 
       
   129 Overloaded = operator
       
   130 @return A Custom Command object containing the new values
       
   131 */
       
   132 EXPORT_C CSsmCustomCommandInfo& CSsmCustomCommandInfo::operator=(const CSsmCustomCommandInfo& aInfo)
       
   133 	{
       
   134 	// protect against self assignment
       
   135 	if( &aInfo != this)
       
   136 		{
       
   137 		// can't do anything with this if it leaves
       
   138 		TRAP_IGNORE(SetL(aInfo.FileName(), aInfo.Ordinal(), aInfo.Unloading(), aInfo.Retries(), aInfo.Params()));
       
   139 		}
       
   140 
       
   141 	return (*this);
       
   142 	}
       
   143 
       
   144 /**
       
   145 Configures the CSsmCustomCommandInfo object using data contained in a ReadStream
       
   146 @param aReadStream 	A read stream containing BIC data
       
   147 @leave				One of the system-wide error codes.
       
   148 */
       
   149 EXPORT_C void CSsmCustomCommandInfo::InternalizeL(RReadStream& aReadStream)
       
   150 	{
       
   151 	aReadStream >> iFileName;
       
   152 	iOrdinal = aReadStream.ReadInt32L();
       
   153 	iUnloading = static_cast<TCmdCustomCommandLibUnloading>(aReadStream.ReadUint8L());
       
   154 	iRetries = aReadStream.ReadInt16L();
       
   155 
       
   156 	HBufC8* paramptr = HBufC8::NewLC(aReadStream, KMaxDLLParams);
       
   157 	delete iParams;
       
   158 	iParams = NULL;
       
   159 	if (paramptr->Length())
       
   160 		{
       
   161 		paramptr->ReAllocL(paramptr->Length());
       
   162 		iParams = paramptr;
       
   163 		CleanupStack::Pop();
       
   164 		}
       
   165 	else
       
   166 		{
       
   167 		CleanupStack::PopAndDestroy();
       
   168 		}
       
   169 	}
       
   170 
       
   171 /**
       
   172 Externalises the CSsmCustomCommandInfo object
       
   173 @param aWriteStream A write stream to write the object data to
       
   174 @leave				One of the system-wide error codes.
       
   175 */
       
   176 EXPORT_C void CSsmCustomCommandInfo::ExternalizeL(RWriteStream& aWriteStream) const
       
   177 	{
       
   178 	aWriteStream << iFileName;
       
   179   	aWriteStream.WriteInt32L(Ordinal());
       
   180   	aWriteStream.WriteUint8L(Unloading());
       
   181   	aWriteStream.WriteInt16L(Retries());
       
   182 	aWriteStream << Params();
       
   183 	}
       
   184