localconnectivityservice/dun/client/src/dunclient.cpp
branchRCL_3
changeset 39 4096754ee773
parent 38 3dcb815346df
child 40 52a167391590
equal deleted inserted replaced
38:3dcb815346df 39:4096754ee773
     1 /*
       
     2 * Copyright (c) 2006-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:  Main client side interface of DUN
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "dunclient.h"
       
    20 #include "dunserverdef.h"
       
    21 #include "DunDebug.h"
       
    22 #include "dunactive.h"
       
    23 
       
    24 const TInt KDunRetryCount        = 3;
       
    25 const TInt KDunNumOfMessageSlots = 4;
       
    26 
       
    27 // ======== LOCAL FUNCTIONS ========
       
    28 
       
    29 // ---------------------------------------------------------------------------
       
    30 // Create server thread/process
       
    31 // ---------------------------------------------------------------------------
       
    32 //
       
    33 static TInt StartServer()
       
    34     {
       
    35     FTRACE(FPrint( _L("StartServer()") ));
       
    36     TInt retVal = KErrNone;
       
    37     TRequestStatus statusStarted;
       
    38 
       
    39     RProcess server;
       
    40     retVal = server.Create( KDialupServerName, KNullDesC, EOwnerThread );
       
    41 
       
    42     if ( retVal != KErrNone )
       
    43         {
       
    44         FTRACE(FPrint( _L("StartServer() complete (%d)"), retVal ));
       
    45         return retVal;
       
    46         }
       
    47 
       
    48     TRequestStatus stat;
       
    49     server.Rendezvous( stat );
       
    50 
       
    51     if ( stat != KRequestPending )
       
    52         {
       
    53         server.Kill( 0 );  //abort startup
       
    54         }
       
    55     else
       
    56         {
       
    57         server.Resume(); //logon OK - start the server
       
    58         }
       
    59 
       
    60     User::WaitForRequest( stat ); //wait the start or death of the server
       
    61 
       
    62     /*
       
    63     we can't use the 'exit reason' if the server panicked as this
       
    64     is the panic 'reason' and may be '0' which cannot be distinguished
       
    65     from KErrNone
       
    66     */
       
    67     retVal = stat.Int();
       
    68     if ( server.ExitType() == EExitPanic )
       
    69         {
       
    70         retVal = KErrServerTerminated;
       
    71         }
       
    72 
       
    73     server.Close();
       
    74     FTRACE(FPrint( _L("StartServer() complete (%d)"), retVal ));
       
    75     return retVal;
       
    76     }
       
    77 
       
    78 // ======== MEMBER FUNCTIONS ========
       
    79 
       
    80 // ---------------------------------------------------------------------------
       
    81 // RDun::RDun()
       
    82 // ---------------------------------------------------------------------------
       
    83 //
       
    84 RDun::RDun()
       
    85     {
       
    86     }
       
    87 
       
    88 // ---------------------------------------------------------------------------
       
    89 // This function starts DUN open/close for different medias
       
    90 // ---------------------------------------------------------------------------
       
    91 //
       
    92 TInt RDun::ManageService( MDunActive* aRequest, TRequestStatus& aReqStatus )
       
    93     {
       
    94     FTRACE(FPrint( _L("RDun::ManageService()") ));
       
    95     SendReceive( EDunFuncManageService,
       
    96                  TIpcArgs(aRequest->Bearer(),
       
    97                           aRequest->BearerStatus()),
       
    98                  aReqStatus );
       
    99     FTRACE(FPrint( _L("RDun::ManageService() complete") ));
       
   100     return KErrNone;
       
   101     }
       
   102 
       
   103 // ---------------------------------------------------------------------------
       
   104 // This function gets the active connection
       
   105 // ---------------------------------------------------------------------------
       
   106 //
       
   107 TAny* RDun::ActiveConnection()
       
   108     {
       
   109     FTRACE(FPrint( _L("RDun::ActiveConnection()") ));
       
   110     TAny* connId = NULL;
       
   111     TPckg<TAny*> connIdPckg( connId );
       
   112     SendReceive( EDunFuncActiveConnection,
       
   113                  TIpcArgs(&connIdPckg) );
       
   114     FTRACE(FPrint( _L("RDun::ActiveConnection() complete") ));
       
   115     return connId;
       
   116     }
       
   117 
       
   118 // ---------------------------------------------------------------------------
       
   119 // Version number
       
   120 // ---------------------------------------------------------------------------
       
   121 //
       
   122 TVersion RDun::Version() const
       
   123     {
       
   124     FTRACE(FPrint( _L("RDun::Version()") ));
       
   125     FTRACE(FPrint( _L("RDun::Version() complete") ));
       
   126     return ( TVersion(KDunServerMajorVersionNumber,
       
   127                       KDunServerMinorVersionNumber,
       
   128                       KDunServerBuildVersionNumber) );
       
   129     }
       
   130 
       
   131 // ---------------------------------------------------------------------------
       
   132 // This function connects to DUN server and creates a new session.
       
   133 // ---------------------------------------------------------------------------
       
   134 //
       
   135 TInt RDun::Connect()
       
   136     {
       
   137     FTRACE(FPrint( _L("RDun::Connect()") ));
       
   138     TInt retry;
       
   139     TInt retVal = KErrNone;
       
   140     for ( retry=KDunRetryCount; retry>=0; retry-- )
       
   141         {
       
   142         retVal=CreateSession( KDialupServerName,
       
   143                               TVersion(KDunServerMajorVersionNumber,
       
   144                                        KDunServerMinorVersionNumber,
       
   145                                        KDunServerBuildVersionNumber),
       
   146                               KDunNumOfMessageSlots );
       
   147         if ( retVal == KErrNotFound || retVal == KErrServerTerminated )
       
   148             {
       
   149             retVal = StartServer();
       
   150             if ( retVal!=KErrNone && retVal!=KErrAlreadyExists )
       
   151                 {
       
   152                 FTRACE(FPrint( _L("RDun::Connect() complete (%d)"), retVal ));
       
   153                 return retVal;
       
   154                 }
       
   155             }
       
   156         else // KErrNone, or other error code.
       
   157             {
       
   158             FTRACE(FPrint( _L("RDun::Connect() complete (%d)"), retVal ));
       
   159             return retVal;
       
   160             }
       
   161         }
       
   162     FTRACE(FPrint( _L("RDun::Connect() complete (%d)"), retVal ));
       
   163     return retVal;
       
   164     }