Audacity 3.2.0
Public Member Functions | Private Attributes | List of all members
ResponseQueue Class Reference

Allow messages to be sent from the main thread to the script thread. More...

#include <ResponseQueue.h>

Collaboration diagram for ResponseQueue:
[legend]

Public Member Functions

 ResponseQueue ()
 
 ~ResponseQueue ()
 
void AddResponse (Response response)
 
Response WaitAndGetResponse ()
 

Private Attributes

std::queue< ResponsemResponses
 
wxMutex mMutex
 
wxCondition mCondition
 

Detailed Description

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.

Definition at line 60 of file ResponseQueue.h.

Constructor & Destructor Documentation

◆ ResponseQueue()

ResponseQueue::ResponseQueue ( )

Definition at line 22 of file ResponseQueue.cpp.

24{ }
wxMutex mMutex
Definition: ResponseQueue.h:63
wxCondition mCondition
Definition: ResponseQueue.h:64

◆ ~ResponseQueue()

ResponseQueue::~ResponseQueue ( )

Definition at line 26 of file ResponseQueue.cpp.

27{ }

Member Function Documentation

◆ AddResponse()

void ResponseQueue::AddResponse ( Response  response)

Definition at line 29 of file ResponseQueue.cpp.

30{
31 wxMutexLocker locker(mMutex);
32 mResponses.push(response);
33 mCondition.Signal();
34}
std::queue< Response > mResponses
Definition: ResponseQueue.h:62

References mCondition, mMutex, and mResponses.

◆ WaitAndGetResponse()

Response ResponseQueue::WaitAndGetResponse ( )

Definition at line 36 of file ResponseQueue.cpp.

37{
38 wxMutexLocker locker(mMutex);
39 if (mResponses.empty())
40 {
41 mCondition.Wait();
42 }
43 wxASSERT(!mResponses.empty());
44 Response msg = mResponses.front();
45 mResponses.pop();
46 return msg;
47}
Stores a command response string (and other response data if it becomes necessary)
Definition: ResponseQueue.h:46

References mCondition, mMutex, and mResponses.

Member Data Documentation

◆ mCondition

wxCondition ResponseQueue::mCondition
private

Definition at line 64 of file ResponseQueue.h.

Referenced by AddResponse(), and WaitAndGetResponse().

◆ mMutex

wxMutex ResponseQueue::mMutex
private

Definition at line 63 of file ResponseQueue.h.

Referenced by AddResponse(), and WaitAndGetResponse().

◆ mResponses

std::queue<Response> ResponseQueue::mResponses
private

Definition at line 62 of file ResponseQueue.h.

Referenced by AddResponse(), and WaitAndGetResponse().


The documentation for this class was generated from the following files: