1 // RequestDumper.cpp
2
3 #include "RequestDumper.h"
4
5 #include <string.h>
6
7 #include <typeinfo>
8
9 #include <ByteOrder.h>
10
11 #include "DebugSupport.h"
12
13 static const char* kIndentation = " ";
14 static const int kMaxIndentation = 32;
15
16 // constructor
RequestDumper()17 RequestDumper::RequestDumper()
18 : RequestMemberVisitor(),
19 fIndentationLevel(0)
20 {
21 }
22
23 // DumpRequest
24 void
DumpRequest(Request * request)25 RequestDumper::DumpRequest(Request* request)
26 {
27 PRINT("request: %s\n", typeid(*request).name());
28 fIndentationLevel++;
29 request->ShowAround(this);
30 fIndentationLevel--;
31 }
32
33 // Visit
34 void
Visit(RequestMember * member,bool & data)35 RequestDumper::Visit(RequestMember* member, bool& data)
36 {
37 PRINT("%sbool: %s\n", _Indentation(), (data ? "true" : "false"));
38 }
39
40 // Visit
41 void
Visit(RequestMember * member,int8 & data)42 RequestDumper::Visit(RequestMember* member, int8& data)
43 {
44 PRINT("%sint8: %d\n", _Indentation(), (int)data);
45 }
46
47 // Visit
48 void
Visit(RequestMember * member,uint8 & data)49 RequestDumper::Visit(RequestMember* member, uint8& data)
50 {
51 PRINT("%suint8: %d\n", _Indentation(), (int)data);
52 }
53
54 // Visit
55 void
Visit(RequestMember * member,int16 & data)56 RequestDumper::Visit(RequestMember* member, int16& data)
57 {
58 PRINT("%sint16: %d\n", _Indentation(), (int)data);
59 }
60
61 // Visit
62 void
Visit(RequestMember * member,uint16 & data)63 RequestDumper::Visit(RequestMember* member, uint16& data)
64 {
65 PRINT("%suint16: %d\n", _Indentation(), (int)data);
66 }
67
68 // Visit
69 void
Visit(RequestMember * member,int32 & data)70 RequestDumper::Visit(RequestMember* member, int32& data)
71 {
72 PRINT("%sint32: %" B_PRId32 "\n", _Indentation(), data);
73 }
74
75 // Visit
76 void
Visit(RequestMember * member,uint32 & data)77 RequestDumper::Visit(RequestMember* member, uint32& data)
78 {
79 PRINT("%suint32: %" B_PRIu32 "\n", _Indentation(), data);
80 }
81
82 // Visit
83 void
Visit(RequestMember * member,int64 & data)84 RequestDumper::Visit(RequestMember* member, int64& data)
85 {
86 PRINT("%sint64: %" B_PRId64 "\n", _Indentation(), data);
87 }
88
89 // Visit
90 void
Visit(RequestMember * member,uint64 & data)91 RequestDumper::Visit(RequestMember* member, uint64& data)
92 {
93 PRINT("%suint64: %" B_PRIu64 "\n", _Indentation(), data);
94 }
95
96 // Visit
97 void
Visit(RequestMember * member,Data & data)98 RequestDumper::Visit(RequestMember* member, Data& data)
99 {
100 PRINT("%sdata: %p (%" B_PRId32 " bytes)\n", _Indentation(),
101 data.GetData(), data.GetSize());
102 }
103
104 // Visit
105 void
Visit(RequestMember * member,StringData & data)106 RequestDumper::Visit(RequestMember* member, StringData& data)
107 {
108 PRINT("%sstring: \"%s\" (%p, %" B_PRId32 " bytes)\n", _Indentation(),
109 data.GetString(), data.GetString(), data.GetSize());
110 }
111
112 // Visit
113 void
Visit(RequestMember * member,RequestMember & subMember)114 RequestDumper::Visit(RequestMember* member, RequestMember& subMember)
115 {
116 PRINT("%ssubmember:\n", _Indentation());
117
118 fIndentationLevel++;
119 subMember.ShowAround(this);
120 fIndentationLevel--;
121 }
122
123 // Visit
124 void
Visit(RequestMember * member,FlattenableRequestMember & subMember)125 RequestDumper::Visit(RequestMember* member,
126 FlattenableRequestMember& subMember)
127 {
128 PRINT("%sflattenable: %s\n", _Indentation(), typeid(subMember).name());
129 }
130
131 // _Indentation
132 const char*
_Indentation() const133 RequestDumper::_Indentation() const
134 {
135 int indentation = fIndentationLevel * 2;
136 if (indentation >= kMaxIndentation)
137 return kIndentation;
138 return kIndentation + kMaxIndentation - indentation;
139 }
140