messagingfw/scheduledsendmtm/schedulesendmtm/src/MsvSendErrorAction.cpp
changeset 0 8e480a14352b
equal deleted inserted replaced
-1:000000000000 0:8e480a14352b
       
     1 // Copyright (c) 1999-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 <msvstd.h>
       
    18 #include <msventry.h>
       
    19 #include <barsread.h>
       
    20 #include <msvsenderroraction.h>
       
    21 #include <schsend_panic.h>
       
    22 
       
    23 
       
    24 //
       
    25 //
       
    26 //	TMsvSendErrorAction Implementation
       
    27 //
       
    28 //
       
    29 
       
    30 /**
       
    31 Default constructor.
       
    32 */
       
    33 
       
    34 EXPORT_C TMsvSendErrorAction::TMsvSendErrorAction()
       
    35 	{
       
    36 	Reset();
       
    37 	}
       
    38 
       
    39 
       
    40 /*
       
    41 EXPORT_C TMsvSendErrorAction::TMsvSendErrorAction(const TMsvSendErrorAction& aErrorAction)
       
    42 	{
       
    43 	iAction			= aErrorAction.iAction;
       
    44 	iError			= aErrorAction.iError;
       
    45 	iMaxRetries		= aErrorAction.iMaxRetries;
       
    46 	iRetries		= aErrorAction.iRetries;
       
    47 	iRetrySpacing	= aErrorAction.iRetrySpacing;
       
    48 	iVersion		= aErrorAction.iVersion;
       
    49 	}
       
    50 */
       
    51 
       
    52 
       
    53 
       
    54 /**
       
    55 Sets all member data to default values.
       
    56 */
       
    57 
       
    58 EXPORT_C void TMsvSendErrorAction::Reset()
       
    59 	{
       
    60 	iError				= KErrNone;
       
    61 	SetMaxRetries(3);
       
    62 	iAction				= ESendActionFail;
       
    63 	iRetries			= ESendRetriesFixed;
       
    64 	iRetrySpacing		= ESendRetrySpacingStatic;
       
    65 	}
       
    66 
       
    67 
       
    68 /**
       
    69 Sets the maximum number of retries.
       
    70 
       
    71 @param aMaxRetries
       
    72 Maximum number of retries.
       
    73 
       
    74 @panic ScheduleSend-DLL 21
       
    75 The maximum number of retries is negative.
       
    76 */
       
    77 
       
    78 EXPORT_C void TMsvSendErrorAction::SetMaxRetries(const TInt16 aMaxRetries)
       
    79 	{
       
    80 	__ASSERT_ALWAYS(aMaxRetries >= 0, gPanic(EMaxRetriesMustBePositive));
       
    81 
       
    82 	iMaxRetries = aMaxRetries;
       
    83 	}
       
    84 
       
    85 
       
    86 /**
       
    87 Gets the maximum number of retries.
       
    88 
       
    89 @return Maximum number of retries
       
    90 */
       
    91 
       
    92 EXPORT_C TInt16 TMsvSendErrorAction::MaxRetries() const
       
    93 	{
       
    94 	return iMaxRetries;
       
    95 	}
       
    96 
       
    97 
       
    98 //
       
    99 //
       
   100 // CMsvSendErrorActions Implementation
       
   101 //
       
   102 //
       
   103 
       
   104 /**
       
   105 Allocates and creates a new CMsvSendErrorActions object.
       
   106 
       
   107 @return New object
       
   108 */
       
   109 EXPORT_C CMsvSendErrorActions* CMsvSendErrorActions::NewL()
       
   110 	{
       
   111 	CMsvSendErrorActions* self = CMsvSendErrorActions::NewLC();
       
   112 	CleanupStack::Pop(self); 
       
   113 	return self;
       
   114 	}
       
   115 
       
   116 /**
       
   117 Allocates and creates a new CMsvSendErrorActions object.
       
   118 
       
   119 @return New object
       
   120 */
       
   121 EXPORT_C CMsvSendErrorActions* CMsvSendErrorActions::NewLC()
       
   122 	{
       
   123 	CMsvSendErrorActions* self = new (ELeave) CMsvSendErrorActions();
       
   124 	CleanupStack::PushL(self);
       
   125 	self->ConstructL();
       
   126 	return self;
       
   127 	}
       
   128 
       
   129 //
       
   130 //	CMsvSendErrorActions Constructor
       
   131 //
       
   132 
       
   133 CMsvSendErrorActions::CMsvSendErrorActions()
       
   134 	{
       
   135 	iDefault.Reset();
       
   136 	}
       
   137 
       
   138 
       
   139 void CMsvSendErrorActions::ConstructL()
       
   140 	{
       
   141 	iErrors = new (ELeave) CArrayFixFlat<TMsvSendErrorAction>(1);
       
   142 	}
       
   143 
       
   144 
       
   145 /**
       
   146 Destructor.
       
   147 */
       
   148 
       
   149 EXPORT_C CMsvSendErrorActions::~CMsvSendErrorActions()
       
   150 	{
       
   151 	delete iErrors;
       
   152 	}
       
   153 	
       
   154 EXPORT_C void CMsvSendErrorActions::Reset()
       
   155 	{
       
   156 	iDefault.Reset();
       
   157 	iErrors->Reset();
       
   158 	}
       
   159 
       
   160 
       
   161 /**
       
   162 Adds a TMsvSendErrorAction object. 
       
   163 
       
   164 If a TMsvSendErrorAction already exists in the collection for the same error, 
       
   165 then it is replaced by aAction.
       
   166 
       
   167 @param aErrorAction
       
   168 Error action to add.
       
   169 
       
   170 @leave Any error code but KErrNone and KErrNotFound
       
   171 We tried to delete the error action if it already exists and 
       
   172 RemoveSendErrorAction() returned an error.
       
   173 
       
   174 @leave KErrAlreadyExists
       
   175 A duplicate was found when inserting the error action in the array.
       
   176 */
       
   177 
       
   178 EXPORT_C void CMsvSendErrorActions::AddSendErrorActionL(const TMsvSendErrorAction& aErrorAction)
       
   179 	{
       
   180 	//Delete the error if it already exists.
       
   181 	TInt error = RemoveSendErrorAction(aErrorAction.iError);
       
   182 
       
   183 	if (error != KErrNone && error != KErrNotFound)
       
   184 		{
       
   185 		User::Leave(error);
       
   186 		}
       
   187 
       
   188 	TInt offSet = _FOFF(TMsvSendErrorAction, iError);
       
   189 	TKeyArrayFix key(offSet, ECmpTInt);
       
   190 
       
   191 	//Insert the error action into the array of errors sorted by iError.
       
   192 	//No duplicates allowed
       
   193 	iErrors->InsertIsqL(aErrorAction, key);
       
   194 	}
       
   195 
       
   196 
       
   197 /**
       
   198 Gets an error action for a specified error.
       
   199 
       
   200 @param aError
       
   201 Error to find.
       
   202 
       
   203 @param aErrorAction
       
   204 On return, the corresponding TMsvSendErrorAction.
       
   205 
       
   206 @return KErrNotFound if there is no corresponding TMsvSendErrorAction 
       
   207 for aError.
       
   208 */
       
   209 
       
   210 EXPORT_C TInt CMsvSendErrorActions::GetSendErrorAction(const TInt aError, TMsvSendErrorAction& aErrorAction) const
       
   211 	{
       
   212 	TInt index = 0;
       
   213 	TInt error = Find(aError, index);
       
   214 
       
   215 	if (error == KErrNone)
       
   216 		{
       
   217 		aErrorAction = iErrors->At(index);
       
   218 		}
       
   219 
       
   220 	return error;
       
   221 	}
       
   222 
       
   223 
       
   224 /*
       
   225 	Find
       
   226 
       
   227 	Returns the index of the TMsvSendErrorAction in iErrors where
       
   228 	TMsvSendErrorAction::iError == aError.
       
   229 
       
   230 	Return KErrNotFound if the aError is not found in iErrors
       
   231 */
       
   232 
       
   233 TInt CMsvSendErrorActions::Find(const TInt aError, TInt& aIndex) const
       
   234 	{
       
   235 	TMsvSendErrorAction tempAction;
       
   236 	tempAction.iError = aError;
       
   237 
       
   238 	TInt offSet = _FOFF(TMsvSendErrorAction, iError);
       
   239 	TKeyArrayFix key(offSet, ECmpTInt);
       
   240 
       
   241 	TInt found = iErrors->FindIsq(tempAction, key, aIndex);
       
   242 
       
   243 	if (found != 0) //Not Found
       
   244 		{
       
   245 		return KErrNotFound;
       
   246 		}
       
   247 
       
   248 	return KErrNone;
       
   249 	}
       
   250 
       
   251 
       
   252 /**
       
   253 Removes an error action.
       
   254 
       
   255 @param aError
       
   256 Error to remove.
       
   257 
       
   258 @return KErrNotFound if there is no corresponding TMsvSendErrorAction for 
       
   259 aError
       
   260 */
       
   261 
       
   262 EXPORT_C TInt CMsvSendErrorActions::RemoveSendErrorAction(const TInt aError)
       
   263 	{
       
   264 	TInt index = 0;
       
   265 	
       
   266 	const TInt error = Find(aError, index);
       
   267 
       
   268 	if (error == KErrNone)
       
   269 		{
       
   270 		iErrors->Delete(index);
       
   271 		}
       
   272 
       
   273 	return error;
       
   274 	}
       
   275 
       
   276 
       
   277 
       
   278 
       
   279 /**
       
   280 Restores the object from a resource. 
       
   281 
       
   282 The resource must be of type SEND_ERROR_ACTIONS.
       
   283 
       
   284 @param aReader
       
   285 Resource reader at appropriate resource.
       
   286 
       
   287 @leave AddSendErrorActionL()
       
   288 */
       
   289 
       
   290 EXPORT_C void CMsvSendErrorActions::RestoreFromResourceL(TResourceReader& aReader)
       
   291 	{
       
   292 	iErrors->Reset();
       
   293 
       
   294 	RestoreErrorActionL(aReader, 1, ETrue);
       
   295 
       
   296 	TInt actionTotal = aReader.ReadInt16();
       
   297 
       
   298 	RestoreErrorActionL(aReader, actionTotal, EFalse);
       
   299 	}
       
   300 
       
   301 
       
   302 void CMsvSendErrorActions::RestoreErrorActionL(TResourceReader& aReader, TInt aActionCount, const TBool aDefault)
       
   303 	{
       
   304 	while (aActionCount--)
       
   305 		{
       
   306 		TInt actionFlags = aReader.ReadInt8();
       
   307 		TMsvSendErrorAction errorAction;
       
   308 
       
   309 		errorAction.iAction = (TMsvSendAction) (actionFlags & KActionMask);
       
   310 		errorAction.iRetries = (TMsvSendRetries) (actionFlags & KRetriesMask);
       
   311 		errorAction.iRetrySpacing = (TMsvSendRetrySpacing) (actionFlags & KRetrySpacingMask);
       
   312 
       
   313 		errorAction.SetMaxRetries((TInt16) aReader.ReadInt16());
       
   314 
       
   315 		TInt errorCount = aReader.ReadInt16();
       
   316 
       
   317 		while (errorCount--)
       
   318 			{
       
   319 			errorAction.iError = aReader.ReadInt32();
       
   320 			aDefault ? SetDefault(errorAction) : AddSendErrorActionL(errorAction);
       
   321 			}
       
   322 		}
       
   323 	}
       
   324 
       
   325 
       
   326 
       
   327 /**
       
   328 Gets the object's array of error-actions.
       
   329 
       
   330 @return The object's array of error-actions
       
   331 */
       
   332 
       
   333 EXPORT_C const CArrayFixFlat<TMsvSendErrorAction>& CMsvSendErrorActions::Errors() const
       
   334 	{
       
   335 	return *iErrors;
       
   336 	}
       
   337 
       
   338 
       
   339 /**
       
   340 Sets the object to an array of error-actions.
       
   341 
       
   342 @param aErrors
       
   343 Array to use.
       
   344 
       
   345 @leave AddSendErrorActionL()
       
   346 */
       
   347 
       
   348 EXPORT_C void CMsvSendErrorActions::SetErrorsL(const CArrayFixFlat<TMsvSendErrorAction>& aErrors)
       
   349 	{
       
   350 	iErrors->Reset();
       
   351 
       
   352 	const TInt count = aErrors.Count();
       
   353 
       
   354 	for (TInt i = 0; i < count; i++)
       
   355 		{
       
   356 		AddSendErrorActionL(aErrors[i]);
       
   357 		}
       
   358 	}
       
   359 
       
   360 
       
   361 /**
       
   362 Gets the default error-action.
       
   363 
       
   364 The default is used if a specified error-action is not found for the error.
       
   365 
       
   366 @return Default error-action
       
   367 */
       
   368 
       
   369 EXPORT_C const TMsvSendErrorAction& CMsvSendErrorActions::Default() const
       
   370 	{
       
   371 	return iDefault;
       
   372 	}
       
   373 
       
   374 
       
   375 /**
       
   376 Sets the default error-action.
       
   377 
       
   378 @param aAction
       
   379 Default error-action.
       
   380 */
       
   381 
       
   382 EXPORT_C void CMsvSendErrorActions::SetDefault(const TMsvSendErrorAction& aAction)
       
   383 	{
       
   384 	iDefault = aAction;
       
   385 	}
       
   386