satengine/SatServer/Engine/src/CSatBIPDataSender.cpp
changeset 0 ff3b6d0fd310
equal deleted inserted replaced
-1:000000000000 0:ff3b6d0fd310
       
     1 /*
       
     2 * Copyright (c) 2002-2007 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Sender class for TCP / UDP sockets
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <es_sock.h>
       
    22 #include "CSatBIPDataSender.h"
       
    23 #include "MSatSendDataObserver.h"
       
    24 #include "SatLog.h"
       
    25 #include "MSatBIPUtils.h"
       
    26 
       
    27 #ifdef ENABLE_SAT_LOGGING
       
    28 const TUint8 KIpAddressLogSize( 40 );
       
    29 #endif
       
    30  
       
    31 
       
    32 // ============================ MEMBER FUNCTIONS ===============================
       
    33 
       
    34 // -----------------------------------------------------------------------------
       
    35 // CSatBIPDataSender::CSatBIPDataSender
       
    36 // C++ default constructor can NOT contain any code, that
       
    37 // might leave.
       
    38 // -----------------------------------------------------------------------------
       
    39 //
       
    40 CSatBIPDataSender::CSatBIPDataSender( MSatSendDataObserver& aObserver, 
       
    41     RSocket& aSocket,
       
    42     TBool aIsTcpSocket,
       
    43     TInt aBufferSize ) : CActive( EPriorityNormal ),
       
    44     iObserver( aObserver ),
       
    45     iSocket( aSocket )
       
    46     {
       
    47     LOG( SIMPLE, "SATENGINE: CSatBIPDataSender::CSatBIPDataSender\
       
    48          calling-exiting" )
       
    49 
       
    50     iIsTcpSocket = aIsTcpSocket;
       
    51     iBufferSize = aBufferSize;
       
    52     CActiveScheduler::Add( this );
       
    53     }
       
    54 
       
    55 // -----------------------------------------------------------------------------
       
    56 // CSatBIPDataSender::~CSatBIPDataSender
       
    57 // Destructor
       
    58 // -----------------------------------------------------------------------------
       
    59 //
       
    60 CSatBIPDataSender::~CSatBIPDataSender()
       
    61     {
       
    62     LOG( SIMPLE, "SATENGINE: CSatBIPDataSender::~CSatBIPDataSender calling" )
       
    63     // Don't have our own pointers...
       
    64     LOG( SIMPLE, "SATENGINE: CSatBIPDataSender::~CSatBIPDataSender exiting" )
       
    65     }
       
    66 
       
    67 // -----------------------------------------------------------------------------
       
    68 // CSatBIPDataSender::RunL
       
    69 // Two-phased constructor.
       
    70 // -----------------------------------------------------------------------------
       
    71 //
       
    72 void CSatBIPDataSender::RunL()
       
    73     {
       
    74     LOG( SIMPLE, "SATENGINE: CSatBIPDataSender::RunL calling" )
       
    75 
       
    76     LOG2( NORMAL, "  RunL with error: %i", iStatus.Int() )
       
    77     LOG2( NORMAL, "  RunL <buffer_size>: %i", iBufferSize )
       
    78     TInt errCode( MSatBIPUtils::ESatBIPSuccess );
       
    79 
       
    80     if ( KErrNone != iStatus.Int() )
       
    81         {
       
    82         // Error, setting error code
       
    83         errCode = MSatBIPUtils::ESatBIPRemoteDeviceNotReachable;
       
    84         }
       
    85 
       
    86     // Notify observer and empty buffer
       
    87     iObserver.DataSentNotification( errCode, iBufferSize );
       
    88     iSendPtr.Zero();
       
    89     LOG( SIMPLE, "SATENGINE: CSatBIPDataSender::RunL exiting" )
       
    90     }
       
    91 
       
    92 // -----------------------------------------------------------------------------
       
    93 // CSatBIPDataSender::DoCancel
       
    94 // Two-phased constructor.
       
    95 // -----------------------------------------------------------------------------
       
    96 //
       
    97 void CSatBIPDataSender::DoCancel()
       
    98     {
       
    99     LOG( SIMPLE, "SATENGINE: CSatBIPDataSender::DoCancel calling" )
       
   100     iSocket.CancelSend();
       
   101     LOG( SIMPLE, "SATENGINE: CSatBIPDataSender::DoCancel exiting" )
       
   102     }
       
   103 
       
   104 // -----------------------------------------------------------------------------
       
   105 // CSatBIPDataSender::SendData
       
   106 // Starts the send process using predefined protocol
       
   107 // -----------------------------------------------------------------------------
       
   108 //
       
   109 void CSatBIPDataSender::SendData( const TDesC8& aData, TInetAddr& aDest )
       
   110     {
       
   111     LOG( SIMPLE, "SATENGINE: CSatBIPDataSender::SendData calling" )
       
   112     // Copy data into local buffer
       
   113     iSendPtr.Copy( aData );
       
   114     
       
   115     #ifdef ENABLE_SAT_LOGGING
       
   116     TBuf<KIpAddressLogSize> addressForLog;
       
   117     #endif
       
   118 
       
   119     #ifdef ENABLE_SAT_LOGGING
       
   120     aDest.Output( addressForLog );
       
   121     LOG2( NORMAL, 
       
   122     "SATENGINE: CSatBIPDataSender::SendData Sending to %S", &addressForLog )
       
   123     #endif    
       
   124     
       
   125     LOG2( NORMAL, "  Port number: %i", aDest.Port() )
       
   126     LOG2( NORMAL, "  Sending %i bytes", aData.Length() )
       
   127     if ( !IsActive() )
       
   128         {
       
   129         // Check protocol
       
   130         if ( iIsTcpSocket )
       
   131             {
       
   132             LOG( SIMPLE, "SATENGINE: CSatBIPDataSender::SendData TCP" )
       
   133             // When using TCP, this request completes when the data is actually
       
   134             // sent to remote device. 
       
   135             iSocket.Send( iSendPtr, 0, iStatus );
       
   136             }
       
   137         else
       
   138             {
       
   139             LOG( SIMPLE, "SATENGINE: CSatBIPDataSender::SendData UDP" )
       
   140             // UDP Socket. This request completes almost immediately. 
       
   141             // There is no
       
   142             // way to be sure that the remote device gets the datagram.
       
   143             iSocket.SendTo( iSendPtr, aDest, 0, iStatus );
       
   144             }
       
   145         SetActive();
       
   146         }
       
   147     LOG( SIMPLE, "SATENGINE: CSatBIPDataSender::SendData exiting" )
       
   148     }
       
   149 
       
   150 // End of file