MtpPacket.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. #ifndef _MTP_PACKET_H
  17. #define _MTP_PACKET_H
  18. #include <android-base/macros.h>
  19. #include "MtpDebug.h"
  20. #include "MtpTypes.h"
  21. struct usb_device;
  22. struct usb_request;
  23. namespace android {
  24. class MtpPacket {
  25. protected:
  26. uint8_t* mBuffer;
  27. // current size of the buffer
  28. size_t mBufferSize;
  29. // number of bytes to add when resizing the buffer
  30. size_t mAllocationIncrement;
  31. // size of the data in the packet
  32. size_t mPacketSize;
  33. public:
  34. explicit MtpPacket(int bufferSize);
  35. virtual ~MtpPacket();
  36. // sets packet size to the default container size and sets buffer to zero
  37. virtual void reset();
  38. void allocate(size_t length);
  39. void dump();
  40. void copyFrom(const MtpPacket& src);
  41. uint16_t getContainerCode() const;
  42. void setContainerCode(uint16_t code);
  43. uint16_t getContainerType() const;
  44. MtpTransactionID getTransactionID() const;
  45. void setTransactionID(MtpTransactionID id);
  46. uint32_t getParameter(int index) const;
  47. void setParameter(int index, uint32_t value);
  48. #ifdef MTP_HOST
  49. int transfer(struct usb_request* request);
  50. #endif
  51. protected:
  52. uint16_t getUInt16(int offset) const;
  53. uint32_t getUInt32(int offset) const;
  54. void putUInt16(int offset, uint16_t value);
  55. void putUInt32(int offset, uint32_t value);
  56. DISALLOW_COPY_AND_ASSIGN(MtpPacket);
  57. };
  58. }; // namespace android
  59. #endif // _MTP_PACKET_H