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) \ #define POST(instance, type, user1, user2) \
cursespp::MessageQueue::Instance().Post( \ cursespp::Window::MessageQueue().Post( \
cursespp::Message::Create(instance, type, user1, user2)); cursespp::Message::Create(instance, type, user1, user2));
#define POST_STREAM_MESSAGE(instance, eventType, uri) \ #define POST_STREAM_MESSAGE(instance, eventType, uri) \
cursespp::MessageQueue::Instance().Post( \ cursespp::Window::MessageQueue().Post( \
cursespp::IMessagePtr(new StreamMessage(instance, eventType, uri))); cursespp::IMessagePtr(new StreamMessage(instance, eventType, uri)));
static inline void loadPreferences( static inline void loadPreferences(

View File

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

View File

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

View File

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

View File

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

View File

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