1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-08-07 07:39:29 +02:00
audacity/src/commands/ResponseQueue.h
James Crook be0e6cd605 Scripting: Unicode chars in responses are now OK.
This is also relevant to batch scripting.  We need to stay in UTF8 to be safe.
Thanks to Robert Hänggi for reporting this issue.
2018-01-17 17:49:43 +00:00

75 lines
1.8 KiB
C++

/**********************************************************************
Audacity - A Digital Audio Editor
Copyright 1999-2009 Audacity Team
License: wxWidgets
Dan Horgan
******************************************************************//**
\file ResponseQueue.h
\brief Contains declarations for Response and ResponseQueue classes
*//****************************************************************//**
\class Response
\brief Stores a command response string (and other response data if it becomes
necessary)
The string is internally stored as a std::string rather than wxString
because of thread-safety concerns.
*//****************************************************************//**
\class ResponseQueue
\brief Allow messages to be sent from the main thread to the script thread
Based roughly on wxMessageQueue<T> (which hasn't reached the stable wxwidgets
yet). Wraps a std::queue<Response> inside a wxMutex with a wxCondition to
force the script thread to wait until a response is available.
*//*******************************************************************/
#ifndef __RESPONSEQUEUE__
#define __RESPONSEQUEUE__
#include <queue>
#include <string>
#include <wx/thread.h>
#include <wx/string.h>
class wxMutex;
class wxCondition;
class wxMutexLocker;
class Response {
private:
std::string mMessage;
public:
Response(const wxString &response)
: mMessage(response.utf8_str())
{ }
wxString GetMessage()
{
return wxString(mMessage.c_str(), wxConvUTF8);
}
};
class ResponseQueue {
private:
std::queue<Response> mResponses;
wxMutex mMutex;
wxCondition mCondition;
public:
ResponseQueue();
~ResponseQueue();
void AddResponse(Response response);
Response WaitAndGetResponse();
};
#endif /* End of include guard: __RESPONSEQUEUE__ */