messagingfw/biomsgfw/BioWatchers/Src/WspPortWatcher.cpp
changeset 62 db3f5fa34ec7
parent 0 8e480a14352b
equal deleted inserted replaced
60:9f5ae1728557 62:db3f5fa34ec7
       
     1 // Copyright (c) 2000-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 
       
    17 #include "WapSocketWatcher.h"
       
    18 #include <watcher.h>
       
    19 
       
    20 #include <wapmessage.h>
       
    21 #include <wapmsgerr.h>
       
    22 
       
    23 //
       
    24 //CWspPortWatcher
       
    25 //
       
    26 
       
    27 CWspPortWatcher::CWspPortWatcher(CWatcherLog& aWatcherLog, TInt aPriority, TUid aBioID, RFs& aFs, Wap::TPort aWapPort)
       
    28 	: CWapPortWatcher(aWatcherLog, aPriority, aBioID, aFs, aWapPort),iPushPckgId(0)
       
    29 	{
       
    30 	}
       
    31 
       
    32 CWspPortWatcher::~CWspPortWatcher()
       
    33 	{
       
    34 	Cancel();
       
    35 	CloseConn();
       
    36 	delete iWspConn;
       
    37 	delete iRecvHeader;
       
    38 	}
       
    39 
       
    40 void CWspPortWatcher::CloseConn()
       
    41 	{
       
    42 	//Close the WSP connection
       
    43 	delete iWspConn;
       
    44 	iWspConn=NULL;
       
    45 
       
    46 	delete iRecvHeader;
       
    47 	iRecvHeader = NULL;
       
    48 
       
    49 	CWapPortWatcher::CloseConn(); //deletes iRecvBuf
       
    50 	}
       
    51 
       
    52 void CWspPortWatcher::DoCancel()
       
    53 	{
       
    54 	if (iWspConn!=NULL)
       
    55 		iWspConn->CancelAwaitPush();
       
    56 	}
       
    57 
       
    58 void CWspPortWatcher::DoSetupL()
       
    59 	{
       
    60 	BIOWATCHERLOG(iWatcherLog.Printf(_L("BioWsp: DoSetupL: %S, port %d"), &iBioMsgText, iWapPort));
       
    61 
       
    62 	//Open Connectionless WSP connection on port iWapPort
       
    63 	if(iWspConn==NULL)
       
    64 		iWspConn=CWapBoundCLPushService::NewL();
       
    65 	User::LeaveIfError(iWspConn->Connect(Wap::ESMS,iWapPort,EFalse));
       
    66 	}
       
    67 
       
    68 void CWspPortWatcher::WaitForMessageL()
       
    69 	{
       
    70 	BIOWATCHERLOG(iWatcherLog.Printf(_L("BioWsp: WaitForMessageL: %S, port %d"), &iBioMsgText, iWapPort));
       
    71 
       
    72 	User::LeaveIfError(iStatus.Int());
       
    73 
       
    74 	//Wait for WSP push message on port iWapPort	
       
    75 	iTempRecvBuf.Zero();
       
    76 	iTempRecvHeader.Zero();
       
    77 	User::LeaveIfError(iWspConn->AwaitPush(iTempRecvHeader,iTempRecvBuf,iPushPckgId,iStatus));
       
    78 
       
    79 	//SetActive() is called by CBaseSmsActiveSocketWatcher::DoRunL()
       
    80 	}
       
    81 
       
    82 void CWspPortWatcher::ReceiveL()
       
    83 	{
       
    84 	BIOWATCHERLOG(iWatcherLog.Printf(_L("BioWsp: ReceiveL: %S, port %d"), &iBioMsgText, iWapPort));
       
    85 
       
    86 	//Receive the WAP Message.
       
    87 
       
    88 	switch (iStatus.Int())
       
    89 		{
       
    90 		case Wap::EMoreData:
       
    91 			{
       
    92 			//if iStatus == EMoreData, then must wait for the rest of the message
       
    93 			AppendToHBufC8L(iRecvHeader, iTempRecvHeader);
       
    94 			AppendToHBufC8L(iRecvBuf, iTempRecvBuf);
       
    95 
       
    96 			TRequestStatus* pS=&iStatus;
       
    97 			User::RequestComplete(pS, KErrNone);
       
    98 			break;
       
    99 			}
       
   100 		case KErrNone:
       
   101 			{
       
   102 			AppendToHBufC8L(iRecvHeader, iTempRecvHeader);
       
   103 			AppendToHBufC8L(iRecvBuf, iTempRecvBuf);
       
   104 			
       
   105 			// DEF053845 Provide a NULL pointer for GetServerAddress().
       
   106 			// GetServerAddress() Allocs and sets up the pointer.
       
   107 			HBufC8* serverAddress = NULL;
       
   108 			// Pick up and interrogate the return rather than User::LeaveIfError.
       
   109 			// Leaving here could result in us receiving the message again
       
   110 			// and again.
       
   111 			TInt err = iWspConn->GetServerAddress(serverAddress);
       
   112 			if(err == KErrNone && serverAddress->Length())
       
   113 				{
       
   114 				CleanupStack::PushL(serverAddress);
       
   115 				DoReceiveL(*serverAddress);
       
   116 				CleanupStack::PopAndDestroy(serverAddress);
       
   117 				}
       
   118 			else
       
   119 				{
       
   120 				delete serverAddress; // Could have been alloc'd but it won't hurt to delete if NULL
       
   121 				DoReceiveL(KNullDesC8);
       
   122 				}							
       
   123 			delete iRecvBuf;
       
   124 			iRecvBuf = NULL;
       
   125 			delete iRecvHeader;
       
   126 			iRecvHeader = NULL;
       
   127 			}
       
   128 			break;
       
   129 		default:
       
   130 			User::Leave(iStatus.Int());
       
   131 			break;
       
   132 		}
       
   133 	}