//*****************************************************************************
//
// Microsoft Windows Media
// Copyright ( C) Microsoft Corporation. All rights reserved.
//
// FileName:            rostream.cpp
//
// Abstract:            Implementation of CROStream, which is an IStream-
//						derived data sourcing class. The IWMSyncReader 
//						interface is capable of sourcing through a custom object 
//						supporting the IStream interface. The CROStream class is 
//						used in the sample to demonstrate this capability.
//
//*****************************************************************************
#include <windows.h>
#include "kpifile_stream.h"

//////////////////////////////////////////////////////////////////////////////
KbKpiFileStream::KbKpiFileStream(IKpiFile *pFile)
{
    m_pFile = pFile;
    pFile->AddRef();
}
//////////////////////////////////////////////////////////////////////////////
KbKpiFileStream::~KbKpiFileStream(void)
{
    m_pFile->Release();
}
//////////////////////////////////////////////////////////////////////////////
HRESULT KbKpiFileStream::Read( void *pv, ULONG cb, ULONG *pcbRead )
{
    *pcbRead = m_pFile->Read(pv, cb);
    return S_OK;
}
//////////////////////////////////////////////////////////////////////////////
HRESULT KbKpiFileStream::Seek(LARGE_INTEGER dlibMove,
                        DWORD dwOrigin,
                        ULARGE_INTEGER *plibNewPosition )
{
    UINT64 qwPos = m_pFile->Seek(dlibMove.QuadPart, dwOrigin);
    if(plibNewPosition){
        plibNewPosition->QuadPart = qwPos;
    }
    if(qwPos == KPI_FILE_EOF){
        return S_FALSE;
    }
    return S_OK;
}
//////////////////////////////////////////////////////////////////////////////
HRESULT KbKpiFileStream::Stat(STATSTG *pstatstg, DWORD grfStatFlag )
{
    if( ( NULL == pstatstg ) || ( STATFLAG_NONAME != grfStatFlag ) )
    {
        return( E_INVALIDARG );
    }
    ZeroMemory(pstatstg, sizeof(STATSTG));
    pstatstg->type = STGTY_STREAM;
    pstatstg->cbSize.QuadPart = m_pFile->GetSize();
    return S_OK;
}

