realtimenetprots/sipfw/SampleApp/gameengine/Src/SIPExStateIdle.cpp
changeset 0 307788aac0a8
equal deleted inserted replaced
-1:000000000000 0:307788aac0a8
       
     1 
       
     2 // Copyright (c) 2004-2009 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:
       
    15 //
       
    16 
       
    17 
       
    18 
       
    19 // INCLUDES
       
    20 #include    "SIPExStateIdle.h"
       
    21 #include    "SIPExGameEngine.h"
       
    22 #include    "SIPExSIPEngine.h"
       
    23 
       
    24 // -----------------------------------------------------------------------------
       
    25 // TSIPExStateIdle::EnableProfile
       
    26 // Notifies the UI, signals SIP engine to enable profile and changes the active
       
    27 // state to the Registering. If no registration is needed the state is changed
       
    28 // straight to the Registered.
       
    29 // -----------------------------------------------------------------------------
       
    30 //
       
    31 void TSIPExStateIdle::EnableProfileL( CSIPExEngine* aContext )
       
    32     {
       
    33     // Notify UI
       
    34     aContext->InfoL( KEnablingProfile() );
       
    35 
       
    36     // The registration is required
       
    37     if( !aContext->SIPEngine()->EnableProfileL() )
       
    38         {
       
    39         ChangeState( aContext, aContext->iStateRegistering );
       
    40         }
       
    41     // The profile was succesfully enabled and registered
       
    42     else
       
    43         {
       
    44         aContext->InfoL( KProfileEnabled() );
       
    45         ChangeState( aContext, aContext->iStateRegistered );
       
    46         }
       
    47     }
       
    48 
       
    49 // -----------------------------------------------------------------------------
       
    50 // TSIPExStateIdle::SessionEnded
       
    51 // Notifies the UI.
       
    52 // -----------------------------------------------------------------------------
       
    53 //
       
    54 void TSIPExStateIdle::SessionEnded( CSIPExEngine* aContext )
       
    55     {
       
    56     // Keep track whether session ended while accept dialog was shown to user.
       
    57     iEnded = ETrue;
       
    58     
       
    59     Info( aContext, KSessionEnded() );
       
    60     }
       
    61 
       
    62 // -----------------------------------------------------------------------------
       
    63 // TSIPExStateIdle::InviteReceived
       
    64 // The acceptance is asked from the user and if accepted we reset game, start
       
    65 // listening socket and signal the SIP engine to send Accepted to the remote
       
    66 // peer.
       
    67 // -----------------------------------------------------------------------------
       
    68 //   
       
    69 void TSIPExStateIdle::InviteReceived( 
       
    70     CSIPExEngine* aContext, 
       
    71     const TDesC8& aFrom, 
       
    72     const TUint32 aIapId )
       
    73     {
       
    74     iEnded = EFalse;
       
    75     
       
    76     TBool retVal( EFalse );
       
    77     TRAPD( ignore, retVal = aContext->AcceptInvitationL( aFrom ) );
       
    78     if ( iEnded )
       
    79         {
       
    80         return;
       
    81         }
       
    82     if( retVal )
       
    83         {
       
    84         ChangeState( aContext, aContext->iStateAcceptingSIP );
       
    85         // The game data is reseted
       
    86         aContext->ResetGame();
       
    87         // The role for the peer is set
       
    88         aContext->SetPeer( CSIPExEngine::EServer );
       
    89         // Start listen incoming connections
       
    90         TInetAddr addr;
       
    91         TRAP( ignore, 
       
    92                 addr = aContext->SocketEngineL()->StartListeningL( aIapId ) );
       
    93         // Signal SIP engine
       
    94         TRAP( ignore, aContext->SIPEngine()->AcceptInviteL( addr ) );
       
    95         Info( aContext, KWaitingRemoteConn() );
       
    96         }
       
    97     else 
       
    98         {
       
    99         // Signal SIP engine
       
   100         TRAP( ignore, aContext->SIPEngine()->DeclineInviteL() );
       
   101         Info( aContext, KInviteDeclined() );
       
   102         }
       
   103     }
       
   104 
       
   105 // End of file