blob: d90b0c071ea6d156b0593257fc79f1d48edf1333 [file] [log] [blame]
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -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 * Copyright (C) 2014 TeamWin - bigbiff and Dees_Troy mtp database conversion to C++
17 */
18
19#ifndef _MTP_DEVICE_H
20#define _MTP_DEVICE_H
21
22#include "MtpRequestPacket.h"
23#include "MtpDataPacket.h"
24#include "MtpResponsePacket.h"
25#include "MtpTypes.h"
26
27#include <utils/threads.h>
28
29struct usb_device;
30struct usb_request;
31struct usb_endpoint_descriptor;
32
33
34class MtpDeviceInfo;
35class MtpObjectInfo;
36class MtpStorageInfo;
37
38class MtpDevice {
39private:
40 struct usb_device* mDevice;
41 int mInterface;
42 struct usb_request* mRequestIn1;
43 struct usb_request* mRequestIn2;
44 struct usb_request* mRequestOut;
45 struct usb_request* mRequestIntr;
46 MtpDeviceInfo* mDeviceInfo;
47 MtpPropertyList mDeviceProperties;
48
49 // current session ID
50 MtpSessionID mSessionID;
51 // current transaction ID
52 MtpTransactionID mTransactionID;
53
54 MtpRequestPacket mRequest;
55 MtpDataPacket mData;
56 MtpResponsePacket mResponse;
57 // set to true if we received a response packet instead of a data packet
58 bool mReceivedResponse;
59
60 // to ensure only one MTP transaction at a time
61 android::Mutex mMutex;
62
63public:
64 MtpDevice(struct usb_device* device, int interface,
65 const struct usb_endpoint_descriptor *ep_in,
66 const struct usb_endpoint_descriptor *ep_out,
67 const struct usb_endpoint_descriptor *ep_intr);
68
69 static MtpDevice* open(const char* deviceName, int fd);
70
71 virtual ~MtpDevice();
72
73 void initialize();
74 void close();
75 void print();
76 const char* getDeviceName();
77
78 bool openSession();
79 bool closeSession();
80
81 MtpDeviceInfo* getDeviceInfo();
82 MtpStorageIDList* getStorageIDs();
83 MtpStorageInfo* getStorageInfo(MtpStorageID storageID);
84 MtpObjectHandleList* getObjectHandles(MtpStorageID storageID, MtpObjectFormat format,
85 MtpObjectHandle parent);
86 MtpObjectInfo* getObjectInfo(MtpObjectHandle handle);
87 void* getThumbnail(MtpObjectHandle handle, int& outLength);
88 MtpObjectHandle sendObjectInfo(MtpObjectInfo* info);
89 bool sendObject(MtpObjectInfo* info, int srcFD);
90 bool deleteObject(MtpObjectHandle handle);
91 MtpObjectHandle getParent(MtpObjectHandle handle);
92 MtpObjectHandle getStorageID(MtpObjectHandle handle);
93
94 MtpObjectPropertyList* getObjectPropsSupported(MtpObjectFormat format);
95
96 MtpProperty* getDevicePropDesc(MtpDeviceProperty code);
97 MtpProperty* getObjectPropDesc(MtpObjectProperty code, MtpObjectFormat format);
98
99 bool readObject(MtpObjectHandle handle,
100 bool (* callback)(void* data, int offset,
101 int length, void* clientData),
102 int objectSize, void* clientData);
103 bool readObject(MtpObjectHandle handle, const char* destPath, int group,
104 int perm);
105
106private:
107 bool sendRequest(MtpOperationCode operation);
108 bool sendData();
109 bool readData();
110 bool writeDataHeader(MtpOperationCode operation, int dataLength);
111 MtpResponseCode readResponse();
112
113};
114
115
116#endif // _MTP_DEVICE_H