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

📄 btcon_msgserver.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.



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


///////////////////////////////////////////////////////////////////////////////
//                                                                           //
// This is a SERVER part of bluetooth communication.                         //
// Server is started and waits for request from client                       //
// to establish connunication                                                //
//                                                                           //
///////////////////////////////////////////////////////////////////////////////


#ifndef __BTCON_MESSAGESERVER_H__
#define __BTCON_MESSAGESERVER_H__


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


class CBTConAppView;
class CSdpManager;


const TInt KMsgBufSizeServ = 32;


class CMsgServer : public CActive
{
public:
  static CMsgServer* NewL(CBTConAppView* aView);
  static CMsgServer* NewLC(CBTConAppView* aView);
  ~CMsgServer();

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

  void ConnectL();

  void Disconnect(TBool aDisplayInfo);

  // Sends a message to a connected party
  void SendMsgL(const TDesC& aMsg);

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

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

  // set to wait for data, issue to read msg
  void RequestData();

  // Set service security requirements
  void SetSecurityL(TInt aChannel);

  // send message after reading message was cancelled first
  void DoSendMsgAfterCanceling();

private:
  enum TCurrentState
    {
    EInitAndDisconnected = 301, // server is disconnected
    EConnecting,          // connecting in progress
    EReading,             // is connected, waiting for data
    ECancelReading,       // cancel reading was issued, wait until it finishes
    EWriting,             // is connected, sending data
    EReady                // is connected, both read or write are possible
    };

private:
  CBTConAppView* iPtrView;

  CSdpManager* iSdpManager;

  TCurrentState iCurrentState;

  // establish subsession communications for RSocket
  RSocketServ iSocketServ;
  // listening socket
  RSocket iSocketListen;
  // socket that connections are accepted to
  RSocket iSocketAccept;

  // the buffer to read data to
  TBuf8<KMsgBufSizeServ> 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 // __MESSAGESERVER_H__

⌨️ 快捷键说明

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