commsconfig/cscengine/src/cscengconnectionhandler.cpp
branchRCL_3
changeset 22 d38647835c2e
parent 0 a4daefaec16c
equal deleted inserted replaced
21:f742655b05bf 22:d38647835c2e
       
     1 /*
       
     2 * Copyright (c) 2007-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:  For handling interactions betweed UI and RConnection.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <e32base.h>
       
    20 #include <nifman.h>
       
    21 
       
    22 #include "cscenglogger.h"
       
    23 #include "cscengconnectionhandler.h"
       
    24 #include "mcscengconnectionobserver.h"
       
    25 
       
    26 
       
    27 // ======== MEMBER FUNCTIONS ========
       
    28 
       
    29 // ---------------------------------------------------------------------------
       
    30 // ---------------------------------------------------------------------------
       
    31 //
       
    32 CCSCEngConnectionHandler::CCSCEngConnectionHandler( 
       
    33     MCSCEngConnectionObserver& aObserver ) : 
       
    34     CActive( EPriorityStandard ), 
       
    35     iObserver( aObserver )
       
    36     {    
       
    37     }
       
    38 
       
    39 
       
    40 // ---------------------------------------------------------------------------
       
    41 // ---------------------------------------------------------------------------
       
    42 //
       
    43 void CCSCEngConnectionHandler::ConstructL()
       
    44     {
       
    45     CSCENGDEBUG( "CCSCEngConnectionHandler::ConstructL - begin" ); 
       
    46     
       
    47     CActiveScheduler::Add( this );
       
    48 
       
    49     iTimer = CCSCEngTimer::NewL( *this );
       
    50     
       
    51     // Open channel to Socket Server
       
    52     User::LeaveIfError( iSocketServ.Connect() );
       
    53     
       
    54     // Open connection
       
    55     User::LeaveIfError( iConnection.Open( iSocketServ ) );
       
    56     
       
    57     CSCENGDEBUG( "CCSCEngConnectionHandler::ConstructL - end" ); 
       
    58     }   
       
    59     
       
    60     
       
    61 // ---------------------------------------------------------------------------
       
    62 // ---------------------------------------------------------------------------
       
    63 //
       
    64 EXPORT_C CCSCEngConnectionHandler* CCSCEngConnectionHandler::NewL( 
       
    65     MCSCEngConnectionObserver& aObserver )
       
    66     {    
       
    67     CCSCEngConnectionHandler* self = 
       
    68         new ( ELeave ) CCSCEngConnectionHandler( aObserver );
       
    69     CleanupStack::PushL( self );
       
    70     self->ConstructL();
       
    71     CleanupStack::Pop( self );
       
    72     return self;
       
    73     }
       
    74 
       
    75 
       
    76 // ---------------------------------------------------------------------------
       
    77 // ---------------------------------------------------------------------------
       
    78 //
       
    79 CCSCEngConnectionHandler::~CCSCEngConnectionHandler()
       
    80     {
       
    81     CSCENGDEBUG( "CCSCEngConnectionHandler::~CCSCEngConnectionHandler - begin" ); 
       
    82     
       
    83     delete iTimer;
       
    84     
       
    85     Cancel();
       
    86     iConnection.Close();
       
    87     iSocketServ.Close();
       
    88     
       
    89     CSCENGDEBUG( "CCSCEngConnectionHandler::~CCSCEngConnectionHandler - end" ); 
       
    90     }
       
    91 
       
    92 // ---------------------------------------------------------------------------
       
    93 // CCSCEngConnectionHandler::StartListeningConnectionEvents
       
    94 // ---------------------------------------------------------------------------
       
    95 //
       
    96 EXPORT_C void CCSCEngConnectionHandler::StartListeningConnectionEvents()
       
    97     {
       
    98     CSCENGDEBUG( "CCSCEngConnectionHandler::StartListeningConnectionEvents" ); 
       
    99     
       
   100     if ( IsActive() )
       
   101         {
       
   102         Cancel();
       
   103         }
       
   104     
       
   105     iTimer->StartTimer( CCSCEngTimer::EConnectionMonitoringTimer ); 
       
   106     iConnection.AllInterfaceNotification( iInfoBuf, iStatus );
       
   107     SetActive(); 
       
   108     }
       
   109 
       
   110 // ---------------------------------------------------------------------------
       
   111 // CCSCEngConnectionHandler::StopListeningConnectionEvents
       
   112 // ---------------------------------------------------------------------------
       
   113 //
       
   114 EXPORT_C void CCSCEngConnectionHandler::StopListeningConnectionEvents()
       
   115      {
       
   116      CSCENGDEBUG( "CCSCEngConnectionHandler::StopListeningConnectionEvents" ); 
       
   117      
       
   118      iTimer->StopTimer();
       
   119      iConnection.CancelAllInterfaceNotification();
       
   120      }    
       
   121 
       
   122 // ---------------------------------------------------------------------------
       
   123 // From MCSCEngTimerObserver
       
   124 // ---------------------------------------------------------------------------
       
   125 //
       
   126 void CCSCEngConnectionHandler::TimerExpired()
       
   127      {
       
   128      CSCENGDEBUG( "CCSCEngConnectionHandler::TimerExpired" ); 
       
   129      
       
   130      iConnection.CancelAllInterfaceNotification();
       
   131      iObserver.NotifyConnectionEvent( EEventTimedOut );
       
   132      } 
       
   133    
       
   134 // ---------------------------------------------------------------------------
       
   135 // CCSCEngConnectionHandler::RunL
       
   136 // ---------------------------------------------------------------------------
       
   137 //
       
   138 void CCSCEngConnectionHandler::RunL()
       
   139     {
       
   140     if ( iStatus.Int() == KErrNone )
       
   141         {
       
   142         CSCENGDEBUG2( 
       
   143             "CCSCEngConnectionHandler::RunL STATE=%d", iInfoBuf().iState );
       
   144         
       
   145         if ( EInterfaceDown == iInfoBuf().iState )
       
   146             {
       
   147             iTimer->StopTimer();
       
   148             iObserver.NotifyConnectionEvent( EEventConnectionDown );
       
   149             }
       
   150         }
       
   151     }
       
   152 
       
   153 
       
   154 // ---------------------------------------------------------------------------
       
   155 // CCSCEngConnectionHandler::DoCancel
       
   156 // ---------------------------------------------------------------------------
       
   157 //
       
   158 void CCSCEngConnectionHandler::DoCancel()
       
   159     {    
       
   160     iTimer->StopTimer();
       
   161     iConnection.CancelAllInterfaceNotification();
       
   162     }
       
   163 
       
   164