* Made TraceEntryIterator available in the kernel.

* Fixed TraceEntryIterator::Current(): If fEntry was NULL, it would
  return 0x4.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26955 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold 2008-08-12 21:16:15 +00:00
parent b31df46fd2
commit ef7102fa29
2 changed files with 121 additions and 98 deletions

View File

@ -63,6 +63,7 @@ class TraceOutput {
bigtime_t fLastEntryTime;
};
class TraceEntry {
public:
TraceEntry();
@ -89,6 +90,7 @@ class TraceEntry {
}
};
class AbstractTraceEntry : public TraceEntry {
public:
AbstractTraceEntry();
@ -108,6 +110,7 @@ class AbstractTraceEntry : public TraceEntry {
bigtime_t fTime;
};
class LazyTraceOutput : public TraceOutput {
public:
LazyTraceOutput(char* buffer, size_t bufferSize, uint32 flags)
@ -126,6 +129,7 @@ public:
}
};
class TraceFilter {
public:
virtual ~TraceFilter();
@ -145,11 +149,52 @@ public:
};
};
class WrapperTraceFilter : public TraceFilter {
public:
virtual void Init(TraceFilter* filter, int direction, bool continued) = 0;
};
class TraceEntryIterator {
public:
TraceEntryIterator()
:
fEntry(NULL),
fIndex(0)
{
}
void Reset()
{
fEntry = NULL;
fIndex = 0;
}
int32 Index() const
{
return fIndex;
}
TraceEntry* Current() const
{
return fEntry != NULL ? TraceEntry::FromTraceEntry(fEntry) : NULL;
}
TraceEntry* Next();
TraceEntry* Previous();
TraceEntry* MoveTo(int32 index);
private:
trace_entry* _NextNonBufferEntry(trace_entry* entry);
trace_entry* _PreviousNonBufferEntry(trace_entry* entry);
private:
trace_entry* fEntry;
int32 fIndex;
};
#endif // __cplusplus
#ifdef __cplusplus

View File

@ -697,119 +697,97 @@ TraceFilterParser TraceFilterParser::sParser;
#if ENABLE_TRACING
class TraceEntryIterator {
public:
TraceEntryIterator()
:
fEntry(NULL),
fIndex(0)
{
TraceEntry*
TraceEntryIterator::Next()
{
if (fIndex == 0) {
fEntry = _NextNonBufferEntry(sFirstEntry);
fIndex = 1;
} else if (fEntry != NULL) {
fEntry = _NextNonBufferEntry(next_entry(fEntry));
fIndex++;
}
void Reset()
{
return Current();
}
TraceEntry*
TraceEntryIterator::Previous()
{
if (fIndex == (int32)sEntries + 1)
fEntry = sAfterLastEntry;
if (fEntry != NULL) {
fEntry = _PreviousNonBufferEntry(previous_entry(fEntry));
fIndex--;
}
return Current();
}
TraceEntry*
TraceEntryIterator::MoveTo(int32 index)
{
if (index == fIndex)
return Current();
if (index <= 0 || index > (int32)sEntries) {
fIndex = (index <= 0 ? 0 : sEntries + 1);
fEntry = NULL;
return NULL;
}
// get the shortest iteration path
int32 distance = index - fIndex;
int32 direction = distance < 0 ? -1 : 1;
distance *= direction;
if (index < distance) {
distance = index;
direction = 1;
fEntry = NULL;
fIndex = 0;
}
int32 Index() const
{
return fIndex;
if ((int32)sEntries + 1 - fIndex < distance) {
distance = sEntries + 1 - fIndex;
direction = -1;
fEntry = NULL;
fIndex = sEntries + 1;
}
TraceEntry* Current() const
{
return TraceEntry::FromTraceEntry(fEntry);
// iterate to the index
if (direction < 0) {
while (fIndex != index)
Previous();
} else {
while (fIndex != index)
Next();
}
TraceEntry* Next()
{
if (fIndex == 0) {
fEntry = _NextNonBufferEntry(sFirstEntry);
fIndex = 1;
} else if (fEntry != NULL) {
fEntry = _NextNonBufferEntry(next_entry(fEntry));
fIndex++;
}
return Current();
}
return Current();
}
TraceEntry* Previous()
{
if (fIndex == (int32)sEntries + 1)
fEntry = sAfterLastEntry;
trace_entry*
TraceEntryIterator::_NextNonBufferEntry(trace_entry* entry)
{
while (entry != NULL && (entry->flags & BUFFER_ENTRY) != 0)
entry = next_entry(entry);
if (fEntry != NULL) {
fEntry = _PreviousNonBufferEntry(previous_entry(fEntry));
fIndex--;
}
return entry;
}
return Current();
}
TraceEntry* MoveTo(int32 index)
{
if (index == fIndex)
return Current();
trace_entry*
TraceEntryIterator::_PreviousNonBufferEntry(trace_entry* entry)
{
while (entry != NULL && (entry->flags & BUFFER_ENTRY) != 0)
entry = previous_entry(entry);
if (index <= 0 || index > (int32)sEntries) {
fIndex = (index <= 0 ? 0 : sEntries + 1);
fEntry = NULL;
return NULL;
}
// get the shortest iteration path
int32 distance = index - fIndex;
int32 direction = distance < 0 ? -1 : 1;
distance *= direction;
if (index < distance) {
distance = index;
direction = 1;
fEntry = NULL;
fIndex = 0;
}
if ((int32)sEntries + 1 - fIndex < distance) {
distance = sEntries + 1 - fIndex;
direction = -1;
fEntry = NULL;
fIndex = sEntries + 1;
}
// iterate to the index
if (direction < 0) {
while (fIndex != index)
Previous();
} else {
while (fIndex != index)
Next();
}
return Current();
}
private:
trace_entry* _NextNonBufferEntry(trace_entry* entry)
{
while (entry != NULL && (entry->flags & BUFFER_ENTRY) != 0)
entry = next_entry(entry);
return entry;
}
trace_entry* _PreviousNonBufferEntry(trace_entry* entry)
{
while (entry != NULL && (entry->flags & BUFFER_ENTRY) != 0)
entry = previous_entry(entry);
return entry;
}
private:
trace_entry* fEntry;
int32 fIndex;
};
return entry;
}
int