messagingfw/suplsmshandler/test/testserver/src/Te_LbsSuplSmsTriggerSender.cpp
changeset 62 db3f5fa34ec7
parent 0 8e480a14352b
equal deleted inserted replaced
60:9f5ae1728557 62:db3f5fa34ec7
       
     1 // Copyright (c) 2007-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 // Te_LbsSuplSmsTriggerSender.h
       
    15 // A class sending SUPL INIT messages via UDP
       
    16 // 
       
    17 //
       
    18 
       
    19 /**
       
    20  @file
       
    21  @internalComponent
       
    22  @prototype
       
    23 */
       
    24 
       
    25 #include <e32base.h>
       
    26 #include <in_sock.h>
       
    27 
       
    28 #include "Te_LbsSuplSmsTriggerSender.h"
       
    29 
       
    30 /**
       
    31 Static factory method for creating an instance of the CTe_LbsSuplSmsTriggerSender class.
       
    32 
       
    33 @param aPort	 [In] The port the message must be sent to.
       
    34 @param aObserver [In] The observer to receive message delivery notifications.
       
    35 
       
    36 @return An instance of the class. The calling application becomes the
       
    37 owner of the returned instance and is responsible its disposal.
       
    38 
       
    39 @leave If a error happens, it leaves with one of the system error codes.
       
    40 */
       
    41 CTe_LbsSuplSmsTriggerSender* CTe_LbsSuplSmsTriggerSender::NewL(TInt aPort, MTe_LbsSuplSmsTriggerSenderObserver& aObserver)
       
    42 	{
       
    43 	CTe_LbsSuplSmsTriggerSender* self = new(ELeave) CTe_LbsSuplSmsTriggerSender(aObserver);
       
    44 	CleanupStack::PushL(self);
       
    45 	self->ConstructL(aPort);
       
    46 	CleanupStack::Pop(self);
       
    47 	return self;
       
    48 	}
       
    49 
       
    50 /**
       
    51 Static factory method for creating an instance of the CTe_LbsSuplSmsTriggerSender class and
       
    52 leaving it on the cleanup stack.
       
    53 
       
    54 @param aPort	 [In] The port messages must be sent to.
       
    55 @param aObserver [In] The observer to receive message delivery notifications.
       
    56 
       
    57 @return An instance of the class. The calling application becomes the
       
    58 owner of the returned instance and is responsible its disposal.
       
    59 
       
    60 @leave If a error happens, it leaves with one of the system error codes.
       
    61 */
       
    62 CTe_LbsSuplSmsTriggerSender* CTe_LbsSuplSmsTriggerSender::NewLC(TInt aPort, MTe_LbsSuplSmsTriggerSenderObserver& aObserver)
       
    63 	{
       
    64 	CTe_LbsSuplSmsTriggerSender* self = new(ELeave) CTe_LbsSuplSmsTriggerSender(aObserver);
       
    65 	CleanupStack::PushL(self);
       
    66 	self->ConstructL(aPort);
       
    67 	return self;
       
    68 	}
       
    69 
       
    70 /**
       
    71 Destructor. Cancels the async request and closes the sockets.
       
    72 */
       
    73 CTe_LbsSuplSmsTriggerSender::~CTe_LbsSuplSmsTriggerSender()
       
    74 	{
       
    75 	Cancel();
       
    76 	iSocket.Close();
       
    77 	iSocketServ.Close();
       
    78 	}
       
    79 
       
    80 /**
       
    81 Sends the given message via UDP on the port specified on the construction.
       
    82 
       
    83 @param aMessage [In] A message to be sent.
       
    84 
       
    85 @see MTe_LbsSuplSmsTriggerSenderObserver::OnMessageSent
       
    86 */
       
    87 void CTe_LbsSuplSmsTriggerSender::SendMessage(const TDesC8& aMessage)
       
    88 	{
       
    89 	__ASSERT_ALWAYS(!IsActive(), User::Invariant());
       
    90 	
       
    91 	iSocket.SendTo(aMessage, iAddr, 0, iStatus);
       
    92 	SetActive();
       
    93 	}
       
    94 
       
    95 /**
       
    96 Constructor. Adds this active object to the active scheduler's list.
       
    97 */
       
    98 CTe_LbsSuplSmsTriggerSender::CTe_LbsSuplSmsTriggerSender(MTe_LbsSuplSmsTriggerSenderObserver& aObserver) : CActive(EPriorityStandard), 
       
    99 iObserver(aObserver)
       
   100 	{
       
   101 	CActiveScheduler::Add(this);
       
   102 	}
       
   103 
       
   104 /**
       
   105 2nd phase constructor. Opens the socket and preinitializes the address.
       
   106 
       
   107 @param aPort	 [In] The port messages must be sent to.
       
   108 
       
   109 @leave If a error happens, it leaves with one of the system error codes.
       
   110 */
       
   111 void CTe_LbsSuplSmsTriggerSender::ConstructL(TInt aPort)
       
   112 	{
       
   113 	// Open channel to Socket Server
       
   114 	User::LeaveIfError(iSocketServ.Connect());
       
   115 	
       
   116 	//Open the socket to listen for messages
       
   117 	User::LeaveIfError(iSocket.Open(iSocketServ, KAfInet, KSockDatagram, KProtocolInetUdp));
       
   118 	
       
   119 	iAddr.SetPort(aPort);
       
   120 	iAddr.SetAddress(INET_ADDR(127,0,0,1));
       
   121 	}
       
   122 
       
   123 /**
       
   124 Called when the message delivery report is received.
       
   125 
       
   126 @see CActive::RunL
       
   127 @see SendTo::SendTo
       
   128 */
       
   129 void CTe_LbsSuplSmsTriggerSender::RunL()
       
   130 	{
       
   131 	iObserver.OnMessageSent(iStatus.Int());
       
   132 	}
       
   133 
       
   134 /**
       
   135 Cancels the outstanding send async request.
       
   136 
       
   137 @see CActive::DoCancel
       
   138 @see SendTo::SendTo
       
   139 */
       
   140 void CTe_LbsSuplSmsTriggerSender::DoCancel()
       
   141 	{
       
   142 	iSocket.CancelRecv();
       
   143 	}
       
   144 
       
   145