GamemComms
A GameComms.dll re-implementation for the Nokia N-Gage
GameBTComms.h
Go to the documentation of this file.
1 
13 #ifndef __GAMEBTCOMMS_H
14 #define __GAMEBTCOMMS_H
15 
20 #define VERSION 1
21 
22 #include <btsdp.h>
23 #include <e32base.h>
24 #include <e32std.h>
25 #include <es_sock.h>
26 #include "GameBTCommsConsts.h"
27 #include "MessageClient.h"
28 
29 class MGameBTCommsNotify;
30 class RSGEDebugLog;
31 class CGameBTBase;
32 
33 struct TBTCommsMsgBase;
34 
47 class CGameBTComms : public CBase
48 {
49 public:
69  IMPORT_C static CGameBTComms *NewL(MGameBTCommsNotify *aEventHandler, TUint32 aGameUID, RSGEDebugLog *aLog = NULL);
70  IMPORT_C ~CGameBTComms();
71 
72 public:
73  enum
74  {
75  KMaxPlayers = KBTMaxPlayers
76  };
77  enum
78  {
79  KServerConnectionId = KBTHostConnectionId
80  };
81  enum TConnectionRole
82  {
83  EIdle, EClient, EHost
84  };
85  enum TGameState
86  {
87  EGameOver, EPlay, EPause
88  };
89  enum TConnectState
90  {
91  ENotConnected, EConnecting, EConnected
92  };
93  enum TGameCommsState
94  {
95  EInit, ERegisterUID, ERegisterDeviceName, ERegisterNetConfig, ERegisterRole, EHandleMessages
96  };
97  enum TRecipientId
98  {
99  EToHost = 1, EToClient1 = 2, EToClient2 = 3, EToClient3 = 4, EToAll = 5, EInvalid = 0xff
100  };
101  enum
102  {
103  KMaxQueueSize = 32,
104  KMaxMessageSize = 64
105  };
106  typedef struct
107  {
108  TUint8 Pos;
109  TUint8 Length[KMaxQueueSize];
110  TUint8 Queue[KMaxQueueSize][KMaxMessageSize];
111 
112  } TMessageQueue;
113 
114 #if VERSION >= 10
115 
116  enum THostAcceptMode
117  {
118  EConfirmClients
119  };
120 
121 #endif /* VERSION >= 10 */
122 
123 public:
153  IMPORT_C void StartHostL(TUint16 aStartPlayers, TUint16 aMinPlayers);
154 
180  IMPORT_C void StartClientL();
181 
199  IMPORT_C TConnectionRole ConnectionRole();
200 
217  IMPORT_C TGameState GameState();
218 
237  IMPORT_C TConnectState ConnectState();
238 
252  IMPORT_C TInt GetLocalDeviceName(THostName &aHostName);
253 
254 #if VERSION < 10
255 
293  IMPORT_C void Disconnect();
294 
295 #endif /* VERSION > 10 */
296 
329  IMPORT_C TInt DisconnectClient(TUint16 aClientId);
330 
356  IMPORT_C TInt SendDataToClient(TUint16 aClientId, TDesC8 &aData);
357 
382  IMPORT_C TInt SendDataToAllClients(TDesC8 &aData);
383 
407  IMPORT_C TInt SendDataToHost(TDesC8 &aData);
408 
434  IMPORT_C TInt ContinueMultiPlayerGame();
435 
479  IMPORT_C TInt ReconnectL(TBool aMustReconnectToAll = ETrue);
480 
506  IMPORT_C TInt PauseMultiPlayerGame();
507 
540  IMPORT_C TInt EndMultiPlayerGame();
541 
567  IMPORT_C TBool IsShowingDeviceSelectDlg();
568 
569 #if VERSION >= 10
570 
571  IMPORT_C TInt Connect(); /* Expects KErrNone */
572  IMPORT_C TInt DeclareRemoteDevice(const TDeviceDetails &aDevice); /* Expects KErrNone */
573  IMPORT_C TInt SetBluetoothPowerState(TBool aState); /* Expects KErrNone */
574  IMPORT_C void SetLocalDeviceName(THostName aHostName); /* Return type unclear */
575  IMPORT_C void BluetoothPowerState(TBool aState); /* Return type unclear */
576  IMPORT_C void Disconnect(TUint16 aClientId = 0, TBool aPermanently = EFalse);
577  IMPORT_C void EndSession(); /* Return type unclear */
578  IMPORT_C void SendData(TUint16 aClientId, TPtr8 aData); /* Return type unclear */
579  IMPORT_C void SetDiscoverabilityModeLimited(TBool aMode); /* Return type unclear */
580  IMPORT_C void SetHostAcceptMode(THostAcceptMode aMode); /* Return type unclear */
581  IMPORT_C void SetSearchModeLimited(TBool aMode); /* Return type unclear */
582 
583 #endif /* VERSION >= 10 */
584 
585  void Update(TUint16 aClientId = EInvalid, const char *aData = NULL, TUint16 aLength = 0, const char *sDebug = NULL);
586 
587 private:
588 
589 protected:
590 
596  CGameBTComms();
597 
603  void ConstructL(MGameBTCommsNotify *aEventHandler, TUint32 aGameUID, RSGEDebugLog *aLog);
604 
605  void MessageBox(const TDesC &aMessage);
606  void HandleForegroundEventL(TBool aForeground);
607 
608 protected:
610  TUint32 iGameUID;
612  CGameBTBase *iComms;
613 
614 private:
615  TConnectionRole iConnectionRole;
616  TConnectionRole iConnectionRoleTemp;
617  TConnectState iConnectState;
618  TGameState iGameState;
619  TGameCommsState iGameCommsState;
620  TUint16 iStartPlayers;
621  TUint16 iMinPlayers;
622  CMessageClient *iClient;
623 
624  char iRecvBuffer[512];
625  TUint16 iRecvLength;
626 
627  TMessageQueue iMessageQueue[5];
628 };
629 
630 #endif /* __GAMEBTCOMMS_H */
const TInt KBTHostConnectionId
Host connection Id.
Definition: GameBTCommsConsts.h:14
const TInt KBTMaxPlayers
Maximum number of players.
Definition: GameBTCommsConsts.h:13
This is the main interface to the library exposing all multidevice games operations available to a de...
Definition: GameBTComms.h:48
IMPORT_C TInt SendDataToHost(TDesC8 &aData)
Performs a synchronous data write operation to the host.
Definition: GameBTComms.cpp:153
IMPORT_C TConnectState ConnectState()
Indicates the state of the connection.
Definition: GameBTComms.cpp:100
IMPORT_C TInt EndMultiPlayerGame()
This is called when a player no longer wishes to be part of the game (no option of continuing allowed...
Definition: GameBTComms.cpp:189
IMPORT_C TInt ContinueMultiPlayerGame()
This is called to continue a multiplayer game with the same parties that was paused by receiving a MG...
Definition: GameBTComms.cpp:162
IMPORT_C TConnectionRole ConnectionRole()
Indicates whether the device is the host or a client.
Definition: GameBTComms.cpp:86
IMPORT_C TInt GetLocalDeviceName(THostName &aHostName)
Gets the name from the user's Bluetooth settings.
Definition: GameBTComms.cpp:107
IMPORT_C TBool IsShowingDeviceSelectDlg()
Determine whether the Symbian device selection dialog is on display.
Definition: GameBTComms.cpp:198
IMPORT_C void Disconnect()
When called from a client, the connection to the host is dropped.
Definition: GameBTComms.cpp:122
CGameBTComms()
Default C++ Constructor.
Definition: GameBTComms.cpp:52
IMPORT_C TGameState GameState()
Indicates the state of the game.
Definition: GameBTComms.cpp:93
MGameBTCommsNotify * iNotify
Stores a pointer to the user object that will receive callbacks.
Definition: GameBTComms.h:609
IMPORT_C TInt SendDataToClient(TUint16 aClientId, TDesC8 &aData)
Performs a synchronous data write operation to the specified client.
Definition: GameBTComms.cpp:136
IMPORT_C TInt PauseMultiPlayerGame()
Sets each device's game status to paused.
Definition: GameBTComms.cpp:180
RSGEDebugLog * iLog
Pointer to file of debug logging (if included in build!)
Definition: GameBTComms.h:611
IMPORT_C TInt DisconnectClient(TUint16 aClientId)
Disconnects the client specified.
Definition: GameBTComms.cpp:127
IMPORT_C void StartHostL(TUint16 aStartPlayers, TUint16 aMinPlayers)
Set device as a the host.
Definition: GameBTComms.cpp:64
IMPORT_C void StartClientL()
Set the device as a client.
Definition: GameBTComms.cpp:73
IMPORT_C TInt SendDataToAllClients(TDesC8 &aData)
Performs a synchronous data broadcast operation to all connected clients.
Definition: GameBTComms.cpp:144
TUint32 iGameUID
UID of the game to be played.
Definition: GameBTComms.h:610
static IMPORT_C CGameBTComms * NewL(MGameBTCommsNotify *aEventHandler, TUint32 aGameUID, RSGEDebugLog *aLog=NULL)
Creates a new CGameBTComms object.
Definition: GameBTComms.cpp:41
void ConstructL(MGameBTCommsNotify *aEventHandler, TUint32 aGameUID, RSGEDebugLog *aLog)
EPOC Constructor.
Definition: GameBTComms.cpp:372
IMPORT_C TInt ReconnectL(TBool aMustReconnectToAll=ETrue)
This is called to reconnect a disconnected device (for example after the application went into the ba...
Definition: GameBTComms.cpp:171
This is the notification interface provided by the library.
Definition: GameBTCommsNotify.h:35
Provides output to a debug log on device (E:\debug.log). This slows down performance markedly.
Definition: SGEDebugLog.h:27
Definition: GameBTComms.h:107