1 /* 2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef _DEBUG_EVENT_STREAM_H 6 #define _DEBUG_EVENT_STREAM_H 7 8 #include <SupportDefs.h> 9 10 11 class BDataIO; 12 13 14 struct debug_event_stream_header { 15 char signature[32]; 16 uint32 version; 17 uint32 flags; 18 uint32 event_mask; 19 uint32 reserved; 20 }; 21 22 23 // signature and version 24 #define B_DEBUG_EVENT_STREAM_SIGNATURE "Haiku debug events" 25 #define B_DEBUG_EVENT_STREAM_VERSION 1 26 27 28 // flags 29 enum { 30 B_DEBUG_EVENT_STREAM_FLAG_HOST_ENDIAN = 0x00000001, 31 B_DEBUG_EVENT_STREAM_FLAG_SWAPPED_ENDIAN = 0x01000000, 32 33 B_DEBUG_EVENT_STREAM_FLAG_ZIPPED = 0x00000002 34 }; 35 36 37 class BDebugEventInputStream { 38 public: 39 BDebugEventInputStream(); 40 ~BDebugEventInputStream(); 41 42 status_t SetTo(BDataIO* stream); 43 status_t SetTo(const void* data, size_t size, 44 bool takeOverOwnership); 45 void Unset(); 46 47 status_t Seek(off_t streamOffset); 48 49 ssize_t ReadNextEvent(uint32* _event, uint32* _cpu, 50 const void** _buffer, 51 off_t* _streamOffset = NULL); 52 53 private: 54 status_t _Init(); 55 ssize_t _Read(void* buffer, size_t size); 56 status_t _GetData(size_t size); 57 58 private: 59 BDataIO* fStream; 60 uint32 fFlags; 61 uint32 fEventMask; 62 uint8* fBuffer; 63 size_t fBufferCapacity; 64 size_t fBufferSize; 65 size_t fBufferPosition; 66 off_t fStreamPosition; 67 bool fOwnsBuffer; 68 }; 69 70 71 class BDebugEventOutputStream { 72 public: 73 BDebugEventOutputStream(); 74 ~BDebugEventOutputStream(); 75 76 status_t SetTo(BDataIO* stream, uint32 flags, 77 uint32 eventMask); 78 void Unset(); 79 80 status_t Write(const void* buffer, size_t size); 81 status_t Flush(); 82 83 private: 84 BDataIO* fStream; 85 uint32 fFlags; 86 }; 87 88 89 #endif // _DEBUG_EVENT_STREAM_H 90