blob: 67bb85f4cba6bb56817fd9887a7269414cf9fa9c [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;
28
Mike Lockwood5ed68d22010-05-25 19:08:48 -040029namespace android {
30
31class MtpDeviceInfo;
32class MtpObjectInfo;
33class MtpStorageInfo;
34
35class MtpDevice {
36private:
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 Lockwooda6c490b2010-06-05 22:45:01 -040043 MtpPropertyList mDeviceProperties;
Mike Lockwood5ed68d22010-05-25 19:08:48 -040044
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;
Mike Lockwoodf7454622010-12-09 18:34:18 -080056 // set to true if we received a response packet instead of a data packet
57 bool mReceivedResponse;
Mike Lockwood5ed68d22010-05-25 19:08:48 -040058
Mike Lockwood0cf89f22010-07-26 20:40:45 -040059 // to ensure only one MTP transaction at a time
60 Mutex mMutex;
61
Mike Lockwood5ed68d22010-05-25 19:08:48 -040062public:
63 MtpDevice(struct usb_device* device, int interface,
64 struct usb_endpoint *ep_in, struct usb_endpoint *ep_out,
65 struct usb_endpoint *ep_intr);
66 virtual ~MtpDevice();
67
68 inline int getID() const { return mID; }
69
70 void initialize();
71 void close();
Mike Lockwood0c7c7c72010-12-07 11:24:28 -080072 void print();
Mike Lockwood5ed68d22010-05-25 19:08:48 -040073 const char* getDeviceName();
74
75 bool openSession();
76 bool closeSession();
77
78 MtpDeviceInfo* getDeviceInfo();
79 MtpStorageIDList* getStorageIDs();
80 MtpStorageInfo* getStorageInfo(MtpStorageID storageID);
Mike Lockwood27afe3a2010-11-19 13:52:20 -050081 MtpObjectHandleList* getObjectHandles(MtpStorageID storageID, MtpObjectFormat format,
82 MtpObjectHandle parent);
Mike Lockwood5ed68d22010-05-25 19:08:48 -040083 MtpObjectInfo* getObjectInfo(MtpObjectHandle handle);
Mike Lockwood3e072b32010-06-10 16:34:20 -040084 void* getThumbnail(MtpObjectHandle handle, int& outLength);
Mike Lockwood0cf89f22010-07-26 20:40:45 -040085 MtpObjectHandle sendObjectInfo(MtpObjectInfo* info);
86 bool sendObject(MtpObjectInfo* info, int srcFD);
Mike Lockwood6afc41d2010-06-11 16:34:52 -040087 bool deleteObject(MtpObjectHandle handle);
88 MtpObjectHandle getParent(MtpObjectHandle handle);
89 MtpObjectHandle getStorageID(MtpObjectHandle handle);
Mike Lockwood5ed68d22010-05-25 19:08:48 -040090
Mike Lockwood98693f62010-12-07 10:58:56 -080091 MtpObjectPropertyList* getObjectPropsSupported(MtpObjectFormat format);
92
Mike Lockwooda6c490b2010-06-05 22:45:01 -040093 MtpProperty* getDevicePropDesc(MtpDeviceProperty code);
Mike Lockwood99e393a2010-12-07 18:53:04 -080094 MtpProperty* getObjectPropDesc(MtpObjectProperty code, MtpObjectFormat format);
Mike Lockwooda6c490b2010-06-05 22:45:01 -040095
Mike Lockwood27afe3a2010-11-19 13:52:20 -050096 bool readObject(MtpObjectHandle handle, const char* destPath, int group,
97 int perm);
Mike Lockwood0cf89f22010-07-26 20:40:45 -040098
Mike Lockwood5ed68d22010-05-25 19:08:48 -040099private:
100 bool sendRequest(MtpOperationCode operation);
Mike Lockwood0cf89f22010-07-26 20:40:45 -0400101 bool sendData();
Mike Lockwood5ed68d22010-05-25 19:08:48 -0400102 bool readData();
Mike Lockwood0cf89f22010-07-26 20:40:45 -0400103 bool writeDataHeader(MtpOperationCode operation, int dataLength);
Mike Lockwood5ed68d22010-05-25 19:08:48 -0400104 MtpResponseCode readResponse();
105
106};
107
108}; // namespace android
109
110#endif // _MTP_DEVICE_H