perfsrv/memspy/Driver/User/Source/MemSpyDriverStreamReaderImp.cpp
author hgs
Mon, 20 Sep 2010 12:20:18 +0300
changeset 52 c2f44e33b468
parent 51 98307c651589
permissions -rw-r--r--
201037
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
51
hgs
parents:
diff changeset
     1
/*
hgs
parents:
diff changeset
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
hgs
parents:
diff changeset
     3
* All rights reserved.
hgs
parents:
diff changeset
     4
* This component and the accompanying materials are made available
hgs
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
hgs
parents:
diff changeset
     6
* which accompanies this distribution, and is available
hgs
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
hgs
parents:
diff changeset
     8
*
hgs
parents:
diff changeset
     9
* Initial Contributors:
hgs
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
hgs
parents:
diff changeset
    11
*
hgs
parents:
diff changeset
    12
* Contributors:
hgs
parents:
diff changeset
    13
*
hgs
parents:
diff changeset
    14
* Description:
hgs
parents:
diff changeset
    15
*
hgs
parents:
diff changeset
    16
*/
hgs
parents:
diff changeset
    17
hgs
parents:
diff changeset
    18
#include "MemSpyDriverStreamReaderImp.h"
hgs
parents:
diff changeset
    19
hgs
parents:
diff changeset
    20
hgs
parents:
diff changeset
    21
hgs
parents:
diff changeset
    22
hgs
parents:
diff changeset
    23
CMemSpyMemStreamReader::CMemSpyMemStreamReader( const TDesC8& aData )
hgs
parents:
diff changeset
    24
    {
hgs
parents:
diff changeset
    25
    iCurrent = aData.Ptr();
hgs
parents:
diff changeset
    26
    iMax = iCurrent + aData.Length();
hgs
parents:
diff changeset
    27
    }
hgs
parents:
diff changeset
    28
hgs
parents:
diff changeset
    29
hgs
parents:
diff changeset
    30
void CMemSpyMemStreamReader::ConstructL()
hgs
parents:
diff changeset
    31
    {
hgs
parents:
diff changeset
    32
    }
hgs
parents:
diff changeset
    33
hgs
parents:
diff changeset
    34
hgs
parents:
diff changeset
    35
TInt32 CMemSpyMemStreamReader::ReadInt32L()
hgs
parents:
diff changeset
    36
    {
hgs
parents:
diff changeset
    37
    TInt32 ret = 0;
hgs
parents:
diff changeset
    38
    //
hgs
parents:
diff changeset
    39
    const TInt size = sizeof( TInt32 );
hgs
parents:
diff changeset
    40
    IsAvailableL( size );
hgs
parents:
diff changeset
    41
    Mem::Copy( (TAny*) &ret, iCurrent, size );
hgs
parents:
diff changeset
    42
    IncrementPos( size );
hgs
parents:
diff changeset
    43
    //
hgs
parents:
diff changeset
    44
    return ret;
hgs
parents:
diff changeset
    45
    }
hgs
parents:
diff changeset
    46
hgs
parents:
diff changeset
    47
hgs
parents:
diff changeset
    48
TUint32 CMemSpyMemStreamReader::ReadUint32L()
hgs
parents:
diff changeset
    49
    {
hgs
parents:
diff changeset
    50
    TUint32 ret = 0;
hgs
parents:
diff changeset
    51
    //
hgs
parents:
diff changeset
    52
    const TInt size = sizeof( TUint32 );
hgs
parents:
diff changeset
    53
    IsAvailableL( size );
hgs
parents:
diff changeset
    54
    Mem::Copy( (TAny*) &ret, iCurrent, size );
hgs
parents:
diff changeset
    55
    IncrementPos( size );
hgs
parents:
diff changeset
    56
    //
hgs
parents:
diff changeset
    57
    return ret;
hgs
parents:
diff changeset
    58
    }
hgs
parents:
diff changeset
    59
hgs
parents:
diff changeset
    60
