xref: /haiku/src/add-ons/kernel/file_systems/netfs/server/RequestBufferReplacer.cpp (revision 1deede7388b04dbeec5af85cae7164735ea9e70d)
1 // RequestBufferReplacer.cpp
2 
3 #include <new>
4 
5 #include <stdlib.h>
6 #include <string.h>
7 
8 #include "RequestBufferReplacer.h"
9 
10 // constructor
11 RequestBufferReplacer::RequestBufferReplacer()
12 	: fBuffer(NULL),
13 	  fBufferSize(0)
14 {
15 }
16 
17 // destructor
18 RequestBufferReplacer::~RequestBufferReplacer()
19 {
20 }
21 
22 // ReplaceBuffer
23 status_t
24 RequestBufferReplacer::ReplaceBuffer(Request* request)
25 {
26 	if (!request)
27 		return B_BAD_VALUE;
28 
29 	// get the size we need to allocate
30 	fBuffer = NULL;
31 	fBufferSize = 0;
32 	request->ShowAround(this);
33 	if (fBufferSize == 0)
34 		return B_OK;
35 
36 	// allocate the buffer
37 	RequestBuffer* requestBuffer = RequestBuffer::Create(fBufferSize);
38 	if (!requestBuffer)
39 		return B_NO_MEMORY;
40 	fBuffer = (char*)requestBuffer->GetData();
41 
42 	// relocate the data
43 	request->ShowAround(this);
44 
45 	// attach the new buffer
46 	request->AttachBuffer(requestBuffer);
47 
48 	return B_OK;
49 }
50 
51 // Visit
52 void
53 RequestBufferReplacer::Visit(RequestMember* member, bool& data)
54 {
55 }
56 
57 // Visit
58 void
59 RequestBufferReplacer::Visit(RequestMember* member, int8& data)
60 {
61 }
62 
63 // Visit
64 void
65 RequestBufferReplacer::Visit(RequestMember* member, uint8& data)
66 {
67 }
68 
69 // Visit
70 void
71 RequestBufferReplacer::Visit(RequestMember* member, int16& data)
72 {
73 }
74 
75 // Visit
76 void
77 RequestBufferReplacer::Visit(RequestMember* member, uint16& data)
78 {
79 }
80 
81 // Visit
82 void
83 RequestBufferReplacer::Visit(RequestMember* member, int32& data)
84 {
85 }
86 
87 // Visit
88 void
89 RequestBufferReplacer::Visit(RequestMember* member, uint32& data)
90 {
91 }
92 
93 // Visit
94 void
95 RequestBufferReplacer::Visit(RequestMember* member, int64& data)
96 {
97 }
98 
99 // Visit
100 void
101 RequestBufferReplacer::Visit(RequestMember* member, uint64& data)
102 {
103 }
104 
105 // Visit
106 void
107 RequestBufferReplacer::Visit(RequestMember* member, Data& data)
108 {
109 	int32 size = data.GetSize();
110 	if (fBuffer) {
111 		if (size > 0) {
112 			memcpy(fBuffer, data.GetData(), size);
113 			data.SetTo(fBuffer, size);
114 			fBuffer += size;
115 		}
116 	} else
117 		fBufferSize += size;
118 }
119 
120 // Visit
121 void
122 RequestBufferReplacer::Visit(RequestMember* member, StringData& data)
123 {
124 	Visit(member, static_cast<Data&>(data));
125 }
126 
127 // Visit
128 void
129 RequestBufferReplacer::Visit(RequestMember* member, RequestMember& subMember)
130 {
131 	subMember.ShowAround(this);
132 }
133 
134 // Visit
135 void
136 RequestBufferReplacer::Visit(RequestMember* member,
137 	FlattenableRequestMember& subMember)
138 {
139 	subMember.ShowAround(this);
140 }
141 
142