cbsref/telephonyrefplugins/atltsy/atcommand/sms/src/atsmsstoreread.cpp
branchRCL_3
changeset 20 07a122eea281
parent 19 630d2f34d719
child 21 4814c5a49428
equal deleted inserted replaced
19:630d2f34d719 20:07a122eea281
     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 atsmsstoreread.cpp
       
    15 // This contains CAtSmsStoreRead which is used to Read PDU Message
       
    16 // via aIndex 
       
    17 // 
       
    18 
       
    19 
       
    20 //system include 
       
    21 #include <ctsy/ltsy/cctsydispatchercallback.h>
       
    22 
       
    23 //user include 
       
    24 #include "atsmsstoreread.h"
       
    25 #include "mslogger.h"
       
    26 #include "smsatutil.h"
       
    27 
       
    28 //constant defination
       
    29 _LIT8(KSmsReadCommand,"AT+CMGR=%d\r");
       
    30 _LIT8(KCMGRResponseString,"+CMGR:");
       
    31 
       
    32 // ---------------------------------------------------------------------------
       
    33 // CAtSmsStoreRead::CAtSmsStoreRead
       
    34 // other items were commented in a header
       
    35 // ---------------------------------------------------------------------------
       
    36 CAtSmsStoreRead::CAtSmsStoreRead(CGlobalPhonemanager& aGloblePhone, 
       
    37                                  CCtsyDispatcherCallback& aCtsyDispatcherCallback)
       
    38                                  :CAtCommandBase(aGloblePhone,aCtsyDispatcherCallback)
       
    39 	{
       
    40 	LOGTEXT(_L8("CAtSmsStoreRead::CAtSmsStoreRead called"));
       
    41 	}
       
    42 
       
    43 // ---------------------------------------------------------------------------
       
    44 // CAtSmsStoreRead::~CAtSmsStoreRead
       
    45 // other items were commented in a header
       
    46 // ---------------------------------------------------------------------------
       
    47 CAtSmsStoreRead::~CAtSmsStoreRead()
       
    48 	{
       
    49 	LOGTEXT(_L8("CAtSmsStoreRead::~CAtSmsStoreRead called"));
       
    50 	}
       
    51 
       
    52 // ---------------------------------------------------------------------------
       
    53 // CAtSmsStoreRead::NewLC
       
    54 // other items were commented in a header
       
    55 // ---------------------------------------------------------------------------
       
    56 CAtSmsStoreRead* CAtSmsStoreRead::NewLC(CGlobalPhonemanager& aGloblePhone, 
       
    57                                         CCtsyDispatcherCallback& aCtsyDispatcherCallback)
       
    58 	{
       
    59 	CAtSmsStoreRead* self = new (ELeave)CAtSmsStoreRead(aGloblePhone, 
       
    60                                                         aCtsyDispatcherCallback);
       
    61 	CleanupStack::PushL(self);
       
    62 	self->ConstructL();
       
    63 	return self;
       
    64 	}
       
    65 
       
    66 // ---------------------------------------------------------------------------
       
    67 // CAtSmsStoreRead::NewL
       
    68 // other items were commented in a header
       
    69 // ---------------------------------------------------------------------------
       
    70 CAtSmsStoreRead* CAtSmsStoreRead::NewL(CGlobalPhonemanager& aGloblePhone, 
       
    71                                        CCtsyDispatcherCallback& aCtsyDispatcherCallback)
       
    72 	{
       
    73 	CAtSmsStoreRead* self=CAtSmsStoreRead::NewLC(aGloblePhone, 
       
    74                                                  aCtsyDispatcherCallback);
       
    75 	CleanupStack::Pop(self);
       
    76 	return self;
       
    77 	}
       
    78 
       
    79 // ---------------------------------------------------------------------------
       
    80 // CAtSmsStoreRead::ConstructL
       
    81 // other items were commented in a header
       
    82 // ---------------------------------------------------------------------------
       
    83 void CAtSmsStoreRead::ConstructL()
       
    84 	{
       
    85 	CAtCommandBase::ConstructL();
       
    86 	}
       
    87 
       
    88 // ---------------------------------------------------------------------------
       
    89 // CAtSmsStoreRead::StartRequest
       
    90 // other items were commented in a header
       
    91 // ---------------------------------------------------------------------------
       
    92 void CAtSmsStoreRead::StartRequest()
       
    93 	{
       
    94 	ExecuteCommand();
       
    95 	}
       
    96 
       
    97 // ---------------------------------------------------------------------------
       
    98 // CAtSmsStoreRead::ExecuteCommand
       
    99 // other items were commented in a header
       
   100 // ---------------------------------------------------------------------------
       
   101 void CAtSmsStoreRead::ExecuteCommand()
       
   102 	{
       
   103 	LOGTEXT(_L8("CAtSmsStoreRead::ExecuteCommand callded"));
       
   104 	ReadMessage();
       
   105 	}
       
   106 
       
   107 // ---------------------------------------------------------------------------
       
   108 // CAtSmsStoreRead::EventSignal
       
   109 // other items were commented in a header
       
   110 // ---------------------------------------------------------------------------
       
   111 void CAtSmsStoreRead::EventSignal(TAtEventSource aEventSource, TInt aStatus)
       
   112 	{
       
   113 	LOGTEXT3(_L8("CAtSmsStoreRead::EventSignal aStatus=%D iSource=%D"),aStatus,aEventSource);
       
   114 		
       
   115 	if(aStatus == KErrNone)
       
   116 		{
       
   117 		if((aEventSource == EWriteCompletion))
       
   118 			{
       
   119 			LOGTEXT(_L8("CAtSmsStoreRead::EventSignal,EWriteCompletion!"));
       
   120 			return;
       
   121 			}
       
   122 		aStatus = iError;
       
   123 		}
       
   124 	Complete();
       
   125 	iPhoneGlobals.iEventSignalActive = EFalse;
       
   126 	iCtsyDispatcherCallback.CallbackPhonebookSmsStoreReadEntryComp(aStatus,iSmsData);
       
   127 	}
       
   128 
       
   129 // ---------------------------------------------------------------------------
       
   130 // CAtSmsStoreRead::SetMsgIndex
       
   131 // other items were commented in a header
       
   132 // ---------------------------------------------------------------------------
       
   133 void CAtSmsStoreRead::SetMsgIndex(TInt aIndex)
       
   134 	{
       
   135 	LOGTEXT(_L8("CAtSmsStoreRead::SetReadMessageParam callded"));
       
   136 	iIndex = aIndex;
       
   137 	}
       
   138 
       
   139 // ---------------------------------------------------------------------------
       
   140 // CAtSmsStoreRead::ReadMessage
       
   141 // other items were commented in a header
       
   142 // ---------------------------------------------------------------------------
       
   143 void CAtSmsStoreRead::ReadMessage()
       
   144 	{
       
   145 	LOGTEXT(_L8("CAtSmsStoreRead::ReadMessage callded"));
       
   146 	iTxBuffer.Zero();
       
   147 	iTxBuffer.Format(KSmsReadCommand,iIndex);
       
   148 	Write();   
       
   149 	}
       
   150 
       
   151 // ---------------------------------------------------------------------------
       
   152 // CAtSmsStoreRead::ParseResponseL
       
   153 // other items were commented in a header
       
   154 // ---------------------------------------------------------------------------
       
   155 void CAtSmsStoreRead::ParseResponseL(const TDesC8& /*aResponseBuf*/)
       
   156 	{
       
   157 	/**
       
   158 	* Response:+CMGR:<stat>,[<alpha>],<length><CR><LF><pdu>
       
   159 	*/
       
   160 	iError = KErrNone;	
       
   161 	RArray<TPtrC8> array;
       
   162 	CleanupClosePushL(array);
       
   163 	iParser->ParseRespondedBuffer(array,Buffer());
       
   164 	if(array[0].MatchF(KAnyATCommand)!=KErrNotFound)
       
   165 		{
       
   166 		array.Remove(0);
       
   167 		}
       
   168 	TInt count = array.Count();
       
   169 #ifdef _DEBUG
       
   170 	for( TInt i=0;i<count;i++ )
       
   171 		{
       
   172         LOGTEXT3(_L8("CAtSmsStoreRead::ParseResponseL\tarray[%d]=%S"),i,&array[i]);  
       
   173 		}
       
   174 #endif   
       
   175 	if (count <= 1)
       
   176 		{
       
   177 		CleanupStack::PopAndDestroy();
       
   178 		iError = KErrNotFound;
       
   179 		return;
       
   180 		}
       
   181 	if(array[0].MatchF(KCMGRResponseString)==KErrNotFound)
       
   182 		{
       
   183 		LOGTEXT(_L8("CAtSmsStoreRead::ParseResponseL\tFound +CMGR String!"));
       
   184 		CleanupStack::PopAndDestroy();
       
   185 		iError = KErrNotFound;
       
   186 		return;
       
   187 		}
       
   188 	// parse the message status
       
   189 	TLex8 lex(array[1]);
       
   190 	TUint16 val;
       
   191 	TInt ret=lex.Val(val,EDecimal);
       
   192 	if(ret!=KErrNone)
       
   193 		{
       
   194 		CleanupStack::PopAndDestroy();
       
   195 		iError = ret;
       
   196 		return;
       
   197 		}
       
   198 	iSmsData.iMessageStatus = val;
       
   199 	
       
   200 	//parse the message length
       
   201 	TLex8 lex1(array[3]);
       
   202 	TUint msgLength;
       
   203 	ret=lex1.Val(msgLength,EDecimal);
       
   204 	if(ret!=KErrNone)
       
   205 		{
       
   206 		CleanupStack::PopAndDestroy();
       
   207 		iError = ret;
       
   208 		return;
       
   209 		}
       
   210 	LOGTEXT2(_L8("CAtSmsStoreRead::ParseResponseL\tMessage Length=%d"),msgLength);
       
   211 	TBuf8<KMaxAsciiPduLength>  pdu;	   //Binary Message pdu
       
   212 	SmsAtUtil::ConvertAsciiToBinary(array[4],pdu);
       
   213 	TPtrC8 pduPtr(pdu);
       
   214 	
       
   215 	RMobilePhone::TMobileAddress gsmServiceCentre;   //messages's SCA
       
   216 	if (msgLength*2 < array[4].Length())
       
   217 		{
       
   218 		// There is an SCA prepended so remove this and store it in iGsmServiceCentre
       
   219 		SmsAtUtil::ReadAndRemoveAddressFromPdu(pduPtr,gsmServiceCentre);
       
   220 		}
       
   221 	iSmsData.iSmsMsg = pduPtr;
       
   222 	iSmsData.iServiceCentre = gsmServiceCentre.iTelNumber;
       
   223 	iSmsData.iMobileScNPI = gsmServiceCentre.iNumberPlan;
       
   224 	iSmsData.iMobileScTON = gsmServiceCentre.iTypeOfNumber;
       
   225 	LOGTEXT2(_L8("CAtSmsStoreRead::ParseResponseL\tMessage Status=%d"),
       
   226 			                       iSmsData.iMessageStatus);
       
   227 	LOGTEXT3(_L8("CAtSmsStoreRead::ParseResponseL\tSmsMsg=%S, ServiceCentre=%S"), 
       
   228 			                       &iSmsData.iSmsMsg, &iSmsData.iServiceCentre);
       
   229 	CleanupStack::PopAndDestroy(&array);
       
   230 	}
       
   231 
       
   232 //End of file