Mike Lockwood | 755fd61 | 2010-05-25 19:08:48 -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 | #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 | |
Mike Lockwood | bc4cb0b | 2010-07-26 20:40:45 -0400 | [diff] [blame] | 25 | #include <utils/threads.h> |
| 26 | |
Mike Lockwood | 3e6616d | 2010-06-29 18:11:52 -0400 | [diff] [blame] | 27 | struct usb_device; |
| 28 | |
Mike Lockwood | 755fd61 | 2010-05-25 19:08:48 -0400 | [diff] [blame] | 29 | namespace android { |
| 30 | |
| 31 | class MtpDeviceInfo; |
| 32 | class MtpObjectInfo; |
| 33 | class MtpStorageInfo; |
| 34 | |
| 35 | class MtpDevice { |
| 36 | private: |
| 37 | struct usb_device* mDevice; |
| 38 | int mInterface; |
| 39 | struct usb_endpoint* mEndpointIn; |
| 40 | struct usb_endpoint* mEndpointOut; |
| 41 | struct usb_endpoint* mEndpointIntr; |
| 42 | MtpDeviceInfo* mDeviceInfo; |
Mike Lockwood | 90f4873 | 2010-06-05 22:45:01 -0400 | [diff] [blame] | 43 | MtpPropertyList mDeviceProperties; |
Mike Lockwood | 755fd61 | 2010-05-25 19:08:48 -0400 | [diff] [blame] | 44 | |
| 45 | // a unique ID for the device |
| 46 | int mID; |
| 47 | |
| 48 | // current session ID |
| 49 | MtpSessionID mSessionID; |
| 50 | // current transaction ID |
| 51 | MtpTransactionID mTransactionID; |
| 52 | |
| 53 | MtpRequestPacket mRequest; |
| 54 | MtpDataPacket mData; |
| 55 | MtpResponsePacket mResponse; |
| 56 | |
Mike Lockwood | bc4cb0b | 2010-07-26 20:40:45 -0400 | [diff] [blame] | 57 | // to ensure only one MTP transaction at a time |
| 58 | Mutex mMutex; |
| 59 | |
Mike Lockwood | 755fd61 | 2010-05-25 19:08:48 -0400 | [diff] [blame] | 60 | public: |
| 61 | MtpDevice(struct usb_device* device, int interface, |
| 62 | struct usb_endpoint *ep_in, struct usb_endpoint *ep_out, |
| 63 | struct usb_endpoint *ep_intr); |
| 64 | virtual ~MtpDevice(); |
| 65 | |
| 66 | inline int getID() const { return mID; } |
| 67 | |
| 68 | void initialize(); |
| 69 | void close(); |
| 70 | const char* getDeviceName(); |
| 71 | |
| 72 | bool openSession(); |
| 73 | bool closeSession(); |
| 74 | |
| 75 | MtpDeviceInfo* getDeviceInfo(); |
| 76 | MtpStorageIDList* getStorageIDs(); |
| 77 | MtpStorageInfo* getStorageInfo(MtpStorageID storageID); |
Mike Lockwood | 929b3da | 2010-11-19 13:52:20 -0500 | [diff] [blame] | 78 | MtpObjectHandleList* getObjectHandles(MtpStorageID storageID, MtpObjectFormat format, |
| 79 | MtpObjectHandle parent); |
Mike Lockwood | 755fd61 | 2010-05-25 19:08:48 -0400 | [diff] [blame] | 80 | MtpObjectInfo* getObjectInfo(MtpObjectHandle handle); |
Mike Lockwood | dda5686 | 2010-06-10 16:34:20 -0400 | [diff] [blame] | 81 | void* getThumbnail(MtpObjectHandle handle, int& outLength); |
Mike Lockwood | bc4cb0b | 2010-07-26 20:40:45 -0400 | [diff] [blame] | 82 | MtpObjectHandle sendObjectInfo(MtpObjectInfo* info); |
| 83 | bool sendObject(MtpObjectInfo* info, int srcFD); |
Mike Lockwood | e0a89f6 | 2010-06-11 16:34:52 -0400 | [diff] [blame] | 84 | bool deleteObject(MtpObjectHandle handle); |
| 85 | MtpObjectHandle getParent(MtpObjectHandle handle); |
| 86 | MtpObjectHandle getStorageID(MtpObjectHandle handle); |
Mike Lockwood | 755fd61 | 2010-05-25 19:08:48 -0400 | [diff] [blame] | 87 | |
Mike Lockwood | 5768f10 | 2010-12-07 10:58:56 -0800 | [diff] [blame^] | 88 | MtpObjectPropertyList* getObjectPropsSupported(MtpObjectFormat format); |
| 89 | |
Mike Lockwood | 90f4873 | 2010-06-05 22:45:01 -0400 | [diff] [blame] | 90 | MtpProperty* getDevicePropDesc(MtpDeviceProperty code); |
Mike Lockwood | 5768f10 | 2010-12-07 10:58:56 -0800 | [diff] [blame^] | 91 | MtpProperty* getObjectPropDesc(MtpObjectProperty code); |
Mike Lockwood | 90f4873 | 2010-06-05 22:45:01 -0400 | [diff] [blame] | 92 | |
Mike Lockwood | 929b3da | 2010-11-19 13:52:20 -0500 | [diff] [blame] | 93 | bool readObject(MtpObjectHandle handle, const char* destPath, int group, |
| 94 | int perm); |
Mike Lockwood | bc4cb0b | 2010-07-26 20:40:45 -0400 | [diff] [blame] | 95 | |
Mike Lockwood | 755fd61 | 2010-05-25 19:08:48 -0400 | [diff] [blame] | 96 | private: |
| 97 | bool sendRequest(MtpOperationCode operation); |
Mike Lockwood | bc4cb0b | 2010-07-26 20:40:45 -0400 | [diff] [blame] | 98 | bool sendData(); |
Mike Lockwood | 755fd61 | 2010-05-25 19:08:48 -0400 | [diff] [blame] | 99 | bool readData(); |
Mike Lockwood | bc4cb0b | 2010-07-26 20:40:45 -0400 | [diff] [blame] | 100 | bool writeDataHeader(MtpOperationCode operation, int dataLength); |
Mike Lockwood | 755fd61 | 2010-05-25 19:08:48 -0400 | [diff] [blame] | 101 | MtpResponseCode readResponse(); |
| 102 | |
| 103 | }; |
| 104 | |
| 105 | }; // namespace android |
| 106 | |
| 107 | #endif // _MTP_DEVICE_H |