MtpRequestPacket.cpp 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#include <stdio.h> 18#include <sys/types.h> 19#include <fcntl.h> 20 21#include "MtpRequestPacket.h" 22 23namespace android { 24 25MtpRequestPacket::MtpRequestPacket() 26 : MtpPacket(512) 27{ 28} 29 30MtpRequestPacket::~MtpRequestPacket() { 31} 32 33#ifdef MTP_DEVICE 34int MtpRequestPacket::read(int fd) { 35 int ret = ::read(fd, mBuffer, mBufferSize); 36 if (ret >= 0) 37 mPacketSize = ret; 38 else 39 mPacketSize = 0; 40 return ret; 41} 42#endif 43 44#ifdef MTP_HOST 45 // write our buffer to the given endpoint (host mode) 46int MtpRequestPacket::write(struct usb_endpoint *ep) 47{ 48 putUInt32(MTP_CONTAINER_LENGTH_OFFSET, mPacketSize); 49 putUInt16(MTP_CONTAINER_TYPE_OFFSET, MTP_CONTAINER_TYPE_COMMAND); 50 return transfer(ep, mBuffer, mPacketSize); 51} 52#endif 53 54} // namespace android 55