hgs
parents:
diff changeset
    61
void CMemSpyMemStreamReader::ReadL( TDes8& aDes )
hgs
parents:
diff changeset
    62
    {
hgs
parents:
diff changeset
    63
    const TInt length = ReadInt32L();
hgs
parents:
diff changeset
    64
hgs
parents:
diff changeset
    65
    // Need to check the remaining text is actually present...
hgs
parents:
diff changeset
    66
    IsAvailableL( length );
hgs
parents:
diff changeset
    67
hgs
parents:
diff changeset
    68
    // Now read into client descriptor
hgs
parents:
diff changeset
    69
    aDes.SetLength( length );
hgs
parents:
diff changeset
    70
    if  ( length > 0 ) 
hgs
parents:
diff changeset
    71
        {
hgs
parents:
diff changeset
    72
        TUint8* dest = const_cast< TUint8* >( aDes.Ptr() );
hgs
parents:
diff changeset
    73
        Mem::Copy( dest, iCurrent, length );
hgs
parents:
diff changeset
    74
        }
hgs
parents:
diff changeset
    75
    //
hgs
parents:
diff changeset
    76
    IncrementPos( length );
hgs
parents:
diff changeset
    77
    }
hgs
parents:
diff changeset
    78
hgs
parents:
diff changeset
    79
hgs
parents:
diff changeset
    80
void CMemSpyMemStreamReader::ReadL( TDes16& aDes )
hgs
parents:
diff changeset
    81
    {
hgs
parents:
diff changeset
    82
    // The kernel driver only ever writes narrow descriptors.
hgs
parents:
diff changeset
    83
    // However, we can expand them to be UCS2
hgs
parents:
diff changeset
    84
    const TInt length = ReadInt32L();
hgs
parents:
diff changeset
    85
hgs
parents:
diff changeset
    86
    // Need to check the remaining text is actually present...
hgs
parents:
diff changeset
    87
    IsAvailableL( length );
hgs
parents:
diff changeset
    88
hgs
parents:
diff changeset
    89
    // Set final length in descriptor
hgs
parents:
diff changeset
    90
    aDes.SetLength( length );
hgs
parents:
diff changeset
    91
hgs
parents:
diff changeset
    92
    // Read each char
hgs
parents:
diff changeset
    93
    TUint16* dest = const_cast< TUint16* >( aDes.Ptr() );
hgs
parents:
diff changeset
    94
    for( TInt i=0; i<length; i++ )
hgs
parents:
diff changeset
    95
        {
hgs
parents:
diff changeset
    96
        *dest++ = *iCurrent++;
hgs
parents:
diff changeset
    97
        }
hgs
parents:
diff changeset
    98
    }
hgs
parents:
diff changeset
    99
hgs
parents:
diff changeset
   100
hgs
parents:
diff changeset
   101
void CMemSpyMemStreamReader::IsAvailableL( TInt aRequired ) const
hgs
parents:
diff changeset
   102
    {
hgs
parents:
diff changeset
   103
    const TUint8* endPos = iCurrent + aRequired;
hgs
parents:
diff changeset
   104
    if  ( endPos > iMax )
hgs
parents:
diff changeset
   105
        {
hgs
parents:
diff changeset
   106
        User::Leave( KErrOverflow );
hgs
parents:
diff changeset
   107
        }
hgs
parents:
diff changeset
   108
    }
hgs
parents:
diff changeset
   109
hgs
parents:
diff changeset
   110
hgs
parents:
diff changeset
   111
void CMemSpyMemStreamReader::IncrementPos( TInt aAmount )
hgs
parents:
diff changeset
   112
    {
hgs
parents:
diff changeset
   113
    iCurrent += aAmount;
hgs
parents:
diff changeset
   114
    }
hgs
parents:
diff changeset
   115
hgs
parents:
diff changeset
   116
hgs
parents:
diff changeset
   117
hgs
parents:
diff changeset
   118