btconnectionbase.cpp

来自「S60培训教材代码(连载)」· C++ 代码 · 共 63 行

CPP
63
字号
/* Copyright (c) 2002, Nokia Mobile Phones. All rights reserved */

#include "BTConnectionBase.h"
#include "Log.h"

CBTConnectionBase::CBTConnectionBase(MLog& aLog)
: CActive(CActive::EPriorityStandard),
  iLog(aLog)
    {
    CActiveScheduler::Add(this);
    }

CBTConnectionBase::~CBTConnectionBase()
    {
    }


void CBTConnectionBase::WriteDataSyncL(TDesC8& aData)
    {
    if (IsActive()) 
        {
        iLog.LogL(_L8("WriteDataSyncL, error still reading! "), iStatus.Int());
        User::Leave(KErrInUse);
        }
    // TODO: Use RSocket::Write() to write data on the connection socket
    // Hint: iDataSocket is the connected socket, iStatus should be used also.

    // TODO: Wait until this has finished
    // Hint: Use User::WaitForRequest()

    // TODO: Check the error code using iStatus.Int()
    // and leave if there has been an error
    }

void CBTConnectionBase::ReadDataL()
    {
    if (IsActive()) 
        {
        User::Leave(KErrInUse);
        }
    // TODO: Read some data from the connected socket
    // Hint: Use RSocket::RecvOneOrMore() - iBuffer should receive the length
    // iLen can be used to get the length (redundant)
    // no flags are needed (0).
    SetActive();
    }

void CBTConnectionBase::ReadDataL(TInt aLength)
    {
    if (IsActive()) 
        {
        User::Leave(KErrInUse);
        }
    if (aLength > iBuffer.MaxLength())
        {
        User::Leave(KErrOverflow);
        }
    iBuffer.SetLength(aLength);
    iDataSocket.Read(iBuffer, iStatus);
    SetActive();
    }

⌨️ 快捷键说明

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