blob: 2f5e931baa94a325e99779dc90498067b91883fa [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];
49 static int AUDIO_PROPERTIES[19];
50 static int VIDEO_PROPERTIES[15];
51 static int IMAGE_PROPERTIES[12];
52 static int ALL_PROPERTIES[25];
53 static int SUPPORTED_PLAYBACK_FORMATS[26];
54 int storagenum;
55 int count;
56 std::string lastfile;
57 std::map<int, MtpStorage*> storagemap;
58 void countDirs(std::string path);
59 int readParentDirs(std::string path, int storageID);
60
61public:
62 MyMtpDatabase();
63 virtual ~MyMtpDatabase();
64
65 void createDB(MtpStorage* storage, MtpStorageID storageID);
66 virtual MtpObjectHandle beginSendObject(const char* path,
67 MtpObjectFormat format,
68 MtpObjectHandle parent,
69 MtpStorageID storage,
70 uint64_t size,
71 time_t modified);
72
73 virtual void endSendObject(const char* path,
74 MtpObjectHandle handle,
75 MtpObjectFormat format,
76 bool succeeded);
77
78 virtual MtpObjectHandleList* getObjectList(MtpStorageID storageID,
79 MtpObjectFormat format,
80 MtpObjectHandle parent);
81
82 virtual int getNumObjects(MtpStorageID storageID,
83 MtpObjectFormat format,
84 MtpObjectHandle parent);
85
86 // callee should delete[] the results from these
87 // results can be NULL
88 virtual MtpObjectFormatList* getSupportedPlaybackFormats();
89 virtual MtpObjectFormatList* getSupportedCaptureFormats();
90 virtual MtpObjectPropertyList* getSupportedObjectProperties(MtpObjectFormat format);
91 virtual MtpDevicePropertyList* getSupportedDeviceProperties();
92
93 virtual MtpResponseCode getObjectPropertyValue(MtpObjectHandle handle,
94 MtpObjectProperty property,
95 MtpDataPacket& packet);
96
97 virtual MtpResponseCode setObjectPropertyValue(MtpObjectHandle handle,
98 MtpObjectProperty property,
99 MtpDataPacket& packet);
100
101 virtual MtpResponseCode getDevicePropertyValue(MtpDeviceProperty property,
102 MtpDataPacket& packet);
103
104 virtual MtpResponseCode setDevicePropertyValue(MtpDeviceProperty property,
105 MtpDataPacket& packet);
106
107 virtual MtpResponseCode resetDeviceProperty(MtpDeviceProperty property);
108
109 virtual MtpResponseCode getObjectPropertyList(MtpObjectHandle handle,
110 uint32_t format, uint32_t property,
111 int groupCode, int depth,
112 MtpDataPacket& packet);
113
114 virtual MtpResponseCode getObjectInfo(MtpObjectHandle handle,
115 MtpObjectInfo& info);
116
117 virtual void* getThumbnail(MtpObjectHandle handle, size_t& outThumbSize);
118
119 virtual MtpResponseCode getObjectFilePath(MtpObjectHandle handle,
120 MtpString& outFilePath,
121 int64_t& outFileLength,
122 MtpObjectFormat& outFormat);
123 virtual MtpResponseCode deleteFile(MtpObjectHandle handle);
124
125 bool getObjectPropertyInfo(MtpObjectProperty property, int& type);
126 bool getDevicePropertyInfo(MtpDeviceProperty property, int& type);
127
128 virtual MtpObjectHandleList* getObjectReferences(MtpObjectHandle handle);
129
130 virtual MtpResponseCode setObjectReferences(MtpObjectHandle handle,
131 MtpObjectHandleList* references);
132
133 virtual MtpProperty* getObjectPropertyDesc(MtpObjectProperty property,
134 MtpObjectFormat format);
135
136 virtual MtpProperty* getDevicePropertyDesc(MtpDeviceProperty property);
137
138 virtual void sessionStarted();
139
140 virtual void sessionEnded();
141 virtual void lockMutex();
142 virtual void unlockMutex();
143};
144#endif