diff options
author | Mike Lockwood <lockwood@android.com> | 2010-07-12 18:54:16 -0400 |
---|---|---|
committer | Mike Lockwood <lockwood@android.com> | 2010-07-13 20:04:22 -0400 |
commit | 873871f3e75831bcda6c3f75bb4d53355ca5c53a (patch) | |
tree | e7fcffe64b2104cba18df6f35cf736cee63eb2d3 /media/mtp/MtpEventPacket.cpp | |
parent | 4714b0766ecf48f09f39b4781a5c4deafc092d49 (diff) | |
download | frameworks_av-873871f3e75831bcda6c3f75bb4d53355ca5c53a.zip frameworks_av-873871f3e75831bcda6c3f75bb4d53355ca5c53a.tar.gz frameworks_av-873871f3e75831bcda6c3f75bb4d53355ca5c53a.tar.bz2 |
MTP: Add support for sending events to the host when objects are added and removed
Change-Id: Ia1d5232b919c644c670ff9ca651eca92b3f9ad42
Signed-off-by: Mike Lockwood <lockwood@android.com>
Diffstat (limited to 'media/mtp/MtpEventPacket.cpp')
-rw-r--r-- | media/mtp/MtpEventPacket.cpp | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/media/mtp/MtpEventPacket.cpp b/media/mtp/MtpEventPacket.cpp new file mode 100644 index 0000000..651761e --- /dev/null +++ b/media/mtp/MtpEventPacket.cpp @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "MtpEventPacket" + +#include <stdio.h> +#include <sys/types.h> +#include <fcntl.h> +#include <sys/ioctl.h> + +#include <f_mtp.h> + +#include "MtpEventPacket.h" + +namespace android { + +MtpEventPacket::MtpEventPacket() + : MtpPacket(512) +{ +} + +MtpEventPacket::~MtpEventPacket() { +} + +#ifdef MTP_DEVICE +int MtpEventPacket::write(int fd) { + struct mtp_event event; + + putUInt32(MTP_CONTAINER_LENGTH_OFFSET, mPacketSize); + putUInt16(MTP_CONTAINER_TYPE_OFFSET, MTP_CONTAINER_TYPE_EVENT); + + event.data = mBuffer; + event.length = mPacketSize; + int ret = ::ioctl(fd, MTP_SEND_EVENT, (unsigned long)&event); + return (ret < 0 ? ret : 0); +} +#endif + +#ifdef MTP_HOST + // read our buffer from the given endpoint +int MtpEventPacket::read(struct usb_endpoint *ep) { + int ret = transfer(ep, mBuffer, mBufferSize); + if (ret >= 0) + mPacketSize = ret; + else + mPacketSize = 0; + return ret; +} +#endif + +} // namespace android + |