localconnectivityservice/dun/client/src/dunplugin.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:  EComm interface implementation and the client side of DUN
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "dunplugin.h"
       
    20 #include "dunactive.h"
       
    21 #include "DunDebug.h"
       
    22 
       
    23 // ---------------------------------------------------------------------------
       
    24 // Two-phased constructor.
       
    25 // ---------------------------------------------------------------------------
       
    26 //
       
    27 CDunPlugin* CDunPlugin::NewL( TLocodServicePluginParams& aParams )
       
    28     {
       
    29     CDunPlugin* self = new (ELeave) CDunPlugin( aParams );
       
    30     CleanupStack::PushL( self );
       
    31     self->ConstructL();
       
    32     CleanupStack::Pop( self );
       
    33     return self;
       
    34     }
       
    35 
       
    36 // ---------------------------------------------------------------------------
       
    37 // Destructor.
       
    38 // ---------------------------------------------------------------------------
       
    39 //
       
    40 CDunPlugin::~CDunPlugin()
       
    41     {
       
    42     FTRACE(FPrint( _L("CDunPlugin::~CDunPlugin()") ));
       
    43     iActiveContainer.ResetAndDestroy();
       
    44     iActiveContainer.Close();
       
    45     if ( iServer.Handle() != KNullHandle )
       
    46         {
       
    47         iServer.Close();
       
    48         }
       
    49     FTRACE(FPrint( _L("CDunPlugin::~CDunPlugin() complete") ));
       
    50     }
       
    51 
       
    52 // ---------------------------------------------------------------------------
       
    53 // Return owned RServer
       
    54 // ---------------------------------------------------------------------------
       
    55 //
       
    56 RDun& CDunPlugin::Server()
       
    57     {
       
    58     FTRACE(FPrint( _L("CDunPlugin::Server()") ));
       
    59     FTRACE(FPrint( _L("CDunPlugin::Server() complete") ));
       
    60     return iServer;
       
    61     }
       
    62 
       
    63 // ---------------------------------------------------------------------------
       
    64 // Called by instance of CDunActive to inform Observer of service completed.
       
    65 // Destruct the active object.
       
    66 // ---------------------------------------------------------------------------
       
    67 //
       
    68 void CDunPlugin::ServiceCompleted( MDunActive* aRequest, TInt aError )
       
    69     {
       
    70     FTRACE(FPrint( _L("CDunPlugin::ServiceCompleted()") ));
       
    71     TInt i;
       
    72     TLocodBearer bearer = aRequest->Bearer();
       
    73     TBool status = aRequest->BearerStatus();
       
    74     for ( i=iActiveContainer.Count()-1; i>=0; i-- )
       
    75         {
       
    76         if ( iActiveContainer[i] == aRequest )
       
    77             {
       
    78             delete iActiveContainer[i];
       
    79             iActiveContainer.Remove( i );
       
    80             break;
       
    81             }
       
    82         }
       
    83     ReportCompletion( bearer, status, aError );
       
    84     FTRACE(FPrint( _L("CDunPlugin::ServiceCompleted() completed (%d)"), aError ));
       
    85     }
       
    86 
       
    87 // ---------------------------------------------------------------------------
       
    88 // From class CLocodServicePlugin.
       
    89 // Implements interface virtual function
       
    90 // ---------------------------------------------------------------------------
       
    91 //
       
    92 void CDunPlugin::ManageService( TLocodBearer aBearer, TBool aBearerStatus )
       
    93     {
       
    94     FTRACE(FPrint( _L("CDunPlugin::ManageService()") ));
       
    95     TInt retTemp;
       
    96     if ( iServer.Handle() == KNullHandle )
       
    97         {
       
    98         retTemp = iServer.Connect();
       
    99         if ( retTemp != KErrNone )
       
   100             {
       
   101             ReportCompletion( aBearer, aBearerStatus, retTemp );
       
   102             FTRACE(FPrint( _L("CDunPlugin::ManageService() (failed!) complete (%d)"), retTemp ));
       
   103             return;
       
   104             }
       
   105         }
       
   106     CDunActive* stateRequest = NULL;
       
   107     TRAPD( retTrap, stateRequest=CDunActive::NewL( this,
       
   108                                                    aBearer,
       
   109                                                    aBearerStatus ));
       
   110     if ( retTrap != KErrNone )
       
   111         {
       
   112         ReportCompletion( aBearer, aBearerStatus, retTrap );
       
   113         FTRACE(FPrint( _L("CDunPlugin::ManageService() (failed!) complete (%d)"), retTrap ));
       
   114         return;
       
   115         }
       
   116     if ( !stateRequest )
       
   117         {
       
   118         ReportCompletion( aBearer, aBearerStatus, KErrGeneral );
       
   119         FTRACE(FPrint( _L("CDunPlugin::ManageService() (failed!) complete (%d)"), KErrGeneral ));
       
   120         return;
       
   121         }
       
   122     retTemp = iActiveContainer.Append( stateRequest );
       
   123     if ( retTemp != KErrNone )
       
   124         {
       
   125         ReportCompletion( aBearer, aBearerStatus, retTemp );
       
   126         FTRACE(FPrint( _L("CDunPlugin::ManageService() (failed!) complete (%d)"), retTemp ));
       
   127         return;
       
   128         }
       
   129     stateRequest->ServiceRequest();
       
   130     FTRACE(FPrint( _L("CDunPlugin::ManageService() complete") ));
       
   131     }
       
   132 
       
   133 // ---------------------------------------------------------------------------
       
   134 // CDunPlugin::CDunPlugin
       
   135 // ---------------------------------------------------------------------------
       
   136 //
       
   137 CDunPlugin::CDunPlugin( TLocodServicePluginParams& aParams )
       
   138     : CLocodServicePlugin( aParams )
       
   139     {
       
   140     }
       
   141 
       
   142 // ---------------------------------------------------------------------------
       
   143 // CDunPlugin::ConstructL
       
   144 // ---------------------------------------------------------------------------
       
   145 //
       
   146 void CDunPlugin::ConstructL()
       
   147     {
       
   148     FTRACE(FPrint( _L("CDunPlugin::ConstructL()") ));
       
   149     FTRACE(FPrint( _L("CDunPlugin::ConstructL() complete") ));
       
   150     }
       
   151 
       
   152 // ---------------------------------------------------------------------------
       
   153 // Reports completion status to LOCOD
       
   154 // ---------------------------------------------------------------------------
       
   155 //
       
   156 void CDunPlugin::ReportCompletion( TLocodBearer aBearer,
       
   157                                    TBool aBearerStatus,
       
   158                                    TInt aErr)
       
   159     {
       
   160     FTRACE(FPrint( _L("CDunPlugin::ReportCompletion()") ));
       
   161     Observer().ManageServiceCompleted( aBearer,
       
   162                                        aBearerStatus,
       
   163                                        ImplementationUid(),
       
   164                                        aErr);
       
   165     FTRACE(FPrint( _L("CDunPlugin::ReportCompletion() completed (%d)"), aErr ));
       
   166     }