Made BDebugEventInputStream::ReadNextEvent() nicer to use.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30260 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold 2009-04-19 11:17:24 +00:00
parent 98b956380c
commit 36e787103f
4 changed files with 51 additions and 30 deletions

View File

@ -7,8 +7,6 @@
#include <SupportDefs.h>
#include <system_profiler_defs.h>
class BDataIO;
@ -43,9 +41,8 @@ public:
status_t SetTo(BDataIO* stream);
void Unset();
ssize_t ReadNextEvent(
const system_profiler_event_header**
_header);
ssize_t ReadNextEvent(uint32* _event, uint32* _cpu,
const void** _buffer);
private:
ssize_t _Read(void* buffer, size_t size);

View File

@ -134,15 +134,19 @@ MainModelLoader::_Loader()
try {
while (true) {
// get next event
const system_profiler_event_header* header;
ssize_t bufferSize = fInput->ReadNextEvent(&header);
if (bufferSize < 0) {
success = bufferSize == B_ENTRY_NOT_FOUND;
uint32 event;
uint32 cpu;
const void* buffer;
ssize_t bufferSize = fInput->ReadNextEvent(&event, &cpu, &buffer);
if (bufferSize < 0)
break;
if (buffer == NULL) {
success = true;
break;
}
// process the event
status_t error = _ProcessEvent(header, bufferSize);
status_t error = _ProcessEvent(event, cpu, buffer, bufferSize);
if (error != B_OK)
break;
@ -178,7 +182,7 @@ MainModelLoader::_Loader()
status_t
MainModelLoader::_ProcessEvent(const system_profiler_event_header* header,
MainModelLoader::_ProcessEvent(uint32 event, uint32 cpu, const void* buffer,
size_t size)
{
// TODO: Implement!

View File

@ -29,9 +29,8 @@ public:
private:
static status_t _LoaderEntry(void* data);
status_t _Loader();
status_t _ProcessEvent(
const system_profiler_event_header* header,
size_t size);
status_t _ProcessEvent(uint32 event, uint32 cpu,
const void* buffer, size_t size);
private:
BLocker fLock;

View File

@ -10,6 +10,8 @@
#include <DataIO.h>
#include <system_profiler_defs.h>
#define INPUT_BUFFER_SIZE (128 * 1024)
@ -98,39 +100,58 @@ BDebugEventInputStream::Unset()
}
/*! \brief Returns the next event in the stream.
At the end of the stream \c 0 is returned and \c *_buffer is set to \c NULL.
For events that don't have data associated with them, \c *_buffer will still
be non-NULL, even if dereferencing that address is not allowed.
\param _event Pointer to a pre-allocated location where the event ID shall
be stored.
\param _cpu Pointer to a pre-allocated location where the CPU index shall
be stored.
\param _buffer Pointer to a pre-allocated location where the pointer to the
event data shall be stored.
\return A negative error code in case an error occurred while trying to read
the info, the size of the data associated with the event otherwise.
*/
ssize_t
BDebugEventInputStream::ReadNextEvent(
const system_profiler_event_header** _header)
BDebugEventInputStream::ReadNextEvent(uint32* _event, uint32* _cpu,
const void** _buffer)
{
// get the next header
status_t error = _GetData(sizeof(system_profiler_event_header));
if (error != B_OK) {
if (error == B_BAD_DATA && fBufferSize == 0)
return B_ENTRY_NOT_FOUND;
if (error == B_BAD_DATA && fBufferSize == 0) {
*_buffer = NULL;
return 0;
}
return error;
}
system_profiler_event_header* header
= (system_profiler_event_header*)(fBuffer + fBufferPosition);
system_profiler_event_header header
= *(system_profiler_event_header*)(fBuffer + fBufferPosition);
// skip the header in the buffer
fBufferSize -= sizeof(system_profiler_event_header);
fBufferPosition += sizeof(system_profiler_event_header);
// get the data
size_t size = header->size;
size_t totalSize = sizeof(system_profiler_event_header) + size;
if (header->size > 0) {
error = _GetData(totalSize);
if (header.size > 0) {
error = _GetData(header.size);
if (error != B_OK)
return error;
}
// header might have moved when getting the data
header = (system_profiler_event_header*)(fBuffer + fBufferPosition);
*_event = header.event;
*_cpu = header.cpu;
*_buffer = fBuffer + fBufferPosition;
// skip the event in the buffer
fBufferSize -= totalSize;
fBufferPosition += totalSize;
fBufferSize -= header.size;
fBufferPosition += header.size;
*_header = header;
return size;
return header.size;
}