MtpResponsePacket.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. #define LOG_TAG "MtpResponsePacket"
  17. #include <stdio.h>
  18. #include <sys/types.h>
  19. #include <fcntl.h>
  20. #include "IMtpHandle.h"
  21. #include "MtpResponsePacket.h"
  22. #include <usbhost/usbhost.h>
  23. namespace android {
  24. MtpResponsePacket::MtpResponsePacket()
  25. : MtpPacket(512)
  26. {
  27. }
  28. MtpResponsePacket::~MtpResponsePacket() {
  29. }
  30. #ifdef MTP_DEVICE
  31. int MtpResponsePacket::write(IMtpHandle *h) {
  32. putUInt32(MTP_CONTAINER_LENGTH_OFFSET, mPacketSize);
  33. putUInt16(MTP_CONTAINER_TYPE_OFFSET, MTP_CONTAINER_TYPE_RESPONSE);
  34. int ret = h->write(mBuffer, mPacketSize);
  35. return (ret < 0 ? ret : 0);
  36. }
  37. #endif
  38. #ifdef MTP_HOST
  39. int MtpResponsePacket::read(struct usb_request *request) {
  40. request->buffer = mBuffer;
  41. request->buffer_length = mBufferSize;
  42. int ret = transfer(request);
  43. if (ret >= 0)
  44. mPacketSize = ret;
  45. else
  46. mPacketSize = 0;
  47. return ret;
  48. }
  49. #endif
  50. } // namespace android