📄 bluetoothengine.h
字号:
#ifndef FightLandLordENGINE_H
#define FightLandLordENGINE_H
// INCLUDES
#include <e32base.h>
#include <aknviewappui.h>
#include <coecntrl.h>
#include <es_sock.h>
#include <btdevice.h>
#include <bt_sock.h>
#include <btsdp.h>
#include <btmanclient.h>
#include "GouYu.hrh"
#include "GouYuappview.h"
#include "GouYuappui.h"
#include "Common.h"
#include "DeviceDiscoverer.h"
#include "ServiceDiscoverer.h"
#include "Listener.h"
#include "Connector.h"
// maximum number of bluetooth device connections
const TInt KMaxConnectedDevices=1;
// length of label message buffer
const TInt KMsgLength = 384;
// FORWARD DECLARATIONS
class CGouYuAppUi;
class CGouYuAppView;
class CDeviceDiscoverer;
class CServiceAdvertiser;
class CServiceDiscoverer;
class CListener;
class CConnector;
// CLASS DECLARATION
/**
* CBluetoothEngine application engine class.
*
*/
class CBluetoothEngine : public CBase,
public MListenerObserver,
public MConnectorObserver,
public MDeviceDiscoObserver,
public MServiceDiscoObserver
{
public:
/*!
* NewL()
*
* discussion Create new CBluetoothEngine object
* return a pointer to the created instance of CBluetoothEngine
*/
static CBluetoothEngine* NewL(CGouYuAppUi*
/* aAppUi */);
/*!
* NewLC()
*
*/
static CBluetoothEngine* NewLC(CGouYuAppUi*
/* aAppUi */);
/*!
* ~CFightLandLordContainer()
*
* discussion Destroy the object and release all memory objects
*/
~CBluetoothEngine();
public: // New functions
/*!
* DiscoverDevicesL()
*
* discussion Discovers bluetooth devices within range. the discovered
* devices will be displayed to user.
*/
void DiscoverDevicesL();
/*!
* StartServiceDiscovery()
*
* discussion Starts service discovery for services on remote devices.
*/
void DiscoverServicesL();
/*!
* StartSlaveL()
*
* discussion Starts the application in slave more. the application will open
* listening socket to listen to incoming connection request, and advertise
* its services.
*/
void StartSlaveL();
/*!
* SendMessage()
*
* discussion Send a message to all connected slaves. the user will be
* prompted to enter the message text he/she wishes to send.
*/
void SendMessage();
void MasterSendMessage(TInt8 aMsgType);
void SlaveSendMessage(TInt8 aMsgType);
TInt num_temp;
/*!
* ConnectDevicesL()
*
* discussion Connects to the remote devices that were discovered to offer
* the service we require.
*/
void ConnectDevicesL();
/*!
* DisconnectDevicesL()
*
* discussion Disconnects from connected remote devices.
*/
void DisconnectDevicesL();
/*!
* ShowConnectedDevicesL()
*
* discussion Displays the connected remote devices.
*/
void ShowConnectedDevicesL();
/*!
* HandleListenerDataReceivedL()
*
* discussion Handles the data slave received from a master.
*
* param aData the data received.
*/
void HandleListenerDataReceivedL(TDesC& aData);
/*!
* HandleConnectedDataReceivedL()
*
* discussion Handles the data a master received from a slave.
*
* param aName the name of the slave that sent the data.
* param aData the data received.
*/
void HandleConnectorDataReceivedL(THostName aName, TDesC& aData);
/*!
* HandleListenerConnectedL()
*
* discussion Handles the event of slave connection (slave was connected to
* by master). user will be notified of connection.
*/
void HandleListenerConnectedL();
/*!
* HandleListenerDisconnectedL()
*
* discussion Handles the event of slave disconnection, the master connection
* to slave was terminated. user will be notitied of disconnection.
*/
void HandleListenerDisconnectedL();
/*!
* HandleDeviceDiscoveryCompleteL()
*
* discussion Handles the event of device discovery completion. the
* discovered devices will be displayed to user.
*/
void HandleDeviceDiscoveryCompleteL();
/*!
* HandleServiceDiscoveryCompleteL()
*
* discussion Handles the event of service discovery completion. the
* discovered services will be displayed to user.
*/
void HandleServiceDiscoveryCompleteL();
/*!
* HasConnection()
*
* discussion Returns true if master has any slave connections.
*/
TBool HasConnections();
private: // in-class methods
/*!
* ShowMessageL()
*
* discussion Displays application messages for user on a label
*
* param aMsg text to be displayed
* param aReset if true, the label will be cleared before displaying aMsg,
* if false, aMsg text will be appended to existing message on label
*/
void ShowMessageL(const TDesC& /* aMsg */, TBool /* aReset=false */);
private: // Basic two-phase EPOC constructors
/*!
* ConstructL()
*
*/
void ConstructL();
/*!
* CFightLandLordContainer()
*
* discussion Perform the first phase of two phase construction
*/
CBluetoothEngine(CGouYuAppUi* /* aAppUi */);
public: // data members
// listener
CListener* iListener;
// device discoverer
CDeviceDiscoverer* iDeviceDiscoverer;
// service advertiser
CServiceAdvertiser* iServiceAdvertiser;
// service discoverer
CServiceDiscoverer* iServiceDiscoverer;
// true if the application is acting as a slave
TBool iIsSlave;
private: // data members
// application UI object reference
CGouYuAppUi* iAppUi;
// socket server
RSocketServ iSocketServ;
// contains the messages shown on label
TBuf<KMsgLength> iMsg;
// number of lines in above
TInt iMsgLines;
// array holding the connectors
CConnector *iConnectedDevices[KMaxConnectedDevices];
// device data list reference
TDeviceDataList iDevDataList;
// number of slave connections master has
TInt iConnectedDeviceCount;
};
#endif
// End of File
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -