Nokia N97 SDK
Example Applications Guide

TSIPExStateLocal Class Reference

#include <SIPExStateLocal.h>

Inheritance diagram for TSIPExStateLocal:

TSIPExState List of all members.

Detailed Description

The state is valid when waiting the user move.

Definition at line 26 of file SIPExStateLocal.h.


Public Member Functions

virtual void  CursorPressed (CSIPExEngine *aContext)
virtual void  CursorRight (CSIPExEngine *aContext)
virtual void  CursorLeft (CSIPExEngine *aContext)
virtual void  MoveCursorL (CSIPExEngine *aContext, const TInt aNewPosition)
virtual TBool  DrawCursor ()
virtual void  SendInstantMsgL (CSIPExEngine *aContext, const TDesC &aAddress, const TDesC &aMsg)
virtual void  InviteL (CSIPExEngine *aContext, const TDesC &aAddress)
virtual void  DisableProfileL (CSIPExEngine *aContext)
virtual void  EndGameL (CSIPExEngine *aContext)
void  ChangeState (CSIPExEngine *aContext, TSIPExState *aNewState)
void  Info (CSIPExEngine *aContext, const TDesC &aText)
void  StatusInfo (CSIPExEngine *aContext, const TDesC &aText)
void  CombineAndShowInfoL (CSIPExEngine *aContext, const TDesC &aText, TInt aNum)
virtual void  InviteReceived (CSIPExEngine *aContext, const TDesC8 &aFrom, const TUint32 aIapId)
virtual void  InviteAcceptedByRemote (CSIPExEngine *aContext, const TInetAddr &aIPAddress, const TUint32 aIapId)
virtual void  InviteDeclinedByRemote (CSIPExEngine *aContext, const TInt aResponse)
virtual void  InviteReceivedByRemote (CSIPExEngine *aContext, const TInt aResponse)
virtual void  InviteAcceptedByUs (CSIPExEngine *aContext)
virtual void  InvitationCancelled (CSIPExEngine *aContext)
virtual void  CancelFailed (CSIPExEngine *aContext)
virtual void  ProfileEnabled (CSIPExEngine *aContext, TUint32 aSIPProfileId)
virtual void  IMReceived (CSIPExEngine *aContext, const TDesC8 &aFrom, const TDesC8 &aMessage)
virtual void  SessionEnded (CSIPExEngine *aContext)
virtual void  ConnectionLost (CSIPExEngine *aContext)
virtual void  ProfileError (CSIPExEngine *aContext, TInt aError)
void  EngineError (CSIPExEngine *aContext, TInt aError)
virtual void  SocketState (CSIPExEngine *aContext, TInt aNewState)
virtual void  SocketData (CSIPExEngine *aContext, TDesC8 &aData)
virtual TBool  DrawBoard ()
virtual TInt  CalculatePos (CSIPExEngine *aContext)
virtual TInt  IsWin (CSIPExEngine *aContext, const TInt aX, const TInt aY)
virtual void  EnableProfileL (CSIPExEngine *aContext)


Member Function Documentation

void TSIPExStateLocal::CursorPressed (  CSIPExEngine *  aContext  )  [virtual]
 

CursorPressed From TSIPExState

Reimplemented from TSIPExState.

Definition at line 29 of file SIPExStateLocal.cpp.

References CSIPExEngine::CalculatePos(), TSIPExState::ChangeState(), CSIPExEngine::Cursor(), EndGameL(), CSIPExEngine::IncreaseMovesBy(), CSIPExEngine::iStateRemote, CSIPExEngine::IsWin(), CSIPExEngine::Moves(), CSIPExEngine::SendMessage(), CSIPExEngine::SetBoard(), and CSIPExEngine::StatusInfoL().

