/*
    Call back from MLlcpReadWriteCb
*/
void CLlcpSocketType1::ReceiveComplete(TInt aError)
    {
    BEGIN
    TInt err = KErrNone;
    if (KErrNone == aError)
        {
        QT_TRYCATCH_ERROR(err,iCallback.invokeReadyRead());
        }
    else
        {
        LOG("err = "<<err);
        QT_TRYCATCH_ERROR(err,iCallback.invokeError());
        }
    Q_UNUSED(err);
    END
    }
/*
    Call back from MLlcpConnLessListener
*/
void CLlcpSocketType1::FrameReceived(MLlcpConnLessTransporter* aConnection)
    {
    BEGIN
    iRemotePort = aConnection->SsapL();
//    StartTransportAndReceive(aConnection);
    // Only accepting one incoming remote connection
    TInt error = KErrNone;
    if (iConnectionWrapper)
        {
        delete iConnectionWrapper;
        iConnectionWrapper = NULL;
        }
    // Creating wrapper for connection.
    TRAP(error, iConnectionWrapper = COwnLlcpConnectionWrapper::NewL(aConnection, *this));

    if (error == KErrNone && iConnectionWrapper != NULL)
        {
        error = iConnectionWrapper->Receive();
        }
    if (error != KErrNone)
        {
        QT_TRYCATCH_ERROR(error,iCallback.invokeError());
        }
    END
    }
void QTimerActiveObject::RunL()
{
    int error;
    QT_TRYCATCH_ERROR(error, Run());
    // All Symbian error codes are negative.
    if (error < 0) {
        CActiveScheduler::Current()->Error(error);  // stop and report here, as this timer will be deleted on scope exit
    }
}
void UT_LifeTimerKeySequenceHandler::t_constructionFails()
{
    EXPECT(CRepository, NewL).willOnce(invoke(generateLeaveL));
    
    int result = 0;
    QT_TRYCATCH_ERROR(result, 
        QScopedPointer<LifeTimerKeySequenceHandler> handler(
            new LifeTimerKeySequenceHandler())
    )
    QVERIFY(0 != result);
}
void CNearFieldTag::DoCancel()
    {
    BEGIN
    iTagConnection->CancelRawModeAccess();
    if (iCallback)
        {
        LOG("call back command complete with KErrCancel");
        TInt err;
        QT_TRYCATCH_ERROR(err, iCallback->CommandComplete(KErrCancel));
        Q_UNUSED(err);
        }
    END
    }
void UT_LifeTimerKeySequenceHandler::t_executeKeySequenceEtelConnectionCreationFails()
{
    EXPECT(CRepository, Get)
        .willOnce(invoke(this, setLifeTimerData))
        .returns(KErrNone);
    EXPECT(RTelServer, Connect).willOnce(invoke(generateLeaveL));
    
    int result = 0;
    QT_TRYCATCH_ERROR(result, m_handler->executeKeySequence(KCodeLifeTimer));
    
    QVERIFY(0 != result);
    QVERIFY(verify());
}
// ----------------------------------------------------------------------------
// CPcsKeyMap::GetMappedStringL
// ----------------------------------------------------------------------------
HBufC* CPcsKeyMap::GetMappedStringL(const TDesC& aSource) const
    {
    PRINT1(_L("Enter CPcsKeyMap::GetMappedStringL input '%S'"), &aSource);

	QString source((QChar*)aSource.Ptr(), aSource.Length());
	QString result;
	TInt err(KErrNone);
	QT_TRYCATCH_ERROR(err, result = GetMappedString(source));
	User::LeaveIfError(err);

    HBufC* destination = HBufC::NewL(result.length());
	destination->Des().Copy(result.utf16());

    PRINT1(_L("End CPcsKeyMap::GetMappedStringL result '%S'"), destination);
    return destination;
    }
// ----------------------------------------------------------------------------
// C12keyKeyMap::ConstructL
// ----------------------------------------------------------------------------
void C12keyKeyMap::ConstructL()
	{
	PRINT(_L("Enter C12keyKeyMap::ConstructL"));

	CPcsKeyMap::ConstructL(HbKeyboardVirtual12Key);

	TInt err(KErrNone);
	QT_TRYCATCH_ERROR(err, GetTextCodecs());
    if (err != KErrNone)
        {
        PRINT1(_L("C12keyKeyMap::ConstructL exception, err=%d"), err);
        User::Leave(err);
        }

	iKoreanKeymap = CKoreanKeyMap::NewL();

	PRINT(_L("End C12keyKeyMap::ConstructL"));
	}
/*
    Sends the datagram at aData  to the service that this socket is connected to.
    Returns the number of bytes sent on success; otherwise return -1;
*/
TInt CLlcpSocketType1::StartWriteDatagram(const TDesC8& aData,TUint8 aPortNum)
    {
    BEGIN
    TInt val = -1;

    if (iConnectionWrapper != NULL && iRemotePort != aPortNum)
        {
        return val;
        }

    if (KErrNone == CreateConnection(aPortNum))
        {
        TInt error = KErrNone;
        QT_TRYCATCH_ERROR(error , iConnectionWrapper->TransferL(aData));

        if (KErrNone == error)
            {
            iCallback.m_writeDatagramRefCount++;
            val =  0;
            }
        }
    END
    return val;
    }