From 3e22c82a53335bab77aef242ca64aa1ce75f63fc Mon Sep 17 00:00:00 2001 From: Casey Langen Date: Sat, 17 Oct 2020 12:21:34 -0700 Subject: [PATCH] Fixed an issue with message queue target registration in libraries. --- src/musikcore/library/LibraryFactory.cpp | 7 ++----- src/musikcore/library/LocalLibrary.cpp | 12 ++++++++---- src/musikcore/library/LocalLibrary.h | 5 +++-- src/musikcore/library/RemoteLibrary.cpp | 11 +++++++---- src/musikcore/library/RemoteLibrary.h | 6 ++++-- 5 files changed, 24 insertions(+), 17 deletions(-) diff --git a/src/musikcore/library/LibraryFactory.cpp b/src/musikcore/library/LibraryFactory.cpp index 1a7b18390..e64712f9c 100644 --- a/src/musikcore/library/LibraryFactory.cpp +++ b/src/musikcore/library/LibraryFactory.cpp @@ -67,13 +67,10 @@ LibraryFactory::~LibraryFactory() { ILibraryPtr LibraryFactory::AddLibrary(int id, ILibrary::Type type, const std::string& name) { ILibraryPtr library = (type == ILibrary::Type::Local) - ? library::LocalLibrary::Create(name, id) - : library::RemoteLibrary::Create(name, id); + ? library::LocalLibrary::Create(name, id, sMessageQueue) + : library::RemoteLibrary::Create(name, id, sMessageQueue); if (library) { - if (sMessageQueue) { - library->SetMessageQueue(*sMessageQueue); - } this->libraries.push_back(library); this->libraryMap[id] = library; this->LibrariesUpdated(); diff --git a/src/musikcore/library/LocalLibrary.cpp b/src/musikcore/library/LocalLibrary.cpp index 282af448c..66b1450d1 100644 --- a/src/musikcore/library/LocalLibrary.cpp +++ b/src/musikcore/library/LocalLibrary.cpp @@ -84,16 +84,20 @@ class LocalLibrary::QueryCompletedMessage: public Message { QueryContextPtr context; }; -ILibraryPtr LocalLibrary::Create(std::string name, int id) { - ILibraryPtr lib(new LocalLibrary(name, id)); +ILibraryPtr LocalLibrary::Create(std::string name, int id, MessageQueue* messageQueue) { + ILibraryPtr lib(new LocalLibrary(name, id, messageQueue)); return lib; } -LocalLibrary::LocalLibrary(std::string name,int id) +LocalLibrary::LocalLibrary(std::string name, int id, MessageQueue* messageQueue) : name(name) , id(id) , exit(false) -, messageQueue(nullptr) { +, messageQueue(messageQueue) { + if (this->messageQueue) { + this->messageQueue->Register(this); + } + this->identifier = std::to_string(id); this->db.Open(this->GetDatabaseFilename().c_str()); diff --git a/src/musikcore/library/LocalLibrary.h b/src/musikcore/library/LocalLibrary.h index 8f5d9cf54..ab83ef6ec 100644 --- a/src/musikcore/library/LocalLibrary.h +++ b/src/musikcore/library/LocalLibrary.h @@ -59,8 +59,9 @@ namespace musik { namespace core { namespace library { public: using LocalQuery = musik::core::library::query::QueryBase; using LocalQueryPtr = std::shared_ptr; + using MessageQueue = musik::core::runtime::IMessageQueue; - static ILibraryPtr Create(std::string name, int id); + static ILibraryPtr Create(std::string name, int id, MessageQueue* messageQueue); LocalLibrary(const LocalLibrary&) = delete; virtual ~LocalLibrary(); @@ -107,7 +108,7 @@ namespace musik { namespace core { namespace library { using QueryContextPtr = std::shared_ptr; using QueryList = std::list; - LocalLibrary(std::string name, int id); /* ctor */ + LocalLibrary(std::string name, int id, MessageQueue* messageQueue); /* ctor */ void RunQuery(QueryContextPtr context, bool notify = true); void ThreadProc(); diff --git a/src/musikcore/library/RemoteLibrary.cpp b/src/musikcore/library/RemoteLibrary.cpp index b2becc8d0..3236c15b0 100644 --- a/src/musikcore/library/RemoteLibrary.cpp +++ b/src/musikcore/library/RemoteLibrary.cpp @@ -88,20 +88,23 @@ class RemoteLibrary::QueryCompletedMessage: public Message { QueryContextPtr context; }; -ILibraryPtr RemoteLibrary::Create(std::string name, int id) { - ILibraryPtr lib(new RemoteLibrary(name, id)); +ILibraryPtr RemoteLibrary::Create(std::string name, int id, MessageQueue* messageQueue) { + ILibraryPtr lib(new RemoteLibrary(name, id, messageQueue)); return lib; } -RemoteLibrary::RemoteLibrary(std::string name, int id) +RemoteLibrary::RemoteLibrary(std::string name, int id, MessageQueue* messageQueue) : name(name) , id(id) , exit(false) -, messageQueue(nullptr) +, messageQueue(messageQueue) , wsc(this) { this->identifier = std::to_string(id); this->thread = new std::thread(std::bind(&RemoteLibrary::ThreadProc, this)); this->ReloadConnectionFromPreferences(); + if (this->messageQueue) { + this->messageQueue->Register(this); + } } RemoteLibrary::~RemoteLibrary() { diff --git a/src/musikcore/library/RemoteLibrary.h b/src/musikcore/library/RemoteLibrary.h index 884e323ac..95f23e410 100644 --- a/src/musikcore/library/RemoteLibrary.h +++ b/src/musikcore/library/RemoteLibrary.h @@ -60,7 +60,9 @@ namespace musik { namespace core { namespace library { public: using Client = musik::core::net::WebSocketClient; using Query = std::shared_ptr; - static ILibraryPtr Create(std::string name, int id); + using MessageQueue = musik::core::runtime::IMessageQueue; + + static ILibraryPtr Create(std::string name, int id, MessageQueue* messageQueue); RemoteLibrary(const RemoteLibrary&) = delete; virtual ~RemoteLibrary(); @@ -109,7 +111,7 @@ namespace musik { namespace core { namespace library { using QueryContextPtr = std::shared_ptr; using QueryList = std::list; - RemoteLibrary(std::string name, int id); /* ctor */ + RemoteLibrary(std::string name, int id, MessageQueue* messageQueue); /* ctor */ void RunQuery(QueryContextPtr context); void RunQueryOnLoopback(QueryContextPtr context);