S60 3rd Edition SDK for Symbian OS
Example Applications Guide

SIPExStateRemote.cpp

00001 /*
00002 * ==============================================================================
00003 *  Name        : SIPExStateRemote.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    "SIPExStateRemote.h"
00018 #include    "SIPExGameEngine.h"
00019 #include    "SIPExSIPEngine.h"
00020 
00021 // -----------------------------------------------------------------------------
00022 // TSIPExStateRegistering::SocketData
00023 // Resolves the move or message from remote player.
00024 // -----------------------------------------------------------------------------
00025 //
00026 void TSIPExStateRemote::SocketData( CSIPExEngine* aContext, TDesC8& aData )
00027     {
00028     // The length is fixed to 4. Format is "x, y".
00029         if ( aData.Length() == 4 ) 
00030         {
00031         TBuf<1> buffer;
00032         buffer.Copy( aData.Mid( 0, 1 ) );
00033         TLex lex( buffer );
00034                 TInt x( 0 );
00035                 TInt y( 0 );
00036         lex.Val( x );
00037         buffer.Copy( aData.Mid( 3, 1 ) );
00038         lex.Assign( buffer );
00039         lex.Val( y );
00040 
00041                 aContext->SetRemote( x, y );
00042         aContext->IncreaseMovesBy( 1 );
00043 
00044         TInt ret = aContext->IsWin(x,y);
00045                 aContext->SetCursor( x );
00046                 if (ret > 0) 
00047             {
00048             ChangeState( aContext, aContext->iStateRegistered );
00049             StatusInfo( aContext, KYouLose() );
00050                     } 
00051         else  if ( aContext->Moves() == KMaxMoves) 
00052             {
00053             ChangeState( aContext, aContext->iStateRegistered );
00054                         StatusInfo( aContext, KGameTie() );
00055                     } 
00056         else 
00057             {
00058             ChangeState( aContext, aContext->iStateLocal );
00059                         StatusInfo( aContext, KYourMove() );
00060                     }
00061             } 
00062     else 
00063         {
00064         HBufC* buf = HBufC::NewLC( aData.Length() );
00065         buf->Des().Copy( aData );
00066         aContext->InfoL( *buf );
00067         CleanupStack::PopAndDestroy( buf );
00068         }
00069     }
00070 
00071 // -----------------------------------------------------------------------------
00072 // TSIPExStateRegistering::SendInstantMsgL
00073 // Calls base classes function to send the instant message.
00074 // -----------------------------------------------------------------------------
00075 //
00076 void TSIPExStateRemote::SendInstantMsgL( CSIPExEngine* aContext, 
00077             const TDesC& aAddress, const TDesC& aMsg )
00078     {
00079     HBufC8* addr = HBufC8::NewLC( aAddress.Length() );
00080     addr->Des().Copy( aAddress );
00081 
00082     HBufC8* msg = HBufC8::NewLC( aMsg.Length() );
00083     msg->Des().Copy( aMsg );
00084 
00085     aContext->SIPEngine()->CreateIML( *msg, *addr );
00086 
00087     CleanupStack::PopAndDestroy( msg );
00088     CleanupStack::PopAndDestroy( addr );
00089     }
00090 
00091 // -----------------------------------------------------------------------------
00092 // TSIPExStateRegistering::DisableProfile
00093 // Notifies the UI.
00094 // -----------------------------------------------------------------------------
00095 //
00096 void TSIPExStateRemote::DisableProfileL( CSIPExEngine* aContext )
00097     {
00098     aContext->InfoL( KGameAlreadyRunning() );
00099     }
00100 
00101 // -----------------------------------------------------------------------------
00102 // TSIPExStateRegistering::EndGameL
00103 // Notifies the UI and changes the active state to the Registered.
00104 // The socket engine will be deleted and the SIP session ended.
00105 // -----------------------------------------------------------------------------
00106 //
00107 void TSIPExStateRemote::EndGameL( CSIPExEngine* aContext )
00108     {
00109     aContext->SIPEngine()->EndSessionL();
00110     }
00111 
00112 // End of file

© Nokia 2006

Back to top