MessageQueue itself is no longer a singleton. However, Window has a static

instance.
This commit is contained in:
casey langen 2016-12-20 22:54:13 -08:00
parent b832b96688
commit 3aa4871e62
6 changed files with 15 additions and 19 deletions

View File

@ -91,11 +91,11 @@ class StreamMessage : public cursespp::Message {
};
#define POST(instance, type, user1, user2) \
cursespp::MessageQueue::Instance().Post( \
cursespp::Window::MessageQueue().Post( \
cursespp::Message::Create(instance, type, user1, user2));
#define POST_STREAM_MESSAGE(instance, eventType, uri) \
cursespp::MessageQueue::Instance().Post( \
cursespp::Window::MessageQueue().Post( \
cursespp::IMessagePtr(new StreamMessage(instance, eventType, uri)));
static inline void loadPreferences(

View File

@ -222,8 +222,7 @@ void App::Run(ILayoutPtr layout) {
this->EnsureFocusIsValid();
Window::WriteToScreen(this->state.input);
MessageQueue::Instance().Dispatch();
Window::MessageQueue().Dispatch();
}
overlays.Clear();

View File

@ -41,16 +41,10 @@ using namespace cursespp;
using LockT = std::unique_lock<std::recursive_mutex>;
MessageQueue MessageQueue::instance;
MessageQueue::MessageQueue() {
}
MessageQueue& MessageQueue::Instance() {
return MessageQueue::instance;
}
void MessageQueue::Dispatch() {
milliseconds now = duration_cast<milliseconds>(
system_clock::now().time_since_epoch());

View File

@ -43,7 +43,7 @@
namespace cursespp {
class MessageQueue {
public:
static MessageQueue& Instance();
MessageQueue();
void Post(IMessagePtr message, int64 delayMs = 0);
void Remove(IMessageTarget *target, int type = -1);
@ -52,8 +52,6 @@ namespace cursespp {
void Dispatch();
private:
static MessageQueue instance;
struct EnqueuedMessage {
IMessagePtr message;
std::chrono::milliseconds time;
@ -62,7 +60,6 @@ namespace cursespp {
std::recursive_mutex queueMutex;
std::list<EnqueuedMessage*> queue;
MessageQueue();
void Dispatch(IMessagePtr message);
};
}

View File

@ -37,7 +37,6 @@
#include "IWindowGroup.h"
#include "IInput.h"
#include "Message.h"
#include "MessageQueue.h"
#include "Colors.h"
#include "Screen.h"
@ -46,6 +45,7 @@ using namespace cursespp;
static int NEXT_ID = 0;
static bool drawPending = false;
static bool freeze = false;
static MessageQueue messageQueue;
#define ENABLE_BOUNDS_CHECK 1
@ -92,6 +92,10 @@ void Window::Unfreeze() {
}
}
MessageQueue& Window::MessageQueue() {
return messageQueue;
}
Window::Window(IWindow *parent) {
this->frame = this->content = 0;
this->framePanel = this->contentPanel = 0;
@ -112,7 +116,7 @@ Window::Window(IWindow *parent) {
}
Window::~Window() {
MessageQueue::Instance().Remove(this);
messageQueue.Remove(this);
this->Destroy();
}
@ -153,7 +157,7 @@ void Window::SendToBottom() {
}
void Window::PostMessage(int messageType, int64 user1, int64 user2, int64 delay) {
MessageQueue::Instance().Post(
messageQueue.Post(
Message::Create(
this,
messageType,
@ -163,7 +167,7 @@ void Window::PostMessage(int messageType, int64 user1, int64 user2, int64 delay)
}
void Window::DebounceMessage(int messageType, int64 user1, int64 user2, int64 delay) {
MessageQueue::Instance().Debounce(
messageQueue.Debounce(
Message::Create(
this,
messageType,
@ -173,7 +177,7 @@ void Window::DebounceMessage(int messageType, int64 user1, int64 user2, int64 de
}
void Window::RemoveMessage(int messageType) {
MessageQueue::Instance().Remove(this, messageType);
messageQueue.Remove(this, messageType);
}
void Window::SetParent(IWindow* parent) {

View File

@ -36,6 +36,7 @@
#include "curses_config.h"
#include "IWindow.h"
#include "MessageQueue.h"
#ifdef WIN32
#define IDLE_TIMEOUT_MS 0
@ -102,6 +103,7 @@ namespace cursespp {
static void InvalidateScreen();
static void Freeze();
static void Unfreeze();
static MessageQueue& MessageQueue();
protected:
IWindow* GetParent() const;