blob: 4b1889851a53956854dcfdef9646c4891ab9d92d [file] [log] [blame]
bigbiff bigbiffaf32bb92018-12-18 18:39:53 -05001/*
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_MTPDATABASE_HPP
20#define MTP_MTPDATABASE_HPP
21
22#include <utils/Log.h>
23
24#include <stdio.h>
25#include <assert.h>
26#include <limits.h>
27#include <unistd.h>
28#include <fcntl.h>
29#include <dirent.h>
30#include <errno.h>
31#include <sys/types.h>
32#include <map>
33#include <string>
34#include <deque>
35
36#include "MtpDatabase.h"
37#include "MtpDataPacket.h"
38#include "MtpObjectInfo.h"
39#include "MtpProperty.h"
40#include "MtpStringBuffer.h"
41#include "MtpUtils.h"
42#include "mtp.h"
43
44class IMtpDatabase : public MtpDatabase {
45private:
46 int* getSupportedObjectProperties(int format);
47
48 static int FILE_PROPERTIES[10];
49 static int DEVICE_PROPERTIES[3];
50 static int AUDIO_PROPERTIES[19];
51 static int VIDEO_PROPERTIES[15];
52 static int IMAGE_PROPERTIES[12];
53 static int ALL_PROPERTIES[25];
54 static int SUPPORTED_PLAYBACK_FORMATS[26];
55 int storagenum;
56 int count;
57 std::string lastfile;
58 std::map<int, MtpStorage*> storagemap;
59 void countDirs(std::string path);
60 int readParentDirs(std::string path, int storageID);
61
62public:
63 IMtpDatabase();
64 virtual ~IMtpDatabase();
65
66 virtual void createDB(MtpStorage* storage, MtpStorageID storageID);
67 virtual void destroyDB(MtpStorageID storageID);
68 virtual MtpObjectHandle beginSendObject(const char* path,
69 MtpObjectFormat format,
70 MtpObjectHandle parent,
71 MtpStorageID storageID,
72 uint64_t size,
73 time_t modified);
74
75 virtual void endSendObject(const char* path,
76 MtpObjectHandle handle,
77 MtpObjectFormat format,
78 bool succeeded);
79
80 virtual MtpObjectHandleList* getObjectList(MtpStorageID storageID,
81 MtpObjectFormat format,
82 MtpObjectHandle parent);
83
84 virtual int getNumObjects(MtpStorageID storageID,
85 MtpObjectFormat format,
86 MtpObjectHandle parent);
87
88 // callee should delete[] the results from these
89 // results can be NULL
90 virtual MtpObjectFormatList* getSupportedPlaybackFormats();
91 virtual MtpObjectFormatList* getSupportedCaptureFormats();
92 virtual MtpObjectPropertyList* getSupportedObjectProperties(MtpObjectFormat format);
93 virtual MtpDevicePropertyList* getSupportedDeviceProperties();
94
95 virtual MtpResponseCode getObjectPropertyValue(MtpObjectHandle handle,
96 MtpObjectProperty property,
97 MtpDataPacket& packet);
98
99 virtual MtpResponseCode setObjectPropertyValue(MtpObjectHandle handle,
100 MtpObjectProperty property,
101 MtpDataPacket& packet);
102
103 virtual MtpResponseCode getDevicePropertyValue(MtpDeviceProperty property,
104 MtpDataPacket& packet);
105
106 virtual MtpResponseCode setDevicePropertyValue(MtpDeviceProperty property,
107 MtpDataPacket& packet);
108
109 virtual MtpResponseCode resetDeviceProperty(MtpDeviceProperty property);
110
111 virtual MtpResponseCode getObjectPropertyList(MtpObjectHandle handle,
112 uint32_t format, uint32_t property,
113 int groupCode, int depth,
114 MtpDataPacket& packet);
115
116 virtual MtpResponseCode getObjectInfo(MtpObjectHandle handle,
117 MtpObjectInfo& info);
118
119 virtual void* getThumbnail(MtpObjectHandle handle, size_t& outThumbSize);
120
121 virtual MtpResponseCode getObjectFilePath(MtpObjectHandle handle,
122 MtpStringBuffer& outFilePath,
123 int64_t& outFileLength,
124 MtpObjectFormat& outFormat);
125 // virtual MtpResponseCode deleteFile(MtpObjectHandle handle);
126
127 bool getObjectPropertyInfo(MtpObjectProperty property, int& type);
128 bool getDevicePropertyInfo(MtpDeviceProperty property, int& type);
129
130 virtual MtpObjectHandleList* getObjectReferences(MtpObjectHandle handle);
131
132 virtual MtpResponseCode setObjectReferences(MtpObjectHandle handle,
133 MtpObjectHandleList* references);
134
135 virtual MtpProperty* getObjectPropertyDesc(MtpObjectProperty property,
136 MtpObjectFormat format);
137
138 virtual MtpProperty* getDevicePropertyDesc(MtpDeviceProperty property);
139
140 virtual void sessionStarted();
141
142 virtual void sessionEnded();
143 virtual void lockMutex();
144 virtual void unlockMutex();
145
146 virtual MtpResponseCode beginDeleteObject(MtpObjectHandle handle);
147 virtual void endDeleteObject(MtpObjectHandle handle, bool succeeded);
148 // Called to rescan a file, such as after an edit.
149 virtual void rescanFile(const char* path,
150 MtpObjectHandle handle,
151 MtpObjectFormat format);
152 virtual MtpResponseCode beginMoveObject(MtpObjectHandle handle, MtpObjectHandle newParent,
153 MtpStorageID newStorage);
154
155 virtual void endMoveObject(MtpObjectHandle oldParent, MtpObjectHandle newParent,
156 MtpStorageID oldStorage, MtpStorageID newStorage,
157 MtpObjectHandle handle, bool succeeded);
158
159 virtual MtpResponseCode beginCopyObject(MtpObjectHandle handle, MtpObjectHandle newParent,
160 MtpStorageID newStorage);
161 virtual void endCopyObject(MtpObjectHandle handle, bool succeeded);
162};
163#endif