00030     {
00031     TInt y = aContext->CalculatePos();
00032         if ( y != -1 ) 
00033         {
00034         aContext->SetBoard( aContext->Cursor(), y, 1 );
00035                 aContext->IncreaseMovesBy( 1 );
00036                 aContext->SendMessage( aContext->Cursor(), y );
00037                 TInt ret = aContext->IsWin( aContext->Cursor(),y ); 
00038                 
00039         if (ret == 1) 
00040             {
00041             ChangeState( aContext, aContext->iStateRemote );
00042             aContext->StatusInfoL( KYouWin() );
00043             EndGameL( aContext );
00044                         }
00045         else  if ( aContext->Moves() == KMaxMoves ) 
00046             {
00047             ChangeState( aContext, aContext->iStateRemote );
00048                         aContext->StatusInfoL( KGameTie() );
00049             EndGameL( aContext );
00050                     }         
00051         else 
00052             {
00053             ChangeState( aContext, aContext->iStateRemote );
00054             aContext->StatusInfoL( KWaitingRemote() );
00055                         }
00056                 }
00057     }

void TSIPExStateLocal::CursorRight (  CSIPExEngine *  aContext  )  [virtual]
 

CursorRight From TSIPExState

Reimplemented from TSIPExState.

Definition at line 64 of file SIPExStateLocal.cpp.

References CSIPExEngine::Cursor(), and CSIPExEngine::SetCursor().

00065     {
00066     aContext->SetCursor( aContext->Cursor() + 1 );
00067         if ( aContext->Cursor() > KBoxCountX - 1 )
00068         {
00069                 aContext->SetCursor( 0 );
00070         }
00071     }

void TSIPExStateLocal::CursorLeft (  CSIPExEngine *  aContext  )  [virtual]
 

CursorLeft From TSIPExState

Reimplemented from TSIPExState.

Definition at line 78 of file SIPExStateLocal.cpp.

References CSIPExEngine::Cursor(), and CSIPExEngine::SetCursor().

00079     {
00080         aContext->SetCursor( aContext->Cursor() - 1 );
00081         if ( aContext->Cursor() < 0 )
00082         {
00083                 aContext->SetCursor( KBoxCountX - 1 );
00084         }
00085     }

void TSIPExStateLocal::MoveCursorL (  CSIPExEngine *  aContext,
const TInt  aNewPosition
)  [virtual]
 

MoveCursorL From TSIPExState

Reimplemented from TSIPExState.

Definition at line 156 of file SIPExStateLocal.cpp.

References CSIPExEngine::SetCursor().

00159     {
00160     aContext->SetCursor( aNewPosition );
00161     }

TBool TSIPExStateLocal::DrawCursor (   )  [virtual]
 

DrawCursor From TSIPExState

Reimplemented from TSIPExState.

Definition at line 93 of file SIPExStateLocal.cpp.

00094     {
00095     return ETrue;
00096     }

void TSIPExStateLocal::SendInstantMsgL (  CSIPExEngine *  aContext,
const TDesC &  aAddress,
const TDesC &  aMsg
)  [virtual]
 

SendInstantMsgL From TSIPExState

Reimplemented from TSIPExState.

Definition at line 103 of file SIPExStateLocal.cpp.

References CSIPExSIPEngine::CreateIML(), and CSIPExEngine::SIPEngine().

00105     {
00106     HBufC8* addr = HBufC8::NewLC( aAddress.Length() );
00107     addr->Des().Copy( aAddress );
00108 
00109     HBufC8* msg = HBufC8::NewLC( aMsg.Length() );
00110     msg->Des().Copy( aMsg );
00111 
00112     aContext->SIPEngine()->CreateIML( *msg, *addr );
00113 
00114     CleanupStack::PopAndDestroy( msg );
00115     CleanupStack::PopAndDestroy( addr );
00116     }

void TSIPExStateLocal::InviteL (  CSIPExEngine *  aContext,
const TDesC &  aAddress
)  [virtual]
 

InviteL From TSIPExState

Reimplemented from TSIPExState.

Definition at line 123 of file SIPExStateLocal.cpp.

References CSIPExEngine::InfoL().

00126     {
00127     aContext->InfoL( KGameAlreadyRunning() );
00128     }

void TSIPExStateLocal::DisableProfileL (  CSIPExEngine *  aContext  )  [virtual]
 

DisableProfile From TSIPExState

Reimplemented from TSIPExState.

Definition at line 135 of file SIPExStateLocal.cpp.

References CSIPExEngine::InfoL().

00136     {
00137     aContext->InfoL( KGameAlreadyRunning() );
00138     }

void TSIPExStateLocal::EndGameL (  CSIPExEngine *  aContext  )  [virtual]
 

EndGameL From TSIPExState

Reimplemented from TSIPExState.

