Skip to content

Commit

Permalink
Use PluginError or HostError for all plugin/host callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
prokopyl committed May 12, 2024
1 parent a2c38e4 commit 144c341
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 42 deletions.
4 changes: 2 additions & 2 deletions extensions/src/audio_ports_config/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ pub trait PluginAudioPortsConfigImpl {
///
/// # Error
///
/// This method may return an [`AudioPortConfigSelectError`] if the given ID is out of bounds,
/// This method may return an error if the given ID is out of bounds,
/// or if the plugin declined or failed to change its Audio Ports Configuration.
fn select(&mut self, config_id: ClapId) -> Result<(), AudioPortConfigSelectError>;
fn select(&mut self, config_id: ClapId) -> Result<(), PluginError>;
}

// SAFETY: The given struct is the CLAP extension struct for the matching side of this extension.
Expand Down
14 changes: 7 additions & 7 deletions extensions/src/gui/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,35 +307,35 @@ pub trait HostGuiImpl {
///
/// # Errors
///
/// This may return a [`GuiError::ResizeError`] if the host denied or was unable to fulfill the
/// This may return an error if the host denied or was unable to fulfill the
/// request.
///
/// Note: as this may not be called from the main thread, a successful return value may only
/// mean the Host acknowledged the request, and will process it asynchronously later. If the
/// request is later found not to be able to be satisfied, then the host will call the plugin's
/// `set_size` method to revert the operation.
fn request_resize(&self, new_size: GuiSize) -> Result<(), GuiError>;
fn request_resize(&self, new_size: GuiSize) -> Result<(), HostError>;

/// Requests the host to show the Plugin's GUI.
///
/// # Errors
///
/// This may return a [`GuiError::RequestShowError`] if the host denied or was unable to fulfill the
/// This may return an error if the host denied or was unable to fulfill the
/// request.
fn request_show(&self) -> Result<(), GuiError>;
fn request_show(&self) -> Result<(), HostError>;

/// Requests the host to hide the Plugin's GUI.
///
/// # Errors
///
/// This may return a [`GuiError::RequestHideError`] if the host denied or was unable to fulfill the
/// This may return an error if the host denied or was unable to fulfill the
/// request.
fn request_hide(&self) -> Result<(), GuiError>;
fn request_hide(&self) -> Result<(), HostError>;

/// Notifies the host that either the floating window has been closed, or that the connection to
/// the GUI was lost.
///
/// If `is_destroyed` is true, than the host must call `destroy` to acknowledge the GUI destruction.
/// If `is_destroyed` is true, then the host must call `destroy` to acknowledge the GUI destruction.
fn closed(&self, was_destroyed: bool);
}

