convergedcallengine/csplugin/src/cspvideocallconnectionhandler.cpp
branchRCL_3
changeset 20 987c9837762f
parent 0 ff3b6d0fd310
equal deleted inserted replaced
19:7d48bed6ce0c 20:987c9837762f
       
     1 /*
       
     2 * Copyright (c) 2007-2009 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:  Contains the implementation of class CSPDataCallConnectionHandler
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <etelmm.h>
       
    20 #include <mccpcallobserver.h>
       
    21 #include <e32property.h>
       
    22 
       
    23 #include "cspvideocallconnectionhandler.h"
       
    24 #include "cspvideocall.h"
       
    25 #include "csplogger.h"
       
    26 #include "cspconsts.h"
       
    27 
       
    28 
       
    29 // ---------------------------------------------------------------------------
       
    30 // Constructs the connection handler via two phased constructing.
       
    31 // ---------------------------------------------------------------------------
       
    32 //
       
    33 CSPVideoCallConnectionHandler* CSPVideoCallConnectionHandler::NewL(
       
    34             CSPVideoCall& aObserver,
       
    35             RMobileCall& aCall ) 
       
    36     {
       
    37     CSPLOGSTRING(CSPOBJECT, "CSPDataCallConnectionHandler::NewL()" );
       
    38     CSPVideoCallConnectionHandler* self = new (ELeave) CSPVideoCallConnectionHandler( 
       
    39                                         aObserver, aCall );
       
    40     CleanupStack::PushL( self );
       
    41     self->ConstructL();
       
    42     CleanupStack::Pop( self );
       
    43     return self;
       
    44     }
       
    45     
       
    46 // ---------------------------------------------------------------------------
       
    47 // Destructor of the object.
       
    48 // ---------------------------------------------------------------------------
       
    49 //
       
    50 CSPVideoCallConnectionHandler::~CSPVideoCallConnectionHandler( )
       
    51     {
       
    52     CSPLOGSTRING(CSPOBJECT, "CSPVideoCallConnectionHandler::~CSPDataCallConnectionHandler()" );
       
    53     ReleaseConnection();
       
    54     Cancel();
       
    55     CloseConnection();
       
    56     }
       
    57 
       
    58 // ---------------------------------------------------------------------------
       
    59 // CSPVideoCallConnectionHandler::InitializeConnection
       
    60 // ---------------------------------------------------------------------------
       
    61 //
       
    62 TInt CSPVideoCallConnectionHandler::InitializeConnection( )
       
    63     {    
       
    64     TInt err = CreateSocketConnection();
       
    65     if ( !err )
       
    66         {        
       
    67         err = LoanDataPort();
       
    68         }    
       
    69     
       
    70     CSPLOGSTRING2(CSPOBJECT, 
       
    71         "CSPVideoCallConnectionHandler::InitializeConnection err=%i", err );
       
    72         
       
    73     return err;
       
    74     }
       
    75     
       
    76 // ---------------------------------------------------------------------------
       
    77 // CSPVideoCallConnectionHandler::ReleaseConnection
       
    78 // ---------------------------------------------------------------------------
       
    79 //
       
    80 TInt CSPVideoCallConnectionHandler::ReleaseConnection( )
       
    81     {    
       
    82     CloseConnection();
       
    83     TInt err = iCall.RecoverDataPort();
       
    84     CSPLOGSTRING2(CSPOBJECT, 
       
    85         "CSPVideoCallConnectionHandler::ReleaseConnection err=%i", err );
       
    86     iConnectionInitialized = EFalse;
       
    87 
       
    88     return err;
       
    89     }
       
    90     
       
    91 // ---------------------------------------------------------------------------
       
    92 // CSPVideoCallConnectionHandler::InitializeConnection
       
    93 // ---------------------------------------------------------------------------
       
    94 //
       
    95 TBool CSPVideoCallConnectionHandler::ConnectionInitialized( )
       
    96     {
       
    97     return iConnectionInitialized;
       
    98     }
       
    99 
       
   100 // -----------------------------------------------------------------------------
       
   101 // Creates socket connection.
       
   102 // Enumerates connections and save Access Point Name of CSD connection.
       
   103 // -----------------------------------------------------------------------------
       
   104 //
       
   105 TInt CSPVideoCallConnectionHandler::CreateSocketConnection()
       
   106     {
       
   107     CSPLOGSTRING( CSPINT, "CSPVideoCallConnectionHandler::CreateSocketConnection() start");
       
   108     // Socket server connection to get Access Point Name
       
   109     TInt errorCode = iSocketServer.Connect();
       
   110     CSPLOGSTRING2( CSPREQOUT,
       
   111       "CSPVideoCallConnectionHandler::CreateSocketConnection: RSocketServ::Connect, error code: %d",
       
   112        errorCode );
       
   113       
       
   114     if ( KErrNone == errorCode )
       
   115         {
       
   116         errorCode = iConnection.Open( iSocketServer );
       
   117         CSPLOGSTRING2( CSPREQOUT,
       
   118          "CSPVideoCallConnectionHandler::CreateSocketConnection: RConnection::Open, errorcode: %d",
       
   119            errorCode );
       
   120         if ( errorCode )
       
   121             {
       
   122             iSocketServer.Close();
       
   123             }
       
   124         }
       
   125     return errorCode;
       
   126     }
       
   127 
       
   128 // ---------------------------------------------------------------------------
       
   129 // CSPVideoCallConnectionHandler::LoanDataPort
       
   130 // ---------------------------------------------------------------------------
       
   131 //
       
   132 TInt CSPVideoCallConnectionHandler::LoanDataPort( )
       
   133     {
       
   134     CSPLOGSTRING(CSPINT, "CSPVideoCallConnectionHandler::LoanDataPort");
       
   135     TInt ret( KErrNone ); 
       
   136     if ( !IsActive() )
       
   137         {
       
   138         SetActive();
       
   139         iCall.LoanDataPort( iStatus, iCommPort );    
       
   140         }
       
   141     else
       
   142         {
       
   143         ret = KErrInUse;
       
   144         CSPLOGSTRING2(CSPERROR, 
       
   145             "CSPVideoCallConnectionHandler::LoanDataPort Error!: %d", 
       
   146             ret);
       
   147         }
       
   148     
       
   149     return ret; 
       
   150     }
       
   151 
       
   152 // -----------------------------------------------------------------------------
       
   153 // Close Socket Server connection, when the call is on Idle state.
       
   154 // -----------------------------------------------------------------------------
       
   155 //
       
   156 void CSPVideoCallConnectionHandler::CloseConnection()
       
   157     {
       
   158     CSPLOGSTRING( CSPINT, "CSPVideoCallConnectionHandler::CloseConnection" );
       
   159     iConnection.Close();
       
   160     iSocketServer.Close();
       
   161     }
       
   162 
       
   163 // ---------------------------------------------------------------------------
       
   164 // CSPVideoCallConnectionHandler::RunL
       
   165 // ---------------------------------------------------------------------------
       
   166 //
       
   167 void CSPVideoCallConnectionHandler::RunL()
       
   168     {
       
   169     // from CActive
       
   170     CSPLOGSTRING2( CSPREQEND, 
       
   171         "CSPVideoCallConnectionHandler::RunL: status: %d", iStatus.Int() );
       
   172     
       
   173     if ( iStatus == KErrNone )
       
   174         {
       
   175         CSPLOGSTRING( CSPINT, 
       
   176             "CSPVideoCallConnectionHandler::RunL: LoanDataPort request OK" );
       
   177         iConnectionInitialized = ETrue;
       
   178         iObserver.ConnectionReady( iCommPort.iPort );        
       
   179         }
       
   180     else
       
   181         {
       
   182         // Error situations         
       
   183         TInt err = iStatus.Int();
       
   184         CSPLOGSTRING2( CSPERROR, "CSPVideoCallConnectionHandler::RunL: request \
       
   185                                 completed with error: %d", err );
       
   186 
       
   187         iObserver.ConnectionEstablishingFailed( err );        
       
   188         }    
       
   189     }
       
   190 
       
   191 // ---------------------------------------------------------------------------
       
   192 // CSPVideoCallConnectionHandler::DoCancel
       
   193 // ---------------------------------------------------------------------------
       
   194 //
       
   195 void CSPVideoCallConnectionHandler::DoCancel()
       
   196     {
       
   197     CSPLOGSTRING( CSPREQOUT, "CSPVideoCallConnectionHandler::DoCancel" );
       
   198     if ( IsActive() )
       
   199         {
       
   200         iCall.LoanDataPortCancel();
       
   201         }
       
   202     else
       
   203         {
       
   204         CSPLOGSTRING( CSPERROR, 
       
   205             "CSPVideoCallConnectionHandler::DoCancel: Already active" );
       
   206         }
       
   207     }
       
   208 
       
   209 // ---------------------------------------------------------------------------
       
   210 // Constructs the requester.
       
   211 // ---------------------------------------------------------------------------
       
   212 //
       
   213 CSPVideoCallConnectionHandler::CSPVideoCallConnectionHandler(
       
   214             CSPVideoCall& aObserver,
       
   215             RMobileCall& aCall ) : 
       
   216                 CActive( EPriorityStandard ), 
       
   217                 iObserver( aObserver ), 
       
   218                 iCall( aCall ), 
       
   219                 iConnectionInitialized( EFalse )
       
   220     {
       
   221     CSPLOGSTRING(CSPOBJECT, "CSPVideoCallConnectionHandler::CSPVideoCallConnectionHandler" );
       
   222     CActiveScheduler::Add( this );
       
   223     }
       
   224     
       
   225 // ---------------------------------------------------------------------------
       
   226 // Constructing in the second phase.
       
   227 // ---------------------------------------------------------------------------
       
   228 //
       
   229 void CSPVideoCallConnectionHandler::ConstructL()
       
   230     {
       
   231     // Empty implementation 
       
   232     }
       
   233 
       
   234 
       
   235 // End of File
       
   236