Definition at line 146 of file SIPExStateLocal.cpp.

References CSIPExSIPEngine::EndSessionL(), and CSIPExEngine::SIPEngine().

Referenced by CursorPressed().

00147     {
00148     aContext->SIPEngine()->EndSessionL();
00149     }

void TSIPExState::ChangeState (  CSIPExEngine *  aContext,
TSIPExState *  aNewState
)  [inherited]
 

ChangeState Changing the active state.

Parameters:
aContext  The pointer to the game engine.
aNewState  The new active state.

Definition at line 26 of file SIPExState.cpp.

References CSIPExEngine::ChangeState().

Referenced by TSIPExState::ConnectionLost(), CursorPressed(), TSIPExStateRegistered::DisableProfileL(), TSIPExStateIdle::EnableProfileL(), TSIPExState::EngineError(), TSIPExStateInviting::InvitationCancelled(), TSIPExStateAcceptingSIP::InvitationCancelled(), TSIPExStateInviting::InviteAcceptedByRemote(), TSIPExStateInviting::InviteDeclinedByRemote(), TSIPExStateRegistered::InviteL(), TSIPExStateRegistered::InviteReceived(), TSIPExStateIdle::InviteReceived(), TSIPExStateRegistering::ProfileEnabled(), TSIPExStateRegistering::ProfileError(), TSIPExState::ProfileError(), TSIPExState::SessionEnded(), TSIPExStateRemote::SocketData(), TSIPExStateConnecting::SocketState(), and TSIPExStateAcceptingSIP::SocketState().

00027     {
00028     aContext->ChangeState( *aNewState );
00029     }

void TSIPExState::Info (  CSIPExEngine *  aContext,
const TDesC &  aText
)  [inherited]
 

Info Non leaving function for setting info text.

Parameters:
aContext  The pointer to the game engine.
aText  A text to set to the info

Definition at line 36 of file SIPExState.cpp.

References CSIPExEngine::InfoL().

Referenced by TSIPExState::CombineAndShowInfoL(), TSIPExState::ConnectionLost(), TSIPExStateInviting::InvitationCancelled(), TSIPExStateInviting::InviteAcceptedByRemote(), TSIPExState::InviteAcceptedByUs(), TSIPExStateRegistered::InviteReceived(), TSIPExStateIdle::InviteReceived(), TSIPExStateRegistering::ProfileEnabled(), TSIPExStateRegistering::ProfileError(), TSIPExStateRegistered::SessionEnded(), TSIPExStateIdle::SessionEnded(), TSIPExState::SessionEnded(), and TSIPExStateRegistered::SocketState().

00037     {
00038     TRAPD( ignore, aContext->InfoL( aText ) );
00039     }

void TSIPExState::StatusInfo (  CSIPExEngine *  aContext,
const TDesC &  aText
)  [inherited]
 

StatusInfo Non leaving function for setting status info text.

Parameters:
aContext  The pointer to the game engine.
aText  A text to set to the info

Definition at line 46 of file SIPExState.cpp.

Referenced by TSIPExState::ConnectionLost(), TSIPExState::EngineError(), TSIPExStateInviting::InvitationCancelled(), TSIPExStateInviting::InviteDeclinedByRemote(), TSIPExStateRegistered::InviteReceived(), TSIPExState::ProfileError(), TSIPExStateRegistered::SessionEnded(), TSIPExState::SessionEnded(), TSIPExStateRemote::SocketData(), and TSIPExStateRegistered::SocketState().

00047     {
00048     TRAPD( ignore, aContext->StatusInfoL( aText ) );
00049     }

void TSIPExState::CombineAndShowInfoL (  CSIPExEngine *  aContext,
const TDesC &  aText,
TInt  aNum
)  [inherited]
 

CombineAndShowInfoL Combines a descriptor and a number value as one descriptor. The result descriptor is set to info view. The max length of the new desc is 64.

Parameters:
aContext  The pointer to the game engine.
aText  A text part.
aNum  A number part.

Definition at line 56 of file SIPExState.cpp.

References TSIPExState::Info().

Referenced by TSIPExState::EngineError(), TSIPExStateInviting::InviteDeclinedByRemote(), TSIPExState::InviteReceivedByRemote(), and TSIPExState::ProfileError().

