📄 gdpbt.h
字号:
// gdpbtr.h
//
// Bluetooth implementation of GDP
//
// Copyright (c) 2002 Symbian Ltd. All rights reserved
#ifndef __GDPBT_H__
#define __GDPBT_H__
#include "gdp.h"
#include "gdpmain.h"
#include "gdpstatemc.h"
#include <es_sock.h>
#include <bt_sock.h>
#include <e32std.h>
#include <e32base.h>
static const TInt KGdpBTMaxPacketLength = 200; // FIXME - What should this be???
static const TInt KGdpBTSendRetries = 4;
// FIXME - what the hell are these ???
const TInt KGdpBTMinLsap = 0x10;
const TInt KGdpBTMaxLsap = 0x7F;
class CGdpBTSender;
class CGdpBTReceiver;
class CGdpBTResourceManager;
/// @class Handle all Bluetooth Communication for GDP
class CGdpBTComms : public CGdpSession
{
public:
static CGdpSession* NewL();
~CGdpBTComms();
// Implementation of CGdpSession functions
void OpenL(MGdpPacketHandler* aHandler);
void Close();
void SendL(const TDesC8& aToAddress, const TDesC8& aData);
TInt ReceiveAll();
TInt GetMaxPacketLength() const;
TBool IsNetworked() const;
private:
// Implementation of MGdpPacketHandler functions ???
private:
CGdpBTComms();
CGdpBTSender* iSender; ///< Opens socket, sends data, closes socket
CGdpBTReceiver* iReceiver; ///< Opens listening socket
CGdpBTResourceManager* iResMan; ///< Stores socket info, BT address etc
};
/// @class CGdpBTStateMachine - generic FSM for BT Sender and BT Receiver
class CGdpBTStateMachine : public CGdpStateMachine
{
public:
CGdpBTStateMachine(CGdpBTResourceManager& aResMan);
protected:
CGdpBTResourceManager& iResMan; ///< Resource Manager - holds all BT data
};
/**
@class CGdpBTSender - Does the actual sending of data over BT
Is a state machine so it can connect to the other end and send the data
each time. NO BLUETOOTH CONNECTION REMAINS UP FOR MORE THAN ONE TRANSACTION
All states are friends so they can read the Sender's data
**/
class CGdpBTSender : public CGdpBTStateMachine
{
// State value declarations
class TSenderState : public CGdpStateMachine::TState
{
public:
TSenderState(CGdpBTSender& aSender);
virtual TState* ErrorL(TInt aCode);
protected:
CGdpBTSender& iSender;
};
class TConnectState : public TSenderState
{
public:
TConnectState(CGdpBTSender& aSender);
void EnterL();
TState* CompleteL();
void Cancel();
};
class TWriteState : public TSenderState
{
public:
TWriteState(CGdpBTSender& aSender);
void EnterL();
TState* CompleteL();
void Cancel();
};
friend class TConnectState;
friend class TWriteState;
public:
CGdpBTSender(CGdpBTResourceManager& aResMan);
void SendL(const TDesC8& aAddress, const TDesC8& aData);
~CGdpBTSender();
void OpenL(MGdpPacketHandler& aHandler);
void Close();
protected:
void Reset();
TState* ErrorOnStateEntry(TInt aError); ///< Override from CGdpStateMachine
TState* ErrorOnStateExit(TInt aError); ///< Override from CGdpStateMachine
private:
RSocket iWriteSocket; ///< Socket to use for sending data out
TBuf8<KGdpBTMaxPacketLength> iPacket; ///< Place to store the data to go out
TBTSockAddr iAddr; ///< BT address of device to send packet to
TInt iRetries; ///< No. of (potential) remaining retires.
MGdpPacketHandler* iHandler;
// States
TConnectState iConnectState;
TWriteState iWriteState;
};
/**
@class CGdpBTReceiver
Does the actual receiving of data over BT.
Is a state machine so it can listen to the other end, accept a connection
from the other end and then receive the data each time.
NO BLUETOOTH CONNECTION REMAINS UP FOR MORE THAN ONE TRANSACTION
**/
class CGdpBTReceiver : public CGdpBTStateMachine
//-----------------
{
// State value declarations
/// @class Generic Receiver state
class TReceiverState : public CGdpStateMachine::TState
{
public:
TReceiverState(CGdpBTReceiver& aReceiver);
protected:
CGdpBTReceiver& iReceiver;
};
/// @class TAcceptState - Accepts the connection from sending end
class TAcceptState : public TReceiverState
{
public:
TAcceptState(CGdpBTReceiver& aReceiver);
void EnterL();
TState* CompleteL();
TState* ErrorL(TInt aCode);
void Cancel();
};
/// @class Reads data from sending end after accepting connection
class TReadState : public TReceiverState
{
public:
TReadState(CGdpBTReceiver& aReceiver);
void EnterL();
TState* CompleteL();
TState* ErrorL(TInt aCode);
void Cancel();
};
/// States are friends so they can read the Receiver's data
friend class TAcceptState;
friend class TReadState;
public:
CGdpBTReceiver(CGdpBTResourceManager& aResMan);
~CGdpBTReceiver();
void OpenL(MGdpPacketHandler& aHandler); //< Open the Receiving socket
void Close();
protected:
// Overrides of CGdpStateMachine functions
TState* ErrorOnStateEntry(TInt aError);
TState* ErrorOnStateExit(TInt aError);
private:
void DoSecurityParams();
private:
MGdpPacketHandler* iHandler; //< Where to send the data to once it's received
/// Two sockets - one for listening for connect, other (clone) for reading
RSocket iListenSocket, iReadSocket;
TBuf8<KGdpBTMaxPacketLength> iPacket; //< Stores the packet of data just in
TBTSockAddr iAddr; //< Socket number to listen on
TBuf8<12> iRemAddr;
TAcceptState iAcceptState;
TReadState iReadState;
};
class CGdpBTResourceManager : public CBase
{
public:
CGdpBTResourceManager();
~CGdpBTResourceManager();
void OpenL();
void Close();
// Resource access
inline RSocketServ& SocketServer();
inline TProtocolDesc& ProtocolDesc();
private:
RSocket iSocket;
// Shared resources
RSocketServ iSocketServer;
TProtocolDesc iProtocolDesc;
};
/************** INLINES DECLARATIONS *****************/
RSocketServ& CGdpBTResourceManager::SocketServer() { return iSocketServer; }
TProtocolDesc& CGdpBTResourceManager::ProtocolDesc() { return iProtocolDesc; }
/*****************************************************/
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -