blob: 3b18e4e4a1206f030e8cac75a56d69222767ca7b [file] [log] [blame]
Mike Lockwood16864ba2010-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_DATA_PACKET_H
18#define _MTP_DATA_PACKET_H
19
20#include "MtpPacket.h"
21#include "mtp.h"
22
23class MtpDataPacket : public MtpPacket {
24private:
25 // current offset for get/put methods
26 int mOffset;
27
28public:
29 MtpDataPacket();
30 virtual ~MtpDataPacket();
31
32 virtual void reset();
33
34 void setOperationCode(MtpOperationCode code);
35 void setTransactionID(MtpTransactionID id);
36
37 inline uint8_t getUInt8() { return (uint8_t)mBuffer[mOffset++]; }
38 inline int8_t getInt8() { return (int8_t)mBuffer[mOffset++]; }
39 uint16_t getUInt16();
40 inline int16_t getInt16() { return (int16_t)getUInt16(); }
41 uint32_t getUInt32();
42 inline int32_t getInt32() { return (int32_t)getUInt32(); }
43 uint64_t getUInt64();
44 inline int64_t getInt64() { return (int64_t)getUInt64(); }
45 void getString(MtpStringBuffer& string);
46
47 void putInt8(int8_t value);
48 void putUInt8(uint8_t value);
49 void putInt16(int16_t value);
50 void putUInt16(uint16_t value);
51 void putInt32(int32_t value);
52 void putUInt32(uint32_t value);
53 void putInt64(int64_t value);
54 void putUInt64(uint64_t value);
55
56 void putAInt8(const int8_t* values, int count);
57 void putAUInt8(const uint8_t* values, int count);
58 void putAInt16(const int16_t* values, int count);
59 void putAUInt16(const uint16_t* values, int count);
60 void putAInt32(const int32_t* values, int count);
61 void putAUInt32(const uint32_t* values, int count);
62 void putAUInt32(const UInt32List* list);
63 void putAInt64(const int64_t* values, int count);
64 void putAUInt64(const uint64_t* values, int count);
65 void putString(const MtpStringBuffer& string);
66 void putString(const char* string);
67 inline void putEmptyString() { putUInt16(0); }
68 inline void putEmptyArray() { putUInt32(0); }
69
70
71#ifdef MTP_DEVICE
72 // fill our buffer with data from the given file descriptor
73 int read(int fd);
74 int readDataHeader(int fd);
75
76 // write our data to the given file descriptor
77 int write(int fd);
78 int writeDataHeader(int fd, uint32_t length);
79#endif
80
81#ifdef MTP_HOST
82 int read(struct usb_endpoint *ep);
83 int write(struct usb_endpoint *ep);
84#endif
85
86 inline bool hasData() const { return mPacketSize > MTP_CONTAINER_HEADER_SIZE; }
87};
88
89#endif // _MTP_DATA_PACKET_H