00060     {
00061     HBufC* buf = HBufC::NewLC( 64 );
00062     buf->Des().Append( aText );
00063     buf->Des().AppendNum( aNum );
00064     Info( aContext, *buf );
00065     CleanupStack::PopAndDestroy( buf );
00066     }

void TSIPExState::InviteReceived (  CSIPExEngine *  aContext,
const TDesC8 &  aFrom,
const TUint32  aIapId
)  [virtual, inherited]
 

InviteReceived From MSIPExSIPEngineObserver.

Reimplemented in TSIPExStateIdle, and TSIPExStateRegistered.

Definition at line 73 of file SIPExState.cpp.

Referenced by CSIPExEngine::InviteReceived().

00075     { 
00076     }

void TSIPExState::InviteAcceptedByRemote (  CSIPExEngine *  aContext,
const TInetAddr &  aIPAddress,
const TUint32  aIapId
)  [virtual, inherited]
 

InviteAcceptedByRemote From MSIPExSIPEngineObserver.

Reimplemented in TSIPExStateInviting.

Definition at line 83 of file SIPExState.cpp.

Referenced by CSIPExEngine::InviteAcceptedByRemote().

00087     { 
00088     }

void TSIPExState::InviteDeclinedByRemote (  CSIPExEngine *  aContext,
const TInt  aResponse
)  [virtual, inherited]
 

InviteDeclinedByRemote From MSIPExSIPEngineObserver.

Reimplemented in TSIPExStateInviting.

Definition at line 95 of file SIPExState.cpp.

Referenced by CSIPExEngine::InviteDeclinedByRemote().

00098     { 
00099     }

void TSIPExState::InviteReceivedByRemote (  CSIPExEngine *  aContext,
const TInt  aResponse
)  [virtual, inherited]
 

InviteReceivedByRemote From MSIPExSIPEngineObserver.

Definition at line 467 of file SIPExState.cpp.

References TSIPExState::CombineAndShowInfoL().

Referenced by CSIPExEngine::InviteReceivedByRemote().

00469     {
00470     TRAPD( ignore, CombineAndShowInfoL( aContext, KProvResponse(), aResponse ) );
00471     }

void TSIPExState::InviteAcceptedByUs (  CSIPExEngine *  aContext  )  [virtual, inherited]
 

InviteAcceptedByUs From MSIPExSIPEngineObserver.

Definition at line 479 of file SIPExState.cpp.

References TSIPExState::Info().

Referenced by CSIPExEngine::InviteAcceptedByUs().

00480     { 
00481     Info( aContext, KAckReceived() ); 
00482     }

void TSIPExState::InvitationCancelled (  CSIPExEngine *  aContext  )  [virtual, inherited]
 

InvitationCancelled From MSIPExSIPEngineObserver.

Reimplemented in TSIPExStateAcceptingSIP, and TSIPExStateInviting.

Definition at line 106 of file SIPExState.cpp.

Referenced by CSIPExEngine::InvitationCancelled().

00107     { 
00108     }

void TSIPExState::CancelFailed (  CSIPExEngine *  aContext  )  [virtual, inherited]
 

CancelFailed From MSIPExSIPEngineObserver.

Definition at line 115 of file SIPExState.cpp.

Referenced by CSIPExEngine::CancelFailed().

00116     { 
00117     }

void TSIPExState::ProfileEnabled (  CSIPExEngine *  aContext,
TUint32  aSIPProfileId
)  [virtual, inherited]
 

ProfileEnabled From MSIPExSIPEngineObserver.

Reimplemented in TSIPExStateRegistering.

Definition at line 124 of file SIPExState.cpp.

Referenced by CSIPExEngine::ProfileEnabled().

00127     { 
00128     }

void TSIPExState::IMReceived (  CSIPExEngine *  aContext,
const TDesC8 &  aFrom,
const TDesC8 &  aMessage
)  [virtual, inherited]
 

IMReceived From MSIPExSIPEngineObserver.

Definition at line 440 of file SIPExState.cpp.

References CSIPExEngine::GameObserver(), and MSIPExGameObserver::IMReceivedL().

Referenced by CSIPExEngine::IMReceived().

00444     {
00445     TRAPD( ignore, aContext->GameObserver().IMReceivedL( aFrom, aMessage ) );
00446     }

