coming
天行健 君子以自强不息
记录我的成长
文章目录
该类管理本地的音乐资料库并提供编辑本地音乐资料库的接口,定义于src/musikcore/library/LocalLibrary.h,继承了ILibrary、IMessageTarget类,并通过继承模板类std::enable_shared_from_this使得this指针成为shared_ptr指针。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
| class LocalLibrary : public ILibrary, public mymusic::core::runtime::IMessageTarget, public std::enable_shared_from_this<LocalLibrary> { public: using LocalQuery = mymusic::core::library::query::QueryBase; using LocalQueryPtr = std::shared_ptr<LocalQuery>; using MessageQueue = mymusic::core::runtime::IMessageQueue; using IIndexer = mymusic::core::IIndexer; static ILibraryPtr Create(std::string name, int id, MessageQueue* messageQueue); LocalLibrary(const LocalLibrary&) = delete; virtual ~LocalLibrary(); int Enqueue(QueryPtr query, Callback cb = Callback()) override; int EnqueueAndWait(QueryPtr query, size_t timeoutMs = kWaitIndefinite, Callback cb = Callback()) override; IIndexer *Indexer() override; int Id() override; const std::string& Name() override; void SetMessageQueue(mymusic::core::runtime::IMessageQueue& queue) override; MessageQueue& GetMessageQueue() override { return *messageQueue; } IResourceLocator& GetResourceLocator() override; bool IsConfigured() override; ConnectionState GetConnectionState() const override { return ConnectionState::Connected; } Type GetType() const override { return Type::Local; } void Close() override; void ProcessMessage(mymusic::core::runtime::IMessage &message) override;
db::Connection& GetConnection() { return this->db; } std::string GetLibraryDirectory(); std::string GetDatabaseFilename(); static void CreateDatabase(db::Connection &db); static void DropIndexes(db::Connection &db); static void CreateIndexes(db::Connection &db); static void InvalidateTrackMetadata(db::Connection &db); private: class QueryCompletedMessage;
struct QueryContext { LocalQueryPtr query; Callback callback; };
using QueryContextPtr = std::shared_ptr<QueryContext>; using QueryList = std::list<QueryContextPtr>; LocalLibrary(std::string name, int id, MessageQueue* messageQueue); void RunQuery(QueryContextPtr context, bool notify = true); void ThreadProc(); QueryContextPtr GetNextQuery(); QueryList queryQueue; mymusic::core::runtime::IMessageQueue* messageQueue; std::string identifier; int id; std::string name; std::thread* thread; std::condition_variable_any queueCondition; std::recursive_mutex mutex; std::atomic<bool> exit; core::IIndexer *indexer; core::db::Connection db; };
|
本文代表个人观点,内容仅供参考。若有不恰当之处,望不吝赐教!