Mike Lockwood | 16864ba | 2010-05-11 17:16:59 -0400 | [diff] [blame] | 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 | #include <stdio.h> |
| 18 | #include <sys/types.h> |
| 19 | #include <fcntl.h> |
| 20 | |
| 21 | #include "MtpResponsePacket.h" |
| 22 | |
Mike Lockwood | 7850ef9 | 2010-05-14 10:10:36 -0400 | [diff] [blame^] | 23 | namespace android { |
| 24 | |
Mike Lockwood | 16864ba | 2010-05-11 17:16:59 -0400 | [diff] [blame] | 25 | MtpResponsePacket::MtpResponsePacket() |
| 26 | : MtpPacket(512) |
| 27 | { |
| 28 | } |
| 29 | |
| 30 | MtpResponsePacket::~MtpResponsePacket() { |
| 31 | } |
| 32 | |
| 33 | #ifdef MTP_DEVICE |
| 34 | int MtpResponsePacket::write(int fd) { |
| 35 | putUInt32(MTP_CONTAINER_LENGTH_OFFSET, mPacketSize); |
| 36 | putUInt16(MTP_CONTAINER_TYPE_OFFSET, MTP_CONTAINER_TYPE_RESPONSE); |
| 37 | int ret = ::write(fd, mBuffer, mPacketSize); |
| 38 | return (ret < 0 ? ret : 0); |
| 39 | } |
| 40 | #endif |
| 41 | |
| 42 | #ifdef MTP_HOST |
| 43 | // read our buffer from the given endpoint |
| 44 | int MtpResponsePacket::read(struct usb_endpoint *ep) { |
| 45 | int ret = transfer(ep, mBuffer, mBufferSize); |
| 46 | if (ret >= 0) |
| 47 | mPacketSize = ret; |
| 48 | else |
| 49 | mPacketSize = 0; |
| 50 | return ret; |
| 51 | } |
| 52 | #endif |
| 53 | |
Mike Lockwood | 7850ef9 | 2010-05-14 10:10:36 -0400 | [diff] [blame^] | 54 | } // namespace android |
Mike Lockwood | 16864ba | 2010-05-11 17:16:59 -0400 | [diff] [blame] | 55 | |