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