voipplugins/dhcppositionprovider/src/dhcpconnectionengine.cpp
branchRCL_3
changeset 22 d38647835c2e
parent 0 a4daefaec16c
equal deleted inserted replaced
21:f742655b05bf 22:d38647835c2e
       
     1 /*
       
     2 * Copyright (c) 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:  Browse and activate proper connection method.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <es_sock.h>
       
    20 #include <es_enum.h>
       
    21 #include "dhcppsylogging.h"
       
    22 #include "dhcppsy.hrh"
       
    23 #include "dhcpconnectionprogressnotifier.h"
       
    24 #include "dhcpconnectionstateobserver.h"
       
    25 #include "dhcpconnectionengine.h"
       
    26 
       
    27 // ---------------------------------------------------------------------------
       
    28 // CDhcpConnectionEngine::NewL
       
    29 // ---------------------------------------------------------------------------
       
    30 //
       
    31 CDhcpConnectionEngine* CDhcpConnectionEngine::NewL (RConnection& aConnection)
       
    32     {
       
    33     CDhcpConnectionEngine* self = new (ELeave) CDhcpConnectionEngine (aConnection);
       
    34     CleanupStack::PushL(self);
       
    35     self->ConstructL();
       
    36     CleanupStack::Pop(self);
       
    37     return self;
       
    38     }
       
    39 
       
    40 // Member methods
       
    41 // ---------------------------------------------------------------------------
       
    42 // CDhcpConnectionEngine::CDhcpConnectionEngine
       
    43 // ---------------------------------------------------------------------------
       
    44 //
       
    45 CDhcpConnectionEngine::CDhcpConnectionEngine (RConnection& aConnection) :  CActive ( EPriorityStandard ),
       
    46         iConnection (aConnection)
       
    47     {
       
    48     TRACESTRING( "CDhcpConnectionEngine::CDhcpConnectionEngine" );
       
    49     CActiveScheduler::Add( this );
       
    50     }
       
    51 
       
    52 // ---------------------------------------------------------------------------
       
    53 // CDhcpConnectionEngine::~CDhcpConnectionEngine
       
    54 // ---------------------------------------------------------------------------
       
    55 //
       
    56 CDhcpConnectionEngine::~CDhcpConnectionEngine()
       
    57     {
       
    58     TRACESTRING( "CDhcpConnectionEngine::~CDhcpConnectionEngine" );
       
    59     Cancel();
       
    60     delete iProgressNotifier;
       
    61     }
       
    62 // ---------------------------------------------------------------------------
       
    63 // CDhcpConnectionEngine::ConstructL
       
    64 // ---------------------------------------------------------------------------
       
    65 //
       
    66 void CDhcpConnectionEngine::ConstructL()
       
    67     {
       
    68     TRACESTRING( "CDhcpConnectionEngine::ContructL" );
       
    69     iProgressNotifier = CDhcpConnectionProgressNotifier::NewL(iConnection, this);
       
    70     }
       
    71 
       
    72 // ---------------------------------------------------------------------------
       
    73 // CDhcpConnectionEngine::DoCancel
       
    74 // ---------------------------------------------------------------------------
       
    75 //
       
    76 void CDhcpConnectionEngine::DoCancel()
       
    77     {
       
    78     TRACESTRING2 ( "CDhcpConnectionEngine::DoCancel, state %d", iStates);
       
    79     // Is this really needed ? Most cases SVP will continue with same IAP connection so
       
    80     // it's not good to drop a connection beforehand ...
       
    81     iProgressNotifier->Cancel ();
       
    82     iConnection.Close ();
       
    83     TRACESTRING( "CDhcpConnectionEngine::DoCancel, end" );
       
    84     }
       
    85 
       
    86 
       
    87 // ---------------------------------------------------------------------------
       
    88 // CDhcpConnectionEngine::ActiveWlanConnection
       
    89 // ---------------------------------------------------------------------------
       
    90 //
       
    91 TBool CDhcpConnectionEngine::IsConnectedL (TUint32 aIAPId )
       
    92     {
       
    93     TUint connectionCount = 0;
       
    94     TBool isConnected = EFalse;
       
    95     if (iProgressNotifier->GetState () == EDhcpConnectStateConnected)
       
    96         {
       
    97         isConnected = ETrue;
       
    98         return isConnected;
       
    99         }
       
   100 
       
   101     User::LeaveIfError( iConnection.EnumerateConnections(connectionCount));
       
   102     TRACESTRING2 ("CDhcpConnectionEngine::IsConnectedL, connCount, %d", connectionCount )
       
   103     // Loop shall start from second item, otherwise this will not work.
       
   104     for ( TUint i = 1; i <= connectionCount; i++ )
       
   105         {
       
   106         TPckgBuf<TConnectionInfo> connInfo;
       
   107         User::LeaveIfError( iConnection.GetConnectionInfo( i, connInfo ) );
       
   108         if ( connInfo().iIapId == aIAPId )
       
   109             {
       
   110             User::LeaveIfError( iConnection.Attach(
       
   111                 connInfo, RConnection::EAttachTypeNormal ) );
       
   112             isConnected = ETrue;
       
   113             break;
       
   114             }
       
   115         }
       
   116     return isConnected;
       
   117     }
       
   118 
       
   119 // ---------------------------------------------------------------------------
       
   120 // CDhcpConnectionEngine::StateChangedL
       
   121 // ---------------------------------------------------------------------------
       
   122 //
       
   123 void CDhcpConnectionEngine::StateChangedL ()
       
   124     {
       
   125     switch(iProgressNotifier->GetState ())
       
   126         {
       
   127         case EDhcpConnectStateConnected:
       
   128             {
       
   129             if (iStates==EConnectionStartup)
       
   130                 {
       
   131                 TRequestStatus *status = iClientStatus;
       
   132                 User::RequestComplete ( status, KErrNone );
       
   133                 iStates = EIdle;
       
   134                 }
       
   135             }
       
   136             break;
       
   137         }
       
   138     }
       
   139 
       
   140 
       
   141 // ---------------------------------------------------------------------------
       
   142 // CDhcpConnectionEngine::ConnectL
       
   143 // ---------------------------------------------------------------------------
       
   144 //
       
   145 void CDhcpConnectionEngine::ConnectL (TUint aIAPConnectionId, TRequestStatus& aStatus)
       
   146     {
       
   147     TRACESTRING( "CDhcpConnectionEngine::ConnectL" );
       
   148     aStatus = KRequestPending;
       
   149     iClientStatus = &aStatus;
       
   150     iIapProfileId = aIAPConnectionId;
       
   151     iPreferences.SetIapId( iIapProfileId );
       
   152     iPreferences.SetDialogPreference( ECommDbDialogPrefDoNotPrompt );
       
   153     iConnection.Start( iPreferences, iStatus );
       
   154     iStates = ETurnConnectionOn;
       
   155     SetActive ();
       
   156     }
       
   157 
       
   158 // ---------------------------------------------------------------------------
       
   159 // CDhcpConnectionEngine::RunL
       
   160 // ---------------------------------------------------------------------------
       
   161 //
       
   162 void CDhcpConnectionEngine::RunL()
       
   163     {
       
   164     TRACESTRING2( "CDhcpConnectionEngine::RunL, %d ", iStates);
       
   165     TRACESTRING2( "CDhcpConnectionEngine::RunL, %d ", iStatus.Int() );
       
   166     TInt retValue = iStatus.Int();
       
   167     if(retValue!=KErrNone)
       
   168         {
       
   169         //
       
   170         // Even we failed to connect specified wlan network, we should continue with
       
   171         // location query progress until the DHCPInform message has been send to someone.
       
   172         // This is reason for that we complete with KErrNone in here.
       
   173         //
       
   174         TRequestStatus *status = iClientStatus;
       
   175         User::RequestComplete ( status, KErrNone );
       
   176         iStates = EIdle;
       
   177         }
       
   178     else
       
   179         {
       
   180         switch (iStates)
       
   181             {
       
   182             case ETurnConnectionOn:
       
   183                 {
       
   184                 // Ok we just flag on until progress notification tells to us that
       
   185                 iStates = EConnectionStartup;
       
   186                 }
       
   187                 break;
       
   188             }
       
   189         }
       
   190     }
       
   191 
       
   192 // End of file