messagingappbase/smsmtm/servermtm/src/SMSRecipientSend.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 #include <e32std.h>
       
    17 #include <e32base.h>
       
    18 #include <msventry.h>
       
    19 #include <smutset.h>
       
    20 #include <gsmubuf.h>
       
    21 #include <smsulog.h>
       
    22 #include <biodb.h>
       
    23 #include <smuthdr.h>
       
    24 
       
    25 #include "SMSRecipientSend.h"
       
    26 #include "SMSSSEND.H"
       
    27 #include "SMSSPAN.H"
       
    28 #include <smsulog.h>
       
    29 #include <logwraplimits.h>
       
    30 
       
    31 CSmsRecipientSend::~CSmsRecipientSend()
       
    32 	{
       
    33 	delete iLogger;
       
    34 
       
    35 	if (iSocket.SubSessionHandle())
       
    36 		{
       
    37 		iSocket.Close();
       
    38 		}
       
    39 
       
    40 	if (iSession.Handle())
       
    41 		{
       
    42 		iSession.Close();
       
    43 		}
       
    44 	}
       
    45 
       
    46 void CSmsRecipientSend::Start(TRequestStatus& aStatus, const TMsvEntry& aEntry, CSmsHeader& aHeader, CSmsNumber& aRecipient)
       
    47 	{
       
    48 	__ASSERT_DEBUG(iState==ESmsRecipientSendWaiting,Panic(KSmssPanicUnexpectedState));
       
    49 
       
    50 	Queue(aStatus);
       
    51 	iEntry		= aEntry;
       
    52 	iHeader		= &aHeader;
       
    53 	iRecipient	= &aRecipient;
       
    54 
       
    55 	TRAPD(err, StartL());
       
    56 
       
    57 	if (err)
       
    58 		Complete(err);
       
    59 	}
       
    60 
       
    61 CSmsRecipientSend::CSmsRecipientSend(TSmsProgress& aProgress, RFs& aFs, CMsvServerEntry& aServerEntry)
       
    62 :	CSmssActive(aFs, aServerEntry, KSmsSessionPriority),
       
    63 	iProgress(aProgress),
       
    64 	iState(ESmsRecipientSendWaiting)
       
    65 	{
       
    66 	CActiveScheduler::Add(this);
       
    67 	}
       
    68 
       
    69 void CSmsRecipientSend::ConstructL()
       
    70 	{
       
    71 	iLogger = CSmsEventLogger::NewL(iFs);
       
    72 	}
       
    73 
       
    74 void CSmsRecipientSend::DoRunL()		
       
    75 	{
       
    76 	switch (iState)
       
    77 		{
       
    78 		case ESmsRecipientSendGetLogEvent:
       
    79 			{
       
    80 			if (iLogger->iStatus == KErrNone)
       
    81 				{
       
    82 				//no log error
       
    83 				ChangeLogEvent();
       
    84 				}
       
    85 			else 
       
    86 				{
       
    87 				//Log error has occurred
       
    88 				if (-(iLogger->iStatus.Int()) == KErrNotFound)
       
    89 					{
       
    90 					AddLogEvent();
       
    91 					}
       
    92 				else
       
    93 					{
       
    94 					SendMessageL();
       
    95 					}
       
    96 				}
       
    97 			break;
       
    98 			}
       
    99 		case ESmsRecipientSendAddLogEvent:
       
   100 			{
       
   101 			TLogId logId = KLogNullId;
       
   102 
       
   103 			if (iLogger->iStatus == KErrNone)
       
   104 				{
       
   105 				//No log error has occurred
       
   106 				logId = iLogger->Event().Id();
       
   107 				}
       
   108 
       
   109 			iHeader->Message().SetLogServerId(logId);
       
   110 			iRecipient->SetLogId(logId);
       
   111 			//do not break here...
       
   112 			}
       
   113 		case ESmsRecipientSendChangeLogEvent:
       
   114 			{
       
   115 			SendMessageL();
       
   116 			break;
       
   117 			}
       
   118 		case ESmsRecipientSendSendingMessage:
       
   119 			{
       
   120 			iState = ESmsRecipientSendWaiting;
       
   121 			break;
       
   122 			}
       
   123 		case ESmsRecipientSendWaiting:
       
   124 		default:
       
   125 			Panic(KSmssPanicUnexpectedState);
       
   126 		}
       
   127 	}
       
   128 
       
   129 void CSmsRecipientSend::DoComplete(TInt& aStatus)
       
   130 	{
       
   131 	//Set the state to waiting
       
   132 	iState		= ESmsRecipientSendWaiting;
       
   133 	iHeader		= NULL;
       
   134 	iRecipient	= NULL;
       
   135 	iEntry		= TMsvEntry();
       
   136 	iProgress.iError = aStatus;
       
   137 
       
   138 	aStatus = KErrNone;
       
   139 
       
   140 	SMSSLOG(FLogFormat(_L8("CSmsRecipientSend completed with %d"), iProgress.iError));
       
   141 	}
       
   142 
       
   143 void CSmsRecipientSend::GetDefaultSendBearerL(TInt aBioType, TBioMsgIdType aBearer, TBioMsgId& rBioMsgId) const
       
   144 	{
       
   145 	CBIODatabase* bdb = CBIODatabase::NewL(iFs);
       
   146 	CleanupStack::PushL(bdb);
       
   147 
       
   148 	TInt index = 0;
       
   149 	TUid uid;
       
   150 	uid.iUid = aBioType;
       
   151 	bdb->GetBioIndexWithMsgIDL(uid, index); //leaves with KErrNotFound if aBioType does not exist in bdb
       
   152 
       
   153 	const CArrayFix<TBioMsgId>* bioIDs = bdb->BIOEntryLC(index);
       
   154 	const TInt count = bioIDs->Count();
       
   155 	TBool found = EFalse;
       
   156 
       
   157 	for (TInt i = 0; !found && i < count; i++) //order important
       
   158 		{
       
   159 		rBioMsgId = bioIDs->At(i);
       
   160 		found = (rBioMsgId.iType == aBearer && AcceptBioMsgId(rBioMsgId));
       
   161 		}
       
   162 
       
   163 	CleanupStack::PopAndDestroy(2); //bdb, bioIDs
       
   164 
       
   165 	if (!found)
       
   166 		User::Leave(KErrNotFound);
       
   167 	}
       
   168 
       
   169 TInt CSmsRecipientSend::AcceptBioType(TInt aBioType, TBioMsgIdType aBearer) const
       
   170 	{
       
   171 	TBioMsgId bioMsgId;
       
   172 	TRAPD(err, GetDefaultSendBearerL(aBioType, aBearer, bioMsgId));
       
   173 	return err;
       
   174 	}
       
   175 
       
   176 void CSmsRecipientSend::GetLogEvent()
       
   177 	{
       
   178 	TLogId id = iRecipient->LogId();
       
   179 	iHeader->Message().SetLogServerId(id);
       
   180 	iLogger->GetEvent(iStatus, id);
       
   181 	SetActive();
       
   182 	iState = ESmsRecipientSendGetLogEvent;
       
   183 	}
       
   184 
       
   185 void CSmsRecipientSend::AddLogEvent()
       
   186 	{
       
   187 	TInt logStatus = R_LOG_DEL_NONE;
       
   188 	iHeader->Message().SetLogServerId(KLogNullId);
       
   189 	
       
   190 	TLogSmsPduData data;
       
   191 	// Initialise the data members
       
   192 	data.iType		= 0;
       
   193 	data.iTotal		= 0;
       
   194 	data.iSent		= 0;
       
   195 	data.iDelivered	= 0;
       
   196 	data.iFailed	= 0;
       
   197 	data.iReceived	= 0;
       
   198 	
       
   199 	iLogger->AddEvent(iStatus, iHeader->Message(), data, &logStatus);
       
   200 	SetActive();
       
   201 	iState = ESmsRecipientSendAddLogEvent;
       
   202 	}
       
   203 
       
   204 void CSmsRecipientSend::ChangeLogEvent()
       
   205 	{
       
   206 	TInt logStatus = R_LOG_DEL_NONE;
       
   207 	TLogSmsPduData data;
       
   208 	data.iType		= 0;
       
   209 	data.iTotal		= 0;
       
   210 	data.iSent		= 0;
       
   211 	data.iDelivered	= 0;
       
   212 	data.iFailed	= 0;
       
   213 	data.iReceived	= 0;
       
   214 	iLogger->ChangeEvent(iStatus, iHeader->Message(), data, &logStatus);
       
   215 	SetActive();
       
   216 	iState = ESmsRecipientSendChangeLogEvent;
       
   217 	}
       
   218 
       
   219 void CSmsRecipientSend::DoSmssCancel()
       
   220 	{
       
   221 	switch (iState)
       
   222 		{
       
   223 		case ESmsRecipientSendGetLogEvent:
       
   224 		case ESmsRecipientSendAddLogEvent:
       
   225 		case ESmsRecipientSendChangeLogEvent:
       
   226 			SMSSLOG(FLogFormat(_L8("CSmsRecipientSend::DoSmssCancel() cancelling logging for msg %d"), iEntry.Id()));
       
   227 			iLogger->Cancel();
       
   228 			break;
       
   229 		case ESmsRecipientSendSendingMessage:
       
   230 			DoCancelSendingMessage();
       
   231 			break;
       
   232 		default:
       
   233 			break;
       
   234 		}
       
   235 	}