From 9e0593eaf6defb15761f41246093c0d3661b140d Mon Sep 17 00:00:00 2001 From: that Date: Wed, 8 Oct 2014 00:01:24 +0200 Subject: mtp: cleanup, fixes and performance improvements - use std::map instead of linked list - read directories on demand - fix writing zip files to storage root - fix creating directories - lots of minor fixes - simplify generation of storage IDs and make them spec compliant Change-Id: I2137c27549ddbdc58466f2e3aeda464fac70a3c5 --- mtp/btree.hpp | 94 +++++++++++++++++++++++++---------------------------------- 1 file changed, 40 insertions(+), 54 deletions(-) (limited to 'mtp/btree.hpp') diff --git a/mtp/btree.hpp b/mtp/btree.hpp index 1fa8d2800..b284e4f4b 100755 --- a/mtp/btree.hpp +++ b/mtp/btree.hpp @@ -17,79 +17,65 @@ #ifndef BTREE_HPP #define BTREE_HPP -#include #include -#include -#include "MtpDebug.h" +#include +#include "MtpTypes.h" -// A generic tree node class +// A directory entry class Node { - int mtpid; - int mtpparentid; - std::string path; - int parentID; - Node* left; - Node* right; - Node* parent; + MtpObjectHandle handle; + MtpObjectHandle parent; + std::string name; // name only without path public: Node(); - void setMtpid(int aMtpid); - void setPath(std::string aPath); - void rename(std::string aPath); - void setLeft(Node* aLeft); - void setRight(Node* aRight); - void setParent(Node* aParent); - void setMtpParentId(int id); - int Mtpid(); - int getMtpParentId(); - std::string getPath(); - Node* Left(); - Node* Right(); - Node* Parent(); - void addProperty(uint64_t property, uint64_t valueInt, std::string valueStr, int dataType); - void updateProperty(uint64_t property, uint64_t valueInt, std::string valueStr, int dataType); - void addProperties(int storageID, int parent_object); - uint64_t getIntProperty(uint64_t property); + Node(MtpObjectHandle handle, MtpObjectHandle parent, const std::string& name); + virtual ~Node() {} + + virtual bool isDir() const { return false; } + + void rename(const std::string& newName); + MtpObjectHandle Mtpid() const; + MtpObjectHandle getMtpParentId() const; + const std::string& getName() const; + + void addProperty(MtpPropertyCode property, uint64_t valueInt, std::string valueStr, MtpDataType dataType); + void updateProperty(MtpPropertyCode property, uint64_t valueInt, std::string valueStr, MtpDataType dataType); + void addProperties(const std::string& path, int storageID); + uint64_t getIntProperty(MtpPropertyCode property); struct mtpProperty { - uint64_t property; + MtpPropertyCode property; + MtpDataType dataType; uint64_t valueInt; std::string valueStr; - int dataType; + mtpProperty() : property(0), dataType(0), valueInt(0) {} }; std::vector& getMtpProps(); std::vector mtpProp; + const mtpProperty& getProperty(MtpPropertyCode property); }; -// Binary Search Tree class -class Tree { - Node* root; +// A directory +class Tree : public Node { + std::map entries; + bool alreadyRead; public: - Tree(); + Tree(MtpObjectHandle handle, MtpObjectHandle parent, const std::string& name); ~Tree(); - Node* Root() { - MTPD("root: %d\n", root); - return root; - }; - Node* addNode(int mtpid, std::string path); - void setMtpParentId(int mtpparentid, Node* node); - Node* findNode(int key, Node* parent); - void getmtpids(Node* node, std::vector* mtpids); - void deleteNode(int key); - Node* min(Node* node); - Node* max(Node* node); - Node* successor(int key, Node* parent); - Node* predecessor(int key, Node* parent); + + virtual bool isDir() const { return true; } + + void addEntry(Node* node); + Node* findNode(MtpObjectHandle handle); + void getmtpids(MtpObjectHandleList* mtpids); + void deleteNode(MtpObjectHandle handle); std::string getPath(Node* node); + int getMtpParentId() { return Node::getMtpParentId(); } int getMtpParentId(Node* node); - Node* findNodePath(std::string path, Node* node); - Node* getNext(Node* node); + Node* findEntryByName(std::string name); int getCount(); - -private: - Node* addNode(int mtpid, Node* leaf, std::string path); - void freeNode(Node* leaf); - int count; + bool wasAlreadyRead() const { return alreadyRead; } + void setAlreadyRead(bool b) { alreadyRead = b; } }; #endif -- cgit v1.2.3