From 45bac55dc325dbd8a0be139116e93b02c9c7d84b Mon Sep 17 00:00:00 2001 From: casey langen Date: Fri, 6 Jan 2017 15:39:17 -0800 Subject: [PATCH] Put MessageQueue behind an interface so implementation can vary on different platforms. --- src/core/core.vcxproj | 1 + src/core/core.vcxproj.filters | 3 ++ src/core/runtime/IMessageQueue.h | 55 ++++++++++++++++++++ src/core/runtime/MessageQueue.cpp | 4 ++ src/core/runtime/MessageQueue.h | 19 ++++--- src/musikbox/Main.cpp | 2 +- src/musikbox/app/service/PlaybackService.cpp | 10 ++-- src/musikbox/app/service/PlaybackService.h | 5 +- src/musikbox/cursespp/Window.cpp | 3 +- src/musikbox/cursespp/Window.h | 4 +- src/musikbox/musikbox.vcxproj | 3 +- src/musikwin/musikwin.vcxproj | 15 +++++- 12 files changed, 103 insertions(+), 21 deletions(-) create mode 100644 src/core/runtime/IMessageQueue.h diff --git a/src/core/core.vcxproj b/src/core/core.vcxproj index 63446aed5..57393a53a 100755 --- a/src/core/core.vcxproj +++ b/src/core/core.vcxproj @@ -149,6 +149,7 @@ + diff --git a/src/core/core.vcxproj.filters b/src/core/core.vcxproj.filters index 4fad2d51e..669c1ae1e 100755 --- a/src/core/core.vcxproj.filters +++ b/src/core/core.vcxproj.filters @@ -318,5 +318,8 @@ src\audio + + src\runtime + \ No newline at end of file diff --git a/src/core/runtime/IMessageQueue.h b/src/core/runtime/IMessageQueue.h new file mode 100644 index 000000000..2c3875a9b --- /dev/null +++ b/src/core/runtime/IMessageQueue.h @@ -0,0 +1,55 @@ +////////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2007-2016 musikcube team +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// * Neither the name of the author nor the names of other contributors may +// be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include "IMessage.h" +#include "IMessageTarget.h" + +namespace musik { + namespace core { + namespace runtime { + class IMessageQueue { + public: + virtual ~IMessageQueue() { } + virtual void Post(IMessagePtr message, int64 delayMs = 0) = 0; + virtual int Remove(IMessageTarget *target, int type = -1) = 0; + virtual bool Contains(IMessageTarget *target, int type = -1) = 0; + virtual void Debounce(IMessagePtr message, int64 delayMs = 0) = 0; + virtual void WaitAndDispatch() = 0; + virtual void Dispatch() = 0; + }; + } + } +} \ No newline at end of file diff --git a/src/core/runtime/MessageQueue.cpp b/src/core/runtime/MessageQueue.cpp index 8060dd424..23f0f8b55 100755 --- a/src/core/runtime/MessageQueue.cpp +++ b/src/core/runtime/MessageQueue.cpp @@ -67,6 +67,10 @@ void MessageQueue::WaitAndDispatch() { this->Dispatch(); } +MessageQueue::~MessageQueue() { + +} + void MessageQueue::Dispatch() { milliseconds now = duration_cast( system_clock::now().time_since_epoch()); diff --git a/src/core/runtime/MessageQueue.h b/src/core/runtime/MessageQueue.h index c63f704cf..41058be4f 100755 --- a/src/core/runtime/MessageQueue.h +++ b/src/core/runtime/MessageQueue.h @@ -34,8 +34,7 @@ #pragma once -#include "IMessage.h" -#include "IMessageTarget.h" +#include "IMessageQueue.h" #include #include @@ -44,17 +43,17 @@ #include namespace musik { namespace core { namespace runtime { - class MessageQueue { + class MessageQueue : public IMessageQueue { public: MessageQueue(); + virtual ~MessageQueue(); - void Post(IMessagePtr message, int64 delayMs = 0); - int Remove(IMessageTarget *target, int type = -1); - bool Contains(IMessageTarget *target, int type = -1); - void Debounce(IMessagePtr message, int64 delayMs = 0); - - void WaitAndDispatch(); - void Dispatch(); + virtual void Post(IMessagePtr message, int64 delayMs = 0); + virtual int Remove(IMessageTarget *target, int type = -1); + virtual bool Contains(IMessageTarget *target, int type = -1); + virtual void Debounce(IMessagePtr message, int64 delayMs = 0); + virtual void WaitAndDispatch(); + virtual void Dispatch(); private: struct EnqueuedMessage { diff --git a/src/musikbox/Main.cpp b/src/musikbox/Main.cpp index 47aa51253..d602470f6 100644 --- a/src/musikbox/Main.cpp +++ b/src/musikbox/Main.cpp @@ -110,7 +110,7 @@ int main(int argc, char* argv[]) LibraryPtr library = LibraryFactory::Libraries().at(0); MasterTransport transport; - PlaybackService playback(library, transport); + PlaybackService playback(Window::MessageQueue(), library, transport); GlobalHotkeys globalHotkeys(playback, library); diff --git a/src/musikbox/app/service/PlaybackService.cpp b/src/musikbox/app/service/PlaybackService.cpp index 745d9e0b6..c0d6631af 100755 --- a/src/musikbox/app/service/PlaybackService.cpp +++ b/src/musikbox/app/service/PlaybackService.cpp @@ -88,11 +88,11 @@ class StreamMessage : public Message { }; #define POST(instance, type, user1, user2) \ - cursespp::Window::MessageQueue().Post( \ + this->messageQueue.Post( \ musik::core::runtime::Message::Create(instance, type, user1, user2)); #define POST_STREAM_MESSAGE(instance, eventType, uri) \ - cursespp::Window::MessageQueue().Post( \ + this->messageQueue.Post( \ musik::core::runtime::IMessagePtr(new StreamMessage(instance, eventType, uri))); static inline void loadPreferences( @@ -117,12 +117,16 @@ static inline void savePreferences( prefs->SetInt(keys::RepeatMode, playback.GetRepeatMode()); } -PlaybackService::PlaybackService(LibraryPtr library, ITransport& transport) +PlaybackService::PlaybackService( + IMessageQueue& messageQueue, + LibraryPtr library, + ITransport& transport) : library(library) , transport(transport) , playlist(library) , unshuffled(library) , repeatMode(RepeatNone) +, messageQueue(messageQueue) , prefs(Preferences::ForComponent(components::Playback)) { transport.StreamEvent.connect(this, &PlaybackService::OnStreamEvent); transport.PlaybackEvent.connect(this, &PlaybackService::OnPlaybackEvent); diff --git a/src/musikbox/app/service/PlaybackService.h b/src/musikbox/app/service/PlaybackService.h index 9165799e1..d7f4345d2 100755 --- a/src/musikbox/app/service/PlaybackService.h +++ b/src/musikbox/app/service/PlaybackService.h @@ -44,7 +44,7 @@ #include #include #include -#include +#include #include @@ -61,6 +61,7 @@ namespace musik { sigslot::signal1 Shuffled; PlaybackService( + musik::core::runtime::IMessageQueue& messageQueue, musik::core::LibraryPtr library, musik::core::audio::ITransport& transport); @@ -118,6 +119,8 @@ namespace musik { musik::core::audio::ITransport& transport; size_t index, nextIndex; musik::core::sdk::RepeatMode repeatMode; + + musik::core::runtime::IMessageQueue& messageQueue; }; } } diff --git a/src/musikbox/cursespp/Window.cpp b/src/musikbox/cursespp/Window.cpp index a1935b35c..61cd71980 100755 --- a/src/musikbox/cursespp/Window.cpp +++ b/src/musikbox/cursespp/Window.cpp @@ -40,6 +40,7 @@ #include "Screen.h" #include +#include using namespace cursespp; using namespace musik::core::runtime; @@ -95,7 +96,7 @@ void Window::Unfreeze() { } } -MessageQueue& Window::MessageQueue() { +IMessageQueue& Window::MessageQueue() { return messageQueue; } diff --git a/src/musikbox/cursespp/Window.h b/src/musikbox/cursespp/Window.h index 4bfaac3ae..274458f31 100755 --- a/src/musikbox/cursespp/Window.h +++ b/src/musikbox/cursespp/Window.h @@ -37,7 +37,7 @@ #include "curses_config.h" #include "IWindow.h" -#include +#include #ifdef WIN32 #define IDLE_TIMEOUT_MS 0 @@ -105,7 +105,7 @@ namespace cursespp { static void Freeze(); static void Unfreeze(); - static musik::core::runtime::MessageQueue& MessageQueue(); + static musik::core::runtime::IMessageQueue& MessageQueue(); protected: IWindow* GetParent() const; diff --git a/src/musikbox/musikbox.vcxproj b/src/musikbox/musikbox.vcxproj index 3dfb8f3e7..3ead58d37 100755 --- a/src/musikbox/musikbox.vcxproj +++ b/src/musikbox/musikbox.vcxproj @@ -76,7 +76,8 @@ %(IgnoreSpecificDefaultLibraries) true Windows - ../../bin/$(Configuration)/mC2.lib + + MachineX86 pdcursesd.lib;pdh.lib;psapi.lib;%(AdditionalDependencies) false diff --git a/src/musikwin/musikwin.vcxproj b/src/musikwin/musikwin.vcxproj index 9065c9fa7..bfd066873 100644 --- a/src/musikwin/musikwin.vcxproj +++ b/src/musikwin/musikwin.vcxproj @@ -72,6 +72,7 @@ true $(SolutionDir)\bin\$(Configuration)\ + .\obj\$(Configuration)\ true @@ -79,6 +80,8 @@ false $(SolutionDir)\bin\$(Configuration)\ + .\obj\$(Configuration)\ + AllRules.ruleset false @@ -99,7 +102,7 @@ Windows true ../../../boost_1_60_0/lib32-msvc-14.0;$(SolutionDir)bin\$(Configuration)\;%(AdditionalLibraryDirectories) - 3rdparty.lib;core.lib;comctl32.lib;%(AdditionalDependencies) + comctl32.lib;%(AdditionalDependencies) @@ -136,7 +139,7 @@ true true ../../../boost_1_60_0/lib32-msvc-14.0;$(SolutionDir)bin\$(Configuration)\;%(AdditionalLibraryDirectories) - 3rdparty.lib;core.lib;comctl32.lib;%(AdditionalDependencies) + comctl32.lib;%(AdditionalDependencies) @@ -246,6 +249,14 @@ + + + {b2165720-b4b2-4f4b-8888-8c390c3cb4db} + + + {b2165720-b4b2-4f4b-9634-8c390c3cb4db} + +