void TSIPExState::SessionEnded (  CSIPExEngine *  aContext  )  [virtual, inherited]
 

SessionEnded From MSIPExSIPEngineObserver.

Reimplemented in TSIPExStateIdle, and TSIPExStateRegistered.

Definition at line 399 of file SIPExState.cpp.

References TSIPExState::ChangeState(), CSIPExEngine::DestroySocketEngine(), TSIPExState::Info(), CSIPExEngine::iStateRegistered, CSIPExEngine::SocketEngineL(), TSIPExState::StatusInfo(), and CSIPExSocketEngine::Stop().

Referenced by CSIPExEngine::SessionEnded().

00400     {
00401     ChangeState( aContext, aContext->iStateRegistered );
00402     Info( aContext, KSessionEnded() );
00403     StatusInfo( aContext, KGameOver() );
00404     TRAPD( ignore, aContext->SocketEngineL()->Stop() );
00405     aContext->DestroySocketEngine();
00406     }

void TSIPExState::ConnectionLost (  CSIPExEngine *  aContext  )  [virtual, inherited]
 

ConnectionLost From MSIPExSIPEngineObserver.

Definition at line 414 of file SIPExState.cpp.

References TSIPExState::ChangeState(), TSIPExState::Info(), CSIPExEngine::iStateIdle, and TSIPExState::StatusInfo().

Referenced by CSIPExEngine::ConnectionLost().

00415     {
00416     ChangeState( aContext, aContext->iStateIdle );
00417     Info( aContext, KConnectionLost() );
00418     StatusInfo( aContext, KGameOver() );
00419     }

void TSIPExState::ProfileError (  CSIPExEngine *  aContext,
TInt  aError
)  [virtual, inherited]
 

ProfileError From MSIPExSIPEngineObserver.

Reimplemented in TSIPExStateRegistering.

Definition at line 427 of file SIPExState.cpp.

References TSIPExState::ChangeState(), TSIPExState::CombineAndShowInfoL(), CSIPExEngine::iStateIdle, and TSIPExState::StatusInfo().

Referenced by CSIPExEngine::ProfileError().

00428     {
00429     ChangeState( aContext, aContext->iStateIdle );
00430     TRAPD( ignore, CombineAndShowInfoL( aContext, KProfileError(), aError ) );
00431     StatusInfo( aContext, KGameOver() );
00432     }

void TSIPExState::EngineError (  CSIPExEngine *  aContext,
TInt  aError
)  [inherited]
 

EngineError From MSIPExSIPEngineObserver.

Definition at line 454 of file SIPExState.cpp.

References TSIPExState::ChangeState(), TSIPExState::CombineAndShowInfoL(), and TSIPExState::StatusInfo().

Referenced by CSIPExEngine::EngineError().

00455     {
00456     ChangeState( aContext, aContext->iStateIdle );
00457     TRAPD( ignore, CombineAndShowInfoL( aContext, KErrorInSIPEngine(), aError ) );
00458     StatusInfo( aContext, KGameOver() );
00459     }

void TSIPExState::SocketState (  CSIPExEngine *  aContext,
TInt  aNewState
)  [virtual, inherited]
 

SocketState From MSIPExSocketEngineObserver.

Reimplemented in TSIPExStateAcceptingSIP, TSIPExStateConnecting, and TSIPExStateRegistered.

Definition at line 135 of file SIPExState.cpp.

Referenced by CSIPExEngine::SocketState().

00136     { 
00137     }

void TSIPExState::SocketData (  CSIPExEngine *  aContext,
TDesC8 &  aData
)  [virtual, inherited]
 

SocketData From MSIPExSocketEngineObserver.

Reimplemented in TSIPExStateRemote.

Definition at line 144 of file SIPExState.cpp.

Referenced by CSIPExEngine::SocketData().

00145     { 
00146     }

TBool TSIPExState::DrawBoard (   )  [virtual, inherited]
 

DrawBoard Tells whether we should draw the board or not.

Definition at line 249 of file SIPExState.cpp.

Referenced by CSIPExEngine::DrawBoard().

00250     { 
00251     return ETrue; 
00252     }

TInt TSIPExState::CalculatePos (  CSIPExEngine *  aContext  )  [virtual, inherited]
 

