added TrGetSequentialStream and underlying code for a sequential stream that

outputs to trace output, also added a bunch of STG_ codes so that they're there
This commit is contained in:
Eric J. Bowersox
2013-06-01 00:17:52 -06:00
parent 5a7bc73aed
commit 2cca2531c8
5 changed files with 161 additions and 21 deletions

View File

@@ -36,6 +36,7 @@
#include <comrogue/objectbase.h>
#include <comrogue/allocator.h>
#include <comrogue/stdobj.h>
#include <comrogue/stream.h>
#include <comrogue/objhelp.h>
/*--------------------------------------------
@@ -93,6 +94,7 @@ HRESULT ObjHlpStandardQueryInterface_ ## iface (IUnknown *pThis, REFIID riid, PP
}
MAKE_BASE_QI(IMalloc)
MAKE_BASE_QI(ISequentialStream)
/*
* "Dummy" version of AddRef/Release used for static objects.
@@ -121,3 +123,17 @@ void ObjHlpDoNothingReturnVoid(IUnknown *pThis)
{
/* do nothing */
}
/*
* Method that does nothing and returns E_NOTIMPL.
*
* Parameters:
* - pThis = Base interface pointer.
*
* Returns:
* E_NOTIMPL.
*/
HRESULT ObjHlpNotImplemented(IUnknown *pThis)
{
return E_NOTIMPL;
}

View File

@@ -32,6 +32,8 @@
#include <stdarg.h>
#include <comrogue/types.h>
#include <comrogue/str.h>
#include <comrogue/stream.h>
#include <comrogue/objhelp.h>
#include <comrogue/internals/seg.h>
#include <comrogue/internals/llio.h>
#include <comrogue/internals/auxdev.h>
@@ -258,6 +260,65 @@ void TrAssertFailed(PCSTR pszFile, INT32 nLine)
TrPrintf8(szMessage, pszFile, nLine);
}
/*
* Writes a buffer full of data (assumed 8-bit) to the trace output.
*
* Parameters:
* - pThis = ISequentialStream output pointer (ignored).
* - pv = Pointer to buffer to be written.
* - cb = Number of bytes to be written.
* - pcbWritten = If non-NULL, points to variable that will receive the number of bytes actually written.
*
* Returns:
* Standard HRESULT success/failure indicator.
*/
static HRESULT traceStreamWrite(ISequentialStream *pThis, PCVOID pv, UINT32 cb, UINT32 *pcbWritten)
{
register PCHAR p1, p2; /* buffer pointers */
if (!pv)
return STG_E_INVALIDPOINTER;
p1 = (PCHAR)pv;
p2 = p1 + cb;
while (p1 < p2)
TrWriteChar8(*p1++);
if (pcbWritten)
*pcbWritten = cb;
return S_OK;
}
/* VTable for an implementation of ISequentialStream that outputs to the trace output. */
static const SEG_RODATA struct ISequentialStreamVTable vtblTraceStream =
{
.QueryInterface = ObjHlpStandardQueryInterface_ISequentialStream,
.AddRef = ObjHlpStaticAddRefRelease,
.Release = ObjHlpStaticAddRefRelease,
.Read = (HRESULT (*)(ISequentialStream*, PVOID, UINT32, UINT32*))ObjHlpNotImplemented,
.Write = traceStreamWrite
};
/* Implementation of ISequentialStream that outputs to the trace output. */
static const SEG_RODATA ISequentialStream traceStream = { &vtblTraceStream };
/*
* Stores a pointer to the ISequentialStream implementation that outputs to the trace output. When
* done with the pointer, be sure to call Release() on it.
*
* Parameters:
* - ppstm = Pointer to the variable to receive the ISequentialStream pointer.
*
* Returns:
* Standard HRESULT success/failure indicator.
*/
HRESULT TrGetSequentialStream(ISequentialStream **ppstm)
{
if (!ppstm)
return E_POINTER;
*ppstm = (ISequentialStream *)(&traceStream);
IUnknown_AddRef(*ppstm);
return S_OK;
}
/*
* Puts the CPU into a loop where it blinks the green ACTIVITY light forever.
*