messagingappbase/smsmtm/servermtm/src/SMSSchSend.cpp
changeset 25 84d9eb65b26f
parent 23 238255e8b033
child 27 e4592d119491
child 37 518b245aa84c
child 79 2981cb3aa489
equal deleted inserted replaced
23:238255e8b033 25:84d9eb65b26f
     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 #ifdef _DEBUG
       
    17 #undef _MSG_NO_LOGGING
       
    18 #endif
       
    19 
       
    20 #include <msvstd.h>
       
    21 #include <msventry.h>
       
    22 
       
    23 #include "SMSSchSend.h"
       
    24 #include <smutset.h>
       
    25 
       
    26 #ifndef _MSG_NO_LOGGING
       
    27 #include <flogger.h>
       
    28 #endif
       
    29 
       
    30 /*
       
    31  *	CSmsScheduleSend Implementation
       
    32  */
       
    33  
       
    34 CSmsScheduleSend* CSmsScheduleSend::NewL(CMsvServerEntry& aServerEntry)
       
    35 	{
       
    36 	CSmsScheduleSend* self = new (ELeave) CSmsScheduleSend(aServerEntry);
       
    37 	CleanupStack::PushL(self);
       
    38 	self->ConstructL();
       
    39 	CleanupStack::Pop(self);
       
    40 	return self;
       
    41 	}
       
    42 
       
    43 CSmsScheduleSend::CSmsScheduleSend(CMsvServerEntry& aServerEntry)
       
    44 	: CMsvScheduleSend(aServerEntry)
       
    45 	{
       
    46 	}
       
    47 
       
    48 /*
       
    49 Returns a pointer to a newly created CSmsScheduledEntry for a specified message.
       
    50 
       
    51 The CSmsScheduledEntry encapsulates the scheduling and recipient information
       
    52 relating to the message identified by aId.
       
    53 
       
    54 @param	Id
       
    55 The ID for the specified message.
       
    56 
       
    57 @return
       
    58 A pointer to the created CSmsScheduledEntry object,
       
    59 */
       
    60 CMsvScheduledEntry* CSmsScheduleSend::GetMessageL(const TMsvId aId) const
       
    61 	{
       
    62 	//Set the iServerEntry to the message identified by aId
       
    63 	User::LeaveIfError(iServerEntry.SetEntry(aId));
       
    64 	
       
    65 	//Create a new CSmsScheduledEntry
       
    66 	CSmsScheduledEntry* entry = CSmsScheduledEntry::NewL(iServerEntry.Entry());
       
    67 	CleanupStack::PushL(entry);
       
    68 	CMsvStore* store = iServerEntry.ReadStoreL();
       
    69 	CleanupStack::PushL(store);
       
    70 	//Restore the entry from the message's store.
       
    71 	entry->RestoreL(*store);
       
    72 
       
    73 	CleanupStack::PopAndDestroy(store);
       
    74 	CleanupStack::Pop(entry);
       
    75 
       
    76 	return entry;
       
    77 	}
       
    78 
       
    79 /*
       
    80  *	CSmsScheduledEntry Implementation
       
    81  */
       
    82 
       
    83 CSmsScheduledEntry* CSmsScheduledEntry::NewL(const TMsvEntry& aEntry)
       
    84 	{
       
    85 	CSmsScheduledEntry* self = new (ELeave) CSmsScheduledEntry(aEntry);
       
    86 	CleanupStack::PushL(self);
       
    87 	self->ConstructL();
       
    88 	CleanupStack::Pop(self);
       
    89 	return self;
       
    90 	}
       
    91 
       
    92 CSmsScheduledEntry::CSmsScheduledEntry(const TMsvEntry& aEntry)
       
    93 	: CMsvScheduledEntry(aEntry)
       
    94 	{
       
    95 	}
       
    96 
       
    97 void CSmsScheduledEntry::ConstructL()
       
    98 	{
       
    99 	iParaLayer = CParaFormatLayer::NewL();
       
   100 	iCharLayer = CCharFormatLayer::NewL();
       
   101 	iRichText = CRichText::NewL( iParaLayer, iCharLayer, CEditableText::EFlatStorage, 256 );
       
   102 	iHeader = CSmsHeader::NewL(CSmsPDU::ESmsSubmit,*iRichText);
       
   103 	}
       
   104 
       
   105 CSmsScheduledEntry::~CSmsScheduledEntry()
       
   106 	{
       
   107 	// don't delete iRecipient
       
   108 	delete iHeader;
       
   109 	delete iRichText;
       
   110 	delete iCharLayer;
       
   111 	delete iParaLayer;
       
   112 	}
       
   113 
       
   114 void CSmsScheduledEntry::RecipientsStoreL(CMsvStore& aStore) const
       
   115 	{
       
   116 	iHeader->StoreL(aStore);
       
   117 	}
       
   118 
       
   119 void CSmsScheduledEntry::RecipientsRestoreL(CMsvStore& aStore)
       
   120 	{
       
   121 	iHeader->RestoreL(aStore);
       
   122 	}
       
   123 
       
   124 TBool CSmsScheduledEntry::CanSendToAnyRecipients(const TMsvSendErrorAction& aAction)
       
   125 	{
       
   126 	CArrayPtrFlat<CSmsNumber>& numbers = iHeader->Recipients();
       
   127 	TInt count = numbers.Count();
       
   128 
       
   129 	TBool retVal = EFalse;
       
   130 
       
   131 	while (count--)
       
   132 		{
       
   133 		CSmsNumber* rcpt = numbers[count];
       
   134 
       
   135 		retVal |= CheckRecipient(*rcpt, aAction);
       
   136 		}
       
   137 
       
   138 	return retVal;
       
   139 	}
       
   140 
       
   141 TBool CSmsScheduledEntry::RecipientsAllSent() const
       
   142 	{
       
   143 	//Returns whether all recipients of this SMS have sent successfully.
       
   144 	//If there are NO recipients, then returns EFalse.
       
   145 
       
   146 	CArrayPtrFlat<CSmsNumber>& numbers = iHeader->Recipients();
       
   147 	TInt count = numbers.Count();
       
   148 	TBool retVal = count;
       
   149 
       
   150 	while (retVal && count--)
       
   151 		{
       
   152 		CSmsNumber* rcpt = numbers[count];
       
   153 		retVal &= (rcpt->Status() == CMsvRecipient::ESentSuccessfully);
       
   154 		}
       
   155 
       
   156 	return retVal;
       
   157 	}
       
   158 
       
   159 TBool CSmsScheduledEntry::CheckRecipient(CSmsNumber& aRcpt, const TMsvSendErrorAction& aAction)
       
   160 	{
       
   161 #ifndef _MSG_NO_LOGGING
       
   162 	TPtrC address(aRcpt.Address());
       
   163 	RFileLogger::WriteFormat(KSchSendLogDir, KSchSendLogFile, EFileLoggingModeAppend,
       
   164 		_L("\t\tCSmsScheduledEntry::CheckRecipient() aRcpt %S: Status %d Retries %d, aAction: Action %d Retries %d MaxRetries %d"),
       
   165 		&address,
       
   166 		aRcpt.Status(),
       
   167 		aRcpt.Retries(),
       
   168 		aAction.iAction,
       
   169 		aAction.iRetries,
       
   170 		aAction.MaxRetries());
       
   171 #endif
       
   172 
       
   173 	TBool retVal = EFalse;
       
   174 
       
   175 	if (aRcpt.Status() != CMsvRecipient::ESentSuccessfully)
       
   176 		{
       
   177 		if (aAction.iAction == ESendActionSentAlready)
       
   178 			{
       
   179 			aRcpt.SetStatus(CMsvRecipient::ESentSuccessfully);
       
   180 			}
       
   181 		else if (aAction.iAction == ESendActionFail)
       
   182 			{
       
   183 			aRcpt.SetStatus(CMsvRecipient::EFailedToSend);
       
   184 			}
       
   185 		else if (aAction.iRetries == ESendRetriesInfinite || aRcpt.Retries() < aAction.MaxRetries())
       
   186 			{
       
   187 			aRcpt.SetStatus(CMsvRecipient::ENotYetSent);
       
   188 			retVal = ETrue;
       
   189 			}
       
   190 		else
       
   191 			{
       
   192 			aRcpt.SetStatus(CMsvRecipient::EFailedToSend);
       
   193 			}
       
   194 		}
       
   195 
       
   196 	return retVal;
       
   197 	}
       
   198 
       
   199 /**
       
   200 Returns ETrue if the message can still sent to any of its recipients.
       
   201 Otherwise returns EFalse.
       
   202 
       
   203 The appropriate error action is also returned. The error action determines if a
       
   204 particular recipient can be re-scheduled. The appropriate error action is given
       
   205 from the list of error actions, which defines the action for a particular error
       
   206 code.
       
   207 
       
   208 @param	aErrorActions
       
   209 The list of error actions that define what re-schedule is required for particular
       
   210 error codes.
       
   211 
       
   212 @param	aAction
       
   213 An output argument with the error action appropriate for the recipient send error.
       
   214 
       
   215 @return
       
   216 A boolean value indicatinng whether the message can be sent to any of its
       
   217 recipients.
       
   218 */
       
   219 TBool CSmsScheduledEntry::CanSendToAnyRecipients(const CMsvSendErrorActions& aErrorActions, TMsvSendErrorAction& aAction)
       
   220 	{
       
   221 	CArrayPtrFlat<CSmsNumber>& numbers = iHeader->Recipients();
       
   222 	TInt count = numbers.Count();
       
   223 
       
   224 	TBool retVal = EFalse;
       
   225 
       
   226 	while (count--)
       
   227 		{
       
   228 		CSmsNumber* rcpt = numbers[count];
       
   229 
       
   230 		TMsvSendErrorAction action;
       
   231 
       
   232 		if (aErrorActions.GetSendErrorAction(rcpt->Error(), action) != KErrNone)
       
   233 			{
       
   234 			action = aErrorActions.Default();
       
   235 			}
       
   236 
       
   237 		if (CheckRecipient(*rcpt, action))
       
   238 			{
       
   239 			retVal = ETrue;
       
   240 			aAction = action;
       
   241 			}
       
   242 		}
       
   243 
       
   244 	return retVal;
       
   245 	}
       
   246 
       
   247 void CSmsScheduledEntry::RecipientsResetRetries()
       
   248 	{
       
   249 	CArrayPtrFlat<CSmsNumber>& numbers = iHeader->Recipients();
       
   250 	TInt count = numbers.Count();
       
   251 
       
   252 	while (count--)
       
   253 		{
       
   254 		CSmsNumber* rcpt = numbers[count];
       
   255 		
       
   256 		if (rcpt->Status() != CMsvRecipient::ESentSuccessfully)
       
   257 			{
       
   258 			rcpt->ResetRetries();
       
   259 			}
       
   260 		}
       
   261 	}
       
   262 
       
   263 void CSmsScheduledEntry::RecipientsIncreaseRetries()
       
   264 	{
       
   265 	CArrayPtrFlat<CSmsNumber>& numbers = iHeader->Recipients();
       
   266 	TInt count = numbers.Count();
       
   267 
       
   268 	while (count--)
       
   269 		{
       
   270 		CSmsNumber* rcpt = numbers[count];
       
   271 		
       
   272 		if (rcpt->Status() != CMsvRecipient::ESentSuccessfully)
       
   273 			{
       
   274 			rcpt->IncreaseRetries();
       
   275 			}
       
   276 		}
       
   277 	}
       
   278 
       
   279 void CSmsScheduledEntry::RecipientsSetFailed()
       
   280 	{
       
   281 	CArrayPtrFlat<CSmsNumber>& numbers = iHeader->Recipients();
       
   282 	TInt count = numbers.Count();
       
   283 
       
   284 	while (count--)
       
   285 		{
       
   286 		CSmsNumber* rcpt = numbers[count];
       
   287 		
       
   288 		if (rcpt->Status() != CMsvRecipient::ESentSuccessfully)
       
   289 			{
       
   290 			rcpt->SetStatus(CMsvRecipient::EFailedToSend);
       
   291 			}
       
   292 		}
       
   293 	}