Update of /cvsroot/audacity/audacity-src/src/commands In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv31971/src/commands
Modified Files: CommandBuilder.cpp ScriptCommandRelay.cpp ScriptCommandRelay.h Log Message: Update scripting on the Audacity side to use ResponseQueue to get command responses back to the script. Index: ScriptCommandRelay.cpp =================================================================== RCS file: /cvsroot/audacity/audacity-src/src/commands/ScriptCommandRelay.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- ScriptCommandRelay.cpp 30 May 2009 04:30:33 -0000 1.1 +++ ScriptCommandRelay.cpp 7 Jun 2009 15:35:49 -0000 1.2 @@ -2,7 +2,7 @@ Audacity - A Digital Audio Editor Copyright 1999-2009 Audacity Team - License: GPL v2 - see LICENSE.txt + File License: wxWidgets Dan Horgan @@ -26,21 +26,19 @@ #include "CommandBuilder.h" #include "AppCommandEvent.h" #include "CommandHandler.h" +#include "ResponseQueue.h" #include <wx/wx.h> - #include "../Project.h" + // Declare static class members CommandHandler *ScriptCommandRelay::sCmdHandler; tpRegScriptServerFunc ScriptCommandRelay::sScriptFn; -tpScriptServerResponseFunc ScriptCommandRelay::sScriptOutFn; +ResponseQueue ScriptCommandRelay::sResponseQueue; void ScriptCommandRelay::SetRegScriptServerFunc(tpRegScriptServerFunc scriptFn) { sScriptFn = scriptFn; } -void ScriptCommandRelay::SetScriptServerResponseFunc(tpScriptServerResponseFunc scriptOutFn) -{ sScriptOutFn = scriptOutFn; } - void ScriptCommandRelay::SetCommandHandler(CommandHandler &ch) { sCmdHandler = &ch; } @@ -48,14 +46,14 @@ { wxASSERT( sScriptFn != NULL ); while( true ) - sScriptFn(&ScriptCommandRelay::ExecCommand); + sScriptFn(&ExecCommand); } /// This is the function which actually obeys one command. Rather than applying /// the command directly, an event containing a reference to the command is sent /// to the main (GUI) thread. This is because having more than one thread access /// the GUI at a time causes problems with wxwidgets. -int ScriptCommandRelay::ExecCommand(wxString *pIn) +int ExecCommand(wxString *pIn, wxString *pOut) { CommandBuilder builder(*pIn); if (builder.WasValid()) @@ -64,18 +62,25 @@ AppCommandEvent ev; ev.SetCommand(cmd); GetActiveProject()->AddPendingEvent(ev); + Response r = ScriptCommandRelay::ReceiveResponse(); + *pOut = r.GetMessage(); } else { - wxMessageOutputDebug().Printf(wxT("Syntax error!\n")); - // TODO: Send message back to script + *pOut = wxT("Syntax error!\n"); + *pOut += builder.GetErrorMessage(); } return 0; } -void ScriptCommandRelay::SendResponse(wxString &pOut) +void ScriptCommandRelay::SendResponse(const wxString &response) { - sScriptOutFn(&pOut); + sResponseQueue.AddResponse(response); +} + +Response ScriptCommandRelay::ReceiveResponse() +{ + return ScriptCommandRelay::sResponseQueue.WaitAndGetResponse(); } // Indentation settings for Vim and Emacs and unique identifier for Arch, a Index: ScriptCommandRelay.h =================================================================== RCS file: /cvsroot/audacity/audacity-src/src/commands/ScriptCommandRelay.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- ScriptCommandRelay.h 30 May 2009 04:30:33 -0000 1.1 +++ ScriptCommandRelay.h 7 Jun 2009 15:35:49 -0000 1.2 @@ -2,7 +2,7 @@ Audacity - A Digital Audio Editor Copyright 1999-2009 Audacity Team - License: GPL v2 - see LICENSE.txt + File License: wxWidgets Dan Horgan @@ -20,33 +20,37 @@ #include <wx/string.h> class CommandHandler; +class ResponseQueue; +class Response; -extern "C" { -typedef int (*tpExecScriptServerFunc)( wxString * pIn); + +typedef int (*tpExecScriptServerFunc)( wxString * pIn, wxString * pOut); typedef int (*tpRegScriptServerFunc)(tpExecScriptServerFunc pFn); -typedef int (*tpScriptServerResponseFunc)( wxString * pOut); + +extern "C" { + AUDACITY_DLL_API int ExecCommand(wxString *pIn, wxString *pOut); +} // End 'extern C' class ScriptCommandRelay { private: + // N.B. Static class members also have to be declared in the .cpp file static CommandHandler *sCmdHandler; static tpRegScriptServerFunc sScriptFn; - static tpScriptServerResponseFunc sScriptOutFn; + static ResponseQueue sResponseQueue; public: static void SetRegScriptServerFunc(tpRegScriptServerFunc scriptFn); - static void SetScriptServerResponseFunc(tpScriptServerResponseFunc scriptOutFn); static void SetCommandHandler(CommandHandler &ch); static void Run(); - AUDACITY_DLL_API static int ExecCommand( wxString * pIn ); - - static void SendResponse(wxString &pOut); + static void SendResponse(const wxString &response); + static Response ReceiveResponse(); }; -} // End 'extern C' + #endif /* End of include guard: __SCRIPTCOMMANDRELAY__ */ // Indentation settings for Vim and Emacs and unique identifier for Arch, a Index: CommandBuilder.cpp =================================================================== RCS file: /cvsroot/audacity/audacity-src/src/commands/CommandBuilder.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- CommandBuilder.cpp 30 May 2009 04:30:33 -0000 1.1 +++ CommandBuilder.cpp 7 Jun 2009 15:35:49 -0000 1.2 @@ -2,7 +2,7 @@ Audacity - A Digital Audio Editor Copyright 1999-2009 Audacity Team - License: GPL v2 - see LICENSE.txt + File License: wxWidgets Dan Horgan @@ -58,11 +58,6 @@ { /* - wxMessageOutputDebug().Printf(cmdName); - // Temp - mValid = true; - - // Split up parameters and add them to the map // The checking below should be replaced by a lookup + polymorphism @@ -78,9 +73,9 @@ // // TODO store command somewhere else... // mCommand = new EffectCommand(f); //} - */ - + // // See if the name refers to a menu command + */ mCommand = new BatchEvalCommand(cmdName, cmdParams); mValid = true; @@ -89,19 +84,18 @@ void CommandBuilder::BuildCommand(const wxString &cmdString) { - // Find the command name terminator... ignore line if not found + // Find the command name terminator... If there is more than one word and + // no terminator, the command is badly formed int splitAt = cmdString.Find(wxT(':')); - if (splitAt < 0) { + if (splitAt < 0 && cmdString.Strip(wxString::both).Find(wxT(' ')) >= 0) { mError = wxT("BAD - Missing ':'?"); - // TODO + mValid = false; + return; } wxString cmdName = cmdString.Left(splitAt).Strip(wxString::both); wxString cmdParams = cmdString.Mid(splitAt+1).Strip(wxString::both); BuildCommand(cmdName, cmdParams); - - // Temp - //mCommand = new DebugPrintCommand(cmdString); } // Indentation settings for Vim and Emacs and unique identifier for Arch, a ------------------------------------------------------------------------------ OpenSolaris 2009.06 is a cutting edge operating system for enterprises looking to deploy the next generation of Solaris that includes the latest innovations from Sun and the OpenSource community. Download a copy and enjoy capabilities such as Networking, Storage and Virtualization. Go to: http://p.sf.net/sfu/opensolaris-get _______________________________________________ Audacity-cvs mailing list Audacity-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/audacity-cvs