Expand Down
16 changes: 7 additions & 9 deletions extensions/src/gui/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ pub trait PluginGuiImpl {
/// its window to stay above the parent window via [`Self::set_transient`].
///
/// If `is_floating` is false, the plugin must embed its window in the parent (host).
fn create(&mut self, configuration: GuiConfiguration) -> Result<(), GuiError>;
fn create(&mut self, configuration: GuiConfiguration) -> Result<(), PluginError>;

/// Free all resources associated with the GUI
fn destroy(&mut self);
Expand All @@ -134,9 +134,7 @@ pub trait PluginGuiImpl {
///
/// Overrides OS settings, and should not be used if the windowing API uses logical pixels. Can
/// be ignored if the plugin will query the OS directly and perform its own calculations.
fn set_scale(&mut self, scale: f64) -> Result<(), GuiError> {
Err(GuiError::SetScaleError)
}
fn set_scale(&mut self, scale: f64) -> Result<(), PluginError>;

/// Get current size of GUI
fn get_size(&mut self) -> Option<GuiSize>;
Expand All @@ -162,28 +160,28 @@ pub trait PluginGuiImpl {
}

/// Set the size of an embedded window
fn set_size(&mut self, size: GuiSize) -> Result<(), GuiError>;
fn set_size(&mut self, size: GuiSize) -> Result<(), PluginError>;

/// Embed UI into the given parent window
fn set_parent(&mut self, window: Window) -> Result<(), GuiError>;
fn set_parent(&mut self, window: Window) -> Result<(), PluginError>;

/// Receive instruction to stay above the given window
///
/// Only applies to floating windows.
fn set_transient(&mut self, window: Window) -> Result<(), GuiError>;
fn set_transient(&mut self, window: Window) -> Result<(), PluginError>;

/// Receive a suggested window title from the host
///
/// Only applies to floating windows.
fn suggest_title(&mut self, title: &str) {}

/// Show the window
fn show(&mut self) -> Result<(), GuiError>;
fn show(&mut self) -> Result<(), PluginError>;

/// Hide the window
///
/// This should not free the resources associated with the GUI, just hide it.
fn hide(&mut self) -> Result<(), GuiError>;
fn hide(&mut self) -> Result<(), PluginError>;
}

// SAFETY: The given struct is the CLAP extension struct for the matching side of this extension.
Expand Down
6 changes: 3 additions & 3 deletions extensions/src/posix_fd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@ mod host {
///
/// The host will call the plugin's `on_fd` method every time the File Descriptor fires one
/// of these events.
fn register_fd(&mut self, fd: RawFd, flags: FdFlags) -> Result<(), FdError>;
fn register_fd(&mut self, fd: RawFd, flags: FdFlags) -> Result<(), HostError>;
/// Updates the set of events a given File Descriptor will fire.
fn modify_fd(&mut self, fd: RawFd, flags: FdFlags) -> Result<(), FdError>;
fn modify_fd(&mut self, fd: RawFd, flags: FdFlags) -> Result<(), HostError>;
/// Removes a given File Descriptor from the host's event reactor.
fn unregister_fd(&mut self, fd: RawFd) -> Result<(), FdError>;
fn unregister_fd(&mut self, fd: RawFd) -> Result<(), HostError>;
}

// SAFETY: The given struct is the CLAP extension struct for the matching side of this extension.
Expand Down
6 changes: 3 additions & 3 deletions extensions/src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ mod plugin {

/// Implementation of the Plugin-side of the Render extension.
pub trait PluginRenderImpl {
/// Returns `true` if the plugin has an hard requirement to process in real-time.
/// Returns `true` if the plugin has a hard requirement to process in real-time.
///
/// This is especially useful for plugins that are acting as a proxy to hardware devices, or
/// other real-time events.
Expand All @@ -90,9 +90,9 @@ mod plugin {
///
/// # Errors
///
/// This may return [`PluginRenderError`] if the plugin either declined or failed to switch
/// This may return an error if the plugin either declined or failed to switch
/// to the given render mode.
fn set(&mut self, mode: RenderMode) -> Result<(), PluginRenderError>;
fn set(&mut self, mode: RenderMode) -> Result<(), PluginError>;
}

// SAFETY: The given struct is the CLAP extension struct for the matching side of this extension.
Expand Down
4 changes: 2 additions & 2 deletions extensions/src/thread_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ mod host {
///
/// # Errors
///
/// This method will return [`ThreadPoolRequestError`] if the host denied the request.
fn request_exec(&mut self, task_count: u32) -> Result<(), ThreadPoolRequestError>;
/// This method will return an error if the host denied the request.
fn request_exec(&mut self, task_count: u32) -> Result<(), HostError>;
}

// SAFETY: The given struct is the CLAP extension struct for the matching side of this extension.
Expand Down
8 changes: 4 additions & 4 deletions extensions/src/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ mod host {
///
/// # Errors
///
/// Returns [`TimerError::RegisterError`] if the host failed or denied to register this timer.
fn register_timer(&mut self, period_ms: u32) -> Result<TimerId, TimerError>;
/// Returns an error if the host failed or refused to register this timer.
fn register_timer(&mut self, period_ms: u32) -> Result<TimerId, HostError>;

/// Unregisters a given Timer, identified by its unique [`TimerId`].
///
Expand All @@ -201,8 +201,8 @@ mod host {
///
/// # Errors
///
/// Returns [`TimerError::UnregisterError`] if the host failed to unregister this timer.
fn unregister_timer(&mut self, timer_id: TimerId) -> Result<(), TimerError>;
/// Returns an error if the host failed to unregister this timer.
fn unregister_timer(&mut self, timer_id: TimerId) -> Result<(), HostError>;
}

// SAFETY: The given struct is the CLAP extension struct for the matching side of this extension.
Expand Down
12 changes: 6 additions & 6 deletions host/examples/cpal/src/host/gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ impl HostGuiImpl for CpalHostShared {
// We don't support any resize hints
}

fn request_resize(&self, new_size: GuiSize) -> Result<(), GuiError> {
self.sender
.send(MainThreadMessage::GuiRequestResized { new_size })
.map_err(|_| GuiError::RequestResizeError)
fn request_resize(&self, new_size: GuiSize) -> Result<(), HostError> {
Ok(self
.sender
.send(MainThreadMessage::GuiRequestResized { new_size })?)
}

fn request_show(&self) -> Result<(), GuiError> {
fn request_show(&self) -> Result<(), HostError> {
// We never hide the window, so showing it again does nothing.
Ok(())
}

fn request_hide(&self) -> Result<(), GuiError> {
fn request_hide(&self) -> Result<(), HostError> {
Ok(())
}

Expand Down
10 changes: 5 additions & 5 deletions host/examples/cpal/src/host/timer.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
use crate::host::CpalHostMainThread;
use clack_extensions::timer::{HostTimerImpl, PluginTimer, TimerError, TimerId};
use clack_host::prelude::PluginMainThreadHandle;
use clack_extensions::timer::{HostTimerImpl, PluginTimer, TimerId};
use clack_host::prelude::{HostError, PluginMainThreadHandle};
use std::cell::{Cell, RefCell};
use std::collections::HashMap;
use std::time::{Duration, Instant};

impl<'a> HostTimerImpl for CpalHostMainThread<'a> {
fn register_timer(&mut self, period_ms: u32) -> Result<TimerId, TimerError> {
fn register_timer(&mut self, period_ms: u32) -> Result<TimerId, HostError> {
Ok(self
.timers
.register_new(Duration::from_millis(period_ms as u64)))
}

fn unregister_timer(&mut self, timer_id: TimerId) -> Result<(), TimerError> {
fn unregister_timer(&mut self, timer_id: TimerId) -> Result<(), HostError> {
if self.timers.unregister(timer_id) {
Ok(())
} else {
Err(TimerError::UnregisterError)
Err(HostError::Message("Unknown timer ID"))
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion host/src/extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ pub mod prelude {
Extension, ExtensionImplementation, HostExtensionSide, PluginExtensionSide,
RawExtension, RawExtensionImplementation,
},
host::HostHandlers,
host::{HostError, HostHandlers},
plugin::{PluginAudioProcessorHandle, PluginMainThreadHandle, PluginSharedHandle},
utils::ClapId,
};
Expand Down

0 comments on commit 144c341

Please sign in to comment.