telephonyserverplugins/multimodetsy/Multimode/sms/sms_rx_queue.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 // Class defintition for CReceiveSmsQueue
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20 */
       
    21 
       
    22 #include <etelmm.h>				// for RMobileSmsMessaging...
       
    23 #include <et_phone.h>           // for TSY_HANDLE_INIT_VALUE
       
    24 #include "mSMSMESS.H"			// for CMobileSmsMessaging...
       
    25 #include "sms_rx_queue.h"		// header for this cpp file
       
    26 #include "mSLOGGER.H"			// for LOGTEXT2...
       
    27 #include "sms_rx_queue_pduread.h"		// for CATSmsReadPDU
       
    28 
       
    29 // Macros
       
    30 #ifdef __LOGDEB__
       
    31 _LIT8(KLogEntry,"CReceiveSmsQueue::%S\t%S");
       
    32 #define LOCAL_LOGTEXT(function,text) {_LIT8(F,function);_LIT8(T,text);LOGTEXT3(KLogEntry,&F,&T);}
       
    33 #else
       
    34 #define LOCAL_LOGTEXT(function,text)
       
    35 #endif
       
    36 
       
    37 
       
    38 CReceiveSmsQueue* CReceiveSmsQueue::NewL(CATIO* aIo,CTelObject* aTelObject,CATInit* aInit,CPhoneGlobals* aGlobals,CMobileSmsMessaging& aMobileSmsMessaging)
       
    39 /** First stage constructor
       
    40  */
       
    41  	{
       
    42 	CReceiveSmsQueue* self=new(ELeave) CReceiveSmsQueue(aMobileSmsMessaging,*aGlobals);
       
    43 	CleanupStack::PushL(self);	
       
    44 	self->ConstructL(aIo,aTelObject,aInit,aGlobals);
       
    45 	CleanupStack::Pop(self);
       
    46 	return self;
       
    47 	}
       
    48 
       
    49 CReceiveSmsQueue::CReceiveSmsQueue(CMobileSmsMessaging& aMobileSmsMessaging,CPhoneGlobals& aGlobals)
       
    50 	: iGlobals(aGlobals), iMobileSmsMessaging(aMobileSmsMessaging)
       
    51  /** C++ constructor
       
    52   */
       
    53 	{}
       
    54 
       
    55 void CReceiveSmsQueue::ConstructL(CATIO* aIo,CTelObject* aTelObject,CATInit* aInit,CPhoneGlobals* aGlobals)
       
    56 /** Second stage constructor
       
    57  */
       
    58 	{
       
    59 	// Create the AT command object which we will use to read PDUs from the 
       
    60 	// phones memory
       
    61 	iATReadPDU=CATSmsReadPDU::NewL(aIo,aTelObject,aInit,aGlobals,*this);
       
    62 	}
       
    63 
       
    64 CReceiveSmsQueue::~CReceiveSmsQueue()
       
    65 /** C++ destructor
       
    66  */
       
    67 	{
       
    68 	delete iATReadPDU;
       
    69 	}
       
    70 
       
    71 
       
    72 
       
    73 void CReceiveSmsQueue::Push(const RMobileSmsMessaging::TMobileSmsGsmTpdu& aPdu, 
       
    74 			      		    const RMobileSmsMessaging::TMobileSmsReceiveAttributesV1& aAttr)
       
    75 	{
       
    76 	LOCAL_LOGTEXT("Push","Pushing item to queue");
       
    77 	LOGTEXT3(_L8("iQueueFront=%d  iQueueBack=%d"),iQueueFront,iQueueBack);
       
    78 		
       
    79 	if(QueueFull())
       
    80 		{
       
    81 		LOCAL_LOGTEXT("Push","Queue overflow!");
       
    82 		// Allow message to drop of front of queue
       
    83 		iQueueFront=(iQueueFront+1)%KReceiveSmsQueueSize;
       
    84 		}
       
    85 
       
    86 	// Copy item into queue
       
    87 	(iQueue[iQueueBack]).iPdu=aPdu;
       
    88 	(iQueue[iQueueBack]).iAttr=aAttr;
       
    89 
       
    90 	// Update pointer
       
    91 	iQueueBack=(iQueueBack+1)%KReceiveSmsQueueSize;
       
    92 
       
    93 	// Try to complete client request in case one was outstanding
       
    94 	CompleteClientReqIfPossible();
       
    95 	}
       
    96 
       
    97 
       
    98 void CReceiveSmsQueue::PopAndCompleteClientWhenPossible(const TTsyReqHandle aReqHandle,
       
    99                                                         RMobileSmsMessaging::TMobileSmsGsmTpdu* aPdu, 
       
   100 									                    RMobileSmsMessaging::TMobileSmsReceiveAttributesV1* aAttr)
       
   101 	{
       
   102 	__ASSERT_DEBUG(iClientReqOutstanding==EFalse,Panic(EReceiveSmsQueueRequestOutstanding));
       
   103 
       
   104 	//
       
   105 	// Store clients request details
       
   106 	iClientReqOutstanding=ETrue;
       
   107 	iClientReq=aReqHandle;
       
   108 	iClientReqPdu=aPdu;
       
   109 	iClientReqAttr=aAttr;
       
   110 
       
   111 	// Try to complete client request
       
   112 	CompleteClientReqIfPossible();
       
   113 	}											
       
   114 
       
   115 void CReceiveSmsQueue::PopAndCompleteClientWhenPossibleCancel()
       
   116 	{
       
   117 	LOCAL_LOGTEXT("PopAndCompleteClientWhenPossibleCancel","Enter function");
       
   118 	LOGTEXT3(_L8("iQueueFront=%d  iQueueBack=%d"),iQueueFront,iQueueBack);
       
   119 	
       
   120 	if(iClientReqOutstanding)
       
   121 		{
       
   122 		// Complete client request with KErrCancel
       
   123 		iMobileSmsMessaging.ReqCompleted(iClientReq,KErrCancel);
       
   124 		iClientReqOutstanding=EFalse;
       
   125 		}
       
   126 	}
       
   127 
       
   128 void CReceiveSmsQueue::ReadPDUFromPhone()
       
   129 /**
       
   130  * ReadPDUFromPhone should be called by CATCommands::Complete at which time the 
       
   131  * TSY base classes guarantee that there is not another AT command which is running.
       
   132  * ReadPDUFromPhone starts the reading of the PDU of the message at the front of
       
   133  * the queue if we do not already store it's PDU.
       
   134  */
       
   135 	{
       
   136 	LOCAL_LOGTEXT("ReadPDUFromPhone","Enter function");
       
   137 
       
   138 	//
       
   139 	// Check if we need to read PDU from phone
       
   140 	if(QueueEmpty())
       
   141 		{
       
   142 		LOCAL_LOGTEXT("ReadPDUFromPhone","Queue is empty, will not read PDU");
       
   143 		return;
       
   144 		}
       
   145 
       
   146 	if((iQueue[iQueueFront]).iPdu.Length()!=0)
       
   147 		{
       
   148 		LOCAL_LOGTEXT("ReadPDUFromPhone","Already have PDU, will not read PDU");
       
   149 		return;
       
   150 		}
       
   151 
       
   152 	LOCAL_LOGTEXT("ReadPDUFromPhone","Need to read a PDU from the phone...");
       
   153 
       
   154 	//
       
   155 	// Read PDU from phone
       
   156 	// (We can call ExecuteCommand with a 0 TSY handle as we are guaranteed, by 
       
   157 	// the CATBase base class that another AT command is not running, and therefore 
       
   158 	// the CATBase will not try to complete this request with KErrInUse 
       
   159 	// due to iEventSignalActive==ETrue)
       
   160 	iATReadPDU->ExecuteCommand(0,&(iQueue[iQueueFront]));
       
   161 	}
       
   162 
       
   163 
       
   164 void CReceiveSmsQueue::CompleteClientReqIfPossible()
       
   165 /**
       
   166  * If there is an oustanding client request then this function
       
   167  * will check to see if the client request can be completed.
       
   168  * If a client request can be completed then this function will 
       
   169  * complete the client request by popping an item from the queue, 
       
   170  * passing the item data to the client and then calling ReqCompleted
       
   171  */	
       
   172 	{
       
   173 	LOCAL_LOGTEXT("CompleteClientReqIfPossible","Enter function");
       
   174 	
       
   175 	//
       
   176 	// We can only complete a client request if...
       
   177 	//   The client has made a request
       
   178 	//   Our Queue is not empty
       
   179 	//   We have the PDU for the message at the front of the queue
       
   180 	if(iClientReqOutstanding && !QueueEmpty() && (iQueue[iQueueFront]).iPdu.Length()!=0)
       
   181 		{
       
   182 		LOCAL_LOGTEXT("CompleteClientReqIfPossible","Popping item from queue");
       
   183 
       
   184 		// Copy item from queue
       
   185 		*iClientReqPdu=(iQueue[iQueueFront]).iPdu;
       
   186 		*iClientReqAttr=(iQueue[iQueueFront]).iAttr;
       
   187 		
       
   188 		// Update pointer
       
   189 		iQueueFront=(iQueueFront+1)%KReceiveSmsQueueSize;
       
   190 
       
   191 		// Complete client request
       
   192 		iMobileSmsMessaging.ReqCompleted(iClientReq,KErrNone);
       
   193 		iClientReqOutstanding=EFalse;
       
   194 		}
       
   195 	}
       
   196 
       
   197 TBool CReceiveSmsQueue::QueueEmpty()
       
   198 /** Class Private Utility function
       
   199  */
       
   200 	{
       
   201 	return iQueueFront==iQueueBack;
       
   202 	}
       
   203 
       
   204 TBool CReceiveSmsQueue::QueueFull()
       
   205 /** Class Private Utility function
       
   206  */
       
   207 	{
       
   208 	return ((iQueueBack+1)%KReceiveSmsQueueSize)==iQueueFront;
       
   209 	}
       
   210 
       
   211 void CReceiveSmsQueue::CompleteClientReqWithError(TInt aError)
       
   212 /** Inform client that there is a problem waiting for messages
       
   213  */
       
   214 	{
       
   215 	if(iClientReqOutstanding)
       
   216 		{
       
   217 		LOGTEXT2(_L8("CReceiveSmsQueue::CompleteClientReqWithError - Error %d"),aError);
       
   218 		iMobileSmsMessaging.ReqCompleted(iClientReq,aError);
       
   219 		iClientReqOutstanding=EFalse;
       
   220 		}
       
   221 	}