Audacity 3.2.0
Public Member Functions | Private Member Functions | Private Attributes | List of all members
AsyncPluginValidator::Impl Class Referencefinal
Inheritance diagram for AsyncPluginValidator::Impl:
[legend]
Collaboration diagram for AsyncPluginValidator::Impl:
[legend]

Public Member Functions

 Impl (Impl &)=delete
 
 Impl (Impl &&)=delete
 
Imploperator= (Impl &)=delete
 
Imploperator= (Impl &&)=delete
 
 Impl (Delegate &delegate)
 
 ~Impl () override
 
void SetDelegate (Delegate *delegate)
 
std::chrono::system_clock::time_point InactiveSince () const noexcept
 
void OnConnect (IPCChannel &channel) noexcept override
 Called when connection established. More...
 
void OnDisconnect () noexcept override
 Invalidates IPCChannel passed as argument in OnConnect. More...
 
void OnConnectionError () noexcept override
 Called when connection attempt fails. More...
 
void OnDataAvailable (const void *data, size_t size) noexcept override
 Called when data chunk received as a result of a preceding call to IPCChannel::Send. Generally, data pointer should not be accessed outside this method, copied if necessary. More...
 
void Validate (const wxString &providerId, const wxString &pluginPath)
 
- Public Member Functions inherited from IPCChannelStatusCallback
virtual ~IPCChannelStatusCallback ()
 
virtual void OnConnectionError () noexcept=0
 Called when connection attempt fails. More...
 
virtual void OnConnect (IPCChannel &channel) noexcept=0
 Called when connection established. More...
 
virtual void OnDisconnect () noexcept=0
 Invalidates IPCChannel passed as argument in OnConnect. More...
 
virtual void OnDataAvailable (const void *data, size_t size) noexcept=0
 Called when data chunk received as a result of a preceding call to IPCChannel::Send. Generally, data pointer should not be accessed outside this method, copied if necessary. More...
 

Private Member Functions

void StartHost ()
 
void HandleInternalError (const wxString &msg) noexcept
 
void HandleResult (detail::PluginValidationResult &&result) noexcept
 

Private Attributes

IPCChannelmChannel {nullptr}
 
std::optional< wxString > mRequest
 
std::atomic< std::chrono::system_clock::duration::rep > mLastTimeActive
 
spinlock mSync
 
DelegatemDelegate {nullptr}
 
std::unique_ptr< IPCServermServer
 
detail::InputMessageReader mMessageReader
 

Detailed Description

Definition at line 31 of file AsyncPluginValidator.cpp.

Constructor & Destructor Documentation

◆ Impl() [1/3]

AsyncPluginValidator::Impl::Impl ( Impl )
delete

◆ Impl() [2/3]

AsyncPluginValidator::Impl::Impl ( Impl &&  )
delete

◆ Impl() [3/3]

AsyncPluginValidator::Impl::Impl ( Delegate delegate)
inline

Definition at line 138 of file AsyncPluginValidator.cpp.

138: mDelegate(&delegate) { }

◆ ~Impl()

AsyncPluginValidator::Impl::~Impl ( )
inlineoverride

Definition at line 140 of file AsyncPluginValidator.cpp.

141 {
142 //important to reset delegate before IPCChannelStatusCallback::OnDisconnect
143 //is called by server
144 mDelegate = nullptr;
145 mServer.reset();
146 }
std::unique_ptr< IPCServer > mServer

Member Function Documentation

◆ HandleInternalError()

void AsyncPluginValidator::Impl::HandleInternalError ( const wxString &  msg)
inlineprivatenoexcept

Definition at line 66 of file AsyncPluginValidator.cpp.

67 {
68 try
69 {
70 BasicUI::CallAfter([wptr = weak_from_this(), msg]
71 {
72 if(auto self = wptr.lock(); self && self->mDelegate != nullptr)
73 self->mDelegate->OnInternalError(msg);
74 });
75 }
76 catch(...)
77 {
78 //no way to report about a problem, though shouldn't be the case...
79 }
80 }
void CallAfter(Action action)
Schedule an action to be done later, and in the main thread.
Definition: BasicUI.cpp:214

References BasicUI::CallAfter().

Here is the call graph for this function:

◆ HandleResult()

