⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 btcon_msgclient.h

📁 C++实现的BlueTooth
💻 H
字号:
/*****************************************************************************

 COPYRIGHT All rights reserved Sony Ericsson Mobile Communications AB 2005.



 The software is the copyrighted work of Sony Ericsson Mobile Communications AB.

 The use of the software is subject to the terms of the end-user license

 agreement which accompanies or is included with the software. The software is

 provided "as is" and Sony Ericsson specifically disclaim any warranty or

 condition whatsoever regarding merchantability or fitness for a specific

 purpose, title or non-infringement. No warranty of any kind is made in

 relation to the condition, suitability, availability, accuracy, reliability,

 merchantability and/or non-infringement of the software provided herein.



 *****************************************************************************/


#ifndef __BTCON_MESSAGECLIENT_H__
#define __BTCON_MESSAGECLIENT_H__

#include <e32base.h>
#include <es_sock.h>

#include <bt_sock.h>
#include <btextnotifiers.h>
#include <BtSdp.h>


class CBTConAppView;
class CSdpAgent;


const TInt KMsgBufSizeClient = 32;


///////////////////////////////////////////////////////////////////////////////
//                                                                           //
// This is a CLIENT part of bluetooth communication.                         //
// Client connects to server to be able to exchange messages                 //
//                                                                           //
///////////////////////////////////////////////////////////////////////////////
class CMsgClient : public CActive,
                   public MSdpAgentNotifier,
                   public MSdpAttributeValueVisitor
{
public:
  static CMsgClient* NewL(CBTConAppView* aView);
  static CMsgClient* NewLC(CBTConAppView* aView);
  ~CMsgClient();

  TBool IsStarted() { return iCurrentState != EInitStage; }

  // starts process of connectng to a remote device
  void ConnectL();

  // sets client to initial, disconnects
  void Disconnect(TBool aDisplayInfo);

  // Sends a message to a connected party
  void SendMsgL(const TDesC& aMsg);
  // send message after reading message was cancelled first
  void DoSendMsgAfterCanceling();

public: // from MSdpAgentNotifier
  virtual void AttributeRequestComplete(TSdpServRecordHandle aHandle,
                                        TInt aError);
  virtual void AttributeRequestResult(TSdpServRecordHandle aHandle,
                                      TSdpAttributeID aAttrID,
                                      CSdpAttrValue* aAttrValue);
  virtual void NextRecordRequestComplete(TInt aError,
                                         TSdpServRecordHandle aHandle,
                                         TInt aTotalRecordsCount);

public: // from MSdpAttributeValueVisitor
  virtual void VisitAttributeValueL(CSdpAttrValue &aValue,
                                    TSdpElementType aType);
  virtual void StartListL(CSdpAttrValueList &aList);
  virtual void EndListL();


private: // from CActive
  void DoCancel();
  void RunL();

private:
  CMsgClient(CBTConAppView* aView);
  void ConstructL();

  void RequestData();

  void ConnectToServerL();
  void FindServiceL();
  void CheckConectionValidity();
  void RetryEstablishingConection();


private:

  enum TCurrentState
    {
    EInitStage = 201,  // initial stage, waits for selecting a device
    ESearchForDevice,  // searching for a device
    ESearchForService, // searching for a service
    EConnecting,       // connecting to a device
    ESendingTestMsg,   // checking conection

    EReading,          // is connected, waiting for data
    ECancelReading,    // cancel reading was issued, wait until it finishes
    EWriting,          // is connected, sending data

    EDisconnecting    // disconnecting from a sevice
    };

private:
  CBTConAppView* iPtrView;
  TCurrentState iCurrentState;

  TBTDeviceResponseParamsPckg iResultPckg;

  // a connection to the socket server
  RSocketServ iSocketServ;

  // a socket to connect with
  RSocket iSocket;

	CSdpAgent* iSdpAgent;
	CSdpSearchPattern* iSdpSearchPattern;
  TBool iHasFoundService;

  TUint iRemotePort;

  // the buffer to read data to
  TBuf8<KMsgBufSizeClient> iMsgBuffer;
  TSockXfrLength iLength;

  // true - sending of new message was already started,
  // no new sending of msg untill current one is finished
  TBool iBusyWriting;
  // saves message to sent when reading have to be canceled first
  HBufC8* iWriteMsgBuf;

};

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -