Mike Lockwood | 5ed68d2 | 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 | |
| 25 | namespace android { |
| 26 | |
| 27 | class MtpDeviceInfo; |
| 28 | class MtpObjectInfo; |
| 29 | class MtpStorageInfo; |
| 30 | |
| 31 | class MtpDevice { |
| 32 | private: |
| 33 | struct usb_device* mDevice; |
| 34 | int mInterface; |
| 35 | struct usb_endpoint* mEndpointIn; |
| 36 | struct usb_endpoint* mEndpointOut; |
| 37 | struct usb_endpoint* mEndpointIntr; |
| 38 | MtpDeviceInfo* mDeviceInfo; |
Mike Lockwood | a6c490b | 2010-06-05 22:45:01 -0400 | [diff] [blame] | 39 | MtpPropertyList mDeviceProperties; |
Mike Lockwood | 5ed68d2 | 2010-05-25 19:08:48 -0400 | [diff] [blame] | 40 | |
| 41 | // a unique ID for the device |
| 42 | int mID; |
| 43 | |
| 44 | // current session ID |
| 45 | MtpSessionID mSessionID; |
| 46 | // current transaction ID |
| 47 | MtpTransactionID mTransactionID; |
| 48 | |
| 49 | MtpRequestPacket mRequest; |
| 50 | MtpDataPacket mData; |
| 51 | MtpResponsePacket mResponse; |
| 52 | |
| 53 | public: |
| 54 | MtpDevice(struct usb_device* device, int interface, |
| 55 | struct usb_endpoint *ep_in, struct usb_endpoint *ep_out, |
| 56 | struct usb_endpoint *ep_intr); |
| 57 | virtual ~MtpDevice(); |
| 58 | |
| 59 | inline int getID() const { return mID; } |
| 60 | |
| 61 | void initialize(); |
| 62 | void close(); |
| 63 | const char* getDeviceName(); |
| 64 | |
| 65 | bool openSession(); |
| 66 | bool closeSession(); |
| 67 | |
| 68 | MtpDeviceInfo* getDeviceInfo(); |
| 69 | MtpStorageIDList* getStorageIDs(); |
| 70 | MtpStorageInfo* getStorageInfo(MtpStorageID storageID); |
| 71 | MtpObjectHandleList* getObjectHandles(MtpStorageID storageID, MtpObjectFormat format, MtpObjectHandle parent); |
| 72 | MtpObjectInfo* getObjectInfo(MtpObjectHandle handle); |
Mike Lockwood | 3e072b3 | 2010-06-10 16:34:20 -0400 | [diff] [blame^] | 73 | void* getThumbnail(MtpObjectHandle handle, int& outLength); |
Mike Lockwood | 5ed68d2 | 2010-05-25 19:08:48 -0400 | [diff] [blame] | 74 | |
Mike Lockwood | a6c490b | 2010-06-05 22:45:01 -0400 | [diff] [blame] | 75 | MtpProperty* getDevicePropDesc(MtpDeviceProperty code); |
| 76 | |
Mike Lockwood | 5ed68d2 | 2010-05-25 19:08:48 -0400 | [diff] [blame] | 77 | private: |
| 78 | bool sendRequest(MtpOperationCode operation); |
| 79 | bool sendData(MtpOperationCode operation); |
| 80 | bool readData(); |
| 81 | MtpResponseCode readResponse(); |
| 82 | |
| 83 | }; |
| 84 | |
| 85 | }; // namespace android |
| 86 | |
| 87 | #endif // _MTP_DEVICE_H |