void AsyncPluginValidator::Impl::HandleResult ( detail::PluginValidationResult &&  result)
inlineprivatenoexcept

no way to report about a problem, though shouldn't be the case...

Definition at line 82 of file AsyncPluginValidator.cpp.

83 {
84 try
85 {
86 BasicUI::CallAfter([wptr = weak_from_this(), result = detail::PluginValidationResult { result }]
87 {
88 if(auto self = wptr.lock())
89 {
90 if(self->mDelegate == nullptr)
91 return;
92
93 //Release the current value to keep state invariant
94 //Caller is free to use Validate now
95 std::optional<wxString> request;
96 {
97 std::lock_guard lck_sync(self->mSync);
98 self->mRequest.swap(request);
99 }
100
101 if(!request.has_value())
102 {
103 //Invalid state error
104 self->mDelegate->OnInternalError(result.GetErrorMessage());
105 return;
106 }
107
108 if(result.IsValid())
109 {
110 for(auto& desc : result.GetDescriptors())
111 self->mDelegate->OnPluginFound(PluginDescriptor { desc });
112 }
113 else
114 {
115 wxString providerId;
116 wxString pluginPath;
117 detail::ParseRequestString(*request, providerId, pluginPath);
118
119 self->mDelegate->OnPluginValidationFailed(providerId, pluginPath);
120 }
121 self->mDelegate->OnValidationFinished();
122 }
123 });
124 }
125 catch(...)
126 {
128 }
129 }
bool IsValid() const noexcept
bool ParseRequestString(const wxString &req, wxString &providerId, wxString &pluginPath)

References BasicUI::CallAfter(), and detail::ParseRequestString().

Here is the call graph for this function:

◆ InactiveSince()

std::chrono::system_clock::time_point AsyncPluginValidator::Impl::InactiveSince ( ) const
inlinenoexcept

Definition at line 153 of file AsyncPluginValidator.cpp.

154 {
155 using std::chrono::system_clock;
156
157 return system_clock::time_point { system_clock::duration{mLastTimeActive.load()} };
158 }
std::atomic< std::chrono::system_clock::duration::rep > mLastTimeActive

◆ OnConnect()

void AsyncPluginValidator::Impl::OnConnect ( IPCChannel channel)
inlineoverridevirtualnoexcept

Called when connection established.

Parameters
channelUsing this channel client or server can send data to the other side.

Implements IPCChannelStatusCallback.

Definition at line 160 of file AsyncPluginValidator.cpp.

161 {
162 std::lock_guard lck(mSync);
163
164 mChannel = &channel;
165 if(mRequest)
166 {
167 try
168 {
169 detail::PutMessage(channel, *mRequest);
170 }
171 catch(...)
172 {
173 HandleInternalError("Can't send message to host");
174 }
175 }
176 }
void HandleInternalError(const wxString &msg) noexcept
std::optional< wxString > mRequest
void PutMessage(IPCChannel &channel, const wxString &value)

References detail::PutMessage().

Here is the call graph for this function:

◆ OnConnectionError()

void AsyncPluginValidator::Impl::OnConnectionError ( )
inlineoverridevirtualnoexcept

Called when connection attempt fails.

Implements IPCChannelStatusCallback.

Definition at line 189 of file AsyncPluginValidator.cpp.

190 {
191 HandleInternalError("Can't connect");
192 }

◆ OnDataAvailable()

void AsyncPluginValidator::Impl::OnDataAvailable ( const void *  data,
size_t  size 
)
inlineoverridevirtualnoexcept

Called when data chunk received as a result of a preceding call to IPCChannel::Send. Generally, data pointer should not be accessed outside this method, copied if necessary.

Parameters
dataPointer to the chunk
sizeSize of the chunk

Implements IPCChannelStatusCallback.

Definition at line 194 of file AsyncPluginValidator.cpp.

195 {
196 try
197 {
199 mLastTimeActive = std::chrono::system_clock::now().time_since_epoch().count();
200 while(mMessageReader.CanPop())
201 {
202 auto message = mMessageReader.Pop();
203 if(message.IsEmpty())
204 continue;
205
207 XMLFileReader xmlReader;
208 xmlReader.ParseString(&result, message);
209
210 HandleResult(std::move(result));
211 }
212 }
213 catch(...)
214 {
215 HandleInternalError("Can't process response from the host");
216 }
217 }
detail::InputMessageReader mMessageReader
void HandleResult(detail::PluginValidationResult &&result) noexcept
Reads a file and passes the results through an XMLTagHandler.
Definition: XMLFileReader.h:19
bool ParseString(XMLTagHandler *baseHandler, const wxString &xmldata)
void ConsumeBytes(const void *bytes, size_t length)
fills internal buffer
bool CanPop() const noexcept

