MtpDevice.h revision 42d0b79a787814d42e4c6f9dfe14f13cc0f6a758
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#ifndef _MTP_DEVICE_H 18#define _MTP_DEVICE_H 19 20#include "MtpRequestPacket.h" 21#include "MtpDataPacket.h" 22#include "MtpResponsePacket.h" 23#include "MtpTypes.h" 24 25#include <utils/threads.h> 26 27struct usb_device; 28struct usb_request; 29struct usb_endpoint_descriptor; 30 31namespace android { 32 33class MtpDeviceInfo; 34class MtpObjectInfo; 35class MtpStorageInfo; 36 37class MtpDevice { 38private: 39 struct usb_device* mDevice; 40 int mInterface; 41 struct usb_request* mRequestIn1; 42 struct usb_request* mRequestIn2; 43 struct usb_request* mRequestOut; 44 struct usb_request* mRequestIntr; 45 MtpDeviceInfo* mDeviceInfo; 46 MtpPropertyList mDeviceProperties; 47 48 // a unique ID for the device 49 int mID; 50 51 // current session ID 52 MtpSessionID mSessionID; 53 // current transaction ID 54 MtpTransactionID mTransactionID; 55 56 MtpRequestPacket mRequest; 57 MtpDataPacket mData; 58 MtpResponsePacket mResponse; 59 // set to true if we received a response packet instead of a data packet 60 bool mReceivedResponse; 61 62 // to ensure only one MTP transaction at a time 63 Mutex mMutex; 64 65public: 66 MtpDevice(struct usb_device* device, int interface, 67 const struct usb_endpoint_descriptor *ep_in, 68 const struct usb_endpoint_descriptor *ep_out, 69 const struct usb_endpoint_descriptor *ep_intr); 70 virtual ~MtpDevice(); 71 72 inline int getID() const { return mID; } 73 74 void initialize(); 75 void close(); 76 void print(); 77 const char* getDeviceName(); 78 79 bool openSession(); 80 bool closeSession(); 81 82 MtpDeviceInfo* getDeviceInfo(); 83 MtpStorageIDList* getStorageIDs(); 84 MtpStorageInfo* getStorageInfo(MtpStorageID storageID); 85 MtpObjectHandleList* getObjectHandles(MtpStorageID storageID, MtpObjectFormat format, 86 MtpObjectHandle parent); 87 MtpObjectInfo* getObjectInfo(MtpObjectHandle handle); 88 void* getThumbnail(MtpObjectHandle handle, int& outLength); 89 MtpObjectHandle sendObjectInfo(MtpObjectInfo* info); 90 bool sendObject(MtpObjectInfo* info, int srcFD); 91 bool deleteObject(MtpObjectHandle handle); 92 MtpObjectHandle getParent(MtpObjectHandle handle); 93 MtpObjectHandle getStorageID(MtpObjectHandle handle); 94 95 MtpObjectPropertyList* getObjectPropsSupported(MtpObjectFormat format); 96 97 MtpProperty* getDevicePropDesc(MtpDeviceProperty code); 98 MtpProperty* getObjectPropDesc(MtpObjectProperty code, MtpObjectFormat format); 99 100 bool readObject(MtpObjectHandle handle, const char* destPath, int group, 101 int perm); 102 103private: 104 bool sendRequest(MtpOperationCode operation); 105 bool sendData(); 106 bool readData(); 107 bool writeDataHeader(MtpOperationCode operation, int dataLength); 108 MtpResponseCode readResponse(); 109 110}; 111 112}; // namespace android 113 114#endif // _MTP_DEVICE_H 115