Mike Lockwood | 56118b5 | 2010-05-11 17:16:59 -0400 | [diff] [blame] | 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 | |
Mike Lockwood | 5bae7f6 | 2010-05-19 10:33:39 -0400 | [diff] [blame] | 20 | #include "MtpTypes.h" |
Mike Lockwood | 56118b5 | 2010-05-11 17:16:59 -0400 | [diff] [blame] | 21 | |
Mike Lockwood | 215b682 | 2011-01-04 14:48:57 -0500 | [diff] [blame] | 22 | struct usb_request; |
Mike Lockwood | 8d3257a | 2010-05-14 10:10:36 -0400 | [diff] [blame] | 23 | |
| 24 | namespace android { |
| 25 | |
Mike Lockwood | 56118b5 | 2010-05-11 17:16:59 -0400 | [diff] [blame] | 26 | class MtpPacket { |
| 27 | |
| 28 | protected: |
| 29 | uint8_t* mBuffer; |
| 30 | // current size of the buffer |
| 31 | int mBufferSize; |
| 32 | // number of bytes to add when resizing the buffer |
| 33 | int mAllocationIncrement; |
| 34 | // size of the data in the packet |
| 35 | int mPacketSize; |
| 36 | |
| 37 | public: |
| 38 | MtpPacket(int bufferSize); |
| 39 | virtual ~MtpPacket(); |
| 40 | |
| 41 | // sets packet size to the default container size and sets buffer to zero |
| 42 | virtual void reset(); |
| 43 | |
| 44 | void allocate(int length); |
| 45 | void dump(); |
Mike Lockwood | bfd1d72 | 2010-12-09 18:34:18 -0800 | [diff] [blame] | 46 | void copyFrom(const MtpPacket& src); |
Mike Lockwood | 56118b5 | 2010-05-11 17:16:59 -0400 | [diff] [blame] | 47 | |
| 48 | uint16_t getContainerCode() const; |
| 49 | void setContainerCode(uint16_t code); |
| 50 | |
Mike Lockwood | bfd1d72 | 2010-12-09 18:34:18 -0800 | [diff] [blame] | 51 | uint16_t getContainerType() const; |
| 52 | |
Mike Lockwood | 56118b5 | 2010-05-11 17:16:59 -0400 | [diff] [blame] | 53 | MtpTransactionID getTransactionID() const; |
| 54 | void setTransactionID(MtpTransactionID id); |
| 55 | |
| 56 | uint32_t getParameter(int index) const; |
| 57 | void setParameter(int index, uint32_t value); |
| 58 | |
| 59 | #ifdef MTP_HOST |
Mike Lockwood | 215b682 | 2011-01-04 14:48:57 -0500 | [diff] [blame] | 60 | int transfer(struct usb_request* request); |
Mike Lockwood | 56118b5 | 2010-05-11 17:16:59 -0400 | [diff] [blame] | 61 | #endif |
| 62 | |
| 63 | protected: |
| 64 | uint16_t getUInt16(int offset) const; |
| 65 | uint32_t getUInt32(int offset) const; |
| 66 | void putUInt16(int offset, uint16_t value); |
| 67 | void putUInt32(int offset, uint32_t value); |
| 68 | }; |
| 69 | |
Mike Lockwood | 8d3257a | 2010-05-14 10:10:36 -0400 | [diff] [blame] | 70 | }; // namespace android |
| 71 | |
Mike Lockwood | 56118b5 | 2010-05-11 17:16:59 -0400 | [diff] [blame] | 72 | #endif // _MTP_PACKET_H |