Commit b1cd1c3b authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen
Browse files

medialibrary: Plug events to the core API

parent 49cbf166
......@@ -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_started.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_progress.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_completed.psz_entry_point = entryPoint.c_str();
ev.discovery_completed.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.reload_started.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.reload_completed.psz_entry_point = entryPoint.c_str();
ev.reload_completed.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.entry_point_removed.psz_entry_point = entryPoint.c_str();
ev.entry_point_removed.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.entry_point_banned.psz_entry_point = entryPoint.c_str();
ev.entry_point_banned.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.entry_point_unbanned.psz_entry_point = entryPoint.c_str();
ev.entry_point_unbanned.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.parsing_progress.i_percent = 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_idle_changed.b_idle = idle;
m_vlc_ml->cbs->pf_send_event( m_vlc_ml, &ev );
}
void MediaLibrary::onMediaThumbnailReady( medialibrary::MediaPtr, bool )
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment