[vlc-devel] [PATCH 4/5] medialibrary: Plug events to the core API
Hugo Beauzée-Luyssen
hugo at beauzee.fr
Thu Aug 16 17:55:13 CEST 2018
---
modules/misc/medialibrary/medialib.cpp | 152 +++++++++++++++++++++----
1 file changed, 127 insertions(+), 25 deletions(-)
diff --git a/modules/misc/medialibrary/medialib.cpp b/modules/misc/medialibrary/medialib.cpp
index 7f4fac7eaa..644c53f1c6 100644
--- a/modules/misc/medialibrary/medialib.cpp
+++ b/modules/misc/medialibrary/medialib.cpp
@@ -67,104 +67,206 @@ private:
vlc_object_t* m_obj;
};
-void MediaLibrary::onMediaAdded( std::vector<medialibrary::MediaPtr> )
+namespace
{
+
+void assignToEvent( vlc_ml_event_t* ev, vlc_ml_media_t* m ) { ev->modification.p_media = m; }
+void assignToEvent( vlc_ml_event_t* ev, vlc_ml_artist_t* a ) { ev->modification.p_artist = a; }
+void assignToEvent( vlc_ml_event_t* ev, vlc_ml_album_t* a ) { ev->modification.p_album = a; }
+void assignToEvent( vlc_ml_event_t* ev, vlc_ml_genre_t* g ) { ev->modification.p_genre = g; }
+void assignToEvent( vlc_ml_event_t* ev, vlc_ml_playlist_t* p ) { ev->modification.p_playlist = p; }
+
+template <typename To, typename From>
+void wrapEntityEventCallback( vlc_medialibrary_module_t* ml,
+ const std::vector<From>& entities, vlc_ml_event_type evType )
+{
+ vlc_ml_event_t ev;
+ ev.i_type = evType;
+ for ( const auto& e : entities )
+ {
+ auto val = vlc::wrap_cptr<To>( static_cast<To*>( malloc( sizeof( To ) ) ),
+ static_cast<void(*)(To*)>( vlc_ml_release ) );
+ if ( unlikely( val == nullptr ) )
+ return;
+ if ( Convert( e.get(), *val ) == false )
+ return;
+ assignToEvent( &ev, val.get() );
+ ml->cbs->pf_send_event( ml, &ev );
+ }
+}
+
+void wrapEntityDeletedEventCallback( vlc_medialibrary_module_t* ml,
+ const std::vector<int64_t>& ids, vlc_ml_event_type evType )
+{
+ vlc_ml_event_t ev;
+ ev.i_type = evType;
+ for ( const auto& id : ids )
+ {
+ ev.deletion.i_entity_id = id;
+ ml->cbs->pf_send_event( ml, &ev );
+ }
+}
+
+} // end of anonymous namespace
+
+void MediaLibrary::onMediaAdded( std::vector<medialibrary::MediaPtr> media )
+{
+ wrapEntityEventCallback<vlc_ml_media_t>( m_vlc_ml, media, VLC_ML_EVENT_MEDIA_ADDED );
}
-void MediaLibrary::onMediaModified( std::vector<medialibrary::MediaPtr> )
+void MediaLibrary::onMediaModified( std::vector<medialibrary::MediaPtr> media )
{
+ wrapEntityEventCallback<vlc_ml_media_t>( m_vlc_ml, media, VLC_ML_EVENT_MEDIA_UPDATED );
}
-void MediaLibrary::onMediaDeleted( std::vector<int64_t> )
+void MediaLibrary::onMediaDeleted( std::vector<int64_t> mediaIds )
{
+ wrapEntityDeletedEventCallback( m_vlc_ml, mediaIds, VLC_ML_EVENT_MEDIA_DELETED );
}
-void MediaLibrary::onArtistsAdded( std::vector<medialibrary::ArtistPtr> )
+void MediaLibrary::onArtistsAdded( std::vector<medialibrary::ArtistPtr> artists )
{
+ wrapEntityEventCallback<vlc_ml_artist_t>( m_vlc_ml, artists, VLC_ML_EVENT_ARTIST_ADDED );
}
-void MediaLibrary::onArtistsModified( std::vector<medialibrary::ArtistPtr> )
+void MediaLibrary::onArtistsModified( std::vector<medialibrary::ArtistPtr> artists )
{
+ wrapEntityEventCallback<vlc_ml_artist_t>( m_vlc_ml, artists, VLC_ML_EVENT_ARTIST_UPDATED );
}
-void MediaLibrary::onArtistsDeleted( std::vector<int64_t> )
+void MediaLibrary::onArtistsDeleted( std::vector<int64_t> artistIds )
{
+ wrapEntityDeletedEventCallback( m_vlc_ml, artistIds, VLC_ML_EVENT_ARTIST_DELETED );
}
-void MediaLibrary::onAlbumsAdded( std::vector<medialibrary::AlbumPtr> )
+void MediaLibrary::onAlbumsAdded( std::vector<medialibrary::AlbumPtr> albums )
{
+ wrapEntityEventCallback<vlc_ml_album_t>( m_vlc_ml, albums, VLC_ML_EVENT_ALBUM_ADDED );
}
-void MediaLibrary::onAlbumsModified( std::vector<medialibrary::AlbumPtr> )
+void MediaLibrary::onAlbumsModified( std::vector<medialibrary::AlbumPtr> albums )
{
+ wrapEntityEventCallback<vlc_ml_album_t>( m_vlc_ml, albums, VLC_ML_EVENT_ALBUM_UPDATED );
}
-void MediaLibrary::onAlbumsDeleted( std::vector<int64_t> )
+void MediaLibrary::onAlbumsDeleted( std::vector<int64_t> albumIds )
{
+ wrapEntityDeletedEventCallback( m_vlc_ml, albumIds, VLC_ML_EVENT_ALBUM_DELETED );
}
-void MediaLibrary::onPlaylistsAdded( std::vector<medialibrary::PlaylistPtr> )
+void MediaLibrary::onPlaylistsAdded( std::vector<medialibrary::PlaylistPtr> playlists )
{
+ wrapEntityEventCallback<vlc_ml_playlist_t>( m_vlc_ml, playlists, VLC_ML_EVENT_PLAYLIST_ADDED );
}
-void MediaLibrary::onPlaylistsModified( std::vector<medialibrary::PlaylistPtr> )
+void MediaLibrary::onPlaylistsModified( std::vector<medialibrary::PlaylistPtr> playlists )
{
+ wrapEntityEventCallback<vlc_ml_playlist_t>( m_vlc_ml, playlists, VLC_ML_EVENT_PLAYLIST_UPDATED );
}
-void MediaLibrary::onPlaylistsDeleted( std::vector<int64_t> )
+void MediaLibrary::onPlaylistsDeleted( std::vector<int64_t> playlistIds )
{
+ wrapEntityDeletedEventCallback( m_vlc_ml, playlistIds, VLC_ML_EVENT_PLAYLIST_DELETED );
}
-void MediaLibrary::onGenresAdded( std::vector<medialibrary::GenrePtr> )
+void MediaLibrary::onGenresAdded( std::vector<medialibrary::GenrePtr> genres )
{
+ wrapEntityEventCallback<vlc_ml_genre_t>( m_vlc_ml, genres, VLC_ML_EVENT_GENRE_ADDED );
}
-void MediaLibrary::onGenresModified( std::vector<medialibrary::GenrePtr> )
+void MediaLibrary::onGenresModified( std::vector<medialibrary::GenrePtr> genres )
{
+ wrapEntityEventCallback<vlc_ml_genre_t>( m_vlc_ml, genres, VLC_ML_EVENT_GENRE_UPDATED );
}
-void MediaLibrary::onGenresDeleted( std::vector<int64_t> )
+void MediaLibrary::onGenresDeleted( std::vector<int64_t> genreIds )
{
+ wrapEntityDeletedEventCallback( m_vlc_ml, genreIds, VLC_ML_EVENT_GENRE_DELETED );
}
-void MediaLibrary::onDiscoveryStarted( const std::string& )
+void MediaLibrary::onDiscoveryStarted( const std::string& entryPoint )
{
+ vlc_ml_event_t ev;
+ ev.i_type = VLC_ML_EVENT_DISCOVERY_STARTED;
+ ev.discovery.psz_entry_point = entryPoint.c_str();
+ m_vlc_ml->cbs->pf_send_event( m_vlc_ml, &ev );
}
-void MediaLibrary::onDiscoveryProgress( const std::string& )
+void MediaLibrary::onDiscoveryProgress( const std::string& entryPoint )
{
+ vlc_ml_event_t ev;
+ ev.i_type = VLC_ML_EVENT_DISCOVERY_PROGRESS;
+ ev.discovery.psz_entry_point = entryPoint.c_str();
+ m_vlc_ml->cbs->pf_send_event( m_vlc_ml, &ev );
}
-void MediaLibrary::onDiscoveryCompleted( const std::string&, bool )
+void MediaLibrary::onDiscoveryCompleted( const std::string& entryPoint, bool success )
{
+ vlc_ml_event_t ev;
+ ev.i_type = VLC_ML_EVENT_DISCOVERY_COMPLETED;
+ ev.discovery.psz_entry_point = entryPoint.c_str();
+ ev.discovery.b_success = success;
+ m_vlc_ml->cbs->pf_send_event( m_vlc_ml, &ev );
}
-void MediaLibrary::onReloadStarted( const std::string& )
+void MediaLibrary::onReloadStarted( const std::string& entryPoint )
{
+ vlc_ml_event_t ev;
+ ev.i_type = VLC_ML_EVENT_RELOAD_STARTED;
+ ev.discovery.psz_entry_point = entryPoint.c_str();
+ m_vlc_ml->cbs->pf_send_event( m_vlc_ml, &ev );
}
-void MediaLibrary::onReloadCompleted(const std::string&, bool )
+void MediaLibrary::onReloadCompleted( const std::string& entryPoint, bool success )
{
+ vlc_ml_event_t ev;
+ ev.i_type = VLC_ML_EVENT_RELOAD_COMPLETED;
+ ev.discovery.psz_entry_point = entryPoint.c_str();
+ ev.discovery.b_success = success;
+ m_vlc_ml->cbs->pf_send_event( m_vlc_ml, &ev );
}
-void MediaLibrary::onEntryPointRemoved( const std::string&, bool )
+void MediaLibrary::onEntryPointRemoved( const std::string& entryPoint, bool success )
{
+ vlc_ml_event_t ev;
+ ev.i_type = VLC_ML_EVENT_ENTRY_POINT_REMOVED;
+ ev.discovery.psz_entry_point = entryPoint.c_str();
+ ev.discovery.b_success = success;
+ m_vlc_ml->cbs->pf_send_event( m_vlc_ml, &ev );
}
-void MediaLibrary::onEntryPointBanned( const std::string&, bool )
+void MediaLibrary::onEntryPointBanned( const std::string& entryPoint, bool success )
{
+ vlc_ml_event_t ev;
+ ev.i_type = VLC_ML_EVENT_ENTRY_POINT_BANNED;
+ ev.discovery.psz_entry_point = entryPoint.c_str();
+ ev.discovery.b_success = success;
+ m_vlc_ml->cbs->pf_send_event( m_vlc_ml, &ev );
}
-void MediaLibrary::onEntryPointUnbanned( const std::string&, bool )
+void MediaLibrary::onEntryPointUnbanned( const std::string& entryPoint, bool success )
{
+ vlc_ml_event_t ev;
+ ev.i_type = VLC_ML_EVENT_ENTRY_POINT_UNBANNED;
+ ev.discovery.psz_entry_point = entryPoint.c_str();
+ ev.discovery.b_success = success;
+ m_vlc_ml->cbs->pf_send_event( m_vlc_ml, &ev );
}
-void MediaLibrary::onParsingStatsUpdated( uint32_t )
+void MediaLibrary::onParsingStatsUpdated( uint32_t progress )
{
+ vlc_ml_event_t ev;
+ ev.i_type = VLC_ML_EVENT_PARSING_PROGRESS_UPDATED;
+ ev.parser.i_progress = progress;
+ m_vlc_ml->cbs->pf_send_event( m_vlc_ml, &ev );
}
-void MediaLibrary::onBackgroundTasksIdleChanged( bool )
+void MediaLibrary::onBackgroundTasksIdleChanged( bool idle )
{
+ vlc_ml_event_t ev;
+ ev.i_type = VLC_ML_EVENT_BACKGROUND_IDLE_CHANGED;
+ ev.background_tasks.b_idle = idle;
+ m_vlc_ml->cbs->pf_send_event( m_vlc_ml, &ev );
}
void MediaLibrary::onMediaThumbnailReady( medialibrary::MediaPtr, bool )
--
2.18.0
More information about the vlc-devel
mailing list