|
S60 3rd Edition SDK for Symbian OS Example Applications Guide |
00001 /* 00002 * ============================================================================== 00003 * Name : SIPExGameEngine.h 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 #ifndef __CSIPEXENGINE_H__ 00017 #define __CSIPEXENGINE_H__ 00018 00019 // INCLUDES 00020 #include "SIPExGameConstants.h" 00021 #include "SIPExSocketEngineObserver.h" 00022 #include "SIPExSIPEngineObserver.h" 00023 00024 00025 // Remove imports in unit test build 00026 #ifdef CPPUNIT_TEST 00027 #undef IMPORT_C 00028 #define IMPORT_C 00029 #endif 00030 00031 // DATA TYPES 00032 00033 // FORWARD DECLARATIONS 00034 class MSIPExStateViewNotifier; 00035 class TSIPExState; 00036 class MSIPExGameObserver; 00037 class CSIPExSIPEngine; 00038 class CSIPExSocketEngine; 00039 class TInetAddr; 00040 00041 // CLASS DECLARATIONS 00042 /** 00043 * The engine class for SIP Example application. 00044 * the networking and SIP messaging. 00045 */ 00046 class CSIPExEngine 00047 : public CBase, 00048 public MSIPExSIPEngineObserver, 00049 public MSIPExSocketEngineObserver 00050 { 00051 public: 00052 00053 /** 00054 * Create new instance of GameEngine. 00055 * @param aGameObserver Reference to observing class. 00056 * @returns Pointer to new CSIPExEngine instance. 00057 */ 00058 IMPORT_C static CSIPExEngine* NewL( MSIPExGameObserver& aGameObserver ); 00059 00060 /** 00061 * Create new instance of GameEngine. 00062 * The GameEngine pointer is left to the CleanupStack 00063 * returned. 00064 * @param aGameObserver Reference to observing class. 00065 * @returns Pointer to new CSIPExEngine instance. 00066 */ 00067 IMPORT_C static CSIPExEngine* NewLC( MSIPExGameObserver& aGameObserver ); 00068 00069 /** 00070 * Destructor. 00071 */ 00072 IMPORT_C ~CSIPExEngine(); 00073 00074 public: // public data 00075 00076 /** 00077 * Enumerations for the application role. 00078 * The inviting peer acts as a client and invited peer as a server. 00079 */ 00080 enum TPeer 00081 { 00082 EUnknown, 00083 EClient, 00084 EServer 00085 }; 00086 00087 /** 00088 * Game engine states for UI. 00089 */ 00090 enum TEngineState 00091 { 00092 EIdle, 00093 EEnabled, 00094 EActivating, 00095 EActive 00096 }; 00097 00098 public: // New functions 00099 00100 /** 00101 * The instant message is send to the remote user. 00102 * Redirects the call to the active State object. 00103 * @param aAddress The address of the recipient. 00104 * @param aMsg The message. 00105 */ 00106 IMPORT_C void SendInstantMsgL( const TDesC& aAddress, const TDesC& aMsg ); 00107 00108 /** 00109 * Player invites the remote peer to the game. 00110 * Redirectes the call to the active State object. 00111 * @param aAddress The address of the invited peer. 00112 */ 00113 IMPORT_C void InviteL( const TDesC& aAddress ); 00114 00115 /** 00116 * The SIP profile is enabled. 00117 * Redirectes the call to the active State object. 00118 */ 00119 IMPORT_C void EnableProfileL(); 00120 00121 /** 00122 * The SIP profile is disabled. 00123 * Redirectes the call to the active State object. 00124 */ 00125 IMPORT_C void DisableProfileL(); 00126 00127 /** 00128 * The user ends the game. 00129 * Redirectes the call to the active State object. 00130 */ 00131 IMPORT_C void EndGameL(); 00132 00133 /** 00134 * Resolves whether we should draw cursor or not. 00135 * @return Returns ETrue if the game is in state where we 00136 * should draw cursor (if it is our turn). Otherwise 00137 * EFalse is returned. 00138 */ 00139 IMPORT_C TBool DrawCursor(); 00140 00141 /** 00142 * Resolves whether we should draw board or not. 00143 * @return Returns ETrue if the game is in state where we 00144 * should draw board (if profile is enabled). Otherwise 00145 * EFalse is returned. 00146 */ 00147 IMPORT_C TBool DrawBoard(); 00148 00149 /** 00150 * Updates the game state. User has pressed left key. 00151 */ 00152 IMPORT_C void CursorLeft(); 00153 00154 /** 00155 * Updates the game state. User has pressed right key. 00156 */ 00157 IMPORT_C void CursorRight(); 00158 00159 /** 00160 * Updates the game state. User has pressed enter key. 00161 */ 00162 IMPORT_C void CursorPressed(); 00163 00164 /** 00165 * Updatas the game state. User moves the cursor with pointer. 00166 * @param aNewCursorPosition A new cursor column position. 00167 */ 00168 IMPORT_C void MoveCursorL( const TInt aNewCursorPosition ); 00169 00170 /** 00171 * Returns value in specified place in the board. 00172 * @param aX The place's x coordinate. 00173 * @param aY The place's y coordinate. 00174 * @return The value in specified place. 00175 */ 00176 IMPORT_C TInt BoardValue( TInt aX, TInt aY ); 00177 00178 /** 00179 * Returns the cursor position. 00180 * @return The cursor's position 00181 */ 00182 IMPORT_C TInt Cursor(); 00183 00184 /** 00185 * Sets the iNotifier. 00186 * @param aNotifier Reference to the view notifier. 00187 */ 00188 IMPORT_C void SetViewNotifier( MSIPExStateViewNotifier& aNotifier ); 00189 00190 public: // From socket observer 00191 00192 /** 00193 * Callback from socket observer. 00194 * Called when the state changes in the socket engine. 00195 * @param aNewState A new state of the socket engine. 00196 */ 00197 void SocketState( TInt aNewState ); 00198 00199 /** 00200 * Callback from socket observer. 00201 * Called when the data is received from the socket. 00202 * @param aData The data received from the socket. 00203 */ 00204 void SocketData( TDesC8& aData ); 00205 00206 private: // From SIP observer. See SIPExObserver.h 00207 void InviteReceived( const TDesC8& aFrom, const TUint32 aIapId ); 00208 void InviteReceivedByRemote( const TInt aResponse ); 00209 void InviteDeclinedByRemote( const TInt aResponse ); 00210 void InviteAcceptedByRemote( const TInetAddr& aIPAddress, const TUint32 aIapId ); 00211 void InviteAcceptedByUs(); 00212 void InvitationCancelled(); 00213 void EngineError( TInt aError ); 00214 void CancelFailed(); 00215 void SessionEnded(); 00216 void ConnectionLost(); 00217 void ProfileEnabled( TUint32 aSIPProfileId ); 00218 void ProfileError( TInt aError ); 00219 void IMReceived( const TDesC8& aFrom, 00220 const TDesC8& aMessage ); 00221 void WriteLog( const TDesC8& aLog ); 00222 00223 private: // New functions 00224 00225 /** 00226 * Initilizes the game state. 00227 */ 00228 void ResetGame(); 00229 00230 /** 00231 * Destroys the iSocketEngine. 00232 */ 00233 void DestroySocketEngine(); 00234 00235 /** 00236 * Changes the active state. 00237 * @param aNewState A reference the to new active state. 00238 */ 00239 void ChangeState( TSIPExState& aNewState ); 00240 00241 /** 00242 * Send the move to the remote peer. 00243 * @param aX The x coordinate of the move. 00244 * @param aY The y coordinate of the move. 00245 */ 00246 void SendMessage( const TInt aX, const TInt aY ); 00247 00248 /** 00249 * Shows the text in the status info area. The call is 00250 * redirected to the view notifier. 00251 * @param aTxt The text shown in the status info area. 00252 */ 00253 void StatusInfoL( const TDesC& aTxt ); 00254 00255 /** 00256 * Shows the text in the info area. The call is redirected 00257 * to the view notifier. 00258 * @param aTxt The text shown in the info area. 00259 */ 00260 void InfoL( const TDesC& aInfoTxt ); 00261 00262 /** 00263 * Calculates the next free place in cursor's column. 00264 * @return The next free position on the board. 00265 */ 00266 TInt CalculatePos(); 00267 00268 /** 00269 * Checks if the move is win move. 00270 * @param aX The x coordinate of the move. 00271 * @param aY The y coordinate of the move. 00272 * @return 1 if you won, 00273 * 2 if the remote player has won, 00274 * -1 if not win move. 00275 */ 00276 TInt IsWin( const TInt aX, const TInt aY ); 00277 00278 /** 00279 * Returns the count of moves in this game. 00280 * @return The count of moves. 00281 */ 00282 TInt Moves(); 00283 00284 /** 00285 * Sets the specified value in to the specified place in 00286 * the board. 00287 * @param aX The x coordinate value. 00288 * @param aY The y coordinate value. 00289 * @param aValue The value to be set to the (x, y) position. 00290 */ 00291 void SetBoard( const TInt aX, const TInt aY, const TInt aValue ); 00292 00293 /** 00294 * Increases the moves value by specified amount. 00295 * @param aAmount The amount of the increased moves. 00296 */ 00297 void IncreaseMovesBy( const TInt aAmount ); 00298 00299 /** 00300 * Set cursor the specified position. 00301 * @param aNewValue The new position value for the cursor. 00302 */ 00303 void SetCursor( const TInt aNewValue ); 00304 00305 /** 00306 * Returns the peer value. 00307 * @return The iPeer value. 00308 */ 00309 TPeer Peer(); 00310 00311 /** 00312 * Sets the iPeer's value 00313 * @param aPeer A new value for the iPeer. 00314 */ 00315 void SetPeer( TPeer aPeer ); 00316 00317 /** 00318 * Sets remote peer's move to the board. 00319 * @param aX The x coordinate value. 00320 * @param aY The y coordinate value. 00321 */ 00322 void SetRemote( const TInt aX, const TInt aY ); 00323 00324 /** 00325 * The acceptance is asked from the user 00326 * Redirectes the call to the game observer. 00327 * @param aFrom The summoner's address 00328 * @return Whether we accept the invitation or not. 00329 */ 00330 TBool AcceptInvitationL( const TDesC8& aFrom ); 00331 00332 /** 00333 * Returns the SIP Engine pointer. 00334 * @return The pointer to the CSIPExSIPEngine. The ownership 00335 * is NOT transferred. 00336 */ 00337 CSIPExSIPEngine* SIPEngine(); 00338 00339 /** 00340 * Returns the socket engine. If the socket engine (iSocketEngine) is 00341 * NULL it will be created. 00342 * @return The pointer to the CSIPExSocketEngine. The ownership 00343 * is NOT transferred. 00344 */ 00345 CSIPExSocketEngine* SocketEngineL(); 00346 00347 /** 00348 * Returns the game observer reference. 00349 * @return The reference to the MSIPExGameObserver. 00350 */ 00351 MSIPExGameObserver& GameObserver(); 00352 00353 private: 00354 00355 /** 00356 * Constructor 00357 * @param aGameObserver The observer reference. 00358 */ 00359 CSIPExEngine( MSIPExGameObserver& aGameObserver ); 00360 00361 /** 00362 * 2nd phase constructor 00363 */ 00364 void ConstructL(); 00365 00366 private: // Member variables 00367 // Owned: States 00368 TSIPExState* iStateIdle; 00369 TSIPExState* iStateRegistering; 00370 TSIPExState* iStateRegistered; 00371 TSIPExState* iStateInviting; 00372 TSIPExState* iStateConnecting; 00373 TSIPExState* iStateLocal; 00374 TSIPExState* iStateRemote; 00375 TSIPExState* iStateAcceptingSIP; 00376 00377 // Not owned: ui notifier 00378 MSIPExStateViewNotifier* iNotifier; 00379 00380 // Owned: The networking engine 00381 CSIPExSocketEngine* iSocketEngine; 00382 00383 // Owned: The SIP signaling engine. 00384 CSIPExSIPEngine* iSIPEngine; 00385 00386 // Observer for game events 00387 MSIPExGameObserver& iGameObserver; 00388 00389 // Game data 00390 TInt iMoves; 00391 TInt iBoard[ KBoxCountX ][ KBoxCountY ]; 00392 TInt iCursor; 00393 TPeer iPeer; 00394 00395 // Not owned: Reference to active state 00396 TSIPExState* iActiveState; 00397 00398 // State classes are friend classes because they need access 00399 // to the engine. 00400 00401 friend class TSIPExState; 00402 friend class TSIPExStateAcceptingSIP; 00403 friend class TSIPExStateConnecting; 00404 friend class TSIPExStateIdle; 00405 friend class TSIPExStateInviting; 00406 friend class TSIPExStateLocal; 00407 friend class TSIPExStateRegistered; 00408 friend class TSIPExStateRegistering; 00409 friend class TSIPExStateRemote; 00410 00411 // In unit tests following friend class definitions are needed 00412 #ifdef CPPUNIT_TEST 00413 friend class CGameEngineTest; 00414 friend class CBaseStateTest; 00415 friend class CStateAcceptingSIPTest; 00416 #endif 00417 }; 00418 00419 #endif // __CSIPEXENGINE_H__ 00420
|
© Nokia 2006 |