⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dsmcc_storage.h

📁 数字电视中间件小型库
💻 H
字号:
#ifndef DSMCC_STORAGE_H#define DSMCC_STORAGE_H

#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <qmap.h>
#include <qstring.h>
#include "dsmcc.h"
#include "dsmcc_biop.h"
#include "mythdbcon.h"

namespace DSM_CC {
    // Parent class for storage policies
    class Storage {

        // Derived classes must implement these operations
        protected:
            virtual bool StoreObject(uint32_t download_id, uint16_t module_id, uint8_t module_version, const BIOP::ServiceGateway& srg) = 0;
            virtual bool StoreObject(uint32_t download_id, uint16_t module_id, uint8_t module_version, const BIOP::DirectoryMessage& dm) = 0;
            virtual bool StoreObject(uint32_t download_id, uint16_t module_id, uint8_t module_version, const BIOP::FileMessage& fm) = 0;

        // These will be typically used by all derived classes inside the StoreObject()
        // definitions, and so are provided here for convenience
        protected:
            // virtual because CarouselTracker ultimately derives from this
            virtual ~Storage() {};
            QString PlacementKey(uint32_t download_id, uint16_t module_id, const BIOP::MessageHeader& header);
            QString PlacementKey(uint32_t download_id, uint16_t module_id, uint32_t object_key, uint8_t object_key_length);

    };

    class FilesystemStorage : private Storage {
        public:
            FilesystemStorage() : rootpath(""), rootvalid(false) {}

            bool StoreObject(uint32_t download_id, uint16_t module_id, uint8_t module_version, const BIOP::ServiceGateway& srg);
            bool StoreObject(uint32_t download_id, uint16_t module_id, uint8_t module_version, const BIOP::DirectoryMessage& dm);
            bool StoreObject(uint32_t download_id, uint16_t module_id, uint8_t module_version, const BIOP::FileMessage& fm);

            void SetStorageRoot(QString newroot);
            QString GetStorageRoot();

        private:
            QMap<QString, QString> placement_map;
            QString rootpath;
            bool    rootvalid;
    };

    class MythDatabaseStorage : private Storage {
        public:
            bool StoreObject(uint32_t download_id, uint16_t module_id, uint8_t module_version, const BIOP::ServiceGateway& srg);
            bool StoreObject(uint32_t download_id, uint16_t module_id, uint8_t module_version, const BIOP::DirectoryMessage& dm);
            bool StoreObject(uint32_t download_id, uint16_t module_id, uint8_t module_version, const BIOP::FileMessage& fm);

        private:
            typedef struct {
                uint32_t parent;
                QString name;
            } object_info_record;

            QMap<QString, object_info_record> object_info;
            static uint32_t         next_insert_id;

            // This actually finds out what the next_insert_id is, in addition to returning it
            uint32_t GetNextInsertId ();

            // For convenience, to concatenate all those byte vectors into strings
            template<class FwdIter> QString MakeString(FwdIter iter, uint32_t length) {
                QString retval = "";
                for(uint32_t done = 0; done < length; ++done, ++iter) {
                    retval += *iter;
                }
                return retval;
            }
    };
}

#endif // DSMCC_STORAGE

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -