Fixed an issue with message queue target registration in libraries.

This commit is contained in:
Casey Langen 2020-10-17 12:21:34 -07:00
parent 6f302cd374
commit 3e22c82a53
5 changed files with 24 additions and 17 deletions

View File

@ -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();

View File

@ -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());

View File

@ -59,8 +59,9 @@ namespace musik { namespace core { namespace library {
public:
using LocalQuery = musik::core::library::query::QueryBase;
using LocalQueryPtr = std::shared_ptr<LocalQuery>;
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<QueryContext>;
using QueryList = std::list<QueryContextPtr>;
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();

View File

@ -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() {

View File

@ -60,7 +60,9 @@ namespace musik { namespace core { namespace library {
public:
using Client = musik::core::net::WebSocketClient;
using Query = std::shared_ptr<musik::core::db::ISerializableQuery>;
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<QueryContext>;
using QueryList = std::list<QueryContextPtr>;
RemoteLibrary(std::string name, int id); /* ctor */
RemoteLibrary(std::string name, int id, MessageQueue* messageQueue); /* ctor */
void RunQuery(QueryContextPtr context);
void RunQueryOnLoopback(QueryContextPtr context);