CalculatePos Calculates the next free place in cursor's column.

Definition at line 259 of file SIPExState.cpp.

References CSIPExEngine::BoardValue(), and CSIPExEngine::Cursor().

Referenced by CSIPExEngine::CalculatePos().

00260     {
00261     TInt y( KErrNotFound );
00262 
00263         for ( TInt i = KBoxCountX - 1; i >= 0; i-- ) 
00264         {
00265                 if ( aContext->BoardValue( aContext->Cursor(), i ) == -1 ) 
00266             {
00267                         y = i;
00268                         return y;
00269                     }
00270             }
00271 
00272         return y;
00273     }

TInt TSIPExState::IsWin (  CSIPExEngine *  aContext,
const TInt  aX,
const TInt  aY
)  [virtual, inherited]
 

IsWin Checks the if the move is winning move.

Definition at line 280 of file SIPExState.cpp.

References CSIPExEngine::BoardValue().

Referenced by CSIPExEngine::IsWin().

00281     {
00282         TInt ret = -1;
00283 
00284         TInt player = aContext->BoardValue( aX, aY );
00285         TInt line1 = 1;
00286         TInt line2 = 1;
00287         TInt line3 = 1;
00288         TInt line4 = 1;
00289 
00290         TInt i = 0;
00291         TInt j = 0;
00292 
00293         for (i = aX + 1; i < 8; i ++) 
00294         {
00295                 if ( aContext->BoardValue( i, aY ) == player )
00296                         line1 ++;
00297                 else
00298                         break;
00299             }
00300 
00301         for (i = aX - 1; i >= 0; i --) 
00302         {
00303                 if ( aContext->BoardValue( i, aY ) == player )
00304                         line1 ++;
00305                 else
00306                         break;
00307             }
00308 
00309         if (line1 >= 4)
00310                 return player;
00311 
00312         for (i = aY + 1; i < 8; i ++) 
00313         {
00314                 if ( aContext->BoardValue( aX, i ) == player )
00315                         line2 ++;
00316                 else
00317                         break;
00318             }
00319 
00320         for (i = aY - 1; i >= 0; i --)
00321         {
00322                 if ( aContext->BoardValue( aX, i ) == player )
00323                         line2 ++;
00324                 else
00325                         break;
00326             }
00327 
00328         if (line2 >= 4)
00329                 return player;
00330 
00331 
00332         j = aY;
00333         for (i = aX + 1; i < 8; i ++) 
00334         {
00335                 j = j + 1;
00336                 if (j > 7)
00337                         break;
00338 
00339                 if ( aContext->BoardValue( i, j ) == player )
00340                         line3 ++;
00341                 else
00342                         break;
00343             }
00344 
00345         j = aY;
00346         for (i = aX - 1; i >= 0; i --) 
00347         {
00348                 j = j - 1;
00349                 if (j < 0)
00350                         break;
00351 
00352                 if ( aContext->BoardValue( i, j ) == player )
00353                         line3 ++;
00354                 else
00355                         break;
00356             }
00357 
00358         if (line3 >= 4)
00359                 return player;
00360 
00361         j = aY;
00362         for (i = aX + 1; i < 8; i ++) 
00363         {
00364                 j = j - 1;
00365                 if (j < 0)
00366                         break;
00367 
00368                 if ( aContext->BoardValue( i, j ) == player )
00369                         line4 ++;
00370                 else
00371                         break;
00372             }
00373 
00374         j = aY;
00375         for (i = aX - 1; i >= 0; i --) 
00376         {
00377                 j = j + 1;
00378                 if (j > 7)
00379                         break;
00380 
00381                 if ( aContext->BoardValue( i, j ) == player )
00382                         line4 ++;
00383                 else
00384                         break;
00385             }
00386 
00387         if (line4 >= 4)
00388                 return player;
00389 
00390         return ret;
00391     }

void TSIPExState::EnableProfileL (  CSIPExEngine *  aContext  )  [virtual, inherited]
 

EnableProfile Virtual function.

Reimplemented in TSIPExStateIdle.

Definition at line 153 of file SIPExState.cpp.

Referenced by CSIPExEngine::EnableProfileL().

00154     { 
00155     }


The documentation for this class was generated from the following files:

© Nokia 2009

Back to top