Commit 545f5b8a authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

addons: simplify events handling

Use fixed owner structure instead of deprecated VLC events.

Notes:
 - Outstanding memory leaks are not fixed.
 - Reference counting in MacOS UI is not obvious if it exists (??).
parent 09673630
...@@ -129,14 +129,22 @@ struct addons_storage_t ...@@ -129,14 +129,22 @@ struct addons_storage_t
addons_storage_sys_t *p_sys; addons_storage_sys_t *p_sys;
}; };
typedef struct addons_manager_t addons_manager_t;
struct addons_manager_owner
{
void *sys;
void (*addon_found)(struct addons_manager_t *, struct addon_entry_t *);
void (*discovery_ended)(struct addons_manager_t *);
void (*addon_changed)(struct addons_manager_t *, struct addon_entry_t *);
};
typedef struct addons_manager_private_t addons_manager_private_t; typedef struct addons_manager_private_t addons_manager_private_t;
struct addons_manager_t struct addons_manager_t
{ {
vlc_event_manager_t * p_event_manager; struct addons_manager_owner owner;
addons_manager_private_t *p_priv; addons_manager_private_t *p_priv;
}; };
typedef struct addons_manager_t addons_manager_t;
/** /**
* addon entry lifecycle * addon entry lifecycle
...@@ -148,7 +156,8 @@ VLC_API void addon_entry_Release(addon_entry_t *); ...@@ -148,7 +156,8 @@ VLC_API void addon_entry_Release(addon_entry_t *);
/** /**
* addons manager lifecycle * addons manager lifecycle
*/ */
VLC_API addons_manager_t *addons_manager_New( vlc_object_t * ); VLC_API addons_manager_t *addons_manager_New( vlc_object_t *,
const struct addons_manager_owner * );
VLC_API void addons_manager_Delete( addons_manager_t * ); VLC_API void addons_manager_Delete( addons_manager_t * );
/** /**
......
...@@ -124,11 +124,6 @@ typedef enum vlc_event_type_t { ...@@ -124,11 +124,6 @@ typedef enum vlc_event_type_t {
/* Renderer Discovery events */ /* Renderer Discovery events */
vlc_RendererDiscoveryItemAdded=vlc_InputItemPreparseEnded+6, vlc_RendererDiscoveryItemAdded=vlc_InputItemPreparseEnded+6,
vlc_RendererDiscoveryItemRemoved, vlc_RendererDiscoveryItemRemoved,
/* Addons Manager events */
vlc_AddonFound,
vlc_AddonsDiscoveryEnded,
vlc_AddonChanged
} vlc_event_type_t; } vlc_event_type_t;
/* Event definition */ /* Event definition */
...@@ -185,12 +180,6 @@ typedef struct vlc_event_t ...@@ -185,12 +180,6 @@ typedef struct vlc_event_t
{ {
vlc_renderer_item_t * p_item; vlc_renderer_item_t * p_item;
} renderer_discovery_item_removed; } renderer_discovery_item_removed;
/* Addons */
struct vlc_addon_generic_event
{
addon_entry_t * p_entry;
} addon_generic_event;
} u; } u;
} vlc_event_t; } vlc_event_t;
......
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
*****************************************************************************/ *****************************************************************************/
#import <vlc_common.h> #import <vlc_common.h>
#import <vlc_events.h>
#import <vlc_addons.h> #import <vlc_addons.h>
#import "VLCAddonsWindowController.h" #import "VLCAddonsWindowController.h"
...@@ -42,17 +41,32 @@ ...@@ -42,17 +41,32 @@
@end @end
static void addonsEventsCallback( const vlc_event_t *event, void *data ) static void addonFoundCallback( addons_manager_t *manager,
addon_entry_t *entry )
{ {
VLCAddonsWindowController *controller = (__bridge VLCAddonsWindowController *)data; VLCAddonsWindowController *controller = (__bridge VLCAddonsWindowController *) manager->owner.sys;
@autoreleasepool { @autoreleasepool {
if (event->type == vlc_AddonFound) [controller performSelectorOnMainThread:@selector(addAddon:) withObject:[NSValue valueWithPointer:entry] waitUntilDone:NO];
[controller performSelectorOnMainThread:@selector(addAddon:) withObject:[NSValue valueWithPointer:event->u.addon_generic_event.p_entry] waitUntilDone:NO]; }
else if (event->type == vlc_AddonsDiscoveryEnded) }
[controller performSelectorOnMainThread:@selector(discoveryEnded) withObject:nil waitUntilDone:NO];
else if (event->type == vlc_AddonChanged) static void addonsDiscoveryEndedCallback( addons_manager_t *manager )
[controller performSelectorOnMainThread:@selector(addonChanged:) withObject:[NSValue valueWithPointer:event->u.addon_generic_event.p_entry] waitUntilDone:NO]; {
VLCAddonsWindowController *controller = (__bridge VLCAddonsWindowController *) manager->owner.sys;
@autoreleasepool {
[controller performSelectorOnMainThread:@selector(discoveryEnded) withObject:nil waitUntilDone:NO];
}
}
static void addonsChangedCallback( addons_manager_t *manager,
addon_entry_t *entry )
{
VLCAddonsWindowController *controller = (__bridge VLCAddonsWindowController *) manager->owner.sys;
@autoreleasepool {
[controller performSelectorOnMainThread:@selector(addonChanged:) withObject:[NSValue valueWithPointer:entry] waitUntilDone:NO];
} }
} }
...@@ -117,15 +131,18 @@ static void addonsEventsCallback( const vlc_event_t *event, void *data ) ...@@ -117,15 +131,18 @@ static void addonsEventsCallback( const vlc_event_t *event, void *data )
[[[_addonsTable tableColumnWithIdentifier:@"author"] headerCell] setStringValue:_NS("Author")]; [[[_addonsTable tableColumnWithIdentifier:@"author"] headerCell] setStringValue:_NS("Author")];
[[[_addonsTable tableColumnWithIdentifier:@"type"] headerCell] setStringValue:_NS("Type")]; [[[_addonsTable tableColumnWithIdentifier:@"type"] headerCell] setStringValue:_NS("Type")];
_manager = addons_manager_New((vlc_object_t *)getIntf()); struct addons_manager_owner owner =
{
(__bridge void *)self,
addonFoundCallback,
addonsDiscoveryEndedCallback,
addonChangedCallback,
};
_manager = addons_manager_New((vlc_object_t *)getIntf(), &owner);
if (!_manager) if (!_manager)
return; return;
vlc_event_manager_t *p_em = _manager->p_event_manager;
vlc_event_attach(p_em, vlc_AddonFound, addonsEventsCallback, (__bridge void *)self);
vlc_event_attach(p_em, vlc_AddonsDiscoveryEnded, addonsEventsCallback, (__bridge void *)self);
vlc_event_attach(p_em, vlc_AddonChanged, addonsEventsCallback, (__bridge void *)self);
[self _findInstalled]; [self _findInstalled];
} }
......
...@@ -30,13 +30,15 @@ const QEvent::Type AddonManagerEvent::DiscoveryEndedEvent = ...@@ -30,13 +30,15 @@ const QEvent::Type AddonManagerEvent::DiscoveryEndedEvent =
AddonsManager::AddonsManager( intf_thread_t *p_intf ) AddonsManager::AddonsManager( intf_thread_t *p_intf )
{ {
p_manager = addons_manager_New( VLC_OBJECT(p_intf) ); struct addons_manager_owner owner =
if ( !p_manager ) return; {
this,
addonFoundCallback,
addonsDiscoveryEndedCallback,
addonChangedCallback,
};
vlc_event_manager_t *p_em = p_manager->p_event_manager; p_manager = addons_manager_New( VLC_OBJECT(p_intf), &owner );
vlc_event_attach( p_em, vlc_AddonFound, addonsEventsCallback, this );
vlc_event_attach( p_em, vlc_AddonsDiscoveryEnded, addonsEventsCallback, this );
vlc_event_attach( p_em, vlc_AddonChanged, addonsEventsCallback, this );
} }
AddonsManager::~AddonsManager() AddonsManager::~AddonsManager()
...@@ -97,27 +99,29 @@ QString AddonsManager::getAddonType( int i_type ) ...@@ -97,27 +99,29 @@ QString AddonsManager::getAddonType( int i_type )
} }
} }
void AddonsManager::addonsEventsCallback( const vlc_event_t *event, void *data ) void AddonsManager::addonFoundCallback( addons_manager_t *manager,
addon_entry_t *entry )
{ {
AddonsManager *me = ( AddonsManager * ) data; AddonsManager *me = (AddonsManager *) manager->owner.sys;
QEvent *ev = NULL; QEvent *ev = new AddonManagerEvent( AddonManagerEvent::AddedEvent,
entry );
QApplication::postEvent( me, ev );
}
if ( event->type == vlc_AddonFound ) void AddonsManager::addonsDiscoveryEndedCallback( addons_manager_t *manager )
{ {
ev = new AddonManagerEvent( AddonManagerEvent::AddedEvent, AddonsManager *me = (AddonsManager *) manager->owner.sys;
event->u.addon_generic_event.p_entry ); QEvent *ev = new QEvent( AddonManagerEvent::DiscoveryEndedEvent );
} QApplication::postEvent( me, ev );
else if ( event->type == vlc_AddonsDiscoveryEnded ) }
{
ev = new QEvent( AddonManagerEvent::DiscoveryEndedEvent );
}
else if ( event->type == vlc_AddonChanged )
{
ev = new AddonManagerEvent( AddonManagerEvent::ChangedEvent,
event->u.addon_generic_event.p_entry );
}
if ( ev ) QApplication::postEvent( me, ev ); void AddonsManager::addonChangedCallback( addons_manager_t *manager,
addon_entry_t *entry )
{
AddonsManager *me = (AddonsManager *) manager->owner.sys;
QEvent *ev = new AddonManagerEvent( AddonManagerEvent::ChangedEvent,
entry );
QApplication::postEvent( me, ev );
} }
void AddonsManager::customEvent( QEvent *event ) void AddonsManager::customEvent( QEvent *event )
......
...@@ -66,7 +66,9 @@ class AddonsManager : public QObject, public Singleton<AddonsManager> ...@@ -66,7 +66,9 @@ class AddonsManager : public QObject, public Singleton<AddonsManager>
public: public:
AddonsManager( intf_thread_t * ); AddonsManager( intf_thread_t * );
virtual ~AddonsManager(); virtual ~AddonsManager();
static void addonsEventsCallback( const vlc_event_t *, void * ); static void addonFoundCallback( addons_manager_t *, addon_entry_t * );
static void addonsDiscoveryEndedCallback( addons_manager_t * );
static void addonChangedCallback( addons_manager_t *, addon_entry_t * );
void customEvent( QEvent * ); void customEvent( QEvent * );
void install( QByteArray id ); void install( QByteArray id );
void remove( QByteArray id ); void remove( QByteArray id );
......
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
#include <vlc_atomic.h> #include <vlc_atomic.h>
#include <vlc_modules.h> #include <vlc_modules.h>
#include <vlc_arrays.h> #include <vlc_arrays.h>
#include <vlc_events.h>
#include "libvlc.h" #include "libvlc.h"
#include <vlc_addons.h> #include <vlc_addons.h>
...@@ -124,7 +123,8 @@ void addon_entry_Release( addon_entry_t * p_entry ) ...@@ -124,7 +123,8 @@ void addon_entry_Release( addon_entry_t * p_entry )
free( owner ); free( owner );
} }
addons_manager_t *addons_manager_New( vlc_object_t *p_this ) addons_manager_t *addons_manager_New( vlc_object_t *p_this,
const struct addons_manager_owner *restrict owner )
{ {
addons_manager_t *p_manager = malloc( sizeof(addons_manager_t) ); addons_manager_t *p_manager = malloc( sizeof(addons_manager_t) );
if ( !p_manager ) return NULL; if ( !p_manager ) return NULL;
...@@ -136,14 +136,7 @@ addons_manager_t *addons_manager_New( vlc_object_t *p_this ) ...@@ -136,14 +136,7 @@ addons_manager_t *addons_manager_New( vlc_object_t *p_this )
return NULL; return NULL;
} }
p_manager->p_event_manager = malloc( sizeof(vlc_event_manager_t) ); p_manager->owner = *owner;
if ( !p_manager->p_event_manager )
{
free( p_manager->p_priv );
free( p_manager );
return NULL;
}
p_manager->p_priv->p_parent = p_this; p_manager->p_priv->p_parent = p_this;
#define INIT_QUEUE( name ) \ #define INIT_QUEUE( name ) \
...@@ -156,12 +149,6 @@ addons_manager_t *addons_manager_New( vlc_object_t *p_this ) ...@@ -156,12 +149,6 @@ addons_manager_t *addons_manager_New( vlc_object_t *p_this )
INIT_QUEUE( installer ) INIT_QUEUE( installer )
ARRAY_INIT( p_manager->p_priv->finder.uris ); ARRAY_INIT( p_manager->p_priv->finder.uris );
vlc_event_manager_t *em = p_manager->p_event_manager;
vlc_event_manager_init( em, p_manager );
vlc_event_manager_register_event_type(em, vlc_AddonFound);
vlc_event_manager_register_event_type(em, vlc_AddonsDiscoveryEnded);
vlc_event_manager_register_event_type(em, vlc_AddonChanged);
return p_manager; return p_manager;
} }
...@@ -187,8 +174,6 @@ void addons_manager_Delete( addons_manager_t *p_manager ) ...@@ -187,8 +174,6 @@ void addons_manager_Delete( addons_manager_t *p_manager )
vlc_join( p_manager->p_priv->installer.thread, NULL ); vlc_join( p_manager->p_priv->installer.thread, NULL );
} }
vlc_event_manager_fini( p_manager->p_event_manager );
#define FREE_QUEUE( name ) \ #define FREE_QUEUE( name ) \
FOREACH_ARRAY( addon_entry_t *p_entry, p_manager->p_priv->name.entries )\ FOREACH_ARRAY( addon_entry_t *p_entry, p_manager->p_priv->name.entries )\
addon_entry_Release( p_entry );\ addon_entry_Release( p_entry );\
...@@ -205,7 +190,6 @@ void addons_manager_Delete( addons_manager_t *p_manager ) ...@@ -205,7 +190,6 @@ void addons_manager_Delete( addons_manager_t *p_manager )
ARRAY_RESET( p_manager->p_priv->finder.uris ); ARRAY_RESET( p_manager->p_priv->finder.uris );
free( p_manager->p_priv ); free( p_manager->p_priv );
free( p_manager->p_event_manager );
free( p_manager ); free( p_manager );
} }
...@@ -273,10 +257,7 @@ static void MergeSources( addons_manager_t *p_manager, ...@@ -273,10 +257,7 @@ static void MergeSources( addons_manager_t *p_manager,
if ( !p_manager_entry ) if ( !p_manager_entry )
{ {
ARRAY_APPEND( p_manager->p_priv->finder.entries, p_entry ); ARRAY_APPEND( p_manager->p_priv->finder.entries, p_entry );
vlc_event_t event; p_manager->owner.addon_found( p_manager, p_entry );
event.type = vlc_AddonFound;
event.u.addon_generic_event.p_entry = p_entry;
vlc_event_send( p_manager->p_event_manager, &event );
} }
else else
{ {
...@@ -361,11 +342,7 @@ static void *FinderThread( void *p_data ) ...@@ -361,11 +342,7 @@ static void *FinderThread( void *p_data )
vlc_object_release( p_finder ); vlc_object_release( p_finder );
} }
vlc_event_t event; p_manager->owner.discovery_ended( p_manager );
event.type = vlc_AddonsDiscoveryEnded;
event.u.addon_generic_event.p_entry = NULL;
vlc_event_send( p_manager->p_event_manager, &event );
vlc_restorecancel( i_cancel ); vlc_restorecancel( i_cancel );
vlc_testcancel(); vlc_testcancel();
} }
...@@ -437,8 +414,6 @@ static void *InstallerThread( void *p_data ) ...@@ -437,8 +414,6 @@ static void *InstallerThread( void *p_data )
{ {
addons_manager_t *p_manager = p_data; addons_manager_t *p_manager = p_data;
int i_ret; int i_ret;
vlc_event_t event;
event.type = vlc_AddonChanged;
for( ;; ) for( ;; )
{ {
...@@ -466,8 +441,7 @@ static void *InstallerThread( void *p_data ) ...@@ -466,8 +441,7 @@ static void *InstallerThread( void *p_data )
vlc_mutex_unlock( &p_entry->lock ); vlc_mutex_unlock( &p_entry->lock );
/* notify */ /* notify */
event.u.addon_generic_event.p_entry = p_entry; p_manager->owner.addon_changed( p_manager, p_entry );
vlc_event_send( p_manager->p_event_manager, &event );
i_ret = installOrRemoveAddon( p_manager, p_entry, false ); i_ret = installOrRemoveAddon( p_manager, p_entry, false );
...@@ -481,8 +455,7 @@ static void *InstallerThread( void *p_data ) ...@@ -481,8 +455,7 @@ static void *InstallerThread( void *p_data )
vlc_mutex_unlock( &p_entry->lock ); vlc_mutex_unlock( &p_entry->lock );
/* notify */ /* notify */
event.u.addon_generic_event.p_entry = p_entry; p_manager->owner.addon_changed( p_manager, p_entry );
vlc_event_send( p_manager->p_event_manager, &event );
i_ret = installOrRemoveAddon( p_manager, p_entry, true ); i_ret = installOrRemoveAddon( p_manager, p_entry, true );
...@@ -493,8 +466,7 @@ static void *InstallerThread( void *p_data ) ...@@ -493,8 +466,7 @@ static void *InstallerThread( void *p_data )
vlc_mutex_unlock( &p_entry->lock ); vlc_mutex_unlock( &p_entry->lock );
/* !DO WORK */ /* !DO WORK */
event.u.addon_generic_event.p_entry = p_entry; p_manager->owner.addon_changed( p_manager, p_entry );
vlc_event_send( p_manager->p_event_manager, &event );
addon_entry_Release( p_entry ); addon_entry_Release( p_entry );
......
Markdown is supported
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