MtpResponsePacket.cpp revision 16864bae0f51c32c456da2c43adf7a057c0c4882
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
23MtpResponsePacket::MtpResponsePacket()
24    :   MtpPacket(512)
25{
26}
27
28MtpResponsePacket::~MtpResponsePacket() {
29}
30
31#ifdef MTP_DEVICE
32int MtpResponsePacket::write(int fd) {
33    putUInt32(MTP_CONTAINER_LENGTH_OFFSET, mPacketSize);
34    putUInt16(MTP_CONTAINER_TYPE_OFFSET, MTP_CONTAINER_TYPE_RESPONSE);
35    int ret = ::write(fd, mBuffer, mPacketSize);
36    return (ret < 0 ? ret : 0);
37}
38#endif
39
40#ifdef MTP_HOST
41    // read our buffer from the given endpoint
42int MtpResponsePacket::read(struct usb_endpoint *ep) {
43    int ret = transfer(ep, mBuffer, mBufferSize);
44     if (ret >= 0)
45        mPacketSize = ret;
46    else
47        mPacketSize = 0;
48    return ret;
49}
50#endif
51
52
53