blob: b69203ec0f5a350546ebdbed3015e5da184ebca7 [file] [log] [blame]
Mike Lockwood755fd612010-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 Lockwoodbc4cb0b2010-07-26 20:40:45 -040025#include <utils/threads.h>
26
Mike Lockwood3e6616d2010-06-29 18:11:52 -040027struct usb_device;
Mike Lockwood215b6822011-01-04 14:48:57 -050028struct usb_request;
29struct usb_endpoint_descriptor;
Mike Lockwood3e6616d2010-06-29 18:11:52 -040030
Mike Lockwood755fd612010-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 Lockwood215b6822011-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 Lockwood755fd612010-05-25 19:08:48 -040045 MtpDeviceInfo* mDeviceInfo;
Mike Lockwood90f48732010-06-05 22:45:01 -040046 MtpPropertyList mDeviceProperties;
Mike Lockwood755fd612010-05-25 19:08:48 -040047
Mike Lockwood755fd612010-05-25 19:08:48 -040048 // current session ID
49 MtpSessionID mSessionID;
50 // current transaction ID
51 MtpTransactionID mTransactionID;
52
53 MtpRequestPacket mRequest;
54 MtpDataPacket mData;
55 MtpResponsePacket mResponse;
Mike Lockwoodbfd1d722010-12-09 18:34:18 -080056 // set to true if we received a response packet instead of a data packet
57 bool mReceivedResponse;
Mike Lockwood755fd612010-05-25 19:08:48 -040058
Mike Lockwoodbc4cb0b2010-07-26 20:40:45 -040059 // to ensure only one MTP transaction at a time
60 Mutex mMutex;
61
Mike Lockwood755fd612010-05-25 19:08:48 -040062public:
63 MtpDevice(struct usb_device* device, int interface,
Mike Lockwood215b6822011-01-04 14:48:57 -050064 const struct usb_endpoint_descriptor *ep_in,
65 const struct usb_endpoint_descriptor *ep_out,
66 const struct usb_endpoint_descriptor *ep_intr);
Mike Lockwood755fd612010-05-25 19:08:48 -040067
Mike Lockwood8182e722010-12-30 15:38:45 -050068 static MtpDevice* open(const char* deviceName, int fd);
69
70 virtual ~MtpDevice();
Mike Lockwood755fd612010-05-25 19:08:48 -040071
72 void initialize();
73 void close();
Mike Lockwoode4880e42010-12-07 11:24:28 -080074 void print();
Mike Lockwood755fd612010-05-25 19:08:48 -040075 const char* getDeviceName();
76
77 bool openSession();
78 bool closeSession();
79
80 MtpDeviceInfo* getDeviceInfo();
81 MtpStorageIDList* getStorageIDs();
82 MtpStorageInfo* getStorageInfo(MtpStorageID storageID);
Mike Lockwood929b3da2010-11-19 13:52:20 -050083 MtpObjectHandleList* getObjectHandles(MtpStorageID storageID, MtpObjectFormat format,
84 MtpObjectHandle parent);
Mike Lockwood755fd612010-05-25 19:08:48 -040085 MtpObjectInfo* getObjectInfo(MtpObjectHandle handle);
Mike Lockwooddda56862010-06-10 16:34:20 -040086 void* getThumbnail(MtpObjectHandle handle, int& outLength);
Mike Lockwoodbc4cb0b2010-07-26 20:40:45 -040087 MtpObjectHandle sendObjectInfo(MtpObjectInfo* info);
88 bool sendObject(MtpObjectInfo* info, int srcFD);
Mike Lockwoode0a89f62010-06-11 16:34:52 -040089 bool deleteObject(MtpObjectHandle handle);
90 MtpObjectHandle getParent(MtpObjectHandle handle);
91 MtpObjectHandle getStorageID(MtpObjectHandle handle);
Mike Lockwood755fd612010-05-25 19:08:48 -040092
Mike Lockwood5768f102010-12-07 10:58:56 -080093 MtpObjectPropertyList* getObjectPropsSupported(MtpObjectFormat format);
94
Mike Lockwood90f48732010-06-05 22:45:01 -040095 MtpProperty* getDevicePropDesc(MtpDeviceProperty code);
Mike Lockwooda194cc72010-12-07 18:53:04 -080096 MtpProperty* getObjectPropDesc(MtpObjectProperty code, MtpObjectFormat format);
Mike Lockwood90f48732010-06-05 22:45:01 -040097
Mike Lockwood8182e722010-12-30 15:38:45 -050098 bool readObject(MtpObjectHandle handle,
99 bool (* callback)(void* data, int offset,
100 int length, void* clientData),
101 int objectSize, void* clientData);
102 bool readObject(MtpObjectHandle handle, const char* destPath, int group,
Mike Lockwood929b3da2010-11-19 13:52:20 -0500103 int perm);
Mike Lockwoodbc4cb0b2010-07-26 20:40:45 -0400104
Mike Lockwood755fd612010-05-25 19:08:48 -0400105private:
106 bool sendRequest(MtpOperationCode operation);
Mike Lockwoodbc4cb0b2010-07-26 20:40:45 -0400107 bool sendData();
Mike Lockwood755fd612010-05-25 19:08:48 -0400108 bool readData();
Mike Lockwoodbc4cb0b2010-07-26 20:40:45 -0400109 bool writeDataHeader(MtpOperationCode operation, int dataLength);
Mike Lockwood755fd612010-05-25 19:08:48 -0400110 MtpResponseCode readResponse();
111
112};
113
114}; // namespace android
115
116#endif // _MTP_DEVICE_H