S60 3rd Edition SDK for Symbian OS
Example Applications Guide

SIPExStateRegistered.cpp

00001 /*
00002 * ==============================================================================
00003 *  Name        : SIPExStateRegistered.cpp
00004 *  Part of     : SIPExEngine
00005 *  Interface   : 
00006 *  Description : 
00007 *  Version     : 
00008 *
00009 *  Copyright (c) 2004-2006 Nokia Corporation.
00010 *  This material, including documentation and any related 
00011 *  computer programs, is protected by copyright controlled by 
00012 *  Nokia Corporation.
00013 * ==============================================================================
00014 */
00015 
00016 // INCLUDES
00017 #include    "SIPExStateRegistered.h"
00018 #include    "SIPExGameEngine.h"
00019 #include    "SIPExSIPEngine.h"
00020 
00021 
00022 // -----------------------------------------------------------------------------
00023 // TSIPExStateRegistered::InviteL
00024 // SIP engine is signaled to send invite to the specified address.
00025 // The UI is notified and the active state changed to the Inviting.
00026 // -----------------------------------------------------------------------------
00027 //   
00028 void TSIPExStateRegistered::InviteL( 
00029     CSIPExEngine* aContext, 
00030     const TDesC& aAddress )
00031     {
00032     ChangeState( aContext, aContext->iStateInviting );
00033     
00034     HBufC8* address = HBufC8::NewLC( aAddress.Length() );
00035     address->Des().Copy( aAddress );
00036     aContext->SIPEngine()->SendInviteL( *address );
00037     aContext->InfoL( KInviting() );
00038     aContext->InfoL( aAddress );
00039     aContext->StatusInfoL( KGameStarting() );
00040     CleanupStack::PopAndDestroy( address );
00041     }
00042 
00043 // -----------------------------------------------------------------------------
00044 // TSIPExStateRegistered::SendInstantMsgL
00045 // Calls base classes function to send the instant message.
00046 // -----------------------------------------------------------------------------
00047 //   
00048 void TSIPExStateRegistered::SendInstantMsgL( CSIPExEngine* aContext, 
00049             const TDesC& aAddress, const TDesC& aMsg )
00050     {
00051     HBufC8* addr = HBufC8::NewLC( aAddress.Length() );
00052     addr->Des().Copy( aAddress );
00053 
00054     HBufC8* msg = HBufC8::NewLC( aMsg.Length() );
00055     msg->Des().Copy( aMsg );
00056 
00057     aContext->SIPEngine()->CreateIML( *msg, *addr );
00058 
00059     CleanupStack::PopAndDestroy( msg );
00060     CleanupStack::PopAndDestroy( addr );
00061     }
00062 
00063 // -----------------------------------------------------------------------------
00064 // TSIPExStateRegistered::SessionEnded
00065 // Notifies the UI.
00066 // -----------------------------------------------------------------------------
00067 //
00068 void TSIPExStateRegistered::SessionEnded( CSIPExEngine* aContext )
00069     {
00070     // Keep track whether session ended while accept dialog was shown to user.
00071     iEnded = ETrue;
00072 
00073     Info( aContext, KSessionEnded() );
00074     StatusInfo( aContext, KGameOver() );
00075     TRAPD( ignore, aContext->SocketEngineL()->Stop() );
00076     aContext->DestroySocketEngine();
00077     }
00078     
00079 // -----------------------------------------------------------------------------
00080 // TSIPExStateRegistered::InviteReceived
00081 // The acceptance is asked from the user and if accepted we reset game, start
00082 // listening socket and signal the SIP engine to send Accepted to the remote
00083 // peer.
00084 // -----------------------------------------------------------------------------
00085 //   
00086 void TSIPExStateRegistered::InviteReceived( 
00087     CSIPExEngine* aContext, 
00088     const TDesC8& aFrom, 
00089     const TUint32 aIapId )
00090     {
00091     iEnded = EFalse;
00092     
00093     TBool retVal( EFalse );
00094     TRAPD( ignore, retVal = aContext->AcceptInvitationL( aFrom ) );
00095     if ( iEnded )
00096         {
00097         return;
00098         }
00099     if( retVal )
00100         {
00101         StatusInfo( aContext, KGameStarting() );
00102         ChangeState( aContext, aContext->iStateAcceptingSIP );
00103         aContext->ResetGame();
00104         aContext->SetPeer( CSIPExEngine::EServer );
00105         Info( aContext, KListening() );
00106         TInetAddr addr;
00107         TRAP( ignore, addr = 
00108                         aContext->SocketEngineL()->StartListeningL( aIapId ) );
00109         Info( aContext, KAccepting() );
00110         TRAP( ignore, aContext->SIPEngine()->AcceptInviteL( addr ) );
00111         Info( aContext, KWaitingRemoteConn() );
00112         }
00113     else 
00114         {
00115         TRAP( ignore, aContext->SIPEngine()->DeclineInviteL() );
00116         Info( aContext, KInviteDeclined() );
00117         }
00118     }
00119 
00120 // -----------------------------------------------------------------------------
00121 // TSIPExStateRegistered::DisableProfile
00122 // Disable profile and notify the UI.
00123 // -----------------------------------------------------------------------------
00124 //   
00125 void TSIPExStateRegistered::DisableProfileL( CSIPExEngine* aContext )
00126     {
00127     ChangeState( aContext, aContext->iStateIdle );
00128     aContext->SIPEngine()->DisableProfileL();
00129     aContext->InfoL( KProfileDisabled() );
00130     }
00131 
00132 // -----------------------------------------------------------------------------
00133 // TSIPExStateRegistered::SocketState
00134 // Notify the UI.
00135 // -----------------------------------------------------------------------------
00136 //  
00137 void TSIPExStateRegistered::SocketState( CSIPExEngine* aContext, TInt aNewState )
00138     {
00139     if( aNewState == CSIPExSocketEngine::ENotConnected )
00140         {
00141         Info( aContext, KConnectionDropped() );
00142         StatusInfo( aContext, KGameOver() );
00143         }
00144     }
00145 
00146 // End of file
00147 

© Nokia 2006

Back to top