blob: d0a0fb3016ee6323b427d27dcb341d8aff308ea0 [file] [log] [blame]
Mike Lockwood5ed68d22010-05-25 19:08:48 -04001/*
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 Lockwood0cf89f22010-07-26 20:40:45 -040025#include <utils/threads.h>
26
Mike Lockwoodb14e5882010-06-29 18:11:52 -040027struct usb_device;
Mike Lockwood42d0b792011-01-04 14:48:57 -050028struct usb_request;
29struct usb_endpoint_descriptor;
Mike Lockwoodb14e5882010-06-29 18:11:52 -040030
Mike Lockwood5ed68d22010-05-25 19:08:48 -040031namespace android {
32
33class MtpDeviceInfo;
34class MtpObjectInfo;
35class MtpStorageInfo;
36
37class MtpDevice {
38private:
39 struct usb_device* mDevice;
40 int mInterface;
Mike Lockwood42d0b792011-01-04 14:48:57 -050041 struct usb_request* mRequestIn1;
42 struct usb_request* mRequestIn2;
43 struct usb_request* mRequestOut;
44 struct usb_request* mRequestIntr;
Mike Lockwood5ed68d22010-05-25 19:08:48 -040045 MtpDeviceInfo* mDeviceInfo;
Mike Lockwooda6c490b2010-06-05 22:45:01 -040046 MtpPropertyList mDeviceProperties;
Mike Lockwood5ed68d22010-05-25 19:08:48 -040047
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;
Mike Lockwoodf7454622010-12-09 18:34:18 -080059 // set to true if we received a response packet instead of a data packet
60 bool mReceivedResponse;
Mike Lockwood5ed68d22010-05-25 19:08:48 -040061
Mike Lockwood0cf89f22010-07-26 20:40:45 -040062 // to ensure only one MTP transaction at a time
63 Mutex mMutex;
64
Mike Lockwood5ed68d22010-05-25 19:08:48 -040065public:
66 MtpDevice(struct usb_device* device, int interface,
Mike Lockwood42d0b792011-01-04 14:48:57 -050067 const struct usb_endpoint_descriptor *ep_in,
68 const struct usb_endpoint_descriptor *ep_out,
69 const struct usb_endpoint_descriptor *ep_intr);
Mike Lockwood5ed68d22010-05-25 19:08:48 -040070 virtual ~MtpDevice();
71
72 inline int getID() const { return mID; }
73
74 void initialize();
75 void close();
Mike Lockwood0c7c7c72010-12-07 11:24:28 -080076 void print();
Mike Lockwood5ed68d22010-05-25 19:08:48 -040077 const char* getDeviceName();
78
79 bool openSession();
80 bool closeSession();
81
82 MtpDeviceInfo* getDeviceInfo();
83 MtpStorageIDList* getStorageIDs();
84 MtpStorageInfo* getStorageInfo(MtpStorageID storageID);
Mike Lockwood27afe3a2010-11-19 13:52:20 -050085 MtpObjectHandleList* getObjectHandles(MtpStorageID storageID, MtpObjectFormat format,
86 MtpObjectHandle parent);
Mike Lockwood5ed68d22010-05-25 19:08:48 -040087 MtpObjectInfo* getObjectInfo(MtpObjectHandle handle);
Mike Lockwood3e072b32010-06-10 16:34:20 -040088 void* getThumbnail(MtpObjectHandle handle, int& outLength);
Mike Lockwood0cf89f22010-07-26 20:40:45 -040089 MtpObjectHandle sendObjectInfo(MtpObjectInfo* info);
90 bool sendObject(MtpObjectInfo* info, int srcFD);
Mike Lockwood6afc41d2010-06-11 16:34:52 -040091 bool deleteObject(MtpObjectHandle handle);
92 MtpObjectHandle getParent(MtpObjectHandle handle);
93 MtpObjectHandle getStorageID(MtpObjectHandle handle);
Mike Lockwood5ed68d22010-05-25 19:08:48 -040094
Mike Lockwood98693f62010-12-07 10:58:56 -080095 MtpObjectPropertyList* getObjectPropsSupported(MtpObjectFormat format);
96
Mike Lockwooda6c490b2010-06-05 22:45:01 -040097 MtpProperty* getDevicePropDesc(MtpDeviceProperty code);
Mike Lockwood99e393a2010-12-07 18:53:04 -080098 MtpProperty* getObjectPropDesc(MtpObjectProperty code, MtpObjectFormat format);
Mike Lockwooda6c490b2010-06-05 22:45:01 -040099
Mike Lockwood27afe3a2010-11-19 13:52:20 -0500100 bool readObject(MtpObjectHandle handle, const char* destPath, int group,
101 int perm);
Mike Lockwood0cf89f22010-07-26 20:40:45 -0400102
Mike Lockwood5ed68d22010-05-25 19:08:48 -0400103private:
104 bool sendRequest(MtpOperationCode operation);
Mike Lockwood0cf89f22010-07-26 20:40:45 -0400105 bool sendData();
Mike Lockwood5ed68d22010-05-25 19:08:48 -0400106 bool readData();
Mike Lockwood0cf89f22010-07-26 20:40:45 -0400107 bool writeDataHeader(MtpOperationCode operation, int dataLength);
Mike Lockwood5ed68d22010-05-25 19:08:48 -0400108 MtpResponseCode readResponse();
109
110};
111
112}; // namespace android
113
114#endif // _MTP_DEVICE_H