1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-25 16:48:44 +02:00
audacity/src/commands/ResponseQueue.h
martynshaw99 4ce2643d5f Remove the
// Indentation settings for Vim and Emacs
etc. lines from all files, as Campbell's patch (except for other changes to Languages.cpp)
2013-09-24 00:14:37 +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.mb_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__ */