MtpPacket.h revision 7850ef999740f214a1990a9c090d3f3865d435aa
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 "mtp.h"
21#include "MtpUtils.h"
22
23#include <stdint.h>
24
25struct usb_endpoint;
26
27namespace android {
28
29class MtpStringBuffer;
30
31class 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
72}; // namespace android
73
74#endif // _MTP_PACKET_H
75