Add register_audio_cache to pmoplaylist (fix circular dependency)
Fix "PlaylistManager not initialized" error without creating circular dependency between pmoparadise and pmoupnp. Changes: - Add AUDIO_CACHE static to pmoplaylist/manager.rs - Add register_audio_cache() function to register cache - Export register_audio_cache from pmoplaylist lib.rs - Update audio_cache() to check local registry first, then pmoupnp - Update play_and_cache example to use pmoplaylist::register_audio_cache - Remove pmoupnp::register_*_cache functions (not needed) The example now calls pmoplaylist::register_audio_cache() to make the cache available for pk validation in WriteHandle::push().
This commit is contained in:
@@ -100,11 +100,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
)?);
|
||||
tracing::debug!("Cover cache initialized at: {}", cover_cache_dir);
|
||||
|
||||
// Enregistrer les caches dans le registre global pmoupnp
|
||||
// Enregistrer le cache audio dans pmoplaylist
|
||||
// (requis par pmoplaylist pour valider les pks)
|
||||
pmoupnp::register_audio_cache(audio_cache.clone());
|
||||
pmoupnp::register_cover_cache(cover_cache.clone());
|
||||
tracing::debug!("Caches registered in pmoupnp global registry");
|
||||
pmoplaylist::register_audio_cache(audio_cache.clone());
|
||||
tracing::debug!("Audio cache registered in pmoplaylist");
|
||||
|
||||
// Utiliser le gestionnaire de playlist singleton
|
||||
tracing::info!("Getting playlist manager...");
|
||||
|
||||
@@ -57,7 +57,7 @@ mod config_ext;
|
||||
// Réexports publics
|
||||
pub use error::{Error, Result};
|
||||
pub use handle::{ReadHandle, WriteHandle};
|
||||
pub use manager::{PlaylistManager, PlaylistManager as Manager};
|
||||
pub use manager::{register_audio_cache, PlaylistManager, PlaylistManager as Manager};
|
||||
pub use track::PlaylistTrack;
|
||||
|
||||
#[cfg(feature = "pmoconfig")]
|
||||
|
||||
@@ -15,6 +15,9 @@ use tokio::sync::RwLock;
|
||||
/// Singleton PlaylistManager
|
||||
static PLAYLIST_MANAGER: OnceCell<PlaylistManager> = OnceCell::new();
|
||||
|
||||
/// Registre global du cache audio
|
||||
static AUDIO_CACHE: OnceCell<Arc<pmoaudiocache::Cache>> = OnceCell::new();
|
||||
|
||||
/// Structure interne du manager
|
||||
struct ManagerInner {
|
||||
playlists: RwLock<HashMap<String, Arc<Playlist>>>,
|
||||
@@ -284,9 +287,35 @@ pub(crate) async fn delete_playlist_internal(id: &str) -> Result<()> {
|
||||
PlaylistManager::get().delete_playlist(id).await
|
||||
}
|
||||
|
||||
/// Enregistre le cache audio global
|
||||
///
|
||||
/// Cette fonction doit être appelée au démarrage de l'application
|
||||
/// pour rendre le cache audio disponible au PlaylistManager.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```rust,ignore
|
||||
/// use pmoplaylist::register_audio_cache;
|
||||
/// use pmoaudiocache::Cache as AudioCache;
|
||||
/// use std::sync::Arc;
|
||||
///
|
||||
/// let audio_cache = Arc::new(AudioCache::new("./cache", 1000)?);
|
||||
/// register_audio_cache(audio_cache);
|
||||
/// ```
|
||||
pub fn register_audio_cache(cache: Arc<pmoaudiocache::Cache>) {
|
||||
let _ = AUDIO_CACHE.set(cache);
|
||||
}
|
||||
|
||||
/// Helper pour acc<63>der au cache audio
|
||||
pub(crate) fn audio_cache() -> Result<Arc<pmoaudiocache::Cache>> {
|
||||
pmoupnp::get_audio_cache().ok_or_else(|| crate::Error::ManagerNotInitialized)
|
||||
AUDIO_CACHE
|
||||
.get()
|
||||
.cloned()
|
||||
.or_else(|| {
|
||||
// Fallback: essayer pmoupnp si disponible
|
||||
pmoupnp::get_audio_cache()
|
||||
})
|
||||
.ok_or_else(|| crate::Error::ManagerNotInitialized)
|
||||
}
|
||||
|
||||
/// Fonction raccourcie pour acc<63>der au singleton
|
||||
|
||||
Reference in New Issue
Block a user