Msrp/MsrpClient/src/CMSRPIncomingListener.cpp
branchMSRP_FrameWork
changeset 25 505ad3f0ce5c
child 58 cdb720e67852
equal deleted inserted replaced
22:f1578314b8da 25:505ad3f0ce5c
       
     1 /*
       
     2 * Copyright (c) 2009-2010 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 * Initial Contributors:
       
     9 * Nokia Corporation - initial contribution.
       
    10 * Contributors:
       
    11 *
       
    12 * Description:
       
    13 * MSRP Implementation
       
    14 *
       
    15 */
       
    16 
       
    17 
       
    18 //  Include Files
       
    19 #include "MsrpCommon.h"
       
    20 #include "CMSRPListenerBase.h"
       
    21 #include "CMSRPIncomingListener.h"
       
    22 #include "CMSRPSessionImplementation.h"
       
    23 #include "MMSRPServerInterface.h"
       
    24 
       
    25 
       
    26 //  Member Functions
       
    27 
       
    28 CMSRPIncomingListener* CMSRPIncomingListener::NewL(
       
    29     CMSRPSessionImplementation& aSessionImpl,
       
    30     MMSRPServerInterface& aServerInterface )
       
    31     {
       
    32     CMSRPIncomingListener* self =
       
    33         new ( ELeave ) CMSRPIncomingListener(
       
    34                 aSessionImpl, aServerInterface );
       
    35     
       
    36     return self;
       
    37     }
       
    38 
       
    39 
       
    40 CMSRPIncomingListener::CMSRPIncomingListener(
       
    41     CMSRPSessionImplementation& aSessionImpl,
       
    42     MMSRPServerInterface& aServerInterface )
       
    43     : CMSRPListenerBase( aSessionImpl, aServerInterface, EPriorityStandard )
       
    44     {
       
    45     }
       
    46 
       
    47 
       
    48 CMSRPIncomingListener::~CMSRPIncomingListener()
       
    49     {
       
    50     Cancel();    
       
    51     }
       
    52 
       
    53 
       
    54 void CMSRPIncomingListener::ListenConnections(
       
    55     const TDesC8& aRemoteHost,
       
    56     const TUint aRemotePort,
       
    57     const TDesC8& aRemoteSessionID )
       
    58     {
       
    59     if ( !IsActive() )
       
    60         {
       
    61         iIsMessage = EFalse;                
       
    62         iServerInterface.ListenConnections( aRemoteHost, aRemotePort, aRemoteSessionID, iIsMessage, iStatus );
       
    63 
       
    64         // Set this handler to active so that it can receive requests.
       
    65         SetActive();
       
    66         }
       
    67     }
       
    68 
       
    69 
       
    70 void CMSRPIncomingListener::ListenMessages( )
       
    71     {
       
    72     if ( !IsActive() )
       
    73         {
       
    74         iIsMessage = ETrue;             
       
    75         iServerInterface.ListenMessages( iIsMessage, iStatus );
       
    76 
       
    77         // Set this handler to active so that it can receive requests.
       
    78         SetActive();
       
    79         }
       
    80     }
       
    81 
       
    82 
       
    83 void CMSRPIncomingListener::RunL()
       
    84     {    
       
    85     if ( !iIsMessage )
       
    86         {
       
    87         // connection was made
       
    88         iSessionImpl.ConnectionEstablishedL( iStatus.Int() );
       
    89         }
       
    90     else
       
    91         {
       
    92         if(iStatus == KErrNone)
       
    93             {
       
    94             if(iServerInterface.GetListenProgress())
       
    95                 {
       
    96                 //handle listen progress
       
    97                 iSessionImpl.ReceiveProgress(iServerInterface.GetBytesReceived(), iServerInterface.GetTotalBytesReceived());                       
       
    98                 }
       
    99             else
       
   100                 {
       
   101                 // Handle incoming message by reading it from server interface
       
   102                 iSessionImpl.HandleIncomingMessageL( iServerInterface.GetReceivedMessage( ),
       
   103                     iServerInterface.GetStatusOfReceivedMessage() );
       
   104                 }
       
   105 
       
   106             // issue a new request
       
   107             iServerInterface.ListenMessages( iIsMessage, iStatus );
       
   108             SetActive();
       
   109             }
       
   110         else
       
   111             {
       
   112             // Error scenario.
       
   113             iSessionImpl.HandleConnectionErrors(iStatus.Int());            
       
   114             }
       
   115         }
       
   116     }
       
   117 
       
   118 
       
   119 void CMSRPIncomingListener::DoCancel()
       
   120     {
       
   121     if ( IsActive() )
       
   122         {
       
   123         iServerInterface.CancelReceiving();
       
   124         }
       
   125    
       
   126     }