bigbiff bigbiff | c7eee6f | 2014-09-02 18:59:01 -0400 | [diff] [blame] | 1 | /* |
| 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_STORAGE_H |
| 20 | #define _MTP_STORAGE_H |
| 21 | |
| 22 | #include "mtp.h" |
| 23 | #include "MtpObjectInfo.h" |
| 24 | #include <string> |
| 25 | #include <deque> |
| 26 | #include <map> |
| 27 | #include <libgen.h> |
| 28 | #include <pthread.h> |
| 29 | #include "btree.hpp" |
| 30 | #include "MtpServer.h" |
| 31 | |
| 32 | class MtpDatabase; |
| 33 | |
| 34 | class MtpStorage { |
| 35 | |
| 36 | private: |
| 37 | MtpStorageID mStorageID; |
| 38 | MtpString mFilePath; |
| 39 | MtpString mDescription; |
| 40 | uint64_t mMaxCapacity; |
| 41 | uint64_t mMaxFileSize; |
| 42 | // amount of free space to leave unallocated |
| 43 | uint64_t mReserveSpace; |
| 44 | bool mRemovable; |
| 45 | MtpServer* mServer; |
| 46 | std::deque<std::string> mtpParentList; |
| 47 | int mtpparentid; |
| 48 | Tree *mtpdbtree; |
| 49 | typedef std::map<int, Tree*> maptree; |
| 50 | typedef maptree::iterator iter; |
| 51 | maptree mtpmap; |
| 52 | std::string mtpstorageparent; |
| 53 | pthread_t inotify_thread; |
| 54 | int inotify_fd; |
| 55 | int inotify_wd; |
| 56 | android::Mutex mMutex; |
| 57 | |
| 58 | public: |
| 59 | MtpStorage(MtpStorageID id, const char* filePath, |
| 60 | const char* description, uint64_t reserveSpace, |
| 61 | bool removable, uint64_t maxFileSize, MtpServer* refserver); |
| 62 | virtual ~MtpStorage(); |
| 63 | |
| 64 | inline MtpStorageID getStorageID() const { return mStorageID; } |
| 65 | int getType() const; |
| 66 | int getFileSystemType() const; |
| 67 | int getAccessCapability() const; |
| 68 | uint64_t getMaxCapacity(); |
| 69 | uint64_t getFreeSpace(); |
| 70 | const char* getDescription() const; |
| 71 | inline const char* getPath() const { return (const char *)mFilePath; } |
| 72 | inline bool isRemovable() const { return mRemovable; } |
| 73 | inline uint64_t getMaxFileSize() const { return mMaxFileSize; } |
| 74 | int readParentDirs(std::string path); |
| 75 | int createDB(); |
| 76 | MtpObjectHandleList* getObjectList(MtpStorageID storageID, MtpObjectHandle parent); |
| 77 | int getObjectInfo(MtpObjectHandle handle, MtpObjectInfo& info); |
| 78 | MtpObjectHandle beginSendObject(const char* path, MtpObjectFormat format, MtpObjectHandle parent, MtpStorageID storage, uint64_t size, time_t modified); |
| 79 | int getObjectPropertyList(MtpObjectHandle handle, uint32_t format, uint32_t property, int groupCode, int depth, MtpDataPacket& packet); |
| 80 | int getObjectFilePath(MtpObjectHandle handle, MtpString& outFilePath, int64_t& outFileLength, MtpObjectFormat& outFormat); |
| 81 | int deleteFile(MtpObjectHandle handle); |
| 82 | int renameObject(MtpObjectHandle handle, std::string newName); |
| 83 | int getObjectPropertyValue(MtpObjectHandle handle, MtpObjectProperty property, uint64_t &longValue); |
| 84 | void lockMutex(int thread_type); |
| 85 | void unlockMutex(int thread_type); |
| 86 | |
| 87 | private: |
| 88 | void createEmptyDir(const char* path); |
| 89 | pthread_t inotify(); |
| 90 | int inotify_t(); |
| 91 | typedef int (MtpStorage::*ThreadPtr)(void); |
| 92 | typedef void* (*PThreadPtr)(void *); |
| 93 | std::map<int, std::string> inotifymap; |
| 94 | int addInotifyDirs(std::string path); |
| 95 | void deleteTrees(int parent); |
| 96 | bool sendEvents; |
| 97 | int getParentObject(std::string parent_path); |
| 98 | bool use_mutex; |
| 99 | pthread_mutex_t inMutex; // inotify mutex |
| 100 | pthread_mutex_t mtpMutex; // main mtp mutex |
| 101 | }; |
| 102 | |
| 103 | #endif // _MTP_STORAGE_H |