blob: 6632c6e04322482a57273b7dc1f5ae9e5f70a0ea [file] [log] [blame]
Mike Lockwood56118b52010-05-11 17:16:59 -04001/*
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 Lockwood56118b52010-05-11 17:16:59 -040020#include "mtp.h"
21#include "MtpUtils.h"
22
23#include <stdint.h>
24
Mike Lockwood8d3257a2010-05-14 10:10:36 -040025struct usb_endpoint;
26
27namespace android {
28
29class MtpStringBuffer;
30
Mike Lockwood56118b52010-05-11 17:16:59 -040031class MtpPacket {
32
33protected:
34 uint8_t* mBuffer;
35 // current size of the buffer
36 int mBufferSize;
37 // number of bytes to add when resizing the buffer
38 int mAllocationIncrement;
39 // size of the data in the packet
40 int mPacketSize;
41
42public:
43 MtpPacket(int bufferSize);
44 virtual ~MtpPacket();
45
46 // sets packet size to the default container size and sets buffer to zero
47 virtual void reset();
48
49 void allocate(int length);
50 void dump();
51
52 uint16_t getContainerCode() const;
53 void setContainerCode(uint16_t code);
54
55 MtpTransactionID getTransactionID() const;
56 void setTransactionID(MtpTransactionID id);
57
58 uint32_t getParameter(int index) const;
59 void setParameter(int index, uint32_t value);
60
61#ifdef MTP_HOST
62 int transfer(struct usb_endpoint *ep, void* buffer, int length);
63#endif
64
65protected:
66 uint16_t getUInt16(int offset) const;
67 uint32_t getUInt32(int offset) const;
68 void putUInt16(int offset, uint16_t value);
69 void putUInt32(int offset, uint32_t value);
70};
71
Mike Lockwood8d3257a2010-05-14 10:10:36 -040072}; // namespace android
73
Mike Lockwood56118b52010-05-11 17:16:59 -040074#endif // _MTP_PACKET_H