telephonyserverplugins/multimodetsy/Multimode/sms/cmti_stored.cpp
changeset 0 3553901f7fa8
child 24 6638e7f4bd8f
equal deleted inserted replaced
-1:000000000000 0:3553901f7fa8
       
     1 // Copyright (c) 1997-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 <etelmm.h>				// for RMobileSmsMessaging::TMobileSmsReceiveAttributesV1
       
    17 #include "mSLOGGER.H"			// for LOGTEXT2 and other logging utilities
       
    18 #include "ATIO.H"			
       
    19 #include "Matstd.h"
       
    20 #include "cmti_stored.h"		// header file for this cpp file
       
    21 #include "sms_rx_queue.h"		// for CReceiveSmsQueue
       
    22 
       
    23 #ifdef __LOGDEB__
       
    24 _LIT8(KLogEntry,"CATSmsWaitForAndHandleCMTIStored::%S\t%S");
       
    25 #define LOCAL_LOGTEXT(function,text) {_LIT8(F,function);_LIT8(T,text);LOGTEXT3(KLogEntry,&F,&T);}
       
    26 #else
       
    27 #define LOCAL_LOGTEXT(function,text)
       
    28 #endif
       
    29 
       
    30 
       
    31 CATSmsWaitForAndHandleCMTIStored* CATSmsWaitForAndHandleCMTIStored::NewL(CATIO* aIo,CTelObject* aTelObject, CPhoneGlobals* aGlobals,
       
    32 									                                     CReceiveSmsQueue& aReceiveQueue)
       
    33 	{
       
    34 	CATSmsWaitForAndHandleCMTIStored* wait=new(ELeave) CATSmsWaitForAndHandleCMTIStored(aIo,aTelObject,aGlobals,aReceiveQueue);
       
    35 	// Currently no need for a ConstructL call
       
    36 	return wait;
       
    37 	}
       
    38 
       
    39 CATSmsWaitForAndHandleCMTIStored::CATSmsWaitForAndHandleCMTIStored(CATIO* aIo, CTelObject* aTelObject,
       
    40 												   CPhoneGlobals* aGlobals, CReceiveSmsQueue& aReceiveQueue) 
       
    41 	:CATBase(aIo,aTelObject,aGlobals)
       
    42 	,iReceiveQueue(aReceiveQueue)
       
    43 	{}
       
    44 
       
    45 
       
    46 CATSmsWaitForAndHandleCMTIStored::~CATSmsWaitForAndHandleCMTIStored()
       
    47 	{
       
    48 	iIo->RemoveExpectStrings(this);		
       
    49 	// We do not need to NULL iCMTExpectString and iCDSExpectString
       
    50 	// as this object is about to de destroyed
       
    51 	}
       
    52 
       
    53 void CATSmsWaitForAndHandleCMTIStored::Enable()
       
    54 	{
       
    55 	LOCAL_LOGTEXT("Enable","Enabled listening for CMTI");
       
    56 		
       
    57 	if (!iMsgArrivedExpectString)
       
    58 		iMsgArrivedExpectString=iIo->AddExpectString(this,KCMTIMatchString);
       
    59 	}
       
    60 
       
    61 void CATSmsWaitForAndHandleCMTIStored::Disable()
       
    62 	{
       
    63 	LOCAL_LOGTEXT("Disable","Disabled listening for CMTI");
       
    64 	iIo->RemoveExpectStrings(this);		
       
    65 	iMsgArrivedExpectString=NULL;
       
    66 	}
       
    67 
       
    68 
       
    69 void CATSmsWaitForAndHandleCMTIStored::EventSignal(TEventSource aSource)
       
    70 /**
       
    71  * Called when a '+CMTI:' is received.
       
    72  * Pushes the received messages details (store name & index) into the CReceiveSmsQueue.
       
    73  */
       
    74 	{
       
    75 	LOCAL_LOGTEXT("EventSignal","Enter function");
       
    76 
       
    77 	TInt ret(KErrNone);
       
    78 	RMobileSmsMessaging::TMobileSmsReceiveAttributesV1 rxAttr;
       
    79 		
       
    80 	__ASSERT_ALWAYS(aSource == EReadCompletion, Panic(EATCommand_IllegalCompletionReadExpected));
       
    81 	__ASSERT_ALWAYS(iPhoneGlobals, Panic(EIllegalNullPtrParameter));
       
    82 	TRAP(ret, CMTIResponseL(rxAttr));
       
    83 	if(ret!=KErrNone)
       
    84 		{
       
    85 		LOCAL_LOGTEXT("EventSignal","Unable to parse CMTI response");
       
    86 		}
       
    87 	else
       
    88 		{
       
    89 		//
       
    90 		// Add the received SMS's details in the CReceiveSmsQueue object
       
    91 		LOCAL_LOGTEXT("EventSignal","Adding SMS details to iReceiveQueue");
       
    92 		RMobileSmsMessaging::TMobileSmsGsmTpdu nullPdu;
       
    93 		nullPdu.Zero();
       
    94 		iReceiveQueue.Push(nullPdu,rxAttr);
       
    95 		
       
    96 		// If no AT command is currently running then we have to prod the CReceiveSmsQueue
       
    97 		// to try and read PDUs from the phone.
       
    98 		// This is because the CReceiveSmsQueue object only attempts to read PDUs
       
    99 		// from the phone just after an AT command completes (see CATCommands::Complete).
       
   100 		// There may not be another AT command completed during the life
       
   101 		// of the TSY, so we have to prod CReceiveSmsQueue so that it can complete
       
   102 		// any outstanding ReadMessage reqeuests.	
       
   103 		if(!iPhoneGlobals->iEventSignalActive)
       
   104 			{
       
   105 			LOCAL_LOGTEXT("EventSignal","Prodding CReceiveSmsQueue object");
       
   106 
       
   107 			// Allow the CReceiveSmsQueue object to read PDUs from the phones memory, if needed
       
   108 			if(iPhoneGlobals->iReceiveSmsQueuePtr)
       
   109 				iPhoneGlobals->iReceiveSmsQueuePtr->ReadPDUFromPhone();
       
   110 			}			
       
   111 		else
       
   112 			{
       
   113 			LOCAL_LOGTEXT("EventSignal","Can not prod CReceiveSmsQueue object as iEventSignalActive");
       
   114 			}
       
   115 
       
   116 		// We are done, but there is no client request to complete
       
   117 		// we just return and wait until we get our next CMTI command
       
   118 		}
       
   119 	}
       
   120 
       
   121 void CATSmsWaitForAndHandleCMTIStored::CMTIResponseL(RMobileSmsMessaging::TMobileSmsReceiveAttributesV1& aAttr)
       
   122 	{
       
   123 	// +CMTI: <type>, <index>
       
   124 	//        string,  number
       
   125 
       
   126 	ParseLineLC();
       
   127 	CATParamListEntry* entry;
       
   128 	TDblQueIter<CATParamListEntry> iter(iRxResults);
       
   129 
       
   130 	//
       
   131 	// Validate we did actually receive the CMTI string
       
   132 	entry=iter++;
       
   133 	if (!entry || entry->iResultPtr != KCMTIResponseString)
       
   134 		User::Leave(KErrGeneral);
       
   135 
       
   136 	//
       
   137 	// Parse and store the store name where the message is stored
       
   138 	entry=iter++;
       
   139 	if (!entry)
       
   140 		User::Leave(KErrGeneral);
       
   141 	CATSmsUtils::ConvertStoreNameToEtelMMVersion(aAttr.iStore,entry->iResultPtr);
       
   142 
       
   143 	//
       
   144 	// Parse and store the index in the store where the message has been stored
       
   145 	entry=iter++;
       
   146 	if (!entry)
       
   147 		User::Leave(KErrGeneral);
       
   148 	TLex8 lex(entry->iResultPtr);
       
   149 	(void)User::LeaveIfError(lex.Val(aAttr.iStoreIndex));
       
   150 
       
   151 	{
       
   152 	//
       
   153 	// For logging purposes we need a 8 bit descriptor 
       
   154 	TBuf8<RMobilePhone::KMaxMobileNameSize> buf;
       
   155 	buf.Copy(aAttr.iStore);
       
   156 	LOCAL_LOGTEXT("CMTIResponseL","Have parsed CMTI response string");
       
   157 	LOGTEXT3(_L8("Index=%d  Store=%S"),aAttr.iStoreIndex,&buf);
       
   158 	}
       
   159 
       
   160 	CleanupStack::PopAndDestroy();	// PopAndDestory object pushed by ParseLineLC
       
   161 	}
       
   162 
       
   163 
       
   164 void CATSmsWaitForAndHandleCMTIStored::CompleteWithIOError(TEventSource /*aSource*/,TInt aStatus)
       
   165 	{
       
   166 	LOCAL_LOGTEXT("CompleteWithIOError","Enter function");
       
   167 	// CATIO removes expect strings in event of IO error so don't do it here
       
   168 	iMsgArrivedExpectString=NULL;	
       
   169 	// inform client of error so that it does not continue to wait for incoming SMS
       
   170 	// now that this wait object has been disabled
       
   171 	iReceiveQueue.CompleteClientReqWithError(aStatus);
       
   172 	}
       
   173