blob: cc8097be228114bd0f7fa133faa05cdf659ed95b [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_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 MyMtpDatabase : public MtpDatabase {
45private:
46 int* getSupportedObjectProperties(int format);
47
48 static int FILE_PROPERTIES[10];
bigbiff bigbiff1812c892014-09-08 21:04:06 -040049 static int DEVICE_PROPERTIES[3];
bigbiff bigbiffc7eee6f2014-09-02 18:59:01 -040050 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 MyMtpDatabase();
64 virtual ~MyMtpDatabase();
65
66 void createDB(MtpStorage* storage, MtpStorageID storageID);
67 virtual MtpObjectHandle beginSendObject(const char* path,
68 MtpObjectFormat format,
69 MtpObjectHandle parent,
70 MtpStorageID storage,
71 uint64_t size,
72 time_t modified);
73
74 virtual void endSendObject(const char* path,
75 MtpObjectHandle handle,
76 MtpObjectFormat format,
77 bool succeeded);
78
79 virtual MtpObjectHandleList* getObjectList(MtpStorageID storageID,
80 MtpObjectFormat format,
81 MtpObjectHandle parent);
82
83 virtual int getNumObjects(MtpStorageID storageID,
84 MtpObjectFormat format,
85 MtpObjectHandle parent);
86
87 // callee should delete[] the results from these
88 // results can be NULL
89 virtual MtpObjectFormatList* getSupportedPlaybackFormats();
90 virtual MtpObjectFormatList* getSupportedCaptureFormats();
91 virtual MtpObjectPropertyList* getSupportedObjectProperties(MtpObjectFormat format);
92 virtual MtpDevicePropertyList* getSupportedDeviceProperties();
93
94 virtual MtpResponseCode getObjectPropertyValue(MtpObjectHandle handle,
95 MtpObjectProperty property,
96 MtpDataPacket& packet);
97
98 virtual MtpResponseCode setObjectPropertyValue(MtpObjectHandle handle,
99 MtpObjectProperty property,
100 MtpDataPacket& packet);
101
102 virtual MtpResponseCode getDevicePropertyValue(MtpDeviceProperty property,
103 MtpDataPacket& packet);
104
105 virtual MtpResponseCode setDevicePropertyValue(MtpDeviceProperty property,
106 MtpDataPacket& packet);
107
108 virtual MtpResponseCode resetDeviceProperty(MtpDeviceProperty property);
109
110 virtual MtpResponseCode getObjectPropertyList(MtpObjectHandle handle,
111 uint32_t format, uint32_t property,
112 int groupCode, int depth,
113 MtpDataPacket& packet);
114
115 virtual MtpResponseCode getObjectInfo(MtpObjectHandle handle,
116 MtpObjectInfo& info);
117
118 virtual void* getThumbnail(MtpObjectHandle handle, size_t& outThumbSize);
119
120 virtual MtpResponseCode getObjectFilePath(MtpObjectHandle handle,
121 MtpString& outFilePath,
122 int64_t& outFileLength,
123 MtpObjectFormat& outFormat);
124 virtual MtpResponseCode deleteFile(MtpObjectHandle handle);
125
126 bool getObjectPropertyInfo(MtpObjectProperty property, int& type);
127 bool getDevicePropertyInfo(MtpDeviceProperty property, int& type);
128
129 virtual MtpObjectHandleList* getObjectReferences(MtpObjectHandle handle);
130
131 virtual MtpResponseCode setObjectReferences(MtpObjectHandle handle,
132 MtpObjectHandleList* references);
133
134 virtual MtpProperty* getObjectPropertyDesc(MtpObjectProperty property,
135 MtpObjectFormat format);
136
137 virtual MtpProperty* getDevicePropertyDesc(MtpDeviceProperty property);
138
139 virtual void sessionStarted();
140
141 virtual void sessionEnded();
142 virtual void lockMutex();
143 virtual void unlockMutex();
144};
145#endif