PECengine/PresenceServer2/ServerSrc/CPEngSession.cpp
changeset 0 094583676ce7
equal deleted inserted replaced
-1:000000000000 0:094583676ce7
       
     1 /*
       
     2 * Copyright (c) 2002 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:  Presence Server session handler implementation
       
    15 *				 All clients request are handler here,
       
    16 *  				 or forwarded to the sub-session
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 
       
    22 //  Include Files
       
    23 #include	<e32base.h>
       
    24 #include	"CPEngSession.h"
       
    25 #include	"MPEngServer.h"
       
    26 #include	"CPEngSubSession.h"
       
    27 #include	"RPEngMessage.h"
       
    28 #include	"TPEngServerCommon.h"
       
    29 
       
    30 //	Debug prints
       
    31 #include	"PresenceDebugPrint.h"
       
    32 
       
    33 // ============================ MEMBER FUNCTIONS ===============================
       
    34 
       
    35 // -----------------------------------------------------------------------------
       
    36 // CPEngSession::CPEngSession
       
    37 // C++ default constructor can NOT contain any code, that might leave.
       
    38 // -----------------------------------------------------------------------------
       
    39 //
       
    40 CPEngSession::CPEngSession(
       
    41     MPEngServer& aServer )
       
    42         : iMainServer( aServer )
       
    43     {
       
    44     iMainServer.SessionCreated();
       
    45     }
       
    46 
       
    47 // -----------------------------------------------------------------------------
       
    48 // CPEngSession::ConstructL
       
    49 // Symbian 2nd phase constructor can leave.
       
    50 // -----------------------------------------------------------------------------
       
    51 //
       
    52 void CPEngSession::ConstructL()
       
    53     {
       
    54     iSubSessions = CObjectIx::NewL();
       
    55     }
       
    56 
       
    57 // Static constructor
       
    58 CPEngSession* CPEngSession::NewL( MPEngServer& aServer )
       
    59     {
       
    60     CPEngSession* self = new( ELeave ) CPEngSession( aServer );
       
    61     CleanupStack::PushL( self );
       
    62     self->ConstructL();
       
    63     CleanupStack::Pop();
       
    64 
       
    65     return self;
       
    66     }
       
    67 
       
    68 
       
    69 // Destructor (virtual by CBase)
       
    70 CPEngSession::~CPEngSession()
       
    71     {
       
    72     delete iSubSessions;
       
    73     // If main session will have some Async operations,
       
    74     // it needs to be canceled here
       
    75     iMainServer.SessionDied();
       
    76     }
       
    77 
       
    78 // =============================================================================
       
    79 // =============== Functions from CSession2 base class =========================
       
    80 // =============================================================================
       
    81 
       
    82 // -----------------------------------------------------------------------------
       
    83 // CPEngSession::ServiceL()
       
    84 // -----------------------------------------------------------------------------
       
    85 //
       
    86 void CPEngSession::ServiceL(
       
    87     const RMessage2 &aMessage )
       
    88     {
       
    89     PENG_DP( D_PENG_LIT( "CPEngSession::ServiceL:%d" ), aMessage.Function() );
       
    90 
       
    91     if ( DispatchMessageL( RPEngMessage( aMessage ) ) )
       
    92         {
       
    93         aMessage.Complete( KErrNone );
       
    94         }
       
    95     PENG_DP( D_PENG_LIT( "CPEngSession::ServiceL:%d -End" ), aMessage.Function() );
       
    96     }
       
    97 
       
    98 // -----------------------------------------------------------------------------
       
    99 // CPEngSession::ServiceError()
       
   100 // -----------------------------------------------------------------------------
       
   101 //
       
   102 void CPEngSession::ServiceError(
       
   103     const RMessage2& aMessage,
       
   104     TInt aError )
       
   105     {
       
   106     PENG_DP( D_PENG_LIT( "CPEngSession::ServiceError:  %d" ), aError );
       
   107     aMessage.Complete( aError );
       
   108     }
       
   109 
       
   110 // =============================================================================
       
   111 // =============== Private functions of the Session class ======================
       
   112 // =============================================================================
       
   113 
       
   114 // -----------------------------------------------------------------------------
       
   115 // CPEngSession::DispatchMessageL()
       
   116 // Dispatch message
       
   117 // (other items were commented in a header).
       
   118 // -----------------------------------------------------------------------------
       
   119 //
       
   120 TBool CPEngSession::DispatchMessageL(
       
   121     const RPEngMessage& aMessage )
       
   122     {
       
   123     TInt request( aMessage.Function() );
       
   124     TBool completeRequest( ETrue );
       
   125 
       
   126     switch ( request )
       
   127         {
       
   128         case EMainSessCreateHolderSubSession:
       
   129         case EMainSessCreateTransactionSubSession:
       
   130             {
       
   131             CreateNewSubSessionL( aMessage );
       
   132             break;
       
   133             }
       
   134 
       
   135         case EMainSessCloseSubSession:
       
   136             {
       
   137             RemoveSubSessionL( aMessage.Int3() );
       
   138             break;
       
   139             }
       
   140         default:
       
   141             {
       
   142             // try to handle message in sub-session
       
   143             CPEngSubSession& subSession = FindSubSessionL( aMessage.Int3() );
       
   144             completeRequest = subSession.DispatchMessageL( aMessage, request );
       
   145             break;
       
   146             }
       
   147         }
       
   148     return completeRequest && aMessage.MessageValid();
       
   149     }
       
   150 
       
   151 // -----------------------------------------------------------------------------
       
   152 // CPEngSession::CreateNewSubSessionL()
       
   153 // Create new sub-session
       
   154 // Back to the client is written handle of the created Sub session
       
   155 // (other items were commented in a header).
       
   156 // -----------------------------------------------------------------------------
       
   157 //
       
   158 void CPEngSession::CreateNewSubSessionL(
       
   159     const RPEngMessage& aMessage )
       
   160     {
       
   161     PENG_DP( D_PENG_LIT( "CPEngSession::CreateNewSubSessionL" ) );
       
   162     CPEngSubSession* subSession =
       
   163         CPEngSubSession::NewLC(
       
   164             iMainServer,
       
   165             aMessage,
       
   166             reinterpret_cast<TInt32>( this ) );
       
   167 
       
   168     iMainServer.AddSubSessionL( *subSession );
       
   169     CleanupStack::Pop( ); // newSubsSession
       
   170 
       
   171     TInt handle( 0 );
       
   172     TRAPD( err, handle = iSubSessions->AddL( subSession ) );
       
   173     if ( err != KErrNone )
       
   174         {
       
   175         iMainServer.RemoveSubSessionL( *subSession );
       
   176         User::Leave( err );
       
   177         }
       
   178 
       
   179     subSession->SetSubSesionHandle( handle );
       
   180 
       
   181     // write back handle of the sub-session
       
   182     TPckg<TInt> handlePckg( handle );
       
   183     err = aMessage.WriteOneDescriptor( KMessageSlot3 , handlePckg );
       
   184     if ( err != KErrNone )
       
   185         {
       
   186         iSubSessions->Remove( handle );
       
   187         PanicClient( aMessage, EPECBadDescriptor );
       
   188         return;
       
   189         }
       
   190     }
       
   191 
       
   192 
       
   193 // -----------------------------------------------------------------------------
       
   194 // CPEngSession::RemoveSubSession()
       
   195 // Remove Sub-Session
       
   196 // Function leaves if there is no such a subssession
       
   197 // (other items were commented in a header).
       
   198 // -----------------------------------------------------------------------------
       
   199 //
       
   200 void CPEngSession::RemoveSubSessionL(
       
   201     TUint  aHandle )
       
   202     {
       
   203     // this will leave if there is such a sub-session
       
   204     FindSubSessionL( aHandle );
       
   205     iSubSessions->Remove( aHandle );
       
   206     }
       
   207 
       
   208 // -----------------------------------------------------------------------------
       
   209 // CPEngSession::FindSubSession()
       
   210 // Find Sub-session
       
   211 // Function leaves if such a subsession does not exists
       
   212 // (other items were commented in a header).
       
   213 // -----------------------------------------------------------------------------
       
   214 //
       
   215 CPEngSubSession& CPEngSession::FindSubSessionL(
       
   216     TUint  aHandle ) const
       
   217     {
       
   218     // if there is no sub-session, it leaves with KErrBadHandle
       
   219     return static_cast<CPEngSubSession&> ( *( iSubSessions->AtL( aHandle ) ) );
       
   220     }
       
   221 
       
   222 // -----------------------------------------------------------------------------
       
   223 // CPEngSession::PanicClient()
       
   224 // Panic client
       
   225 // (other items were commented in a header).
       
   226 // -----------------------------------------------------------------------------
       
   227 //
       
   228 void CPEngSession::PanicClient(
       
   229     const RPEngMessage& aMessage,
       
   230     const TInt aPanic ) const
       
   231     {
       
   232     aMessage.Panic( KSessionName, aPanic );
       
   233     }
       
   234 
       
   235 //  End of File
       
   236 
       
   237 
       
   238 
       
   239 
       
   240 
       
   241 
       
   242 
       
   243 
       
   244