PECengine/PresenceManager2/SrcNWSessionSlot/CPEngNWSessionProxy.cpp
changeset 0 094583676ce7
equal deleted inserted replaced
-1:000000000000 0:094583676ce7
       
     1 /*
       
     2 * Copyright (c) 2005 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: this class handles the network session operation
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include "CPEngNWSessionProxy.h"
       
    20 #include "CPEngNWSessionSlotID2Imp.h"
       
    21 #include "CPEngSessionSlotId.h"
       
    22 
       
    23 #include <CPEngNWSessionSlotID2.h>
       
    24 #include <E32Std.h>
       
    25 
       
    26 
       
    27 
       
    28 // ============================ MEMBER FUNCTIONS ===============================
       
    29 
       
    30 // -----------------------------------------------------------------------------
       
    31 // CPEngNWSessionProxy::NewL()
       
    32 // Two-phased constructor.
       
    33 // -----------------------------------------------------------------------------
       
    34 //
       
    35 CPEngNWSessionProxy* CPEngNWSessionProxy::NewL(
       
    36     const CPEngNWSessionSlotID2& aNWSessionSlotID )
       
    37     {
       
    38     CPEngNWSessionProxy* self = new ( ELeave ) CPEngNWSessionProxy;
       
    39     CleanupStack::PushL( self );
       
    40     self->ConstructL( aNWSessionSlotID );
       
    41     CleanupStack::Pop( self );
       
    42     return self;
       
    43     }
       
    44 
       
    45 
       
    46 
       
    47 
       
    48 // Destructor
       
    49 CPEngNWSessionProxy::~CPEngNWSessionProxy()
       
    50     {
       
    51     Close();
       
    52     delete iNWSessionSlotID;
       
    53     }
       
    54 
       
    55 
       
    56 // -----------------------------------------------------------------------------
       
    57 // CPEngNWSessionProxy::CPEngNWSessionProxy
       
    58 // C++ default constructor can NOT contain any code, that
       
    59 // might leave.
       
    60 // -----------------------------------------------------------------------------
       
    61 //
       
    62 CPEngNWSessionProxy::CPEngNWSessionProxy()
       
    63         : iInitialized( EFalse )
       
    64     {
       
    65     }
       
    66 
       
    67 
       
    68 // -----------------------------------------------------------------------------
       
    69 // CPEngNWSessionProxy::ConstructL()
       
    70 // -----------------------------------------------------------------------------
       
    71 //
       
    72 void CPEngNWSessionProxy::ConstructL( const CPEngNWSessionSlotID2& aNWSessionSlotID )
       
    73     {
       
    74     iNWSessionSlotID = aNWSessionSlotID.Implementation()->CloneL();
       
    75     }
       
    76 
       
    77 
       
    78 // -----------------------------------------------------------------------------
       
    79 // CPEngNWSessionProxy::InitializeConnection()
       
    80 // -----------------------------------------------------------------------------
       
    81 //
       
    82 TInt CPEngNWSessionProxy::InitializeConnection()
       
    83     {
       
    84     if ( iInitialized )
       
    85         {
       
    86         return KErrNone;
       
    87         }
       
    88 
       
    89     TInt err = iMainClient.Connect();
       
    90     if ( err == KErrNone )
       
    91         {
       
    92         TRAP( err,
       
    93             {
       
    94             HBufC8* slotIdPkg = iNWSessionSlotID->BasePart().PackLC();
       
    95             User::LeaveIfError( iSessionClient.Connect( *slotIdPkg,
       
    96                                                         iNWSessionSlotID->AppId(),
       
    97                                                         iMainClient ) );
       
    98             CleanupStack::PopAndDestroy( slotIdPkg );
       
    99             } );
       
   100         }
       
   101 
       
   102     if ( err == KErrNone )
       
   103         {
       
   104         iInitialized = ETrue;
       
   105         }
       
   106     else
       
   107         {
       
   108         Close();
       
   109         }
       
   110 
       
   111     return err;
       
   112     }
       
   113 
       
   114 
       
   115 // -----------------------------------------------------------------------------
       
   116 // CPEngNWSessionProxy::Close()
       
   117 // -----------------------------------------------------------------------------
       
   118 //
       
   119 void CPEngNWSessionProxy::Close()
       
   120     {
       
   121     iSessionClient.Close();
       
   122     iMainClient.Close();
       
   123     iInitialized = EFalse;
       
   124     }
       
   125 
       
   126 
       
   127 // -----------------------------------------------------------------------------
       
   128 // CPEngNWSessionProxy::OpenSession()
       
   129 // -----------------------------------------------------------------------------
       
   130 //
       
   131 TInt CPEngNWSessionProxy::OpenSession( const TDesC8& aLogInData,
       
   132                                        TRequestStatus& aStatus )
       
   133     {
       
   134     TInt err = InitializeConnection();
       
   135     if ( err != KErrNone )
       
   136         {
       
   137         return err;
       
   138         }
       
   139 
       
   140     return iSessionClient.LogIn( aLogInData, aStatus );
       
   141     }
       
   142 
       
   143 
       
   144 // -----------------------------------------------------------------------------
       
   145 // CPEngNWSessionProxy::CancelOpenSession()
       
   146 // -----------------------------------------------------------------------------
       
   147 //
       
   148 void CPEngNWSessionProxy::CancelOpenSession()
       
   149     {
       
   150     if ( iInitialized )
       
   151         {
       
   152         iSessionClient.CancelLogIn();
       
   153         }
       
   154     }
       
   155 
       
   156 
       
   157 // -----------------------------------------------------------------------------
       
   158 // CPEngNWSessionProxy::CloseSession()
       
   159 // -----------------------------------------------------------------------------
       
   160 //
       
   161 TInt CPEngNWSessionProxy::CloseSession( TRequestStatus& aStatus )
       
   162     {
       
   163     if ( !iInitialized )
       
   164         {
       
   165         return KErrNotReady;
       
   166         }
       
   167 
       
   168     return iSessionClient.Detach( aStatus );
       
   169     }
       
   170 
       
   171 
       
   172 // -----------------------------------------------------------------------------
       
   173 // CPEngNWSessionProxy::CancelCloseSession()
       
   174 // -----------------------------------------------------------------------------
       
   175 //
       
   176 void CPEngNWSessionProxy::CancelCloseSession()
       
   177     {
       
   178     if ( iInitialized )
       
   179         {
       
   180         iSessionClient.CancelDetach();
       
   181         }
       
   182     }
       
   183 
       
   184 
       
   185 // -----------------------------------------------------------------------------
       
   186 // CPEngNWSessionProxy::ForceCloseSession()
       
   187 // -----------------------------------------------------------------------------
       
   188 //
       
   189 TInt CPEngNWSessionProxy::ForceCloseSession( TRequestStatus& aStatus )
       
   190     {
       
   191     TInt err = InitializeConnection();
       
   192     if ( err != KErrNone )
       
   193         {
       
   194         return err;
       
   195         }
       
   196 
       
   197     return iSessionClient.ForceLogOut( aStatus );
       
   198     }
       
   199 
       
   200 
       
   201 // -----------------------------------------------------------------------------
       
   202 // CPEngNWSessionProxy::CancelForceCloseSession()
       
   203 // -----------------------------------------------------------------------------
       
   204 //
       
   205 void CPEngNWSessionProxy::CancelForceCloseSession()
       
   206     {
       
   207     if ( iInitialized )
       
   208         {
       
   209         iSessionClient.CancelLogOut();
       
   210         }
       
   211     }
       
   212 
       
   213 
       
   214 // -----------------------------------------------------------------------------
       
   215 // CPEngNWSessionProxy::OpenOwnership()
       
   216 // -----------------------------------------------------------------------------
       
   217 //
       
   218 TInt CPEngNWSessionProxy::OpenOwnership()
       
   219     {
       
   220     TInt err = InitializeConnection();
       
   221     if ( err != KErrNone )
       
   222         {
       
   223         return err;
       
   224         }
       
   225 
       
   226     return iSessionClient.Attach();
       
   227     }
       
   228 
       
   229 
       
   230 // -----------------------------------------------------------------------------
       
   231 // CPEngNWSessionProxy::StoreOwnership()
       
   232 // -----------------------------------------------------------------------------
       
   233 //
       
   234 TInt CPEngNWSessionProxy::StoreOwnership( const TDesC16& aOwnerID )
       
   235     {
       
   236     TInt err = KErrNotReady;
       
   237 
       
   238     if ( iInitialized )
       
   239         {
       
   240         err = iSessionClient.LeaveAlive( aOwnerID );
       
   241         }
       
   242 
       
   243     return err;
       
   244     }
       
   245 
       
   246 
       
   247 // -----------------------------------------------------------------------------
       
   248 // CPEngNWSessionProxy::RestoreOwnership()
       
   249 // -----------------------------------------------------------------------------
       
   250 //
       
   251 TInt CPEngNWSessionProxy::RestoreOwnership( const TDesC16& aOwnerID )
       
   252     {
       
   253     TInt err = InitializeConnection();
       
   254     if ( err != KErrNone )
       
   255         {
       
   256         return err;
       
   257         }
       
   258 
       
   259     return iSessionClient.Attach( aOwnerID );
       
   260     }
       
   261 
       
   262 
       
   263 // -----------------------------------------------------------------------------
       
   264 // CPEngNWSessionProxy::GetServiceTree()
       
   265 // -----------------------------------------------------------------------------
       
   266 //
       
   267 TInt CPEngNWSessionProxy::GetServiceTree( TPEngWVCspServicesTree2& aCspTree )
       
   268     {
       
   269     TInt err = InitializeConnection();
       
   270     if ( err != KErrNone )
       
   271         {
       
   272         return err;
       
   273         }
       
   274 
       
   275     return iSessionClient.GetServiceTree( aCspTree );
       
   276     }
       
   277 
       
   278 
       
   279 // -----------------------------------------------------------------------------
       
   280 // CPEngNWSessionProxy::GetLoginData()
       
   281 // -----------------------------------------------------------------------------
       
   282 //
       
   283 TInt CPEngNWSessionProxy::GetLoginData( HBufC8*& aLogInData )
       
   284     {
       
   285     TInt err = InitializeConnection();
       
   286     if ( err != KErrNone )
       
   287         {
       
   288         return err;
       
   289         }
       
   290     aLogInData = NULL;
       
   291     return iSessionClient.LogInData( aLogInData );
       
   292     }
       
   293 
       
   294 
       
   295 //  End of File
       
   296