mirror of
https://github.com/cookiengineer/audacity
synced 2025-11-23 17:30:17 +01:00
Break cycle of ScriptCommandRelay and CommandBuilder
This commit is contained in:
@@ -26,7 +26,6 @@ system by constructing BatchCommandEval objects.
|
||||
|
||||
#include "CommandDirectory.h"
|
||||
#include "Command.h"
|
||||
#include "ScriptCommandRelay.h"
|
||||
#include "CommandContext.h"
|
||||
#include "CommandTargets.h"
|
||||
#include "../Shuttle.h"
|
||||
@@ -83,7 +82,7 @@ void CommandBuilder::BuildCommand(const wxString &cmdName,
|
||||
{
|
||||
// Stage 1: create a Command object of the right type
|
||||
|
||||
auto scriptOutput = ScriptCommandRelay::GetResponseTarget();
|
||||
auto scriptOutput = std::make_shared< ResponseQueueTarget >();
|
||||
auto output
|
||||
= std::make_unique<CommandOutputTargets>(std::make_unique<NullProgressTarget>(),
|
||||
scriptOutput,
|
||||
@@ -192,7 +191,8 @@ void CommandBuilder::BuildCommand(const wxString &cmdStringArg)
|
||||
int splitAt = cmdString.Find(wxT(':'));
|
||||
if (splitAt < 0 && cmdString.Find(wxT(' ')) >= 0) {
|
||||
mError = wxT("Command is missing ':'");
|
||||
ScriptCommandRelay::SendResponse(wxT("\n"));
|
||||
ResponseQueueTarget::sResponseQueue().AddResponse(
|
||||
Response{wxT("\n")});
|
||||
mValid = false;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -458,3 +458,9 @@ void StatusBarTarget::Update(const wxString &message)
|
||||
{
|
||||
mStatus.SetStatusText(message, 0);
|
||||
}
|
||||
|
||||
ResponseQueue &ResponseQueueTarget::sResponseQueue()
|
||||
{
|
||||
static ResponseQueue queue;
|
||||
return queue;
|
||||
}
|
||||
|
||||
@@ -221,23 +221,23 @@ public:
|
||||
void Update(const wxString &message) override;
|
||||
};
|
||||
|
||||
/// Adds messages to a response queue (to be sent back to a script)
|
||||
/// Adds messages to the global response queue (to be sent back to a script)
|
||||
class ResponseQueueTarget final : public CommandMessageTarget
|
||||
{
|
||||
private:
|
||||
ResponseQueue &mResponseQueue;
|
||||
wxString mBuffer;
|
||||
public:
|
||||
ResponseQueueTarget(ResponseQueue &responseQueue)
|
||||
: mResponseQueue(responseQueue),
|
||||
mBuffer( wxEmptyString )
|
||||
static ResponseQueue &sResponseQueue();
|
||||
|
||||
ResponseQueueTarget()
|
||||
: mBuffer( wxEmptyString )
|
||||
{ }
|
||||
virtual ~ResponseQueueTarget()
|
||||
{
|
||||
if( mBuffer.StartsWith("\n" ) )
|
||||
mBuffer = mBuffer.Mid( 1 );
|
||||
mResponseQueue.AddResponse( mBuffer );
|
||||
mResponseQueue.AddResponse(wxString(wxT("\n")));
|
||||
sResponseQueue().AddResponse( mBuffer );
|
||||
sResponseQueue().AddResponse(wxString(wxT("\n")));
|
||||
}
|
||||
void Update(const wxString &message) override
|
||||
{
|
||||
|
||||
@@ -31,7 +31,6 @@ code out of ModuleManager.
|
||||
// Declare static class members
|
||||
CommandHandler *ScriptCommandRelay::sCmdHandler;
|
||||
tpRegScriptServerFunc ScriptCommandRelay::sScriptFn;
|
||||
ResponseQueue ScriptCommandRelay::sResponseQueue;
|
||||
|
||||
void ScriptCommandRelay::SetRegScriptServerFunc(tpRegScriptServerFunc scriptFn)
|
||||
{
|
||||
@@ -162,22 +161,8 @@ void * ExecForLisp( char * pIn ){
|
||||
};
|
||||
|
||||
|
||||
/// Adds a response to the queue to be sent back to the script
|
||||
void ScriptCommandRelay::SendResponse(const wxString &response)
|
||||
{
|
||||
sResponseQueue.AddResponse(response);
|
||||
}
|
||||
|
||||
/// Gets a response from the queue (may block)
|
||||
Response ScriptCommandRelay::ReceiveResponse()
|
||||
{
|
||||
return ScriptCommandRelay::sResponseQueue.WaitAndGetResponse();
|
||||
}
|
||||
|
||||
/// Get a pointer to a message target which allows commands to send responses
|
||||
/// back to a script.
|
||||
std::shared_ptr<ResponseQueueTarget> ScriptCommandRelay::GetResponseTarget()
|
||||
{
|
||||
// This should be deleted by a Command destructor
|
||||
return std::make_shared<ResponseQueueTarget>(sResponseQueue);
|
||||
return ResponseQueueTarget::sResponseQueue().WaitAndGetResponse();
|
||||
}
|
||||
|
||||
@@ -22,9 +22,7 @@
|
||||
|
||||
class wxWindow;
|
||||
class CommandHandler;
|
||||
class ResponseQueue;
|
||||
class Response;
|
||||
class ResponseQueueTarget;
|
||||
class OldStyleCommand;
|
||||
using OldStyleCommandPointer = std::shared_ptr<OldStyleCommand>;
|
||||
class wxString;
|
||||
@@ -42,7 +40,6 @@ class ScriptCommandRelay
|
||||
// N.B. Static class members also have to be declared in the .cpp file
|
||||
static CommandHandler *sCmdHandler;
|
||||
static tpRegScriptServerFunc sScriptFn;
|
||||
static ResponseQueue sResponseQueue;
|
||||
|
||||
public:
|
||||
|
||||
@@ -52,9 +49,7 @@ class ScriptCommandRelay
|
||||
static void Run();
|
||||
static void PostCommand(
|
||||
wxWindow *pWindow, const OldStyleCommandPointer &cmd);
|
||||
static void SendResponse(const wxString &response);
|
||||
static Response ReceiveResponse();
|
||||
static std::shared_ptr<ResponseQueueTarget> GetResponseTarget();
|
||||
};
|
||||
|
||||
#endif /* End of include guard: __SCRIPT_COMMAND_RELAY__ */
|
||||
|
||||
Reference in New Issue
Block a user