natfw/natfwunsaf_protocols/unsaf_transport/src/tnatfwunsafmsgstateheaderstart.cpp
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 2006-2007 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:   
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #include "tnatfwunsafmsgstateheaderstart.h"
       
    22 #include "mnatfwunsafmsgassemblerctx.h"
       
    23 
       
    24 // ----------------------------------------------------------------------------
       
    25 // TNATFWUNSAFMsgStateHeaderStart::DataReceivedL
       
    26 // ----------------------------------------------------------------------------
       
    27 //
       
    28 TBool TNATFWUNSAFMsgStateHeaderStart::DataReceivedL(
       
    29     TPtr8 aData,
       
    30     TUint& aNextLength )
       
    31     {
       
    32     TInt messageLength( iMsgAssembler.MessageLength() );
       
    33     __ASSERT_ALWAYS( messageLength > 0,
       
    34                      User::Leave( KErrNotReady ) );
       
    35 
       
    36     TBool retVal( EFalse );
       
    37 
       
    38     if ( iMsgAssembler.MsgBuffer().Size() > 0 )
       
    39         {
       
    40         // If there's existing data in msg buffer insert the received data
       
    41         // to msg buffer.
       
    42         iMsgAssembler.MsgBuffer().InsertL( iMsgAssembler.MsgBuffer().Size(),
       
    43                                            aData );
       
    44         iMsgAssembler.MsgBuffer().Compress();
       
    45 
       
    46         // delete content of received data.
       
    47         aData.Delete( 0, aData.Length() );
       
    48         TPtr8 bufPtr = iMsgAssembler.MsgBuffer().Ptr( 0 );
       
    49 
       
    50         if ( bufPtr.Length() >= messageLength )
       
    51             {
       
    52             // There's enough data for complete NATFWUNSAF msg
       
    53 
       
    54             HBufC8* newData = HBufC8::NewLC( bufPtr.Length() );
       
    55 
       
    56             // copy the msg buffer data to new data
       
    57             TPtr8 newDataPtr = newData->Des();
       
    58             newDataPtr.Append( bufPtr );
       
    59 
       
    60             // clean the msg buffer
       
    61             iMsgAssembler.MsgBuffer().Reset();
       
    62             iMsgAssembler.MsgBuffer().Compress();
       
    63 
       
    64             iMsgAssembler.ChangeState(
       
    65                 TNATFWUNSAFMsgStateBase::EMsgHeaderEnd );
       
    66             retVal =
       
    67                 iMsgAssembler.CurrentState().DataReceivedL( newDataPtr,
       
    68                                                             aNextLength );
       
    69             CleanupStack::PopAndDestroy( newData );
       
    70             }
       
    71         }
       
    72     else if ( aData.Length() >= messageLength )
       
    73         {
       
    74         // There's enough data for complete NATFWUNSAF msg
       
    75 
       
    76         iMsgAssembler.ChangeState( TNATFWUNSAFMsgStateBase::EMsgHeaderEnd );
       
    77         retVal =
       
    78             iMsgAssembler.CurrentState().DataReceivedL( aData, aNextLength );
       
    79         }
       
    80     else
       
    81         {
       
    82         // There's not enough data for complete UNSAF message,
       
    83         // wait for more incoming data
       
    84         iMsgAssembler.MsgBuffer().InsertL( iMsgAssembler.MsgBuffer().Size(),
       
    85                                            aData );
       
    86 
       
    87         iMsgAssembler.MsgBuffer().Compress();
       
    88 
       
    89         aNextLength =
       
    90             messageLength - iMsgAssembler.MsgBuffer().Ptr( 0 ).Length();
       
    91         }
       
    92 
       
    93     return retVal;
       
    94     }
       
    95 
       
    96 // End of File
       
    97