33 public std::enable_shared_from_this<Impl>
59 auto server = std::make_unique<IPCServer>(*
this);
61 throw std::runtime_error(
"cannot start plugin host process");
62 mLastTimeActive = std::chrono::system_clock::now().time_since_epoch().count();
72 if(
auto self = wptr.lock(); self && self->mDelegate !=
nullptr)
73 self->mDelegate->OnInternalError(msg);
88 if(
auto self = wptr.lock())
90 if(self->mDelegate == nullptr)
95 std::optional<wxString> request;
97 std::lock_guard lck_sync(self->mSync);
98 self->mRequest.swap(request);
101 if(!request.has_value())
104 self->mDelegate->OnInternalError(result.GetErrorMessage());
110 for(auto& desc : result.GetDescriptors())
111 self->mDelegate->OnPluginFound(PluginDescriptor { desc });
119 self->mDelegate->OnPluginValidationFailed(providerId, pluginPath);
121 self->mDelegate->OnValidationFinished();
150 mDelegate = delegate;
155 using std::chrono::system_clock;
157 return system_clock::time_point { system_clock::duration{mLastTimeActive.load()} };
162 std::lock_guard lck(mSync);
173 HandleInternalError(
"Can't send message to host");
181 std::lock_guard lck(mSync);
186 HandleResult(std::move(result));
191 HandleInternalError(
"Can't connect");
198 mMessageReader.ConsumeBytes(data,
size);
199 mLastTimeActive = std::chrono::system_clock::now().time_since_epoch().count();
200 while(mMessageReader.CanPop())
202 auto message = mMessageReader.Pop();
203 if(message.IsEmpty())
210 HandleResult(std::move(result));
215 HandleInternalError(
"Can't process response from the host");
219 void Validate(
const wxString& providerId,
const wxString& pluginPath)
221 std::lock_guard lck(mSync);
224 assert(!mRequest.has_value());
237 mImpl = std::make_unique<Impl>(delegate);
244 mImpl->Validate(providerId, pluginPath);
249 mImpl->SetDelegate(delegate);
254 return mImpl->InactiveSince();
Toolkit-neutral facade for basic user interface services.
Used to talk back to calling side.
void HandleInternalError(const wxString &msg) noexcept
void SetDelegate(Delegate *delegate)
void Validate(const wxString &providerId, const wxString &pluginPath)
void OnDisconnect() noexcept override
Invalidates IPCChannel passed as argument in OnConnect.
void OnConnectionError() noexcept override
Called when connection attempt fails.
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....
Impl & operator=(Impl &&)=delete
std::unique_ptr< IPCServer > mServer
std::optional< wxString > mRequest
std::atomic< std::chrono::system_clock::duration::rep > mLastTimeActive
void OnConnect(IPCChannel &channel) noexcept override
Called when connection established.
detail::InputMessageReader mMessageReader
Impl & operator=(Impl &)=delete
std::chrono::system_clock::time_point InactiveSince() const noexcept
void HandleResult(detail::PluginValidationResult &&result) noexcept
void Validate(const wxString &providerId, const wxString &pluginPath)
Each call to Validate should result in appropriate call OnValidationFinished, until then it's not all...
void SetDelegate(Delegate *delegate)
std::shared_ptr< Impl > mImpl
std::chrono::system_clock::time_point InactiveSince() const noexcept
AsyncPluginValidator(AsyncPluginValidator &)=delete
Interface for sending data from client to server or vice versa, complemented by IPCChannelStatusCallb...
Interface for listening connection status changes.
static bool Start(int connectPort)
Attempts to start a host application (should be called from the main application)
Reads a file and passes the results through an XMLTagHandler.
bool ParseString(XMLTagHandler *baseHandler, const wxString &xmldata)
void SetError(const wxString &msg)
Intended for locking of resources that are only lightly contended and locked for very short times,...
void CallAfter(Action action)
Schedule an action to be done later, and in the main thread.
bool ParseRequestString(const wxString &req, wxString &providerId, wxString &pluginPath)
void PutMessage(IPCChannel &channel, const wxString &value)
wxString MakeRequestString(const wxString &providerId, const wxString &pluginPath)