1 // Request.cpp 2 3 #include "Request.h" 4 5 #include <new> 6 7 #include <stdlib.h> 8 9 #include "DebugSupport.h" 10 #include "RequestFlattener.h" 11 #include "RequestUnflattener.h" 12 13 // RequestMember 14 15 // constructor 16 RequestMember::RequestMember() 17 { 18 } 19 20 // destructor 21 RequestMember::~RequestMember() 22 { 23 } 24 25 26 // #pragma mark - 27 28 // FlattenableRequestMember 29 30 // constructor 31 FlattenableRequestMember::FlattenableRequestMember() 32 { 33 } 34 35 // destructor 36 FlattenableRequestMember::~FlattenableRequestMember() 37 { 38 } 39 40 41 // #pragma mark - 42 43 // Create 44 RequestBuffer* 45 RequestBuffer::Create(uint32 dataSize) 46 { 47 void* buffer = malloc(sizeof(RequestBuffer) + dataSize); 48 if (!buffer) 49 return NULL; 50 51 return new(buffer) RequestBuffer; 52 } 53 54 // Delete 55 void 56 RequestBuffer::Delete(RequestBuffer* buffer) 57 { 58 if (buffer) { 59 buffer->~RequestBuffer(); 60 free(buffer); 61 } 62 } 63 64 // GetData 65 void* 66 RequestBuffer::GetData() 67 { 68 return ((char*)this + sizeof(RequestBuffer)); 69 } 70 71 // GetData 72 const void* 73 RequestBuffer::GetData() const 74 { 75 return ((char*)this + sizeof(RequestBuffer)); 76 } 77 78 79 // #pragma mark - 80 81 // Request 82 83 // constructor 84 Request::Request(uint32 type) 85 : FlattenableRequestMember(), 86 fType(type), 87 fBuffers() 88 { 89 } 90 91 // destructor 92 Request::~Request() 93 { 94 while (RequestBuffer* buffer = fBuffers.GetFirst()) { 95 fBuffers.Remove(buffer); 96 RequestBuffer::Delete(buffer); 97 } 98 } 99 100 // GetType 101 uint32 102 Request::GetType() const 103 { 104 return fType; 105 } 106 107 // AttachBuffer 108 void 109 Request::AttachBuffer(RequestBuffer* buffer) 110 { 111 if (!buffer) 112 return; 113 114 fBuffers.Insert(buffer); 115 116 } 117 118 // Flatten 119 status_t 120 Request::Flatten(RequestFlattener* flattener) 121 { 122 ShowAround(flattener); 123 return B_OK; 124 } 125 126 // Unflatten 127 status_t 128 Request::Unflatten(RequestUnflattener* unflattener) 129 { 130 ShowAround(unflattener); 131 return B_OK; 132 } 133 134 135 // #pragma mark - 136 137 // RequestMemberVisitor 138 139 // constructor 140 RequestMemberVisitor::RequestMemberVisitor() 141 { 142 } 143 144 // destructor 145 RequestMemberVisitor::~RequestMemberVisitor() 146 { 147 } 148 149