cbsref/telephonyrefplugins/atltsy/atcommand/sms/src/atsmsstorewrite.cpp
branchRCL_3
changeset 65 630d2f34d719
equal deleted inserted replaced
61:17af172ffa5f 65:630d2f34d719
       
     1 // Copyright (c) 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 // @file atsmsstorewrite.cpp
       
    15 // This contains CAtSmsStoreWrite which is used to write sms message
       
    16 // 
       
    17 
       
    18 //system include 
       
    19 #include <ctsy/ltsy/cctsydispatchercallback.h>
       
    20 
       
    21 //user include
       
    22 #include "atsmsstorewrite.h"
       
    23 #include "mslogger.h"
       
    24 #include "atmanager.h"
       
    25 #include "commengine.h"
       
    26 #include "smsatutil.h"
       
    27 
       
    28 //constant defination
       
    29 _LIT8(KCMGWResponseString,"+CMGW:");
       
    30 _LIT8(KSmsWriteLengthCommand,"AT+CMGW = %d\r");
       
    31 _LIT8(KDefaultSCA,"00");
       
    32 _LIT8(KSmsEnterPduResponse,">");
       
    33 const TInt KLtsyOnePause = 100000;   //0.1s
       
    34 
       
    35 // ---------------------------------------------------------------------------
       
    36 // CAtSmsStoreWrite::CAtSmsStoreWrite
       
    37 // other items were commented in a header
       
    38 // ---------------------------------------------------------------------------
       
    39 CAtSmsStoreWrite::CAtSmsStoreWrite(CGlobalPhonemanager& aGloblePhone, 
       
    40                                    CCtsyDispatcherCallback& aCtsyDispatcherCallback)
       
    41                                    :CAtCommandBase(aGloblePhone,aCtsyDispatcherCallback)
       
    42 	{
       
    43 	LOGTEXT(_L8("CAtSmsStoreWrite::CAtSmsStoreWrite called"));
       
    44 	}
       
    45 
       
    46 // ---------------------------------------------------------------------------
       
    47 // CAtSmsStoreWrite::~CAtSmsStoreWrite
       
    48 // other items were commented in a header
       
    49 // ---------------------------------------------------------------------------
       
    50 CAtSmsStoreWrite::~CAtSmsStoreWrite()
       
    51 	{
       
    52 	LOGTEXT(_L8("CAtSmsStoreWrite::~CAtSmsStoreWrite called"));
       
    53 	delete iCallbackTimer;
       
    54 	iCallbackTimer = NULL;
       
    55 	}
       
    56 
       
    57 // ---------------------------------------------------------------------------
       
    58 // CAtSmsStoreWrite::NewLC
       
    59 // other items were commented in a header
       
    60 // ---------------------------------------------------------------------------
       
    61 CAtSmsStoreWrite* CAtSmsStoreWrite::NewLC(CGlobalPhonemanager& aGloblePhone, 
       
    62                                           CCtsyDispatcherCallback& aCtsyDispatcherCallback)
       
    63 	{
       
    64 	CAtSmsStoreWrite* self = new (ELeave)CAtSmsStoreWrite(aGloblePhone, 
       
    65                                                           aCtsyDispatcherCallback);
       
    66 	CleanupStack::PushL(self);
       
    67 	self->ConstructL();
       
    68 	return self;
       
    69 	}
       
    70 
       
    71 // ---------------------------------------------------------------------------
       
    72 // CAtSmsStoreWrite::NewL
       
    73 // other items were commented in a header
       
    74 // ---------------------------------------------------------------------------
       
    75 CAtSmsStoreWrite* CAtSmsStoreWrite::NewL(CGlobalPhonemanager& aGloblePhone, 
       
    76                                          CCtsyDispatcherCallback& aCtsyDispatcherCallback)
       
    77 	{
       
    78 	CAtSmsStoreWrite* self=CAtSmsStoreWrite::NewLC(aGloblePhone, 
       
    79                                                    aCtsyDispatcherCallback);
       
    80 	CleanupStack::Pop(self);
       
    81 	return self;
       
    82 	}
       
    83 
       
    84 // ---------------------------------------------------------------------------
       
    85 // CAtSmsStoreWrite::ConstructL
       
    86 // other items were commented in a header
       
    87 // ---------------------------------------------------------------------------
       
    88 void CAtSmsStoreWrite::ConstructL()
       
    89 	{
       
    90 	CAtCommandBase::ConstructL();
       
    91 	//Create Timer
       
    92 	iCallbackTimer = CCallbackTimer::NewL(*this);
       
    93 	//set writing timeout
       
    94 	iWriteTimeOut = KLtsyDefaultWriteTimeOut;
       
    95 	AddExpectStringL(KSmsEnterPduResponse);
       
    96 	}
       
    97 
       
    98 // ---------------------------------------------------------------------------
       
    99 // CAtSmsStoreWrite::SeGsmSmsEntry
       
   100 // other items were commented in a header
       
   101 // ---------------------------------------------------------------------------
       
   102 void CAtSmsStoreWrite::SeGsmSmsEntry(RMobileSmsStore::TMobileGsmSmsEntryV1 aMobileGsmEntry)
       
   103 	{
       
   104 	iMobileGsmEntry = aMobileGsmEntry;
       
   105 	}
       
   106 
       
   107 // ---------------------------------------------------------------------------
       
   108 // CAtSmsStoreWrite::StartRequest
       
   109 // other items were commented in a header
       
   110 // ---------------------------------------------------------------------------
       
   111 void CAtSmsStoreWrite::StartRequest()
       
   112 	{
       
   113 	ExecuteCommand();
       
   114 	}
       
   115 
       
   116 // ---------------------------------------------------------------------------
       
   117 // CAtSmsStoreWrite::ExecuteCommand
       
   118 // other items were commented in a header
       
   119 // ---------------------------------------------------------------------------
       
   120 void CAtSmsStoreWrite::ExecuteCommand()
       
   121 	{
       
   122 	LOGTEXT(_L8("CAtSmsStoreWrite::ExecuteCommand callded"));
       
   123 	WriteMessage();
       
   124 	}
       
   125 
       
   126 // ---------------------------------------------------------------------------
       
   127 // CAtSmsStoreWrite::WriteMessage
       
   128 // other items were commented in a header
       
   129 // ---------------------------------------------------------------------------
       
   130 void CAtSmsStoreWrite::WriteMessage()
       
   131 	{
       
   132 	LOGTEXT(_L8("CAtSmsStoreWrite::WriteMessage callded"));
       
   133 	iTxBuffer.Zero();
       
   134 	
       
   135 	RMobilePhone::TMobileAddress  msgSca = iMobileGsmEntry.iServiceCentre;
       
   136 	if( msgSca.iTelNumber.Length()!=0 )
       
   137 		{
       
   138 		//Here is a SCA
       
   139 		TInt ret = SmsAtUtil::AppendAddressToAscii(iMsgDataAscii,msgSca);
       
   140 		if( ret!=KErrNone )
       
   141 			{
       
   142 			BeginTimer();
       
   143 			iCallbackVal = ret;
       
   144 			return;
       
   145 			}
       
   146 		}
       
   147 	else 
       
   148 		{
       
   149 		//Here is no SCA,usign default SCA
       
   150 		iMsgDataAscii.Append(KDefaultSCA);
       
   151 		}
       
   152 	
       
   153 	const TInt msgDataAsciiLen(iMsgDataAscii.Length());
       
   154 	// Convert PDU to ASCII
       
   155 	SmsAtUtil::AppendDataToAscii(iMsgDataAscii,iMobileGsmEntry.iMsgData);
       
   156 	iState = ESetPDULengthComplete;
       
   157 	StartWritingPduLength();	
       
   158 	}
       
   159 
       
   160 // ---------------------------------------------------------------------------
       
   161 // CAtSmsStoreWrite::StartWritingPduLength
       
   162 // other items were commented in a header
       
   163 // ---------------------------------------------------------------------------
       
   164 void CAtSmsStoreWrite::StartWritingPduLength()
       
   165 	{
       
   166 	LOGTEXT(_L8("CAtSmsStoreWrite::StartWritingPduLength called"));
       
   167 	TInt pduLen = iMobileGsmEntry.iMsgData.Length();
       
   168 	iTxBuffer.Zero();
       
   169 	iTxBuffer.Format(KSmsWriteLengthCommand,pduLen);
       
   170 	ClearBuffer();
       
   171 	iPhoneGlobals.iAtManager->SetSolicitedAtCommand(this);
       
   172 	iPhoneGlobals.iCommEngine->CommWrite(iTxBuffer);	
       
   173 	StartTimer(iWriteTimeOut);
       
   174 	}
       
   175 
       
   176 
       
   177 // ---------------------------------------------------------------------------
       
   178 // CAtSmsStoreWrite::StartWritingPdu
       
   179 // other items were commented in a header
       
   180 // ---------------------------------------------------------------------------
       
   181 void CAtSmsStoreWrite::StartWritingPdu()
       
   182 	{
       
   183 	LOGTEXT(_L8("CAtSmsStoreWrite::StartWritingPdu called"));
       
   184 	iTxBuffer.Zero();
       
   185 	iTxBuffer.Append(iMsgDataAscii);
       
   186 	iTxBuffer.Append(KLtsyCtrlZChar);
       
   187 	ClearBuffer();
       
   188 	iPhoneGlobals.iAtManager->SetSolicitedAtCommand(this);
       
   189 	iPhoneGlobals.iCommEngine->CommWrite(iTxBuffer);	
       
   190 	StartTimer(iWriteTimeOut);
       
   191 	}
       
   192 
       
   193 // ---------------------------------------------------------------------------
       
   194 // CAtSmsStoreWrite::EventSignal
       
   195 // other items were commented in a header
       
   196 // ---------------------------------------------------------------------------
       
   197 void CAtSmsStoreWrite::EventSignal(TAtEventSource aEventSource, TInt aStatus)
       
   198 	{
       
   199 	LOGTEXT3(_L8("CAtSmsStoreWrite::EventSignal aStatus=%D iSource=%D"),aStatus,aEventSource);
       
   200 		
       
   201 	if(aStatus == KErrNone)
       
   202 		{
       
   203 		if((aEventSource == EWriteCompletion))
       
   204 			{
       
   205 			LOGTEXT(_L8("CAtSmsStoreWrite::EventSignal,EWriteCompletion!"));
       
   206 			return;
       
   207 			}
       
   208 		else
       
   209 			{
       
   210 			if( iState == ESetPDULengthComplete )
       
   211 				{
       
   212 	            if(iError==KErrNone)
       
   213 	            	{
       
   214 			    	iState = EWritePDUComplete;
       
   215 			    	Complete();
       
   216 			    	StartWritingPdu();
       
   217 			    	return;     
       
   218 	            	}
       
   219 				}
       
   220 			}
       
   221 		aStatus = iError;
       
   222 		}
       
   223 	Complete();
       
   224 	iPhoneGlobals.iEventSignalActive = EFalse;
       
   225 	iCtsyDispatcherCallback.CallbackPhonebookSmsStoreWriteEntryComp(aStatus,iLocation,EFalse);
       
   226 	}
       
   227 
       
   228 // ---------------------------------------------------------------------------
       
   229 // CAtSmsStoreWrite::ParseResponseL
       
   230 // other items were commented in a header
       
   231 // ---------------------------------------------------------------------------
       
   232 void CAtSmsStoreWrite::ParseResponseL(const TDesC8& /*aResponseBuf*/)
       
   233 	{
       
   234     LOGTEXT(_L8("CAtSmsStoreWrite::ParseResponseL called!"));
       
   235     if(iState == ESetPDULengthComplete) 
       
   236 	    {
       
   237    	    if(CurrentLine().MatchF(KSmsEnterPduResponse) != KErrNotFound)
       
   238 	    	{
       
   239 	    	iError = KErrNone;
       
   240 	    	}
       
   241 	    else
       
   242 	    	{
       
   243 	    	iError = KErrNotFound;
       
   244 	    	}
       
   245 	    }
       
   246     else
       
   247     	{
       
   248 	    iError = KErrNone;	
       
   249 	    TPtrC8 responseBuf;
       
   250 	    responseBuf.Set(Buffer());
       
   251 		TInt pos = responseBuf.FindF(KCMGWResponseString);
       
   252 		if (pos == KErrNotFound)
       
   253 			{
       
   254 			LOGTEXT(_L8("CAtSmsStoreWrite::ParseResponseL\tError - Cannot find '+CMGW:' string"));
       
   255 			iError = KErrNotFound;
       
   256 			return;
       
   257 			}
       
   258 		pos += KCMGWResponseString().Length();
       
   259 		//skip a "space" start
       
   260 		while(!(TChar(responseBuf[pos]).IsDigit()))
       
   261 			{
       
   262 			++pos;
       
   263 			}
       
   264 		// Place the message reference number into buffer 
       
   265 		//(ie: everything after +CMGW: string)
       
   266 		TInt refPos = responseBuf.Length()-pos;
       
   267 		responseBuf.Set(responseBuf.Right(refPos));
       
   268 		
       
   269 		
       
   270 		TLex8 lex(responseBuf);
       
   271 		TUint16 val;
       
   272 		TInt ret = lex.Val(val,EDecimal);
       
   273 		if(ret != KErrNone)
       
   274 			{
       
   275 			iError = ret;
       
   276 			return;
       
   277 			}
       
   278 		iLocation = val;
       
   279 		LOGTEXT2(_L8("CAtSmsStoreWrite::ParseResponseL write index =%d"),iLocation);
       
   280     	}
       
   281 	}
       
   282 
       
   283 
       
   284 // ---------------------------------------------------------------------------
       
   285 // CAtSmsStoreWrite::BeginTimer
       
   286 // other items were commented in a header
       
   287 // ---------------------------------------------------------------------------
       
   288 void CAtSmsStoreWrite::BeginTimer()
       
   289 	{
       
   290 	LOGTEXT(_L8("CAtSmsStoreWrite::BeginTimer() called"));	
       
   291 	
       
   292     if (iCallbackTimer->IsActive())
       
   293     	{
       
   294     	iCallbackTimer->Cancel();
       
   295     	}
       
   296 	iCallbackTimer->After(KLtsyOnePause);	
       
   297 	}
       
   298 
       
   299 // ---------------------------------------------------------------------------
       
   300 // CAtSmsStoreWrite::TimerRun
       
   301 // other items were commented in a header
       
   302 // ---------------------------------------------------------------------------
       
   303 void CAtSmsStoreWrite::TimerRun(TInt aError)
       
   304 	{
       
   305 	LOGTEXT(_L8("CAtSmsStoreWrite::TimerRun() called"));
       
   306 	if(aError == KErrNone)
       
   307 		{
       
   308 		Complete();
       
   309 		iPhoneGlobals.iEventSignalActive = EFalse;
       
   310 		iCtsyDispatcherCallback.CallbackPhonebookSmsStoreWriteEntryComp(
       
   311 				                iCallbackVal,iLocation,EFalse);
       
   312 		
       
   313 		}
       
   314 	}
       
   315 
       
   316 //End of file