References XMLFileReader::ParseString(), and size.

Here is the call graph for this function:

◆ OnDisconnect()

void AsyncPluginValidator::Impl::OnDisconnect ( )
inlineoverridevirtualnoexcept

Invalidates IPCChannel passed as argument in OnConnect.

Implements IPCChannelStatusCallback.

Definition at line 178 of file AsyncPluginValidator.cpp.

179 {
180 {
181 std::lock_guard lck(mSync);
182 mChannel = nullptr;
183 }
185 result.SetError("Disconnect");
186 HandleResult(std::move(result));
187 }
void SetError(const wxString &msg)

References detail::PluginValidationResult::SetError().

Here is the call graph for this function:

◆ operator=() [1/2]

Impl & AsyncPluginValidator::Impl::operator= ( Impl &&  )
delete

◆ operator=() [2/2]

Impl & AsyncPluginValidator::Impl::operator= ( Impl )
delete

◆ SetDelegate()

void AsyncPluginValidator::Impl::SetDelegate ( Delegate delegate)
inline

Definition at line 148 of file AsyncPluginValidator.cpp.

149 {
150 mDelegate = delegate;
151 }

◆ StartHost()

void AsyncPluginValidator::Impl::StartHost ( )
inlineprivate

Definition at line 57 of file AsyncPluginValidator.cpp.

58 {
59 auto server = std::make_unique<IPCServer>(*this);
60 if(!PluginHost::Start(server->GetConnectPort()))
61 throw std::runtime_error("cannot start plugin host process");
62 mLastTimeActive = std::chrono::system_clock::now().time_since_epoch().count();
63 mServer = std::move(server);
64 }
static bool Start(int connectPort)
Attempts to start a host application (should be called from the main application)
Definition: PluginHost.cpp:184

References mLastTimeActive, mServer, and PluginHost::Start().

Here is the call graph for this function:

◆ Validate()

void AsyncPluginValidator::Impl::Validate ( const wxString &  providerId,
const wxString &  pluginPath 
)
inline

Definition at line 219 of file AsyncPluginValidator.cpp.

220 {
221 std::lock_guard lck(mSync);
222
223 //one request at a time
224 assert(!mRequest.has_value());
225
226 mRequest = detail::MakeRequestString(providerId, pluginPath);
227 if(mChannel)
229 else
230 //create host process on demand
231 StartHost();
232 }
wxString MakeRequestString(const wxString &providerId, const wxString &pluginPath)

References detail::MakeRequestString(), and detail::PutMessage().

Here is the call graph for this function:

Member Data Documentation

◆ mChannel

IPCChannel* AsyncPluginValidator::Impl::mChannel {nullptr}
private

Definition at line 37 of file AsyncPluginValidator.cpp.

◆ mDelegate

Delegate* AsyncPluginValidator::Impl::mDelegate {nullptr}
private

Definition at line 49 of file AsyncPluginValidator.cpp.

◆ mLastTimeActive

std::atomic<std::chrono::system_clock::duration::rep> AsyncPluginValidator::Impl::mLastTimeActive
private

Definition at line 39 of file AsyncPluginValidator.cpp.

Referenced by StartHost().

◆ mMessageReader

detail::InputMessageReader AsyncPluginValidator::Impl::mMessageReader
private

Definition at line 54 of file AsyncPluginValidator.cpp.

◆ mRequest

std::optional<wxString> AsyncPluginValidator::Impl::mRequest
private

Definition at line 38 of file AsyncPluginValidator.cpp.

◆ mServer

std::unique_ptr<IPCServer> AsyncPluginValidator::Impl::mServer
private

Definition at line 50 of file AsyncPluginValidator.cpp.

Referenced by StartHost().

◆ mSync

spinlock AsyncPluginValidator::Impl::mSync
private

Definition at line 45 of file AsyncPluginValidator.cpp.


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