MtpPacket.h revision 335dd2be955607f2632eabc25045857f2cc8b674
1/* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17#ifndef _MTP_PACKET_H 18#define _MTP_PACKET_H 19 20#include "MtpTypes.h" 21 22struct usb_endpoint; 23 24namespace android { 25 26class MtpStringBuffer; 27 28class MtpPacket { 29 30protected: 31 uint8_t* mBuffer; 32 // current size of the buffer 33 int mBufferSize; 34 // number of bytes to add when resizing the buffer 35 int mAllocationIncrement; 36 // size of the data in the packet 37 int mPacketSize; 38 39public: 40 MtpPacket(int bufferSize); 41 virtual ~MtpPacket(); 42 43 // sets packet size to the default container size and sets buffer to zero 44 virtual void reset(); 45 46 void allocate(int length); 47 void dump(); 48 49 uint16_t getContainerCode() const; 50 void setContainerCode(uint16_t code); 51 52 MtpTransactionID getTransactionID() const; 53 void setTransactionID(MtpTransactionID id); 54 55 uint32_t getParameter(int index) const; 56 void setParameter(int index, uint32_t value); 57 58#ifdef MTP_HOST 59 int transfer(struct usb_endpoint *ep, void* buffer, int length); 60#endif 61 62protected: 63 uint16_t getUInt16(int offset) const; 64 uint32_t getUInt32(int offset) const; 65 void putUInt16(int offset, uint16_t value); 66 void putUInt32(int offset, uint32_t value); 67}; 68 69}; // namespace android 70 71#endif // _MTP_PACKET_H 72